vf_fieldorder: switch to filter_frame, this filter did not support real slices
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
59907340e1
commit
e67fdbffe5
@ -121,90 +121,39 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int
|
|||||||
return ff_get_video_buffer(outlink, perms, w, h);
|
return ff_get_video_buffer(outlink, perms, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
|
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
|
||||||
{
|
{
|
||||||
AVFilterContext *ctx = inlink->dst;
|
AVFilterContext *ctx = inlink->dst;
|
||||||
AVFilterLink *outlink = ctx->outputs[0];
|
FieldOrderContext *s = ctx->priv;
|
||||||
|
AVFilterLink *outlink = ctx->outputs[0];
|
||||||
|
int h, plane, line_step, line_size, line;
|
||||||
|
uint8_t *data;
|
||||||
|
|
||||||
AVFilterBufferRef *outpicref, *for_next_filter;
|
if (!frame->video->interlaced ||
|
||||||
int ret = 0;
|
frame->video->top_field_first == s->dst_tff)
|
||||||
|
return ff_filter_frame(outlink, frame);
|
||||||
|
|
||||||
outpicref = avfilter_ref_buffer(inpicref, ~0);
|
|
||||||
if (!outpicref)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
|
||||||
for_next_filter = avfilter_ref_buffer(outpicref, ~0);
|
|
||||||
if (!for_next_filter) {
|
|
||||||
avfilter_unref_bufferp(&outpicref);
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ff_start_frame(outlink, for_next_filter);
|
|
||||||
if (ret < 0) {
|
|
||||||
avfilter_unref_bufferp(&outpicref);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
outlink->out_buf = outpicref;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
|
|
||||||
{
|
|
||||||
AVFilterContext *ctx = inlink->dst;
|
|
||||||
FieldOrderContext *fieldorder = ctx->priv;
|
|
||||||
AVFilterLink *outlink = ctx->outputs[0];
|
|
||||||
|
|
||||||
AVFilterBufferRef *inpicref = inlink->cur_buf;
|
|
||||||
|
|
||||||
/** can only currently do slices if this filter is doing nothing
|
|
||||||
* because this filter is moving picture content, the output
|
|
||||||
* slice will contain different video lines than the input slice
|
|
||||||
* and that complexity will be added later */
|
|
||||||
if ( !inpicref->video->interlaced
|
|
||||||
|| inpicref->video->top_field_first == fieldorder->dst_tff) {
|
|
||||||
return ff_draw_slice(outlink, y, h, slice_dir);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int end_frame(AVFilterLink *inlink)
|
|
||||||
{
|
|
||||||
AVFilterContext *ctx = inlink->dst;
|
|
||||||
FieldOrderContext *fieldorder = ctx->priv;
|
|
||||||
AVFilterLink *outlink = ctx->outputs[0];
|
|
||||||
|
|
||||||
AVFilterBufferRef *inpicref = inlink->cur_buf;
|
|
||||||
AVFilterBufferRef *outpicref = outlink->out_buf;
|
|
||||||
|
|
||||||
int h, plane, line_step, line_size, line;
|
|
||||||
uint8_t *cpy_src, *cpy_dst;
|
|
||||||
|
|
||||||
if ( inpicref->video->interlaced
|
|
||||||
&& inpicref->video->top_field_first != fieldorder->dst_tff) {
|
|
||||||
av_dlog(ctx,
|
av_dlog(ctx,
|
||||||
"picture will move %s one line\n",
|
"picture will move %s one line\n",
|
||||||
fieldorder->dst_tff ? "up" : "down");
|
s->dst_tff ? "up" : "down");
|
||||||
h = inpicref->video->h;
|
h = frame->video->h;
|
||||||
for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) {
|
for (plane = 0; plane < 4 && frame->data[plane]; plane++) {
|
||||||
line_step = inpicref->linesize[plane];
|
line_step = frame->linesize[plane];
|
||||||
line_size = fieldorder->line_size[plane];
|
line_size = s->line_size[plane];
|
||||||
cpy_src = inpicref->data[plane];
|
data = frame->data[plane];
|
||||||
cpy_dst = outpicref->data[plane];
|
if (s->dst_tff) {
|
||||||
if (fieldorder->dst_tff) {
|
|
||||||
/** Move every line up one line, working from
|
/** Move every line up one line, working from
|
||||||
* the top to the bottom of the frame.
|
* the top to the bottom of the frame.
|
||||||
* The original top line is lost.
|
* The original top line is lost.
|
||||||
* The new last line is created as a copy of the
|
* The new last line is created as a copy of the
|
||||||
* penultimate line from that field. */
|
* penultimate line from that field. */
|
||||||
for (line = 0; line < h; line++) {
|
for (line = 0; line < h; line++) {
|
||||||
if (1 + line < outpicref->video->h) {
|
if (1 + line < frame->video->h) {
|
||||||
memcpy(cpy_dst, cpy_src + line_step, line_size);
|
memcpy(data, data + line_step, line_size);
|
||||||
} else {
|
} else {
|
||||||
memcpy(cpy_dst, cpy_src - line_step - line_step, line_size);
|
memcpy(data, data - line_step - line_step, line_size);
|
||||||
}
|
}
|
||||||
cpy_src += line_step;
|
data += line_step;
|
||||||
cpy_dst += line_step;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/** Move every line down one line, working from
|
/** Move every line down one line, working from
|
||||||
@ -212,27 +161,20 @@ static int end_frame(AVFilterLink *inlink)
|
|||||||
* The original bottom line is lost.
|
* The original bottom line is lost.
|
||||||
* The new first line is created as a copy of the
|
* The new first line is created as a copy of the
|
||||||
* second line from that field. */
|
* second line from that field. */
|
||||||
cpy_src += (h - 1) * line_step;
|
data += (h - 1) * line_step;
|
||||||
cpy_dst += (h - 1) * line_step;
|
|
||||||
for (line = h - 1; line >= 0 ; line--) {
|
for (line = h - 1; line >= 0 ; line--) {
|
||||||
if (line > 0) {
|
if (line > 0) {
|
||||||
memcpy(cpy_dst, cpy_src - line_step, line_size);
|
memcpy(data, data - line_step, line_size);
|
||||||
} else {
|
} else {
|
||||||
memcpy(cpy_dst, cpy_src + line_step + line_step, line_size);
|
memcpy(data, data + line_step + line_step, line_size);
|
||||||
}
|
}
|
||||||
cpy_src -= line_step;
|
data -= line_step;
|
||||||
cpy_dst -= line_step;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outpicref->video->top_field_first = fieldorder->dst_tff;
|
frame->video->top_field_first = s->dst_tff;
|
||||||
ff_draw_slice(outlink, 0, h, 1);
|
|
||||||
} else {
|
|
||||||
av_dlog(ctx,
|
|
||||||
"not interlaced or field order already correct\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ff_end_frame(outlink);
|
return ff_filter_frame(outlink, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AVFilterPad avfilter_vf_fieldorder_inputs[] = {
|
static const AVFilterPad avfilter_vf_fieldorder_inputs[] = {
|
||||||
@ -240,11 +182,9 @@ static const AVFilterPad avfilter_vf_fieldorder_inputs[] = {
|
|||||||
.name = "default",
|
.name = "default",
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
.config_props = config_input,
|
.config_props = config_input,
|
||||||
.start_frame = start_frame,
|
|
||||||
.get_video_buffer = get_video_buffer,
|
.get_video_buffer = get_video_buffer,
|
||||||
.draw_slice = draw_slice,
|
.filter_frame = filter_frame,
|
||||||
.end_frame = end_frame,
|
.min_perms = AV_PERM_READ | AV_PERM_WRITE,
|
||||||
.min_perms = AV_PERM_READ | AV_PERM_PRESERVE,
|
|
||||||
},
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user