-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatroskaChapterData.cpp
216 lines (171 loc) · 5.48 KB
/
MatroskaChapterData.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* Part of The TCMP Matroska CDL, a plugin to access extra features of Matroska files with TCMP
*
* MatroskaChapterData.cpp
*
* Copyright (C) Jory Stone - February 2004
*
* The TCMP Matroska CDL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* The TCMP Matroska CDL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with The TCMP Matroska CDL; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*!
\file MatroskaChapterData.cpp
\version \$Id: MatroskaChapterData.cpp,v 1.4 2004/03/20 05:08:30 jcsston Exp $
\brief Code to handle Matroska Chapters
\author Jory Stone <jcsston @ toughguy.net>
*/
#include "MatroskaChapterData.h"
#include <Shlwapi.h>
using namespace MatroskaUtilsNamespace;
namespace MatroskaUtilsNamespace {
void MatroskaChapterList::Add(MatroskaChapterEntry *chapter)
{
assert(chapter != NULL);
for (size_t c = 0; c < size(); c++)
if (at(c)->chapterUID == chapter->chapterUID)
return;
push_back(chapter);
}
MatroskaChapterList::~MatroskaChapterList()
{
for (size_t c = 0; c < size(); c++)
delete at(c);
}
#ifdef USING_TINYXML
void MatroskaChapterList::ListAsXML(TiXmlElement &baseElement)
{
size_t i;
for (i = 0; i < size(); i++) {
at(i)->ListAsXML(baseElement);
}
}
#endif
MatroskaChapterDisplayInfo::MatroskaChapterDisplayInfo()
{
string = L" ";
lang = "eng";
};
MatroskaChapterDisplayInfo::~MatroskaChapterDisplayInfo()
{
};
MatroskaChapterEntry::MatroskaChapterEntry()
{
chapterUID = 0;
timeStart = 0;
timeEnd = 0;
parent = NULL;
}
MatroskaChapterEntry::MatroskaChapterEntry(MatroskaChapterEntry *_parent)
{
assert(_parent != NULL);
MatroskaChapterEntry();
parent = _parent;
}
MatroskaChapterEntry::~MatroskaChapterEntry()
{
}
UTFstring &MatroskaChapterEntry::GetTimeStartStr()
{
if (m_timeStartStr.length() == 0) {
wchar_t buffer[256];
#ifdef WIN32
StrFromTimeIntervalW(buffer, 255, (DWORD)timeStart, 5);
m_timeStartStr = buffer;
#else
m_timeStartStr = L"";
#endif
}
return m_timeStartStr;
}
UTFstring &MatroskaChapterEntry::GetTimeEndStr()
{
if (m_timeEndStr.length() == 0) {
wchar_t buffer[256];
#ifdef WIN32
StrFromTimeIntervalW(buffer, 255, (DWORD)timeEnd, 5);
m_timeEndStr = buffer;
#else
m_timeEndStr = L"";
#endif
}
return m_timeEndStr;
}
#ifdef USING_TINYXML
void MatroskaChapterEntry::ListAsXML(TiXmlElement &baseElement)
{
size_t i;
uint32 HH, MM, SS, mm;
char buffer[65];
TiXmlElement chapterElement("ChapterAtom");
#if 0
TiXmlElement chapterUIDElement("ChapterUID");
snprintf(buffer, 64, "%u", chapterUID);
TiXmlText chapterUIDText(buffer);
chapterUIDElement.InsertEndChild(chapterUIDText);
chapterElement.InsertEndChild(chapterUIDElement);
#endif
TiXmlElement chapterTimeStartElement("ChapterTimeStart");
HH = timeStart / 1000 / 60 / 60;
MM = (timeStart / 1000 / 60) % 60;
SS = (timeStart / 1000) % 60;
mm = timeStart % 1000;
snprintf(buffer, 64, "%02u:%02u:%02u.%03u", HH, MM, SS, mm);
TiXmlText chapterTimeStartText(buffer);
chapterTimeStartElement.InsertEndChild(chapterTimeStartText);
chapterElement.InsertEndChild(chapterTimeStartElement);
TiXmlElement chapterTimeEndElement("ChapterTimeEnd");
HH = timeEnd / 1000 / 60 / 60;
MM = (timeEnd / 1000 / 60) % 60;
SS = (timeEnd / 1000) % 60;
mm = timeEnd % 1000;
snprintf(buffer, 64, "%02u:%02u:%02u.%03u", HH, MM, SS, mm);
TiXmlText chapterTimeEndText(buffer);
chapterTimeEndElement.InsertEndChild(chapterTimeEndText);
chapterElement.InsertEndChild(chapterTimeEndElement);
for (i = 0; i < display.size(); i++) {
MatroskaChapterDisplayInfo &displayInfo = display.at(i);
TiXmlElement chapterDisplayElement("ChapterDisplay");
//if (displayInfo.string.length() > 0) {
TiXmlElement chapterStringElement("ChapterString");
TiXmlText chapterStringText(displayInfo.string.GetUTF8().c_str());
chapterStringElement.InsertEndChild(chapterStringText);
chapterDisplayElement.InsertEndChild(chapterStringElement);
//}
//if (displayInfo.lang.length() > 0) {
TiXmlElement chapterLanguageElement("ChapterLanguage");
TiXmlText chapterLanguageText(displayInfo.lang.c_str());
chapterLanguageElement.InsertEndChild(chapterLanguageText);
chapterDisplayElement.InsertEndChild(chapterLanguageElement);
//}
if (displayInfo.country.length() > 0) {
TiXmlElement chapterTimeEndElement("ChapterCountry");
TiXmlText chapterTimeEndText(displayInfo.country.c_str());
chapterTimeEndElement.InsertEndChild(chapterTimeEndText);
chapterDisplayElement.InsertEndChild(chapterTimeEndElement);
}
chapterElement.InsertEndChild(chapterDisplayElement);
}
for (i = 0; i < tracks.size(); i++) {
TiXmlElement chapterTrackNumberElement("ChapterTrackNumber");
snprintf(buffer, 255, "%u", (uint32)tracks.at(i));
TiXmlText chapterTrackNumberText(buffer);
chapterTrackNumberElement.InsertEndChild(chapterTrackNumberText);
chapterElement.InsertEndChild(chapterTrackNumberElement);
}
children.ListAsXML(chapterElement);
baseElement.InsertEndChild(chapterElement);
}
#endif // USING_TINYXML
}; // namespace MatroskaUtilsNamespace