1 /**************************************************************************
2 copyright : (C) 2007 by Lukáš Lalinský
3 email : lalinsky@gmail.com
4 **************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
36 #include "mp4properties.h"
38 using namespace TagLib;
40 class MP4::Properties::PropertiesPrivate
43 PropertiesPrivate() : length(0), bitrate(0), sampleRate(0), channels(0), bitsPerSample(0) {}
52 MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
53 : AudioProperties(style)
55 d = new PropertiesPrivate;
57 MP4::Atom *moov = atoms->find("moov");
59 debug("MP4: Atom 'moov' not found");
66 MP4::AtomList trakList = moov->findall("trak");
67 for (unsigned int i = 0; i < trakList.size(); i++) {
69 MP4::Atom *hdlr = trak->find("mdia", "hdlr");
71 debug("MP4: Atom 'trak.mdia.hdlr' not found");
74 file->seek(hdlr->offset);
75 data = file->readBlock(hdlr->length);
76 if(data.mid(16, 4) == "soun") {
82 debug("MP4: No audio tracks");
86 MP4::Atom *mdhd = trak->find("mdia", "mdhd");
88 debug("MP4: Atom 'trak.mdia.mdhd' not found");
92 file->seek(mdhd->offset);
93 data = file->readBlock(mdhd->length);
95 unsigned int unit = data.mid(20, 4).toUInt();
96 unsigned int length = data.mid(24, 4).toUInt();
97 d->length = length / unit;
100 long long unit = data.mid(28, 8).toLongLong();
101 long long length = data.mid(36, 8).toLongLong();
102 d->length = int(length / unit);
105 MP4::Atom *atom = trak->find("mdia", "minf", "stbl", "stsd");
110 file->seek(atom->offset);
111 data = file->readBlock(atom->length);
112 if(data.mid(20, 4) == "mp4a") {
113 d->channels = data.mid(40, 2).toShort();
114 d->bitsPerSample = data.mid(42, 2).toShort();
115 d->sampleRate = data.mid(46, 4).toUInt();
116 if(data.mid(56, 4) == "esds" && data[64] == 0x03) {
118 if(data.mid(pos, 3) == "\x80\x80\x80") {
122 if(data[pos] == 0x04) {
124 if(data.mid(pos, 3) == "\x80\x80\x80") {
128 d->bitrate = (data.mid(pos, 4).toUInt() + 500) / 1000;
134 MP4::Properties::~Properties()
140 MP4::Properties::channels() const
146 MP4::Properties::sampleRate() const
148 return d->sampleRate;
152 MP4::Properties::length() const
158 MP4::Properties::bitrate() const
164 MP4::Properties::bitsPerSample() const
166 return d->bitsPerSample;