X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/2f84bb4236accadffdfad30a5ec0d80e72449f15..d4f89906e3b310609b636cf6071313ec557ec873:/libavfilter/vf_fieldorder.c diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index 59ca778..4ea7fe1 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2011 Mark Himsley * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -28,6 +28,9 @@ #include "libavutil/imgutils.h" #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "video.h" typedef struct { @@ -35,7 +38,7 @@ typedef struct int line_size[4]; ///< bytes of pixel data per line for each plane } FieldOrderContext; -static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +static av_cold int init(AVFilterContext *ctx, const char *args) { FieldOrderContext *fieldorder = ctx->priv; @@ -55,7 +58,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) return AVERROR(EINVAL); } - av_log(ctx, AV_LOG_INFO, "output field order: %s\n", + av_log(ctx, AV_LOG_VERBOSE, "output field order: %s\n", fieldorder->dst_tff ? tff : bff); return 0; @@ -76,12 +79,12 @@ static int query_formats(AVFilterContext *ctx) || av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BITSTREAM) && av_pix_fmt_descriptors[pix_fmt].nb_components && !av_pix_fmt_descriptors[pix_fmt].log2_chroma_h - && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { - avfilter_formats_unref(&formats); + && (ret = ff_add_format(&formats, pix_fmt)) < 0) { + ff_formats_unref(&formats); return ret; } - avfilter_formats_ref(formats, &ctx->inputs[0]->out_formats); - avfilter_formats_ref(formats, &ctx->outputs[0]->in_formats); + ff_formats_ref(formats, &ctx->inputs[0]->out_formats); + ff_formats_ref(formats, &ctx->outputs[0]->in_formats); } return 0; @@ -110,23 +113,38 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; - return avfilter_get_video_buffer(outlink, perms, w, h); + return ff_get_video_buffer(outlink, perms, w, h); } -static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) +static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; - AVFilterBufferRef *outpicref; + AVFilterBufferRef *outpicref, *for_next_filter; + int ret = 0; outpicref = avfilter_ref_buffer(inpicref, ~0); - outlink->out_buf = outpicref; + 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; + } - avfilter_start_frame(outlink, outpicref); + outlink->out_buf = outpicref; + return 0; } -static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { AVFilterContext *ctx = inlink->dst; FieldOrderContext *fieldorder = ctx->priv; @@ -140,11 +158,12 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) * and that complexity will be added later */ if ( !inpicref->video->interlaced || inpicref->video->top_field_first == fieldorder->dst_tff) { - avfilter_draw_slice(outlink, y, h, slice_dir); + return ff_draw_slice(outlink, y, h, slice_dir); } + return 0; } -static void end_frame(AVFilterLink *inlink) +static int end_frame(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; FieldOrderContext *fieldorder = ctx->priv; @@ -153,7 +172,7 @@ static void end_frame(AVFilterLink *inlink) AVFilterBufferRef *inpicref = inlink->cur_buf; AVFilterBufferRef *outpicref = outlink->out_buf; - int h, w, plane, line_step, line_size, line; + int h, plane, line_step, line_size, line; uint8_t *cpy_src, *cpy_dst; if ( inpicref->video->interlaced @@ -162,7 +181,6 @@ static void end_frame(AVFilterLink *inlink) "picture will move %s one line\n", fieldorder->dst_tff ? "up" : "down"); h = inpicref->video->h; - w = inpicref->video->w; for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) { line_step = inpicref->linesize[plane]; line_size = fieldorder->line_size[plane]; @@ -203,14 +221,13 @@ static void end_frame(AVFilterLink *inlink) } } outpicref->video->top_field_first = fieldorder->dst_tff; - avfilter_draw_slice(outlink, 0, h, 1); + ff_draw_slice(outlink, 0, h, 1); } else { av_dlog(ctx, "not interlaced or field order already correct\n"); } - avfilter_end_frame(outlink); - avfilter_unref_buffer(inpicref); + return ff_end_frame(outlink); } AVFilter avfilter_vf_fieldorder = { @@ -219,17 +236,17 @@ AVFilter avfilter_vf_fieldorder = { .init = init, .priv_size = sizeof(FieldOrderContext), .query_formats = query_formats, - .inputs = (AVFilterPad[]) {{ .name = "default", - .type = AVMEDIA_TYPE_VIDEO, - .config_props = config_input, - .start_frame = start_frame, - .get_video_buffer = get_video_buffer, - .draw_slice = draw_slice, - .end_frame = end_frame, - .min_perms = AV_PERM_READ, - .rej_perms = AV_PERM_REUSE2|AV_PERM_PRESERVE,}, - { .name = NULL}}, - .outputs = (AVFilterPad[]) {{ .name = "default", - .type = AVMEDIA_TYPE_VIDEO, }, - { .name = NULL}}, + .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .start_frame = start_frame, + .get_video_buffer = get_video_buffer, + .draw_slice = draw_slice, + .end_frame = end_frame, + .min_perms = AV_PERM_READ, + .rej_perms = AV_PERM_REUSE2|AV_PERM_PRESERVE,}, + { .name = NULL}}, + .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, };