]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_yadif.c
http: add 'timeout' AVOption
[ffmpeg] / libavfilter / vf_yadif.c
index 9f949f800af408d66b7c79c98b9869ef8bdc3e66..f14d9d7a2946cc067a09667cb28ca1670d2f3a8e 100644 (file)
@@ -30,6 +30,8 @@
 #undef NDEBUG
 #include <assert.h>
 
+#define PERM_RWP AV_PERM_WRITE | AV_PERM_PRESERVE | AV_PERM_REUSE
+
 #define CHECK(j)\
     {   int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\
                   + FFABS(cur[mrefs  +(j)] - cur[prefs  -(j)])\
         int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
         int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \
         int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \
-        int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); \
-        int spatial_pred = (c+e)>>1; \
-        int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) \
-                          + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; \
+        int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, temporal_diff2); \
+        int spatial_pred = (c+e) >> 1; \
+        int spatial_score = FFABS(cur[mrefs - 1] - cur[prefs - 1]) + FFABS(c-e) \
+                          + FFABS(cur[mrefs + 1] - cur[prefs + 1]) - 1; \
  \
         CHECK(-1) CHECK(-2) }} }} \
         CHECK( 1) CHECK( 2) }} }} \
  \
         if (mode < 2) { \
-            int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; \
-            int f = (prev2[2*prefs] + next2[2*prefs])>>1; \
-            int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); \
-            int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); \
+            int b = (prev2[2 * mrefs] + next2[2 * mrefs])>>1; \
+            int f = (prev2[2 * prefs] + next2[2 * prefs])>>1; \
+            int max = FFMAX3(d - e, d - c, FFMIN(b - c, f - e)); \
+            int min = FFMIN3(d - e, d - c, FFMAX(b - c, f - e)); \
  \
             diff = FFMAX3(diff, min, -max); \
         } \
@@ -91,7 +93,8 @@ static void filter_line_c(uint8_t *dst,
 
 static void filter_line_c_16bit(uint16_t *dst,
                                 uint16_t *prev, uint16_t *cur, uint16_t *next,
-                                int w, int prefs, int mrefs, int parity, int mode)
+                                int w, int prefs, int mrefs, int parity,
+                                int mode)
 {
     int x;
     uint16_t *prev2 = parity ? prev : cur ;
@@ -129,16 +132,15 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
 
         for (y = 0; y < h; y++) {
             if ((y ^ parity) & 1) {
-                uint8_t *prev = &yadif->prev->data[i][y*refs];
-                uint8_t *cur  = &yadif->cur ->data[i][y*refs];
-                uint8_t *next = &yadif->next->data[i][y*refs];
-                uint8_t *dst  = &dstpic->data[i][y*dstpic->linesize[i]];
-                int     mode  = y==1 || y+2==h ? 2 : yadif->mode;
+                uint8_t *prev = &yadif->prev->data[i][y * refs];
+                uint8_t *cur  = &yadif->cur ->data[i][y * refs];
+                uint8_t *next = &yadif->next->data[i][y * refs];
+                uint8_t *dst  = &dstpic->data[i][y * dstpic->linesize[i]];
+                int     mode  = y == 1 || y + 2 == h ? 2 : yadif->mode;
                 int     prefs = y+1<h ? refs : -refs;
                 int     mrefs =     y ?-refs :  refs;
 
                 if(y<=1 || y+2>=h) {
-                    int j;
                     uint8_t *tmp = yadif->temp_line + 64 + 2*absrefs;
                     if(mode<2)
                         memcpy(tmp+2*mrefs, cur+2*mrefs, w*df);
@@ -152,10 +154,12 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
                     cur = tmp;
                 }
 
-                yadif->filter_line(dst, prev, cur, next, w, prefs, mrefs, parity ^ tff, mode);
+                yadif->filter_line(dst, prev, cur, next, w,
+                                   prefs, mrefs,
+                                   parity ^ tff, mode);
             } else {
-                memcpy(&dstpic->data[i][y*dstpic->linesize[i]],
-                       &yadif->cur->data[i][y*refs], w*df);
+                memcpy(&dstpic->data[i][y * dstpic->linesize[i]],
+                       &yadif->cur->data[i][y * refs], w * df);
             }
         }
     }
