• 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 #define IMPLEMENT_MovieExtendsHeaderAtom
19 
20 #include "movieextendsheaderatom.h"
21 #include "a_isucceedfail.h"
22 #include "atomutils.h"
23 
24 
25 // constructor
PVA_FF_MovieExtendsHeaderAtom()26 PVA_FF_MovieExtendsHeaderAtom::PVA_FF_MovieExtendsHeaderAtom()
27         : PVA_FF_FullAtom(MOVIE_EXTENDS_HEADER_ATOM, (uint8)0, (uint32)0)
28 {
29     _fragmentDuration = 0;
30     _fileOffset = 0;
31     _oRendered = false;
32     recomputeSize();
33 
34 }
35 
36 //destructor
~PVA_FF_MovieExtendsHeaderAtom()37 PVA_FF_MovieExtendsHeaderAtom::~PVA_FF_MovieExtendsHeaderAtom()
38 {
39     // do nothing
40 }
41 
42 
43 // return fragment duration
44 uint32
getFragmentDuration(void)45 PVA_FF_MovieExtendsHeaderAtom::getFragmentDuration(void)
46 {
47     return _fragmentDuration;
48 }
49 
50 
51 // set fragment duration
52 void
setFragmentDuration(uint32 duration)53 PVA_FF_MovieExtendsHeaderAtom::setFragmentDuration(uint32 duration)
54 {
55     _fragmentDuration = duration;
56 }
57 
58 
59 // update the value of fragment duration for new sample
60 void
updateMovieFragmentDuration(uint32 ts)61 PVA_FF_MovieExtendsHeaderAtom::updateMovieFragmentDuration(uint32 ts)
62 {
63     if (ts > _fragmentDuration)
64     {
65         _fragmentDuration = ts;
66     }
67 }
68 
69 // write the duration value at the file offset stored during rendering
70 void
writeMovieFragmentDuration(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)71 PVA_FF_MovieExtendsHeaderAtom::writeMovieFragmentDuration(MP4_AUTHOR_FF_FILE_IO_WRAP* fp)
72 {
73     uint32 fileWriteOffset;
74 
75     fileWriteOffset = PVA_FF_AtomUtils::getCurrentFilePosition(fp);
76 
77     PVA_FF_AtomUtils::seekFromStart(fp, _fileOffset);
78 
79     if (_oRendered == true)
80     {
81         PVA_FF_AtomUtils::render32(fp, _fragmentDuration);
82     }
83 
84     PVA_FF_AtomUtils::seekFromStart(fp, fileWriteOffset);
85 }
86 
87 
88 // recompute size of atom
89 void
recomputeSize()90 PVA_FF_MovieExtendsHeaderAtom::recomputeSize()
91 {
92     int32 size = getDefaultSize();
93 
94     size += 4; // For fragment duration
95 
96     _size = size;
97 
98     // Update the parent atom size
99     if (_pparent != NULL)
100     {
101         _pparent->recomputeSize();
102     }
103 }
104 
105 
106 // write atom to the target file
107 bool
renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP * fp)108 PVA_FF_MovieExtendsHeaderAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP* fp)
109 {
110     uint32 rendered = 0;
111 
112     if (!renderAtomBaseMembers(fp))
113     {
114         return false;
115     }
116     rendered += getDefaultSize();
117 
118     // store file offset to modify duration later
119     _fileOffset = PVA_FF_AtomUtils::getCurrentFilePosition(fp);
120 
121     if (!PVA_FF_AtomUtils::render32(fp, _fragmentDuration))
122     {
123         return false;
124     }
125 
126     rendered += 4;
127 
128     _oRendered = true;
129 
130     return true;
131 }
132