• 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 "editlistatom.h"
19 #include "atomutils.h"
20 
21 typedef Oscl_Vector<uint32, OsclMemAllocator> uint32VecType;
22 typedef Oscl_Vector<int32, OsclMemAllocator> int32VecType;
23 typedef Oscl_Vector<uint16, OsclMemAllocator> uint16VecType;
24 
25 //WMF
EditListAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)26 EditListAtom::EditListAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
27         : FullAtom(fp, size, type)
28 {
29     uint32  i = 0, temp = 0;
30     uint16 temp_16;
31 
32     _psegmentDurations = NULL;
33     _pmediaTimes       = NULL;
34     _pmediaRates       = NULL;
35     _preserveds        = NULL;
36 
37     if (_success)
38     {
39 
40         PV_MP4_FF_NEW(fp->auditCB, uint32VecType, (), _psegmentDurations);
41         PV_MP4_FF_NEW(fp->auditCB, int32VecType, (), _pmediaTimes);
42         PV_MP4_FF_NEW(fp->auditCB, uint16VecType, (), _pmediaRates);
43         PV_MP4_FF_NEW(fp->auditCB, uint16VecType, (), _preserveds);
44 
45         AtomUtils::read32(fp, _entryCount);
46 
47         uint32 dataSize = _size - (DEFAULT_FULL_ATOM_SIZE + 4);
48 
49         uint32 entrySize = (4 + 4 + 2 + 2);
50 
51         if ((_entryCount*entrySize) > dataSize)
52         {
53             _success = false;
54             _mp4ErrorCode = READ_EDITLIST_ATOM_FAILED;
55             return;
56         }
57 
58         for (i = 0; i < _entryCount; i++)
59         {//only assume version 0 by now.
60 
61             AtomUtils::read32(fp, temp);
62             (*_psegmentDurations).push_back(temp);
63 
64             AtomUtils::read32(fp, temp);
65             (*_pmediaTimes).push_back(temp);
66 
67             AtomUtils::read16(fp, temp_16);
68             (*_pmediaRates).push_back(temp_16);
69 
70             AtomUtils::read16(fp, temp_16); //just for reserve
71             (*_preserveds).push_back(temp_16);
72 
73         }
74     }
75     else
76     {
77         if (_mp4ErrorCode != ATOM_VERSION_NOT_SUPPORTED)
78             _mp4ErrorCode = READ_EDITLIST_ATOM_FAILED;
79     }
80 }
81 
getInitialTimeOffset()82 uint32 EditListAtom::getInitialTimeOffset()
83 {
84     if ((_pmediaTimes == NULL) ||
85             (_psegmentDurations == NULL))
86     {
87         return 0;
88     }
89 
90     if (_pmediaTimes->size() != 0)
91     {
92         if ((*_pmediaTimes)[0] == -1)
93         {
94             return((*_psegmentDurations)[0]);
95         }
96         else
97         {
98             return 0;
99         }
100     }
101     else
102     {
103         return 0;
104     }
105 }
106 
107 // Destructor
~EditListAtom()108 EditListAtom::~EditListAtom()
109 {
110     if (_psegmentDurations != NULL)
111     {
112         PV_MP4_FF_TEMPLATED_DELETE(NULL, uint32VecType, Oscl_Vector, _psegmentDurations);
113     }
114     if (_pmediaTimes != NULL)
115     {
116         PV_MP4_FF_TEMPLATED_DELETE(NULL, int32VecType, Oscl_Vector, _pmediaTimes);
117     }
118     if (_pmediaRates != NULL)
119     {
120         PV_MP4_FF_TEMPLATED_DELETE(NULL, uint16VecType, Oscl_Vector, _pmediaRates);
121     }
122     if (_preserveds != NULL)
123     {
124         PV_MP4_FF_TEMPLATED_DELETE(NULL, uint16VecType, Oscl_Vector, _preserveds);
125     }
126 }
127