]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_setfield.c
x86: Fix assembly with NASM
[ffmpeg] / libavfilter / vf_setfield.c
1 /*
2  * Copyright (c) 2012 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * set field order
24  */
25
26 #include "avfilter.h"
27 #include "video.h"
28
29 enum SetFieldMode {
30     MODE_AUTO = -1,
31     MODE_BFF,
32     MODE_TFF,
33     MODE_PROG,
34 };
35
36 typedef struct {
37     enum SetFieldMode mode;
38 } SetFieldContext;
39
40 static av_cold int init(AVFilterContext *ctx, const char *args)
41 {
42     SetFieldContext *setfield = ctx->priv;
43
44     setfield->mode = MODE_AUTO;
45
46     if (args) {
47         char c;
48         if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
49             if      (!strcmp("tff",  args)) setfield->mode = MODE_TFF;
50             else if (!strcmp("bff",  args)) setfield->mode = MODE_BFF;
51             else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
52             else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
53             else {
54                 av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
55                 return AVERROR(EINVAL);
56             }
57         } else {
58             if (setfield->mode < -1 || setfield->mode > 1) {
59                 av_log(ctx, AV_LOG_ERROR,
60                        "Provided integer value %d must be included between -1 and +1\n",
61                        setfield->mode);
62                 return AVERROR(EINVAL);
63             }
64             av_log(ctx, AV_LOG_WARNING,
65                    "Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
66         }
67     }
68
69     return 0;
70 }
71
72 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
73 {
74     SetFieldContext *setfield = inlink->dst->priv;
75     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
76
77     if (setfield->mode == MODE_PROG) {
78         outpicref->video->interlaced = 0;
79     } else if (setfield->mode != MODE_AUTO) {
80         outpicref->video->interlaced = 1;
81         outpicref->video->top_field_first = setfield->mode;
82     }
83     return ff_start_frame(inlink->dst->outputs[0], outpicref);
84 }
85
86 AVFilter avfilter_vf_setfield = {
87     .name      = "setfield",
88     .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
89     .init      = init,
90
91     .priv_size = sizeof(SetFieldContext),
92
93     .inputs = (const AVFilterPad[]) {
94         { .name             = "default",
95           .type             = AVMEDIA_TYPE_VIDEO,
96           .get_video_buffer = ff_null_get_video_buffer,
97           .start_frame      = start_frame, },
98         { .name = NULL }
99     },
100     .outputs = (const AVFilterPad[]) {
101         { .name             = "default",
102           .type             = AVMEDIA_TYPE_VIDEO, },
103         { .name = NULL }
104     },
105 };