diff options
author | Anton Khirnov <anton@khirnov.net> | 2012-11-27 07:49:45 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2012-11-28 08:50:19 +0100 |
commit | 565e4993c63f797e2d50ad2f1e8f62fdbe299666 (patch) | |
tree | bae5282b2ee875de4b01467f3cfaab54b0ab6ec0 /libavfilter/vf_pad.c | |
parent | bb6c67bb36b136de10256f0999128df4a42f9ffc (diff) | |
download | ffmpeg-565e4993c63f797e2d50ad2f1e8f62fdbe299666.tar.gz |
lavfi: merge start_frame/draw_slice/end_frame
Any alleged performance benefits gained from the split are purely
mythological and do not justify added code complexity.
Diffstat (limited to 'libavfilter/vf_pad.c')
-rw-r--r-- | libavfilter/vf_pad.c | 151 |
1 files changed, 49 insertions, 102 deletions
diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index c14835d68c..f1a890eb1d 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -106,7 +106,6 @@ typedef struct { uint8_t *line[4]; int line_step[4]; int hsub, vsub; ///< chroma subsampling values - int needs_copy; } PadContext; static av_cold int init(AVFilterContext *ctx, const char *args) @@ -303,135 +302,85 @@ static int does_clip(PadContext *pad, AVFilterBufferRef *outpicref, int plane, i return 0; } -static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) +static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in) { PadContext *pad = inlink->dst->priv; - AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0); - AVFilterBufferRef *for_next_filter; - int plane, ret = 0; + AVFilterBufferRef *out = avfilter_ref_buffer(in, ~0); + int plane, needs_copy; - if (!outpicref) + if (!out) { + avfilter_unref_bufferp(&in); return AVERROR(ENOMEM); + } - for (plane = 0; plane < 4 && outpicref->data[plane]; plane++) { + for (plane = 0; plane < 4 && out->data[plane]; plane++) { int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0; int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0; - av_assert0(outpicref->buf->w>0 && outpicref->buf->h>0); + av_assert0(out->buf->w > 0 && out->buf->h > 0); - if(outpicref->format != outpicref->buf->format) //unsupported currently + if (out->format != out->buf->format) //unsupported currently break; - outpicref->data[plane] -= (pad->x >> hsub) * pad ->line_step[plane] - + (pad->y >> vsub) * outpicref->linesize [plane]; + out->data[plane] -= (pad->x >> hsub) * pad->line_step[plane] + + (pad->y >> vsub) * out->linesize [plane]; - if( does_clip(pad, outpicref, plane, hsub, vsub, 0, 0) - || does_clip(pad, outpicref, plane, hsub, vsub, 0, pad->h-1) - || does_clip(pad, outpicref, plane, hsub, vsub, pad->w-1, 0) - || does_clip(pad, outpicref, plane, hsub, vsub, pad->w-1, pad->h-1) - ) + if (does_clip(pad, out, plane, hsub, vsub, 0, 0) || + does_clip(pad, out, plane, hsub, vsub, 0, pad->h - 1) || + does_clip(pad, out, plane, hsub, vsub, pad->w - 1, 0) || + does_clip(pad, out, plane, hsub, vsub, pad->w - 1, pad->h - 1)) break; } - pad->needs_copy= plane < 4 && outpicref->data[plane]; - if(pad->needs_copy){ + needs_copy = plane < 4 && out->data[plane]; + if (needs_copy) { av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n"); - avfilter_unref_buffer(outpicref); - outpicref = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES, - FFMAX(inlink->w, pad->w), - FFMAX(inlink->h, pad->h)); - if (!outpicref) + avfilter_unref_buffer(out); + out = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES, + FFMAX(inlink->w, pad->w), + FFMAX(inlink->h, pad->h)); + if (!out) { + avfilter_unref_bufferp(&in); return AVERROR(ENOMEM); + } - avfilter_copy_buffer_ref_props(outpicref, inpicref); - } - - outpicref->video->w = pad->w; - outpicref->video->h = pad->h; - - for_next_filter = avfilter_ref_buffer(outpicref, ~0); - if (!for_next_filter) { - ret = AVERROR(ENOMEM); - goto fail; + avfilter_copy_buffer_ref_props(out, in); } - ret = ff_start_frame(inlink->dst->outputs[0], for_next_filter); - if (ret < 0) - goto fail; - - inlink->dst->outputs[0]->out_buf = outpicref; - return 0; - -fail: - avfilter_unref_bufferp(&outpicref); - return ret; -} - -static int end_frame(AVFilterLink *link) -{ - return ff_end_frame(link->dst->outputs[0]); -} + out->video->w = pad->w; + out->video->h = pad->h; -static int draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice) -{ - PadContext *pad = link->dst->priv; - int bar_y, bar_h = 0, ret = 0; - - if (slice_dir * before_slice == 1 && y == pad->y) { - /* top bar */ - bar_y = 0; - bar_h = pad->y; - } else if (slice_dir * before_slice == -1 && (y + h) == (pad->y + pad->in_h)) { - /* bottom bar */ - bar_y = pad->y + pad->in_h; - bar_h = pad->h - pad->in_h - pad->y; + /* top bar */ + if (pad->y) { + ff_draw_rectangle(out->data, out->linesize, + pad->line, pad->line_step, pad->hsub, pad->vsub, + 0, 0, pad->w, pad->y); } - if (bar_h) { - ff_draw_rectangle(link->dst->outputs[0]->out_buf->data, - link->dst->outputs[0]->out_buf->linesize, + /* bottom bar */ + if (pad->h > pad->y + pad->in_h) { + ff_draw_rectangle(out->data, out->linesize, pad->line, pad->line_step, pad->hsub, pad->vsub, - 0, bar_y, pad->w, bar_h); - ret = ff_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir); + 0, pad->y + pad->in_h, pad->w, pad->h - pad->y - pad->in_h); } - return ret; -} - -static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir) -{ - PadContext *pad = link->dst->priv; - AVFilterBufferRef *outpic = link->dst->outputs[0]->out_buf; - AVFilterBufferRef *inpic = link->cur_buf; - int ret; - - y += pad->y; - - y &= ~((1 << pad->vsub) - 1); - h &= ~((1 << pad->vsub) - 1); - - if (!h) - return 0; - draw_send_bar_slice(link, y, h, slice_dir, 1); /* left border */ - ff_draw_rectangle(outpic->data, outpic->linesize, pad->line, pad->line_step, - pad->hsub, pad->vsub, 0, y, pad->x, h); - - if(pad->needs_copy){ - ff_copy_rectangle(outpic->data, outpic->linesize, - inpic->data, inpic->linesize, pad->line_step, - pad->hsub, pad->vsub, - pad->x, y, y-pad->y, inpic->video->w, h); + ff_draw_rectangle(out->data, out->linesize, pad->line, pad->line_step, + pad->hsub, pad->vsub, 0, pad->y, pad->x, in->video->h); + + if (needs_copy) { + ff_copy_rectangle(out->data, out->linesize, in->data, in->linesize, + pad->line_step, pad->hsub, pad->vsub, + pad->x, pad->y, 0, in->video->w, in->video->h); } /* right border */ - ff_draw_rectangle(outpic->data, outpic->linesize, + ff_draw_rectangle(out->data, out->linesize, pad->line, pad->line_step, pad->hsub, pad->vsub, - pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h); - ret = ff_draw_slice(link->dst->outputs[0], y, h, slice_dir); - if (ret < 0) - return ret; + pad->x + pad->in_w, pad->y, pad->w - pad->x - pad->in_w, + in->video->h); - return draw_send_bar_slice(link, y, h, slice_dir, -1); + avfilter_unref_bufferp(&in); + return ff_filter_frame(inlink->dst->outputs[0], out); } static const AVFilterPad avfilter_vf_pad_inputs[] = { @@ -440,9 +389,7 @@ static const AVFilterPad avfilter_vf_pad_inputs[] = { .type = AVMEDIA_TYPE_VIDEO, .config_props = config_input, .get_video_buffer = get_video_buffer, - .start_frame = start_frame, - .draw_slice = draw_slice, - .end_frame = end_frame, + .filter_frame = filter_frame, }, { NULL } }; |