1 /***************************************************************** 2 | 3 | AP4 - trun Atoms 4 | 5 | Copyright 2002-2008 Axiomatic Systems, LLC 6 | 7 | 8 | This file is part of Bento4/AP4 (MP4 Atom Processing Library). 9 | 10 | Unless you have obtained Bento4 under a difference license, 11 | this version of Bento4 is Bento4|GPL. 12 | Bento4|GPL is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2, or (at your option) 15 | any later version. 16 | 17 | Bento4|GPL is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with Bento4|GPL; see the file COPYING. If not, write to the 24 | Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 25 | 02111-1307, USA. 26 | 27 ****************************************************************/ 28 29 #ifndef _AP4_TRUN_ATOM_H_ 30 #define _AP4_TRUN_ATOM_H_ 31 32 /*---------------------------------------------------------------------- 33 | includes 34 +---------------------------------------------------------------------*/ 35 #include "Ap4Atom.h" 36 #include "Ap4Array.h" 37 38 /*---------------------------------------------------------------------- 39 | constants 40 +---------------------------------------------------------------------*/ 41 const AP4_UI32 AP4_TRUN_FLAG_DATA_OFFSET_PRESENT = 0x0001; 42 const AP4_UI32 AP4_TRUN_FLAG_FIRST_SAMPLE_FLAGS_PRESENT = 0x0004; 43 const AP4_UI32 AP4_TRUN_FLAG_SAMPLE_DURATION_PRESENT = 0x0100; 44 const AP4_UI32 AP4_TRUN_FLAG_SAMPLE_SIZE_PRESENT = 0x0200; 45 const AP4_UI32 AP4_TRUN_FLAG_SAMPLE_FLAGS_PRESENT = 0x0400; 46 const AP4_UI32 AP4_TRUN_FLAG_SAMPLE_COMPOSITION_TIME_OFFSET_PRESENT = 0x0800; 47 48 /*---------------------------------------------------------------------- 49 | AP4_TrunAtom 50 +---------------------------------------------------------------------*/ 51 class AP4_TrunAtom : public AP4_Atom 52 { 53 public: 54 AP4_IMPLEMENT_DYNAMIC_CAST(AP4_TrunAtom) 55 56 // types 57 struct Entry { EntryEntry58 Entry() : sample_duration(0), sample_size(0), sample_flags(0), sample_composition_time_offset(0) {} 59 AP4_UI32 sample_duration; 60 AP4_UI32 sample_size; 61 AP4_UI32 sample_flags; 62 AP4_UI32 sample_composition_time_offset; 63 }; 64 65 // class methods 66 static AP4_TrunAtom* Create(AP4_Size size, AP4_ByteStream& stream); 67 static unsigned int ComputeOptionalFieldsCount(AP4_UI32 flags); 68 static unsigned int ComputeRecordFieldsCount(AP4_UI32 flags); 69 70 // methods 71 AP4_TrunAtom(AP4_UI32 flags, 72 AP4_SI32 data_offset, 73 AP4_UI32 first_sample_flags); 74 void UpdateFlags(AP4_UI32 flags); 75 virtual AP4_Result InspectFields(AP4_AtomInspector& inspector); 76 virtual AP4_Result WriteFields(AP4_ByteStream& stream); 77 78 // accessors GetDataOffset()79 AP4_SI32 GetDataOffset() { return m_DataOffset; } SetDataOffset(AP4_SI32 offset)80 void SetDataOffset(AP4_SI32 offset) { m_DataOffset = offset; } GetFirstSampleFlags()81 AP4_UI32 GetFirstSampleFlags() { return m_FirstSampleFlags; } SetFirstSampleFlags(AP4_UI32 flags)82 void SetFirstSampleFlags(AP4_UI32 flags) { m_FirstSampleFlags = flags; } GetEntries()83 const AP4_Array<Entry>& GetEntries() { return m_Entries; } UseEntries()84 AP4_Array<Entry>& UseEntries() { return m_Entries; } 85 AP4_Result SetEntries(const AP4_Array<Entry>& entries); 86 87 private: 88 // methods 89 AP4_TrunAtom(AP4_UI32 size, 90 AP4_UI08 version, 91 AP4_UI32 flags, 92 AP4_ByteStream& stream); 93 94 // members 95 AP4_SI32 m_DataOffset; 96 AP4_UI32 m_FirstSampleFlags; 97 AP4_Array<Entry> m_Entries; 98 }; 99 100 #endif // _AP4_TRUN_ATOM_H_ 101