• 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 #include "metadataatom.h"
19 #include "atomdefs.h"
20 
21 
MetaDataAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)22 MetaDataAtom::MetaDataAtom(MP4_FF_FILE *fp, uint32 size, uint32 type): Atom(fp, size, type)
23 {
24     _success = true;
25 
26     // User ilst Data
27     _pITunesILSTAtom = NULL;
28     _pHdlrAtom = NULL;
29     uint32 _count = _size - getDefaultSize();
30 
31     uint32 data_32_hdlr = 0;
32     iLogger = PVLogger::GetLoggerObject("mp4ffparser");
33 
34     // Skip first 4 bytes.
35     if (!AtomUtils::read32(fp, data_32_hdlr))
36     {
37         _success = false;
38         _mp4ErrorCode = READ_META_DATA_FAILED;
39         PVMF_MP4FFPARSER_LOGERROR((0, "ERROR =>MetaDataAtom::MetaDataAtom READ_META_DATA_FAILED   if(!AtomUtils::read32(fp,data_32_hdlr)))"));
40         return;
41     }
42     _count -= 4;
43 
44     while (_count > 0)
45     {
46         uint32 atomType = UNKNOWN_ATOM;
47         uint32 atomSize = 0;
48 
49         uint32 currPtr = AtomUtils::getCurrentFilePosition(fp);
50         AtomUtils::getNextAtomType(fp, atomSize, atomType);
51 
52         if ((atomType == FREE_SPACE_ATOM) || (atomType == UNKNOWN_ATOM))
53         {
54             //skip the atom
55             if (atomSize < DEFAULT_ATOM_SIZE)
56             {
57                 _success = false;
58                 _mp4ErrorCode = ZERO_OR_NEGATIVE_ATOM_SIZE;
59                 break;
60             }
61             if (_count < atomSize)
62             {
63                 AtomUtils::seekFromStart(fp, currPtr);
64                 AtomUtils::seekFromCurrPos(fp, _count);
65                 _count = 0;
66                 return;
67             }
68 
69             _count -= atomSize;
70             atomSize -= DEFAULT_ATOM_SIZE;
71             AtomUtils::seekFromCurrPos(fp, atomSize);
72         }
73         else if (atomType == HANDLER_ATOM)
74         {
75             PV_MP4_FF_NEW(fp->auditCB, HandlerAtom, (fp, atomSize, atomType), _pHdlrAtom);
76 
77             if (!_pHdlrAtom->MP4Success())
78             {
79                 AtomUtils::seekFromStart(fp, currPtr);
80                 AtomUtils::seekFromCurrPos(fp, atomSize);
81                 PV_MP4_FF_DELETE(NULL, HandlerAtom, _pHdlrAtom);
82                 _pHdlrAtom = NULL;
83                 _count -= atomSize;
84             }
85 
86             if (_pHdlrAtom != NULL)
87             {
88                 if (_pHdlrAtom->getHandlerType() != ITUNES_MDIRAPPL_HDLR_PART1)
89                 {
90                     // Skip the parsing...
91                     fp->_pvfile.Seek(atomSize, Oscl_File::SEEKCUR);
92                     return;
93                 }
94                 _count -= _pHdlrAtom->getSize();
95             }
96         }
97         // Read the ilst Atom
98         else if (atomType == ITUNES_ILST_ATOM)
99         {
100             PV_MP4_FF_NEW(fp->auditCB, ITunesILSTAtom, (fp, atomSize, atomType), _pITunesILSTAtom);
101 
102             if (!_pITunesILSTAtom->MP4Success())
103             {
104                 AtomUtils::seekFromStart(fp, currPtr);
105                 AtomUtils::seekFromCurrPos(fp, atomSize);
106                 PV_MP4_FF_DELETE(NULL, ITunesILSTAtom, _pITunesILSTAtom);
107                 _pITunesILSTAtom = NULL;
108                 _count -= atomSize;
109             }
110             else
111                 _count -= _pITunesILSTAtom->getSize();
112         }
113     }
114 }
115 
~MetaDataAtom()116 MetaDataAtom::~MetaDataAtom()
117 {
118     if (_pHdlrAtom != NULL)
119     {
120         PV_MP4_FF_DELETE(NULL, HandlerAtom, _pHdlrAtom);
121     }
122     if (_pITunesILSTAtom != NULL)
123     {
124         PV_MP4_FF_DELETE(NULL, ITunesILSTAtom, _pITunesILSTAtom);
125     }
126 }
127