00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "mp4properties.h"
00023
00024
00025 #include <tstring.h>
00026
00027
00028 #ifdef HAVE_SYSTEMS_H
00029 #include <systems.h>
00030 #endif
00031
00032 #include <stdint.h>
00033
00034 #ifndef UINT64_TO_DOUBLE
00035 #define UINT64_TO_DOUBLE(a) ((double)((int64_t)(a)))
00036 #endif
00037
00038 using namespace TagLib;
00039
00040
00042
00044
00045 MP4::Properties::Properties(Properties::ReadStyle style) : AudioProperties(style)
00046 {
00047 m_length = 0;
00048 m_bitrate = 0;
00049 m_sampleRate = 0;
00050 m_channels = 0;
00051 }
00052
00053 MP4::Properties::~Properties()
00054 {
00055 }
00056
00057 int MP4::Properties::length() const
00058 {
00059 return m_length;
00060 }
00061
00062 int MP4::Properties::bitrate() const
00063 {
00064 return m_bitrate;
00065 }
00066
00067 int MP4::Properties::sampleRate() const
00068 {
00069 return m_sampleRate;
00070 }
00071
00072 int MP4::Properties::channels() const
00073 {
00074 return m_channels;
00075 }
00076
00077 void MP4::Properties::readMP4Properties( MP4FileHandle mp4File )
00078 {
00079 u_int32_t numTracks = MP4GetNumberOfTracks(mp4File);
00080
00081 for (u_int32_t i = 0; i < numTracks; i++)
00082 {
00083 MP4TrackId trackId = MP4FindTrackId(mp4File, i);
00084
00085 const char* trackType =
00086 MP4GetTrackType(mp4File, trackId);
00087
00088 if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE))
00089 {
00090
00091
00092 readAudioTrackProperties(mp4File, trackId );
00093 }
00094 }
00095 }
00096
00097 void MP4::Properties::readAudioTrackProperties(MP4FileHandle mp4File, MP4TrackId trackId )
00098 {
00099
00100 u_int32_t timeScale =
00101 MP4GetTrackTimeScale(mp4File, trackId);
00102
00103 MP4Duration trackDuration =
00104 MP4GetTrackDuration(mp4File, trackId);
00105
00106 double msDuration =
00107 UINT64_TO_DOUBLE(MP4ConvertFromTrackDuration(mp4File, trackId,
00108 trackDuration, MP4_MSECS_TIME_SCALE));
00109
00110 u_int32_t avgBitRate =
00111 MP4GetTrackBitRate(mp4File, trackId);
00112
00113 m_bitrate = (avgBitRate + 500) / 1000;
00114 m_sampleRate = timeScale;
00115 m_length = (int)(msDuration / 1000.0);
00116 m_channels = 2;
00117
00118
00119
00120 }