Rename av_vsrc_buffer_add_frame to av_vsrc_buffer_add_video_buffer_ref(), and change its inteface to make it accept in input an AVFilterBufferRef rather than an AVFrame. This way the interface can be used without requiring the inclusion/installation of libavcodec headers.
Showing the changes to libavfilter/vsrc_buffer.c (1 of 3 files). Show all
Unified · Split
| @@ -29,8 +29,7 @@ · 28 unmodified lines | ||
| 29 | 29 | #include "libavutil/imgutils.h" |
| 30 | 30 | |
| 31 | 31 | typedef struct { |
| 32 | − AVFrame frame; | |
| 33 | − int has_frame; | |
| 32 | + AVFilterBufferRef *picref; | |
| 34 | 33 | int h, w; |
| 35 | 34 | enum PixelFormat pix_fmt; |
| 36 | 35 | AVRational time_base; ///< time_base to set in the output link |
| @@ -38,13 +37,14 @@ typedef struct { · 1 unmodified line | ||
| 38 | 37 | char sws_param[256]; |
| 39 | 38 | } BufferSourceContext; |
| 40 | 39 | |
| 41 | −int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, | |
| 42 | − const char *sws_param) | |
| 40 | +int av_vsrc_buffer_add_video_buffer_ref2(AVFilterContext *buffer_filter, AVFilterBufferRef *picref, | |
| 41 | + const char *sws_param) | |
| 43 | 42 | { |
| 44 | 43 | BufferSourceContext *c = buffer_filter->priv; |
| 44 | + AVFilterLink *outlink = buffer_filter->outputs[0]; | |
| 45 | 45 | int ret; |
| 46 | 46 | |
| 47 | − if (c->has_frame) { | |
| 47 | + if (c->picref) { | |
| 48 | 48 | av_log(buffer_filter, AV_LOG_ERROR, |
| 49 | 49 | "Buffering several frames is not supported. " |
| 50 | 50 | "Please consume all available frames before adding a new one.\n" |
| @@ -56,14 +56,14 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, · 5 unmodified lines | ||
| 56 | 56 | snprintf(c->sws_param, 255, "%d:%d:%s", c->w, c->h, sws_param); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | − if (frame->width != c->w || frame->height != c->h || frame->format != c->pix_fmt) { | |
| 59 | + if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { | |
| 60 | 60 | AVFilterContext *scale= buffer_filter->outputs[0]->dst; |
| 61 | 61 | AVFilterLink *link; |
| 62 | 62 | |
| 63 | 63 | av_log(buffer_filter, AV_LOG_INFO, |
| 64 | 64 | "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", |
| 65 | 65 | c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, |
| 66 | − frame->width, frame->height, av_pix_fmt_descriptors[frame->format].name); | |
| 66 | + picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name); | |
| 67 | 67 | |
| 68 | 68 | if(!scale || strcmp(scale->filter->name,"scale")){ |
| 69 | 69 | AVFilter *f= avfilter_get_by_name("scale"); |
| @@ -89,26 +89,28 @@ int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, · 19 unmodified lines | ||
| 89 | 89 | scale->filter->init(scale, c->sws_param, NULL); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | − c->pix_fmt = scale->inputs[0]->format = frame->format; | |
| 93 | − c->w = scale->inputs[0]->w = frame->width; | |
| 94 | − c->h = scale->inputs[0]->h = frame->height; | |
| 92 | + c->pix_fmt = scale->inputs[0]->format = picref->format; | |
| 93 | + c->w = scale->inputs[0]->w = picref->video->w; | |
| 94 | + c->h = scale->inputs[0]->h = picref->video->h; | |
| 95 | 95 | |
| 96 | 96 | link= scale->outputs[0]; |
| 97 | 97 | if ((ret = link->srcpad->config_props(link)) < 0) |
| 98 | 98 | return ret; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | − c->frame = *frame; | |
| 102 | − memcpy(c->frame.data , frame->data , sizeof(frame->data)); | |
| 103 | − memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); | |
| 104 | − c->has_frame = 1; | |
| 101 | + c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, | |
| 102 | + picref->video->w, picref->video->h); | |
| 103 | + av_image_copy(c->picref->data, c->picref->linesize, | |
| 104 | + picref->data, picref->linesize, | |
| 105 | + picref->format, picref->video->w, picref->video->h); | |
| 106 | + avfilter_copy_buffer_ref_props(c->picref, picref); | |
| 105 | 107 | |
| 106 | 108 | return 0; |
| 107 | 109 | } |
| 108 | 110 | |
| 109 | −int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame) | |
| 111 | +int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) | |
| 110 | 112 | { |
| 111 | − return av_vsrc_buffer_add_frame2(buffer_filter, frame, ""); | |
| 113 | + return av_vsrc_buffer_add_video_buffer_ref2(buffer_filter, picref, ""); | |
| 112 | 114 | } |
| 113 | 115 | |
| 114 | 116 | static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
| @@ -164,31 +166,18 @@ static int config_props(AVFilterLink *link) · 49 unmodified lines | ||
| 164 | 166 | static int request_frame(AVFilterLink *link) |
| 165 | 167 | { |
| 166 | 168 | BufferSourceContext *c = link->src->priv; |
| 167 | − AVFilterBufferRef *picref; | |
| 168 | 169 | |
| 169 | − if (!c->has_frame) { | |
| 170 | + if (!c->picref) { | |
| 170 | 171 | av_log(link->src, AV_LOG_ERROR, |
| 171 | 172 | "request_frame() called with no available frame!\n"); |
| 172 | 173 | //return -1; |
| 173 | 174 | } |
| 174 | 175 | |
| 175 | − /* This picture will be needed unmodified later for decoding the next | |
| 176 | − * frame */ | |
| 177 | − picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | | |
| 178 | − AV_PERM_REUSE2, | |
| 179 | − link->w, link->h); | |
| 180 | − | |
| 181 | − av_image_copy(picref->data, picref->linesize, | |
| 182 | − c->frame.data, c->frame.linesize, | |
| 183 | − picref->format, link->w, link->h); | |
| 184 | − avfilter_copy_frame_props(picref, &c->frame); | |
| 185 | − | |
| 186 | − avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); | |
| 176 | + avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0)); | |
| 187 | 177 | avfilter_draw_slice(link, 0, link->h, 1); |
| 188 | 178 | avfilter_end_frame(link); |
| 189 | − avfilter_unref_buffer(picref); | |
| 190 | − | |
| 191 | − c->has_frame = 0; | |
| 179 | + avfilter_unref_buffer(c->picref); | |
| 180 | + c->picref = NULL; | |
| 192 | 181 | |
| 193 | 182 | return 0; |
| 194 | 183 | } |
| @@ -196,7 +185,7 @@ static int request_frame(AVFilterLink *link) · 1 unmodified line | ||
| 196 | 185 | static int poll_frame(AVFilterLink *link) |
| 197 | 186 | { |
| 198 | 187 | BufferSourceContext *c = link->src->priv; |
| 199 | − return !!(c->has_frame); | |
| 188 | + return !!(c->picref); | |
| 200 | 189 | } |
| 201 | 190 | |
| 202 | 191 | AVFilter avfilter_vsrc_buffer = { |