History

lavfi/fifo: add audio version of the fifo filter.

Anton Khirnov committed 14 years ago

Commit 4a97ff21 parent 27570e23 files · +53 −20Browse files

Unified · Split

3 files
  1. libavfilter/Makefile +1 −0
  2. libavfilter/allfilters.c +1 −0
  3. libavfilter/fifo.c +51 −20
libavfilter/Makefile+1−0
@@ -25,6 +25,7 @@ OBJS = allfilters.o \ · 24 unmodified lines
25 vf_scale.o \25 vf_scale.o \
26 video.o \26 video.o \
27 27
28OBJS-$(CONFIG_AFIFO_FILTER) += fifo.o
28OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o29OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o
29OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o30OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o
30OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o31OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
libavfilter/allfilters.c+1−0
@@ -34,6 +34,7 @@ void avfilter_register_all(void) · 33 unmodified lines
34 return;34 return;
35 initialized = 1;35 initialized = 1;
36 36
37 REGISTER_FILTER (AFIFO, afifo, af);
37 REGISTER_FILTER (AFORMAT, aformat, af);38 REGISTER_FILTER (AFORMAT, aformat, af);
38 REGISTER_FILTER (AMIX, amix, af);39 REGISTER_FILTER (AMIX, amix, af);
39 REGISTER_FILTER (ANULL, anull, af);40 REGISTER_FILTER (ANULL, anull, af);
libavfilter/fifo.c+51−20
@@ -20,21 +20,22 @@ · 19 unmodified lines
20 20
21/**21/**
22 * @file22 * @file
23 * FIFO buffering video filter23 * FIFO buffering filter
24 */24 */
25 25
26#include "audio.h"
26#include "avfilter.h"27#include "avfilter.h"
27#include "internal.h"28#include "internal.h"
28#include "video.h"29#include "video.h"
29 30
30typedef struct BufPic {31typedef struct Buf {
31 AVFilterBufferRef *picref;32 AVFilterBufferRef *buf;
32 struct BufPic *next;33 struct Buf *next;
33} BufPic;34} Buf;
34 35
35typedef struct {36typedef struct {
36 BufPic root;37 Buf root;
37 BufPic *last; ///< last buffered picture38 Buf *last; ///< last buffered frame
38} FifoContext;39} FifoContext;
39 40
40static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)41static 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) · 8 unmodified lines
49static av_cold void uninit(AVFilterContext *ctx)50static av_cold void uninit(AVFilterContext *ctx)
50{51{
51 FifoContext *fifo = ctx->priv;52 FifoContext *fifo = ctx->priv;
52 BufPic *pic, *tmp;53 Buf *buf, *tmp;
53 54
54 for (pic = fifo->root.next; pic; pic = tmp) {55 for (buf = fifo->root.next; buf; buf = tmp) {
55 tmp = pic->next;56 tmp = buf->next;
56 avfilter_unref_buffer(pic->picref);57 avfilter_unref_buffer(buf->buf);
57 av_free(pic);58 av_free(buf);
58 }59 }
59}60}
60 61
61static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)62static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
62{63{
63 FifoContext *fifo = inlink->dst->priv;64 FifoContext *fifo = inlink->dst->priv;
64 65
65 fifo->last->next = av_mallocz(sizeof(BufPic));66 fifo->last->next = av_mallocz(sizeof(Buf));
66 fifo->last = fifo->last->next;67 fifo->last = fifo->last->next;
67 fifo->last->picref = picref;68 fifo->last->buf = buf;
68}69}
69 70
70static void end_frame(AVFilterLink *inlink) { }71static void end_frame(AVFilterLink *inlink) { }
@@ -74,7 +75,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } · 3 unmodified lines
74static int request_frame(AVFilterLink *outlink)75static int request_frame(AVFilterLink *outlink)
75{76{
76 FifoContext *fifo = outlink->src->priv;77 FifoContext *fifo = outlink->src->priv;
77 BufPic *tmp;78 Buf *tmp;
78 int ret;79 int ret;
79 80
80 if (!fifo->root.next) {81 if (!fifo->root.next) {
@@ -84,9 +85,18 @@ static int request_frame(AVFilterLink *outlink) · 3 unmodified lines
84 85
85 /* by doing this, we give ownership of the reference to the next filter,86 /* by doing this, we give ownership of the reference to the next filter,
86 * so we don't have to worry about dereferencing it ourselves. */87 * so we don't have to worry about dereferencing it ourselves. */
87 ff_start_frame(outlink, fifo->root.next->picref);88 switch (outlink->type) {
88 ff_draw_slice (outlink, 0, outlink->h, 1);89 case AVMEDIA_TYPE_VIDEO:
89 ff_end_frame (outlink);90 ff_start_frame(outlink, fifo->root.next->buf);
91 ff_draw_slice (outlink, 0, outlink->h, 1);
92 ff_end_frame (outlink);
93 break;
94 case AVMEDIA_TYPE_AUDIO:
95 ff_filter_samples(outlink, fifo->root.next->buf);
96 break;
97 default:
98 return AVERROR(EINVAL);
99 }
90 100
91 if (fifo->last == fifo->root.next)101 if (fifo->last == fifo->root.next)
92 fifo->last = &fifo->root;102 fifo->last = &fifo->root;
@@ -109,7 +119,7 @@ AVFilter avfilter_vf_fifo = { · 16 unmodified lines
109 .inputs = (AVFilterPad[]) {{ .name = "default",119 .inputs = (AVFilterPad[]) {{ .name = "default",
110 .type = AVMEDIA_TYPE_VIDEO,120 .type = AVMEDIA_TYPE_VIDEO,
111 .get_video_buffer= ff_null_get_video_buffer,121 .get_video_buffer= ff_null_get_video_buffer,
112 .start_frame = start_frame,122 .start_frame = add_to_queue,
113 .draw_slice = draw_slice,123 .draw_slice = draw_slice,
114 .end_frame = end_frame,124 .end_frame = end_frame,
115 .rej_perms = AV_PERM_REUSE2, },125 .rej_perms = AV_PERM_REUSE2, },
@@ -119,3 +129,24 @@ AVFilter avfilter_vf_fifo = { · 3 unmodified lines
119 .request_frame = request_frame, },129 .request_frame = request_frame, },
120 { .name = NULL}},130 { .name = NULL}},
121};131};
132
133AVFilter avfilter_af_afifo = {
134 .name = "afifo",
135 .description = NULL_IF_CONFIG_SMALL("Buffer input frames and send them when they are requested."),
136
137 .init = init,
138 .uninit = uninit,
139
140 .priv_size = sizeof(FifoContext),
141
142 .inputs = (AVFilterPad[]) {{ .name = "default",
143 .type = AVMEDIA_TYPE_AUDIO,
144 .get_audio_buffer = ff_null_get_audio_buffer,
145 .filter_samples = add_to_queue,
146 .rej_perms = AV_PERM_REUSE2, },
147 { .name = NULL}},
148 .outputs = (AVFilterPad[]) {{ .name = "default",
149 .type = AVMEDIA_TYPE_AUDIO,
150 .request_frame = request_frame, },
151 { .name = NULL}},
152};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t