diff --git a/src/apps/mediaconverter/MediaFileInfo.cpp b/src/apps/mediaconverter/MediaFileInfo.cpp index 19157e77c7..1c504aa2eb 100644 --- a/src/apps/mediaconverter/MediaFileInfo.cpp +++ b/src/apps/mediaconverter/MediaFileInfo.cpp @@ -16,12 +16,12 @@ MediaFileInfo::MediaFileInfo(BMediaFile* file) } -void +status_t MediaFileInfo::LoadInfo(BMediaFile* file) { _Reset(); if (!file) - return; + return B_BAD_VALUE; BMediaTrack* track; media_format format; @@ -33,17 +33,33 @@ MediaFileInfo::LoadInfo(BMediaFile* file) int32 tracks = file->CountTracks(); int64 videoFrames = 0; int64 audioFrames = 0; + status_t ret = B_OK; + for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) { track = file->TrackAt(i); + ret = track->InitCheck(); + if (ret != B_OK) + return ret; + if (track != NULL) { - 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; - track->DecodedFormat(&format); + + ret = track->DecodedFormat(&format); + if (ret != B_OK) + return ret; + media_raw_video_format *rvf = &(format.u.raw_video); - track->GetCodecInfo(&codecInfo); + ret = track->GetCodecInfo(&codecInfo); + if (ret != B_OK) + return ret; + video.format << codecInfo.pretty_name; videoDuration = track->Duration(); videoFrames = track->CountFrames(); @@ -58,7 +74,10 @@ MediaFileInfo::LoadInfo(BMediaFile* file) } else if (format.IsAudio()) { memset(&format, 0, sizeof(format)); format.type = B_MEDIA_RAW_AUDIO; - track->DecodedFormat(&format); + 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); if (bytesPerSample == 1) { @@ -69,7 +88,10 @@ MediaFileInfo::LoadInfo(BMediaFile* file) audio.details << bytesPerSample << "byte "; } - track->GetCodecInfo(&codecInfo); + ret = track->GetCodecInfo(&codecInfo); + if (ret != B_OK) + return ret; + audio.format << codecInfo.pretty_name; audioDuration = track->Duration(); audioFrames = track->CountFrames(); @@ -86,13 +108,17 @@ MediaFileInfo::LoadInfo(BMediaFile* file) audio.details << audioFrames << " frames"; audioDone = true; } - file->ReleaseTrack(track); - } + ret = file->ReleaseTrack(track); + if (ret != B_OK) + return ret; + } } useconds = MAX(audioDuration, videoDuration); duration << (int32)(useconds / 1000000) << " seconds"; + + return B_OK; } diff --git a/src/apps/mediaconverter/MediaFileInfo.h b/src/apps/mediaconverter/MediaFileInfo.h index 1c62eba12c..4f9541e511 100644 --- a/src/apps/mediaconverter/MediaFileInfo.h +++ b/src/apps/mediaconverter/MediaFileInfo.h @@ -18,7 +18,7 @@ struct MediaInfo { struct MediaFileInfo { MediaFileInfo(BMediaFile* file = NULL); - void LoadInfo(BMediaFile* file); + status_t LoadInfo(BMediaFile* file); MediaInfo audio; MediaInfo video; diff --git a/src/apps/mediaconverter/MediaFileInfoView.cpp b/src/apps/mediaconverter/MediaFileInfoView.cpp index bea8d7d407..b1bfec8999 100644 --- a/src/apps/mediaconverter/MediaFileInfoView.cpp +++ b/src/apps/mediaconverter/MediaFileInfoView.cpp @@ -4,6 +4,7 @@ // This file may be used under the terms of the Be Sample Code License. #include "MediaFileInfoView.h" +#include #include #include #include @@ -155,7 +156,15 @@ MediaFileInfoView::Update(BMediaFile* file, entry_ref* ref) else fRef = entry_ref(); - fInfo.LoadInfo(file); + status_t ret = fInfo.LoadInfo(file); + if (ret != B_OK) { + BString error("An error has occurred reading the " + "file info.\n\nError : "); + error << strerror(ret); + BAlert* alert = new BAlert("File Error", error.String(), + "OK"); + alert->Go(NULL); + } InvalidateLayout(); Invalidate();