* memory buffer source filter
*/
+#include "libavutil/channel_layout.h"
+#include "libavutil/common.h"
+#include "libavutil/fifo.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/samplefmt.h"
#include "audio.h"
#include "avfilter.h"
#include "buffersrc.h"
#include "internal.h"
#include "video.h"
-#include "libavutil/audioconvert.h"
-#include "libavutil/fifo.h"
-#include "libavutil/imgutils.h"
-#include "libavutil/opt.h"
-#include "libavutil/samplefmt.h"
-
typedef struct {
const AVClass *class;
AVFifoBuffer *fifo;
/* video only */
int h, w;
- enum PixelFormat pix_fmt;
+ enum AVPixelFormat pix_fmt;
AVRational pixel_aspect;
/* audio only */
return AVERROR(EINVAL);\
}
-int av_buffersrc_write_frame(AVFilterContext *buffer_filter, AVFrame *frame)
+int av_buffersrc_write_frame(AVFilterContext *buffer_filter, const AVFrame *frame)
{
BufferSourceContext *c = buffer_filter->priv;
AVFilterBufferRef *buf;
frame->format);
buf = ff_get_audio_buffer(buffer_filter->outputs[0], AV_PERM_WRITE,
frame->nb_samples);
+ if (!buf)
+ return AVERROR(ENOMEM);
+
av_samples_copy(buf->extended_data, frame->extended_data,
0, 0, frame->nb_samples,
av_get_channel_layout_nb_channels(frame->channel_layout),
av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but %d found in '%s'\n", n, args);
return AVERROR(EINVAL);
}
- if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) {
+ if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == AV_PIX_FMT_NONE) {
char *tail;
c->pix_fmt = strtol(pix_fmt_str, &tail, 10);
- if (*tail || c->pix_fmt < 0 || c->pix_fmt >= PIX_FMT_NB) {
+ if (*tail || c->pix_fmt < 0 || c->pix_fmt >= AV_PIX_FMT_NB) {
av_log(ctx, AV_LOG_ERROR, "Invalid pixel format string '%s'\n", pix_fmt_str);
return AVERROR(EINVAL);
}
if (!(c->fifo = av_fifo_alloc(sizeof(AVFilterBufferRef*))))
return AVERROR(ENOMEM);
- av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name);
+ av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s\n", c->w, c->h, av_get_pix_fmt_name(c->pix_fmt));
return 0;
}
#define OFFSET(x) offsetof(BufferSourceContext, x)
#define A AV_OPT_FLAG_AUDIO_PARAM
static const AVOption audio_options[] = {
- { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { 0 }, 0, INT_MAX, A },
- { "sample_rate", NULL, OFFSET(sample_rate), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, A },
+ { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, A },
+ { "sample_rate", NULL, OFFSET(sample_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, A },
{ "sample_fmt", NULL, OFFSET(sample_fmt_str), AV_OPT_TYPE_STRING, .flags = A },
{ "channel_layout", NULL, OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, .flags = A },
{ NULL },
}
av_fifo_generic_read(c->fifo, &buf, sizeof(buf), NULL);
- switch (link->type) {
- case AVMEDIA_TYPE_VIDEO:
- if ((ret = ff_start_frame(link, buf)) < 0 ||
- (ret = ff_draw_slice(link, 0, link->h, 1)) < 0 ||
- (ret = ff_end_frame(link)) < 0)
- return ret;
- break;
- case AVMEDIA_TYPE_AUDIO:
- ret = ff_filter_samples(link, buf);
- break;
- default:
- avfilter_unref_bufferp(&buf);
- return AVERROR(EINVAL);
- }
+ ff_filter_frame(link, buf);
return ret;
}
return size/sizeof(AVFilterBufferRef*);
}
+static const AVFilterPad avfilter_vsrc_buffer_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .request_frame = request_frame,
+ .poll_frame = poll_frame,
+ .config_props = config_props,
+ },
+ { NULL }
+};
+
AVFilter avfilter_vsrc_buffer = {
.name = "buffer",
.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them accessible to the filterchain."),
.init = init_video,
.uninit = uninit,
- .inputs = (const AVFilterPad[]) {{ .name = NULL }},
- .outputs = (const AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .request_frame = request_frame,
- .poll_frame = poll_frame,
- .config_props = config_props, },
- { .name = NULL}},
+ .inputs = NULL,
+ .outputs = avfilter_vsrc_buffer_outputs,
+};
+
+static const AVFilterPad avfilter_asrc_abuffer_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .request_frame = request_frame,
+ .poll_frame = poll_frame,
+ .config_props = config_props,
+ },
+ { NULL }
};
AVFilter avfilter_asrc_abuffer = {
.init = init_audio,
.uninit = uninit,
- .inputs = (const AVFilterPad[]) {{ .name = NULL }},
- .outputs = (const AVFilterPad[]) {{ .name = "default",
- .type = AVMEDIA_TYPE_AUDIO,
- .request_frame = request_frame,
- .poll_frame = poll_frame,
- .config_props = config_props, },
- { .name = NULL}},
+ .inputs = NULL,
+ .outputs = avfilter_asrc_abuffer_outputs,
};