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:
@@ -16,12 +16,12 @@ MediaFileInfo::MediaFileInfo(BMediaFile* file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
status_t
|
||||||
MediaFileInfo::LoadInfo(BMediaFile* file)
|
MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||||
{
|
{
|
||||||
_Reset();
|
_Reset();
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
BMediaTrack* track;
|
BMediaTrack* track;
|
||||||
media_format format;
|
media_format format;
|
||||||
@@ -33,17 +33,33 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
|||||||
int32 tracks = file->CountTracks();
|
int32 tracks = file->CountTracks();
|
||||||
int64 videoFrames = 0;
|
int64 videoFrames = 0;
|
||||||
int64 audioFrames = 0;
|
int64 audioFrames = 0;
|
||||||
|
status_t ret = B_OK;
|
||||||
|
|
||||||
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
|
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
|
||||||
track = file->TrackAt(i);
|
track = file->TrackAt(i);
|
||||||
|
ret = track->InitCheck();
|
||||||
|
if (ret != B_OK)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (track != NULL) {
|
if (track != NULL) {
|
||||||
track->EncodedFormat(&format);
|
ret = track->EncodedFormat(&format);
|
||||||
|
if (ret != B_OK)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (format.IsVideo()) {
|
if (format.IsVideo()) {
|
||||||
memset(&format, 0, sizeof(format));
|
memset(&format, 0, sizeof(format));
|
||||||
format.type = B_MEDIA_RAW_VIDEO;
|
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);
|
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;
|
video.format << codecInfo.pretty_name;
|
||||||
videoDuration = track->Duration();
|
videoDuration = track->Duration();
|
||||||
videoFrames = track->CountFrames();
|
videoFrames = track->CountFrames();
|
||||||
@@ -58,7 +74,10 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
|||||||
} else if (format.IsAudio()) {
|
} else if (format.IsAudio()) {
|
||||||
memset(&format, 0, sizeof(format));
|
memset(&format, 0, sizeof(format));
|
||||||
format.type = B_MEDIA_RAW_AUDIO;
|
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);
|
media_raw_audio_format *raf = &(format.u.raw_audio);
|
||||||
char bytesPerSample = (char)(raf->format & 0xf);
|
char bytesPerSample = (char)(raf->format & 0xf);
|
||||||
if (bytesPerSample == 1) {
|
if (bytesPerSample == 1) {
|
||||||
@@ -69,7 +88,10 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
|||||||
audio.details << bytesPerSample << "byte ";
|
audio.details << bytesPerSample << "byte ";
|
||||||
}
|
}
|
||||||
|
|
||||||
track->GetCodecInfo(&codecInfo);
|
ret = track->GetCodecInfo(&codecInfo);
|
||||||
|
if (ret != B_OK)
|
||||||
|
return ret;
|
||||||
|
|
||||||
audio.format << codecInfo.pretty_name;
|
audio.format << codecInfo.pretty_name;
|
||||||
audioDuration = track->Duration();
|
audioDuration = track->Duration();
|
||||||
audioFrames = track->CountFrames();
|
audioFrames = track->CountFrames();
|
||||||
@@ -86,13 +108,17 @@ MediaFileInfo::LoadInfo(BMediaFile* file)
|
|||||||
audio.details << audioFrames << " frames";
|
audio.details << audioFrames << " frames";
|
||||||
audioDone = true;
|
audioDone = true;
|
||||||
}
|
}
|
||||||
file->ReleaseTrack(track);
|
ret = file->ReleaseTrack(track);
|
||||||
}
|
if (ret != B_OK)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useconds = MAX(audioDuration, videoDuration);
|
useconds = MAX(audioDuration, videoDuration);
|
||||||
duration << (int32)(useconds / 1000000)
|
duration << (int32)(useconds / 1000000)
|
||||||
<< " seconds";
|
<< " seconds";
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ struct MediaInfo {
|
|||||||
|
|
||||||
struct MediaFileInfo {
|
struct MediaFileInfo {
|
||||||
MediaFileInfo(BMediaFile* file = NULL);
|
MediaFileInfo(BMediaFile* file = NULL);
|
||||||
void LoadInfo(BMediaFile* file);
|
status_t LoadInfo(BMediaFile* file);
|
||||||
|
|
||||||
MediaInfo audio;
|
MediaInfo audio;
|
||||||
MediaInfo video;
|
MediaInfo video;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
// This file may be used under the terms of the Be Sample Code License.
|
// This file may be used under the terms of the Be Sample Code License.
|
||||||
#include "MediaFileInfoView.h"
|
#include "MediaFileInfoView.h"
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
#include <MediaFile.h>
|
#include <MediaFile.h>
|
||||||
#include <MediaTrack.h>
|
#include <MediaTrack.h>
|
||||||
@@ -155,7 +156,15 @@ MediaFileInfoView::Update(BMediaFile* file, entry_ref* ref)
|
|||||||
else
|
else
|
||||||
fRef = entry_ref();
|
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();
|
InvalidateLayout();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|||||||
Reference in New Issue
Block a user