@@ -166,19 +170,18 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
 static int return_frame(AVFilterContext *ctx, int is_second)
 {
     YADIFContext *yadif = ctx->priv;
-    AVFilterLink *link= ctx->outputs[0];
+    AVFilterLink *link  = ctx->outputs[0];
     int tff, ret;
 
     if (yadif->parity == -1) {
         tff = yadif->cur->video->interlaced ?
-            yadif->cur->video->top_field_first : 1;
+              yadif->cur->video->top_field_first : 1;
     } else {
-        tff = yadif->parity^1;
+        tff = yadif->parity ^ 1;
     }
 
     if (is_second) {
-        yadif->out = ff_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
-                                         AV_PERM_REUSE, link->w, link->h);
+        yadif->out = ff_get_video_buffer(link, PERM_RWP, link->w, link->h);
         if (!yadif->out)
             return AVERROR(ENOMEM);
 
@@ -254,15 +257,17 @@ static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
         !(yadif->prev = avfilter_ref_buffer(yadif->cur, ~AV_PERM_WRITE)))
         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);
+    yadif->out = ff_get_video_buffer(ctx->outputs[0], PERM_RWP,
+                                     link->w, link->h);
     if (!yadif->out)
         return AVERROR(ENOMEM);
 
     avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
     yadif->out->video->interlaced = 0;
+
     if (yadif->out->pts != AV_NOPTS_VALUE)
         yadif->out->pts *= 2;
+
     return ff_start_frame(ctx->outputs[0], yadif->out);
 }
 
@@ -305,6 +310,7 @@ static int request_frame(AVFilterLink *link)
 
         if (ret == AVERROR_EOF && yadif->cur) {
             AVFilterBufferRef *next = avfilter_ref_buffer(yadif->next, ~AV_PERM_WRITE);
+
             if (!next)
                 return AVERROR(ENOMEM);
 
@@ -333,7 +339,8 @@ 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
+    //FIXME change API to not requre this red tape
+    if (val >= 1 && !yadif->next) {
         if ((ret = ff_request_frame(link->src->inputs[0])) < 0)
             return ret;
         val = ff_poll_frame(link->src->inputs[0]);
@@ -360,29 +367,29 @@ static av_cold void uninit(AVFilterContext *ctx)
 
 static int query_formats(AVFilterContext *ctx)
 {
-    static const enum PixelFormat pix_fmts[] = {
-        PIX_FMT_YUV420P,
-        PIX_FMT_YUV422P,
-        PIX_FMT_YUV444P,
-        PIX_FMT_YUV410P,
-        PIX_FMT_YUV411P,
-        PIX_FMT_GRAY8,
-        PIX_FMT_YUVJ420P,
-        PIX_FMT_YUVJ422P,
-        PIX_FMT_YUVJ444P,
-        AV_NE( PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE ),
-        PIX_FMT_YUV440P,
-        PIX_FMT_YUVJ440P,
-        AV_NE( PIX_FMT_YUV420P10BE, PIX_FMT_YUV420P10LE ),
-        AV_NE( PIX_FMT_YUV422P10BE, PIX_FMT_YUV422P10LE ),
-        AV_NE( PIX_FMT_YUV444P10BE, PIX_FMT_YUV444P10LE ),
-        AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ),
-        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
+    static const enum AVPixelFormat pix_fmts[] = {
+        AV_PIX_FMT_YUV420P,
+        AV_PIX_FMT_YUV422P,
+        AV_PIX_FMT_YUV444P,
+        AV_PIX_FMT_YUV410P,
+        AV_PIX_FMT_YUV411P,
+        AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_YUVJ420P,
+        AV_PIX_FMT_YUVJ422P,
+        AV_PIX_FMT_YUVJ444P,
+        AV_NE( AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_GRAY16LE ),
+        AV_PIX_FMT_YUV440P,
+        AV_PIX_FMT_YUVJ440P,
+        AV_NE( AV_PIX_FMT_YUV420P10BE, AV_PIX_FMT_YUV420P10LE ),
+        AV_NE( AV_PIX_FMT_YUV422P10BE, AV_PIX_FMT_YUV422P10LE ),
+        AV_NE( AV_PIX_FMT_YUV444P10BE, AV_PIX_FMT_YUV444P10LE ),
+        AV_NE( AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_YUV420P16LE ),
+        AV_NE( AV_PIX_FMT_YUV422P16BE, AV_PIX_FMT_YUV422P16LE ),
+        AV_NE( AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUV444P16LE ),
+        AV_PIX_FMT_YUVA420P,
+        AV_PIX_FMT_YUVA422P,
+        AV_PIX_FMT_YUVA444P,
+        AV_PIX_FMT_NONE
     };
 
     ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
@@ -399,14 +406,17 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     yadif->auto_enable = 0;
     yadif->csp = NULL;
 
-    if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable);
+    if (args)
+        sscanf(args, "%d:%d:%d",
+               &yadif->mode, &yadif->parity, &yadif->auto_enable);
 
     yadif->filter_line = filter_line_c;
 
     if (HAVE_MMX)
         ff_yadif_init_x86(yadif);
 
-    av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable);
+    av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n",
+           yadif->mode, yadif->parity, yadif->auto_enable);
 
     return 0;
 }