Fix a few memory leaks in the FFMS2 providers. Patch by Myrsloik.
Originally committed to SVN as r2880.
This commit is contained in:
parent
338188b184
commit
1b2d26c231
3 changed files with 19 additions and 14 deletions
|
@ -89,12 +89,17 @@ 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);
|
||||
if (NumTracks <= 0)
|
||||
if (NumTracks <= 0) {
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
throw _T("FFmpegSource audio provider: no tracks found in index file");
|
||||
}
|
||||
|
||||
for (int i = 0; i < NumTracks; i++) {
|
||||
FrameInfoVector *FrameData = FFMS_GetTITrackIndex(Index, i, FFMSErrMsg, MsgSize);
|
||||
if (FrameData == NULL) {
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
wxString temp(FFMSErrMsg, wxConvUTF8);
|
||||
MsgString << _T("Couldn't get track data: ") << temp;
|
||||
throw MsgString;
|
||||
|
@ -104,6 +109,8 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
|
|||
if (FFMS_GetNumFrames(FrameData) <= 0 && (FFMS_GetTrackType(FrameData) == FFMS_TYPE_AUDIO)) {
|
||||
// found an unindexed audio track, we'll need to reindex
|
||||
try {
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
Index = DoIndexing(Index, FileNameWX, CacheName, FFMSTrackMaskAll, false);
|
||||
} catch (wxString temp) {
|
||||
MsgString << temp;
|
||||
|
@ -121,12 +128,16 @@ void FFmpegSourceAudioProvider::LoadAudio(Aegisub::String filename) {
|
|||
// FIXME: provide a way to choose which audio track to load?
|
||||
int TrackNumber = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_AUDIO, FFMSErrMsg, MsgSize);
|
||||
if (TrackNumber < 0) {
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
wxString temp(FFMSErrMsg, wxConvUTF8);
|
||||
MsgString << _T("Couldn't find any audio tracks: ") << temp;
|
||||
throw MsgString;
|
||||
}
|
||||
|
||||
AudioSource = FFMS_CreateAudioSource(FileNameWX.mb_str(wxConvLocal), TrackNumber, Index, FFMSErrMsg, MsgSize);
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
if (!AudioSource) {
|
||||
wxString temp(FFMSErrMsg, wxConvUTF8);
|
||||
MsgString << _T("Failed to open audio track: ") << temp;
|
||||
|
@ -166,13 +177,8 @@ FFmpegSourceAudioProvider::~FFmpegSourceAudioProvider() {
|
|||
///////////
|
||||
// Clean up
|
||||
void FFmpegSourceAudioProvider::Close() {
|
||||
if (AudioSource)
|
||||
FFMS_DestroyAudioSource(AudioSource);
|
||||
FFMS_DestroyAudioSource(AudioSource);
|
||||
AudioSource = NULL;
|
||||
if (Index)
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(Aegisub::String filename, d
|
|||
|
||||
// clean up variables
|
||||
VideoSource = NULL;
|
||||
Index = NULL;
|
||||
DstFormat = FFMS_GetPixFmt("none");
|
||||
LastDstFormat = FFMS_GetPixFmt("none");
|
||||
KeyFramesLoaded = false;
|
||||
|
@ -89,7 +88,7 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
|
|||
wxString CacheName = GetCacheFilename(filename.c_str());
|
||||
|
||||
// try to read index
|
||||
Index = FFMS_ReadIndex(CacheName.char_str(), FFMSErrorMessage, MessageSize);
|
||||
FrameIndex *Index = FFMS_ReadIndex(CacheName.char_str(), FFMSErrorMessage, MessageSize);
|
||||
if (Index == NULL) {
|
||||
// index didn't exist or was invalid, we'll have to (re)create it
|
||||
try {
|
||||
|
@ -124,12 +123,16 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
|
|||
// FIXME: provide a way to choose which audio track to load?
|
||||
int TrackNumber = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_VIDEO, FFMSErrorMessage, MessageSize);
|
||||
if (TrackNumber < 0) {
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
wxString temp(FFMSErrorMessage, wxConvUTF8);
|
||||
ErrorMsg << _T("Couldn't find any video tracks: ") << temp;
|
||||
throw ErrorMsg;
|
||||
}
|
||||
|
||||
VideoSource = FFMS_CreateVideoSource(FileNameWX.mb_str(wxConvLocal), TrackNumber, Index, "", Threads, SeekMode, FFMSErrorMessage, MessageSize);
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
Index = NULL;
|
||||
if (VideoSource == NULL) {
|
||||
wxString temp(FFMSErrorMessage, wxConvUTF8);
|
||||
ErrorMsg << _T("Failed to open video track: ") << temp;
|
||||
|
@ -188,11 +191,8 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
|
|||
///////////////
|
||||
// Close video
|
||||
void FFmpegSourceVideoProvider::Close() {
|
||||
if (VideoSource)
|
||||
FFMS_DestroyVideoSource(VideoSource);
|
||||
FFMS_DestroyVideoSource(VideoSource);
|
||||
VideoSource = NULL;
|
||||
if (Index)
|
||||
FFMS_DestroyFrameIndex(Index);
|
||||
|
||||
DstFormat = FFMS_GetPixFmt("none");
|
||||
LastDstFormat = FFMS_GetPixFmt("none");
|
||||
|
|
|
@ -49,7 +49,6 @@ class FFmpegSourceVideoProvider : public VideoProvider, FFmpegSourceProvider {
|
|||
private:
|
||||
VideoBase *VideoSource;
|
||||
const VideoProperties *VideoInfo;
|
||||
FrameIndex *Index;
|
||||
|
||||
int FrameNumber;
|
||||
wxArrayInt KeyFramesList;
|
||||
|
|
Loading…
Reference in a new issue