• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/ancestory.h"
9 
10 #include "webm/id.h"
11 
12 namespace webm {
13 
ById(Id id,Ancestory * ancestory)14 bool Ancestory::ById(Id id, Ancestory* ancestory) {
15   // These lists of IDs were generated and must match the switch statement and
16   // have static storage duration. They were generated as follows:
17   //
18   // 1. List all the master elements:
19   //      kEbml
20   //      kSegment
21   //      kSeekHead
22   //      kSeek
23   //      kInfo
24   //      kCluster
25   //      kBlockGroup
26   //      kBlockAdditions
27   //      kBlockMore
28   //      kSlices
29   //      kTimeSlice
30   //      etc.
31   //
32   // 2. Now prefix each entry with its full ancestory:
33   //      kEbml
34   //      kSegment
35   //      kSegment, kSeekHead
36   //      kSegment, kSeekHead, kSeek
37   //      kSegment, kInfo
38   //      kSegment, kCluster
39   //      kSegment, kCluster, kBlockGroup
40   //      kSegment, kCluster, kBlockGroup, kBlockAdditions
41   //      kSegment, kCluster, kBlockGroup, kBlockAdditions, kBlockMore
42   //      kSegment, kCluster, kBlockGroup, kSlices
43   //      kSegment, kCluster, kBlockGroup, kSlices, kTimeSlice
44   //      etc.
45   //
46   // 3. Now remove entries that are just subsets of others:
47   //      kEbml
48   //      kSegment, kSeekHead, kSeek
49   //      kSegment, kInfo
50   //      kSegment, kCluster, kBlockGroup, kBlockAdditions, kBlockMore
51   //      kSegment, kCluster, kBlockGroup, kSlices, kTimeSlice
52   //      etc.
53   static constexpr Id kEbmlAncestory[] = {
54       Id::kEbml,
55   };
56   static constexpr Id kSeekAncestory[] = {
57       Id::kSegment,
58       Id::kSeekHead,
59       Id::kSeek,
60   };
61   static constexpr Id kInfoAncestory[] = {
62       Id::kSegment,
63       Id::kInfo,
64   };
65   static constexpr Id kBlockMoreAncestory[] = {
66       Id::kSegment,        Id::kCluster,   Id::kBlockGroup,
67       Id::kBlockAdditions, Id::kBlockMore,
68   };
69   static constexpr Id kTimeSliceAncestory[] = {
70       Id::kSegment, Id::kCluster, Id::kBlockGroup, Id::kSlices, Id::kTimeSlice,
71   };
72   static constexpr Id kVideoAncestory[] = {
73       Id::kSegment,
74       Id::kTracks,
75       Id::kTrackEntry,
76       Id::kVideo,
77   };
78   static constexpr Id kAudioAncestory[] = {
79       Id::kSegment,
80       Id::kTracks,
81       Id::kTrackEntry,
82       Id::kAudio,
83   };
84   static constexpr Id kContentEncAesSettingsAncestory[] = {
85       Id::kSegment,
86       Id::kTracks,
87       Id::kTrackEntry,
88       Id::kContentEncodings,
89       Id::kContentEncoding,
90       Id::kContentEncryption,
91       Id::kContentEncAesSettings,
92   };
93   static constexpr Id kCueTrackPositionsAncestory[] = {
94       Id::kSegment,
95       Id::kCues,
96       Id::kCuePoint,
97       Id::kCueTrackPositions,
98   };
99   static constexpr Id kChapterDisplayAncestory[] = {
100       Id::kSegment,     Id::kChapters,       Id::kEditionEntry,
101       Id::kChapterAtom, Id::kChapterDisplay,
102   };
103   static constexpr Id kTargetsAncestory[] = {
104       Id::kSegment,
105       Id::kTags,
106       Id::kTag,
107       Id::kTargets,
108   };
109   static constexpr Id kSimpleTagAncestory[] = {
110       Id::kSegment,
111       Id::kTags,
112       Id::kTag,
113       Id::kSimpleTag,
114   };
115 
116   switch (id) {
117     case Id::kEbmlVersion:
118     case Id::kEbmlReadVersion:
119     case Id::kEbmlMaxIdLength:
120     case Id::kEbmlMaxSizeLength:
121     case Id::kDocType:
122     case Id::kDocTypeVersion:
123     case Id::kDocTypeReadVersion:
124       *ancestory = Ancestory(kEbmlAncestory, 1);
125       return true;
126 
127     case Id::kSeekHead:
128     case Id::kInfo:
129     case Id::kCluster:
130     case Id::kTracks:
131     case Id::kCues:
132     case Id::kChapters:
133     case Id::kTags:
134       *ancestory = Ancestory(kSeekAncestory, 1);
135       return true;
136 
137     case Id::kSeek:
138       *ancestory = Ancestory(kSeekAncestory, 2);
139       return true;
140 
141     case Id::kSeekId:
142     case Id::kSeekPosition:
143       *ancestory = Ancestory(kSeekAncestory, 3);
144       return true;
145 
146     case Id::kTimecodeScale:
147     case Id::kDuration:
148     case Id::kDateUtc:
149     case Id::kTitle:
150     case Id::kMuxingApp:
151     case Id::kWritingApp:
152       *ancestory = Ancestory(kInfoAncestory, 2);
153       return true;
154 
155     case Id::kTimecode:
156     case Id::kPrevSize:
157     case Id::kSimpleBlock:
158     case Id::kBlockGroup:
159       *ancestory = Ancestory(kBlockMoreAncestory, 2);
160       return true;
161 
162     case Id::kBlock:
163     case Id::kBlockVirtual:
164     case Id::kBlockAdditions:
165     case Id::kBlockDuration:
166     case Id::kReferenceBlock:
167     case Id::kDiscardPadding:
168     case Id::kSlices:
169       *ancestory = Ancestory(kBlockMoreAncestory, 3);
170       return true;
171 
172     case Id::kBlockMore:
173       *ancestory = Ancestory(kBlockMoreAncestory, 4);
174       return true;
175 
176     case Id::kBlockAddId:
177     case Id::kBlockAdditional:
178       *ancestory = Ancestory(kBlockMoreAncestory, 5);
179       return true;
180 
181     case Id::kTimeSlice:
182       *ancestory = Ancestory(kTimeSliceAncestory, 4);
183       return true;
184 
185     case Id::kLaceNumber:
186       *ancestory = Ancestory(kTimeSliceAncestory, 5);
187       return true;
188 
189     case Id::kTrackEntry:
190       *ancestory = Ancestory(kVideoAncestory, 2);
191       return true;
192 
193     case Id::kTrackNumber:
194     case Id::kTrackUid:
195     case Id::kTrackType:
196     case Id::kFlagEnabled:
197     case Id::kFlagDefault:
198     case Id::kFlagForced:
199     case Id::kFlagLacing:
200     case Id::kDefaultDuration:
201     case Id::kName:
202     case Id::kLanguage:
203     case Id::kCodecId:
204     case Id::kCodecPrivate:
205     case Id::kCodecName:
206     case Id::kCodecDelay:
207     case Id::kSeekPreRoll:
208     case Id::kVideo:
209     case Id::kAudio:
210     case Id::kContentEncodings:
211       *ancestory = Ancestory(kVideoAncestory, 3);
212       return true;
213 
214     case Id::kFlagInterlaced:
215     case Id::kStereoMode:
216     case Id::kAlphaMode:
217     case Id::kPixelWidth:
218     case Id::kPixelHeight:
219     case Id::kPixelCropBottom:
220     case Id::kPixelCropTop:
221     case Id::kPixelCropLeft:
222     case Id::kPixelCropRight:
223     case Id::kDisplayWidth:
224     case Id::kDisplayHeight:
225     case Id::kDisplayUnit:
226     case Id::kAspectRatioType:
227     case Id::kFrameRate:
228       *ancestory = Ancestory(kVideoAncestory, 4);
229       return true;
230 
231     case Id::kSamplingFrequency:
232     case Id::kOutputSamplingFrequency:
233     case Id::kChannels:
234     case Id::kBitDepth:
235       *ancestory = Ancestory(kAudioAncestory, 4);
236       return true;
237 
238     case Id::kContentEncoding:
239       *ancestory = Ancestory(kContentEncAesSettingsAncestory, 4);
240       return true;
241 
242     case Id::kContentEncodingOrder:
243     case Id::kContentEncodingScope:
244     case Id::kContentEncodingType:
245     case Id::kContentEncryption:
246       *ancestory = Ancestory(kContentEncAesSettingsAncestory, 5);
247       return true;
248 
249     case Id::kContentEncAlgo:
250     case Id::kContentEncKeyId:
251     case Id::kContentEncAesSettings:
252       *ancestory = Ancestory(kContentEncAesSettingsAncestory, 6);
253       return true;
254 
255     case Id::kAesSettingsCipherMode:
256       *ancestory = Ancestory(kContentEncAesSettingsAncestory, 7);
257       return true;
258 
259     case Id::kCuePoint:
260       *ancestory = Ancestory(kCueTrackPositionsAncestory, 2);
261       return true;
262 
263     case Id::kCueTime:
264     case Id::kCueTrackPositions:
265       *ancestory = Ancestory(kCueTrackPositionsAncestory, 3);
266       return true;
267 
268     case Id::kCueTrack:
269     case Id::kCueClusterPosition:
270     case Id::kCueRelativePosition:
271     case Id::kCueDuration:
272     case Id::kCueBlockNumber:
273       *ancestory = Ancestory(kCueTrackPositionsAncestory, 4);
274       return true;
275 
276     case Id::kEditionEntry:
277       *ancestory = Ancestory(kChapterDisplayAncestory, 2);
278       return true;
279 
280     case Id::kChapterAtom:
281       *ancestory = Ancestory(kChapterDisplayAncestory, 3);
282       return true;
283 
284     case Id::kChapterUid:
285     case Id::kChapterStringUid:
286     case Id::kChapterTimeStart:
287     case Id::kChapterTimeEnd:
288     case Id::kChapterDisplay:
289       *ancestory = Ancestory(kChapterDisplayAncestory, 4);
290       return true;
291 
292     case Id::kChapString:
293     case Id::kChapLanguage:
294     case Id::kChapCountry:
295       *ancestory = Ancestory(kChapterDisplayAncestory, 5);
296       return true;
297 
298     case Id::kTag:
299       *ancestory = Ancestory(kTargetsAncestory, 2);
300       return true;
301 
302     case Id::kTargets:
303     case Id::kSimpleTag:
304       *ancestory = Ancestory(kTargetsAncestory, 3);
305       return true;
306 
307     case Id::kTargetTypeValue:
308     case Id::kTargetType:
309     case Id::kTagTrackUid:
310       *ancestory = Ancestory(kTargetsAncestory, 4);
311       return true;
312 
313     case Id::kTagName:
314     case Id::kTagLanguage:
315     case Id::kTagDefault:
316     case Id::kTagString:
317     case Id::kTagBinary:
318       *ancestory = Ancestory(kSimpleTagAncestory, 4);
319       return true;
320 
321     case Id::kEbml:
322     case Id::kSegment:
323       *ancestory = {};
324       return true;
325 
326     default:
327       // This is an unknown element or a global element (i.e. Void); its
328       // ancestory cannot be deduced.
329       *ancestory = {};
330       return false;
331   }
332 }
333 
334 }  // namespace webm
335