diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-12-29 01:40:34 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-12-29 01:40:34 +0100 |
commit | 6071e4d87a9b257c3f7b5912825ede9caa757624 (patch) | |
tree | aeaad3a1d7eb0b27f20a66665740d2a96e99f7c2 /libavformat/mpegtsenc.c | |
parent | 7e5cbb3c2d96c27d526aa69cbdbd1ab23739d7e5 (diff) | |
parent | 8f5216905f88510c9a74cd91a424902aa989b9a1 (diff) | |
download | ffmpeg-6071e4d87a9b257c3f7b5912825ede9caa757624.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
v410dec: Check for sufficient input data. Fixes crash
fate: Add v210 codec regression tests
mpegts: adjustable minimum PES payload
mpegts: properly output large audio packets
avformat: Add SMJPEG demuxer.
Indeo 4 decoder
Conflicts:
doc/general.texi
libavcodec/v410dec.c
libavcodec/version.h
libavformat/mpegtsenc.c
libavformat/smjpeg.c
libavformat/version.h
tests/codec-regression.sh
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/mpegtsenc.c')
-rw-r--r-- | libavformat/mpegtsenc.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 29b679a948..e4caa7cbcf 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -69,6 +69,7 @@ typedef struct MpegTSWrite { int tsid; int64_t first_pcr; int mux_rate; ///< set to 1 when VBR + int pes_payload_size; int transport_stream_id; int original_network_id; @@ -79,6 +80,10 @@ typedef struct MpegTSWrite { int m2ts_mode; } MpegTSWrite; +/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ +#define DEFAULT_PES_HEADER_FREQ 16 +#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) + static const AVOption options[] = { { "mpegts_transport_stream_id", "Set transport_stream_id field.", offsetof(MpegTSWrite, transport_stream_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, @@ -94,6 +99,8 @@ static const AVOption options[] = { offsetof(MpegTSWrite, m2ts_mode), AV_OPT_TYPE_INT, {.dbl = -1 }, -1,1, AV_OPT_FLAG_ENCODING_PARAM}, { "muxrate", NULL, offsetof(MpegTSWrite, mux_rate), AV_OPT_TYPE_INT, {1}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, + { "pes_payload_size", "Minimum PES packet payload in bytes", + offsetof(MpegTSWrite, pes_payload_size), AV_OPT_TYPE_INT, {DEFAULT_PES_PAYLOAD_SIZE}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, { NULL }, }; @@ -193,10 +200,6 @@ static int mpegts_write_section1(MpegTSSection *s, int tid, int id, #define DEFAULT_PROVIDER_NAME "FFmpeg" #define DEFAULT_SERVICE_NAME "Service01" -/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ -#define DEFAULT_PES_HEADER_FREQ 16 -#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) - /* we retransmit the SI info at this rate */ #define SDT_RETRANS_TIME 500 #define PAT_RETRANS_TIME 100 @@ -211,7 +214,7 @@ typedef struct MpegTSWriteStream { int64_t payload_pts; int64_t payload_dts; int payload_flags; - uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE]; + uint8_t *payload; ADTSContext *adts; } MpegTSWriteStream; @@ -483,6 +486,9 @@ static int mpegts_write_header(AVFormatContext *s) const char *provider_name; int *pids; + // round up to a whole number of TS packets + ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14; + ts->tsid = ts->transport_stream_id; ts->onid = ts->original_network_id; /* allocate a single DVB service */ @@ -519,6 +525,9 @@ static int mpegts_write_header(AVFormatContext *s) if (!ts_st) goto fail; st->priv_data = ts_st; + ts_st->payload = av_mallocz(ts->pes_payload_size); + if (!ts_st->payload) + goto fail; ts_st->service = service; /* MPEG pid values < 16 are reserved. Applications which set st->id in * this range are assigned a calculated pid. */ @@ -554,10 +563,10 @@ static int mpegts_write_header(AVFormatContext *s) st->codec->extradata_size > 0) { ts_st->adts = av_mallocz(sizeof(*ts_st->adts)); if (!ts_st->adts) - return AVERROR(ENOMEM); + goto fail; if (ff_adts_decode_extradata(s, ts_st->adts, st->codec->extradata, st->codec->extradata_size) < 0) - return -1; + goto fail; } } @@ -633,7 +642,13 @@ static int mpegts_write_header(AVFormatContext *s) fail: av_free(pids); for(i = 0;i < s->nb_streams; i++) { + MpegTSWriteStream *ts_st; st = s->streams[i]; + ts_st = st->priv_data; + if (ts_st) { + av_freep(&ts_st->payload); + av_freep(&ts_st->adts); + } av_freep(&st->priv_data); } return -1; @@ -959,6 +974,7 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) int size = pkt->size; uint8_t *buf= pkt->data; uint8_t *data= NULL; + MpegTSWrite *ts = s->priv_data; MpegTSWriteStream *ts_st = st->priv_data; const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE)*2; int64_t dts = AV_NOPTS_VALUE, pts = AV_NOPTS_VALUE; @@ -1034,14 +1050,14 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (ts_st->payload_size && ts_st->payload_size + size > DEFAULT_PES_PAYLOAD_SIZE) { + if (ts_st->payload_size && ts_st->payload_size + size > ts->pes_payload_size) { 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_size = 0; } - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || size > DEFAULT_PES_PAYLOAD_SIZE) { + if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || size > ts->pes_payload_size) { 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); @@ -1080,6 +1096,7 @@ static int mpegts_write_end(AVFormatContext *s) ts_st->payload_pts, ts_st->payload_dts, ts_st->payload_flags & AV_PKT_FLAG_KEY); } + av_freep(&ts_st->payload); av_freep(&ts_st->adts); } avio_flush(s->pb); |