LCOV - code coverage report
Current view: top level - libavfilter - vf_repeatfields.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 74 0.0 %
Date: 2017-12-16 13:57:32 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2003 Tobias Diedrich
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 2 of the License, or
       9             :  * (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
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
      18             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             :  */
      20             : 
      21             : #include "libavutil/imgutils.h"
      22             : #include "avfilter.h"
      23             : #include "internal.h"
      24             : 
      25             : typedef struct RepeatFieldsContext {
      26             :     const AVClass *class;
      27             :     int state;
      28             :     int nb_planes;
      29             :     int linesize[4];
      30             :     int planeheight[4];
      31             :     AVFrame *frame;
      32             : } RepeatFieldsContext;
      33             : 
      34           0 : static av_cold void uninit(AVFilterContext *ctx)
      35             : {
      36           0 :     RepeatFieldsContext *s = ctx->priv;
      37             : 
      38           0 :     av_frame_free(&s->frame);
      39           0 : }
      40             : 
      41           0 : static int query_formats(AVFilterContext *ctx)
      42             : {
      43             :     static const enum AVPixelFormat pixel_fmts_eq[] = {
      44             :         AV_PIX_FMT_GRAY8,
      45             :         AV_PIX_FMT_YUV410P,
      46             :         AV_PIX_FMT_YUV411P,
      47             :         AV_PIX_FMT_YUV420P,
      48             :         AV_PIX_FMT_YUV422P,
      49             :         AV_PIX_FMT_YUV444P,
      50             :         AV_PIX_FMT_NONE
      51             :     };
      52             : 
      53           0 :     AVFilterFormats *fmts_list = ff_make_format_list(pixel_fmts_eq);
      54           0 :     if (!fmts_list)
      55           0 :         return AVERROR(ENOMEM);
      56           0 :     return ff_set_common_formats(ctx, fmts_list);
      57             : }
      58             : 
      59           0 : static int config_input(AVFilterLink *inlink)
      60             : {
      61           0 :     RepeatFieldsContext *s = inlink->dst->priv;
      62           0 :     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
      63             :     int ret;
      64             : 
      65           0 :     if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
      66           0 :         return ret;
      67             : 
      68           0 :     s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
      69           0 :     s->planeheight[0] = s->planeheight[3] = inlink->h;
      70             : 
      71           0 :     s->nb_planes = av_pix_fmt_count_planes(inlink->format);
      72             : 
      73           0 :     return 0;
      74             : }
      75             : 
      76           0 : static void update_pts(AVFilterLink *link, AVFrame *f, int64_t pts, int fields)
      77             : {
      78           0 :     if (av_cmp_q(link->frame_rate, (AVRational){30000, 1001}) == 0 &&
      79           0 :          av_cmp_q(link->time_base, (AVRational){1001, 60000}) <= 0
      80             :     ) {
      81           0 :         f->pts = pts + av_rescale_q(fields, (AVRational){1001, 60000}, link->time_base);
      82             :     } else
      83           0 :         f->pts = AV_NOPTS_VALUE;
      84           0 : }
      85             : 
      86           0 : static int filter_frame(AVFilterLink *inlink, AVFrame *in) {
      87           0 :     AVFilterContext *ctx = inlink->dst;
      88           0 :     AVFilterLink *outlink = inlink->dst->outputs[0];
      89           0 :     RepeatFieldsContext *s = ctx->priv;
      90             :     AVFrame *out;
      91             :     int ret, i;
      92           0 :     int state = s->state;
      93             : 
      94           0 :     if (!s->frame) {
      95           0 :         s->frame = av_frame_clone(in);
      96           0 :         if (!s->frame)
      97           0 :             return AVERROR(ENOMEM);
      98           0 :         s->frame->pts = AV_NOPTS_VALUE;
      99             :     }
     100             : 
     101           0 :     out = s->frame;
     102             : 
     103           0 :     if ((state == 0 && !in->top_field_first) ||
     104           0 :         (state == 1 &&  in->top_field_first)) {
     105           0 :         av_log(ctx, AV_LOG_WARNING, "Unexpected field flags: "
     106             :                                     "state=%d top_field_first=%d repeat_first_field=%d\n",
     107           0 :                                     state, in->top_field_first, in->repeat_pict);
     108           0 :         state ^= 1;
     109             :     }
     110             : 
     111           0 :     if (state == 0) {
     112             :         AVFrame *new;
     113             : 
     114           0 :         new = av_frame_clone(in);
     115           0 :         if (!new)
     116           0 :             return AVERROR(ENOMEM);
     117             : 
     118           0 :         ret = ff_filter_frame(outlink, new);
     119             : 
     120           0 :         if (in->repeat_pict) {
     121           0 :             av_frame_make_writable(out);
     122           0 :             update_pts(outlink, out, in->pts, 2);
     123           0 :             for (i = 0; i < s->nb_planes; i++) {
     124           0 :                 av_image_copy_plane(out->data[i], out->linesize[i] * 2,
     125           0 :                                     in->data[i], in->linesize[i] * 2,
     126           0 :                                     s->linesize[i], s->planeheight[i] / 2);
     127             :             }
     128           0 :             state = 1;
     129             :         }
     130             :     } else {
     131           0 :         for (i = 0; i < s->nb_planes; i++) {
     132           0 :             av_frame_make_writable(out);
     133           0 :             av_image_copy_plane(out->data[i] + out->linesize[i], out->linesize[i] * 2,
     134           0 :                                 in->data[i] + in->linesize[i], in->linesize[i] * 2,
     135           0 :                                 s->linesize[i], s->planeheight[i] / 2);
     136             :         }
     137             : 
     138           0 :         ret = ff_filter_frame(outlink, av_frame_clone(out));
     139             : 
     140           0 :         if (in->repeat_pict) {
     141             :             AVFrame *new;
     142             : 
     143           0 :             new = av_frame_clone(in);
     144           0 :             if (!new)
     145           0 :                 return AVERROR(ENOMEM);
     146             : 
     147           0 :             ret = ff_filter_frame(outlink, new);
     148           0 :             state = 0;
     149             :         } else {
     150           0 :             av_frame_make_writable(out);
     151           0 :             update_pts(outlink, out, in->pts, 1);
     152           0 :             for (i = 0; i < s->nb_planes; i++) {
     153           0 :                 av_image_copy_plane(out->data[i], out->linesize[i] * 2,
     154           0 :                                     in->data[i], in->linesize[i] * 2,
     155           0 :                                     s->linesize[i], s->planeheight[i] / 2);
     156             :             }
     157             :         }
     158             :     }
     159             : 
     160           0 :     s->state = state;
     161             : 
     162           0 :     av_frame_free(&in);
     163           0 :     return ret;
     164             : }
     165             : 
     166             : static const AVFilterPad repeatfields_inputs[] = {
     167             :     {
     168             :         .name         = "default",
     169             :         .type         = AVMEDIA_TYPE_VIDEO,
     170             :         .filter_frame = filter_frame,
     171             :         .config_props = config_input,
     172             :     },
     173             :     { NULL }
     174             : };
     175             : 
     176             : static const AVFilterPad repeatfields_outputs[] = {
     177             :     {
     178             :         .name = "default",
     179             :         .type = AVMEDIA_TYPE_VIDEO,
     180             :     },
     181             :     { NULL }
     182             : };
     183             : 
     184             : AVFilter ff_vf_repeatfields = {
     185             :     .name          = "repeatfields",
     186             :     .description   = NULL_IF_CONFIG_SMALL("Hard repeat fields based on MPEG repeat field flag."),
     187             :     .priv_size     = sizeof(RepeatFieldsContext),
     188             :     .uninit        = uninit,
     189             :     .inputs        = repeatfields_inputs,
     190             :     .outputs       = repeatfields_outputs,
     191             :     .query_formats = query_formats,
     192             : };

Generated by: LCOV version 1.13