[vlc-commits] [Git][videolan/vlc][master] 5 commits: doc: libvlc: use _strdup() on Windows samples

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Mar 3 20:27:17 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
4bad605e by Steve Lhomme at 2022-03-03T18:43:58+00:00
doc: libvlc: use _strdup() on Windows samples

strdup() is issuing a deprecated warning with the MS SDK.

- - - - -
db6ad1bc by Steve Lhomme at 2022-03-03T18:43:58+00:00
doc: libvlc: fix type casting

- - - - -
df63adaf by Steve Lhomme at 2022-03-03T18:43:58+00:00
doc: fix warnings with MSVC in d3d11_player

- - - - -
e70bb016 by Steve Lhomme at 2022-03-03T18:43:58+00:00
doc: libvlc: add a CMake makefile to build the win32 samples

CMake has good integration with VSCode which makes it as easy as just loading
the folder in VSCode, set the SDK folder and build.

- - - - -
a3771591 by Steve Lhomme at 2022-03-03T18:43:58+00:00
CI: build the win32 libvlc sample when build the win64 target

- - - - -


5 changed files:

- + doc/libvlc/CMakeLists.txt
- doc/libvlc/d3d11_player.cpp
- doc/libvlc/d3d9_player.c
- doc/libvlc/win_player.c
- extras/ci/gitlab-ci.yml


Changes:

=====================================
doc/libvlc/CMakeLists.txt
=====================================
@@ -0,0 +1,41 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
+
+# configure with your own path
+#  -DLIBVLC_SDK_INC:STRING=S:/sources/build/win64/win64/vlc-4.0.0-dev/sdk/include
+#  -DLIBVLC_SDK_LIB:STRING=S:/sources/build/win64/win64/vlc-4.0.0-dev/sdk/lib
+#
+# or set them in your VSCode settings
+# {
+#     "cmake.configureSettings": {
+#         "LIBVLC_SDK_INC": "S:/sources/vlc/include",
+#         "LIBVLC_SDK_LIB": "S:/sources/build/win64/win64/lib/.libs"
+#     }
+# }
+
+set("LIBVLC_SDK_INC" "" CACHE PATH "libvlc include folder, containing the vlc/ includes")
+set("LIBVLC_SDK_LIB" "" CACHE PATH "libvlc library folder, containing the libvlc libraries")
+
+project("libvlc samples")
+
+# define the libvlc external build
+add_library(libvlc SHARED IMPORTED GLOBAL)
+target_include_directories(libvlc INTERFACE "${LIBVLC_SDK_INC}")
+if (MSVC)
+    set_target_properties(libvlc PROPERTIES IMPORTED_IMPLIB "${LIBVLC_SDK_LIB}/libvlc.lib")
+else ()
+    set_target_properties(libvlc PROPERTIES IMPORTED_IMPLIB "${LIBVLC_SDK_LIB}/libvlc.dll.a")
+endif ()
+
+if(WIN32)
+
+    add_executable(d3d9_player WIN32 d3d9_player.c)
+    target_link_libraries(d3d9_player libvlc d3d9)
+
+    add_executable(d3d11_player WIN32 d3d11_player.cpp)
+    target_compile_definitions(d3d11_player PRIVATE _WIN32_WINNT=0x0601)
+    target_link_libraries(d3d11_player libvlc d3d11 d3dcompiler uuid)
+
+    add_executable(win_player WIN32 win_player.c)
+    target_link_libraries(win_player libvlc)
+
+endif()


