Patch by Barrett: Check for errors when obtaining information
about the contained tracks from media files. Display an alert accordingly. Fixes ticket #6497. Thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39157 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
961e35fb58
commit
e66d0f5520
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
// This file may be used under the terms of the Be Sample Code License.
|
||||
#include "MediaFileInfoView.h"
|
||||
|
||||
#include <Alert.h>
|
||||
#include <ControlLook.h>
|
||||
#include <MediaFile.h>
|
||||
#include <MediaTrack.h>
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue