diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-06-30 10:11:22 +0200 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2012-06-30 14:03:54 +0200 |
commit | 0689d5e17ac0a3269c604b4df2c01140be328647 (patch) | |
tree | b13f02db581e86c23feeaeffa396503ef37cef0c /libavfilter/audio.c | |
parent | c9c4835f5164b86510591d4ba604bfb448c7a356 (diff) | |
download | ffmpeg-0689d5e17ac0a3269c604b4df2c01140be328647.tar.gz |
lavfi: implement samples framing on links.
Links can be set up to group samples into buffers of
specified minimum and maximum size.
Diffstat (limited to 'libavfilter/audio.c')
-rw-r--r-- | libavfilter/audio.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 6a86597342..0ebec3c2d0 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -156,7 +156,8 @@ static void default_filter_samples(AVFilterLink *link, ff_filter_samples(link->dst->outputs[0], samplesref); } -void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) +void ff_filter_samples_framed(AVFilterLink *link, + AVFilterBufferRef *samplesref) { void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); AVFilterPad *dst = link->dstpad; @@ -195,3 +196,48 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) filter_samples(link, buf_out); ff_update_link_current_pts(link, pts); } + +void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) +{ + int insamples = samplesref->audio->nb_samples, inpos = 0, nb_samples; + AVFilterBufferRef *pbuf = link->partial_buf; + int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout); + + if (!link->min_samples || + (!pbuf && + insamples >= link->min_samples && insamples <= link->max_samples)) { + ff_filter_samples_framed(link, samplesref); + return; + } + /* Handle framing (min_samples, max_samples) */ + while (insamples) { + if (!pbuf) { + AVRational samples_tb = { 1, link->sample_rate }; + int perms = link->dstpad->min_perms | AV_PERM_WRITE; + pbuf = ff_get_audio_buffer(link, perms, link->partial_buf_size); + if (!pbuf) { + av_log(link->dst, AV_LOG_WARNING, + "Samples dropped due to memory allocation failure.\n"); + return; + } + avfilter_copy_buffer_ref_props(pbuf, samplesref); + pbuf->pts = samplesref->pts + + av_rescale_q(inpos, samples_tb, link->time_base); + pbuf->audio->nb_samples = 0; + } + nb_samples = FFMIN(insamples, + link->partial_buf_size - pbuf->audio->nb_samples); + av_samples_copy(pbuf->extended_data, samplesref->extended_data, + pbuf->audio->nb_samples, inpos, + nb_samples, nb_channels, link->format); + inpos += nb_samples; + insamples -= nb_samples; + pbuf->audio->nb_samples += nb_samples; + if (pbuf->audio->nb_samples >= link->min_samples) { + ff_filter_samples_framed(link, pbuf); + pbuf = NULL; + } + } + avfilter_unref_buffer(samplesref); + link->partial_buf = pbuf; +} |