From 394a2a04527d480b605a4c7331222df03f964fcd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 16 May 2012 08:15:54 +0200 Subject: lavfi: rename vf_fifo.c -> fifo.c It will be used for audio too. --- libavfilter/Makefile | 2 +- libavfilter/fifo.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ libavfilter/vf_fifo.c | 121 -------------------------------------------------- 3 files changed, 122 insertions(+), 122 deletions(-) create mode 100644 libavfilter/fifo.c delete mode 100644 libavfilter/vf_fifo.c (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 955a97cafb..a4cc7f3737 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -47,7 +47,7 @@ OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o OBJS-$(CONFIG_DRAWTEXT_FILTER) += vf_drawtext.o OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o OBJS-$(CONFIG_FIELDORDER_FILTER) += vf_fieldorder.o -OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o +OBJS-$(CONFIG_FIFO_FILTER) += fifo.o OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_FPS_FILTER) += vf_fps.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c new file mode 100644 index 0000000000..1785946a4f --- /dev/null +++ b/libavfilter/fifo.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2007 Bobby Bingham + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * FIFO buffering video filter + */ + +#include "avfilter.h" +#include "internal.h" +#include "video.h" + +typedef struct BufPic { + AVFilterBufferRef *picref; + struct BufPic *next; +} BufPic; + +typedef struct { + BufPic root; + BufPic *last; ///< last buffered picture +} FifoContext; + +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +{ + FifoContext *fifo = ctx->priv; + fifo->last = &fifo->root; + + av_log(ctx, AV_LOG_INFO, "\n"); + return 0; +} + +static av_cold void uninit(AVFilterContext *ctx) +{ + FifoContext *fifo = ctx->priv; + BufPic *pic, *tmp; + + for (pic = fifo->root.next; pic; pic = tmp) { + tmp = pic->next; + avfilter_unref_buffer(pic->picref); + av_free(pic); + } +} + +static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) +{ + FifoContext *fifo = inlink->dst->priv; + + fifo->last->next = av_mallocz(sizeof(BufPic)); + fifo->last = fifo->last->next; + fifo->last->picref = picref; +} + +static void end_frame(AVFilterLink *inlink) { } + +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } + +static int request_frame(AVFilterLink *outlink) +{ + FifoContext *fifo = outlink->src->priv; + BufPic *tmp; + int ret; + + if (!fifo->root.next) { + if ((ret = ff_request_frame(outlink->src->inputs[0]) < 0)) + return ret; + } + + /* by doing this, we give ownership of the reference to the next filter, + * so we don't have to worry about dereferencing it ourselves. */ + ff_start_frame(outlink, fifo->root.next->picref); + ff_draw_slice (outlink, 0, outlink->h, 1); + ff_end_frame (outlink); + + if (fifo->last == fifo->root.next) + fifo->last = &fifo->root; + tmp = fifo->root.next->next; + av_free(fifo->root.next); + fifo->root.next = tmp; + + return 0; +} + +AVFilter avfilter_vf_fifo = { + .name = "fifo", + .description = NULL_IF_CONFIG_SMALL("Buffer input images and send them when they are requested."), + + .init = init, + .uninit = uninit, + + .priv_size = sizeof(FifoContext), + + .inputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer= ff_null_get_video_buffer, + .start_frame = start_frame, + .draw_slice = draw_slice, + .end_frame = end_frame, + .rej_perms = AV_PERM_REUSE2, }, + { .name = NULL}}, + .outputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .request_frame = request_frame, }, + { .name = NULL}}, +}; diff --git a/libavfilter/vf_fifo.c b/libavfilter/vf_fifo.c deleted file mode 100644 index 1785946a4f..0000000000 --- a/libavfilter/vf_fifo.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2007 Bobby Bingham - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * FIFO buffering video filter - */ - -#include "avfilter.h" -#include "internal.h" -#include "video.h" - -typedef struct BufPic { - AVFilterBufferRef *picref; - struct BufPic *next; -} BufPic; - -typedef struct { - BufPic root; - BufPic *last; ///< last buffered picture -} FifoContext; - -static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) -{ - FifoContext *fifo = ctx->priv; - fifo->last = &fifo->root; - - av_log(ctx, AV_LOG_INFO, "\n"); - return 0; -} - -static av_cold void uninit(AVFilterContext *ctx) -{ - FifoContext *fifo = ctx->priv; - BufPic *pic, *tmp; - - for (pic = fifo->root.next; pic; pic = tmp) { - tmp = pic->next; - avfilter_unref_buffer(pic->picref); - av_free(pic); - } -} - -static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) -{ - FifoContext *fifo = inlink->dst->priv; - - fifo->last->next = av_mallocz(sizeof(BufPic)); - fifo->last = fifo->last->next; - fifo->last->picref = picref; -} - -static void end_frame(AVFilterLink *inlink) { } - -static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } - -static int request_frame(AVFilterLink *outlink) -{ - FifoContext *fifo = outlink->src->priv; - BufPic *tmp; - int ret; - - if (!fifo->root.next) { - if ((ret = ff_request_frame(outlink->src->inputs[0]) < 0)) - return ret; - } - - /* by doing this, we give ownership of the reference to the next filter, - * so we don't have to worry about dereferencing it ourselves. */ - ff_start_frame(outlink, fifo->root.next->picref); - ff_draw_slice (outlink, 0, outlink->h, 1); - ff_end_frame (outlink); - - if (fifo->last == fifo->root.next) - fifo->last = &fifo->root; - tmp = fifo->root.next->next; - av_free(fifo->root.next); - fifo->root.next = tmp; - - return 0; -} - -AVFilter avfilter_vf_fifo = { - .name = "fifo", - .description = NULL_IF_CONFIG_SMALL("Buffer input images and send them when they are requested."), - - .init = init, - .uninit = uninit, - - .priv_size = sizeof(FifoContext), - - .inputs = (AVFilterPad[]) {{ .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .get_video_buffer= ff_null_get_video_buffer, - .start_frame = start_frame, - .draw_slice = draw_slice, - .end_frame = end_frame, - .rej_perms = AV_PERM_REUSE2, }, - { .name = NULL}}, - .outputs = (AVFilterPad[]) {{ .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .request_frame = request_frame, }, - { .name = NULL}}, -}; -- cgit v1.2.3 From 27570e211a080a9a0498bac16364447508e3ba7c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 27 May 2012 22:45:52 +0200 Subject: fifo: fix parenthesis placement. --- libavfilter/fifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c index 1785946a4f..6d21d5db2f 100644 --- a/libavfilter/fifo.c +++ b/libavfilter/fifo.c @@ -78,7 +78,7 @@ static int request_frame(AVFilterLink *outlink) int ret; if (!fifo->root.next) { - if ((ret = ff_request_frame(outlink->src->inputs[0]) < 0)) + if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0) return ret; } -- cgit v1.2.3 From 4a97ff2fa7a733e657c464640f6f787293849aee Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 16 May 2012 08:21:47 +0200 Subject: lavfi/fifo: add audio version of the fifo filter. --- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/fifo.c | 71 ++++++++++++++++++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 20 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index a4cc7f3737..377956e6af 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -25,6 +25,7 @@ OBJS = allfilters.o \ vf_scale.o \ video.o \ +OBJS-$(CONFIG_AFIFO_FILTER) += fifo.o OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 118f09d057..5a249c08c8 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -34,6 +34,7 @@ void avfilter_register_all(void) return; initialized = 1; + REGISTER_FILTER (AFIFO, afifo, af); REGISTER_FILTER (AFORMAT, aformat, af); REGISTER_FILTER (AMIX, amix, af); REGISTER_FILTER (ANULL, anull, af); diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c index 6d21d5db2f..3fa4faab39 100644 --- a/libavfilter/fifo.c +++ b/libavfilter/fifo.c @@ -20,21 +20,22 @@ /** * @file - * FIFO buffering video filter + * FIFO buffering filter */ +#include "audio.h" #include "avfilter.h" #include "internal.h" #include "video.h" -typedef struct BufPic { - AVFilterBufferRef *picref; - struct BufPic *next; -} BufPic; +typedef struct Buf { + AVFilterBufferRef *buf; + struct Buf *next; +} Buf; typedef struct { - BufPic root; - BufPic *last; ///< last buffered picture + Buf root; + Buf *last; ///< last buffered frame } FifoContext; static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) @@ -49,22 +50,22 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) static av_cold void uninit(AVFilterContext *ctx) { FifoContext *fifo = ctx->priv; - BufPic *pic, *tmp; + Buf *buf, *tmp; - for (pic = fifo->root.next; pic; pic = tmp) { - tmp = pic->next; - avfilter_unref_buffer(pic->picref); - av_free(pic); + for (buf = fifo->root.next; buf; buf = tmp) { + tmp = buf->next; + avfilter_unref_buffer(buf->buf); + av_free(buf); } } -static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) +static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf) { FifoContext *fifo = inlink->dst->priv; - fifo->last->next = av_mallocz(sizeof(BufPic)); + fifo->last->next = av_mallocz(sizeof(Buf)); fifo->last = fifo->last->next; - fifo->last->picref = picref; + fifo->last->buf = buf; } static void end_frame(AVFilterLink *inlink) { } @@ -74,7 +75,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } static int request_frame(AVFilterLink *outlink) { FifoContext *fifo = outlink->src->priv; - BufPic *tmp; + Buf *tmp; int ret; if (!fifo->root.next) { @@ -84,9 +85,18 @@ static int request_frame(AVFilterLink *outlink) /* by doing this, we give ownership of the reference to the next filter, * so we don't have to worry about dereferencing it ourselves. */ - ff_start_frame(outlink, fifo->root.next->picref); - ff_draw_slice (outlink, 0, outlink->h, 1); - ff_end_frame (outlink); + switch (outlink->type) { + case AVMEDIA_TYPE_VIDEO: + ff_start_frame(outlink, fifo->root.next->buf); + ff_draw_slice (outlink, 0, outlink->h, 1); + ff_end_frame (outlink); + break; + case AVMEDIA_TYPE_AUDIO: + ff_filter_samples(outlink, fifo->root.next->buf); + break; + default: + return AVERROR(EINVAL); + } if (fifo->last == fifo->root.next) fifo->last = &fifo->root; @@ -109,7 +119,7 @@ AVFilter avfilter_vf_fifo = { .inputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, .get_video_buffer= ff_null_get_video_buffer, - .start_frame = start_frame, + .start_frame = add_to_queue, .draw_slice = draw_slice, .end_frame = end_frame, .rej_perms = AV_PERM_REUSE2, }, @@ -119,3 +129,24 @@ AVFilter avfilter_vf_fifo = { .request_frame = request_frame, }, { .name = NULL}}, }; + +AVFilter avfilter_af_afifo = { + .name = "afifo", + .description = NULL_IF_CONFIG_SMALL("Buffer input frames and send them when they are requested."), + + .init = init, + .uninit = uninit, + + .priv_size = sizeof(FifoContext), + + .inputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .get_audio_buffer = ff_null_get_audio_buffer, + .filter_samples = add_to_queue, + .rej_perms = AV_PERM_REUSE2, }, + { .name = NULL}}, + .outputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .request_frame = request_frame, }, + { .name = NULL}}, +}; -- cgit v1.2.3 From e026c9b390102fc8b77e6d49ba7a6db7b7c80324 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 17 Jun 2012 10:21:49 +0200 Subject: lavfi/audio: don't set cur_buf in ff_filter_samples(). It's redundant, since the input buffer is passed as a parameter to the filter_samples() callback, and can lead to stale pointers remaining on the link. --- libavfilter/audio.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/audio.c b/libavfilter/audio.c index a6fef9d273..72e2ced478 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -176,6 +176,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); AVFilterPad *dst = link->dstpad; + AVFilterBufferRef *buf_out; FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1); @@ -189,21 +190,21 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n", samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms); - link->cur_buf = ff_default_get_audio_buffer(link, dst->min_perms, - samplesref->audio->nb_samples); - link->cur_buf->pts = samplesref->pts; - link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate; + buf_out = ff_default_get_audio_buffer(link, dst->min_perms, + samplesref->audio->nb_samples); + buf_out->pts = samplesref->pts; + buf_out->audio->sample_rate = samplesref->audio->sample_rate; /* Copy actual data into new samples buffer */ - av_samples_copy(link->cur_buf->extended_data, samplesref->extended_data, + av_samples_copy(buf_out->extended_data, samplesref->extended_data, 0, 0, samplesref->audio->nb_samples, av_get_channel_layout_nb_channels(link->channel_layout), link->format); avfilter_unref_buffer(samplesref); } else - link->cur_buf = samplesref; + buf_out = samplesref; - filter_samples(link, link->cur_buf); + filter_samples(link, buf_out); } -- cgit v1.2.3