diff options
author | Vignesh Venkatasubramanian <vigneshv@google.com> | 2013-08-30 11:26:53 -0700 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-09-11 01:03:07 +0200 |
commit | ae12d655384a48d5a958140abf876f06d9371832 (patch) | |
tree | 8d030fa9c78d5bdb88b914742e7e2af3f0d3d099 | |
parent | 7b0a839b0bbdcb76b834cd4d4a724b414a63ce47 (diff) | |
download | ffmpeg-ae12d655384a48d5a958140abf876f06d9371832.tar.gz |
lavcodec: Adding support for End Trimming in Opus encoder
Adds the end trimming value (duration to be trimmed from the end
of the file due to padding) to the packet's side data. This is
then made use by the muxer to put the value in the container.
Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/libopusenc.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c index 59caac76c7..6b22b753c5 100644 --- a/libavcodec/libopusenc.c +++ b/libavcodec/libopusenc.c @@ -313,6 +313,7 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, av_get_bytes_per_sample(avctx->sample_fmt); uint8_t *audio; int ret; + int discard_padding; if (frame) { ff_af_queue_add(&opus->afq, frame); @@ -354,6 +355,25 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&opus->afq, opus->opts.packet_size, &avpkt->pts, &avpkt->duration); + discard_padding = opus->opts.packet_size - avpkt->duration; + // Check if subtraction resulted in an overflow + if ((discard_padding < opus->opts.packet_size) != (avpkt->duration > 0)) { + av_free_packet(avpkt); + av_free(avpkt); + return AVERROR(EINVAL); + } + if (discard_padding > 0) { + uint8_t* side_data = av_packet_new_side_data(avpkt, + AV_PKT_DATA_SKIP_SAMPLES, + 10); + if(side_data == NULL) { + av_free_packet(avpkt); + av_free(avpkt); + return AVERROR(ENOMEM); + } + AV_WL32(side_data + 4, discard_padding); + } + *got_packet_ptr = 1; return 0; |