Debian Codegraph @

components/tagger/tocplist/tocplist.cpp

raw symbols SCIP
1 /* BoCA - BonkEnc Component Architecture
2 * Copyright (C) 2007-2017 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include <smooth.h>
14
15 #include "tocplist.h"
16
17 const String &BoCA::TaggerTOCPList::GetComponentSpecs()
18 {
19 static String componentSpecs = " \
20 \
21 <?xml version=\"1.0\" encoding=\"UTF-8\"?> \
22 <component> \
23 <name>.TOC.plist Parser</name> \
24 <version>1.0</version> \
25 <id>tocplist-tag</id> \
26 <type>tagger</type> \
27 </component> \
28 \
29 ";
30
31 return componentSpecs;
32 }
33
34 BoCA::TaggerTOCPList::TaggerTOCPList()
35 {
36 }
37
38 BoCA::TaggerTOCPList::~TaggerTOCPList()
39 {
40 }
41
42 Error BoCA::TaggerTOCPList::ParseStreamInfo(const String &fileName, Track &track)
43 {
44 String pListFile = fileName.Head(fileName.FindLast(Directory::GetDirectoryDelimiter()) + 1).Append(".TOC.plist");
45
46 if (!File(pListFile).Exists()) return Success();
47
48 Bool error = False;
49 XML::Document *pList = new XML::Document();
50
51 if (pList->LoadFile(pListFile) == Success())
52 {
53 XML::Node *root = pList->GetRootNode();
54 XML::Node *dict = root->GetNodeByName("dict");
55
56 for (Int i = 0; i < dict->GetNOfNodes(); i++)
57 {
58 /* Look for sessions key.
59 */
60 XML::Node *node = dict->GetNthNode(i);
61
62 if (node->GetName() != "key" || node->GetContent() != "Sessions") continue;
63
64 /* Parse sessions and build MCDI.
65 */
66 Buffer<UnsignedByte> mcdi(4);
67 Int32 address;
68 XML::Node *array = dict->GetNthNode(++i);
69
70 if (array->GetName() == "array") ReadSessions(array, mcdi, address);
71
72 if (mcdi.Size() > 4)
73 {
74 ((UnsignedByte *) mcdi)[0] = ((mcdi.Size() + 6) >> 8) & 255;
75 ((UnsignedByte *) mcdi)[1] = (mcdi.Size() + 6) & 255;
76 ((UnsignedByte *) mcdi)[2] = ((UnsignedByte *) mcdi)[6];
77 ((UnsignedByte *) mcdi)[3] = ((UnsignedByte *) mcdi)[mcdi.Size() - 6];
78
79 /* Add lead-out entry.
80 */
81 Int offset = mcdi.Size();
82
83 mcdi.Resize(offset + 8);
84
85 ((UnsignedByte *) mcdi)[offset + 0] = 0;
86 ((UnsignedByte *) mcdi)[offset + 1] = 16;
87 ((UnsignedByte *) mcdi)[offset + 2] = 170;
88 ((UnsignedByte *) mcdi)[offset + 3] = 0;
89
90 ((UnsignedByte *) mcdi)[offset + 4] = (address >> 24) & 255;
91 ((UnsignedByte *) mcdi)[offset + 5] = (address >> 16) & 255;
92 ((UnsignedByte *) mcdi)[offset + 6] = (address >> 8) & 255;
93 ((UnsignedByte *) mcdi)[offset + 7] = address & 255;
94
95 /* Set MCDI in track info.
96 */
97 Info info = track.GetInfo();
98
99 info.track = File(fileName).GetFileName().Head(2).ToInt();
100
101 info.mcdi.SetData(mcdi);
102
103 track.SetInfo(info);
104 }
105 }
106 }
107
108 delete pList;
109
110 if (error) return Error();
111 else return Success();
112 }
113
114 Bool BoCA::TaggerTOCPList::ReadSessions(XML::Node *sessions, Buffer<UnsignedByte> &mcdi, Int32 &leadOut)
115 {
116 for (Int i = 0; i < sessions->GetNOfNodes(); i++)
117 {
118 XML::Node *session = sessions->GetNthNode(i);
119
120 if (session->GetName() == "dict") ReadSession(session, mcdi, leadOut);
121 }
122
123 return True;
124 }
125
126 Bool BoCA::TaggerTOCPList::ReadSession(XML::Node *session, Buffer<UnsignedByte> &mcdi, Int32 &leadOut)
127 {
128 for (Int i = 0; i < session->GetNOfNodes(); i++)
129 {
130 XML::Node *node = session->GetNthNode(i);
131
132 if (node->GetName() == "key" && node->GetContent() == "Leadout Block") leadOut = session->GetNthNode(++i)->GetContent().ToInt() - 150;
133
134 if (node->GetName() != "key" || node->GetContent() != "Track Array") continue;
135
136 XML::Node *array = session->GetNthNode(++i);
137
138 if (array->GetName() == "array") ReadTracks(array, mcdi);
139 }
140
141 return True;
142 }
143
144 Bool BoCA::TaggerTOCPList::ReadTracks(XML::Node *tracks, Buffer<UnsignedByte> &mcdi)
145 {
146 for (Int i = 0; i < tracks->GetNOfNodes(); i++)
147 {
148 XML::Node *track = tracks->GetNthNode(i);
149
150 if (track->GetName() == "dict") ReadTrack(track, mcdi);
151 }
152
153 return True;
154 }
155
156 Bool BoCA::TaggerTOCPList::ReadTrack(XML::Node *track, Buffer<UnsignedByte> &mcdi)
157 {
158 Bool data = False;
159 Bool preemp = False;
160 Int number = 0;
161 Int32 address = 0;
162
163 for (Int i = 0; i < track->GetNOfNodes(); i++)
164 {
165 XML::Node *node = track->GetNthNode(i);
166
167 if (node->GetName() == "key")
168 {
169 if (node->GetContent() == "Data") data = track->GetNthNode(++i)->GetName() == "true" ? True : False;
170 else if (node->GetContent() == "Pre-Emphasis Enabled") preemp = track->GetNthNode(++i)->GetName() == "true" ? True : False;
171 else if (node->GetContent() == "Point") number = track->GetNthNode(++i)->GetContent().ToInt();
172 else if (node->GetContent() == "Start Block") address = track->GetNthNode(++i)->GetContent().ToInt() - 150;
173 }
174 }
175
176 Int offset = mcdi.Size();
177
178 mcdi.Resize(offset + 8);
179
180 ((UnsignedByte *) mcdi)[offset + 0] = 0;
181 ((UnsignedByte *) mcdi)[offset + 1] = 16 + (data ? 4 : 0) + (preemp ? 1 : 0);
182 ((UnsignedByte *) mcdi)[offset + 2] = number;
183 ((UnsignedByte *) mcdi)[offset + 3] = 0;
184
185 ((UnsignedByte *) mcdi)[offset + 4] = (address >> 24) & 255;
186 ((UnsignedByte *) mcdi)[offset + 5] = (address >> 16) & 255;
187 ((UnsignedByte *) mcdi)[offset + 6] = (address >> 8) & 255;
188 ((UnsignedByte *) mcdi)[offset + 7] = address & 255;
189
190 return True;
191 }