Ap4Co64Atom.cpp

00001 /*****************************************************************
00002 |
00003 |    AP4 - co64 Atoms 
00004 |
00005 |    Copyright 2002 Gilles Boccon-Gibod
00006 |
00007 |
00008 |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
00009 |
00010 |    Unless you have obtained Bento4 under a difference license,
00011 |    this version of Bento4 is Bento4|GPL.
00012 |    Bento4|GPL is free software; you can redistribute it and/or modify
00013 |    it under the terms of the GNU General Public License as published by
00014 |    the Free Software Foundation; either version 2, or (at your option)
00015 |    any later version.
00016 |
00017 |    Bento4|GPL is distributed in the hope that it will be useful,
00018 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 |    GNU General Public License for more details.
00021 |
00022 |    You should have received a copy of the GNU General Public License
00023 |    along with Bento4|GPL; see the file COPYING.  If not, write to the
00024 |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
00025 |    02111-1307, USA.
00026 |
00027  ****************************************************************/
00028 
00029 /*----------------------------------------------------------------------
00030 |       includes
00031 +---------------------------------------------------------------------*/
00032 #include "Ap4.h"
00033 #include "Ap4Co64Atom.h"
00034 #include "Ap4AtomFactory.h"
00035 #include "Ap4Utils.h"
00036 
00037 /*----------------------------------------------------------------------
00038 |       AP4_Co64Atom::AP4_Co64Atom
00039 +---------------------------------------------------------------------*/
00040 AP4_Co64Atom::AP4_Co64Atom(AP4_UI64* entries, AP4_UI32 entry_count) :
00041 AP4_Atom(AP4_ATOM_TYPE_CO64,  
00042          AP4_FULL_ATOM_HEADER_SIZE+4+entry_count*8, 
00043          true),
00044          m_Entries(new AP4_UI64[entry_count]),
00045          m_EntryCount(entry_count)
00046 {
00047     memcpy(m_Entries, entries, m_EntryCount*8);
00048 }
00049 
00050 /*----------------------------------------------------------------------
00051 |       AP4_Co64Atom::AP4_Co64Atom
00052 +---------------------------------------------------------------------*/
00053 AP4_Co64Atom::AP4_Co64Atom(AP4_Size size, AP4_ByteStream& stream) :
00054     AP4_Atom(AP4_ATOM_TYPE_CO64, size, true, stream)
00055 {
00056     stream.ReadUI32(m_EntryCount);
00057     if (m_EntryCount > (size-AP4_FULL_ATOM_HEADER_SIZE-4)/8) {
00058         m_EntryCount = (size-AP4_FULL_ATOM_HEADER_SIZE-4)/8;
00059     }
00060     m_Entries = new AP4_UI64[m_EntryCount];
00061     for (AP4_Ordinal i=0; i<m_EntryCount; i++) {
00062         stream.ReadUI64(m_Entries[i]);
00063     }
00064 }
00065 
00066 /*----------------------------------------------------------------------
00067 |       AP4_Co64Atom::~AP4_Co64Atom
00068 +---------------------------------------------------------------------*/
00069 AP4_Co64Atom::~AP4_Co64Atom()
00070 {
00071     delete[] m_Entries;
00072 }
00073 
00074 /*----------------------------------------------------------------------
00075 |       AP4_Co64Atom::GetChunkOffset
00076 +---------------------------------------------------------------------*/
00077 AP4_Result
00078 AP4_Co64Atom::GetChunkOffset(AP4_Ordinal chunk, AP4_Offset& chunk_offset)
00079 {
00080     // check the bounds
00081     if (chunk > m_EntryCount || chunk == 0) {
00082         return AP4_ERROR_OUT_OF_RANGE;
00083     }
00084 
00085     // get the chunk offset
00086     chunk_offset = m_Entries[chunk - 1]; // m_Entries is zero index based
00087 
00088     return AP4_SUCCESS;
00089 }
00090 
00091 /*----------------------------------------------------------------------
00092 |       AP4_Co64Atom::SetChunkOffset
00093 +---------------------------------------------------------------------*/
00094 AP4_Result
00095 AP4_Co64Atom::SetChunkOffset(AP4_Ordinal chunk, AP4_Offset chunk_offset)
00096 {
00097     // check the bounds
00098     if (chunk > m_EntryCount || chunk == 0) {
00099         return AP4_ERROR_OUT_OF_RANGE;
00100     }
00101 
00102     // get the chunk offset
00103     m_Entries[chunk - 1] = chunk_offset; // m_Entries is zero index based
00104 
00105     return AP4_SUCCESS;
00106 }
00107 
00108 /*----------------------------------------------------------------------
00109 |       AP4_Co64Atom::AdjustChunkOffsets
00110 +---------------------------------------------------------------------*/
00111 AP4_Result
00112 AP4_Co64Atom::AdjustChunkOffsets(AP4_Offset offset)
00113 {
00114     for (AP4_Ordinal i=0; i<m_EntryCount; i++) {
00115         m_Entries[i] += offset;
00116     }
00117 
00118     return AP4_SUCCESS;
00119 }
00120 
00121 /*----------------------------------------------------------------------
00122 |       AP4_Co64Atom::WriteFields
00123 +---------------------------------------------------------------------*/
00124 AP4_Result
00125 AP4_Co64Atom::WriteFields(AP4_ByteStream& stream)
00126 {
00127     AP4_Result result;
00128 
00129     // entry count
00130     result = stream.WriteUI32(m_EntryCount);
00131     if (AP4_FAILED(result)) return result;
00132 
00133     // entries
00134     for (AP4_Ordinal i=0; i<m_EntryCount; i++) {
00135         result = stream.WriteUI64(m_Entries[i]);
00136         if (AP4_FAILED(result)) return result;
00137     }
00138 
00139     return result;
00140 }
00141 
00142 /*----------------------------------------------------------------------
00143 |       AP4_Co64Atom::InspectFields
00144 +---------------------------------------------------------------------*/
00145 AP4_Result
00146 AP4_Co64Atom::InspectFields(AP4_AtomInspector& inspector)
00147 {
00148     inspector.AddField("entry_count", m_EntryCount);
00149 
00150     return AP4_SUCCESS;
00151 }

Generated on Tue Dec 13 14:47:19 2005 for guliverkli by  doxygen 1.4.5