-
Notifications
You must be signed in to change notification settings - Fork 50
/
descriptor.go
2171 lines (1824 loc) · 59.2 KB
/
descriptor.go
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package astits
import (
"fmt"
"time"
"github.com/asticode/go-astikit"
)
// Audio types
// Page: 683 | https://books.google.fr/books?id=6dgWB3-rChYC&printsec=frontcover&hl=fr
const (
AudioTypeCleanEffects = 0x1
AudioTypeHearingImpaired = 0x2
AudioTypeVisualImpairedCommentary = 0x3
)
// Data stream alignments
// Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf
const (
DataStreamAligmentAudioSyncWord = 0x1
DataStreamAligmentVideoSliceOrAccessUnit = 0x1
DataStreamAligmentVideoAccessUnit = 0x2
DataStreamAligmentVideoGOPOrSEQ = 0x3
DataStreamAligmentVideoSEQ = 0x4
)
// Descriptor tags
// Chapter: 6.1 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
const (
DescriptorTagAC3 = 0x6a
DescriptorTagAVCVideo = 0x28
DescriptorTagComponent = 0x50
DescriptorTagContent = 0x54
DescriptorTagDataStreamAlignment = 0x6
DescriptorTagEnhancedAC3 = 0x7a
DescriptorTagExtendedEvent = 0x4e
DescriptorTagExtension = 0x7f
DescriptorTagISO639LanguageAndAudioType = 0xa
DescriptorTagLocalTimeOffset = 0x58
DescriptorTagMaximumBitrate = 0xe
DescriptorTagNetworkName = 0x40
DescriptorTagParentalRating = 0x55
DescriptorTagPrivateDataIndicator = 0xf
DescriptorTagPrivateDataSpecifier = 0x5f
DescriptorTagRegistration = 0x5
DescriptorTagService = 0x48
DescriptorTagShortEvent = 0x4d
DescriptorTagStreamIdentifier = 0x52
DescriptorTagSubtitling = 0x59
DescriptorTagTeletext = 0x56
DescriptorTagVBIData = 0x45
DescriptorTagVBITeletext = 0x46
)
// Descriptor extension tags
// Chapter: 6.3 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
const (
DescriptorTagExtensionSupplementaryAudio = 0x6
)
// Service types
// Chapter: 6.2.33 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
const (
ServiceTypeDigitalTelevisionService = 0x1
)
// Teletext types
// Chapter: 6.2.43 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
const (
TeletextTypeAdditionalInformationPage = 0x3
TeletextTypeInitialTeletextPage = 0x1
TeletextTypeProgramSchedulePage = 0x4
TeletextTypeTeletextSubtitlePage = 0x2
TeletextTypeTeletextSubtitlePageForHearingImpairedPeople = 0x5
)
// VBI data service id
// Chapter: 6.2.47 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
const (
VBIDataServiceIDClosedCaptioning = 0x6
VBIDataServiceIDEBUTeletext = 0x1
VBIDataServiceIDInvertedTeletext = 0x2
VBIDataServiceIDMonochrome442Samples = 0x7
VBIDataServiceIDVPS = 0x4
VBIDataServiceIDWSS = 0x5
)
// Descriptor represents a descriptor
// TODO Handle UTF8
type Descriptor struct {
AC3 *DescriptorAC3
AVCVideo *DescriptorAVCVideo
Component *DescriptorComponent
Content *DescriptorContent
DataStreamAlignment *DescriptorDataStreamAlignment
EnhancedAC3 *DescriptorEnhancedAC3
ExtendedEvent *DescriptorExtendedEvent
Extension *DescriptorExtension
ISO639LanguageAndAudioType *DescriptorISO639LanguageAndAudioType
Length uint8
LocalTimeOffset *DescriptorLocalTimeOffset
MaximumBitrate *DescriptorMaximumBitrate
NetworkName *DescriptorNetworkName
ParentalRating *DescriptorParentalRating
PrivateDataIndicator *DescriptorPrivateDataIndicator
PrivateDataSpecifier *DescriptorPrivateDataSpecifier
Registration *DescriptorRegistration
Service *DescriptorService
ShortEvent *DescriptorShortEvent
StreamIdentifier *DescriptorStreamIdentifier
Subtitling *DescriptorSubtitling
Tag uint8 // the tag defines the structure of the contained data following the descriptor length.
Teletext *DescriptorTeletext
Unknown *DescriptorUnknown
UserDefined []byte
VBIData *DescriptorVBIData
VBITeletext *DescriptorTeletext
}
// DescriptorAC3 represents an AC3 descriptor
// Chapter: Annex D | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorAC3 struct {
AdditionalInfo []byte
ASVC uint8
BSID uint8
ComponentType uint8
HasASVC bool
HasBSID bool
HasComponentType bool
HasMainID bool
MainID uint8
}
func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3, err error) {
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Create descriptor
d = &DescriptorAC3{
HasASVC: uint8(b&0x10) > 0,
HasBSID: uint8(b&0x40) > 0,
HasComponentType: uint8(b&0x80) > 0,
HasMainID: uint8(b&0x20) > 0,
}
// Component type
if d.HasComponentType {
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.ComponentType = uint8(b)
}
// BSID
if d.HasBSID {
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.BSID = uint8(b)
}
// Main ID
if d.HasMainID {
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.MainID = uint8(b)
}
// ASVC
if d.HasASVC {
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.ASVC = uint8(b)
}
// Additional info
if i.Offset() < offsetEnd {
if d.AdditionalInfo, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
}
return
}
// DescriptorAVCVideo represents an AVC video descriptor
// No doc found unfortunately, basing the implementation on https://github.com/gfto/bitstream/blob/master/mpeg/psi/desc_28.h
type DescriptorAVCVideo struct {
AVC24HourPictureFlag bool
AVCStillPresent bool
CompatibleFlags uint8
ConstraintSet0Flag bool
ConstraintSet1Flag bool
ConstraintSet2Flag bool
LevelIDC uint8
ProfileIDC uint8
}
func newDescriptorAVCVideo(i *astikit.BytesIterator) (d *DescriptorAVCVideo, err error) {
// Init
d = &DescriptorAVCVideo{}
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Profile idc
d.ProfileIDC = uint8(b)
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Flags
d.ConstraintSet0Flag = b&0x80 > 0
d.ConstraintSet1Flag = b&0x40 > 0
d.ConstraintSet2Flag = b&0x20 > 0
d.CompatibleFlags = b & 0x1f
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Level idc
d.LevelIDC = uint8(b)
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// AVC still present
d.AVCStillPresent = b&0x80 > 0
// AVC 24 hour picture flag
d.AVC24HourPictureFlag = b&0x40 > 0
return
}
// DescriptorComponent represents a component descriptor
// Chapter: 6.2.8 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorComponent struct {
ComponentTag uint8
ComponentType uint8
ISO639LanguageCode []byte
StreamContent uint8
StreamContentExt uint8
Text []byte
}
func newDescriptorComponent(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorComponent, err error) {
// Init
d = &DescriptorComponent{}
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Stream content ext
d.StreamContentExt = uint8(b >> 4)
// Stream content
d.StreamContent = uint8(b & 0xf)
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Component type
d.ComponentType = uint8(b)
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Component tag
d.ComponentTag = uint8(b)
// ISO639 language code
if d.ISO639LanguageCode, err = i.NextBytes(3); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Text
if i.Offset() < offsetEnd {
if d.Text, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
}
return
}
// DescriptorContent represents a content descriptor
// Chapter: 6.2.9 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorContent struct {
Items []*DescriptorContentItem
}
// DescriptorContentItem represents a content item descriptor
// Chapter: 6.2.9 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorContentItem struct {
ContentNibbleLevel1 uint8
ContentNibbleLevel2 uint8
UserByte uint8
}
func newDescriptorContent(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorContent, err error) {
// Init
d = &DescriptorContent{}
// Add items
for i.Offset() < offsetEnd {
// Get next bytes
var bs []byte
if bs, err = i.NextBytesNoCopy(2); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Append item
d.Items = append(d.Items, &DescriptorContentItem{
ContentNibbleLevel1: uint8(bs[0] >> 4),
ContentNibbleLevel2: uint8(bs[0] & 0xf),
UserByte: uint8(bs[1]),
})
}
return
}
// DescriptorDataStreamAlignment represents a data stream alignment descriptor
type DescriptorDataStreamAlignment struct {
Type uint8
}
func newDescriptorDataStreamAlignment(i *astikit.BytesIterator) (d *DescriptorDataStreamAlignment, err error) {
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d = &DescriptorDataStreamAlignment{Type: uint8(b)}
return
}
// DescriptorEnhancedAC3 represents an enhanced AC3 descriptor
// Chapter: Annex D | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorEnhancedAC3 struct {
AdditionalInfo []byte
ASVC uint8
BSID uint8
ComponentType uint8
HasASVC bool
HasBSID bool
HasComponentType bool
HasMainID bool
HasSubStream1 bool
HasSubStream2 bool
HasSubStream3 bool
MainID uint8
MixInfoExists bool
SubStream1 uint8
SubStream2 uint8
SubStream3 uint8
}
func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorEnhancedAC3, err error) {
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Create descriptor
d = &DescriptorEnhancedAC3{
HasASVC: uint8(b&0x10) > 0,
HasBSID: uint8(b&0x40) > 0,
HasComponentType: uint8(b&0x80) > 0,
HasMainID: uint8(b&0x20) > 0,
HasSubStream1: uint8(b&0x4) > 0,
HasSubStream2: uint8(b&0x2) > 0,
HasSubStream3: uint8(b&0x1) > 0,
MixInfoExists: uint8(b&0x8) > 0,
}
// Component type
if d.HasComponentType {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.ComponentType = uint8(b)
}
// BSID
if d.HasBSID {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.BSID = uint8(b)
}
// Main ID
if d.HasMainID {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.MainID = uint8(b)
}
// ASVC
if d.HasASVC {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.ASVC = uint8(b)
}
// Substream 1
if d.HasSubStream1 {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.SubStream1 = uint8(b)
}
// Substream 2
if d.HasSubStream2 {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.SubStream2 = uint8(b)
}
// Substream 3
if d.HasSubStream3 {
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
d.SubStream3 = uint8(b)
}
// Additional info
if i.Offset() < offsetEnd {
if d.AdditionalInfo, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
}
return
}
// DescriptorExtendedEvent represents an extended event descriptor
// Chapter: 6.2.15 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorExtendedEvent struct {
ISO639LanguageCode []byte
Items []*DescriptorExtendedEventItem
LastDescriptorNumber uint8
Number uint8
Text []byte
}
// DescriptorExtendedEventItem represents an extended event item descriptor
// Chapter: 6.2.15 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorExtendedEventItem struct {
Content []byte
Description []byte
}
func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtendedEvent, err error) {
// Init
d = &DescriptorExtendedEvent{}
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Number
d.Number = uint8(b >> 4)
// Last descriptor number
d.LastDescriptorNumber = uint8(b & 0xf)
// ISO639 language code
if d.ISO639LanguageCode, err = i.NextBytes(3); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Items length
itemsLength := int(b)
// Items
offsetEnd := i.Offset() + itemsLength
for i.Offset() < offsetEnd {
// Create item
var item *DescriptorExtendedEventItem
if item, err = newDescriptorExtendedEventItem(i); err != nil {
err = fmt.Errorf("astits: creating extended event item failed: %w", err)
return
}
// Append item
d.Items = append(d.Items, item)
}
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Text length
textLength := int(b)
// Text
if d.Text, err = i.NextBytes(textLength); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
return
}
func newDescriptorExtendedEventItem(i *astikit.BytesIterator) (d *DescriptorExtendedEventItem, err error) {
// Init
d = &DescriptorExtendedEventItem{}
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Description length
descriptionLength := int(b)
// Description
if d.Description, err = i.NextBytes(descriptionLength); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Content length
contentLength := int(b)
// Content
if d.Content, err = i.NextBytes(contentLength); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
return
}
// DescriptorExtension represents an extension descriptor
// Chapter: 6.2.16 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorExtension struct {
SupplementaryAudio *DescriptorExtensionSupplementaryAudio
Tag uint8
Unknown *[]byte
}
func newDescriptorExtension(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorExtension, err error) {
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Create descriptor
d = &DescriptorExtension{Tag: uint8(b)}
// Switch on tag
switch d.Tag {
case DescriptorTagExtensionSupplementaryAudio:
if d.SupplementaryAudio, err = newDescriptorExtensionSupplementaryAudio(i, offsetEnd); err != nil {
err = fmt.Errorf("astits: parsing extension supplementary audio descriptor failed: %w", err)
return
}
default:
// Get next bytes
var b []byte
if b, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Update unknown
d.Unknown = &b
}
return
}
// DescriptorExtensionSupplementaryAudio represents a supplementary audio extension descriptor
// Chapter: 6.4.10 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorExtensionSupplementaryAudio struct {
EditorialClassification uint8
HasLanguageCode bool
LanguageCode []byte
MixType bool
PrivateData []byte
}
func newDescriptorExtensionSupplementaryAudio(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorExtensionSupplementaryAudio, err error) {
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Init
d = &DescriptorExtensionSupplementaryAudio{
EditorialClassification: uint8(b >> 2 & 0x1f),
HasLanguageCode: b&0x1 > 0,
MixType: b&0x80 > 0,
}
// Language code
if d.HasLanguageCode {
if d.LanguageCode, err = i.NextBytes(3); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
}
// Private data
if i.Offset() < offsetEnd {
if d.PrivateData, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
}
return
}
// DescriptorISO639LanguageAndAudioType represents an ISO639 language descriptor
// https://github.com/gfto/bitstream/blob/master/mpeg/psi/desc_0a.h
// FIXME (barbashov) according to Chapter 2.6.18 ISO/IEC 13818-1:2015 there could be not one, but multiple such descriptors
type DescriptorISO639LanguageAndAudioType struct {
Language []byte
Type uint8
}
// In some actual cases, the length is 3 and the language is described in only 2 bytes
func newDescriptorISO639LanguageAndAudioType(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorISO639LanguageAndAudioType, err error) {
// Get next bytes
var bs []byte
if bs, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Create descriptor
d = &DescriptorISO639LanguageAndAudioType{
Language: bs[0 : len(bs)-1],
Type: uint8(bs[len(bs)-1]),
}
return
}
// DescriptorLocalTimeOffset represents a local time offset descriptor
// Chapter: 6.2.20 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorLocalTimeOffset struct {
Items []*DescriptorLocalTimeOffsetItem
}
// DescriptorLocalTimeOffsetItem represents a local time offset item descriptor
// Chapter: 6.2.20 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorLocalTimeOffsetItem struct {
CountryCode []byte
CountryRegionID uint8
LocalTimeOffset time.Duration
LocalTimeOffsetPolarity bool
NextTimeOffset time.Duration
TimeOfChange time.Time
}
func newDescriptorLocalTimeOffset(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorLocalTimeOffset, err error) {
// Init
d = &DescriptorLocalTimeOffset{}
// Add items
for i.Offset() < offsetEnd {
// Create item
itm := &DescriptorLocalTimeOffsetItem{}
// Country code
if itm.CountryCode, err = i.NextBytes(3); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Country region ID
itm.CountryRegionID = uint8(b >> 2)
// Local time offset polarity
itm.LocalTimeOffsetPolarity = b&0x1 > 0
// Local time offset
if itm.LocalTimeOffset, err = parseDVBDurationMinutes(i); err != nil {
err = fmt.Errorf("astits: parsing DVB durationminutes failed: %w", err)
return
}
// Time of change
if itm.TimeOfChange, err = parseDVBTime(i); err != nil {
err = fmt.Errorf("astits: parsing DVB time failed: %w", err)
return
}
// Next time offset
if itm.NextTimeOffset, err = parseDVBDurationMinutes(i); err != nil {
err = fmt.Errorf("astits: parsing DVB duration minutes failed: %w", err)
return
}
// Append item
d.Items = append(d.Items, itm)
}
return
}
// DescriptorMaximumBitrate represents a maximum bitrate descriptor
type DescriptorMaximumBitrate struct {
Bitrate uint32 // In bytes/second
}
func newDescriptorMaximumBitrate(i *astikit.BytesIterator) (d *DescriptorMaximumBitrate, err error) {
// Get next bytes
var bs []byte
if bs, err = i.NextBytesNoCopy(3); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Create descriptor
d = &DescriptorMaximumBitrate{Bitrate: (uint32(bs[0]&0x3f)<<16 | uint32(bs[1])<<8 | uint32(bs[2])) * 50}
return
}
// DescriptorNetworkName represents a network name descriptor
// Chapter: 6.2.27 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorNetworkName struct {
Name []byte
}
func newDescriptorNetworkName(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorNetworkName, err error) {
// Create descriptor
d = &DescriptorNetworkName{}
// Name
if d.Name, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
return
}
// DescriptorParentalRating represents a parental rating descriptor
// Chapter: 6.2.28 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorParentalRating struct {
Items []*DescriptorParentalRatingItem
}
// DescriptorParentalRatingItem represents a parental rating item descriptor
// Chapter: 6.2.28 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorParentalRatingItem struct {
CountryCode []byte
Rating uint8
}
// MinimumAge returns the minimum age for the parental rating
func (d DescriptorParentalRatingItem) MinimumAge() int {
// Undefined or user defined ratings
if d.Rating == 0 || d.Rating > 0x10 {
return 0
}
return int(d.Rating) + 3
}
func newDescriptorParentalRating(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorParentalRating, err error) {
// Create descriptor
d = &DescriptorParentalRating{}
// Add items
for i.Offset() < offsetEnd {
// Get next bytes
var bs []byte
if bs, err = i.NextBytes(4); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Append item
d.Items = append(d.Items, &DescriptorParentalRatingItem{
CountryCode: bs[:3],
Rating: uint8(bs[3]),
})
}
return
}
// DescriptorPrivateDataIndicator represents a private data Indicator descriptor
type DescriptorPrivateDataIndicator struct {
Indicator uint32
}
func newDescriptorPrivateDataIndicator(i *astikit.BytesIterator) (d *DescriptorPrivateDataIndicator, err error) {
// Get next bytes
var bs []byte
if bs, err = i.NextBytesNoCopy(4); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Create descriptor
d = &DescriptorPrivateDataIndicator{Indicator: uint32(bs[0])<<24 | uint32(bs[1])<<16 | uint32(bs[2])<<8 | uint32(bs[3])}
return
}
// DescriptorPrivateDataSpecifier represents a private data specifier descriptor
type DescriptorPrivateDataSpecifier struct {
Specifier uint32
}
func newDescriptorPrivateDataSpecifier(i *astikit.BytesIterator) (d *DescriptorPrivateDataSpecifier, err error) {
// Get next bytes
var bs []byte
if bs, err = i.NextBytesNoCopy(4); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Create descriptor
d = &DescriptorPrivateDataSpecifier{Specifier: uint32(bs[0])<<24 | uint32(bs[1])<<16 | uint32(bs[2])<<8 | uint32(bs[3])}
return
}
// DescriptorRegistration represents a registration descriptor
// Page: 84 | http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf
type DescriptorRegistration struct {
AdditionalIdentificationInfo []byte
FormatIdentifier uint32
}
func newDescriptorRegistration(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorRegistration, err error) {
// Get next bytes
var bs []byte
if bs, err = i.NextBytesNoCopy(4); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Create descriptor
d = &DescriptorRegistration{FormatIdentifier: uint32(bs[0])<<24 | uint32(bs[1])<<16 | uint32(bs[2])<<8 | uint32(bs[3])}
// Additional identification info
if i.Offset() < offsetEnd {
if d.AdditionalIdentificationInfo, err = i.NextBytes(offsetEnd - i.Offset()); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
}
return
}
// DescriptorService represents a service descriptor
// Chapter: 6.2.33 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorService struct {
Name []byte
Provider []byte
Type uint8
}
func newDescriptorService(i *astikit.BytesIterator) (d *DescriptorService, err error) {
// Get next byte
var b byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Create descriptor
d = &DescriptorService{Type: uint8(b)}
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Provider length
providerLength := int(b)
// Provider
if d.Provider, err = i.NextBytes(providerLength); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
// Get next byte
if b, err = i.NextByte(); err != nil {
err = fmt.Errorf("astits: fetching next byte failed: %w", err)
return
}
// Name length
nameLength := int(b)
// Name
if d.Name, err = i.NextBytes(nameLength); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}
return
}
// DescriptorShortEvent represents a short event descriptor
// Chapter: 6.2.37 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf
type DescriptorShortEvent struct {
EventName []byte
Language []byte
Text []byte
}
func newDescriptorShortEvent(i *astikit.BytesIterator) (d *DescriptorShortEvent, err error) {
// Create descriptor
d = &DescriptorShortEvent{}
// Language
if d.Language, err = i.NextBytes(3); err != nil {
err = fmt.Errorf("astits: fetching next bytes failed: %w", err)
return
}