]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_yadif.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavfilter / vf_yadif.c
index 1025ba12c7dd2bc8f041a7f2adf7a7acfa4e03c5..afbd900af4434b740d8ffe68b9c3cbf1f233ff30 100644 (file)
@@ -1,24 +1,23 @@
 /*
- * Copyright (C) 2006-2010 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2006-2011 Michael Niedermayer <michaelni@gmx.at>
  *               2010      James Darnley <james.darnley@gmail.com>
  *
- * This file is part of Libav.
- *
- * Libav is free software; you can redistribute it and/or modify
+ * FFmpeg is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along
- * with Libav; if not, write to the Free Software Foundation, Inc.,
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/cpu.h"
 #include "libavutil/common.h"
 #include "libavutil/pixdesc.h"
@@ -173,6 +172,9 @@ static int return_frame(AVFilterContext *ctx, int is_second)
     if (is_second) {
         yadif->out = ff_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
                                          AV_PERM_REUSE, link->w, link->h);
+        if (!yadif->out)
+            return AVERROR(ENOMEM);
+
         avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
         yadif->out->video->interlaced = 0;
     }
@@ -180,7 +182,7 @@ static int return_frame(AVFilterContext *ctx, int is_second)
     if (!yadif->csp)
         yadif->csp = &av_pix_fmt_descriptors[link->format];
     if (yadif->csp->comp[0].depth_minus1 / 8 == 1)
-        yadif->filter_line = filter_line_c_16bit;
+        yadif->filter_line = (void*)filter_line_c_16bit;
 
     filter(ctx, yadif->out, tff ^ !is_second, tff);
 
@@ -210,6 +212,8 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     AVFilterContext *ctx = link->dst;
     YADIFContext *yadif = ctx->priv;
 
+    av_assert0(picref);
+
     if (yadif->frame_pending)
         return_frame(ctx, 1);
 
@@ -218,23 +222,30 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     yadif->prev = yadif->cur;
     yadif->cur  = yadif->next;
     yadif->next = picref;
+    link->cur_buf = NULL;
 
     if (!yadif->cur)
         return 0;
 
     if (yadif->auto_enable && !yadif->cur->video->interlaced) {
         yadif->out  = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
+        if (!yadif->out)
+            return AVERROR(ENOMEM);
+
         avfilter_unref_bufferp(&yadif->prev);
         if (yadif->out->pts != AV_NOPTS_VALUE)
             yadif->out->pts *= 2;
         return ff_start_frame(ctx->outputs[0], yadif->out);
     }
 
-    if (!yadif->prev)
-        yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
+    if (!yadif->prev &&
+        !(yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ)))
+        return AVERROR(ENOMEM);
 
     yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
                                      AV_PERM_REUSE, link->w, link->h);
+    if (!yadif->out)
+        return AVERROR(ENOMEM);
 
     avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
     yadif->out->video->interlaced = 0;
@@ -280,8 +291,11 @@ static int request_frame(AVFilterLink *link)
 
         ret  = ff_request_frame(link->src->inputs[0]);
 
-        if (ret == AVERROR_EOF && yadif->next) {
+        if (ret == AVERROR_EOF && yadif->cur) {
             AVFilterBufferRef *next = avfilter_ref_buffer(yadif->next, AV_PERM_READ);
+            if (!next)
+                return AVERROR(ENOMEM);
+
             next->pts = yadif->next->pts * 2 - yadif->cur->pts;
 
             start_frame(link->src->inputs[0], next);
@@ -307,7 +321,7 @@ static int poll_frame(AVFilterLink *link)
     if (val <= 0)
         return val;
 
-    if (val==1 && !yadif->next) { //FIXME change API to not requre this red tape
+    if (val >= 1 && !yadif->next) { //FIXME change API to not requre this red tape
         if ((ret = ff_request_frame(link->src->inputs[0])) < 0)
             return ret;
         val = ff_poll_frame(link->src->inputs[0]);
@@ -353,6 +367,8 @@ static int query_formats(AVFilterContext *ctx)
         AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ),
         AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ),
         PIX_FMT_YUVA420P,
+        PIX_FMT_YUVA422P,
+        PIX_FMT_YUVA444P,
         PIX_FMT_NONE
     };
 
@@ -399,7 +415,7 @@ static int config_props(AVFilterLink *link)
 
 AVFilter avfilter_vf_yadif = {
     .name          = "yadif",
-    .description   = NULL_IF_CONFIG_SMALL("Deinterlace the input image"),
+    .description   = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
 
     .priv_size     = sizeof(YADIFContext),
     .init          = init,
@@ -411,7 +427,8 @@ AVFilter avfilter_vf_yadif = {
                                           .start_frame      = start_frame,
                                           .get_video_buffer = get_video_buffer,
                                           .draw_slice       = null_draw_slice,
-                                          .end_frame        = end_frame, },
+                                          .end_frame        = end_frame,
+                                          .rej_perms        = AV_PERM_REUSE2, },
                                         { .name = NULL}},
 
     .outputs   = (const AVFilterPad[]) {{ .name             = "default",