• 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_UserDataAtom Class fp a container atom for informative user-data.
20 */
21 
22 
23 #define __IMPLEMENT_UserDataAtom__
24 
25 #include "userdataatom.h"
26 #include "a_atomdefs.h"
27 #include "atomutils.h"
28 #include "assetinfoatoms.h"
29 
30 typedef Oscl_Vector<PVA_FF_Atom*, OsclMemAllocator> PVA_FF_AtomVecType;
31 // Constructor
PVA_FF_UserDataAtom()32 PVA_FF_UserDataAtom::PVA_FF_UserDataAtom() : PVA_FF_Atom(USER_DATA_ATOM)
33 {
34     _size = getDefaultSize();
35     PV_MP4_FF_NEW(fp->auditCB, PVA_FF_AtomVecType, (), _pUserDataAtomVec);
36 }
37 
38 // Destructor
~PVA_FF_UserDataAtom()39 PVA_FF_UserDataAtom::~PVA_FF_UserDataAtom()
40 {
41     // Delete all USER data Atoms
42 
43     for (uint32 i = 0; i < _pUserDataAtomVec->size(); i++)
44     {
45         PVA_FF_Atom* atomPtr = (*_pUserDataAtomVec)[i];
46         if (atomPtr->getType() == ASSET_INFO_TITLE_ATOM)
47         {
48             PVA_FF_AssetInfoTitleAtom * ptr = (PVA_FF_AssetInfoTitleAtom*)(*_pUserDataAtomVec)[i];
49             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoTitleAtom , ptr);
50         }
51         else if (atomPtr->getType() == ASSET_INFO_DESCP_ATOM)
52         {
53             PVA_FF_AssetInfoDescAtom * ptr = (PVA_FF_AssetInfoDescAtom*)(*_pUserDataAtomVec)[i];
54             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoDescAtom , ptr);
55         }
56         else if (atomPtr->getType() == ASSET_INFO_PERF_ATOM)
57         {
58             PVA_FF_AssetInfoPerformerAtom * ptr = (PVA_FF_AssetInfoPerformerAtom*)(*_pUserDataAtomVec)[i];
59             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoPerformerAtom , ptr);
60         }
61         else if (atomPtr->getType() == ASSET_INFO_AUTHOR_ATOM)
62         {
63             PVA_FF_AssetInfoAuthorAtom * ptr = (PVA_FF_AssetInfoAuthorAtom*)(*_pUserDataAtomVec)[i];
64             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoAuthorAtom , ptr);
65         }
66         else if (atomPtr->getType() == ASSET_INFO_GENRE_ATOM)
67         {
68             PVA_FF_AssetInfoGenreAtom * ptr = (PVA_FF_AssetInfoGenreAtom*)(*_pUserDataAtomVec)[i];
69             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoGenreAtom , ptr);
70         }
71         else if (atomPtr->getType() == ASSET_INFO_RATING_ATOM)
72         {
73             PVA_FF_AssetInfoRatingAtom * ptr = (PVA_FF_AssetInfoRatingAtom*)(*_pUserDataAtomVec)[i];
74             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoRatingAtom , ptr);
75         }
76         else if (atomPtr->getType() == ASSET_INFO_KEYWORD_ATOM)
77         {
78             PVA_FF_AssetInfoKeyWordsAtom * ptr = (PVA_FF_AssetInfoKeyWordsAtom*)(*_pUserDataAtomVec)[i];
79             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoKeyWordsAtom , ptr);
80         }
81         else if (atomPtr->getType() == ASSET_INFO_CLSF_ATOM)
82         {
83             PVA_FF_AssetInfoClassificationAtom * ptr = (PVA_FF_AssetInfoClassificationAtom*)(*_pUserDataAtomVec)[i];
84             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoClassificationAtom , ptr);
85         }
86         else if (atomPtr->getType() == ASSET_INFO_LOCINFO_ATOM)
87         {
88             PVA_FF_AssetInfoLocationInfoAtom * ptr = (PVA_FF_AssetInfoLocationInfoAtom*)(*_pUserDataAtomVec)[i];
89             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoLocationInfoAtom , ptr);
90         }
91         else if (atomPtr->getType() == ASSET_INFO_CPRT_ATOM)
92         {
93             PVA_FF_AssetInfoCopyRightAtom * ptr = (PVA_FF_AssetInfoCopyRightAtom*)(*_pUserDataAtomVec)[i];
94             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoCopyRightAtom , ptr);
95         }
96         else if (atomPtr->getType() == ASSET_INFO_ALBUM_TITLE_ATOM)
97         {
98             PVA_FF_AssetInfoAlbumAtom * ptr = (PVA_FF_AssetInfoAlbumAtom*)(*_pUserDataAtomVec)[i];
99             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoAlbumAtom , ptr);
100         }
101         else if (atomPtr->getType() == ASSET_INFO_RECORDING_YEAR_ATOM)
102         {
103             PVA_FF_AssetInfoRecordingYearAtom * ptr = (PVA_FF_AssetInfoRecordingYearAtom*)(*_pUserDataAtomVec)[i];
104             PV_MP4_FF_DELETE(NULL, PVA_FF_AssetInfoRecordingYearAtom , ptr);
105         }
106 
107     }
108 
109     PV_MP4_FF_TEMPLATED_DELETE(NULL, PVA_FF_AtomVecType, Oscl_Vector, _pUserDataAtomVec);
110     return;
111 }
112 
addAtom(PVA_FF_Atom * atom)113 void PVA_FF_UserDataAtom::addAtom(PVA_FF_Atom* atom)
114 {
115     // Adds a new vector to the array of user data atom pointers
116     _pUserDataAtomVec->push_back(atom);
117     atom->setParent(this);
118     recomputeSize();
119 }
120 
121 // Rendering the PVA_FF_Atom in proper format (bitlengths, etc.) to an ostream
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)122 bool PVA_FF_UserDataAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
123 {
124     int32 rendered = 0; // Keep track of number of bytes rendered
125     uint32 i = 0;
126 
127     recomputeSize();
128 
129     // Render PVA_FF_Atom type and size
130     if (!renderAtomBaseMembers(fp))
131     {
132         return false;
133     }
134     rendered += getDefaultSize();
135 
136     // Render all the user data atoms in sequence to the file
137     for (i = 0; i < _pUserDataAtomVec->size(); i++)
138     {
139         if (!((*_pUserDataAtomVec)[i]->renderToFileStream(fp)))
140         {
141             return false;
142         }
143         rendered += (*_pUserDataAtomVec)[i]->getSize();
144     }
145 
146     return true;
147 }
148 
149 void
recomputeSize()150 PVA_FF_UserDataAtom::recomputeSize()
151 {
152     _size = getDefaultSize();
153 
154     for (uint32 i = 0; i < _pUserDataAtomVec->size(); i++)
155     {
156         _size += (*_pUserDataAtomVec)[i]->getSize();
157     }
158 
159     // Update the size of the parent atom since this child atom may have changed
160     if (_pparent != NULL)
161     {
162         _pparent->recomputeSize();
163     }
164 }
165 
166 
167 
168 
169 
170