=====================================
doc/libvlc/d3d11_player.cpp
=====================================
@@ -1,4 +1,4 @@
-/* compile: g++ d3d11_player.cpp -o d3d11_player.exe -L<path/libvlc> -lvlc -ld3d11 -ld3dcompiler_47 -luuid */
+/* compile: g++ d3d11_player.cpp -o d3d11_player.exe -L<path/libvlc> -lvlc -ld3d11 -ld3dcompiler -luuid */
 
 /* This is the most extreme use case where libvlc is given its own ID3D11DeviceContext
    and draws in a texture shared with the ID3D11DeviceContext of the app..
@@ -153,7 +153,7 @@ static void init_direct3d(struct render_context *ctx)
                                   NULL,
                                   creationFlags,
                                   NULL,
-                                  NULL,
+                                  0,
                                   D3D11_SDK_VERSION,
                                   &scd,
                                   &ctx->swapchain,
@@ -228,9 +228,9 @@ static void init_direct3d(struct render_context *ctx)
     ctx->vertexBufferStride = sizeof(OurVertices[0]);
 
     D3D11_MAPPED_SUBRESOURCE ms;
-    ctx->d3dctx->Map(ctx->pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
+    ctx->d3dctx->Map(ctx->pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &ms);
     memcpy(ms.pData, OurVertices, sizeof(OurVertices));
-    ctx->d3dctx->Unmap(ctx->pVertexBuffer, NULL);
+    ctx->d3dctx->Unmap(ctx->pVertexBuffer, 0);
 
     ctx->quadIndexCount = 6;
     D3D11_BUFFER_DESC quadDesc = { };
@@ -240,7 +240,7 @@ static void init_direct3d(struct render_context *ctx)
     quadDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
     ctx->d3device->CreateBuffer(&quadDesc, NULL, &ctx->pIndexBuffer);
 
-    ctx->d3dctx->Map(ctx->pIndexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
+    ctx->d3dctx->Map(ctx->pIndexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &ms);
     WORD *triangle_pos = static_cast<WORD*>(ms.pData);
     triangle_pos[0] = 3;
     triangle_pos[1] = 1;
@@ -249,7 +249,7 @@ static void init_direct3d(struct render_context *ctx)
     triangle_pos[3] = 2;
     triangle_pos[4] = 1;
     triangle_pos[5] = 3;
-    ctx->d3dctx->Unmap(ctx->pIndexBuffer, NULL);
+    ctx->d3dctx->Unmap(ctx->pIndexBuffer, 0);
 
     ctx->d3dctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 
@@ -413,10 +413,9 @@ static bool UpdateOutput_cb( void *opaque, const libvlc_video_render_cfg_t *cfg,
 
     ctx->d3dctx->PSSetShaderResources(0, 1, &ctx->resized.textureShaderInput);
 
-    D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc = {
-        .Format = texDesc.Format,
-        .ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D,
-    };
+    D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc = { };
+    renderTargetViewDesc.Format = texDesc.Format;
+    renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
     hr = ctx->d3deviceVLC->CreateRenderTargetView(ctx->resized.textureVLC, &renderTargetViewDesc, &ctx->resized.textureRenderTarget);
     if (FAILED(hr)) return false;
 
@@ -553,8 +552,8 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
             }
             ReleaseSRWLockExclusive(&ctx->swapchainLock);
 
-            ctx->width  = LOWORD(lParam) * (BORDER_RIGHT - BORDER_LEFT) / 2.0f; /* remove the orange part ! */
-            ctx->height = HIWORD(lParam) * (BORDER_TOP - BORDER_BOTTOM) / 2.0f;
+            ctx->width  = unsigned(LOWORD(lParam) * (BORDER_RIGHT - BORDER_LEFT) / 2.0f); // remove the orange part !
+            ctx->height = unsigned(HIWORD(lParam) * (BORDER_TOP - BORDER_BOTTOM) / 2.0f);
 
             // tell libvlc we want a new rendering size
             // we could also match the source video size and scale in swapchain render
