diff options
author | Vignesh Venkatasubramanian <vigneshv@google.com> | 2013-09-10 12:07:43 -0700 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-09-10 22:53:21 +0200 |
commit | 889bc79b5f5cef757be3b23dd44c9908fc08330e (patch) | |
tree | 931da112da068bcc15b5111640bcd54691dd69ae /libavcodec/utils.c | |
parent | bf5ceeffc3c47035819ad7a6b1bf67e2911a1041 (diff) | |
download | ffmpeg-889bc79b5f5cef757be3b23dd44c9908fc08330e.tar.gz |
lavc/utils: Add support for discarding samples from the end
Adding support for discarding samples from the end based on the value in
AV_PKT_DATA_SKIP_SAMPLES side data's bytes 5-8.
Signed-off By: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7f361ef876..65bf38397a 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2112,6 +2112,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) { uint8_t *side; int side_size; + uint32_t discard_padding = 0; // copy to ensure we do not change avpkt AVPacket tmp = *avpkt; int did_split = av_packet_split_side_data(&tmp); @@ -2146,6 +2147,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, avctx->internal->skip_samples = AV_RL32(side); av_log(avctx, AV_LOG_DEBUG, "skip %d samples due to side data\n", avctx->internal->skip_samples); + discard_padding = AV_RL32(side + 4); } if (avctx->internal->skip_samples && *got_frame_ptr) { if(frame->nb_samples <= avctx->internal->skip_samples){ @@ -2176,6 +2178,25 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, } } + if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) { + if (discard_padding == frame->nb_samples) { + *got_frame_ptr = 0; + } else { + if(avctx->pkt_timebase.num && avctx->sample_rate) { + int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding, + (AVRational){1, avctx->sample_rate}, + avctx->pkt_timebase); + if (av_frame_get_pkt_duration(frame) >= diff_ts) + av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts); + } else { + av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n"); + } + av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n", + discard_padding, frame->nb_samples); + frame->nb_samples -= discard_padding; + } + } + avctx->pkt = NULL; if (did_split) { av_packet_free_side_data(&tmp); |