61
|
1 /*
|
|
2 * The contents of this file are subject to the Mozilla Public
|
|
3 * License Version 1.1 (the "License"); you may not use this file
|
|
4 * except in compliance with the License. You may obtain a copy of
|
|
5 * the License at http://www.mozilla.org/MPL/
|
|
6 *
|
|
7 * Software distributed under the License is distributed on an "AS
|
|
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
9 * implied. See the License for the specific language governing
|
|
10 * rights and limitations under the License.
|
|
11 *
|
|
12 * The Original Code is MPEG4IP.
|
|
13 *
|
|
14 * The Initial Developer of the Original Code is Cisco Systems Inc.
|
|
15 * Portions created by Cisco Systems Inc. are
|
|
16 * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
|
|
17 *
|
|
18 * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
|
|
19 * and was contributed by Ximpo Group Ltd.
|
|
20 *
|
|
21 * Portions created by Ximpo Group Ltd. are
|
|
22 * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
|
|
23 *
|
|
24 * Contributor(s):
|
|
25 * Ximpo Group Ltd. mp4v2@ximpo.com
|
|
26 */
|
|
27
|
|
28 #include "mp4common.h"
|
|
29
|
|
30 #define _3GP_MAJOR_BRAND "3gp5"
|
|
31 #define _3GP_MINOR_VERSION 0x0001
|
|
32
|
|
33 void MP4File::Make3GPCompliant(const char* fileName, char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount, bool deleteIodsAtom)
|
|
34 {
|
|
35 char brand[5] = "3gp5";
|
|
36 char* _3gpSupportedBrands[1] = { (char*)&brand };
|
|
37
|
|
38 if (majorBrand) {
|
|
39 if (!supportedBrands || !supportedBrandsCount) {
|
|
40 throw new MP4Error("Invalid parameters", "MP4File::Make3GPCompliant");
|
|
41 }
|
|
42 }
|
|
43
|
|
44 MakeFtypAtom(
|
|
45 majorBrand ? majorBrand : (char*)brand,
|
|
46 majorBrand ? minorVersion : _3GP_MINOR_VERSION,
|
|
47 majorBrand ? supportedBrands : (char**)_3gpSupportedBrands,
|
|
48 majorBrand ? supportedBrandsCount : 1);
|
|
49
|
|
50 if (deleteIodsAtom) {
|
|
51 // Delete the iods atom, if it exists....
|
|
52 MP4Atom* iodsAtom = m_pRootAtom->FindAtom("moov.iods");
|
|
53 if (iodsAtom) {
|
|
54 MP4Atom* moovAtom = m_pRootAtom->FindAtom("moov");
|
|
55 ASSERT(moovAtom);
|
|
56
|
|
57 moovAtom->DeleteChildAtom(iodsAtom);
|
|
58 }
|
|
59 }
|
|
60
|
|
61 }
|
|
62
|
|
63 void MP4File::MakeFtypAtom(char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount)
|
|
64 {
|
|
65 bool rewriteNeeded = false;
|
|
66 u_int32_t currentSupportedBrandsCount;
|
|
67 u_int32_t i;
|
|
68
|
|
69
|
|
70 MP4Atom* ftypAtom = m_pRootAtom->FindAtom("ftyp");
|
|
71 if (ftypAtom == NULL) {
|
|
72 ftypAtom = InsertChildAtom(m_pRootAtom, "ftyp", 0);
|
|
73 }
|
|
74 if (majorBrand == NULL)
|
|
75 return;
|
|
76 MP4StringProperty* pMajorBrandProperty;
|
|
77 ftypAtom->FindProperty(
|
|
78 "ftyp.majorBrand",
|
|
79 (MP4Property**)&pMajorBrandProperty);
|
|
80
|
|
81 pMajorBrandProperty->SetValue(majorBrand);
|
|
82
|
|
83
|
|
84 MP4Integer32Property* pMinorVersionProperty;
|
|
85 ftypAtom->FindProperty(
|
|
86 "ftype.minorVersion",
|
|
87 (MP4Property**)&pMinorVersionProperty);
|
|
88
|
|
89 pMinorVersionProperty->SetValue(minorVersion);
|
|
90
|
|
91 MP4Integer32Property* pCompatibleBrandsCountProperty;
|
|
92 ftypAtom->FindProperty(
|
|
93 "ftyp.compatibleBrandsCount",
|
|
94 (MP4Property**)&pCompatibleBrandsCountProperty);
|
|
95
|
|
96 currentSupportedBrandsCount = pCompatibleBrandsCountProperty->GetValue();
|
|
97
|
|
98 MP4TableProperty* pCompatibleBrandsProperty;
|
|
99 ftypAtom->FindProperty(
|
|
100 "ftyp.compatibleBrands",
|
|
101 (MP4Property**)&pCompatibleBrandsProperty);
|
|
102
|
|
103 MP4StringProperty* pBrandProperty = (MP4StringProperty*)
|
|
104 pCompatibleBrandsProperty->GetProperty(0);
|
|
105 ASSERT(pBrandProperty);
|
|
106
|
|
107 for (i = 0 ; i < ((currentSupportedBrandsCount > supportedBrandsCount) ? supportedBrandsCount : currentSupportedBrandsCount) ; i++) {
|
|
108 pBrandProperty->SetValue(supportedBrands[i], i);
|
|
109
|
|
110 }
|
|
111
|
|
112 if (i < supportedBrandsCount) {
|
|
113 for ( ; i < supportedBrandsCount ; i++) {
|
|
114 pBrandProperty->AddValue(supportedBrands[i]);
|
|
115 }
|
|
116 }
|
|
117
|
|
118 if (currentSupportedBrandsCount != supportedBrandsCount) {
|
|
119 rewriteNeeded = true;
|
|
120 pBrandProperty->SetCount(supportedBrandsCount);
|
|
121 pCompatibleBrandsCountProperty->SetReadOnly(false);
|
|
122 pCompatibleBrandsCountProperty->SetValue(supportedBrandsCount);
|
|
123 pCompatibleBrandsCountProperty->SetReadOnly(true);
|
|
124 }
|
|
125
|
|
126 }
|