• 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 Movie Extends Atom Class                             */
21 /*     -------------------------------------------------------------------       */
22 /*********************************************************************************/
23 /*
24 */
25 
26 #define IMPLEMENT_MovieExtendsAtom
27 
28 #include "movieextendsatom.h"
29 #include "atomdefs.h"
30 #include "atomutils.h"
31 
32 
33 typedef Oscl_Vector<TrackExtendsAtom*, OsclMemAllocator> trackExtendsAtomVecType;
34 // Constructor
MovieExtendsAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)35 MovieExtendsAtom::MovieExtendsAtom(MP4_FF_FILE *fp,
36                                    uint32 size,
37                                    uint32 type)
38         : Atom(fp, size, type)
39 {
40     _pMovieExtendsHeaderAtom        = NULL;
41 
42     PV_MP4_FF_NEW(fp->auditCB, trackExtendsAtomVecType, (), _pTrackExtendsAtomVec);
43 
44     uint32 count = size - DEFAULT_ATOM_SIZE;
45 
46     if (_success)
47     {
48         while (count > 0)
49         {
50             uint32 atomType = UNKNOWN_ATOM;
51             uint32 atomSize = 0;
52 
53             AtomUtils::getNextAtomType(fp, atomSize, atomType);
54 
55             if (atomType == MOVIE_EXTENDS_HEADER_ATOM)
56             {
57                 if (_pMovieExtendsHeaderAtom == NULL)
58                 {
59                     PV_MP4_FF_NEW(fp->auditCB, MovieExtendsHeaderAtom, (fp, atomSize, atomType), _pMovieExtendsHeaderAtom);
60                     if (!_pMovieExtendsHeaderAtom->MP4Success())
61                     {
62                         _success = false;
63                         _mp4ErrorCode = READ_MOVIE_EXTENDS_HEADER_FAILED;
64                         return;
65                     }
66                     count -= _pMovieExtendsHeaderAtom->getSize();
67                 }
68                 else
69                 {
70                     //duplicate atom
71                     count -= atomSize;
72                     atomSize -= DEFAULT_ATOM_SIZE;
73                     AtomUtils::seekFromCurrPos(fp, atomSize);
74                 }
75             }
76             else if (atomType == TRACK_EXTENDS_ATOM)
77             {
78                 TrackExtendsAtom *pTrackExtendsAtom = NULL;
79                 PV_MP4_FF_NEW(fp->auditCB, TrackExtendsAtom, (fp, atomSize, atomType), pTrackExtendsAtom);
80                 if (!pTrackExtendsAtom->MP4Success())
81                 {
82                     _success = false;
83                     PV_MP4_FF_DELETE(NULL, TrackExtendsAtom, pTrackExtendsAtom);
84                     _mp4ErrorCode = READ_TRACK_EXTENDS_ATOM_FAILED;
85                     return;
86                 }
87                 count -= pTrackExtendsAtom->getSize();
88                 _pTrackExtendsAtomVec->push_back(pTrackExtendsAtom);
89             }
90 
91         }
92     }
93     else
94     {
95         _mp4ErrorCode = READ_MOVIE_EXTENDS_ATOM_FAILED;
96     }
97 }
98 
~MovieExtendsAtom()99 MovieExtendsAtom::~MovieExtendsAtom()
100 {
101     if (_pMovieExtendsHeaderAtom != NULL)
102     {
103         PV_MP4_FF_DELETE(NULL, MovieExtendsHeaderAtom, _pMovieExtendsHeaderAtom);
104         _pMovieExtendsHeaderAtom = NULL;
105     }
106     for (uint32 i = 0; i < _pTrackExtendsAtomVec->size(); i++)
107     {
108         PV_MP4_FF_DELETE(NULL, TrackExtendsAtom, (*_pTrackExtendsAtomVec)[i]);
109     }
110     PV_MP4_FF_TEMPLATED_DELETE(NULL, trackExtendsAtomVecType, Oscl_Vector, _pTrackExtendsAtomVec);
111 
112 }
113