• 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 /*     -------------------------------------------------------------------       */
20 /*                       MPEG-4 MediaInformationAtom Class                       */
21 /*     -------------------------------------------------------------------       */
22 /*********************************************************************************/
23 /*
24     This MediaInformationHeaderAtom Class is the base class of the other
25     MediaInformationHeaderAtoms, VideoMediaHeaderAtom VIDEO_MEDIA_HEADER_ATOM, SoundMediaHeaderAtom
26     SOUND_MEDIA_HEADER_ATOM, HintMediaHeaderAtom HINT_MEDIA_HEADER_ATOM, and Mpeg4MediaHeaderAtom MPEG4_MEDIA_HEADER_ATOM
27 */
28 
29 
30 #define IMPLEMENT_MediaInformationAtom_H__
31 
32 #include "mediainformationatom.h"
33 #include "atomutils.h"
34 #include "atomdefs.h"
35 
36 #include "videomediaheaderatom.h"
37 #include "soundmediaheaderatom.h"
38 #include "hintmediaheaderatom.h"
39 #include "mpeg4mediaheaderatom.h"
40 
41 
42 // Stream-in ctor
MediaInformationAtom(MP4_FF_FILE * fp,uint32 mediaType,OSCL_wString & filename,bool oPVContentDownloadable,uint32 parsingMode)43 MediaInformationAtom::MediaInformationAtom(MP4_FF_FILE *fp,
44         uint32 mediaType,
45         OSCL_wString& filename,
46         bool oPVContentDownloadable,
47         uint32 parsingMode)
48         : Atom(fp)
49 {
50     _pmediaInformationHeader = NULL;
51     _pdataInformationAtom    = NULL;
52     _psampleTableAtom        = NULL;
53 
54     if (_success)
55     {
56         _pparent = NULL;
57 
58         // Need to allow reading in in ANY ORDER!
59         uint32 atomType = UNKNOWN_ATOM;
60         uint32 atomSize = 0;
61 
62         int32 count = _size - DEFAULT_ATOM_SIZE;
63 
64         // Read in the MediaInformationHeaderAtom (either Video, Sound, Hint, or Mpeg4)
65         // and Data Information Atom and Sample Table Atom in ANY ORDER!!!!
66         while (count > 0)
67         {
68             AtomUtils::getNextAtomType(fp, atomSize, atomType);
69 
70             if (atomType == SOUND_MEDIA_HEADER_ATOM)
71             { //smhd
72                 // Read in SoundMediaHeaderAtom
73 
74                 PV_MP4_FF_NEW(fp->auditCB, SoundMediaHeaderAtom, (fp, atomSize, atomType), _pmediaInformationHeader);
75 
76                 if (!_pmediaInformationHeader->MP4Success())
77                 {
78                     _success = false;
79                     _mp4ErrorCode = _pmediaInformationHeader->GetMP4Error();
80                     break;
81                 }
82                 count -= _pmediaInformationHeader->getSize();
83             }
84             else if (atomType == VIDEO_MEDIA_HEADER_ATOM)
85             {
86                 // Read in VideoMediaHeaderAtom
87                 PV_MP4_FF_NEW(fp->auditCB, VideoMediaHeaderAtom, (fp, atomSize, atomType), _pmediaInformationHeader);
88 
89                 if (!_pmediaInformationHeader->MP4Success())
90                 {
91                     _success = false;
92                     _mp4ErrorCode = _pmediaInformationHeader->GetMP4Error();
93                     break;
94                 }
95                 count -= _pmediaInformationHeader->getSize();
96             }
97             else if ((atomType == UUID_ATOM)
98                      || (atomType == UNKNOWN_ATOM))
99             {
100                 if (atomSize < DEFAULT_ATOM_SIZE)
101                 {
102                     _success = false;
103                     _mp4ErrorCode = ZERO_OR_NEGATIVE_ATOM_SIZE;
104                     break;
105                 }
106                 if (count < (int32)atomSize)
107                 {
108                     _success = false;
109                     _mp4ErrorCode = READ_FAILED;
110                     break;
111                 }
112                 count -= atomSize;
113                 atomSize -= DEFAULT_ATOM_SIZE;
114                 AtomUtils::seekFromCurrPos(fp, atomSize);
115             }
116             else if (atomType == HINT_MEDIA_HEADER_ATOM)
117             {
118                 // Read in HintMediaHeaderAtom
119 
120                 PV_MP4_FF_NEW(fp->auditCB, HintMediaHeaderAtom,
121                               (fp, atomSize, atomType),
122                               _pmediaInformationHeader);
123 
124                 if (!_pmediaInformationHeader->MP4Success())
125                 {
126                     _success = false;
127                     _mp4ErrorCode = _pmediaInformationHeader->GetMP4Error();
128                     break;
129                 }
130                 count -= _pmediaInformationHeader->getSize();
131             }
132             else if (atomType == MPEG4_MEDIA_HEADER_ATOM)
133             {
134                 //nmhd
135                 // Read in generic Mpeg4MediaHeaderAtom
136 
137                 PV_MP4_FF_NEW(fp->auditCB, Mpeg4MediaHeaderAtom,
138                               (fp, mediaType, atomSize, atomType),
139                               _pmediaInformationHeader);
140 
141                 if (!_pmediaInformationHeader->MP4Success())
142                 {
143                     _success = false;
144                     _mp4ErrorCode = _pmediaInformationHeader->GetMP4Error();
145                     break;
146                 }
147                 count -= _pmediaInformationHeader->getSize();
148             }
149             else if (atomType == DATA_INFORMATION_ATOM)
150             {
151                 //dinf
152                 // Read in the DataInformationAtom
153                 PV_MP4_FF_NEW(fp->auditCB, DataInformationAtom,
154                               (fp, atomSize, atomType),
155                               _pdataInformationAtom);
156 
157                 if (!_pdataInformationAtom->MP4Success())
158                 {
159                     _success = false;
160                     _mp4ErrorCode = _pdataInformationAtom->GetMP4Error();
161                     break;
162                 }
163                 _pdataInformationAtom->setParent(this);
164                 count -= _pdataInformationAtom->getSize();
165             }
166             else if (atomType == SAMPLE_TABLE_ATOM)
167             {
168                 //stbl
169                 // Read in the SampleTableAtom
170                 PV_MP4_FF_NEW(fp->auditCB, SampleTableAtom,
171                               (fp, mediaType, filename, atomSize,
172                                atomType, oPVContentDownloadable,
173                                parsingMode), _psampleTableAtom);
174 
175                 if (!_psampleTableAtom->MP4Success())
176                 {
177                     _success = false;
178                     _mp4ErrorCode = _psampleTableAtom->GetMP4Error();
179                     break;
180                 }
181                 _psampleTableAtom->setParent(this);
182                 count -= _psampleTableAtom->getSize();
183             }
184             else
185             {
186                 count -= atomSize;
187                 atomSize -= DEFAULT_ATOM_SIZE;
188                 AtomUtils::seekFromCurrPos(fp, atomSize);
189             }
190         }
191         if (_pmediaInformationHeader != NULL)
192             _pmediaInformationHeader->setParent(this);
193 
194         if ((_pmediaInformationHeader == NULL) ||
195                 (_pdataInformationAtom == NULL)    ||
196                 (_psampleTableAtom == NULL))
197         {
198             _success = false;
199             _mp4ErrorCode = READ_MEDIA_INFORMATION_ATOM_FAILED;
200         }
201     }
202     else
203     {
204         _mp4ErrorCode = READ_MEDIA_INFORMATION_ATOM_FAILED;
205     }
206 }
207 
208 // Destructor
~MediaInformationAtom()209 MediaInformationAtom::~MediaInformationAtom()
210 {
211     if (_psampleTableAtom != NULL)
212     {
213         PV_MP4_FF_DELETE(NULL, SampleTableAtom, _psampleTableAtom);
214     }
215     if (_pdataInformationAtom != NULL)
216     {
217         PV_MP4_FF_DELETE(NULL, DataInformationAtom, _pdataInformationAtom);
218     }
219     if (_pmediaInformationHeader != NULL)
220     {
221         PV_MP4_FF_DELETE(NULL, MediaInformationHeaderAtom, _pmediaInformationHeader);
222     }
223 }
224