mp4tag/mp4properties.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 copyright            : (C) 2005 by Andy Leadbetter
00003 email                : andrew.leadbetter@gmail.com
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *   This library is free software; you can redistribute it and/or modify  *
00008  *   it  under the terms of the GNU Lesser General Public License version  *
00009  *   2.1 as published by the Free Software Foundation.                     *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful, but   *
00012  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the Free Software   *
00018  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,            *
00019  *   MA  02110-1301  USA                                                   *
00020  ***************************************************************************/
00021 
00022 #include "mp4properties.h"
00023 
00024 
00025 #include <tstring.h>
00026 
00027 //#include <config.h>
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 // public members
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             // OK we found an audio track so
00091             // decode it.
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 }

Generated on Mon Aug 6 21:24:20 2007 for plai by  doxygen 1.5.1