Browse code

avcodec/cuvid: don't overwrite deinterlace at progressive input

If there is progressive input it will disable deinterlacing in cuvid for
all future frames even those interlaced.

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>

Miroslav Slugeň authored on 2017/02/13 02:47:07
Showing 1 changed files
... ...
@@ -51,6 +51,7 @@ typedef struct CuvidContext
51 51
     AVFifoBuffer *frame_queue;
52 52
 
53 53
     int deint_mode;
54
+    int deint_mode_current;
54 55
     int64_t prev_pts;
55 56
 
56 57
     int internal_error;
... ...
@@ -164,7 +165,11 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
164 164
         (AVRational){ format->display_aspect_ratio.x, format->display_aspect_ratio.y },
165 165
         (AVRational){ avctx->width, avctx->height }));
166 166
 
167
-    if (!format->progressive_sequence && ctx->deint_mode == cudaVideoDeinterlaceMode_Weave)
167
+    ctx->deint_mode_current = format->progressive_sequence
168
+                              ? cudaVideoDeinterlaceMode_Weave
169
+                              : ctx->deint_mode;
170
+
171
+    if (!format->progressive_sequence && ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave)
168 172
         avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT;
169 173
     else
170 174
         avctx->flags &= ~AV_CODEC_FLAG_INTERLACED_DCT;
... ...
@@ -260,14 +265,9 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form
260 260
     cuinfo.ulNumOutputSurfaces = 1;
261 261
     cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID;
262 262
     cuinfo.bitDepthMinus8 = format->bit_depth_luma_minus8;
263
+    cuinfo.DeinterlaceMode = ctx->deint_mode_current;
263 264
 
264
-    if (format->progressive_sequence) {
265
-        ctx->deint_mode = cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave;
266
-    } else {
267
-        cuinfo.DeinterlaceMode = ctx->deint_mode;
268
-    }
269
-
270
-    if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave)
265
+    if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave)
271 266
         avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
272 267
 
273 268
     ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
... ...
@@ -312,7 +312,7 @@ static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINF
312 312
     parsed_frame.dispinfo = *dispinfo;
313 313
     ctx->internal_error = 0;
314 314
 
315
-    if (ctx->deint_mode == cudaVideoDeinterlaceMode_Weave) {
315
+    if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) {
316 316
         av_fifo_generic_write(ctx->frame_queue, &parsed_frame, sizeof(CuvidParsedFrame), NULL);
317 317
     } else {
318 318
         parsed_frame.is_deinterlacing = 1;
... ...
@@ -583,7 +583,7 @@ static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
583 583
 
584 584
     av_log(avctx, AV_LOG_TRACE, "cuvid_decode_frame\n");
585 585
 
586
-    if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave) {
586
+    if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave) {
587 587
         av_log(avctx, AV_LOG_ERROR, "Deinterlacing is not supported via the old API\n");
588 588
         return AVERROR(EINVAL);
589 589
     }