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 "editatom.h"
19 #include "atomutils.h"
20 #include "atomdefs.h"
21
22 typedef Oscl_Vector<EditListAtom*, OsclMemAllocator> editListAtomVecType;
23
24 //WMF
25 // Stream-in Constructor
EditAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)26 EditAtom::EditAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
27 : Atom(fp, size, type)
28 {
29 _pEditListVec = NULL;
30
31 if (_success)
32 {
33 int32 dataLength;
34
35 PV_MP4_FF_NEW(fp->auditCB, editListAtomVecType, (), _pEditListVec);
36
37 //multiple editlist atom within one edit atom
38 dataLength = getSize() - 8;
39 while (dataLength > 0)
40 {
41 uint32 atomType = UNKNOWN_ATOM;
42 uint32 atomSize = 0;
43
44 AtomUtils::getNextAtomType(fp, atomSize, atomType);
45
46 if (atomType == EDIT_LIST_ATOM)
47 {
48 EditListAtom *_pEditList = NULL;
49
50 PV_MP4_FF_NEW(fp->auditCB, EditListAtom, (fp, atomSize, atomType), _pEditList);
51
52 if (!_pEditList->MP4Success())
53 {
54 _success = false;
55 _mp4ErrorCode = _pEditList->GetMP4Error();
56 PV_MP4_FF_DELETE(NULL, EditListAtom, _pEditList);
57 break;
58 }
59 (*_pEditListVec).push_back(_pEditList);
60 dataLength -= _pEditList->getSize();
61 }
62 else
63 {
64 _success = false;
65 _mp4ErrorCode = READ_UNKNOWN_ATOM;
66 break;
67 }
68
69 }
70 }
71 }
72
getInitialTimeOffset()73 uint32 EditAtom::getInitialTimeOffset()
74 {
75 if (_pEditListVec == NULL)
76 {
77 return 0;
78 }
79
80 //only assume one edit list atom in edit atom, so get element 0
81 if (_pEditListVec->size() != 0)
82 {
83 return (*_pEditListVec)[0]->getInitialTimeOffset();
84 }
85 else
86 {
87 return 0;
88 }
89 }
90
91 // Destructor
~EditAtom()92 EditAtom::~EditAtom()
93 {
94 uint32 i;
95
96 if (_pEditListVec != NULL)
97 {
98 for (i = 0; i < _pEditListVec->size(); i++)
99 PV_MP4_FF_DELETE(NULL, EditListAtom, (*_pEditListVec)[i]);
100
101 PV_MP4_FF_TEMPLATED_DELETE(NULL, editListAtomVecType, Oscl_Vector, _pEditListVec);
102 }
103 }
104