1 // Copyright 1999, Be Incorporated. All Rights Reserved.
2 // Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
3 // Copyright 2007, Stephan Aßmus. All Rights Reserved.
4 // Copyright 2010, Haiku, Inc. All Rights Reserved.
5 // This file may be used under the terms of the Be Sample Code License.
8 #include "MediaFileInfo.h"
11 #include <MediaTrack.h>
12 #include <MessageFormat.h>
15 #undef B_TRANSLATION_CONTEXT
16 #define B_TRANSLATION_CONTEXT "MediaFileInfo"
18 MediaFileInfo::MediaFileInfo(BMediaFile
* file
)
25 MediaFileInfo::LoadInfo(BMediaFile
* file
)
33 memset(&format
, 0, sizeof(format
));
34 media_codec_info codecInfo
;
35 bool audioDone(false), videoDone(false);
36 bigtime_t audioDuration
= 0;
37 bigtime_t videoDuration
= 0;
38 int32 tracks
= file
->CountTracks();
39 int64 videoFrames
= 0;
40 int64 audioFrames
= 0;
43 for (int32 i
= 0; i
< tracks
&& (!audioDone
|| !videoDone
); i
++) {
44 track
= file
->TrackAt(i
);
48 ret
= track
->InitCheck();
52 ret
= track
->EncodedFormat(&format
);
56 static BMessageFormat
frameFormat(B_TRANSLATE(
57 "{0, plural, one{# frame} other{# frames}}"));
59 if (format
.IsVideo()) {
60 memset(&format
, 0, sizeof(format
));
61 format
.type
= B_MEDIA_RAW_VIDEO
;
63 ret
= track
->DecodedFormat(&format
);
67 media_raw_video_format
*rvf
= &(format
.u
.raw_video
);
69 ret
= track
->GetCodecInfo(&codecInfo
);
73 video
.format
<< codecInfo
.pretty_name
;
74 videoDuration
= track
->Duration();
75 videoFrames
= track
->CountFrames();
79 B_TRANSLATE_COMMENT("%u x %u, %.2ffps", "Width x Height, fps"),
80 format
.Width(), format
.Height(),
81 rvf
->field_rate
/ rvf
->interlace
);
84 frameFormat
.Format(details
, videoFrames
);
86 video
.details
<< details
;
89 } else if (format
.IsAudio()) {
90 memset(&format
, 0, sizeof(format
));
91 format
.type
= B_MEDIA_RAW_AUDIO
;
92 ret
= track
->DecodedFormat(&format
);
95 media_raw_audio_format
*raf
= &(format
.u
.raw_audio
);
96 char bytesPerSample
= (char)(raf
->format
& 0xf);
99 if (bytesPerSample
== 1 || bytesPerSample
== 2) {
100 static BMessageFormat
bitFormat(
101 B_TRANSLATE("{0, plural, one{# bit} other{# bits}}"));
102 bitFormat
.Format(details
, bytesPerSample
* 8);
103 details
.SetToFormat(B_TRANSLATE("%d bit "), bytesPerSample
* 8);
105 static BMessageFormat
bitFormat(
106 B_TRANSLATE("{0, plural, one{# byte} other{# bytes}}"));
107 bitFormat
.Format(details
, bytesPerSample
);
109 audio
.details
<< details
;
110 audio
.details
<< " ";
112 ret
= track
->GetCodecInfo(&codecInfo
);
116 audio
.format
<< codecInfo
.pretty_name
;
117 audioDuration
= track
->Duration();
118 audioFrames
= track
->CountFrames();
120 if (raf
->channel_count
== 1) {
121 channels
.SetToFormat(B_TRANSLATE("%.1f kHz mono"),
122 raf
->frame_rate
/ 1000.f
);
123 } else if (raf
->channel_count
== 2) {
124 channels
.SetToFormat(B_TRANSLATE("%.1f kHz stereo"),
125 raf
->frame_rate
/ 1000.f
);
127 channels
.SetToFormat(B_TRANSLATE("%.1f kHz %ld channel"),
128 raf
->frame_rate
/ 1000.f
, raf
->channel_count
);
132 frameFormat
.Format(channels
, audioFrames
);
134 audio
.details
<< channels
;
138 ret
= file
->ReleaseTrack(track
);
143 useconds
= MAX(audioDuration
, videoDuration
);
144 duration
<< (int32
)(useconds
/ 1000000)
145 << B_TRANSLATE(" seconds");
152 MediaFileInfo::_Reset()
154 audio
.details
.SetTo("");
155 audio
.format
.SetTo("");
156 video
.details
.SetTo("");
157 video
.format
.SetTo("");