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 "editlistatom.h"
20 #include "atomutils.h"
21 #include "a_atomdefs.h"
22
23 // Constructor
PVA_FF_EditAtom()24 PVA_FF_EditAtom::PVA_FF_EditAtom()
25 : PVA_FF_Atom(FourCharConstToUint32('e', 'd', 't', 's'))
26 {
27 _size = getDefaultSize();
28
29 _peditList = NULL;
30
31 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_EditListAtom, (), _peditList);
32
33 _peditList->setParent(this);
34 }
35
36 bool
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)37 PVA_FF_EditAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp)
38 {
39 int32 rendered = 0; // Keep track of number of bytes rendered
40
41 recomputeSize();
42
43 // Render PVA_FF_Atom type and size
44 if (!renderAtomBaseMembers(fp))
45 {
46 return false;
47 }
48 rendered += getDefaultSize();
49
50 // Render the data of the members once they get implemented
51 if (!_peditList->renderToFileStream(fp))
52 {
53 return false;
54 }
55
56 return true;
57 }
58
59
addEditEntry(uint32 duration,int32 time,uint16 rate)60 void PVA_FF_EditAtom::addEditEntry(uint32 duration, int32 time, uint16 rate)
61 {
62 _peditList->addEditEntry(duration, time, rate);
63 recomputeSize();
64 }
65
addEmptyEdit(uint32 duration)66 void PVA_FF_EditAtom::addEmptyEdit(uint32 duration)
67 {
68 _peditList->addEditEntry(duration, -1, 1);
69 recomputeSize();
70 }
71
72
recomputeSize()73 void PVA_FF_EditAtom::recomputeSize()
74 {
75 _size = getDefaultSize();
76 _size += _peditList->getSize();
77
78 // Update the size of the parent atom since this child atom may have changed
79 if (_pparent != NULL)
80 {
81 _pparent->recomputeSize();
82 }
83 }
84
~PVA_FF_EditAtom()85 PVA_FF_EditAtom::~PVA_FF_EditAtom()
86 {
87 if (_peditList != NULL)
88 {
89 PV_MP4_FF_DELETE(NULL, PVA_FF_EditListAtom, _peditList);
90 }
91 }
92
93