1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /*********************************************************************************/
19 /* ------------------------------------------------------------------- */
20 /* MPEG-4 DataReferenceAtom Class */
21 /* ------------------------------------------------------------------- */
22 /*********************************************************************************/
23 /*
24 This DataReferenceAtom Class contains a table of data references which declare
25 the location of the media data used within the MPEG-4 presentation.
26 */
27
28
29 #define IMPLEMENT_DataReferenceAtom
30
31 #include "datareferenceatom.h"
32 #include "dataentryurlatom.h"
33 #include "atomdefs.h"
34 #include "atomutils.h"
35
36 typedef Oscl_Vector<DataEntryUrlAtom*, OsclMemAllocator> dataEntryUrlAtomVecType;
37 // Stream-in ctor
DataReferenceAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)38 DataReferenceAtom::DataReferenceAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
39 : FullAtom(fp, size, type)
40 {
41
42 _pdataEntryVec = NULL;
43
44 if (_success)
45 {
46
47 _pparent = NULL;
48
49 PV_MP4_FF_NEW(fp->auditCB, dataEntryUrlAtomVecType, (), _pdataEntryVec);
50
51 if (!AtomUtils::read32(fp, _entryCount))
52 {
53 _success = false;
54 _mp4ErrorCode = READ_DATA_REFERENCE_ATOM_FAILED;
55 }
56 else
57 {
58 // THERE MUST BE ATLEAST ONE ENTRY
59 int32 temp = (int32)(_entryCount);
60
61 if (temp <= 0)
62 {
63 _success = false;
64 _mp4ErrorCode = READ_DATA_REFERENCE_ATOM_FAILED;
65 }
66 }
67
68 if (_success)
69 {
70 DataEntryUrlAtom *deua = NULL;
71 for (uint32 i = 0; i < _entryCount; i++)
72 {
73 PV_MP4_FF_NEW(fp->auditCB, DataEntryUrlAtom, (fp), deua);
74 if (!deua->MP4Success())
75 {
76 _success = false;
77 _mp4ErrorCode = deua->GetMP4Error();
78 if (deua != NULL)
79 {
80 PV_MP4_FF_DELETE(NULL, DataEntryUrlAtom, deua);
81 deua = NULL;
82 }
83 break;
84 }
85 else
86 {
87 (*_pdataEntryVec).push_back(deua);
88 deua->setParent(this);
89 }
90 }
91 }
92 }
93 else
94 {
95 if (_mp4ErrorCode != ATOM_VERSION_NOT_SUPPORTED)
96 _mp4ErrorCode = READ_DATA_REFERENCE_ATOM_FAILED;
97 }
98
99 }
100
101 // Destructor
~DataReferenceAtom()102 DataReferenceAtom::~DataReferenceAtom()
103 {
104 // Clean up vector of DataEntryAtoms
105 if (_pdataEntryVec != NULL)
106 {
107 for (uint32 i = 0; i < _pdataEntryVec->size(); i++)
108 {
109 PV_MP4_FF_DELETE(NULL, DataEntryUrlAtom, (*_pdataEntryVec)[i]);
110 }
111
112 PV_MP4_FF_TEMPLATED_DELETE(NULL, dataEntryUrlAtomVecType, Oscl_Vector, _pdataEntryVec);
113 _pdataEntryVec = NULL;
114 }
115 }
116
117 DataEntryAtom *
getEntryAt(int32 index)118 DataReferenceAtom::getEntryAt(int32 index)
119 {
120 if ((uint32)index < _pdataEntryVec->size())
121 {
122 return (DataEntryAtom*)(*_pdataEntryVec)[index];
123 }
124 else
125 {
126 return NULL;
127 }
128 }
129