From fd8a7750c7de5df01d50e9a3ef90a465dd827f00 Mon Sep 17 00:00:00 2001
From: Karl Blomster <kalle.blomster@gmail.com>
Date: Wed, 1 Oct 2008 22:08:28 +0000
Subject: [PATCH] Update ffms2 providers to work with latest ffms2 API. Also
 fixes a few error messages.

Originally committed to SVN as r2408.
---
 aegisub/audio_provider_ffmpegsource.cpp | 12 ++++-----
 aegisub/ffmpegsource_common.cpp         |  6 ++---
 aegisub/video_provider_ffmpegsource.cpp | 33 +++++++++++--------------
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/aegisub/audio_provider_ffmpegsource.cpp b/aegisub/audio_provider_ffmpegsource.cpp
index 9049c95a9..3e57bc7a2 100644
--- a/aegisub/audio_provider_ffmpegsource.cpp
+++ b/aegisub/audio_provider_ffmpegsource.cpp
@@ -86,7 +86,7 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
 		}
 	} else {
 		// index exists, but does it have indexing info for the audio track(s)?
-		int NumTracks = FFMS_GetNumTracks(Index, FFMSErrMsg, MsgSize);
+		int NumTracks = FFMS_GetNumTracks(Index);
 		if (NumTracks <= 0)
 			throw _T("FFmpegSource audio provider: no tracks found in index file");
 
@@ -94,12 +94,12 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
 			FrameInfoVector *FrameData = FFMS_GetTITrackIndex(Index, i, FFMSErrMsg, MsgSize);
 			if (FrameData == NULL) {
 				wxString temp(FFMSErrMsg, wxConvUTF8);
-				MsgString << _T("couldn't get track data: ") << temp;
+				MsgString << _T("Couldn't get track data: ") << temp;
 				throw MsgString;
 			}
 
 			// does the track have any indexed frames?
-			if (FFMS_GetNumFrames(FrameData, FFMSErrMsg, MsgSize) <= 0 && (FFMS_GetTrackType(FrameData, FFMSErrMsg, MsgSize) == FFMS_TYPE_AUDIO)) {
+			if (FFMS_GetNumFrames(FrameData) <= 0 && (FFMS_GetTrackType(FrameData) == FFMS_TYPE_AUDIO)) {
 				// found an unindexed audio track, we'll need to reindex
 				try {
 					Index = DoIndexing(Index, FileNameWX, CacheName, FFMSTrackMaskAll, false);
@@ -120,14 +120,14 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
 	int TrackNumber = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_AUDIO, FFMSErrMsg, MsgSize);
 	if (TrackNumber < 0) {
 		wxString temp(FFMSErrMsg, wxConvUTF8);
-		MsgString << _T("couldn't find any audio tracks: ") << temp;
+		MsgString << _T("Couldn't find any audio tracks: ") << temp;
 		throw MsgString;
 	}
 
 	AudioSource = FFMS_CreateAudioSource(FileNameWX.char_str(), TrackNumber, Index, FFMSErrMsg, MsgSize);
 	if (!AudioSource) {
 			wxString temp(FFMSErrMsg, wxConvUTF8);
-			MsgString << _T("failed to open audio track: ") << temp;
+			MsgString << _T("Failed to open audio track: ") << temp;
 			throw MsgString;
 	}
 		
@@ -179,7 +179,7 @@ void FFmpegSourceAudioProvider::Close() {
 void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count) {
 	if (FFMS_GetAudio(AudioSource, Buf, Start, Count, FFMSErrMsg, MsgSize)) {
 		wxString temp(FFMSErrMsg, wxConvUTF8);
-		MsgString << _T("failed to get audio samples: ") << temp;
+		MsgString << _T("Failed to get audio samples: ") << temp;
 		throw MsgString;
 	}
 }
diff --git a/aegisub/ffmpegsource_common.cpp b/aegisub/ffmpegsource_common.cpp
index 00da75225..538d18fe8 100644
--- a/aegisub/ffmpegsource_common.cpp
+++ b/aegisub/ffmpegsource_common.cpp
@@ -64,7 +64,7 @@ FrameIndex *FFmpegSourceProvider::DoIndexing(FrameIndex *Index, wxString FileNam
 	// set up progress dialog callback
 	IndexingProgressDialog Progress;
 	Progress.IndexingCanceled = false;
-	Progress.ProgressDialog = new DialogProgress(NULL, _("Indexing"), &Progress.IndexingCanceled, _("Indexing timecodes and frame/sample data"), 0, 1);
+	Progress.ProgressDialog = new DialogProgress(NULL, _("Indexing"), &Progress.IndexingCanceled, _("Reading timecodes and frame/sample data"), 0, 1);
 	Progress.ProgressDialog->Show();
 	Progress.ProgressDialog->SetProgress(0,1);
 
@@ -73,7 +73,7 @@ FrameIndex *FFmpegSourceProvider::DoIndexing(FrameIndex *Index, wxString FileNam
 	if (!Index) {
 		Progress.ProgressDialog->Destroy();
 		wxString temp(FFMSErrMsg, wxConvUTF8);
-		MsgString << _T("failed to index: ") << temp;
+		MsgString << _T("Failed to index: ") << temp;
 		throw MsgString;
 	}
 	Progress.ProgressDialog->Destroy();
@@ -81,7 +81,7 @@ FrameIndex *FFmpegSourceProvider::DoIndexing(FrameIndex *Index, wxString FileNam
 	// write index to disk for later use
 	if (FFMS_WriteIndex(CacheName.char_str(), Index, FFMSErrMsg, MsgSize)) {
 		wxString temp(FFMSErrMsg, wxConvUTF8);
-		MsgString << _T("failed to write index: ") << temp;
+		MsgString << _T("Failed to write index: ") << temp;
 		throw MsgString;
 	}
 
diff --git a/aegisub/video_provider_ffmpegsource.cpp b/aegisub/video_provider_ffmpegsource.cpp
index 0a9f23cf4..b64ff0202 100644
--- a/aegisub/video_provider_ffmpegsource.cpp
+++ b/aegisub/video_provider_ffmpegsource.cpp
@@ -117,14 +117,14 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
 	int TrackNumber = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_VIDEO, FFMSErrorMessage, MessageSize);
 	if (TrackNumber < 0) {
 		wxString temp(FFMSErrorMessage, wxConvUTF8);
-		ErrorMsg << _T("couldn't find any video tracks: ") << temp;
+		ErrorMsg << _T("Couldn't find any video tracks: ") << temp;
 		throw ErrorMsg;
 	}
 
 	VideoSource = FFMS_CreateVideoSource(FileNameWX.char_str(), TrackNumber, Index, "", Threads, SeekMode, FFMSErrorMessage, MessageSize);
 	if (VideoSource == NULL) {
 		wxString temp(FFMSErrorMessage, wxConvUTF8);
-		ErrorMsg << _T("failed to open video track: ") << temp;
+		ErrorMsg << _T("Failed to open video track: ") << temp;
 		throw ErrorMsg;
 	}
 
@@ -132,18 +132,12 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
 	VideoInfo = FFMS_GetVideoProperties(VideoSource);
 
 	// get frame info data
-	FrameInfoVector *FrameData = FFMS_GetVSTrackIndex(VideoSource, FFMSErrorMessage, MessageSize);
-	if (FrameData == NULL) {
-		wxString temp(FFMSErrorMessage, wxConvUTF8);
-		ErrorMsg << _T("couldn't get track data: ") << temp;
-		throw ErrorMsg;
-	}
-	const TrackTimeBase *TimeBase = FFMS_GetTimeBase(FrameData, FFMSErrorMessage, MessageSize);
-	if (TimeBase == NULL) {
-		wxString temp(FFMSErrorMessage, wxConvUTF8);
-		ErrorMsg << _T("couldn't get track time base: ") << temp;
-		throw ErrorMsg;
-	}
+	FrameInfoVector *FrameData = FFMS_GetVSTrackIndex(VideoSource);
+	if (FrameData == NULL)
+		throw _T("FFmpegSource video provider: failed to get frame data");
+	const TrackTimeBase *TimeBase = FFMS_GetTimeBase(FrameData);
+	if (TimeBase == NULL)
+		throw _T("FFmpegSource video provider: failed to get track time base");
 
 	const FrameInfo *CurFrameData;
 
@@ -152,7 +146,7 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
 		CurFrameData = FFMS_GetFrameInfo(FrameData, CurFrameNum, FFMSErrorMessage, MessageSize);
 		if (CurFrameData == NULL) {
 			wxString temp(FFMSErrorMessage, wxConvUTF8);
-			ErrorMsg << _T("couldn't get framedata for frame ") << CurFrameNum << _T(": ") << temp;
+			ErrorMsg << _T("Couldn't get framedata for frame ") << CurFrameNum << _T(": ") << temp;
 			throw ErrorMsg;
 		}
 
@@ -238,8 +232,11 @@ const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType)
 
 	// requested format was changed since last time we were called, (re)set output format
 	if (LastDstFormat != DstFormat) {
-		if (FFMS_SetOutputFormat(VideoSource, DstFormat, w, h))
-			throw _T("FFmpegSource video provider: failed to set desired output format");
+		if (FFMS_SetOutputFormat(VideoSource, DstFormat, w, h, FFMSErrorMessage, MessageSize)) {
+			wxString temp(FFMSErrorMessage, wxConvUTF8);
+			ErrorMsg << _T("Failed to set output format: ") << temp;
+			throw ErrorMsg;
+		}
 		LastDstFormat = DstFormat;
 	}
 
@@ -247,7 +244,7 @@ const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType)
 	const AVFrameLite *SrcFrame = FFMS_GetFrame(VideoSource, n, FFMSErrorMessage, MessageSize);
 	if (SrcFrame == NULL) {
 		wxString temp(FFMSErrorMessage, wxConvUTF8);
-		ErrorMsg << _T("failed to retrieve frame: ") << temp;
+		ErrorMsg << _T("Failed to retrieve frame: ") << temp;
 		throw ErrorMsg;
 	}
 
-- 
GitLab