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 ***************************************************************************/
34 #include "mp4properties.h"
36 using namespace TagLib;
38 class MP4::Properties::PropertiesPrivate
41 PropertiesPrivate() : length(0), bitrate(0), sampleRate(0), channels(0), bitsPerSample(0) {}
50 MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style)
51 : AudioProperties(style)
53 d = new PropertiesPrivate;
55 MP4::Atom *moov = atoms->find("moov");
57 debug("MP4: Atom 'moov' not found");
64 MP4::AtomList trakList = moov->findall("trak");
65 for (unsigned int i = 0; i < trakList.size(); i++) {
67 MP4::Atom *hdlr = trak->find("mdia", "hdlr");
69 debug("MP4: Atom 'trak.mdia.hdlr' not found");
72 file->seek(hdlr->offset);
73 data = file->readBlock(hdlr->length);
74 if(data.mid(16, 4) == "soun") {
80 debug("MP4: No audio tracks");
84 MP4::Atom *mdhd = trak->find("mdia", "mdhd");
86 debug("MP4: Atom 'trak.mdia.mdhd' not found");
90 file->seek(mdhd->offset);
91 data = file->readBlock(mdhd->length);
93 unsigned int unit = data.mid(20, 4).toUInt();
94 unsigned int length = data.mid(24, 4).toUInt();
95 d->length = length / unit;
98 long long unit = data.mid(28, 8).toLongLong();
99 long long length = data.mid(36, 8).toLongLong();
100 d->length = int(length / unit);
103 MP4::Atom *atom = trak->find("mdia", "minf", "stbl", "stsd");
108 file->seek(atom->offset);
109 data = file->readBlock(atom->length);
110 if(data.mid(20, 4) == "mp4a") {
111 d->channels = data.mid(40, 2).toShort();
112 d->bitsPerSample = data.mid(42, 2).toShort();
113 d->sampleRate = data.mid(46, 4).toUInt();
114 if(data.mid(56, 4) == "esds" && data[64] == 0x03) {
116 if(data.mid(pos, 3) == "\x80\x80\x80") {
120 if(data[pos] == 0x04) {
122 if(data.mid(pos, 3) == "\x80\x80\x80") {
126 d->bitrate = (data.mid(pos, 4).toUInt() + 500) / 1000;
132 MP4::Properties::~Properties()
138 MP4::Properties::channels() const
144 MP4::Properties::sampleRate() const
146 return d->sampleRate;
150 MP4::Properties::length() const
156 MP4::Properties::bitrate() const
162 MP4::Properties::bitsPerSample() const
164 return d->bitsPerSample;