[vlc-devel] [PATCH 7/8] libvlc: add support for HDR10 metadata during the rendering start

Steve Lhomme robux4 at ycbcr.xyz
Thu May 9 16:28:06 CEST 2019


---
 doc/libvlc/d3d11_player.cpp             |  2 +-
 doc/libvlc/d3d9_player.c                |  2 +-
 include/vlc/libvlc_media_player.h       | 16 ++++++-
 modules/video_output/win32/direct3d11.c | 61 ++++++++++++++++---------
 modules/video_output/win32/direct3d9.c  |  7 +--
 5 files changed, 60 insertions(+), 28 deletions(-)

diff --git a/doc/libvlc/d3d11_player.cpp b/doc/libvlc/d3d11_player.cpp
index 33555ca037..a1aca891ab 100644
--- a/doc/libvlc/d3d11_player.cpp
+++ b/doc/libvlc/d3d11_player.cpp
@@ -151,7 +151,7 @@ static void EndRender(struct render_context *ctx)
     ctx->d3dctx->DrawIndexed(ctx->quadIndexCount, 0, 0);
 }
 
-static bool StartRendering_cb( void *opaque, bool enter )
+static bool StartRendering_cb( void *opaque, bool enter, const libvlc_video_direct3d_hdr10_metadata_t *hdr10 )
 {
     struct render_context *ctx = static_cast<struct render_context *>( opaque );
     if ( enter )
diff --git a/doc/libvlc/d3d9_player.c b/doc/libvlc/d3d9_player.c
index d4faad3a4f..1472885779 100644
--- a/doc/libvlc/d3d9_player.c
+++ b/doc/libvlc/d3d9_player.c
@@ -259,7 +259,7 @@ static void Swap_cb( void* opaque )
     Swap( ctx );
 }
 
-static bool StartRendering_cb( void *opaque, bool enter )
+static bool StartRendering_cb( void *opaque, bool enter, const libvlc_video_direct3d_hdr10_metadata_t *hdr10 )
 {
     struct render_context *ctx = opaque;
     if ( enter )
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index cbeb7231a9..cebe81f9fa 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -673,10 +673,24 @@ typedef struct
  */
 typedef bool( *libvlc_video_direct3d_update_output_cb )( void *opaque, const libvlc_video_direct3d_cfg_t *cfg, libvlc_video_output_cfg_t *output );
 
+typedef struct
+{
+    /* similar to SMPTE ST 2086 mastering display color volume */
+    uint16_t RedPrimary[2];
+    uint16_t GreenPrimary[2];
+    uint16_t BluePrimary[2];
+    uint16_t WhitePoint[2];
+    unsigned int MaxMasteringLuminance;
+    unsigned int MinMasteringLuminance;
+    uint16_t MaxContentLightLevel;
+    uint16_t MaxFrameAverageLightLevel;
+} libvlc_video_direct3d_hdr10_metadata_t;
+
 /** Tell the host the rendering is about to start/has finished.
  *
  * \param opaque private pointer passed to the @a libvlc_video_direct3d_set_callbacks() [IN]
  * \param enter true if the rendering is about to start, false if it's finished
+ * \param hdr10 libvlc_video_direct3d_hdr10_metadata_t* or NULL
  * \return true on success
  * \version LibVLC 4.0.0 or later
  *
@@ -720,7 +734,7 @@ typedef bool( *libvlc_video_direct3d_update_output_cb )( void *opaque, const lib
  * - RSSetViewports()
  * - DrawIndexed()
  */
-typedef bool( *libvlc_video_direct3d_start_end_rendering_cb )( void *opaque, bool enter );
+typedef bool( *libvlc_video_direct3d_start_end_rendering_cb )( void *opaque, bool enter, const libvlc_video_direct3d_hdr10_metadata_t *hdr10 );
 
 
 /**
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index e7fbc9df8e..9f5f9f4de2 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -605,12 +605,30 @@ static bool LocalSwapchainUpdateOutput( void *opaque, const libvlc_video_direct3
     return true;
 }
 
-static bool LocalSwapchainStartEndRendering( void *opaque, bool enter )
+static bool LocalSwapchainStartEndRendering( void *opaque, bool enter, const libvlc_video_direct3d_hdr10_metadata_t *p_hdr10 )
 {
     struct d3d11_local_swapchain *display = opaque;
 
     if ( enter )
     {
+        if ( display->dxgiswapChain4 && p_hdr10 != NULL )
+        {
+            DXGI_HDR_METADATA_HDR10 hdr10 = { 0 };
+            hdr10.GreenPrimary[0] = p_hdr10->GreenPrimary[0];
+            hdr10.GreenPrimary[1] = p_hdr10->GreenPrimary[1];
+            hdr10.BluePrimary[0] = p_hdr10->BluePrimary[2];
+            hdr10.BluePrimary[1] = p_hdr10->BluePrimary[3];
+            hdr10.RedPrimary[0] = p_hdr10->RedPrimary[4];
+            hdr10.RedPrimary[1] = p_hdr10->RedPrimary[5];
+            hdr10.WhitePoint[0] = p_hdr10->WhitePoint[0];
+            hdr10.WhitePoint[1] = p_hdr10->WhitePoint[1];
+            hdr10.MinMasteringLuminance = p_hdr10->MinMasteringLuminance;
+            hdr10.MaxMasteringLuminance = p_hdr10->MaxMasteringLuminance;
+            hdr10.MaxContentLightLevel = p_hdr10->MaxContentLightLevel;
+            hdr10.MaxFrameAverageLightLevel = p_hdr10->MaxFrameAverageLightLevel;
+            IDXGISwapChain4_SetHDRMetaData( display->dxgiswapChain4, DXGI_HDR_METADATA_TYPE_HDR10, sizeof( hdr10 ), &hdr10 );
+        }
+
         D3D11_ClearRenderTargets( &display->d3d_dev, display->pixelFormat, display->swapchainTargetView );
     }
     return true;
@@ -1040,25 +1058,6 @@ static void PreparePicture(vout_display_t *vd, picture_t *picture, subpicture_t
     if (picture->format.mastering.max_luminance)
     {
         D3D11_UpdateQuadLuminanceScale(vd, &sys->d3d_dev, &sys->picQuad, GetFormatLuminance(VLC_OBJECT(vd), &picture->format) / (float)sys->display.luminance_peak);
-
-        struct d3d11_local_swapchain *display = &vd->sys->internal_swapchain;
-        if (display->dxgiswapChain4)
-        {
-            DXGI_HDR_METADATA_HDR10 hdr10 = {0};
-            hdr10.GreenPrimary[0] = picture->format.mastering.primaries[0];
-            hdr10.GreenPrimary[1] = picture->format.mastering.primaries[1];
-            hdr10.BluePrimary[0]  = picture->format.mastering.primaries[2];
-            hdr10.BluePrimary[1]  = picture->format.mastering.primaries[3];
-            hdr10.RedPrimary[0]   = picture->format.mastering.primaries[4];
-            hdr10.RedPrimary[1]   = picture->format.mastering.primaries[5];
-            hdr10.WhitePoint[0] = picture->format.mastering.white_point[0];
-            hdr10.WhitePoint[1] = picture->format.mastering.white_point[1];
-            hdr10.MinMasteringLuminance = picture->format.mastering.min_luminance;
-            hdr10.MaxMasteringLuminance = picture->format.mastering.max_luminance;
-            hdr10.MaxContentLightLevel = picture->format.lighting.MaxCLL;
-            hdr10.MaxFrameAverageLightLevel = picture->format.lighting.MaxFALL;
-            IDXGISwapChain4_SetHDRMetaData(display->dxgiswapChain4, DXGI_HDR_METADATA_TYPE_HDR10, sizeof(hdr10), &hdr10);
-        }
     }
 
     /* Render the quad */
@@ -1126,11 +1125,29 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
     }
 #endif
 
