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 MP4MdhdAtom::MP4MdhdAtom()
|
|
25 : MP4Atom("mdhd")
|
|
26 {
|
|
27 AddVersionAndFlags();
|
|
28 }
|
|
29
|
|
30 void MP4MdhdAtom::AddProperties(u_int8_t version)
|
|
31 {
|
|
32 if (version == 1) {
|
|
33 AddProperty(
|
|
34 new MP4Integer64Property("creationTime"));
|
|
35 AddProperty(
|
|
36 new MP4Integer64Property("modificationTime"));
|
|
37 } else {
|
|
38 AddProperty(
|
|
39 new MP4Integer32Property("creationTime"));
|
|
40 AddProperty(
|
|
41 new MP4Integer32Property("modificationTime"));
|
|
42 }
|
|
43
|
|
44 AddProperty(
|
|
45 new MP4Integer32Property("timeScale"));
|
|
46
|
|
47 if (version == 1) {
|
|
48 AddProperty(
|
|
49 new MP4Integer64Property("duration"));
|
|
50 } else {
|
|
51 AddProperty(
|
|
52 new MP4Integer32Property("duration"));
|
|
53 }
|
|
54
|
|
55 AddProperty(
|
|
56 new MP4Integer16Property("language"));
|
|
57 AddReserved("reserved", 2);
|
|
58 }
|
|
59
|
|
60 void MP4MdhdAtom::Generate()
|
|
61 {
|
|
62 u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
|
|
63 SetVersion(version);
|
|
64 AddProperties(version);
|
|
65
|
|
66 MP4Atom::Generate();
|
|
67
|
|
68 // set creation and modification times
|
|
69 MP4Timestamp now = MP4GetAbsTimestamp();
|
|
70 if (version == 1) {
|
|
71 ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
|
|
72 ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
|
|
73 } else {
|
|
74 ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
|
|
75 ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
|
|
76 }
|
|
77 }
|
|
78
|
|
79 void MP4MdhdAtom::Read()
|
|
80 {
|
|
81 /* read atom version */
|
|
82 ReadProperties(0, 1);
|
|
83
|
|
84 /* need to create the properties based on the atom version */
|
|
85 AddProperties(GetVersion());
|
|
86
|
|
87 /* now we can read the remaining properties */
|
|
88 ReadProperties(1);
|
|
89
|
|
90 Skip(); // to end of atom
|
|
91 }
|