summaryrefslogtreecommitdiff
path: root/libavformat/mpegtsenc.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2015-11-18 19:23:03 +0100
committerStefano Sabatini <stefasab@gmail.com>2016-02-23 18:44:12 +0100
commit14f7a3d55a43c1082ee1186a1990a431c641052d (patch)
tree8413603eb9ebbdfb8f6e84b8356a314d9101e19f /libavformat/mpegtsenc.c
parent3ba57bfe8ddcf151d0dcfc6bdfe76b2bb57ba018 (diff)
lavc/lavf: transmit stream_id information for mpegts KLV data packets
This allows to copy information related to the stream ID from the demuxer to the muxer, thus allowing for example to retain information related to synchronous and asynchronous KLV data packets. This information is used in the muxer when remuxing to distinguish the two kind of packets (if the information is lacking, data packets are considered synchronous). The fate reference changes are due to the use of av_packet_merge_side_data(), which increases the size of the output packet size, since side data is merged into the packet data.
Diffstat (limited to 'libavformat/mpegtsenc.c')
-rw-r--r--libavformat/mpegtsenc.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 765672067a..68f98673da 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1111,7 +1111,7 @@ static uint8_t *get_ts_payload_start(uint8_t *pkt)
* NOTE: 'payload' contains a complete PES payload. */
static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
const uint8_t *payload, int payload_size,
- int64_t pts, int64_t dts, int key)
+ int64_t pts, int64_t dts, int key, int stream_id)
{
MpegTSWriteStream *ts_st = st->priv_data;
MpegTSWrite *ts = s->priv_data;
@@ -1208,6 +1208,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
st->codec->codec_id == AV_CODEC_ID_AC3 &&
ts->m2ts_mode) {
*q++ = 0xfd;
+ } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) {
+ *q++ = stream_id != -1 ? stream_id : 0xfc;
+
+ if (stream_id == 0xbd) /* asynchronous KLV */
+ pts = dts = AV_NOPTS_VALUE;
} else {
*q++ = 0xbd;
if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
@@ -1451,6 +1456,15 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) * 2;
int64_t dts = pkt->dts, pts = pkt->pts;
int opus_samples = 0;
+ int side_data_size;
+ char *side_data = NULL;
+ int stream_id = -1;
+
+ side_data = av_packet_get_side_data(pkt,
+ AV_PKT_DATA_MPEGTS_STREAM_ID,
+ &side_data_size);
+ if (side_data)
+ stream_id = side_data[0];
if (ts->reemit_pat_pmt) {
av_log(s, AV_LOG_WARNING,
@@ -1629,8 +1643,8 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
if ( ts_st2->payload_size
&& (ts_st2->payload_dts == AV_NOPTS_VALUE || dts - ts_st2->payload_dts > delay/2)) {
mpegts_write_pes(s, st2, ts_st2->payload, ts_st2->payload_size,
- ts_st2->payload_pts, ts_st2->payload_dts,
- ts_st2->payload_flags & AV_PKT_FLAG_KEY);
+ ts_st2->payload_pts, ts_st2->payload_dts,
+ ts_st2->payload_flags & AV_PKT_FLAG_KEY, stream_id);
ts_st2->payload_size = 0;
}
}
@@ -1643,7 +1657,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
ts_st->opus_queued_samples + opus_samples >= 5760 /* 120ms */)) {
mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size,
ts_st->payload_pts, ts_st->payload_dts,
- ts_st->payload_flags & AV_PKT_FLAG_KEY);
+ ts_st->payload_flags & AV_PKT_FLAG_KEY, stream_id);
ts_st->payload_size = 0;
ts_st->opus_queued_samples = 0;
}
@@ -1652,7 +1666,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
av_assert0(!ts_st->payload_size);
// for video and subtitle, write a single pes packet
mpegts_write_pes(s, st, buf, size, pts, dts,
- pkt->flags & AV_PKT_FLAG_KEY);
+ pkt->flags & AV_PKT_FLAG_KEY, stream_id);
ts_st->opus_queued_samples = 0;
av_free(data);
return 0;
@@ -1684,7 +1698,7 @@ static void mpegts_write_flush(AVFormatContext *s)
if (ts_st->payload_size > 0) {
mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size,
ts_st->payload_pts, ts_st->payload_dts,
- ts_st->payload_flags & AV_PKT_FLAG_KEY);
+ ts_st->payload_flags & AV_PKT_FLAG_KEY, -1);
ts_st->payload_size = 0;
ts_st->opus_queued_samples = 0;
}