-    if (sys->startEndRenderingCb(sys->outside_opaque, true))
+    libvlc_video_direct3d_hdr10_metadata_t hdr10;
+    if (picture->format.mastering.max_luminance)
+    {
+        hdr10.GreenPrimary[0] = picture->format.mastering.primaries[0];
+        hdr10.GreenPrimary[1] = picture->format.mastering.primaries[1];
+        hdr10.BluePrimary[0]  = picture->format.mastering.primaries[2];
+        hdr10.BluePrimary[1]  = picture->format.mastering.primaries[3];
+        hdr10.RedPrimary[0]   = picture->format.mastering.primaries[4];
+        hdr10.RedPrimary[1]   = picture->format.mastering.primaries[5];
+        hdr10.WhitePoint[0]   = picture->format.mastering.white_point[0];
+        hdr10.WhitePoint[1]   = picture->format.mastering.white_point[1];
+        hdr10.MinMasteringLuminance = picture->format.mastering.min_luminance;
+        hdr10.MaxMasteringLuminance = picture->format.mastering.max_luminance;
+        hdr10.MaxContentLightLevel = picture->format.lighting.MaxCLL;
+        hdr10.MaxFrameAverageLightLevel = picture->format.lighting.MaxFALL;
+    }
+
+    if ( sys->startEndRenderingCb( sys->outside_opaque, true,
+                                   picture->format.mastering.max_luminance ? &hdr10 : NULL))
     {
         PreparePicture(vd, picture, subpicture);
 
-        sys->startEndRenderingCb(sys->outside_opaque, false);
+        sys->startEndRenderingCb( sys->outside_opaque, false, NULL );
     }
 }
 
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index fe937116dd..c7254407e9 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -1224,7 +1224,7 @@ static void Direct3D9RenderScene(vout_display_t *vd,
     vout_display_sys_t *sys = vd->sys;
     IDirect3DDevice9 *d3ddev = sys->d3d_dev.dev;
 
-    if (!sys->startEndRenderingCb( sys->outside_opaque, true ))
+    if (!sys->startEndRenderingCb( sys->outside_opaque, true, NULL ))
         return;
 
     Direct3D9RenderRegion(vd, picture, true);
@@ -1240,7 +1240,7 @@ static void Direct3D9RenderScene(vout_display_t *vd,
         IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE);
     }
 
-    sys->startEndRenderingCb( sys->outside_opaque, false );
+    sys->startEndRenderingCb( sys->outside_opaque, false, NULL );
 }
 
 static void Prepare(vout_display_t *vd, picture_t *picture,
@@ -1649,8 +1649,9 @@ static void LocalSwapchainSwap( void *opaque )
     Swap( vd );
 }
 
-static bool LocalSwapchainStartEndRendering( void *opaque, bool enter )
+static bool LocalSwapchainStartEndRendering( void *opaque, bool enter, const libvlc_video_direct3d_hdr10_metadata_t *p_hdr10 )
 {
+    VLC_UNUSED(p_hdr10);
     vout_display_t *vd = opaque;
     if ( enter )
     {
-- 
2.17.1



More information about the vlc-devel mailing list