16
|
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 MP4MvhdAtom::MP4MvhdAtom()
|
|
25 : MP4Atom("mvhd")
|
|
26 {
|
|
27 AddVersionAndFlags();
|
|
28 }
|
|
29
|
|
30 void MP4MvhdAtom::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 {
|
|
38 AddProperty( /* 2 */
|
|
39 new MP4Integer32Property("creationTime"));
|
|
40 AddProperty( /* 3 */
|
|
41 new MP4Integer32Property("modificationTime"));
|
|
42 }
|
|
43
|
|
44 AddProperty( /* 4 */
|
|
45 new MP4Integer32Property("timeScale"));
|
|
46
|
|
47 if (version == 1) {
|
|
48 AddProperty( /* 5 */
|
|
49 new MP4Integer64Property("duration"));
|
|
50 } else {
|
|
51 AddProperty( /* 5 */
|
|
52 new MP4Integer32Property("duration"));
|
|
53 }
|
|
54
|
|
55 MP4Float32Property* pProp;
|
|
56
|
|
57 pProp = new MP4Float32Property("rate");
|
|
58 pProp->SetFixed32Format();
|
|
59 AddProperty(pProp); /* 6 */
|
|
60
|
|
61 pProp = new MP4Float32Property("volume");
|
|
62 pProp->SetFixed16Format();
|
|
63 AddProperty(pProp); /* 7 */
|
|
64
|
|
65 AddReserved("reserved1", 70); /* 8 */
|
|
66
|
|
67 AddProperty( /* 9 */
|
|
68 new MP4Integer32Property("nextTrackId"));
|
|
69 }
|
|
70
|
|
71 void MP4MvhdAtom::Generate()
|
|
72 {
|
|
73 u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
|
|
74 SetVersion(version);
|
|
75 AddProperties(version);
|
|
76
|
|
77 MP4Atom::Generate();
|
|
78
|
|
79 // set creation and modification times
|
|
80 MP4Timestamp now = MP4GetAbsTimestamp();
|
|
81 if (version == 1) {
|
|
82 ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
|
|
83 ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
|
|
84 } else {
|
|
85 ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
|
|
86 ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
|
|
87 }
|
|
88
|
|
89 ((MP4Integer32Property*)m_pProperties[4])->SetValue(1000);
|
|
90
|
|
91 ((MP4Float32Property*)m_pProperties[6])->SetValue(1.0);
|
|
92 ((MP4Float32Property*)m_pProperties[7])->SetValue(1.0);
|
|
93
|
|
94 // property reserved has non-zero fixed values
|
|
95 static u_int8_t reserved[70] = {
|
|
96 0x00, 0x00,
|
|
97 0x00, 0x00, 0x00, 0x00,
|
|
98 0x00, 0x00, 0x00, 0x00,
|
|
99 0x00, 0x01, 0x00, 0x00,
|
|
100 0x00, 0x00, 0x00, 0x00,
|
|
101 0x00, 0x00, 0x00, 0x00,
|
|
102 0x00, 0x00, 0x00, 0x00,
|
|
103 0x00, 0x01, 0x00, 0x00,
|
|
104 0x00, 0x00, 0x00, 0x00,
|
|
105 0x00, 0x00, 0x00, 0x00,
|
|
106 0x00, 0x00, 0x00, 0x00,
|
|
107 0x40, 0x00, 0x00, 0x00,
|
|
108 0x00, 0x00, 0x00, 0x00,
|
|
109 0x00, 0x00, 0x00, 0x00,
|
|
110 0x00, 0x00, 0x00, 0x00,
|
|
111 0x00, 0x00, 0x00, 0x00,
|
|
112 0x00, 0x00, 0x00, 0x00,
|
|
113 0x00, 0x00, 0x00, 0x00,
|
|
114 };
|
|
115 m_pProperties[8]->SetReadOnly(false);
|
|
116 ((MP4BytesProperty*)m_pProperties[8])->
|
|
117 SetValue(reserved, sizeof(reserved));
|
|
118 m_pProperties[8]->SetReadOnly(true);
|
|
119
|
|
120 // set next track id
|
|
121 ((MP4Integer32Property*)m_pProperties[9])->SetValue(1);
|
|
122 }
|
|
123
|
|
124 void MP4MvhdAtom::Read()
|
|
125 {
|
|
126 /* read atom version */
|
|
127 ReadProperties(0, 1);
|
|
128
|
|
129 /* need to create the properties based on the atom version */
|
|
130 AddProperties(GetVersion());
|
|
131
|
|
132 /* now we can read the remaining properties */
|
|
133 ReadProperties(1);
|
|
134
|
|
135 Skip(); // to end of atom
|
|
136 }
|