diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-06-24 04:09:53 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-06-24 04:09:53 +0400 |
commit | 1c600888857544986d6576bc164e0dc8f0f4b6c7 (patch) | |
tree | f4e77c53d1050223a9170f75e4ea719f29cd04eb /libavfilter/buffersink.c | |
parent | da728d5d2e7993911c7ed92c212ab900b7be180c (diff) | |
parent | fe07c9c6b5a870b8f2ffcfac649228b4d76e9505 (diff) |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
x86: Only use optimizations with cmov if the CPU supports the instruction
x86: Add CPU flag for the i686 cmov instruction
x86: remove unused inline asm macros from dsputil_mmx.h
x86: move some inline asm macros to the only places they are used
lavfi: Add the af_channelmap audio channel mapping filter.
lavfi: add join audio filter.
lavfi: allow audio filters to request a given number of samples.
lavfi: support automatically inserting the fifo filter when needed.
lavfi/audio: eliminate ff_default_filter_samples().
Conflicts:
Changelog
libavcodec/x86/h264dsp_mmx.c
libavfilter/Makefile
libavfilter/allfilters.c
libavfilter/avfilter.h
libavfilter/avfiltergraph.c
libavfilter/version.h
libavutil/x86/cpu.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter/buffersink.c')
-rw-r--r-- | libavfilter/buffersink.c | 81 |
1 files changed, 20 insertions, 61 deletions
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index bd693baca8..642350080b 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -25,7 +25,7 @@ #include "libavutil/audio_fifo.h" #include "libavutil/audioconvert.h" -#include "libavutil/fifo.h" +#include "libavutil/avassert.h" #include "libavutil/mathematics.h" #include "audio.h" @@ -34,86 +34,45 @@ #include "internal.h" typedef struct { - AVFifoBuffer *fifo; ///< FIFO buffer of frame references - + AVFilterBufferRef *cur_buf; ///< last buffer delivered on the sink AVAudioFifo *audio_fifo; ///< FIFO for audio samples int64_t next_pts; ///< interpolating audio pts } BufferSinkContext; -#define FIFO_INIT_SIZE 8 - static av_cold void uninit(AVFilterContext *ctx) { BufferSinkContext *sink = ctx->priv; - while (sink->fifo && av_fifo_size(sink->fifo)) { - AVFilterBufferRef *buf; - av_fifo_generic_read(sink->fifo, &buf, sizeof(buf), NULL); - avfilter_unref_buffer(buf); - } - av_fifo_free(sink->fifo); - if (sink->audio_fifo) av_audio_fifo_free(sink->audio_fifo); } -static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) -{ - BufferSinkContext *sink = ctx->priv; - - if (!(sink->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef*)))) { - av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n"); - return AVERROR(ENOMEM); - } - - return 0; -} - -static void write_buf(AVFilterContext *ctx, AVFilterBufferRef *buf) +static void start_frame(AVFilterLink *link, AVFilterBufferRef *buf) { - BufferSinkContext *sink = ctx->priv; - - if (av_fifo_space(sink->fifo) < sizeof(AVFilterBufferRef *) && - (av_fifo_realloc2(sink->fifo, av_fifo_size(sink->fifo) * 2) < 0)) { - av_log(ctx, AV_LOG_ERROR, "Error reallocating the FIFO.\n"); - return; - } + BufferSinkContext *s = link->dst->priv; - av_fifo_generic_write(sink->fifo, &buf, sizeof(buf), NULL); -} - -static void end_frame(AVFilterLink *link) -{ - write_buf(link->dst, link->cur_buf); +// av_assert0(!s->cur_buf); + s->cur_buf = buf; link->cur_buf = NULL; -} - -static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) -{ - write_buf(link->dst, buf); -} +}; int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf) { - BufferSinkContext *sink = ctx->priv; + BufferSinkContext *s = ctx->priv; AVFilterLink *link = ctx->inputs[0]; int ret; - if (!buf) { - if (av_fifo_size(sink->fifo)) - return av_fifo_size(sink->fifo)/sizeof(*buf); - else - return ff_poll_frame(ctx->inputs[0]); - } + if (!buf) + return ff_poll_frame(ctx->inputs[0]); - if (!av_fifo_size(sink->fifo) && - (ret = ff_request_frame(link)) < 0) + if ((ret = ff_request_frame(link)) < 0) return ret; - if (!av_fifo_size(sink->fifo)) + if (!s->cur_buf) return AVERROR(EINVAL); - av_fifo_generic_read(sink->fifo, buf, sizeof(*buf), NULL); + *buf = s->cur_buf; + s->cur_buf = NULL; return 0; } @@ -182,13 +141,13 @@ AVFilter avfilter_vsink_buffer = { .name = "buffersink_old", .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), .priv_size = sizeof(BufferSinkContext), - .init = init, .uninit = uninit, .inputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, - .end_frame = end_frame, - .min_perms = AV_PERM_READ, }, + .start_frame = start_frame, + .min_perms = AV_PERM_READ, + .needs_fifo = 1 }, { .name = NULL }}, .outputs = (AVFilterPad[]) {{ .name = NULL }}, }; @@ -197,13 +156,13 @@ AVFilter avfilter_asink_abuffer = { .name = "abuffersink_old", .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), .priv_size = sizeof(BufferSinkContext), - .init = init, .uninit = uninit, .inputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_AUDIO, - .filter_samples = filter_samples, - .min_perms = AV_PERM_READ, }, + .filter_samples = start_frame, + .min_perms = AV_PERM_READ, + .needs_fifo = 1 }, { .name = NULL }}, .outputs = (AVFilterPad[]) {{ .name = NULL }}, }; |