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 "filetypeatom.h"
19 #include "atomutils.h"
20
21 typedef Oscl_Vector<uint32, OsclMemAllocator> uint32VecType;
22
FileTypeAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)23 OSCL_EXPORT_REF FileTypeAtom::FileTypeAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
24 : Atom(fp, size, type)
25 {
26 uint32 i, brandName, atomSize;
27
28 _pCompatible_brand = NULL;
29 _pMajorBrand = 0;
30 _pVersion = 0;
31 if (_success)
32 {
33 PV_MP4_FF_NEW(fp->auditCB, uint32VecType, (), _pCompatible_brand);
34
35
36 // ftype size is only 8. In that case we should not read beyond the atom boundry blindly
37 atomSize = getSize();
38 int32 count = atomSize;
39 count -= DEFAULT_ATOM_SIZE;
40
41 if (atomSize >= MINIMUM_SIZE_REQUIRED_TO_READ_MAJOR_BRAND)
42 {
43 AtomUtils::read32(fp, _pMajorBrand);
44 count -= 4;
45 }
46
47 // Read only when it is inside the atom size specified. dont just assume that it is present
48 if (atomSize >= MINIMUM_SIZE_REQUIRED_TO_READ_MINOR_VERSION)
49 {
50 AtomUtils::read32(fp, _pVersion);
51 count -= 4;
52 }
53
54 //subtract 16 bytes, 4 from tag and 4 from size 4 from Brand and 4 from Version, now I assume
55 //the size if the total atom
56
57 if (atomSize >= 16)
58 {
59 for (i = 0; i < atomSize - 16; i += 4)
60 {
61 if (count >= 4)
62 {
63 AtomUtils::read32(fp, brandName);
64 (*_pCompatible_brand).push_back(brandName);
65 count -= 4;
66 }
67 }
68 }
69 if (count > 0)
70 {
71 AtomUtils::seekFromCurrPos(fp, count);
72 }
73 }
74 else
75 {
76 _success = false;
77 _mp4ErrorCode = READ_FILE_TYPE_ATOM_FAILED;
78 }
79 }
80
81
82 // Destructor
~FileTypeAtom()83 OSCL_EXPORT_REF FileTypeAtom::~FileTypeAtom()
84 {
85 if (_pCompatible_brand != NULL)
86 PV_MP4_FF_TEMPLATED_DELETE(NULL, uint32VecType, Oscl_Vector, _pCompatible_brand);
87 }
88
89