[vlc-devel] [PATCH 2/8] d3d11_deinterlace: select the right processor for the requested deinterlacing mode

Steve Lhomme robux4 at videolabs.io
Sat Jul 1 18:07:08 CEST 2017


---
 modules/video_output/win32/d3d11_deinterlace.c | 78 +++++++++++++++++++++++++-
 1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/modules/video_output/win32/d3d11_deinterlace.c b/modules/video_output/win32/d3d11_deinterlace.c
index 309ba51d2a..b1006e66bf 100644
--- a/modules/video_output/win32/d3d11_deinterlace.c
+++ b/modules/video_output/win32/d3d11_deinterlace.c
@@ -39,7 +39,12 @@
 #include "../../video_chroma/d3d11_fmt.h"
 
 #ifdef __MINGW32__
-#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BOB  2
+#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BLEND               0x1
+#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BOB                 0x2
+#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_ADAPTIVE            0x4
+#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_MOTION_COMPENSATION 0x8
+#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_INVERSE_TELECINE               0x10
+#define D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_FRAME_RATE_CONVERSION          0x20
 #endif
 
 struct filter_sys_t
@@ -55,6 +60,26 @@ struct filter_sys_t
         ID3D11Resource             *outResource;
     };
     ID3D11VideoProcessorOutputView *processorOutput;
+
+    UINT                           deint_mode;
+};
+
+#define FILTER_CFG_PREFIX "sout-deinterlace-"
+
+static const char *const mode_list[] = {
+    "blend", "bob", "mean", "linear", "yadif", "yadif2x", "ivtc" };
+
+/** User labels for the available deinterlace modes. */
+static const char *const mode_list_text[] = {
+    N_("Blend"), N_("Bob"), N_("Mean"), N_("Linear"), "Yadif", "Yadif (2x)",
+    N_("Film NTSC (IVTC)") };
+
+#define DEINT_MODE_TEXT N_("Streaming deinterlace mode")
+#define DEINT_MODE_LONGTEXT N_("Deinterlace method to use for streaming.")
+
+static const char *const ppsz_filter_options[] = {
+    "mode",
+    NULL
 };
 
 static picture_t *Deinterlace(filter_t *filter, picture_t *src)
@@ -129,6 +154,22 @@ error:
     return src;
 }
 
+static UINT GetPreferredMode(const char *mode)
+{
+    if( mode == NULL )
+        mode = "blend";
+
+    if( !strcmp( mode, "blend" ) )
+        return D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BLEND;
+    if( !strcmp( mode, "bob" ) )
+        return D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BOB;
+    if( !strcmp( mode, "ivtc" ) )
+        return D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_INVERSE_TELECINE;
+    if( !strcmp( mode, "yadif" ) || !strcmp( mode, "yadif2x" ) )
+        return D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_ADAPTIVE;
+    return 0;
+}
+
 static int Open(vlc_object_t *obj)
 {
     filter_t *filter = (filter_t *)obj;
@@ -233,11 +274,21 @@ static int Open(vlc_object_t *obj)
     if (FAILED(hr))
         goto error;
 
+    config_ChainParse( filter, FILTER_CFG_PREFIX, ppsz_filter_options,
+                       filter->p_cfg );
+    char *psz_mode = var_InheritString( filter, FILTER_CFG_PREFIX "mode" );
+    sys->deint_mode = GetPreferredMode(psz_mode);
+    if (sys->deint_mode == 0)
+    {
+        msg_Dbg(filter, "unknown mode %s, trying blend", psz_mode);
+        sys->deint_mode = GetPreferredMode("blend");
+    }
+
     for (UINT type = 0; type < processorCaps.RateConversionCapsCount; ++type)
     {
         D3D11_VIDEO_PROCESSOR_RATE_CONVERSION_CAPS rateCaps;
         ID3D11VideoProcessorEnumerator_GetVideoProcessorRateConversionCaps(processorEnumerator, type, &rateCaps);
-        if (!(rateCaps.ProcessorCaps & D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BOB))
+        if (!(rateCaps.ProcessorCaps & sys->deint_mode))
             continue;
 
         hr = ID3D11VideoDevice_CreateVideoProcessor(sys->d3dviddev,
@@ -246,6 +297,24 @@ static int Open(vlc_object_t *obj)
             break;
         sys->videoProcessor = NULL;
     }
+    if (sys->videoProcessor==NULL && sys->deint_mode != D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BOB)
+    {
+        msg_Dbg(filter, "mode %s not available, trying bob", psz_mode);
+        sys->deint_mode = D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS_DEINTERLACE_BOB;
+        for (UINT type = 0; type < processorCaps.RateConversionCapsCount; ++type)
+        {
+            D3D11_VIDEO_PROCESSOR_RATE_CONVERSION_CAPS rateCaps;
+            ID3D11VideoProcessorEnumerator_GetVideoProcessorRateConversionCaps(processorEnumerator, type, &rateCaps);
+            if (!(rateCaps.ProcessorCaps & sys->deint_mode))
+                continue;
+
+            hr = ID3D11VideoDevice_CreateVideoProcessor(sys->d3dviddev,
+                                                        processorEnumerator, type, &sys->videoProcessor);
+            if (SUCCEEDED(hr))
+                break;
+            sys->videoProcessor = NULL;
+        }
+    }
 
     if (sys->videoProcessor == NULL)
     {
@@ -339,4 +408,9 @@ vlc_module_begin()
     set_subcategory(SUBCAT_VIDEO_VFILTER)
     set_callbacks(Open, Close)
     add_shortcut ("deinterlace")
+
+    add_string( FILTER_CFG_PREFIX "mode", "blend", DEINT_MODE_TEXT,
+                DEINT_MODE_LONGTEXT, false )
+        change_string_list( mode_list, mode_list_text )
+        change_safe ()
 vlc_module_end()
-- 
2.13.0



More information about the vlc-devel mailing list