@@ -572,7 +571,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
         case WM_KEYDOWN:
         case WM_SYSKEYDOWN:
             {
-                int key = tolower( (unsigned char)MapVirtualKey( wParam, 2 ) );
+                int key = tolower( MapVirtualKey( (UINT)wParam, 2 ) );
                 if (key == 'a')
                 {
                     if (AspectRatio == NULL)
@@ -622,12 +621,12 @@ int WINAPI WinMain(HINSTANCE hInstance,
     /* remove "" around the given path */
     if (lpCmdLine[0] == '"')
     {
-        file_path = strdup( lpCmdLine+1 );
+        file_path = _strdup( lpCmdLine+1 );
         if (file_path[strlen(file_path)-1] == '"')
             file_path[strlen(file_path)-1] = '\0';
     }
     else
-        file_path = strdup( lpCmdLine );
+        file_path = _strdup( lpCmdLine );
 
     p_libvlc = libvlc_new( 0, NULL );
     p_media = libvlc_media_new_path( p_libvlc, file_path );
@@ -703,5 +702,5 @@ int WINAPI WinMain(HINSTANCE hInstance,
 
     libvlc_release( p_libvlc );
 
-    return msg.wParam;
+    return (int)msg.wParam;
 }


=====================================
doc/libvlc/d3d9_player.c
=====================================
@@ -315,7 +315,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
         case WM_KEYDOWN:
         case WM_SYSKEYDOWN:
             {
-                int key = tolower( (unsigned char)MapVirtualKey( wParam, 2 ) );
+                int key = tolower( MapVirtualKey( (UINT)wParam, 2 ) );
                 if (key == 'a')
                 {
                     if (AspectRatio == NULL)
@@ -366,12 +366,12 @@ int WINAPI WinMain(HINSTANCE hInstance,
     /* remove "" around the given path */
     if (lpCmdLine[0] == '"')
     {
-        file_path = strdup( lpCmdLine+1 );
+        file_path = _strdup( lpCmdLine+1 );
         if (file_path[strlen(file_path)-1] == '"')
             file_path[strlen(file_path)-1] = '\0';
     }
     else
-        file_path = strdup( lpCmdLine );
+        file_path = _strdup( lpCmdLine );
 
     p_libvlc = libvlc_new( 0, NULL );
     p_media = libvlc_media_new_path( p_libvlc, file_path );
@@ -444,5 +444,5 @@ int WINAPI WinMain(HINSTANCE hInstance,
     DeleteCriticalSection(&Context.sizeLock);
     release_direct3d(&Context);
 
-    return msg.wParam;
+    return (int)msg.wParam;
 }


=====================================
doc/libvlc/win_player.c
=====================================
@@ -58,7 +58,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
         case WM_KEYDOWN:
         case WM_SYSKEYDOWN:
             {
-                int key = tolower( (unsigned char)MapVirtualKey( wParam, 2 ) );
+                int key = tolower( MapVirtualKey( (UINT)wParam, 2 ) );
                 if (key == 'a')
                 {
                     if (AspectRatio == NULL)
@@ -108,12 +108,12 @@ int WINAPI WinMain(HINSTANCE hInstance,
     /* remove "" around the given path */
     if (lpCmdLine[0] == '"')
     {
-        file_path = strdup( lpCmdLine+1 );
+        file_path = _strdup( lpCmdLine+1 );
         if (file_path[strlen(file_path)-1] == '"')
             file_path[strlen(file_path)-1] = '\0';
     }
     else
-        file_path = strdup( lpCmdLine );
+        file_path = _strdup( lpCmdLine );
 
     Context.p_libvlc = libvlc_new( 0, NULL );
     p_media = libvlc_media_new_path( Context.p_libvlc, file_path );
@@ -169,5 +169,5 @@ int WINAPI WinMain(HINSTANCE hInstance,
     libvlc_media_player_release( Context.p_mediaplayer );
     libvlc_release( Context.p_libvlc );
 
-    return msg.wParam;
+    return (int)msg.wParam;
 }


=====================================
extras/ci/gitlab-ci.yml
=====================================
@@ -140,6 +140,11 @@ variables:
         else
             extras/package/win32/build.sh -c -a $HOST_ARCH $NIGHTLY_EXTRA_BUILD_FLAGS $LIBVLC_EXTRA_BUILD_FLAGS $UWP_EXTRA_BUILD_FLAGS
         fi
+        if [ "${CI_JOB_NAME}" = "win64" ]; then
+          cmake -DLIBVLC_SDK_INC:STRING=${CI_PROJECT_DIR}/include -DLIBVLC_SDK_LIB:STRING=${CI_PROJECT_DIR}/${SHORTARCH}/lib/.libs -H${CI_PROJECT_DIR}/doc/libvlc -B${CI_PROJECT_DIR}/doc/libvlc/build \
+                -G Ninja -DCMAKE_C_COMPILER=${TRIPLET}-gcc -DCMAKE_CXX_COMPILER=${TRIPLET}-g++ -DCMAKE_SYSTEM_NAME=Windows
+          cmake --build ${CI_PROJECT_DIR}/doc/libvlc/build
+        fi
 
 win32:
     extends: .win-common



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6eab1792ba5e484d27f157b922b1749c4a6d20b6...a37715916283d42cdfd97d25810b2fa32674cba9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6eab1792ba5e484d27f157b922b1749c4a6d20b6...a37715916283d42cdfd97d25810b2fa32674cba9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list