-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathspecifications.hpp
3832 lines (3461 loc) · 110 KB
/
specifications.hpp
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
/*++
* tssi - A library for parsing MPEG-2 and DVB Transport Streams
*
* Copyright (C) 2017 Martin Hoernig (goforcode.com)
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
--*/
#pragma once
#include "span_reader.hpp"
namespace tssi
{
/****t* tssi/R1
* NAME
* R1 -- Reads a byte
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset
* and returns the bit at bit_position.
* SOURCE
*/
template <size_t offset, size_t bit_position, size_t loop_length = 0>
using R1 = bit_reader<basic_reader<offset, loop_length>, bit_position>;
/*******/
/****t* tssi/R8
* NAME
* R8 -- Reads 8 bits
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset.
* SOURCE
*/
template <size_t offset, size_t loop_length = 0>
using R8 = endian_aware_value_reader<uint_fast8_t, basic_reader<offset, loop_length>, 1>;
/*******/
/****t* tssi/R16
* NAME
* R16 -- Reads 8 bits
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset.
* SOURCE
*/
template <size_t offset, size_t loop_length = 0>
using R16 = endian_aware_value_reader<uint_fast16_t, basic_reader<offset, loop_length>, 2>;
/*******/
/****t* tssi/R24
* NAME
* R24 -- Reads 24 bits
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset.
* SOURCE
*/
template <size_t offset, size_t loop_length = 0>
using R24 = endian_aware_value_reader<uint_fast32_t, basic_reader<offset, loop_length>, 3>;
/*******/
/****t* tssi/R32
* NAME
* R32 -- Reads 32 bits
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset.
* SOURCE
*/
template <size_t offset, size_t loop_length = 0>
using R32 = endian_aware_value_reader<uint_fast32_t, basic_reader<offset, loop_length>, 4>;
/*******/
/****t* tssi/R40
* NAME
* R40 -- Reads 40 bits
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset.
* SOURCE
*/
template <size_t offset, size_t loop_length = 0>
using R40 = endian_aware_value_reader<uint_fast64_t, basic_reader<offset, loop_length>, 5>;
/*******/
/****t* tssi/R64
* NAME
* R64 -- Reads 64 bits
* - at offset or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset.
* SOURCE
*/
template <size_t offset, size_t loop_length = 0>
using R64 = endian_aware_value_reader<uint_fast64_t, basic_reader<offset, loop_length>, 8>;
/*******/
/****t* tssi/ADD_R1
* NAME
* ADD_R1 -- Reads a byte
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset)
* and returns the bit at bit_position.
* SOURCE
*/
template <class reference, size_t offset, size_t bit_position, size_t loop_length = 0>
using ADD_R1 = bit_reader<combined_reader<
basic_reader<offset, loop_length>, reference>, bit_position>;
/*******/
/****t* tssi/ADD_R8
* NAME
* ADD_R8 -- Reads 8 bits
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset).
* SOURCE
*/
template <class reference, size_t offset, size_t loop_length = 0>
using ADD_R8 = endian_aware_value_reader<
uint_fast8_t, combined_reader<basic_reader<offset, loop_length>, reference>, 1>;
/*******/
/****t* tssi/ADD_R16
* NAME
* ADD_R16 -- Reads 16 bits
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset).
* SOURCE
*/
template <class reference, size_t offset, size_t loop_length = 0>
using ADD_R16 = endian_aware_value_reader<
uint_fast16_t, combined_reader<basic_reader<offset, loop_length>, reference>, 2>;
/*******/
/****t* tssi/ADD_R24
* NAME
* ADD_R24 -- Reads 24 bits
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset).
* SOURCE
*/
template <class reference, size_t offset, size_t loop_length = 0>
using ADD_R24 = endian_aware_value_reader<
uint_fast32_t, combined_reader<basic_reader<offset, loop_length>, reference>, 3>;
/*******/
/****t* tssi/ADD_R32
* NAME
* ADD_R32 -- Reads 32 bits
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset).
* SOURCE
*/
template <class reference, size_t offset, size_t loop_length = 0>
using ADD_R32 = endian_aware_value_reader<
uint_fast32_t, combined_reader<basic_reader<offset, loop_length>, reference>, 4>;
/*******/
/****t* tssi/ADD_R40
* NAME
* ADD_R40 -- Reads 40 bits
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset).
* SOURCE
*/
template <class reference, size_t offset, size_t loop_length = 0>
using ADD_R40 = endian_aware_value_reader<
uint_fast64_t, combined_reader<basic_reader<offset, loop_length>, reference>, 5>;
/*******/
/****t* tssi/ADD_R64
* NAME
* ADD_R64 -- Reads 64 bits
* - at (reference + offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset).
* SOURCE
*/
template <class reference, size_t offset, size_t loop_length = 0>
using ADD_R64 = endian_aware_value_reader<
uint_fast64_t, combined_reader<basic_reader<offset, loop_length>, reference>, 8>;
/*******/
/****t* tssi/DAT
* NAME
* DAT -- Reads a gsl::span<const char> memory buffer
* - at offset with length (count_reference + reference_offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* offset with length (count_reference + reference_offset).
* SOURCE
*/
template <size_t offset, class count_reference, ptrdiff_t reference_offset = 0, size_t loop_length = 0>
using DAT = span_reader<offset, count_reference, reference_offset, loop_length>;
/*******/
/****t* tssi/ADD_DAT
* NAME
* ADD_DAT -- Reads a gsl::span<const char> memory buffer
* - at (reference + offset) with length (count_reference +
* reference_offset) or
* - in an i-th iteration of a loop with fixed loop size loop_length at
* (reference + offset) with length (count_reference + reference_offset).
* SOURCE
*/
template <class reference, size_t offset, class count_reference, ptrdiff_t reference_offset = 0, size_t loop_length = 0>
using ADD_DAT = combined_reader<span_reader
<offset, count_reference, reference_offset, loop_length>, reference>;
/*******/
/****t* tssi/ADD
* NAME
* ADD -- Calculates the sum of two references.
* SOURCE
*/
template <class reference_a, class reference_b>
using ADD = reference_sum<reference_a, reference_b>;
/*******/
/****t* tssi/SUB
* NAME
* SUB -- Calculates the difference of two references.
* SOURCE
*/
template <class reference_a, class reference_b>
using SUB = reference_difference<reference_a, reference_b>;
/*******/
/****t* tssi/MS
* NAME
* MS -- Performs a bitwise and followed by a shift right operation on the given value:
* (value & mask) >> shift
* SOURCE
*/
template <class value, uint_fast64_t mask, uint_fast64_t shift>
using MS = mask_shift<value, mask, shift>;
/*******/
/****t* tssi/TIME
* NAME
* TIME -- Converts an ETSI 300 468 Annex C-typed time value to time_c.
* SOURCE
*/
template <class value>
using TIME = time_convert<value>;
/*******/
/****t* tssi/DUR
* NAME
* DUR -- Converts a six digit (hh::mm:ss) BCD duration value to
* std::chrono::seconds.
* SOURCE
*/
template <class duration>
using DUR = duration_convert<duration>;
/*******/
/****t* tssi/CHAR
* NAME
* CHAR -- Converts an ETSI EN 300468 Annex A (Text) memory buffer to utf-8
* carried within std::string. The returned object is a std::pair of bool and
* std::string. The bool is true if the conversion was successful otherwise it
* the string contains an error message.
* NOTES
* CHAR may throw exceptions (see std::string).
* SOURCE
*/
template <class span>
using CHAR = string_reader<span>;
/*******/
/****t* tssi/BCD
* NAME
* BCD -- Decodes a given BCD value.
* SOURCE
*/
template <class value, size_t digits>
using BCD = bcd_convert<value, digits>;
/*******/
/****t* tssi/ITER
* NAME
* ITER -- Associates data (gsl::span<const char>) with syntax (structure). Therefore,
* allows to iterate through data loops of variables sizes by utilizing
* range_span, range_span_iterator and range for.
* e.g.
* for (auto loop : range_span_ITER(data)) {}
* SOURCE
*/
template <class span, tssi_size_t structure>
using ITER = iterable_span<span, structure>;
/*******/
#define TSSI_MTD_ESC(...) __VA_ARGS__
#define TSSI_MTD_FAC(classname, functionname) \
inline auto functionname(gsl::span<const char> data, size_t index = 0) \
noexcept(noexcept(classname::at(data, index))) \
{ return classname::at(data, index); }
/****d* tssi/TSSI_MTD
* NAME
* TSSI_MTD -- Function factory. Defines functions with the signature
* inline [return_type] functionname (gsl::span<const char> data, size_t index = 0);
* NOTES
* The functions does not throw if the underlying reader does not throw.
* SOURCE
*/
#define TSSI_MTD(classname, functionname) TSSI_MTD_FAC(TSSI_MTD_ESC classname, functionname)
/*******/
namespace iso138183 {
/****h* tssi::iso138183/frame_header
* NAME
* frame_header -- MPEG Audio frame header, version 1 (ISO 11172-3),
* version 2 (ISO 13818-3), and version 2.5
* SOURCE
*/
namespace frame_header {
TSSI_MTD((MS<R16<0>, 0xffe0, 5>),
frame_sync);
TSSI_MTD((MS<R8<1>, 0x18, 3>),
mpeg_audio_version);
TSSI_MTD((MS<R8<1>, 0x6, 1>),
layer_description);
TSSI_MTD((R1<1, 7>),
crc_protection_bit);
TSSI_MTD((MS<R8<2>, 0xf0, 4>),
bitrate_index);
TSSI_MTD((MS<R8<2>, 0xc, 2>),
sampling_rate_index);
TSSI_MTD((R1<2, 6>),
padding_bit);
TSSI_MTD((R1<2, 7>),
private_bit);
TSSI_MTD((MS<R8<3>, 0xc0, 6>),
channel_mode);
TSSI_MTD((MS<R8<3>, 0x30, 4>),
mode_extension);
TSSI_MTD((R1<3, 4>),
copyright_bit);
TSSI_MTD((R1<3, 5>),
original_media_bit);
TSSI_MTD((MS<R8<3>, 0x03, 0>),
emphasis);
}
/*******/
}
namespace iso138181 {
/****h* tssi::iso138181/transport_packet
* NAME
* transport_packet -- Basic unit of an MPEG transport stream, 188 byte in length
* SOURCE
*/
namespace transport_packet {
TSSI_MTD((R8<0>),
sync_byte);
TSSI_MTD((R1<1, 7>),
transport_error_indicator);
TSSI_MTD((R1<1, 6>),
payload_unit_start_indicator);
TSSI_MTD((R1<1, 5>),
transport_priority);
TSSI_MTD((MS<R16<1>, 0x1fff, 0>),
PID);
TSSI_MTD((MS<R8<3>, 0xc0, 6>),
transport_scrambling_control);
TSSI_MTD((MS<R8<3>, 0x30, 4>),
adaptation_field_control);
TSSI_MTD((MS<R8<3>, 0x0f, 0>),
continuity_counter);
}
/*******/
/****h* tssi::iso138181/adaptation_field
* NAME
* adaptation_field -- Optional field included after transport_packet if
* adaptation_field_control is equal to 0x2 or 0x3.
* TODO
* Implement missing members
* SOURCE
*/
namespace adaptation_field {
TSSI_MTD((R8<0>),
adaptation_field_length);
// if (adaptation_field_length > 0) {
TSSI_MTD((R1<1, 7>),
discontinuity_indicator);
TSSI_MTD((R1<1, 6>),
random_access_indicator);
TSSI_MTD((R1<1, 5>),
elementary_stream_priority_indicator);
TSSI_MTD((R1<1, 4>),
PCR_flag);
TSSI_MTD((R1<1, 3>),
OPCR_flag);
TSSI_MTD((R1<1, 2>),
splicing_point_flag);
TSSI_MTD((R1<1, 1>),
transport_private_data_flag);
TSSI_MTD((R1<1, 0>),
adaptation_field_extension_flag);
// if (PCR_flag == 1) {
TSSI_MTD((MS<R64<2>, 0xffffffff80000000, 31>),
program_clock_reference_base);
TSSI_MTD((MS<R16<6>, 0x1ff, 0>),
program_clock_reference_extension);
// }
// }
}
/*******/
/****h* tssi::iso138181/PES_packet
* NAME
* PES_packet -- Packetized Elementary Stream (PES) packets are used to carry
* elementary streams.
* NOTES
* Make use of appropriate derived classes if stream_id is known.
* DERIVED BY
* PES_packet_media, PES_packet_auxiliary
* SOURCE
*/
namespace PES_packet {
TSSI_MTD((R24<0>),
packet_start_code_prefix);
TSSI_MTD((R8<3>),
stream_id);
TSSI_MTD((R16<4>),
PES_packet_length);
}
/*******/
/****h* tssi::iso138181/PES_packet_media
* NAME
* PES_packet_media -- Packetized Elementary Stream (PES) packets carrying a
* sophisticated header
* SOURCE
*/
namespace PES_packet_media {
using namespace PES_packet;
// if (stream_id != program_stream_map
// && stream_id != padding_stream
// && stream_id != private_stream_2
// && stream_id != ECM
// && stream_id != EMM
// && stream_id != program_stream_directory
// && stream_id != DSMCC_stream
// && stream_id != ITU - T Rec.H.222.1 type E stream) {
TSSI_MTD((MS<R8<6>, 0xc0, 6>),
_signature1); // == 0x2
TSSI_MTD((MS<R8<6>, 0x30, 4>),
PES_scrambling_control);
TSSI_MTD((R1<6, 3>),
PES_priority);
TSSI_MTD((R1<6, 2>),
data_alignment_indicator);
TSSI_MTD((R1<6, 1>),
copyright);
TSSI_MTD((R1<6, 0>),
original_or_copy);
TSSI_MTD((MS<R8<7>, 0xc0, 6>),
PTS_DTS_flags);
TSSI_MTD((R1<7, 5>),
ESCR_flag);
TSSI_MTD((R1<7, 4>),
ES_rate_flag);
TSSI_MTD((R1<7, 3>),
DSM_trick_mode_flag);
TSSI_MTD((R1<7, 2>),
additional_copy_info_flag);
TSSI_MTD((R1<7, 1>),
PES_CRC_flag);
TSSI_MTD((R1<7, 0>),
PES_extension_flag);
TSSI_MTD((R8<8>),
PES_header_data_length);
// if ((PTS_DTS_flags & 0x2) == 0x2) {
TSSI_MTD((MS<R8<9>, 0xf0, 4>),
_signature2); // == PTS_DTS_flags
TSSI_MTD((MS<R8<9>, 0xe0, 1>),
PTS_32_30);
TSSI_MTD((R1<9, 0>),
marker_bit1); // == 1
TSSI_MTD((MS<R16<10>, 0xfffe, 1>),
PTS_29_15);
TSSI_MTD((R1<11, 0>),
marker_bit2); // == 1
TSSI_MTD((MS<R16<12>, 0xfffe, 1>),
PTS_14_0);
TSSI_MTD((R1<13, 0>),
marker_bit3); // == 1
inline uint_fast64_t PTS(gsl::span<const char> data) noexcept {
return static_cast<uint_fast64_t>(PTS_14_0(data)) | (static_cast<uint_fast64_t>(PTS_29_15(data)) << 15) | (static_cast<uint_fast64_t>(PTS_32_30(data)) << 30);
}
// if ((PTS_DTS_flags & 0x1) == 0x1) {
TSSI_MTD((MS<R8<14>, 0xf0, 4>),
_signature3); // == 0x1
TSSI_MTD((MS<R8<14>, 0xe0, 1>),
DTS_32_30);
TSSI_MTD((R1<14, 0>),
marker_bit4); // == 1
TSSI_MTD((MS<R16<15>, 0xfffe, 1>),
DTS_29_15);
TSSI_MTD((R1<16, 0>),
marker_bit5); // == 1
TSSI_MTD((MS<R16<17>, 0xfffe, 1>),
DTS_14_0);
TSSI_MTD((R1<18, 0>),
marker_bit6); // == 1
inline uint_fast64_t DTS(gsl::span<const char> data) noexcept {
return static_cast<uint_fast64_t>(DTS_14_0(data)) | (static_cast<uint_fast64_t>(DTS_29_15(data)) << 15) | (static_cast<uint_fast64_t>(DTS_32_30(data)) << 30);
}
// } DTS
// } PTS
inline gsl::span<const char> PES_packet_data_bytes(gsl::span<const char> data) noexcept
{
auto header_length = PES_header_data_length(data) + 9;
if (header_length <= data.size())
return data.subspan(PES_header_data_length(data) + 9);
else
return data.subspan(data.size());
}
// }
}
/*******/
/****h* tssi::iso138181/PES_packet_auxiliary
* NAME
* PES_packet_auxiliary -- Packetized Elementary Stream (PES) packets with thin header
* SOURCE
*/
namespace PES_packet_auxiliary {
using namespace PES_packet;
namespace {
using PES_packet_length_t =
R16<4>;
}
// if (stream_id == program_stream_map
// || stream_id == private_stream_2
// || stream_id == ECM
// || stream_id == EMM
// || stream_id == program_stream_directory
// || stream_id == DSMCC_stream
// || stream_id == ITU - T Rec.H.222.1 type E stream) {
TSSI_MTD((DAT<6, PES_packet_length_t>),
PES_packet_data_bytes);
// }
}
/*******/
/****h* tssi::iso138181/descriptor
* NAME
* descriptor -- "[D]escriptors are namespaceures which may be used to extend the
* definitions of [other elements]" [ISO/IEC 13818-1, 2nd edition].
* SOURCE
*/
namespace descriptor {
TSSI_MTD((R8<0>),
descriptor_tag);
TSSI_MTD((R8<1>),
descriptor_length);
inline ptrdiff_t size(gsl::span<const char> data) noexcept { return descriptor_length(data) + 2; }
}
/*******/
}
/****h* tssi/descriptor_loop
* NAME
* descriptor_loop -- Helper to define the length of single desriptors in
* descriptor lists for range_span.
* SOURCE
*/
namespace descriptor_loop = iso138181::descriptor;
/*******/
namespace iso138181 {
/****h* tssi::iso138181/private_section
* NAME
* private_section -- The syntax of a private section is the basic template for all
* PSI sections.
* DERIVED BY
* private_section_syntax
* SOURCE
*/
namespace private_section {
TSSI_MTD((R8<0>),
table_id);
TSSI_MTD((R1<1, 7>),
section_syntax_indicator);
TSSI_MTD((R1<1, 6>),
private_indicator);
TSSI_MTD((MS<R16<1>, 0xfff, 0>),
section_length);
// private_data_bytes
}
/*******/
/****h* tssi::iso138181/private_section_syntax
* NAME
* private_section_syntax -- PSI section with section_syntax_indicator == 1. Allows
* for versioning, multiple sections and crc32-checks.
* SOURCE
*/
namespace private_section_syntax {
using namespace private_section;
TSSI_MTD((R16<3>),
table_id_extension);
TSSI_MTD((MS<R8<5>, 0x3e, 1>),
version_number);
TSSI_MTD((R1<5, 0>),
current_next_indicator);
TSSI_MTD((R8<6>),
section_number);
TSSI_MTD((R8<7>),
last_section_number);
// private_data_bytes
// CRC_32
}
/*******/
/****h* tssi::iso138181/program_association_section
* NAME
* program_association_section -- "The Program Association Table provides
* the correspondence between a program_number and the PID value of the
* Transport Stream packets which carry the program definition. The program_number
* is the numeric label associated with a program" [ISO/IEC 13818-1, 2nd edition].
* - PID: 0x00
* - table_id: 0x00
* SOURCE
*/
namespace program_association_section {
using namespace private_section_syntax;
TSSI_MTD((R16<3>),
transport_stream_id);
inline size_t N(gsl::span<const char> data) noexcept { return (section_length(data) - 9) >> 2; }
// for (i = 0; i < N; i++) {
TSSI_MTD((R16<8, 4>),
program_number);
TSSI_MTD((MS<R16<8 + 2, 4>, 0x1fff, 0>),
program_map_PID);
// }
// CRC_32
}
/*******/
/****h* tssi::iso138181/CA_section
* NAME
* CA_section -- "The Conditional Access (CA) Table provides the association
* between one or more CA systems, their EMM streams and any special parameters
* associated with them" [ISO/IEC 13818-1, 2nd edition].
* - PID: 0x01
* - table_id: 0x01
* SOURCE
*/
namespace CA_section {
using namespace private_section_syntax;
namespace {
using section_length_t = MS<R16<1>, 0xfff, 0>;
}
TSSI_MTD((ITER<DAT<8, section_length_t, -9>, descriptor_loop::size>),
descriptors);
// CRC_32
}
/*******/
/****h* tssi::iso138181/TS_program_map_section
* NAME
* TS_program_map_section -- "The Program Map Table provides the mappings between
* program numbers and the program elements that comprise them"
* [ISO/IEC 13818-1, 2nd edition].
* - PID: indicated in program_association_section
* - table_id: 0x02
* SOURCE
*/
namespace TS_program_map_section {
using namespace private_section_syntax;
namespace {
using program_info_length_t =
MS<R16<10>, 0xfff, 0>;
using section_length_t =
MS<R16<1>, 0xfff, 0>;
}
TSSI_MTD((R16<3>),
program_number);
TSSI_MTD((MS<R16<8>, 0x1fff, 0>),
PCR_PID);
TSSI_MTD((program_info_length_t),
program_info_length);
TSSI_MTD((ITER<DAT<12, program_info_length_t>, descriptor_loop::size>),
descriptors);
// for (auto loop : program_info_loop(data)) {
namespace loop {
namespace {
using ES_info_length_t =
MS<R16<3>, 0xfff, 0>;
}
TSSI_MTD((R8<0>),
stream_type);
TSSI_MTD((MS<R16<1>, 0x1fff, 0>),
elementary_PID);
TSSI_MTD((ES_info_length_t),
ES_info_length);
TSSI_MTD((ITER<DAT<5, ES_info_length_t>, descriptor_loop::size>),
descriptors);
inline ptrdiff_t size(gsl::span<const char> data) noexcept { return ES_info_length(data) + 5; }
}
// }
TSSI_MTD((ITER<ADD_DAT<program_info_length_t, 12, SUB<section_length_t, program_info_length_t>, -13>, loop::size>),
program_info_loop);
// CRC_32
}
/*******/
/****h* tssi::iso138181/TS_description_section
* NAME
* TS_description_section -- "The Transport Stream Description Table is defined to
* support the carriage of descriptors [...] for an entire Transport Stream. The
* descriptors shall apply to the entire Transport Stream"
* [ISO/IEC 13818-1, 2nd edition].
* - PID: 0x02
* - table_id: 0x03
* SOURCE
*/
namespace TS_description_section {
using namespace private_section_syntax;
namespace {
using section_length_t = MS<R16<1>, 0xfff, 0>;
}
TSSI_MTD((ITER<DAT<8, section_length_t, -9>, descriptor_loop::size>),
descriptors);
// CRC_32
}
/*******/
}
namespace etsi300468 {
/****h* tssi::etsi300468/network_information_section
* NAME
* network_information_section -- "The NIT conveys information relating to the
* physical organization of the multiplexes/TSs carried via a given network, and
* the characteristics of the network itself" [ETSI EN 300 468 V1.13.1].
* - PID: 0x10
* - table_id: 0x40 (actual network), 0x41 (other network)
* SOURCE
*/
namespace network_information_section {
using namespace iso138181::private_section_syntax;
namespace {
using network_descriptors_length_t =
MS<R16<8>, 0xfff, 0>;
using transport_stream_loop_length_t =
MS<ADD_R16<network_descriptors_length_t, 10>, 0xfff, 0>;
}
TSSI_MTD((R16<3>),
network_id);
TSSI_MTD((network_descriptors_length_t),
network_descriptors_length);
TSSI_MTD((ITER<DAT<10, network_descriptors_length_t>, descriptor_loop::size>),
descriptors);
TSSI_MTD((transport_stream_loop_length_t),
transport_stream_loop_length);
// for (auto loop : transport_stream_loop(data)) {
namespace loop {
namespace {
using transport_descriptors_length_t =
MS<R16<4>, 0xfff, 0>;
}
TSSI_MTD((R16<0>),
transport_stream_id);
TSSI_MTD((R16<2>),
original_network_id);
TSSI_MTD((transport_descriptors_length_t),
transport_descriptors_length);
TSSI_MTD((ITER<DAT<6, transport_descriptors_length_t>, descriptor_loop::size>),
descriptors);
inline ptrdiff_t size(gsl::span<const char> data) noexcept { return transport_descriptors_length(data) + 6; }
}
// }
TSSI_MTD((ITER<ADD_DAT<network_descriptors_length_t, 12, transport_stream_loop_length_t>, loop::size>),
transport_stream_loop);
// CRC_32
}
/*******/
/****h* tssi::etsi300468/bouquet_association_section
* NAME
* bouquet_association_section -- "The BAT provides information regarding
* bouquets. A bouquet is a collection of services, which may traverse the boundary
* of a network" [ETSI EN 300 468 V1.13.1].
* - PID: 0x11
* - table_id: 0x4a
* SOURCE
*/
namespace bouquet_association_section {
using namespace iso138181::private_section_syntax;
namespace {
using bouquet_descriptors_length_t =
MS<R16<8>, 0xfff, 0>;
using transport_stream_loop_length_t =
MS<ADD_R16<bouquet_descriptors_length_t, 10>, 0xfff, 0>;
}
TSSI_MTD((R16<3>),
bouquet_id);
TSSI_MTD((bouquet_descriptors_length_t),
bouquet_descriptors_length);
TSSI_MTD((ITER<DAT<10, bouquet_descriptors_length_t>, descriptor_loop::size>),
descriptors);
TSSI_MTD((transport_stream_loop_length_t),
transport_stream_loop_length);
// for (auto loop : transport_stream_loop(data)) {
namespace loop {
namespace {
using transport_descriptors_length_t =
MS<R16<4>, 0xfff, 0>;
}
TSSI_MTD((R16<0>),
transport_stream_id);
TSSI_MTD((R16<2>),
original_network_id);
TSSI_MTD((transport_descriptors_length_t),
transport_descriptors_length);
TSSI_MTD((ITER<DAT<6, transport_descriptors_length_t>, descriptor_loop::size>),
descriptors);
inline ptrdiff_t size(gsl::span<const char> data) noexcept { return transport_descriptors_length(data) + 6; }
}
// }
TSSI_MTD((ITER<ADD_DAT<bouquet_descriptors_length_t, 12, transport_stream_loop_length_t>, loop::size>),
transport_stream_loop);
// CRC_32
}
/*******/
/****h* tssi::etsi300468/service_description_section
* NAME
* service_description_section -- "Each sub_table of the SDT shall describe services
* that are contained within a particular TS. The services may be part of the actual
* TS or part of other TSs" [ETSI EN 300 468 V1.13.1].
* - PID: 0x11
* - table_id: 0x42 (actual TS), 0x46 (other TS)
* SOURCE
*/
namespace service_description_section {
using namespace iso138181::private_section_syntax;
namespace {
using section_length_t =
MS<R16<1>, 0xfff, 0>;
}
TSSI_MTD((R16<3>),
transport_stream_id);
TSSI_MTD((R16<8>),
original_network_id);
// for (auto loop : service_info_loop(data)) {
namespace loop {
namespace {
using descriptors_loop_length_t =
MS<R16<3>, 0xfff, 0>;
}
TSSI_MTD((R16<0>),
service_id);
TSSI_MTD((R1<2, 1>),
EIT_schedule_flag);
TSSI_MTD((R1<2, 0>),
EIT_present_following_flag);
TSSI_MTD((MS<R8<3>, 0xe0, 5>),
running_status);
TSSI_MTD((R1<3, 4>),
free_CA_mode);
TSSI_MTD((descriptors_loop_length_t),
descriptors_loop_length);
TSSI_MTD((ITER<DAT<5, descriptors_loop_length_t>, descriptor_loop::size>),
descriptors);
inline ptrdiff_t size(gsl::span<const char> data) noexcept { return descriptors_loop_length(data) + 5; }
}
// }
TSSI_MTD((ITER<DAT<11, section_length_t, -12>, loop::size>),
service_info_loop);
// CRC_32
}
/*******/
/****h* tssi::etsi300468/event_information_section
* NAME
* event_information_section -- "The EIT provides information in chronological order
* regarding the events contained within each service" [ETSI EN 300 468 V1.13.1].
* - PID: 0x12
* - table_id: 0x4e (actual ts, present and following events)
* 0x4f (other ts, present and following events)
* 0x50 to 0x5f (actual ts, schedule)
* 0x60 to 0x6f (other ts, schedule)
* SOURCE
*/
namespace event_information_section {
using namespace iso138181::private_section_syntax;
namespace {
using section_length_t =
MS<R16<1>, 0xfff, 0>;
}
TSSI_MTD((R16<3>),
service_id);
TSSI_MTD((R16<8>),
transport_stream_id);
TSSI_MTD((R16<10>),
original_network_id);
TSSI_MTD((R8<12>),
segment_last_section_number);
TSSI_MTD((R8<13>),
last_table_id);
// for (auto loop : event_info_loop(data)) {
namespace loop {
namespace {
using descriptors_loop_length_t =
MS<R16<10>, 0xfff, 0>;
}
TSSI_MTD((R16<0>),
event_id);
TSSI_MTD((TIME<R40<2>>),
start_time);
TSSI_MTD((DUR<R24<7>>),
duration);
TSSI_MTD((MS<R8<10>, 0xe0, 5>),
running_status);
TSSI_MTD((R1<10, 4>),
free_CA_mode);
TSSI_MTD((descriptors_loop_length_t),
descriptors_loop_length);
TSSI_MTD((ITER<DAT<12, descriptors_loop_length_t>, descriptor_loop::size>),