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 * Contributor(s):
|
|
19 * Dave Mackie dmackie@cisco.com
|
|
20 */
|
|
21
|
|
22 #include "mp4common.h"
|
|
23
|
|
24 MP4TkhdAtom::MP4TkhdAtom()
|
|
25 : MP4Atom("tkhd")
|
|
26 {
|
|
27 AddVersionAndFlags();
|
|
28 }
|
|
29
|
|
30 void MP4TkhdAtom::AddProperties(u_int8_t version)
|
|
31 {
|
|
32 if (version == 1) {
|
|
33 AddProperty( /* 2 */
|
|
34 new MP4Integer64Property("creationTime"));
|
|
35 AddProperty( /* 3 */
|
|
36 new MP4Integer64Property("modificationTime"));
|
|
37 } else { // version == 0
|
|
38 AddProperty( /* 2 */
|
|
39 new MP4Integer32Property("creationTime"));
|
|
40 AddProperty( /* 3 */
|
|
41 new MP4Integer32Property("modificationTime"));
|
|
42 }
|
|
43
|
|
44 AddProperty( /* 4 */
|
|
45 new MP4Integer32Property("trackId"));
|
|
46 AddReserved("reserved1", 4); /* 5 */
|
|
47
|
|
48 if (version == 1) {
|
|
49 AddProperty( /* 6 */
|
|
50 new MP4Integer64Property("duration"));
|
|
51 } else {
|
|
52 AddProperty( /* 6 */
|
|
53 new MP4Integer32Property("duration"));
|
|
54 }
|
|
55
|
|
56 AddReserved("reserved2", 12); /* 7 */
|
|
57
|
|
58 MP4Float32Property* pProp;
|
|
59
|
|
60 pProp = new MP4Float32Property("volume");
|
|
61 pProp->SetFixed16Format();
|
|
62 AddProperty(pProp); /* 8 */
|
|
63
|
|
64 AddReserved("reserved3", 38); /* 9 */
|
|
65
|
|
66 pProp = new MP4Float32Property("width");
|
|
67 pProp->SetFixed32Format();
|
|
68 AddProperty(pProp); /* 10 */
|
|
69
|
|
70 pProp = new MP4Float32Property("height");
|
|
71 pProp->SetFixed32Format();
|
|
72 AddProperty(pProp); /* 11 */
|
|
73 }
|
|
74
|
|
75 void MP4TkhdAtom::Generate()
|
|
76 {
|
|
77 u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
|
|
78 SetVersion(version);
|
|
79 AddProperties(version);
|
|
80
|
|
81 MP4Atom::Generate();
|
|
82
|
|
83 // set creation and modification times
|
|
84 MP4Timestamp now = MP4GetAbsTimestamp();
|
|
85 if (version == 1) {
|
|
86 ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
|
|
87 ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
|
|
88 } else {
|
|
89 ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
|
|
90 ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
|
|
91 }
|
|
92
|
|
93 // property reserved3 has non-zero fixed values
|
|
94 static u_int8_t reserved3[38] = {
|
|
95 0x00, 0x00,
|
|
96 0x00, 0x01, 0x00, 0x00,
|
|
97 0x00, 0x00, 0x00, 0x00,
|
|
98 0x00, 0x00, 0x00, 0x00,
|
|
99 0x00, 0x00, 0x00, 0x00,
|
|
100 0x00, 0x01, 0x00, 0x00,
|
|
101 0x00, 0x00, 0x00, 0x00,
|
|
102 0x00, 0x00, 0x00, 0x00,
|
|
103 0x00, 0x00, 0x00, 0x00,
|
|
104 0x40, 0x00, 0x00, 0x00,
|
|
105 };
|
|
106 m_pProperties[9]->SetReadOnly(false);
|
|
107 ((MP4BytesProperty*)m_pProperties[9])->
|
|
108 SetValue(reserved3, sizeof(reserved3));
|
|
109 m_pProperties[9]->SetReadOnly(true);
|
|
110 }
|
|
111
|
|
112 void MP4TkhdAtom::Read()
|
|
113 {
|
|
114 /* read atom version */
|
|
115 ReadProperties(0, 1);
|
|
116
|
|
117 /* need to create the properties based on the atom version */
|
|
118 AddProperties(GetVersion());
|
|
119
|
|
120 /* now we can read the remaining properties */
|
|
121 ReadProperties(1);
|
|
122
|
|
123 Skip(); // to end of atom
|
|
124 }
|