[FFmpeg-devel] [PATCH] examples/filtering_audio: update to new API
Clément Bœsch
ubitux at gmail.com
Thu Mar 14 01:40:33 CET 2013
On Wed, Mar 13, 2013 at 10:09:10PM +0100, Stefano Sabatini wrote:
> In particular, fix crash.
> ---
> doc/examples/filtering_audio.c | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
> index ad69d32..01e6926 100644
> --- a/doc/examples/filtering_audio.c
> +++ b/doc/examples/filtering_audio.c
> @@ -150,11 +150,10 @@ static int init_filters(const char *filters_descr)
> return 0;
> }
>
> -static void print_samplesref(AVFilterBufferRef *samplesref)
> +static void print_frame(AVFrame *frame)
Note: I think this could be made const.
> {
> - const AVFilterBufferRefAudioProps *props = samplesref->audio;
> - const int n = props->nb_samples * av_get_channel_layout_nb_channels(props->channel_layout);
> - const uint16_t *p = (uint16_t*)samplesref->data[0];
> + const int n = frame->nb_samples * av_get_channel_layout_nb_channels(av_frame_get_channel_layout(frame));
> + const uint16_t *p = (uint16_t*)frame->data[0];
> const uint16_t *p_end = p + n;
>
> while (p < p_end) {
> @@ -169,10 +168,11 @@ int main(int argc, char **argv)
> {
> int ret;
> AVPacket packet;
> - AVFrame *frame = avcodec_alloc_frame();
> + AVFrame *frame = av_frame_alloc();
> + AVFrame *filt_frame = av_frame_alloc();
> int got_frame;
>
> - if (!frame) {
> + if (!frame || !filt_frame) {
> perror("Could not allocate frame");
> exit(1);
> }
> @@ -192,7 +192,6 @@ int main(int argc, char **argv)
>
> /* read all packets */
> while (1) {
> - AVFilterBufferRef *samplesref;
> if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
> break;
>
> @@ -207,22 +206,20 @@ int main(int argc, char **argv)
>
> if (got_frame) {
> /* push the audio data from decoded frame into the filtergraph */
> - if (av_buffersrc_add_frame(buffersrc_ctx, frame) < 0) {
> + if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
> av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
> break;
> }
>
> /* pull filtered audio from the filtergraph */
> while (1) {
> - ret = av_buffersink_get_buffer_ref(buffersink_ctx, &samplesref, 0);
> + ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
> if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
> break;
> if(ret < 0)
> goto end;
> - if (samplesref) {
> - print_samplesref(samplesref);
> - avfilter_unref_bufferp(&samplesref);
> - }
> + print_frame(filt_frame);
> + av_frame_unref(filt_frame);
> }
> }
> }
> @@ -233,7 +230,8 @@ end:
> if (dec_ctx)
> avcodec_close(dec_ctx);
> avformat_close_input(&fmt_ctx);
> - av_freep(&frame);
> + av_frame_free(&frame);
> + av_frame_free(&filt_frame);
>
> if (ret < 0 && ret != AVERROR_EOF) {
> char buf[1024];
I wonder if a in_frame/out_frame naming wouldn't be more easy to
understand (or at least just a note along with each alloc).
Patch LGTM.
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130314/344569b3/attachment.asc>
More information about the ffmpeg-devel
mailing list