[vlc-commits] libvlc: add support for HDR10 metadata during the rendering start

Steve Lhomme git at videolan.org
Sat May 11 07:36:12 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu May  9 14:09:33 2019 +0200| [9b6e022193b8024640225644541561e2c4084b82] | committer: Steve Lhomme

libvlc: add support for HDR10 metadata during the rendering start

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9b6e022193b8024640225644541561e2c4084b82
---

 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 a32505ceee..bf262fce72 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 1264e63daf..de6d54d901 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 4ba8c4965b..18bb03e0b0 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -679,10 +679,24 @@ 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 set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [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 [IN]
  * \return true on success
  * \version LibVLC 4.0.0 or later
  *
@@ -726,7 +740,7 @@ typedef bool( *libvlc_video_direct3d_update_output_cb )( void *opaque,
  * - 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 fb9a49a28b..bbe525d3e7 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -607,12 +607,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;
@@ -1039,25 +1057,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 */
@@ -1125,11 +1124,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 5d293f8066..3f1381c3fe 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 )
     {



More information about the vlc-commits mailing list