• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     This PVA_FF_DataReferenceAtom Class contains a table of data references which declare
20     the location of the media data used within the MPEG-4 presentation.
21 */
22 
23 
24 #define IMPLEMENT_DataReferenceAtom
25 
26 #include "datareferenceatom.h"
27 #include "dataentryurlatom.h"
28 #include "a_atomdefs.h"
29 #include "atomutils.h"
30 
31 typedef Oscl_Vector<PVA_FF_DataEntryAtom*, OsclMemAllocator> PVA_FF_DataEntryAtomVecType;
32 
33 // Constructor
PVA_FF_DataReferenceAtom()34 PVA_FF_DataReferenceAtom::PVA_FF_DataReferenceAtom()
35         : PVA_FF_FullAtom(DATA_REFERENCE_ATOM, (uint8)0, (uint32)0)
36 {
37     init();
38     recomputeSize();
39 }
40 
41 // Destructor
~PVA_FF_DataReferenceAtom()42 PVA_FF_DataReferenceAtom::~PVA_FF_DataReferenceAtom()
43 {
44     // Clean up vector of DataEntryAtoms
45     for (uint32 i = 0; i < _pdataEntryVec->size(); i++)
46     {
47         PVA_FF_DataEntryUrlAtom *atom = (PVA_FF_DataEntryUrlAtom*)(*_pdataEntryVec)[i];
48         PV_MP4_FF_DELETE(NULL, PVA_FF_DataEntryUrlAtom, atom);
49     }
50     PV_MP4_FF_TEMPLATED_DELETE(NULL, PVA_FF_DataEntryAtomVecType, Oscl_Vector, _pdataEntryVec);
51 }
52 
53 void
init()54 PVA_FF_DataReferenceAtom::init()
55 {
56     _entryCount = 0;
57 
58     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_DataEntryAtomVecType, (), _pdataEntryVec);
59 
60     // Add default URLDataEntry with flag set indicating that the
61     // media data is local to the file
62     PVA_FF_DataEntryUrlAtom *deua = NULL;
63     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_DataEntryUrlAtom, ((uint32)1), deua);
64     addDataEntryAtom(deua);
65 
66     recomputeSize();
67 }
68 
69 void
addDataEntryAtom(PVA_FF_DataEntryAtom * atom)70 PVA_FF_DataReferenceAtom::addDataEntryAtom(PVA_FF_DataEntryAtom *atom)
71 {
72     _pdataEntryVec->push_back(atom);
73     atom->setParent(this);
74     _entryCount++;
75 }
76 
77 
78 // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream
79 bool
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)80 PVA_FF_DataReferenceAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
81 {
82     int32 rendered = 0;
83 
84     if (!renderAtomBaseMembers(fp))
85     {
86         return false;
87     }
88     rendered += getDefaultSize();
89 
90     if (!PVA_FF_AtomUtils::render32(fp, getEntryCount()))
91     {
92         return false;
93     }
94     rendered += 4;
95 
96     for (uint32 i = 0; i < _pdataEntryVec->size(); i++)
97     {
98         if (!(*_pdataEntryVec)[i]->renderToFileStream(fp))
99         {
100             return false;
101         }
102         rendered += (*_pdataEntryVec)[i]->getSize();
103     }
104 
105     return true;
106 }
107 
108 
109 
110 void
recomputeSize()111 PVA_FF_DataReferenceAtom::recomputeSize()
112 {
113     int32 size = getDefaultSize();
114 
115     size += 4; // For entry count
116 
117     for (uint32 i = 0; i < _pdataEntryVec->size(); i++)
118     {
119         size += (*_pdataEntryVec)[i]->getSize();
120     }
121 
122     _size = size;
123 
124     // Update the size of the parent atoms
125     if (_pparent != NULL)
126     {
127         _pparent->recomputeSize();
128     }
129 }
130