From f52d672815f861b43e1d77378c3e20f842325b5a Mon Sep 17 00:00:00 2001 From: Wim van der Meer Date: Sun, 27 Jun 2010 08:40:54 +0000 Subject: [PATCH] Compiler warning and code style fixes. No functional change. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37273 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../plugins/mp4_reader/libMP4/MP4Atom.cpp | 150 ++- .../media/plugins/mp4_reader/libMP4/MP4Atom.h | 160 +-- .../plugins/mp4_reader/libMP4/MP4Parser.cpp | 992 ++++++++++++------ .../plugins/mp4_reader/libMP4/MP4Parser.h | 718 +++++++------ .../plugins/mp4_reader/libMP4/MP4TrakAtom.cpp | 169 +-- 5 files changed, 1404 insertions(+), 785 deletions(-) diff --git a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.cpp b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.cpp index 2ef4ef5844..af3d235dcf 100644 --- a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.cpp +++ b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.cpp @@ -22,11 +22,15 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include + #include "MP4Atom.h" -AtomBase::AtomBase(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) +#include + + +AtomBase::AtomBase(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, + uint64 patomSize) { theStream = pStream; streamOffset = pstreamOffset; @@ -35,13 +39,16 @@ AtomBase::AtomBase(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, parentAtom = NULL; } + AtomBase::~AtomBase() { theStream = NULL; parentAtom = NULL; } -char *AtomBase::GetAtomTypeAsFourcc() + +char * +AtomBase::GetAtomTypeAsFourcc() { fourcc[0] = (char)((atomType >> 24) & 0xff); fourcc[1] = (char)((atomType >> 16) & 0xff); @@ -52,9 +59,11 @@ char *AtomBase::GetAtomTypeAsFourcc() return fourcc; } -char *AtomBase::GetAtomName() + +const char * +AtomBase::GetAtomName() { - char *_result; + const char *_result; _result = OnGetAtomName(); if (_result) { return _result; @@ -69,12 +78,16 @@ char *AtomBase::GetAtomName() return fourcc; } -char *AtomBase::OnGetAtomName() + +const char * +AtomBase::OnGetAtomName() { return NULL; } -void AtomBase::ProcessMetaData() + +void +AtomBase::ProcessMetaData() // ProcessMetaData() - Reads in the basic Atom Meta Data // - Calls OnProcessMetaData() // - Calls ProcessMetaData on each child atom @@ -87,12 +100,16 @@ void AtomBase::ProcessMetaData() MoveToEnd(); } -void AtomBase::OnProcessMetaData() + +void +AtomBase::OnProcessMetaData() { MoveToEnd(); } -bool AtomBase::MoveToEnd() + +bool +AtomBase::MoveToEnd() { off_t NewPosition = streamOffset + atomSize; @@ -102,60 +119,79 @@ bool AtomBase::MoveToEnd() return true; } -uint64 AtomBase::GetBytesRemaining() + +uint64 +AtomBase::GetBytesRemaining() { off_t EndPosition = streamOffset + atomSize; off_t CurrPosition = GetStream()->Position(); if (CurrPosition > EndPosition) { - printf("ERROR: Read past atom boundary by %Ld bytes\n",CurrPosition - EndPosition); + printf("ERROR: Read past atom boundary by %Ld bytes\n", + CurrPosition - EndPosition); return 0; } return (EndPosition - CurrPosition); } -void AtomBase::DisplayAtoms() + +void +AtomBase::DisplayAtoms() { uint32 aindent = 0; DisplayAtoms(aindent); } -void AtomBase::DisplayAtoms(uint32 pindent) + +void +AtomBase::DisplayAtoms(uint32 pindent) { Indent(pindent); printf("(%s)\n",GetAtomName()); } -void AtomBase::Indent(uint32 pindent) + +void +AtomBase::Indent(uint32 pindent) { for (uint32 i=0;iNoEntries); } -BPositionIO *AtomBase::OnGetStream() + +BPositionIO * +AtomBase::OnGetStream() { // default implementation return theStream; } -BPositionIO *AtomBase::GetStream() + +BPositionIO * +AtomBase::GetStream() { return OnGetStream(); } -void AtomBase::Read(uint64 *value) + +void +AtomBase::Read(uint64 *value) { uint32 bytes_read; @@ -166,7 +202,9 @@ void AtomBase::Read(uint64 *value) *value = B_BENDIAN_TO_HOST_INT64(*value); } -void AtomBase::Read(uint32 *value) + +void +AtomBase::Read(uint32 *value) { uint32 bytes_read; @@ -177,7 +215,9 @@ void AtomBase::Read(uint32 *value) *value = B_BENDIAN_TO_HOST_INT32(*value); } -void AtomBase::Read(int32 *value) + +void +AtomBase::Read(int32 *value) { uint32 bytes_read; @@ -188,7 +228,9 @@ void AtomBase::Read(int32 *value) *value = B_BENDIAN_TO_HOST_INT32(*value); } -void AtomBase::Read(uint16 *value) + +void +AtomBase::Read(uint16 *value) { uint32 bytes_read; @@ -199,7 +241,9 @@ void AtomBase::Read(uint16 *value) *value = B_BENDIAN_TO_HOST_INT16(*value); } -void AtomBase::Read(uint8 *value) + +void +AtomBase::Read(uint8 *value) { uint32 bytes_read; @@ -208,7 +252,9 @@ void AtomBase::Read(uint8 *value) // Assert((bytes_read == sizeof(uint8),"Read Error"); } -void AtomBase::Read(char *value, uint32 maxread) + +void +AtomBase::Read(char *value, uint32 maxread) { uint32 bytes_read; @@ -217,7 +263,9 @@ void AtomBase::Read(char *value, uint32 maxread) // Assert((bytes_read == maxread,"Read Error"); } -void AtomBase::Read(uint8 *value, uint32 maxread) + +void +AtomBase::Read(uint8 *value, uint32 maxread) { uint32 bytes_read; @@ -226,10 +274,13 @@ void AtomBase::Read(uint8 *value, uint32 maxread) // Assert((bytes_read == maxread,"Read Error"); } -uint64 AtomBase::GetBits(uint64 buffer, uint8 startBit, uint8 totalBits) + +uint64 +AtomBase::GetBits(uint64 buffer, uint8 startBit, uint8 totalBits) { // startBit should range from 0-63, totalBits should range from 1-64 - if ((startBit < 64) && (totalBits > 0) && (totalBits <= 64) && (startBit + totalBits <= 64)) { + if ((startBit < 64) && (totalBits > 0) && (totalBits <= 64) + && (startBit + totalBits <= 64)) { // Ok pull from the buffer the bits wanted. buffer = buffer << startBit; buffer = buffer >> (64 - (totalBits + startBit) + startBit); @@ -240,10 +291,13 @@ uint64 AtomBase::GetBits(uint64 buffer, uint8 startBit, uint8 totalBits) return 0L; } -uint32 AtomBase::GetBits(uint32 buffer, uint8 startBit, uint8 totalBits) + +uint32 +AtomBase::GetBits(uint32 buffer, uint8 startBit, uint8 totalBits) { // startBit should range from 0-31, totalBits should range from 1-32 - if ((startBit < 32) && (totalBits > 0) && (totalBits <= 32) && (startBit + totalBits <= 32)) { + if ((startBit < 32) && (totalBits > 0) && (totalBits <= 32) + && (startBit + totalBits <= 32)) { // Ok pull from the buffer the bits wanted. buffer = buffer << startBit; buffer = buffer >> (32 - (startBit + totalBits) + startBit); @@ -254,15 +308,22 @@ uint32 AtomBase::GetBits(uint32 buffer, uint8 startBit, uint8 totalBits) return 0; } -FullAtom::FullAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) + +FullAtom::FullAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, + uint64 patomSize) + : + AtomBase(pStream, pstreamOffset, patomType, patomSize) { } + FullAtom::~FullAtom() { } -void FullAtom::OnProcessMetaData() + +void +FullAtom::OnProcessMetaData() { Read(&Version); Read(&Flags1); @@ -270,16 +331,23 @@ void FullAtom::OnProcessMetaData() Read(&Flags3); } -AtomContainer::AtomContainer(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomBase(pStream, pstreamOffset, patomType, patomSize) + +AtomContainer::AtomContainer(BPositionIO *pStream, off_t pstreamOffset, + uint32 patomType, uint64 patomSize) + : + AtomBase(pStream, pstreamOffset, patomType, patomSize) { TotalChildren = 0; } + AtomContainer::~AtomContainer() { } -void AtomContainer::DisplayAtoms(uint32 pindent) + +void +AtomContainer::DisplayAtoms(uint32 pindent) { Indent(pindent); printf("%ld:(%s)\n",TotalChildren,GetAtomName()); @@ -291,7 +359,9 @@ void AtomContainer::DisplayAtoms(uint32 pindent) } -void AtomContainer::ProcessMetaData() + +void +AtomContainer::ProcessMetaData() { SetAtomOffset(GetStream()->Position()); @@ -310,7 +380,9 @@ void AtomContainer::ProcessMetaData() MoveToEnd(); } -bool AtomContainer::AddChild(AtomBase *pChildAtom) + +bool +AtomContainer::AddChild(AtomBase *pChildAtom) { if (pChildAtom) { pChildAtom->SetParent(this); @@ -321,6 +393,7 @@ bool AtomContainer::AddChild(AtomBase *pChildAtom) return false; } + AtomBase *AtomContainer::GetChildAtom(uint32 patomType, uint32 offset) { for (uint32 i=0;iIsContainer()) { // search container - AtomBase *aAtomBase = (dynamic_cast(atomChildren[i])->GetChildAtom(patomType, offset)); + AtomBase *aAtomBase = dynamic_cast + (atomChildren[i])->GetChildAtom(patomType, offset); if (aAtomBase) { // found in container return aAtomBase; @@ -346,6 +420,8 @@ AtomBase *AtomContainer::GetChildAtom(uint32 patomType, uint32 offset) return NULL; } -void AtomContainer::OnProcessMetaData() + +void +AtomContainer::OnProcessMetaData() { } diff --git a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.h b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.h index 84be06a179..4aa89f7ed4 100644 --- a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.h +++ b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Atom.h @@ -25,6 +25,7 @@ #ifndef _MP4_ATOM_H #define _MP4_ATOM_H + #include "MP4Structs.h" #include @@ -57,151 +58,154 @@ public GetTypeAsString() - returns the type as something the user can read*/ + class AtomBase; + typedef AtomBase* AtomBasePtr; typedef std::vector AtomArray; + class AtomBase { - /* - This is the basic or standard atom. It contains data describing some aspect of the file/stream - */ - private: - off_t streamOffset; - off_t atomOffset; - uint32 atomType; - uint64 atomSize; - char fourcc[5]; // make this an alias to atomType - AtomBase *parentAtom; + off_t streamOffset; + off_t atomOffset; + uint32 atomType; + uint64 atomSize; + char fourcc[5]; // make this an alias to atomType + AtomBase* parentAtom; protected: - BPositionIO *theStream; - void Indent(uint32 pindent); - + BPositionIO *theStream; + void Indent(uint32 pindent); + public: - AtomBase(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize); - virtual ~AtomBase(); + AtomBase(BPositionIO *pStream, off_t pstreamOffset, + uint32 patomType, uint64 patomSize); + virtual ~AtomBase(); - virtual bool IsContainer() {return false;}; + virtual bool IsContainer() {return false;}; - virtual BPositionIO *OnGetStream(); - BPositionIO *GetStream(); + virtual BPositionIO *OnGetStream(); + BPositionIO *GetStream(); - bool IsExtended() {return false;}; - bool IsEndOfAtom() {return (GetStream()->Position() >= off_t(streamOffset + atomSize));}; + bool IsExtended() {return false;}; + bool IsEndOfAtom() {return (GetStream()->Position() >= + off_t(streamOffset + atomSize));}; // Is this a known atom type - bool IsKnown(); + bool IsKnown(); - virtual void DisplayAtoms(uint32 pindent); + virtual void DisplayAtoms(uint32 pindent); - uint64 GetAtomSize() {return atomSize;}; - uint32 GetAtomType() {return atomType;}; - char *GetAtomTypeAsFourcc(); - off_t GetAtomOffset() { return atomOffset; }; - off_t GetStreamOffset() { return streamOffset; }; + uint64 GetAtomSize() {return atomSize;}; + uint32 GetAtomType() {return atomType;}; + char* GetAtomTypeAsFourcc(); + off_t GetAtomOffset() { return atomOffset; }; + off_t GetStreamOffset() { return streamOffset; }; - uint64 GetDataSize() { return atomSize - 8;}; + uint64 GetDataSize() { return atomSize - 8;}; - uint64 GetBytesRemaining(); + uint64 GetBytesRemaining(); - bool IsType(uint32 patomType) { return patomType == atomType; }; + bool IsType(uint32 patomType) { return patomType == atomType; }; - void SetAtomOffset(off_t patomOffset) { atomOffset = patomOffset; }; - void SetStreamOffset(off_t pstreamOffset) { streamOffset = pstreamOffset; }; + void SetAtomOffset(off_t patomOffset) { atomOffset = patomOffset; }; + void SetStreamOffset(off_t pstreamOffset) { streamOffset = pstreamOffset; }; - char *GetAtomName(); + const char *GetAtomName(); - virtual char *OnGetAtomName(); + virtual const char *OnGetAtomName(); // ProcessMetaData() - Reads in the basic Atom Meta Data // - Calls OnProcessMetaData() - virtual void ProcessMetaData(); + virtual void ProcessMetaData(); // OnProcessMetaData() - Subclass override to read/set meta data - virtual void OnProcessMetaData(); + virtual void OnProcessMetaData(); // Move stream ptr to where atom ends in stream (return false on failure) - bool MoveToEnd(); + bool MoveToEnd(); - void DisplayAtoms(); + void DisplayAtoms(); // Many atoms use an array header - void ReadArrayHeader(array_header *pHeader); + void ReadArrayHeader(array_header *pHeader); - void SetParent(AtomBase *pParent) {parentAtom = pParent;}; - AtomBase *GetParent() { return parentAtom;}; + void SetParent(AtomBase *pParent) {parentAtom = pParent;}; + AtomBase* GetParent() { return parentAtom;}; - void Read(uint64 *value); - void Read(uint32 *value); - void Read(int32 *value); - void Read(uint16 *value); - void Read(uint8 *value); - void Read(char *value, uint32 maxread); - void Read(uint8 *value, uint32 maxread); + void Read(uint64 *value); + void Read(uint32 *value); + void Read(int32 *value); + void Read(uint16 *value); + void Read(uint8 *value); + void Read(char *value, uint32 maxread); + void Read(uint8 *value, uint32 maxread); - uint64 GetBits(uint64 buffer, uint8 startBit, uint8 totalBits); - uint32 GetBits(uint32 buffer, uint8 startBit, uint8 totalBits); + uint64 GetBits(uint64 buffer, uint8 startBit, uint8 totalBits); + uint32 GetBits(uint32 buffer, uint8 startBit, uint8 totalBits); }; + class FullAtom : public AtomBase { public: - FullAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize); - virtual ~FullAtom(); + FullAtom(BPositionIO *pStream, off_t pstreamOffset, + uint32 patomType, uint64 patomSize); + virtual ~FullAtom(); + + virtual void OnProcessMetaData(); + uint8 GetVersion() {return Version;}; + uint8 GetFlags1() {return Flags1;}; + uint8 GetFlags2() {return Flags2;}; + uint8 GetFlags3() {return Flags3;}; - virtual void OnProcessMetaData(); - uint8 GetVersion() {return Version;}; - uint8 GetFlags1() {return Flags1;}; - uint8 GetFlags2() {return Flags2;}; - uint8 GetFlags3() {return Flags3;}; - private: - uint8 Version; - uint8 Flags1; - uint8 Flags2; - uint8 Flags3; + uint8 Version; + uint8 Flags1; + uint8 Flags2; + uint8 Flags3; }; + class AtomContainer : public AtomBase { - /* - This is an Atom that contains other atoms. It has children that may be Container Atoms or Standard Atoms - */ - private: - AtomArray atomChildren; - uint32 TotalChildren; + AtomArray atomChildren; + uint32 TotalChildren; - virtual void DisplayAtoms(uint32 pindent); + virtual void DisplayAtoms(uint32 pindent); public: - AtomContainer(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize); - virtual ~AtomContainer(); + AtomContainer(BPositionIO *pStream, off_t pstreamOffset, + uint32 patomType, uint64 patomSize); + virtual ~AtomContainer(); - virtual bool IsContainer() {return true;}; - AtomBase *GetChildAtom(uint32 patomType, uint32 offset=0); - uint32 CountChildAtoms(uint32 patomType); + virtual bool IsContainer() {return true;}; + AtomBase *GetChildAtom(uint32 patomType, uint32 offset=0); + uint32 CountChildAtoms(uint32 patomType); // ProcessMetaData() - Reads in the basic Atom Meta Data // - Calls OnProcessMetaData() // - Calls ProcessMetaData on each child atom // (ensures stream is correct for child via offset) - virtual void ProcessMetaData(); + virtual void ProcessMetaData(); // Add a atom to the children array (return false on failure) - bool AddChild(AtomBase *pChildAtom); + bool AddChild(AtomBase *pChildAtom); // OnProcessMetaData() - Subclass override to read/set meta data - virtual void OnProcessMetaData(); - virtual void OnChildProcessingComplete() {}; + virtual void OnProcessMetaData(); + virtual void OnChildProcessingComplete() {}; }; + extern AtomBase *GetAtom(BPositionIO *pStream); + #endif // _MP4_ATOM_H diff --git a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp index 2843e472f6..235a97cb75 100644 --- a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp +++ b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.cpp @@ -22,19 +22,23 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ + + +#include "MP4Parser.h" + #include #include -#include #include +#include #include -#include "MP4Parser.h" #include "BitParser.h" -//static -AtomBase *GetAtom(BPositionIO *pStream) + +AtomBase * +GetAtom(BPositionIO *pStream) { uint32 aAtomType; uint32 aAtomSize; @@ -62,193 +66,171 @@ AtomBase *GetAtom(BPositionIO *pStream) aRealAtomSize = aAtomSize; } - if (aAtomType == uint32('moov')) { + if (aAtomType == uint32('moov')) return new MOOVAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('mvhd')) { + if (aAtomType == uint32('mvhd')) return new MVHDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('trak')) { + if (aAtomType == uint32('trak')) return new TRAKAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('tkhd')) { + if (aAtomType == uint32('tkhd')) return new TKHDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('free')) { + if (aAtomType == uint32('free')) return new FREEAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('skip')) { + if (aAtomType == uint32('skip')) return new SKIPAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('wide')) { + if (aAtomType == uint32('wide')) return new WIDEAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('mdat')) { + if (aAtomType == uint32('mdat')) return new MDATAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('mdia')) { + if (aAtomType == uint32('mdia')) return new MDIAAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('mdhd')) { + if (aAtomType == uint32('mdhd')) return new MDHDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('hdlr')) { + if (aAtomType == uint32('hdlr')) return new HDLRAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('minf')) { + if (aAtomType == uint32('minf')) return new MINFAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('vmhd')) { + if (aAtomType == uint32('vmhd')) return new VMHDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('smhd')) { + if (aAtomType == uint32('smhd')) return new SMHDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('dinf')) { + if (aAtomType == uint32('dinf')) return new DINFAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stbl')) { + if (aAtomType == uint32('stbl')) return new STBLAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stsd')) { + if (aAtomType == uint32('stsd')) return new STSDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('tmcd')) { + if (aAtomType == uint32('tmcd')) return new TMCDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stts')) { + if (aAtomType == uint32('stts')) return new STTSAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('pnot')) { + if (aAtomType == uint32('pnot')) return new PNOTAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stsc')) { + if (aAtomType == uint32('stsc')) return new STSCAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stco')) { + if (aAtomType == uint32('stco')) return new STCOAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stss')) { + if (aAtomType == uint32('stss')) return new STSSAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('ctts')) { + if (aAtomType == uint32('ctts')) return new CTTSAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stsz')) { + if (aAtomType == uint32('stsz')) return new STSZAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('stz2')) { + if (aAtomType == uint32('stz2')) return new STZ2Atom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('ftyp')) { + if (aAtomType == uint32('ftyp')) return new FTYPAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('cmov')) { + if (aAtomType == uint32('cmov')) return new CMOVAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('dcom')) { + if (aAtomType == uint32('dcom')) return new DCOMAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('cmvd')) { + if (aAtomType == uint32('cmvd')) return new CMVDAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('esds')) { + if (aAtomType == uint32('esds')) return new ESDSAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('alac')) { + if (aAtomType == uint32('alac')) return new ALACAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('wave')) { + if (aAtomType == uint32('wave')) return new WAVEAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('dac3')) { + if (aAtomType == uint32('dac3')) return new DAC3Atom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('dec3')) { + if (aAtomType == uint32('dec3')) return new DEC3Atom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } - if (aAtomType == uint32('avcC')) { - return new DecoderConfigAtom(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } + if (aAtomType == uint32('avcC')) + return new DecoderConfigAtom(pStream, aStreamOffset, aAtomType, + aRealAtomSize); return new AtomBase(pStream, aStreamOffset, aAtomType, aRealAtomSize); - } -MOOVAtom::MOOVAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) + +MOOVAtom::MOOVAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, + pAtomSize) { theMVHDAtom = NULL; } + MOOVAtom::~MOOVAtom() { theMVHDAtom = NULL; } -void MOOVAtom::OnProcessMetaData() + +void +MOOVAtom::OnProcessMetaData() { } -char *MOOVAtom::OnGetAtomName() +const char * +MOOVAtom::OnGetAtomName() { return "MPEG-4 Movie"; } -CMOVAtom::CMOVAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) + +CMOVAtom::CMOVAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, + pAtomSize) { theUncompressedStream = NULL; } + CMOVAtom::~CMOVAtom() { } -BPositionIO *CMOVAtom::OnGetStream() + +BPositionIO * +CMOVAtom::OnGetStream() { // Use the decompressed stream instead of file stream - if (theUncompressedStream) { + if (theUncompressedStream) return theUncompressedStream; - } return theStream; } -void CMOVAtom::OnProcessMetaData() + +void +CMOVAtom::OnProcessMetaData() { BMallocIO *theUncompressedData; uint8 *outBuffer; @@ -327,7 +309,9 @@ void CMOVAtom::OnProcessMetaData() } -void CMOVAtom::OnChildProcessingComplete() + +void +CMOVAtom::OnChildProcessingComplete() { // revert back to file stream once all children have finished if (theUncompressedStream) { @@ -336,44 +320,61 @@ void CMOVAtom::OnChildProcessingComplete() theUncompressedStream = NULL; } -char *CMOVAtom::OnGetAtomName() + +const char * +CMOVAtom::OnGetAtomName() { return "Compressed MPEG-4 Movie"; } -DCOMAtom::DCOMAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +DCOMAtom::DCOMAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + DCOMAtom::~DCOMAtom() { } -void DCOMAtom::OnProcessMetaData() + +void +DCOMAtom::OnProcessMetaData() { Read(&compressionID); } -char *DCOMAtom::OnGetAtomName() + +const char * +DCOMAtom::OnGetAtomName() { return "Decompression Atom"; } -CMVDAtom::CMVDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +CMVDAtom::CMVDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { Buffer = NULL; UncompressedSize = 0; BufferSize = 0; } + CMVDAtom::~CMVDAtom() { - if (Buffer) { + if (Buffer) free(Buffer); - } } -void CMVDAtom::OnProcessMetaData() + +void +CMVDAtom::OnProcessMetaData() { Read(&UncompressedSize); @@ -384,20 +385,29 @@ void CMVDAtom::OnProcessMetaData() } } -char *CMVDAtom::OnGetAtomName() + +const char * +CMVDAtom::OnGetAtomName() { return "Compressed Movie Data"; } -MVHDAtom::MVHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +MVHDAtom::MVHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + MVHDAtom::~MVHDAtom() { } -void MVHDAtom::OnProcessMetaData() + +void +MVHDAtom::OnProcessMetaData() { FullAtom::OnProcessMetaData(); @@ -452,14 +462,18 @@ void MVHDAtom::OnProcessMetaData() } } -char *MVHDAtom::OnGetAtomName() + +const char * +MVHDAtom::OnGetAtomName() { return "MPEG-4 Movie Header"; } -MVHDAtom *MOOVAtom::GetMVHDAtom() + +MVHDAtom * +MOOVAtom::GetMVHDAtom() { -AtomBase *aAtomBase; + AtomBase *aAtomBase; if (theMVHDAtom == NULL) { aAtomBase = GetChildAtom(uint32('mvhd')); @@ -470,13 +484,18 @@ AtomBase *aAtomBase; return theMVHDAtom; } -STTSAtom::STTSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +STTSAtom::STTSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { theHeader.NoEntries = 0; SUMDurations = 0; SUMCounts = 0; } + STTSAtom::~STTSAtom() { for (uint32 i=0;iDuration); theTimeToSampleArray[i] = aTimeToSample; - SUMDurations += (theTimeToSampleArray[i]->Duration * theTimeToSampleArray[i]->Count); + SUMDurations += (theTimeToSampleArray[i]->Duration + * theTimeToSampleArray[i]->Count); SUMCounts += theTimeToSampleArray[i]->Count; } } -char *STTSAtom::OnGetAtomName() + +const char * +STTSAtom::OnGetAtomName() { return "Time to Sample Atom"; } -uint32 STTSAtom::GetSampleForTime(bigtime_t pTime) + +uint32 +STTSAtom::GetSampleForTime(bigtime_t pTime) { // Sample for time is this calc, how does STTS help us? return uint32((pTime * FrameRate + 50) / 1000000.0); - // TODO this is too slow. PreCalc when loading this? /* bigtime_t TotalDuration = 0; uint64 TotalCount = 0; for (uint32 i=0;iDuration * theTimeToSampleArray[i]->Count); + TotalDuration += (theTimeToSampleArray[i]->Duration + * theTimeToSampleArray[i]->Count); TotalCount += theTimeToSampleArray[i]->Count; if ((TotalDuration * 44100) > pTime) { return uint32((pTime * FrameRate + 50) / 1000000.0); } } - return 0; */ + return 0; +*/ } -uint32 STTSAtom::GetSampleForFrame(uint32 pFrame) + +uint32 +STTSAtom::GetSampleForFrame(uint32 pFrame) { // Convert frame to time and call GetSampleForTime() return pFrame; } -CTTSAtom::CTTSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +CTTSAtom::CTTSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { theHeader.NoEntries = 0; } + CTTSAtom::~CTTSAtom() { for (uint32 i=0;iFirstChunk > pChunkID) { @@ -630,30 +679,37 @@ uint32 STSCAtom::GetNoSamplesInChunk(uint32 pChunkID) return theSampleToChunkArray[theHeader.NoEntries-1]->SamplesPerChunk; } -uint32 STSCAtom::GetFirstSampleInChunk(uint32 pChunkID) + +uint32 +STSCAtom::GetFirstSampleInChunk(uint32 pChunkID) { -uint32 Diff; + uint32 Diff; for (uint32 i=0;iFirstChunk > pChunkID) { Diff = pChunkID - theSampleToChunkArray[i-1]->FirstChunk; - return ((Diff * theSampleToChunkArray[i-1]->SamplesPerChunk) + theSampleToChunkArray[i-1]->TotalPrevSamples); + return ((Diff * theSampleToChunkArray[i-1]->SamplesPerChunk) + + theSampleToChunkArray[i-1]->TotalPrevSamples); } } Diff = pChunkID - theSampleToChunkArray[theHeader.NoEntries-1]->FirstChunk; - return ((Diff * theSampleToChunkArray[theHeader.NoEntries-1]->SamplesPerChunk) + theSampleToChunkArray[theHeader.NoEntries-1]->TotalPrevSamples); + return Diff * theSampleToChunkArray[theHeader.NoEntries-1]->SamplesPerChunk + + theSampleToChunkArray[theHeader.NoEntries-1]->TotalPrevSamples; } -uint32 STSCAtom::GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) + +uint32 +STSCAtom::GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) { uint32 ChunkID = 0; for (int32 i=theHeader.NoEntries-1;i>=0;i--) { if (pSample >= theSampleToChunkArray[i]->TotalPrevSamples) { // Found chunk now calculate offset - ChunkID = ((pSample - theSampleToChunkArray[i]->TotalPrevSamples) / theSampleToChunkArray[i]->SamplesPerChunk) - + theSampleToChunkArray[i]->FirstChunk; + ChunkID = ((pSample - theSampleToChunkArray[i]->TotalPrevSamples) + / theSampleToChunkArray[i]->SamplesPerChunk) + + theSampleToChunkArray[i]->FirstChunk; *pOffsetInChunk = (pSample - theSampleToChunkArray[i]->TotalPrevSamples) % theSampleToChunkArray[i]->SamplesPerChunk; @@ -665,11 +721,16 @@ uint32 STSCAtom::GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) return theSampleToChunkArray[theHeader.NoEntries-1]->FirstChunk; } -STSSAtom::STSSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +STSSAtom::STSSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { theHeader.NoEntries = 0; } + STSSAtom::~STSSAtom() { for (uint32 i=0;iSyncSampleNo); - aSyncSample->SyncSampleNo--; // First frame is 0 for haiku + aSyncSample->SyncSampleNo--; // First frame is 0 for haiku theSyncSampleArray.push_back(aSyncSample); } } -char *STSSAtom::OnGetAtomName() + +const char * +STSSAtom::OnGetAtomName() { return "Sync Sample Atom"; } -bool STSSAtom::IsSyncSample(uint32 pSampleNo) + +bool +STSSAtom::IsSyncSample(uint32 pSampleNo) { for (uint32 i=0;i 0) { // All samples are the same size @@ -772,16 +851,23 @@ uint32 STSZAtom::GetSizeForSample(uint32 pSampleNo) return 0; } -bool STSZAtom::IsSingleSampleSize() + +bool +STSZAtom::IsSingleSampleSize() { return (SampleSize > 0); } -STZ2Atom::STZ2Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +STZ2Atom::STZ2Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { SampleCount = 0; } + STZ2Atom::~STZ2Atom() { for (uint32 i=0;iEntrySize; } -bool STZ2Atom::IsSingleSampleSize() + +bool +STZ2Atom::IsSingleSampleSize() { return false; } -STCOAtom::STCOAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +STCOAtom::STCOAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { theHeader.NoEntries = 0; } + STCOAtom::~STCOAtom() { for (uint32 i=0;i 0) && (pChunkIndex <= theHeader.NoEntries)) { return theChunkToOffsetArray[pChunkIndex - 1]->Offset; } - #ifdef DEBUG - char msg[100]; sprintf(msg, "Bad Chunk ID %ld / %ld\n", pChunkIndex, theHeader.NoEntries); - DEBUGGER(msg); - #endif +#ifdef DEBUG + char msg[100]; sprintf(msg, "Bad Chunk ID %ld / %ld\n", pChunkIndex, + theHeader.NoEntries); + DEBUGGER(msg); +#endif TRESPASS(); return 0LL; } -DecoderConfigAtom::DecoderConfigAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +DecoderConfigAtom::DecoderConfigAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { theDecoderConfig = NULL; DecoderConfigSize = 0; } + DecoderConfigAtom::~DecoderConfigAtom() { if (theDecoderConfig) { @@ -945,6 +1058,7 @@ DecoderConfigAtom::~DecoderConfigAtom() } } + void DecoderConfigAtom::OnProcessMetaData() { DecoderConfigSize = GetBytesRemaining(); @@ -953,12 +1067,17 @@ void DecoderConfigAtom::OnProcessMetaData() Read(theDecoderConfig,DecoderConfigSize); } -uint8 *DecoderConfigAtom::GetDecoderConfig() + +uint8 * +DecoderConfigAtom::GetDecoderConfig() { return theDecoderConfig; } -bool DecoderConfigAtom::SkipTag(uint8 *ESDS, uint8 Tag, uint32 *offset) { + +bool +DecoderConfigAtom::SkipTag(uint8 *ESDS, uint8 Tag, uint32 *offset) +{ uint8 byte; byte = ESDS[(*offset)++]; @@ -971,7 +1090,6 @@ bool DecoderConfigAtom::SkipTag(uint8 *ESDS, uint8 Tag, uint32 *offset) { numBytes++; length = (length << 7) | (byte & 0x7F); } while ((byte & 0x80) && numBytes < 4); - } else { // go back Tag not found (*offset)--; @@ -981,12 +1099,16 @@ bool DecoderConfigAtom::SkipTag(uint8 *ESDS, uint8 Tag, uint32 *offset) { return true; } -char *DecoderConfigAtom::OnGetAtomName() + +const char * +DecoderConfigAtom::OnGetAtomName() { return "Decoder Config Atom - Unknown type"; } -void DecoderConfigAtom::OverrideAudioDescription(AudioDescription *pAudioDescription) + +void +DecoderConfigAtom::OverrideAudioDescription(AudioDescription *pAudioDescription) { if (pAudioDescription) { pAudioDescription->DecoderConfigSize = DecoderConfigSize; @@ -996,7 +1118,9 @@ void DecoderConfigAtom::OverrideAudioDescription(AudioDescription *pAudioDescrip } } -void DecoderConfigAtom::OverrideVideoDescription(VideoDescription *pVideoDescription) + +void +DecoderConfigAtom::OverrideVideoDescription(VideoDescription *pVideoDescription) { if (pVideoDescription) { pVideoDescription->DecoderConfigSize = DecoderConfigSize; @@ -1006,15 +1130,22 @@ void DecoderConfigAtom::OverrideVideoDescription(VideoDescription *pVideoDescrip } } -ESDSAtom::ESDSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +ESDSAtom::ESDSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + ESDSAtom::~ESDSAtom() { } -void ESDSAtom::OnProcessMetaData() + +void +ESDSAtom::OnProcessMetaData() { // Read 4 bytes because this is really a FullAtom uint32 version; @@ -1022,12 +1153,15 @@ void ESDSAtom::OnProcessMetaData() DecoderConfigAtom::OnProcessMetaData(); } -char *ESDSAtom::OnGetAtomName() + +const char * +ESDSAtom::OnGetAtomName() { return "Extended Sample Description Atom"; } -char *obj_type_names[]= + +const char * obj_type_names[]= { "Unknown", "Main-AAC", @@ -1038,13 +1172,16 @@ char *obj_type_names[]= "HE-AAC(disabled)" }; + int aac_sampling_rate[16] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, 0, 0, 0 }; -void ESDSAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) + +void +ESDSAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) { // decode for aac and check for HE-AAC which uses a framesize of 2048 // also check for MP3 which has an ESDS @@ -1058,7 +1195,8 @@ void ESDSAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) } if (SkipTag(pAudioDescription->theDecoderConfig, 0x04, &offset)) { - parser.Init(&pAudioDescription->theDecoderConfig[offset], (pAudioDescription->DecoderConfigSize-offset) * 8); + parser.Init(&pAudioDescription->theDecoderConfig[offset], + (pAudioDescription->DecoderConfigSize - offset) * 8); ESDSType = parser.GetValue(8); StreamType = parser.GetValue(6); @@ -1082,46 +1220,50 @@ void ESDSAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) switch (ESDSType) { case 64: // AAC so use AAC Header details to override ESDS values - parser.Init(&pAudioDescription->theDecoderConfig[offset], (pAudioDescription->DecoderConfigSize-offset) * 8); - - // 5 bits are decoder type - theAACHeader.objTypeIndex = parser.GetValue(5); - if (theAACHeader.objTypeIndex == 31) { - theAACHeader.objTypeIndex = 32 + parser.GetValue(6); - } - // 4 bits are frequency index - theAACHeader.sampleRateIndex = parser.GetValue(4); - if (theAACHeader.sampleRateIndex == 15) { - // Direct encoding of SampleRate - SampleRate = parser.GetValue(24); - } else { - SampleRate = aac_sampling_rate[theAACHeader.sampleRateIndex]; - } + parser.Init(&pAudioDescription->theDecoderConfig[offset], + (pAudioDescription->DecoderConfigSize - offset) * 8); - // 4 bits are channels - theAACHeader.totalChannels = parser.GetValue(4); - // 1 bit determines small frame size - smallFrameSize = (parser.GetValue(1) == 1); - - if (theAACHeader.objTypeIndex < 3) { - pAudioDescription->codecSubType = 'mp4a'; - pAudioDescription->FrameSize = 1024; - if (smallFrameSize) { - pAudioDescription->FrameSize = 960; + // 5 bits are decoder type + theAACHeader.objTypeIndex = parser.GetValue(5); + if (theAACHeader.objTypeIndex == 31) { + theAACHeader.objTypeIndex = 32 + parser.GetValue(6); + } + // 4 bits are frequency index + theAACHeader.sampleRateIndex = parser.GetValue(4); + if (theAACHeader.sampleRateIndex == 15) { + // Direct encoding of SampleRate + SampleRate = parser.GetValue(24); + } else { + SampleRate = aac_sampling_rate[theAACHeader.sampleRateIndex]; + } + + // 4 bits are channels + theAACHeader.totalChannels = parser.GetValue(4); + // 1 bit determines small frame size + smallFrameSize = (parser.GetValue(1) == 1); + + if (theAACHeader.objTypeIndex < 3) { + pAudioDescription->codecSubType = 'mp4a'; + pAudioDescription->FrameSize = 1024; + if (smallFrameSize) { + pAudioDescription->FrameSize = 960; + } + } else { + pAudioDescription->codecSubType = 'haac'; + pAudioDescription->FrameSize = 2048; } - } else { - pAudioDescription->codecSubType = 'haac'; - pAudioDescription->FrameSize = 2048; - } - // Override STSD - pAudioDescription->theAudioSampleEntry.SampleRate = SampleRate; - pAudioDescription->theAudioSampleEntry.ChannelCount = theAACHeader.totalChannels; + // Override STSD + pAudioDescription->theAudioSampleEntry.SampleRate = SampleRate; + pAudioDescription->theAudioSampleEntry.ChannelCount = + theAACHeader.totalChannels; - // Reset decoder Config memory - memcpy(pAudioDescription->theDecoderConfig, &pAudioDescription->theDecoderConfig[extendedAudioConfig], pAudioDescription->DecoderConfigSize-extendedAudioConfig+1); + // Reset decoder Config memory + memcpy(pAudioDescription->theDecoderConfig, + &pAudioDescription->theDecoderConfig[extendedAudioConfig], + pAudioDescription->DecoderConfigSize - extendedAudioConfig + 1); - break; + break; case 107: // MP3 pAudioDescription->codecSubType = '.mp3'; @@ -1135,128 +1277,185 @@ void ESDSAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) } } -void ESDSAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) + +void +ESDSAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) { // Nothing to override } -ALACAtom::ALACAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +ALACAtom::ALACAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + ALACAtom::~ALACAtom() { } -void ALACAtom::OnProcessMetaData() + +void +ALACAtom::OnProcessMetaData() { DecoderConfigAtom::OnProcessMetaData(); } -char *ALACAtom::OnGetAtomName() + +const char * +ALACAtom::OnGetAtomName() { return "ALAC Decoder Config Atom"; } -void ALACAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) + +void +ALACAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) { pAudioDescription->codecSubType = 'alac'; pAudioDescription->FrameSize = 4096; } -void ALACAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) + +void +ALACAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) { // Nothing to override } -WAVEAtom::WAVEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +WAVEAtom::WAVEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + WAVEAtom::~WAVEAtom() { } -void WAVEAtom::OnProcessMetaData() + +void +WAVEAtom::OnProcessMetaData() { } -char *WAVEAtom::OnGetAtomName() + +const char * +WAVEAtom::OnGetAtomName() { return "WAVE Decoder Config Atom"; } -void WAVEAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) + +void +WAVEAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) { pAudioDescription->codecSubType = '.mp3'; pAudioDescription->FrameSize = 1; } -void WAVEAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) + +void +WAVEAtom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) { // Nothing to override } -DAC3Atom::DAC3Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +DAC3Atom::DAC3Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + DAC3Atom::~DAC3Atom() { } -void DAC3Atom::OnProcessMetaData() + +void +DAC3Atom::OnProcessMetaData() { DecoderConfigAtom::OnProcessMetaData(); } -void DAC3Atom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) + +void +DAC3Atom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) { pAudioDescription->codecSubType = 'dac3'; pAudioDescription->FrameSize = 1536; } -void DAC3Atom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) + +void +DAC3Atom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) { // Nothing to override } -char *DAC3Atom::OnGetAtomName() + +const char * +DAC3Atom::OnGetAtomName() { return "Digital AC3"; } -DEC3Atom::DEC3Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +DEC3Atom::DEC3Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + DecoderConfigAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + DEC3Atom::~DEC3Atom() { } -void DEC3Atom::OnProcessMetaData() + +void +DEC3Atom::OnProcessMetaData() { DecoderConfigAtom::OnProcessMetaData(); } -void DEC3Atom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) + +void +DEC3Atom::OnOverrideAudioDescription(AudioDescription *pAudioDescription) { pAudioDescription->codecSubType = 'dec3'; pAudioDescription->FrameSize = 1536; } -void DEC3Atom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) + +void +DEC3Atom::OnOverrideVideoDescription(VideoDescription *pVideoDescription) { // Nothing to override } -char *DEC3Atom::OnGetAtomName() + +const char * +DEC3Atom::OnGetAtomName() { return "Digital EAC3"; } -STSDAtom::STSDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) +STSDAtom::STSDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { theHeader.NoEntries = 0; theAudioDescription.codecid = 0; @@ -1268,6 +1467,7 @@ STSDAtom::STSDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, theVideoDescription.theDecoderConfig = NULL; } + STSDAtom::~STSDAtom() { if (theAudioDescription.theDecoderConfig) { @@ -1281,17 +1481,23 @@ STSDAtom::~STSDAtom() } } -uint32 STSDAtom::GetMediaHandlerType() + +uint32 +STSDAtom::GetMediaHandlerType() { return dynamic_cast(GetParent())->GetMediaHandlerType(); } -void STSDAtom::ReadDecoderConfig(uint8 **pDecoderConfig, size_t *pDecoderConfigSize, AudioDescription *pAudioDescription, VideoDescription *pVideoDescription) + +void +STSDAtom::ReadDecoderConfig(uint8 **pDecoderConfig, size_t *pDecoderConfigSize, + AudioDescription *pAudioDescription, VideoDescription *pVideoDescription) { // Check for a Decoder Config and if it exists copy it back to the caller - // MPEG-4 video/audio use the various decoder config structures to pass additional - // decoder information to the decoder. The extractor sometimes needs to decode the data - // to work out how to properly construct the decoder + // MPEG-4 video/audio use the various decoder config structures to pass + // additional decoder information to the decoder. The extractor sometimes + // needs to decode the data to work out how to properly construct the + // decoder // First make sure we have a something if (GetBytesRemaining() > 0) { @@ -1303,7 +1509,8 @@ void STSDAtom::ReadDecoderConfig(uint8 **pDecoderConfig, size_t *pDecoderConfigS if (dynamic_cast(aAtomBase)) { // DecoderConfig atom good - DecoderConfigAtom *aDecoderConfigAtom = dynamic_cast(aAtomBase); + DecoderConfigAtom *aDecoderConfigAtom = + dynamic_cast(aAtomBase); aDecoderConfigAtom->OverrideAudioDescription(pAudioDescription); aDecoderConfigAtom->OverrideVideoDescription(pVideoDescription); @@ -1316,7 +1523,9 @@ void STSDAtom::ReadDecoderConfig(uint8 **pDecoderConfig, size_t *pDecoderConfigS } } -void STSDAtom::ReadSoundDescription() + +void +STSDAtom::ReadSoundDescription() { Read(&theAudioDescription.theAudioSampleEntry.Reserved[1]); Read(&theAudioDescription.theAudioSampleEntry.Reserved[2]); @@ -1326,12 +1535,17 @@ void STSDAtom::ReadSoundDescription() Read(&theAudioDescription.theAudioSampleEntry.reserved); Read(&theAudioDescription.theAudioSampleEntry.SampleRate); - theAudioDescription.theAudioSampleEntry.SampleRate = theAudioDescription.theAudioSampleEntry.SampleRate / 65536; // Convert from fixed point decimal to float + theAudioDescription.theAudioSampleEntry.SampleRate = + theAudioDescription.theAudioSampleEntry.SampleRate / 65536; + // Convert from fixed point decimal to float - ReadDecoderConfig(&theAudioDescription.theDecoderConfig, &theAudioDescription.DecoderConfigSize, &theAudioDescription, NULL); + ReadDecoderConfig(&theAudioDescription.theDecoderConfig, + &theAudioDescription.DecoderConfigSize, &theAudioDescription, NULL); } -void STSDAtom::ReadVideoDescription() + +void +STSDAtom::ReadVideoDescription() { Read(&theVideoDescription.theVideoSampleEntry.pre_defined1); Read(&theVideoDescription.theVideoSampleEntry.reserved1); @@ -1350,9 +1564,11 @@ void STSDAtom::ReadVideoDescription() // convert from pascal string (first bytes size) to C string (null terminated) uint8 size = (uint8)(theVideoDescription.theVideoSampleEntry.CompressorName[0]); if (size > 0 && size < 32) { - memmove(&theVideoDescription.theVideoSampleEntry.CompressorName[0],&theVideoDescription.theVideoSampleEntry.CompressorName[1],size); + memmove(&theVideoDescription.theVideoSampleEntry.CompressorName[0], + &theVideoDescription.theVideoSampleEntry.CompressorName[1],size); theVideoDescription.theVideoSampleEntry.CompressorName[size] = '\0'; - printf("Compressed using %s\n",theVideoDescription.theVideoSampleEntry.CompressorName); + printf("Compressed using %s\n", + theVideoDescription.theVideoSampleEntry.CompressorName); } Read(&theVideoDescription.theVideoSampleEntry.Depth); @@ -1361,9 +1577,10 @@ void STSDAtom::ReadVideoDescription() ReadDecoderConfig(&theVideoDescription.theDecoderConfig, &theVideoDescription.DecoderConfigSize, NULL, &theVideoDescription); } -void STSDAtom::OnProcessMetaData() -{ +void +STSDAtom::OnProcessMetaData() +{ FullAtom::OnProcessMetaData(); ReadArrayHeader(&theHeader); @@ -1396,67 +1613,97 @@ void STSDAtom::OnProcessMetaData() } } -VideoDescription STSDAtom::GetAsVideo() + +VideoDescription +STSDAtom::GetAsVideo() { // Assert IsVideo return theVideoDescription; } + AudioDescription STSDAtom::GetAsAudio() { // Assert IsAudio return theAudioDescription; } -char *STSDAtom::OnGetAtomName() + +const char * +STSDAtom::OnGetAtomName() { return "Sample Description Atom"; } -TMCDAtom::TMCDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +TMCDAtom::TMCDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + TMCDAtom::~TMCDAtom() { } -void TMCDAtom::OnProcessMetaData() + +void +TMCDAtom::OnProcessMetaData() { } -char *TMCDAtom::OnGetAtomName() + +const char * +TMCDAtom::OnGetAtomName() { return "TimeCode Atom"; } -WIDEAtom::WIDEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +WIDEAtom::WIDEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + WIDEAtom::~WIDEAtom() { } -void WIDEAtom::OnProcessMetaData() + +void +WIDEAtom::OnProcessMetaData() { } -char *WIDEAtom::OnGetAtomName() + +const char * +WIDEAtom::OnGetAtomName() { return "WIDE Atom"; } -FTYPAtom::FTYPAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +FTYPAtom::FTYPAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { total_brands = 0; } + FTYPAtom::~FTYPAtom() { } -void FTYPAtom::OnProcessMetaData() + +void +FTYPAtom::OnProcessMetaData() { Read(&major_brand); Read(&minor_version); @@ -1473,12 +1720,15 @@ void FTYPAtom::OnProcessMetaData() } -char *FTYPAtom::OnGetAtomName() + +const char * +FTYPAtom::OnGetAtomName() { return "File type Atom"; } -bool FTYPAtom::HasBrand(uint32 brand) +bool +FTYPAtom::HasBrand(uint32 brand) { if (major_brand == brand) { @@ -1495,149 +1745,225 @@ bool FTYPAtom::HasBrand(uint32 brand) return false; } -FREEAtom::FREEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +FREEAtom::FREEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + FREEAtom::~FREEAtom() { } -void FREEAtom::OnProcessMetaData() + +void +FREEAtom::OnProcessMetaData() { } -char *FREEAtom::OnGetAtomName() + +const char * +FREEAtom::OnGetAtomName() { return "Free Atom"; } -PNOTAtom::PNOTAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +PNOTAtom::PNOTAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + PNOTAtom::~PNOTAtom() { } -void PNOTAtom::OnProcessMetaData() + +void +PNOTAtom::OnProcessMetaData() { } -char *PNOTAtom::OnGetAtomName() + +const char * +PNOTAtom::OnGetAtomName() { return "Preview Atom"; } -SKIPAtom::SKIPAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +SKIPAtom::SKIPAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + SKIPAtom::~SKIPAtom() { } -void SKIPAtom::OnProcessMetaData() + +void +SKIPAtom::OnProcessMetaData() { } -char *SKIPAtom::OnGetAtomName() + +const char * +SKIPAtom::OnGetAtomName() { return "Skip Atom"; } -MDATAtom::MDATAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) + +MDATAtom::MDATAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomBase(pStream, pStreamOffset, pAtomType, pAtomSize) { } + MDATAtom::~MDATAtom() { } -void MDATAtom::OnProcessMetaData() + +void +MDATAtom::OnProcessMetaData() { } -char *MDATAtom::OnGetAtomName() + +const char * +MDATAtom::OnGetAtomName() { return "Media Data Atom"; } -off_t MDATAtom::GetEOF() + +off_t +MDATAtom::GetEOF() { return GetAtomOffset() + GetAtomSize() - 8; } -MINFAtom::MINFAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) + +MINFAtom::MINFAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) { } + MINFAtom::~MINFAtom() { } -void MINFAtom::OnProcessMetaData() + +void +MINFAtom::OnProcessMetaData() { } -char *MINFAtom::OnGetAtomName() + +const char * +MINFAtom::OnGetAtomName() { return "MPEG-4 Media Information Atom"; } -uint32 MINFAtom::GetMediaHandlerType() + +uint32 +MINFAtom::GetMediaHandlerType() { return dynamic_cast(GetParent())->GetMediaHandlerType(); } -STBLAtom::STBLAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) + +STBLAtom::STBLAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) { } + STBLAtom::~STBLAtom() { } -void STBLAtom::OnProcessMetaData() + +void +STBLAtom::OnProcessMetaData() { } -char *STBLAtom::OnGetAtomName() + +const char * +STBLAtom::OnGetAtomName() { return "MPEG-4 Sample Table Atom"; } -uint32 STBLAtom::GetMediaHandlerType() + +uint32 +STBLAtom::GetMediaHandlerType() { return dynamic_cast(GetParent())->GetMediaHandlerType(); } -DINFAtom::DINFAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) + +DINFAtom::DINFAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) { } + DINFAtom::~DINFAtom() { } -void DINFAtom::OnProcessMetaData() + +void +DINFAtom::OnProcessMetaData() { } -char *DINFAtom::OnGetAtomName() + +const char * +DINFAtom::OnGetAtomName() { return "MPEG-4 Data Information Atom"; } -TKHDAtom::TKHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +TKHDAtom::TKHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + TKHDAtom::~TKHDAtom() { } -void TKHDAtom::OnProcessMetaData() + +void +TKHDAtom::OnProcessMetaData() { FullAtom::OnProcessMetaData(); @@ -1674,7 +2000,6 @@ void TKHDAtom::OnProcessMetaData() theHeader.Volume = aHeaderV0.Volume; theHeader.TrackWidth = aHeaderV0.TrackWidth; theHeader.TrackHeight = aHeaderV0.TrackHeight; - } else { Read(&theHeader.CreationTime); Read(&theHeader.ModificationTime); @@ -1688,39 +2013,50 @@ void TKHDAtom::OnProcessMetaData() Read(&theHeader.Volume); Read(&theHeader.Reserved3); - for (uint32 i=0;i<9;i++) { + for (uint32 i=0;i<9;i++) Read(&theHeader.MatrixStructure[i]); - } Read(&theHeader.TrackWidth); Read(&theHeader.TrackHeight); } - } -char *TKHDAtom::OnGetAtomName() + +const char * +TKHDAtom::OnGetAtomName() { return "MPEG-4 Track Header"; } -MDIAAtom::MDIAAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) + +MDIAAtom::MDIAAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + AtomContainer(pStream, pStreamOffset, pAtomType, pAtomSize) { } + MDIAAtom::~MDIAAtom() { } -void MDIAAtom::OnProcessMetaData() + +void +MDIAAtom::OnProcessMetaData() { } -char *MDIAAtom::OnGetAtomName() + +const char * +MDIAAtom::OnGetAtomName() { return "MPEG-4 Media Atom"; } -uint32 MDIAAtom::GetMediaHandlerType() + +uint32 +MDIAAtom::GetMediaHandlerType() { // Get child atom hdlr HDLRAtom *aHDLRAtom; @@ -1733,15 +2069,22 @@ uint32 MDIAAtom::GetMediaHandlerType() return 0; } -MDHDAtom::MDHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +MDHDAtom::MDHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + MDHDAtom::~MDHDAtom() { } -void MDHDAtom::OnProcessMetaData() + +void +MDHDAtom::OnProcessMetaData() { FullAtom::OnProcessMetaData(); @@ -1770,26 +2113,37 @@ void MDHDAtom::OnProcessMetaData() } } -char *MDHDAtom::OnGetAtomName() + +const char * +MDHDAtom::OnGetAtomName() { return "MPEG-4 Media Header"; } -bigtime_t MDHDAtom::GetDuration() + +bigtime_t +MDHDAtom::GetDuration() { return bigtime_t((theHeader.Duration * 1000000.0) / theHeader.TimeScale); } -uint32 MDHDAtom::GetTimeScale() + +uint32 +MDHDAtom::GetTimeScale() { return theHeader.TimeScale; } -HDLRAtom::HDLRAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +HDLRAtom::HDLRAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { name = NULL; } + HDLRAtom::~HDLRAtom() { if (name) { @@ -1797,7 +2151,9 @@ HDLRAtom::~HDLRAtom() } } -void HDLRAtom::OnProcessMetaData() + +void +HDLRAtom::OnProcessMetaData() { FullAtom::OnProcessMetaData(); @@ -1812,35 +2168,50 @@ void HDLRAtom::OnProcessMetaData() Read(name,GetBytesRemaining()); } -char *HDLRAtom::OnGetAtomName() + +const char * +HDLRAtom::OnGetAtomName() { return "MPEG-4 Handler Reference Atom "; } -bool HDLRAtom::IsVideoHandler() + +bool +HDLRAtom::IsVideoHandler() { return (theHeader.handler_type == 'vide'); } -bool HDLRAtom::IsAudioHandler() + +bool +HDLRAtom::IsAudioHandler() { return (theHeader.handler_type == 'soun'); } -uint32 HDLRAtom::GetMediaHandlerType() + +uint32 +HDLRAtom::GetMediaHandlerType() { return theHeader.handler_type; } -VMHDAtom::VMHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +VMHDAtom::VMHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + VMHDAtom::~VMHDAtom() { } -void VMHDAtom::OnProcessMetaData() + +void +VMHDAtom::OnProcessMetaData() { FullAtom::OnProcessMetaData(); @@ -1850,20 +2221,29 @@ void VMHDAtom::OnProcessMetaData() Read(&theHeader.OpColour[2]); } -char *VMHDAtom::OnGetAtomName() + +const char * +VMHDAtom::OnGetAtomName() { return "MPEG-4 Video Media Header"; } -SMHDAtom::SMHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize) : FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) + +SMHDAtom::SMHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize) + : + FullAtom(pStream, pStreamOffset, pAtomType, pAtomSize) { } + SMHDAtom::~SMHDAtom() { } -void SMHDAtom::OnProcessMetaData() + +void +SMHDAtom::OnProcessMetaData() { FullAtom::OnProcessMetaData(); @@ -1871,7 +2251,9 @@ void SMHDAtom::OnProcessMetaData() Read(&theHeader.Reserved); } -char *SMHDAtom::OnGetAtomName() + +const char * +SMHDAtom::OnGetAtomName() { return "MPEG-4 Sound Media Header"; } diff --git a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.h b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.h index 7a8ef9f7fa..bec95ef99b 100644 --- a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.h +++ b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4Parser.h @@ -25,6 +25,7 @@ #ifndef _MP4_PARSER_H #define _MP4_PARSER_H + #include #include #include @@ -35,6 +36,7 @@ #include "MP4Atom.h" + typedef CompTimeToSample* CompTimeToSamplePtr; typedef std::map > CompTimeToSampleArray; typedef TimeToSample* TimeToSamplePtr; @@ -48,556 +50,660 @@ typedef std::vector SyncSampleArray; typedef SampleSizeEntry* SampleSizePtr; typedef std::vector SampleSizeArray; + // Atom class for reading the movie header atom class MVHDAtom : public FullAtom { public: - MVHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~MVHDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - uint32 GetTimeScale() {return theHeader.TimeScale;}; - uint32 GetDuration() {return theHeader.Duration;}; + MVHDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~MVHDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + uint32 GetTimeScale() {return theHeader.TimeScale;}; + uint32 GetDuration() {return theHeader.Duration;}; + private: - mvhdV1 theHeader; + mvhdV1 theHeader; }; + // Atom class for reading the moov atom class MOOVAtom : public AtomContainer { public: - MOOVAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~MOOVAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + MOOVAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~MOOVAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - MVHDAtom *GetMVHDAtom(); + MVHDAtom* GetMVHDAtom(); + private: - MVHDAtom *theMVHDAtom; + MVHDAtom* theMVHDAtom; }; + // Atom class for reading the cmov atom class CMOVAtom : public AtomContainer { public: - CMOVAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~CMOVAtom(); + CMOVAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~CMOVAtom(); - BPositionIO *OnGetStream(); - void OnProcessMetaData(); - void OnChildProcessingComplete(); + BPositionIO *OnGetStream(); + void OnProcessMetaData(); + void OnChildProcessingComplete(); + + const char *OnGetAtomName(); - char *OnGetAtomName(); private: - BMallocIO *theUncompressedStream; + BMallocIO* theUncompressedStream; }; + // Atom class for reading the dcom atom class DCOMAtom : public AtomBase { public: - DCOMAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~DCOMAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - uint32 GetCompressionID() {return compressionID;}; + DCOMAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~DCOMAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + uint32 GetCompressionID() {return compressionID;}; + private: - uint32 compressionID; + uint32 compressionID; }; + // Atom class for reading the cmvd atom class CMVDAtom : public AtomBase { public: - CMVDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~CMVDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - uint32 GetUncompressedSize() {return UncompressedSize;}; - uint8 *GetCompressedData() {return Buffer;}; - uint32 GetBufferSize() {return BufferSize;}; + CMVDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~CMVDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + uint32 GetUncompressedSize() {return UncompressedSize;}; + uint8* GetCompressedData() {return Buffer;}; + uint32 GetBufferSize() {return BufferSize;}; + private: - uint32 UncompressedSize; - uint32 BufferSize; - uint8 *Buffer; + uint32 UncompressedSize; + uint32 BufferSize; + uint8* Buffer; }; + // Atom class for reading the ftyp atom class FTYPAtom : public AtomBase { public: - FTYPAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~FTYPAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + FTYPAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~FTYPAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - bool HasBrand(uint32 brand); + bool HasBrand(uint32 brand); + private: - uint32 major_brand; - uint32 minor_version; - uint32 compatable_brands[32]; // Should be infinite but we will settle for max 32 - uint32 total_brands; + uint32 major_brand; + uint32 minor_version; + uint32 compatable_brands[32]; + // Should be infinite but we will settle for max 32 + uint32 total_brands; }; + // Atom class for reading the wide atom class WIDEAtom : public AtomBase { public: - WIDEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~WIDEAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - + WIDEAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~WIDEAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); }; + // Atom class for reading the free atom class FREEAtom : public AtomBase { public: - FREEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~FREEAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - + FREEAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~FREEAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); }; + // Atom class for reading the preview atom class PNOTAtom : public AtomBase { public: - PNOTAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~PNOTAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + PNOTAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~PNOTAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); }; + // Atom class for reading the time to sample atom class STTSAtom : public FullAtom { public: - STTSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STTSAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - - uint64 GetSUMCounts() { return SUMCounts; }; - bigtime_t GetSUMDurations() { return SUMDurations; }; - uint32 GetSampleForTime(bigtime_t pTime); - uint32 GetSampleForFrame(uint32 pFrame); - void SetFrameRate(float pFrameRate) { FrameRate = pFrameRate; }; + STTSAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STTSAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + uint64 GetSUMCounts() { return SUMCounts; }; + bigtime_t GetSUMDurations() { return SUMDurations; }; + uint32 GetSampleForTime(bigtime_t pTime); + uint32 GetSampleForFrame(uint32 pFrame); + void SetFrameRate(float pFrameRate) + { FrameRate = pFrameRate; }; + private: - array_header theHeader; - TimeToSampleArray theTimeToSampleArray; - bigtime_t SUMDurations; - uint64 SUMCounts; - float FrameRate; + array_header theHeader; + TimeToSampleArray theTimeToSampleArray; + bigtime_t SUMDurations; + uint64 SUMCounts; + float FrameRate; }; + // Atom class for reading the composition time to sample atom class CTTSAtom : public FullAtom { public: - CTTSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~CTTSAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - + CTTSAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~CTTSAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + private: - array_header theHeader; - CompTimeToSampleArray theCompTimeToSampleArray; + array_header theHeader; + CompTimeToSampleArray theCompTimeToSampleArray; }; + // Atom class for reading the sample to chunk atom class STSCAtom : public FullAtom { public: - STSCAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STSCAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + STSCAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STSCAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint32 GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk); - uint32 GetFirstSampleInChunk(uint32 pChunkIndex); - uint32 GetNoSamplesInChunk(uint32 pChunkIndex); + uint32 GetChunkForSample(uint32 pSample, + uint32 *pOffsetInChunk); + uint32 GetFirstSampleInChunk(uint32 pChunkIndex); + uint32 GetNoSamplesInChunk(uint32 pChunkIndex); + private: array_header theHeader; SampleToChunkArray theSampleToChunkArray; }; + // Atom class for reading the chunk to offset atom class STCOAtom : public FullAtom { public: - STCOAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STCOAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + STCOAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STCOAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint64 GetOffsetForChunk(uint32 pChunkIndex); - uint32 GetTotalChunks() {return theHeader.NoEntries;}; + uint64 GetOffsetForChunk(uint32 pChunkIndex); + uint32 GetTotalChunks() {return theHeader.NoEntries;}; protected: // Read a single chunk offset from Stream - virtual uint64 OnGetChunkOffset(); + virtual uint64 OnGetChunkOffset(); private: - array_header theHeader; - ChunkToOffsetArray theChunkToOffsetArray; + array_header theHeader; + ChunkToOffsetArray theChunkToOffsetArray; }; + // Atom class for reading the sync sample atom class STSSAtom : public FullAtom { public: - STSSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STSSAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + STSSAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STSSAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - bool IsSyncSample(uint32 pSampleNo); + bool IsSyncSample(uint32 pSampleNo); + private: - array_header theHeader; - SyncSampleArray theSyncSampleArray; + array_header theHeader; + SyncSampleArray theSyncSampleArray; }; + // Atom class for reading the sample size atom class STSZAtom : public FullAtom { public: - STSZAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STSZAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + STSZAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STSZAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint32 GetSizeForSample(uint32 pSampleNo); - bool IsSingleSampleSize(); + uint32 GetSizeForSample(uint32 pSampleNo); + bool IsSingleSampleSize(); + private: - uint32 SampleSize; - uint32 SampleCount; - - SampleSizeArray theSampleSizeArray; + uint32 SampleSize; + uint32 SampleCount; + + SampleSizeArray theSampleSizeArray; }; + // Atom class for reading the sample size 2 atom class STZ2Atom : public FullAtom { public: - STZ2Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STZ2Atom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - - uint32 GetSizeForSample(uint32 pSampleNo); - bool IsSingleSampleSize(); + STZ2Atom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STZ2Atom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + + uint32 GetSizeForSample(uint32 pSampleNo); + bool IsSingleSampleSize(); private: - uint32 SampleSize; - uint32 SampleCount; - uint8 FieldSize; + uint32 SampleSize; + uint32 SampleCount; + uint8 FieldSize; - SampleSizeArray theSampleSizeArray; + SampleSizeArray theSampleSizeArray; }; + // Atom class for reading the skip atom class SKIPAtom : public AtomBase { public: - SKIPAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~SKIPAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - + SKIPAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~SKIPAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); }; + // Atom class for reading the media data atom class MDATAtom : public AtomBase { public: - MDATAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~MDATAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - off_t GetEOF(); + MDATAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~MDATAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + off_t GetEOF(); }; + // Subclass for handling special decoder config atoms like ESDS, ALAC, AVCC, AMR // ESDS is actually a FullAtom but others are not :-( class DecoderConfigAtom : public AtomBase { public: - DecoderConfigAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~DecoderConfigAtom(); - virtual void OnProcessMetaData(); - virtual char *OnGetAtomName(); + DecoderConfigAtom(BPositionIO *pStream, + off_t pStreamOffset, uint32 pAtomType, + uint64 pAtomSize); + virtual ~DecoderConfigAtom(); + virtual void OnProcessMetaData(); + virtual const char *OnGetAtomName(); // The decoder config is what the decoder uses for it's setup // The values SHOULD mirror the Container values but often don't // So we have to parse the config and use the values as container overrides - void OverrideAudioDescription(AudioDescription *pAudioDescription); - virtual void OnOverrideAudioDescription(AudioDescription *pAudioDescription) {} ; - void OverrideVideoDescription(VideoDescription *pVideoDescription); - virtual void OnOverrideVideoDescription(VideoDescription *pVideoDescription) {} ; - bool SkipTag(uint8 *ESDS, uint8 Tag, uint32 *offset); + void OverrideAudioDescription( + AudioDescription *pAudioDescription); + virtual void OnOverrideAudioDescription( + AudioDescription *pAudioDescription) {}; + void OverrideVideoDescription( + VideoDescription *pVideoDescription); + virtual void OnOverrideVideoDescription( + VideoDescription *pVideoDescription) {}; + bool SkipTag(uint8 *ESDS, uint8 Tag, uint32 *offset); - uint8 *GetDecoderConfig(); - size_t GetDecoderConfigSize() { return DecoderConfigSize; } ; + uint8 *GetDecoderConfig(); + size_t GetDecoderConfigSize() {return DecoderConfigSize;}; + private: - uint8 *theDecoderConfig; - size_t DecoderConfigSize; + uint8 *theDecoderConfig; + size_t DecoderConfigSize; }; + // Atom class for reading the ESDS decoder config atom class ESDSAtom : public DecoderConfigAtom { public: - ESDSAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~ESDSAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - void OnOverrideAudioDescription(AudioDescription *pAudioDescription); - void OnOverrideVideoDescription(VideoDescription *pVideoDescription); + ESDSAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~ESDSAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + void OnOverrideAudioDescription( + AudioDescription *pAudioDescription); + void OnOverrideVideoDescription( + VideoDescription *pVideoDescription); + private: - uint8 ESDSType; - uint8 StreamType; - uint32 NeededBufferSize; - uint32 MaxBitRate; - uint32 AvgBitRate; - AACHeader theAACHeader; + uint8 ESDSType; + uint8 StreamType; + uint32 NeededBufferSize; + uint32 MaxBitRate; + uint32 AvgBitRate; + AACHeader theAACHeader; }; + // Atom class for reading the ALAC decoder config atom class ALACAtom : public DecoderConfigAtom { public: - ALACAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~ALACAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - void OnOverrideAudioDescription(AudioDescription *pAudioDescription); - void OnOverrideVideoDescription(VideoDescription *pVideoDescription); + ALACAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~ALACAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + void OnOverrideAudioDescription( + AudioDescription *pAudioDescription); + void OnOverrideVideoDescription( + VideoDescription *pVideoDescription); }; + // Atom class for reading the WAVE atom for mp3 decoder config class WAVEAtom : public DecoderConfigAtom { public: - WAVEAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~WAVEAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - void OnOverrideAudioDescription(AudioDescription *pAudioDescription); - void OnOverrideVideoDescription(VideoDescription *pVideoDescription); + WAVEAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~WAVEAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + void OnOverrideAudioDescription( + AudioDescription *pAudioDescription); + void OnOverrideVideoDescription( + VideoDescription *pVideoDescription); }; + // Atom class for reading the Sample Description atom class STSDAtom : public FullAtom { public: - STSDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STSDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + STSDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STSDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - VideoDescription GetAsVideo(); - AudioDescription GetAsAudio(); - -private: - uint32 GetMediaHandlerType(); + VideoDescription GetAsVideo(); + AudioDescription GetAsAudio(); - void ReadDecoderConfig(uint8 **pDecoderConfig, size_t *pDecoderConfigSize, AudioDescription *pAudioDescription, VideoDescription *pVideoDescription); - void ReadSoundDescription(); - void ReadVideoDescription(); - void ReadHintDescription(); +private: + uint32 GetMediaHandlerType(); + + void ReadDecoderConfig(uint8 **pDecoderConfig, + size_t *pDecoderConfigSize, + AudioDescription *pAudioDescription, + VideoDescription *pVideoDescription); + void ReadSoundDescription(); + void ReadVideoDescription(); + void ReadHintDescription(); - uint32 codecid; + uint32 codecid; - array_header theHeader; - SampleEntry theSampleEntry; - AudioDescription theAudioDescription; - VideoDescription theVideoDescription; + array_header theHeader; + SampleEntry theSampleEntry; + AudioDescription theAudioDescription; + VideoDescription theVideoDescription; }; + // Atom class for reading the track header atom class TKHDAtom : public FullAtom { public: - TKHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~TKHDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + TKHDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~TKHDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint32 GetDuration() {return theHeader.Duration;}; // duration is in the scale of the media + uint32 GetDuration() {return theHeader.Duration;}; + // duration is in the scale of the media - // Flags3 should contain the following - // 0x001 Track enabled - // 0x002 Track in Movie - // 0x004 Track in Preview - // 0x008 Track in Poster - - bool IsActive() {return ((GetFlags3() && 0x01) || (GetFlags3() && 0x0f));}; + // Flags3 should contain the following + // 0x001 Track enabled + // 0x002 Track in Movie + // 0x004 Track in Preview + // 0x008 Track in Poster + bool IsActive() {return ((GetFlags3() && 0x01) + || (GetFlags3() && 0x0f));}; + private: - tkhdV1 theHeader; + tkhdV1 theHeader; }; + // Atom class for reading the media header atom class MDHDAtom : public FullAtom { public: - MDHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~MDHDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + MDHDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~MDHDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + + // return duration in ms + bigtime_t GetDuration(); + uint32 GetTimeScale(); - // return duration in ms - bigtime_t GetDuration(); - uint32 GetTimeScale(); - private: - mdhdV1 theHeader; + mdhdV1 theHeader; }; + // Atom class for reading the video media header atom class VMHDAtom : public FullAtom { public: - VMHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~VMHDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + VMHDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~VMHDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - bool IsCopyMode() {return theHeader.GraphicsMode == 0;}; + bool IsCopyMode() {return theHeader.GraphicsMode == 0;}; private: - vmhd theHeader ; + vmhd theHeader ; }; + // Atom class for reading the sound media header atom class SMHDAtom : public FullAtom { public: - SMHDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~SMHDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + SMHDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~SMHDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + private: - smhd theHeader; + smhd theHeader; }; + // Atom class for reading the track atom class TRAKAtom : public AtomContainer { public: - TRAKAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~TRAKAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - void OnChildProcessingComplete(); + TRAKAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~TRAKAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + void OnChildProcessingComplete(); - bigtime_t Duration(uint32 TimeScale); // Return duration of track - bigtime_t Duration() { return Duration(timeScale); } - uint32 FrameCount() { return frameCount; }; - bool IsVideo(); // Is this a video track - bool IsAudio(); // Is this a audio track - // GetAudioMetaData() // If this is a audio track Get the audio meta data - // GetVideoMetaData() // If this is a video track Get the video meta data + bigtime_t Duration(uint32 TimeScale); // Return duration of track + bigtime_t Duration() { return Duration(timeScale); } + uint32 FrameCount() { return frameCount; }; + bool IsVideo(); // Is this a video track + bool IsAudio(); // Is this a audio track + // GetAudioMetaData() // If this is a audio track Get the audio meta data + // GetVideoMetaData() // If this is a video track Get the video meta data - bigtime_t GetTimeForFrame(uint32 pFrame); - uint32 GetFrameForTime(bigtime_t time); - uint32 GetSampleForTime(bigtime_t pTime); - uint32 GetSampleForFrame(uint32 pFrame); - uint32 GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk); - uint64 GetOffsetForChunk(uint32 pChunkIndex); - uint32 GetFirstSampleInChunk(uint32 pChunkIndex); - uint32 GetSizeForSample(uint32 pSample); - uint32 GetNoSamplesInChunk(uint32 pChunkIndex); - uint32 GetTotalChunks(); - uint32 GetChunkSize(uint32 pChunkIndex); - uint32 ChunkCount(); + bigtime_t GetTimeForFrame(uint32 pFrame); + uint32 GetFrameForTime(bigtime_t time); + uint32 GetSampleForTime(bigtime_t pTime); + uint32 GetSampleForFrame(uint32 pFrame); + uint32 GetChunkForSample(uint32 pSample, + uint32 *pOffsetInChunk); + uint64 GetOffsetForChunk(uint32 pChunkIndex); + uint32 GetFirstSampleInChunk(uint32 pChunkIndex); + uint32 GetSizeForSample(uint32 pSample); + uint32 GetNoSamplesInChunk(uint32 pChunkIndex); + uint32 GetTotalChunks(); + uint32 GetChunkSize(uint32 pChunkIndex); + uint32 ChunkCount(); - float GetSampleRate(); - float GetFrameRate(); + float GetSampleRate(); + float GetFrameRate(); - bool IsSyncSample(uint32 pSampleNo); - bool IsSingleSampleSize(); - bool IsActive(); + bool IsSyncSample(uint32 pSampleNo); + bool IsSingleSampleSize(); + bool IsActive(); - uint32 GetBytesPerSample(); + uint32 GetBytesPerSample(); - TKHDAtom *GetTKHDAtom(); - MDHDAtom *GetMDHDAtom(); + TKHDAtom *GetTKHDAtom(); + MDHDAtom *GetMDHDAtom(); private: - TKHDAtom *theTKHDAtom; - MDHDAtom *theMDHDAtom; - - uint32 frameCount; - uint32 bytesPerSample; - uint32 timeScale; + TKHDAtom *theTKHDAtom; + MDHDAtom *theMDHDAtom; + + uint32 frameCount; + uint32 bytesPerSample; + uint32 timeScale; }; + // Atom class for reading the media container atom class MDIAAtom : public AtomContainer { public: - MDIAAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~MDIAAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + MDIAAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~MDIAAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint32 GetMediaHandlerType(); + uint32 GetMediaHandlerType(); }; + // Atom class for reading the media information atom class MINFAtom : public AtomContainer { public: - MINFAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~MINFAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + MINFAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~MINFAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint32 GetMediaHandlerType(); + uint32 GetMediaHandlerType(); }; + // Atom class for reading the stbl atom class STBLAtom : public AtomContainer { public: - STBLAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~STBLAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + STBLAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~STBLAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - uint32 GetMediaHandlerType(); + uint32 GetMediaHandlerType(); }; + // Atom class for reading the dinf atom class DINFAtom : public AtomContainer { public: - DINFAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~DINFAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + DINFAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~DINFAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); }; + // Atom class for reading the tmcd atom class TMCDAtom : public AtomBase { public: - TMCDAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~TMCDAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - + TMCDAtom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~TMCDAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); }; + // Atom class for reading the dac3 atom class DAC3Atom : public DecoderConfigAtom { public: - DAC3Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~DAC3Atom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - void OnOverrideAudioDescription(AudioDescription *pAudioDescription); - void OnOverrideVideoDescription(VideoDescription *pVideoDescription); + DAC3Atom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~DAC3Atom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + void OnOverrideAudioDescription( + AudioDescription *pAudioDescription); + void OnOverrideVideoDescription( + VideoDescription *pVideoDescription); }; + // Atom class for reading the dec3 atom class DEC3Atom : public DecoderConfigAtom { public: - DEC3Atom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~DEC3Atom(); - void OnProcessMetaData(); - char *OnGetAtomName(); - void OnOverrideAudioDescription(AudioDescription *pAudioDescription); - void OnOverrideVideoDescription(VideoDescription *pVideoDescription); + DEC3Atom(BPositionIO *pStream, off_t pStreamOffset, + uint32 pAtomType, uint64 pAtomSize); + virtual ~DEC3Atom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); + void OnOverrideAudioDescription( + AudioDescription *pAudioDescription); + void OnOverrideVideoDescription( + VideoDescription *pVideoDescription); }; + // Atom class for reading the Media Handler atom class HDLRAtom : public FullAtom { public: - HDLRAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); - virtual ~HDLRAtom(); - void OnProcessMetaData(); - char *OnGetAtomName(); + HDLRAtom(BPositionIO *pStream, off_t pStreamOffset, uint32 pAtomType, uint64 pAtomSize); + virtual ~HDLRAtom(); + void OnProcessMetaData(); + const char *OnGetAtomName(); - bool IsVideoHandler(); - bool IsAudioHandler(); - uint32 GetMediaHandlerType(); + bool IsVideoHandler(); + bool IsAudioHandler(); + uint32 GetMediaHandlerType(); private: - hdlr theHeader; - char *name; + hdlr theHeader; + char *name; }; + #endif diff --git a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4TrakAtom.cpp b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4TrakAtom.cpp index 1458e9bd7d..35e96483a1 100644 --- a/src/add-ons/media/plugins/mp4_reader/libMP4/MP4TrakAtom.cpp +++ b/src/add-ons/media/plugins/mp4_reader/libMP4/MP4TrakAtom.cpp @@ -22,9 +22,15 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ + + #include "MP4Parser.h" -TRAKAtom::TRAKAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, uint64 patomSize) : AtomContainer(pStream, pstreamOffset, patomType, patomSize) + +TRAKAtom::TRAKAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, + uint64 patomSize) + : + AtomContainer(pStream, pstreamOffset, patomType, patomSize) { theTKHDAtom = NULL; theMDHDAtom = NULL; @@ -33,20 +39,27 @@ TRAKAtom::TRAKAtom(BPositionIO *pStream, off_t pstreamOffset, uint32 patomType, timeScale = 1; } + TRAKAtom::~TRAKAtom() { } -void TRAKAtom::OnProcessMetaData() + +void +TRAKAtom::OnProcessMetaData() { } -char *TRAKAtom::OnGetAtomName() + +const char * +TRAKAtom::OnGetAtomName() { return "MPEG-4 Track Atom"; } -TKHDAtom *TRAKAtom::GetTKHDAtom() + +TKHDAtom * +TRAKAtom::GetTKHDAtom() { if (theTKHDAtom) { return theTKHDAtom; @@ -59,11 +72,12 @@ TKHDAtom *TRAKAtom::GetTKHDAtom() return theTKHDAtom; } -MDHDAtom *TRAKAtom::GetMDHDAtom() + +MDHDAtom * +TRAKAtom::GetMDHDAtom() { - if (theMDHDAtom) { + if (theMDHDAtom) return theMDHDAtom; - } theMDHDAtom = dynamic_cast(GetChildAtom(uint32('mdhd'),0)); @@ -72,21 +86,24 @@ MDHDAtom *TRAKAtom::GetMDHDAtom() return theMDHDAtom; } -// Return duration of track -bigtime_t TRAKAtom::Duration(uint32 TimeScale) + +bigtime_t +TRAKAtom::Duration(uint32 TimeScale) { - if (IsAudio() || IsVideo()) { + if (IsAudio() || IsVideo()) return GetMDHDAtom()->GetDuration(); - } return bigtime_t(GetTKHDAtom()->GetDuration() * 1000000.0) / TimeScale; } -void TRAKAtom::OnChildProcessingComplete() + +void +TRAKAtom::OnChildProcessingComplete() { timeScale = GetMDHDAtom()->GetTimeScale(); - STTSAtom *aSTTSAtom = dynamic_cast(GetChildAtom(uint32('stts'),0)); + STTSAtom *aSTTSAtom = dynamic_cast + (GetChildAtom(uint32('stts'),0)); if (aSTTSAtom) { frameCount = aSTTSAtom->GetSUMCounts(); @@ -95,22 +112,26 @@ void TRAKAtom::OnChildProcessingComplete() } -// Is this a video track -bool TRAKAtom::IsVideo() + +bool +TRAKAtom::IsVideo() { // video tracks have a vmhd atom return (GetChildAtom(uint32('vmhd'),0) != NULL); } -// Is this a audio track -bool TRAKAtom::IsAudio() + +bool +TRAKAtom::IsAudio() { // audio tracks have a smhd atom return (GetChildAtom(uint32('smhd'),0) != NULL); } + // frames per us -float TRAKAtom::GetFrameRate() +float +TRAKAtom::GetFrameRate() { if (IsAudio()) { AtomBase *aAtomBase = GetChildAtom(uint32('stsd'),0); @@ -118,7 +139,8 @@ float TRAKAtom::GetFrameRate() STSDAtom *aSTSDAtom = dynamic_cast(aAtomBase); AudioDescription aAudioDescription = aSTSDAtom->GetAsAudio(); - return (aAudioDescription.theAudioSampleEntry.SampleRate) / aAudioDescription.FrameSize; + return (aAudioDescription.theAudioSampleEntry.SampleRate) + / aAudioDescription.FrameSize; } } else if (IsVideo()) { return (frameCount * 1000000.0) / Duration(); @@ -127,7 +149,9 @@ float TRAKAtom::GetFrameRate() return 0.0; } -float TRAKAtom::GetSampleRate() + +float +TRAKAtom::GetSampleRate() { // Only valid for Audio if (IsAudio()) { @@ -143,6 +167,7 @@ float TRAKAtom::GetSampleRate() return 0.0; } + uint32 TRAKAtom::GetFrameForTime(bigtime_t time) { // time / duration * frameCount? @@ -150,12 +175,16 @@ TRAKAtom::GetFrameForTime(bigtime_t time) { return time * frameCount / Duration(); } -bigtime_t TRAKAtom::GetTimeForFrame(uint32 pFrame) + +bigtime_t +TRAKAtom::GetTimeForFrame(uint32 pFrame) { return bigtime_t((pFrame * 1000000LL) / GetFrameRate()); } -uint32 TRAKAtom::GetSampleForTime(bigtime_t pTime) + +uint32 +TRAKAtom::GetSampleForTime(bigtime_t pTime) { AtomBase *aAtomBase = GetChildAtom(uint32('stts'),0); @@ -166,40 +195,49 @@ uint32 TRAKAtom::GetSampleForTime(bigtime_t pTime) return 0; } -uint32 TRAKAtom::GetSampleForFrame(uint32 pFrame) + +uint32 +TRAKAtom::GetSampleForFrame(uint32 pFrame) { AtomBase *aAtomBase = GetChildAtom(uint32('stts'),0); if (aAtomBase) { - return (dynamic_cast(aAtomBase))->GetSampleForTime(GetTimeForFrame(pFrame)); + return (dynamic_cast + (aAtomBase))->GetSampleForTime(GetTimeForFrame(pFrame)); } return 0; } -uint32 TRAKAtom::GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) + +uint32 +TRAKAtom::GetChunkForSample(uint32 pSample, uint32 *pOffsetInChunk) { AtomBase *aAtomBase = GetChildAtom(uint32('stsc'),0); - if (aAtomBase) { - return (dynamic_cast(aAtomBase))->GetChunkForSample(pSample, pOffsetInChunk); - } + if (aAtomBase) + return (dynamic_cast(aAtomBase))->GetChunkForSample(pSample, + pOffsetInChunk); return 0; } -uint32 TRAKAtom::GetNoSamplesInChunk(uint32 pChunkIndex) + +uint32 +TRAKAtom::GetNoSamplesInChunk(uint32 pChunkIndex) { AtomBase *aAtomBase = GetChildAtom(uint32('stsc'),0); - if (aAtomBase) { - return (dynamic_cast(aAtomBase))->GetNoSamplesInChunk(pChunkIndex); - } + if (aAtomBase) + return (dynamic_cast + (aAtomBase))->GetNoSamplesInChunk(pChunkIndex); return 0; } -uint32 TRAKAtom::GetSizeForSample(uint32 pSample) + +uint32 +TRAKAtom::GetSizeForSample(uint32 pSample) { AtomBase *aAtomBase = GetChildAtom(uint32('stsz'),0); @@ -210,74 +248,84 @@ uint32 TRAKAtom::GetSizeForSample(uint32 pSample) return 0; } -uint64 TRAKAtom::GetOffsetForChunk(uint32 pChunkIndex) + +uint64 +TRAKAtom::GetOffsetForChunk(uint32 pChunkIndex) { AtomBase *aAtomBase = GetChildAtom(uint32('stco'),0); if (aAtomBase) { - return (dynamic_cast(aAtomBase))->GetOffsetForChunk(pChunkIndex); + return (dynamic_cast + (aAtomBase))->GetOffsetForChunk(pChunkIndex); } return 0; } -uint32 TRAKAtom::ChunkCount() { + +uint32 +TRAKAtom::ChunkCount() +{ AtomBase *aAtomBase = GetChildAtom(uint32('stco'),0); - if (aAtomBase) { + if (aAtomBase) return (dynamic_cast(aAtomBase))->GetTotalChunks(); - } - + return 0; } -uint32 TRAKAtom::GetFirstSampleInChunk(uint32 pChunkIndex) +uint32 +TRAKAtom::GetFirstSampleInChunk(uint32 pChunkIndex) { AtomBase *aAtomBase = GetChildAtom(uint32('stsc'),0); - if (aAtomBase) { - return (dynamic_cast(aAtomBase))->GetFirstSampleInChunk(pChunkIndex); - } + if (aAtomBase) + return (dynamic_cast + (aAtomBase))->GetFirstSampleInChunk(pChunkIndex); return 0; } -bool TRAKAtom::IsSyncSample(uint32 pSampleNo) +bool +TRAKAtom::IsSyncSample(uint32 pSampleNo) { AtomBase *aAtomBase = GetChildAtom(uint32('stss'),0); - if (aAtomBase) { + if (aAtomBase) return (dynamic_cast(aAtomBase))->IsSyncSample(pSampleNo); - } return false; } -bool TRAKAtom::IsSingleSampleSize() + +bool +TRAKAtom::IsSingleSampleSize() { AtomBase *aAtomBase = GetChildAtom(uint32('stsz'),0); - if (aAtomBase) { + if (aAtomBase) return (dynamic_cast(aAtomBase))->IsSingleSampleSize(); - } return false; } -bool TRAKAtom::IsActive() + +bool +TRAKAtom::IsActive() { return GetTKHDAtom()->IsActive(); } -uint32 TRAKAtom::GetBytesPerSample() -{ -AtomBase *aAtomBase; - if (bytesPerSample > 0) { +uint32 +TRAKAtom::GetBytesPerSample() +{ + AtomBase *aAtomBase; + + if (bytesPerSample > 0) return bytesPerSample; - } // calculate bytes per sample and cache it @@ -289,13 +337,15 @@ AtomBase *aAtomBase; AudioDescription aAudioDescription = aSTSDAtom->GetAsAudio(); - bytesPerSample = aAudioDescription.theAudioSampleEntry.SampleSize / 8; + bytesPerSample = aAudioDescription.theAudioSampleEntry.SampleSize + / 8; } } return bytesPerSample; } + uint32 TRAKAtom::GetChunkSize(uint32 pChunkIndex) { @@ -319,13 +369,14 @@ TRAKAtom::GetChunkSize(uint32 pChunkIndex) return 0; } -uint32 TRAKAtom::GetTotalChunks() + +uint32 +TRAKAtom::GetTotalChunks() { AtomBase *aAtomBase = GetChildAtom(uint32('stco'),0); - if (aAtomBase) { + if (aAtomBase) return (dynamic_cast(aAtomBase))->GetTotalChunks(); - } return 0; }