-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathatom_text.cpp
147 lines (115 loc) · 4.27 KB
/
atom_text.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* Contributer has declined to give copyright information, and gives
* it freely to the world.
*/
#include "src/impl.h"
namespace mp4v2 {
namespace impl {
///////////////////////////////////////////////////////////////////////////////
MP4TextAtom::MP4TextAtom(MP4File &file)
: MP4Atom(file, "text")
{
// The atom type "text" is used in two complete unrelated ways
// i.e. it's real two atoms with the same name
// To handle that we need to postpone property creation until
// we know who our parent atom is (stsd or gmhd) which gives us
// the context info we need to know who we are
}
void MP4TextAtom::AddPropertiesStsdType()
{
AddReserved(*this, "reserved1", 6); /* 0 */
AddProperty(new MP4Integer16Property(*this, "dataReferenceIndex"));/* 1 */
AddProperty(new MP4Integer32Property(*this, "displayFlags")); /* 2 */
AddProperty(new MP4Integer32Property(*this, "textJustification")); /* 3 */
AddProperty(new MP4Integer16Property(*this, "bgColorRed")); /* 4 */
AddProperty(new MP4Integer16Property(*this, "bgColorGreen")); /* 5 */
AddProperty(new MP4Integer16Property(*this, "bgColorBlue")); /* 6 */
AddProperty(new MP4Integer16Property(*this, "defTextBoxTop")); /* 7 */
AddProperty(new MP4Integer16Property(*this, "defTextBoxLeft")); /* 8 */
AddProperty(new MP4Integer16Property(*this, "defTextBoxBottom")); /* 9 */
AddProperty(new MP4Integer16Property(*this, "defTextBoxRight")); /* 10 */
AddReserved(*this, "reserved2", 8); /* 11 */
AddProperty(new MP4Integer16Property(*this, "fontNumber")); /* 12 */
AddProperty(new MP4Integer16Property(*this, "fontFace")); /* 13 */
AddReserved(*this, "reserved3", 1); /* 14 */
AddReserved(*this, "reserved4", 2); /* 15 */
AddProperty(new MP4Integer16Property(*this, "foreColorRed")); /* 16 */
AddProperty(new MP4Integer16Property(*this, "foreColorGreen")); /* 17 */
AddProperty(new MP4Integer16Property(*this, "foreColorBlue")); /* 18 */
}
void MP4TextAtom::AddPropertiesGmhdType()
{
AddProperty(new MP4BytesProperty(*this, "textData", 36)); /* 0 */
}
void MP4TextAtom::Generate()
{
ASSERT(m_pParentAtom);
if (ATOMID(m_pParentAtom->GetType()) == ATOMID("stsd")) {
AddPropertiesStsdType();
GenerateStsdType();
} else if (ATOMID(m_pParentAtom->GetType()) == ATOMID("gmhd")) {
AddPropertiesGmhdType();
GenerateGmhdType();
} else {
log.warningf("%s: \"%s\": text atom in unexpected context, can not generate", __FUNCTION__,
GetFile().GetFilename().c_str());
}
}
void MP4TextAtom::GenerateStsdType()
{
// generate children
MP4Atom::Generate();
((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
((MP4Integer32Property*)m_pProperties[2])->SetValue(1);
((MP4Integer32Property*)m_pProperties[3])->SetValue(1);
}
void MP4TextAtom::GenerateGmhdType()
{
MP4Atom::Generate();
// property 0 has non-zero fixed values
static uint8_t textData[36] = {
0x00, 0x01,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x01,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x40, 0x00,
0x00, 0x00,
};
((MP4BytesProperty*)m_pProperties[0])->SetValue(textData, sizeof(textData));
}
void MP4TextAtom::Read ()
{
if (ATOMID(m_pParentAtom->GetType()) == ATOMID("stsd")) {
AddPropertiesStsdType();
} else if (ATOMID(m_pParentAtom->GetType()) == ATOMID("gmhd")) {
AddPropertiesGmhdType();
}
MP4Atom::Read();
}
///////////////////////////////////////////////////////////////////////////////
}
} // namespace mp4v2::impl