mediaconverter: fix memory leak

If the file has multiple audio or video tracks, only one is converted.
But in this case there would be memory leaks of various objects for the
other (unused) tracks. Fix this for now by allowing only the first track
of each type to be used. Ideally, MediaConverter should allow converting
all tracks or selecting which ones to keep.

Change-Id: I78c0c31648c80c7760dd68b3b4f64537ad2cee88
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5744
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
PulkoMandy 2022-12-22 18:02:15 +01:00 committed by Adrien Destugues
parent c9e5ef8796
commit 81f94bfd9e

View File

@ -378,6 +378,7 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile,
int64 audioFrameCount = 0;
status_t ret = B_OK;
bool multiTrack = false;
int32 tracks = inFile->CountTracks();
for (int32 i = 0; i < tracks && (!outAudTrack || !outVidTrack); i++) {
@ -385,6 +386,10 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile,
inFormat.Clear();
inTrack->EncodedFormat(&inFormat);
if (inFormat.IsAudio() && (audioCodec != NULL)) {
if (outAudTrack != NULL) {
multiTrack = true;
continue;
}
inAudTrack = inTrack;
outAudFormat.Clear();
outAudFormat.type = B_MEDIA_RAW_AUDIO;
@ -412,6 +417,10 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile,
}
} else if (inFormat.IsVideo() && (videoCodec != NULL)) {
if (outVidTrack != NULL) {
multiTrack = true;
continue;
}
inVidTrack = inTrack;
width = (int32)inFormat.Width();
height = (int32)inFormat.Height();
@ -499,6 +508,14 @@ MediaConverterApp::_ConvertFile(BMediaFile* inFile, BMediaFile* outFile,
ret = B_ERROR;
}
if (multiTrack) {
BAlert* alert = new BAlert(B_TRANSLATE("Multi-track file detected"),
B_TRANSLATE("The file has multiple audio or video tracks, only the first one of each will "
"be converted."),
B_TRANSLATE("Understood"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go();
}
if (fCancel) {
// don't have any video or audio tracks here, or cancelled
printf("MediaConverterApp::_ConvertFile()"