mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
vf_pad: switch to filter_frame
Based on patch by Anton Khirnov Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
a0958949eb
commit
6be0df5080
@ -88,7 +88,6 @@ typedef struct {
|
|||||||
uint8_t rgba_color[4]; ///< color for the padding area
|
uint8_t rgba_color[4]; ///< color for the padding area
|
||||||
FFDrawContext draw;
|
FFDrawContext draw;
|
||||||
FFDrawColor color;
|
FFDrawColor color;
|
||||||
int needs_copy;
|
|
||||||
} PadContext;
|
} PadContext;
|
||||||
|
|
||||||
static av_cold int init(AVFilterContext *ctx, const char *args)
|
static av_cold int init(AVFilterContext *ctx, const char *args)
|
||||||
@ -263,129 +262,84 @@ static int does_clip(PadContext *pad, AVFilterBufferRef *outpicref, int plane, i
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
|
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
|
||||||
{
|
{
|
||||||
PadContext *pad = inlink->dst->priv;
|
PadContext *pad = inlink->dst->priv;
|
||||||
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
|
AVFilterBufferRef *out = avfilter_ref_buffer(in, ~0);
|
||||||
AVFilterBufferRef *for_next_filter;
|
int plane, needs_copy;
|
||||||
int plane, ret = 0;
|
|
||||||
|
|
||||||
if (!outpicref)
|
if (!out) {
|
||||||
|
avfilter_unref_bufferp(&in);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
for (plane = 0; plane < 4 && outpicref->data[plane] && pad->draw.pixelstep[plane]; plane++) {
|
for (plane = 0; plane < 4 && out->data[plane] && pad->draw.pixelstep[plane]; plane++) {
|
||||||
int hsub = pad->draw.hsub[plane];
|
int hsub = pad->draw.hsub[plane];
|
||||||
int vsub = pad->draw.vsub[plane];
|
int vsub = pad->draw.vsub[plane];
|
||||||
|
|
||||||
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;
|
break;
|
||||||
|
|
||||||
outpicref->data[plane] -= (pad->x >> hsub) * pad->draw.pixelstep[plane]
|
out->data[plane] -= (pad->x >> hsub) * pad->draw.pixelstep[plane] +
|
||||||
+ (pad->y >> vsub) * outpicref->linesize[plane];
|
(pad->y >> vsub) * out->linesize[plane];
|
||||||
|
|
||||||
if( does_clip(pad, outpicref, plane, hsub, vsub, 0, 0)
|
if (does_clip(pad, out, plane, hsub, vsub, 0, 0) ||
|
||||||
|| does_clip(pad, outpicref, plane, hsub, vsub, 0, pad->h-1)
|
does_clip(pad, out, plane, hsub, vsub, 0, pad->h - 1) ||
|
||||||
|| does_clip(pad, outpicref, plane, hsub, vsub, pad->w-1, 0)
|
does_clip(pad, out, plane, hsub, vsub, pad->w - 1, 0) ||
|
||||||
|| does_clip(pad, outpicref, plane, hsub, vsub, pad->w-1, pad->h-1)
|
does_clip(pad, out, plane, hsub, vsub, pad->w - 1, pad->h - 1))
|
||||||
)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pad->needs_copy= plane < 4 && outpicref->data[plane] || !(outpicref->perms & AV_PERM_WRITE);
|
needs_copy = plane < 4 && out->data[plane] || !(out->perms & AV_PERM_WRITE);
|
||||||
if(pad->needs_copy){
|
if (needs_copy) {
|
||||||
av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
|
av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
|
||||||
avfilter_unref_buffer(outpicref);
|
avfilter_unref_buffer(out);
|
||||||
outpicref = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES,
|
out = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES,
|
||||||
FFMAX(inlink->w, pad->w),
|
FFMAX(inlink->w, pad->w),
|
||||||
FFMAX(inlink->h, pad->h));
|
FFMAX(inlink->h, pad->h));
|
||||||
if (!outpicref)
|
if (!out) {
|
||||||
|
avfilter_unref_bufferp(&in);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
avfilter_copy_buffer_ref_props(outpicref, inpicref);
|
avfilter_copy_buffer_ref_props(out, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
outpicref->video->w = pad->w;
|
out->video->w = pad->w;
|
||||||
outpicref->video->h = pad->h;
|
out->video->h = pad->h;
|
||||||
|
|
||||||
for_next_filter = avfilter_ref_buffer(outpicref, ~0);
|
/* top bar */
|
||||||
if (!for_next_filter) {
|
if (pad->y) {
|
||||||
ret = AVERROR(ENOMEM);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bar_h) {
|
|
||||||
ff_fill_rectangle(&pad->draw, &pad->color,
|
ff_fill_rectangle(&pad->draw, &pad->color,
|
||||||
link->dst->outputs[0]->out_buf->data,
|
out->data, out->linesize,
|
||||||
link->dst->outputs[0]->out_buf->linesize,
|
0, 0, pad->w, pad->y);
|
||||||
0, bar_y, pad->w, bar_h);
|
|
||||||
ret = ff_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir);
|
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
|
/* bottom bar */
|
||||||
{
|
if (pad->h > pad->y + pad->in_h) {
|
||||||
PadContext *pad = link->dst->priv;
|
ff_fill_rectangle(&pad->draw, &pad->color,
|
||||||
AVFilterBufferRef *outpic = link->dst->outputs[0]->out_buf;
|
out->data, out->linesize,
|
||||||
AVFilterBufferRef *inpic = link->cur_buf;
|
0, pad->y + pad->in_h, pad->w, pad->h - pad->y - pad->in_h);
|
||||||
int ret;
|
}
|
||||||
|
|
||||||
y += pad->y;
|
|
||||||
|
|
||||||
y = ff_draw_round_to_sub(&pad->draw, 1, -1, y);
|
|
||||||
h = ff_draw_round_to_sub(&pad->draw, 1, -1, h);
|
|
||||||
|
|
||||||
if (!h)
|
|
||||||
return 0;
|
|
||||||
draw_send_bar_slice(link, y, h, slice_dir, 1);
|
|
||||||
|
|
||||||
/* left border */
|
/* left border */
|
||||||
ff_fill_rectangle(&pad->draw, &pad->color, outpic->data, outpic->linesize,
|
ff_fill_rectangle(&pad->draw, &pad->color, out->data, out->linesize,
|
||||||
0, y, pad->x, h);
|
0, pad->y, pad->x, in->video->h);
|
||||||
|
|
||||||
if(pad->needs_copy){
|
if (needs_copy) {
|
||||||
ff_copy_rectangle2(&pad->draw,
|
ff_copy_rectangle2(&pad->draw,
|
||||||
outpic->data, outpic->linesize,
|
out->data, out->linesize, in->data, in->linesize,
|
||||||
inpic ->data, inpic ->linesize,
|
pad->x, pad->y, 0, 0, in->video->w, in->video->h);
|
||||||
pad->x, y, 0, y - pad->y, inpic->video->w, h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* right border */
|
/* right border */
|
||||||
ff_fill_rectangle(&pad->draw, &pad->color, outpic->data, outpic->linesize,
|
ff_fill_rectangle(&pad->draw, &pad->color, out->data, out->linesize,
|
||||||
pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h);
|
pad->x + pad->in_w, pad->y, pad->w - pad->x - pad->in_w,
|
||||||
ret = ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
|
in->video->h);
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
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[] = {
|
static const AVFilterPad avfilter_vf_pad_inputs[] = {
|
||||||
@ -394,8 +348,7 @@ static const AVFilterPad avfilter_vf_pad_inputs[] = {
|
|||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
.config_props = config_input,
|
.config_props = config_input,
|
||||||
.get_video_buffer = get_video_buffer,
|
.get_video_buffer = get_video_buffer,
|
||||||
.start_frame = start_frame,
|
.filter_frame = filter_frame,
|
||||||
.draw_slice = draw_slice,
|
|
||||||
},
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user