aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/libmp4v2/atom_text.cpp
blob: 290e73d7450aa5a08967b9a970136612500a5eac (plain) (blame)
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
/*
 * 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 "mp4common.h"

MP4TextAtom::MP4TextAtom() 
	: MP4Atom("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("reserved1", 6); /* 0 */

	AddProperty(new MP4Integer16Property("dataReferenceIndex"));/* 1 */

	AddProperty(new MP4Integer32Property("displayFlags")); /* 2 */
	AddProperty(new MP4Integer32Property("textJustification")); /* 3 */

	AddProperty(new MP4Integer16Property("bgColorRed")); /* 4 */
	AddProperty(new MP4Integer16Property("bgColorGreen")); /* 5 */
	AddProperty(new MP4Integer16Property("bgColorBlue")); /* 6 */

	AddProperty(new MP4Integer16Property("defTextBoxTop")); /* 7 */
	AddProperty(new MP4Integer16Property("defTextBoxLeft")); /* 8 */
	AddProperty(new MP4Integer16Property("defTextBoxBottom")); /* 9 */
	AddProperty(new MP4Integer16Property("defTextBoxRight")); /* 10 */

	AddReserved("reserved2", 8); /* 11 */

	AddProperty(new MP4Integer16Property("fontNumber")); /* 12 */
	AddProperty(new MP4Integer16Property("fontFace")); /* 13 */

	AddReserved("reserved3", 1); /* 14 */
	AddReserved("reserved4", 2); /* 15 */

	AddProperty(new MP4Integer16Property("foreColorRed")); /* 16 */
	AddProperty(new MP4Integer16Property("foreColorGreen")); /* 17 */
	AddProperty(new MP4Integer16Property("foreColorBlue")); /* 18 */

}

void MP4TextAtom::AddPropertiesGmhdType()
{

	AddProperty(new MP4BytesProperty("textData", 36)); /* 0 */

}


void MP4TextAtom::Generate()
{

	if (!strcmp(m_pParentAtom->GetType(), "stsd")) {
		AddPropertiesStsdType();
		GenerateStsdType();
	} else if (!strcmp(m_pParentAtom->GetType(), "gmhd")) {
		AddPropertiesGmhdType();
		GenerateGmhdType();
	} else {
		VERBOSE_WARNING(m_pFile->GetVerbosity(),
			printf("Warning: text atom in unexpected context, can not generate"));
	}

}

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 u_int8_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));
	
}