Minimal support for ATSC PSIP tables. Does not support STT or
EIT tables and so is not compliant with terrestrial ATSC.
ATSC tables are not created by default, and will only be transmitted
if either "atsc_name" or "atsc_channel" metadata is supplied.
Signed-off-by: Phillip Burr
---
doc/muxers.texi | 33 +++-
libavformat/mpegts.h| 8 +
libavformat/mpegtsenc.c | 412
3 files changed, 372 insertions(+), 81 deletions(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index 83ae017d6c..dd68eec362 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1500,10 +1500,35 @@ MPEG transport stream muxer.
This muxer implements ISO 13818-1 and part of ETSI EN 300 468.
-The recognized metadata settings in mpegts muxer are @code{service_provider}
-and @code{service_name}. If they are not set the default for
-@code{service_provider} is @samp{FFmpeg} and the default for
-@code{service_name} is @samp{Service01}.
+@subsection Metadata
+
+The recognized metadata settings in this muxer are:
+
+@table @option
+@item service_name @var{string}
+Set the @code{service_provider}. Default is @samp{FFmpeg}.
+
+@item service_name @var{string}
+Set the @code{service_name}. Default is @samp{Service01}.
+
+@item atsc_name @var{string}
+Set the @code{atsc_name} for the stream. This is the ATSC short
+channel name for the stream.
+
+@item atsc_channel @var{string}
+Set the @code{atsc_channel} virtual channel for the stream. This
+is parsed as @samp{Channel[.SubChannel]} format where the subchannel
+is optional and defaults to @code{1}.
+
+@end table
+
+ATSC tables will @emph{not} be generated unless either @code{atsc_name}
+or @code{atsc_channel} are provided @emph{and} @code{muxrate} is provided.
+In the event that either @code{atsc_name} or @code{atsc_channel} is provided
+but not both, the default for @code{atsc_name} is @samp{FFmpeg}
+and the default for @code{atsc_channel} is @samp{1.1}.
+ATSC tables generated include @code{MGT} and @code{TVCT} tables but are
lacking the mandatory
+@code{STT}, @code{EIT0}, @code{EIT1}, @code{EIT2} and @code{EIT3} tables
needed for terrestrial ATC compliance.
@subsection Options
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index 272e2be4f7..ca6943b1ba 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -35,12 +35,20 @@
/* pids */
#define PAT_PID 0x
#define SDT_PID 0x0011
+#define ATSC_PID0x1ffb
/* table ids */
#define PAT_TID 0x00
#define PMT_TID 0x02
#define M4OD_TID 0x05
#define SDT_TID 0x42
+#define MGT_TID 0xc7
+#define TVCT_TID 0xc8
+#define CVCT_TID 0xc9
+#define RRT_TID 0xca
+#define EIT_TID 0xcb
+#define ETT_TID 0xcc
+#define STT_TID 0xcd
#define STREAM_TYPE_VIDEO_MPEG1 0x01
#define STREAM_TYPE_VIDEO_MPEG2 0x02
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index fc0ea225c6..cd3460e5f3 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -56,6 +56,11 @@ typedef struct MpegTSService {
int sid; /* service ID */
uint8_t name[256];
uint8_t provider_name[256];
+
+uint16_t atsc_name[7]; /* ATSC VCT fields */
+int atsc_mj_channel;
+int atsc_mn_channel;
+
int pcr_pid;
int pcr_packet_count;
int pcr_packet_period;
@@ -77,11 +82,16 @@ typedef struct MpegTSWrite {
const AVClass *av_class;
MpegTSSection pat; /* MPEG-2 PAT table */
MpegTSSection sdt; /* MPEG-2 SDT table context */
+MpegTSSection atsc; /* ATSC tables */
MpegTSService **services;
int sdt_packet_count;
int sdt_packet_period;
int pat_packet_count;
int pat_packet_period;
+int mgt_packet_count;
+int mgt_packet_period;
+int tvct_packet_count;
+int tvct_packet_period;
int nb_services;
int onid;
int tsid;
@@ -113,6 +123,9 @@ typedef struct MpegTSWrite {
double sdt_period;
int64_t last_pat_ts;
int64_t last_sdt_ts;
+int64_t last_mgt_ts;
+int64_t last_tvct_ts;
+int xmit_atsc;
int omit_video_pes_length;
} MpegTSWrite;
@@ -189,14 +202,24 @@ static inline void put16(uint8_t **q_ptr, int val)
*q_ptr = q;
}
+static inline void put32(uint8_t **q_ptr, int val)
+{
+uint8_t *q;
+q = *q_ptr;
+*q++ = val >> 24;
+*q++ = val >> 16;
+*q++ = val >> 8;
+*q++ = val;
+*q_ptr = q;
+}
+
static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
int version, int sec_num, int last_sec_num,
- uint8_t *buf, int len)
+ int private, uint8_t *buf, int len)
{
uint8_t section[1024], *q;
unsigned int tot_len;
-/* reserved_future_use field must be set to 1 for SDT */
-unsigned int flags = tid == SDT_TID ? 0xf000 : 0xb000;
+unsigned int flags = private ? 0xf000 : 0xb000;
tot_len = 3 + 5 + len + 4;
/* check if not too