MediaConverter: Move a NULL check

To avoid a NULL dereference, moving a NULL check earlier.

CID 5955.
This commit is contained in:
Philippe Saint-Pierre
2012-01-02 23:27:59 -05:00
parent 7cd8f5f9b9
commit 82556487af
+72 -73
View File
@@ -41,95 +41,94 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
track = file->TrackAt(i);
if (track == NULL)
return B_ERROR;
ret = track->InitCheck();
if (ret != B_OK)
return ret;
if (track != NULL) {
ret = track->EncodedFormat(&format);
ret = track->EncodedFormat(&format);
if (ret != B_OK)
return ret;
if (format.IsVideo()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_VIDEO;
ret = track->DecodedFormat(&format);
if (ret != B_OK)
return ret;
if (format.IsVideo()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_VIDEO;
media_raw_video_format *rvf = &(format.u.raw_video);
ret = track->DecodedFormat(&format);
if (ret != B_OK)
return ret;
ret = track->GetCodecInfo(&codecInfo);
if (ret != B_OK)
return ret;
media_raw_video_format *rvf = &(format.u.raw_video);
video.format << codecInfo.pretty_name;
videoDuration = track->Duration();
videoFrames = track->CountFrames();
ret = track->GetCodecInfo(&codecInfo);
if (ret != B_OK)
return ret;
BString details;
snprintf(details.LockBuffer(256), 256,
B_TRANSLATE_COMMENT("%u x %u, %.2ffps / %Ld frames",
"Width x Height, fps / frames"),
format.Width(), format.Height(),
rvf->field_rate / rvf->interlace, videoFrames);
details.UnlockBuffer();
video.details << details;
videoDone = true;
video.format << codecInfo.pretty_name;
videoDuration = track->Duration();
videoFrames = track->CountFrames();
} else if (format.IsAudio()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_AUDIO;
ret = track->DecodedFormat(&format);
if (ret != B_OK)
return ret;
media_raw_audio_format *raf = &(format.u.raw_audio);
char bytesPerSample = (char)(raf->format & 0xf);
BString details;
snprintf(details.LockBuffer(256), 256,
B_TRANSLATE_COMMENT("%u x %u, %.2ffps / %Ld frames",
"Width x Height, fps / frames"),
format.Width(), format.Height(),
rvf->field_rate / rvf->interlace, videoFrames);
details.UnlockBuffer();
video.details << details;
videoDone = true;
} else if (format.IsAudio()) {
memset(&format, 0, sizeof(format));
format.type = B_MEDIA_RAW_AUDIO;
ret = track->DecodedFormat(&format);
if (ret != B_OK)
return ret;
media_raw_audio_format *raf = &(format.u.raw_audio);
char bytesPerSample = (char)(raf->format & 0xf);
BString details;
if (bytesPerSample == 1 || bytesPerSample == 2) {
snprintf(details.LockBuffer(16), 16,
B_TRANSLATE("%d bit "), bytesPerSample * 8);
} else {
snprintf(details.LockBuffer(16), 16,
B_TRANSLATE("%d byte "), bytesPerSample);
}
details.UnlockBuffer();
audio.details << details;
ret = track->GetCodecInfo(&codecInfo);
if (ret != B_OK)
return ret;
audio.format << codecInfo.pretty_name;
audioDuration = track->Duration();
audioFrames = track->CountFrames();
BString channels;
if (raf->channel_count == 1) {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz mono / %lld frames"),
raf->frame_rate / 1000.f, audioFrames);
} else if (raf->channel_count == 2) {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz stereo / %lld frames"),
raf->frame_rate / 1000.f, audioFrames);
} else {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz %ld channel / %lld frames"),
raf->frame_rate / 1000.f, raf->channel_count, audioFrames);
}
channels.UnlockBuffer();
audio.details << channels;
audioDone = true;
BString details;
if (bytesPerSample == 1 || bytesPerSample == 2) {
snprintf(details.LockBuffer(16), 16,
B_TRANSLATE("%d bit "), bytesPerSample * 8);
} else {
snprintf(details.LockBuffer(16), 16,
B_TRANSLATE("%d byte "), bytesPerSample);
}
ret = file->ReleaseTrack(track);
details.UnlockBuffer();
audio.details << details;
ret = track->GetCodecInfo(&codecInfo);
if (ret != B_OK)
return ret;
audio.format << codecInfo.pretty_name;
audioDuration = track->Duration();
audioFrames = track->CountFrames();
BString channels;
if (raf->channel_count == 1) {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz mono / %lld frames"),
raf->frame_rate / 1000.f, audioFrames);
} else if (raf->channel_count == 2) {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz stereo / %lld frames"),
raf->frame_rate / 1000.f, audioFrames);
} else {
snprintf(channels.LockBuffer(64), 64,
B_TRANSLATE("%.1f kHz %ld channel / %lld frames"),
raf->frame_rate / 1000.f, raf->channel_count, audioFrames);
}
channels.UnlockBuffer();
audio.details << channels;
audioDone = true;
}
ret = file->ReleaseTrack(track);
if (ret != B_OK)
return ret;
}
useconds = MAX(audioDuration, videoDuration);