26
26
#include "avfilter.h"
27
#include "buffersrc.h"
27
28
#include "vsrc_buffer.h"
28
29
#include "libavutil/imgutils.h"
32
AVFilterBufferRef *buf;
35
34
enum PixelFormat pix_fmt;
36
35
AVRational time_base; ///< time_base to set in the output link
37
36
AVRational pixel_aspect;
38
37
} BufferSourceContext;
39
#define CHECK_PARAM_CHANGE(s, c, width, height, format)\
40
if (c->w != width || c->h != height || c->pix_fmt != format) {\
41
av_log(s, AV_LOG_ERROR, "Changing frame properties on the fly is not supported.\n");\
42
return AVERROR(EINVAL);\
40
45
int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
41
46
int64_t pts, AVRational pixel_aspect)
43
48
BufferSourceContext *c = buffer_filter->priv;
46
51
av_log(buffer_filter, AV_LOG_ERROR,
47
52
"Buffering several frames is not supported. "
48
53
"Please consume all available frames before adding a new one.\n"
53
memcpy(c->frame.data , frame->data , sizeof(frame->data));
54
memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
55
c->frame.interlaced_frame= frame->interlaced_frame;
56
c->frame.top_field_first = frame->top_field_first;
57
c->frame.key_frame = frame->key_frame;
58
c->frame.pict_type = frame->pict_type;
60
c->pixel_aspect = pixel_aspect;
58
CHECK_PARAM_CHANGE(buffer_filter, c, frame->width, frame->height, frame->format);
60
c->buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE,
62
av_image_copy(c->buf->data, c->buf->linesize, frame->data, frame->linesize,
63
c->pix_fmt, c->w, c->h);
65
avfilter_copy_frame_props(c->buf, frame);
67
c->buf->video->pixel_aspect = pixel_aspect;
72
int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
74
BufferSourceContext *c = s->priv;
77
av_log(s, AV_LOG_ERROR,
78
"Buffering several frames is not supported. "
79
"Please consume all available frames before adding a new one.\n"
81
return AVERROR(EINVAL);
84
CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format);
113
138
static int request_frame(AVFilterLink *link)
115
140
BufferSourceContext *c = link->src->priv;
116
AVFilterBufferRef *picref;
119
143
av_log(link->src, AV_LOG_ERROR,
120
144
"request_frame() called with no available frame!\n");
124
/* This picture will be needed unmodified later for decoding the next
126
picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
130
av_image_copy(picref->data, picref->linesize,
131
c->frame.data, c->frame.linesize,
132
picref->format, link->w, link->h);
134
picref->pts = c->pts;
135
picref->video->pixel_aspect = c->pixel_aspect;
136
picref->video->interlaced = c->frame.interlaced_frame;
137
picref->video->top_field_first = c->frame.top_field_first;
138
picref->video->key_frame = c->frame.key_frame;
139
picref->video->pict_type = c->frame.pict_type;
140
avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
148
avfilter_start_frame(link, avfilter_ref_buffer(c->buf, ~0));
141
149
avfilter_draw_slice(link, 0, link->h, 1);
142
150
avfilter_end_frame(link);
143
avfilter_unref_buffer(picref);
151
avfilter_unref_buffer(c->buf);