Browse code

libavformat/mpegtsenc: allow to set service_type in sdt

This adds an option to set the service type in mpegts as defined in ETSI 300 468.

I added what I believe are the most useful service types as pre defined values,
the others can be sent by using their hexdecimal form directly (e.g. -mpegts_service_type digital_radio, -mpegts_service_type 0x07).

I've been using this patch in order to pipe internet radio stream (originally as HLS/m3u8) from ffmpeg to tvheadend,
when the service type set right tvheadend recognize the mpegts stream as a radio channel.

The patch in its original form was written by linuxstb from freenode's hts channel which allowed me pushing it upstream.

This close issue 4118.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

dhead666 authored on 2015/02/02 18:56:52
Showing 2 changed files
... ...
@@ -690,6 +690,9 @@ Set the transport_stream_id (default 0x0001). This identifies a
690 690
 transponder in DVB.
691 691
 @item -mpegts_service_id @var{number}
692 692
 Set the service_id (default 0x0001) also known as program in DVB.
693
+@item -mpegts_service_type @var{number}
694
+Set the program service_type (default @var{digital_tv}), see below
695
+a list of pre defined values.
693 696
 @item -mpegts_pmt_start_pid @var{number}
694 697
 Set the first PID for PMT (default 0x1000, max 0x1f00).
695 698
 @item -mpegts_start_pid @var{number}
... ...
@@ -724,6 +727,27 @@ ffmpeg -i source2.ts -codec copy -f mpegts -tables_version 1 udp://1.1.1.1:1111
724 724
 @end example
725 725
 @end table
726 726
 
727
+Option mpegts_service_type accepts the following values:
728
+
729
+@table @option
730
+@item hex_value
731
+Any hexdecimal value between 0x01 to 0xff as defined in ETSI 300 468.
732
+@item digital_tv
733
+Digital TV service.
734
+@item digital_radio
735
+Digital Radio service.
736
+@item teletext
737
+Teletext service.
738
+@item advanced_codec_digital_radio
739
+Advanced Codec Digital Radio service.
740
+@item mpeg2_digital_hdtv
741
+MPEG2 Digital HDTV service.
742
+@item advanced_codec_digital_sdtv
743
+Advanced Codec Digital SDTV service.
744
+@item advanced_codec_digital_hdtv
745
+Advanced Codec Digital HDTV service.
746
+@end table
747
+
727 748
 Option mpegts_flags may take a set of such flags:
728 749
 
729 750
 @table @option
... ...
@@ -76,6 +76,17 @@ typedef struct MpegTSWrite {
76 76
     int transport_stream_id;
77 77
     int original_network_id;
78 78
     int service_id;
79
+    int service_type;
80
+// service_type values as defined in ETSI 300 468
81
+   enum {
82
+     MPEGTS_SERVICE_TYPE_DIGITAL_TV                   = 0x01,
83
+     MPEGTS_SERVICE_TYPE_DIGITAL_RADIO                = 0x02,
84
+     MPEGTS_SERVICE_TYPE_TELETEXT                     = 0x03,
85
+     MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_RADIO = 0x0A,
86
+     MPEGTS_SERVICE_TYPE_MPEG2_DIGITAL_HDTV           = 0x11,
87
+     MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_SDTV  = 0x16,
88
+     MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_HDTV  = 0x19
89
+   };
79 90
 
80 91
     int pmt_start_pid;
81 92
     int start_pid;
... ...
@@ -521,7 +532,7 @@ static void mpegts_write_sdt(AVFormatContext *s)
521 521
         *q++         = 0x48;
522 522
         desc_len_ptr = q;
523 523
         q++;
524
-        *q++         = 0x01; /* digital television service */
524
+        *q++         = ts->service_type;
525 525
         putstr8(&q, service->provider_name);
526 526
         putstr8(&q, service->name);
527 527
         desc_len_ptr[0] = q - desc_len_ptr - 1;
... ...
@@ -1434,6 +1445,30 @@ static const AVOption options[] = {
1434 1434
     { "mpegts_service_id", "Set service_id field.",
1435 1435
       offsetof(MpegTSWrite, service_id), AV_OPT_TYPE_INT,
1436 1436
       { .i64 = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM },
1437
+    { "mpegts_service_type", "Set service_type field.",
1438
+      offsetof(MpegTSWrite, service_type), AV_OPT_TYPE_INT,
1439
+      { .i64 = 0x01 }, 0x01, 0xff, AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1440
+    { "digital_tv", "Digital Television.",
1441
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_DIGITAL_TV }, 0x01, 0xff,
1442
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1443
+    { "digital_radio", "Digital Radio.",
1444
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_DIGITAL_RADIO }, 0x01, 0xff,
1445
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1446
+    { "teletext", "Teletext.",
1447
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_TELETEXT }, 0x01, 0xff,
1448
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1449
+    { "advanced_codec_digital_radio", "Advanced Codec Digital Radio.",
1450
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_RADIO }, 0x01, 0xff,
1451
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1452
+    { "mpeg2_digital_hdtv", "MPEG2 Digital HDTV.",
1453
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_MPEG2_DIGITAL_HDTV }, 0x01, 0xff,
1454
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1455
+    { "advanced_codec_digital_sdtv", "Advanced Codec Digital SDTV.",
1456
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_SDTV }, 0x01, 0xff,
1457
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1458
+    { "advanced_codec_digital_hdtv", "Advanced Codec Digital HDTV.",
1459
+      0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_HDTV }, 0x01, 0xff,
1460
+      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
1437 1461
     { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
1438 1462
       offsetof(MpegTSWrite, pmt_start_pid), AV_OPT_TYPE_INT,
1439 1463
       { .i64 = 0x1000 }, 0x0010, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM },