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