From 9e181699598b4741ebe7ab63262bd7328ccdffbc Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Wed, 4 Jun 2025 16:30:50 +0300 Subject: [PATCH] Merge pull request #27355 from asmorkalov:as/gapi_control_msmf Check MS Media Foundation availability in G-API too #27355 Tries to address https://github.com/opencv/opencv-python/issues/771 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/gapi/CMakeLists.txt | 9 +++++++++ .../onevpl/demux/async_mfp_demux_data_provider.cpp | 8 +++++--- .../onevpl/demux/async_mfp_demux_data_provider.hpp | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/gapi/CMakeLists.txt b/modules/gapi/CMakeLists.txt index f18290ca7d..29b20cabf6 100644 --- a/modules/gapi/CMakeLists.txt +++ b/modules/gapi/CMakeLists.txt @@ -380,6 +380,15 @@ if(WIN32) ocv_target_link_libraries(${the_module} PRIVATE wsock32 ws2_32) endif() +ocv_option(OPENCV_GAPI_MSMF "Build G-API with MS Media Foundation support" HAVE_MSMF) +if(HAVE_MSMF AND OPENCV_GAPI_MSMF) + if(TARGET opencv_test_gapi) + ocv_target_compile_definitions(opencv_test_gapi PRIVATE -DHAVE_GAPI_MSMF) + endif() + ocv_target_compile_definitions(${the_module} PRIVATE -DHAVE_GAPI_MSMF) + ocv_target_link_libraries(${the_module} PRIVATE ocv.3rdparty.msmf) +endif() + if(HAVE_DIRECTML) ocv_target_compile_definitions(${the_module} PRIVATE HAVE_DIRECTML=1) endif() diff --git a/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp b/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp index becd893e09..a4eb4546f1 100644 --- a/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp +++ b/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp @@ -14,7 +14,9 @@ namespace cv { namespace gapi { namespace wip { namespace onevpl { -#ifdef _WIN32 + +#ifdef HAVE_GAPI_MSMF + static HRESULT create_media_source(const std::string& url, IMFMediaSource **ppSource) { wchar_t sURL[MAX_PATH]; GAPI_Assert(url.size() < MAX_PATH && "Windows MAX_PATH limit was reached"); @@ -785,7 +787,7 @@ bool MFPAsyncDemuxDataProvider::empty() const { (processing_locked_buffer_storage.size() == 0) && (get_locked_buffer_size() == 0); } -#else // _WIN32 +#else // HAVE_GAPI_MSMF MFPAsyncDemuxDataProvider::MFPAsyncDemuxDataProvider(const std::string&) { GAPI_Error("Unsupported: Microsoft Media Foundation is not available"); @@ -804,7 +806,7 @@ bool MFPAsyncDemuxDataProvider::empty() const { GAPI_Error("Unsupported: Microsoft Media Foundation is not available"); return true; } -#endif // _WIN32 +#endif // HAVE_GAPI_MSMF } // namespace onevpl } // namespace wip } // namespace gapi diff --git a/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.hpp b/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.hpp index aab237f413..057e41e429 100644 --- a/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.hpp +++ b/modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.hpp @@ -16,7 +16,7 @@ #include "streaming/onevpl/onevpl_export.hpp" #include -#ifdef _WIN32 +#ifdef HAVE_GAPI_MSMF #define NOMINMAX #include #include @@ -104,7 +104,7 @@ private: } // namespace gapi } // namespace cv -#else // _WIN32 +#else // HAVE_GAPI_MSMF namespace cv { namespace gapi { namespace wip { @@ -121,6 +121,6 @@ struct GAPI_EXPORTS MFPAsyncDemuxDataProvider : public IDataProvider { } // namespace gapi } // namespace cv -#endif // _WIN32 +#endif // HAVE_GAPI_MSMF #endif // HAVE_ONEVPL #endif // GAPI_STREAMING_ONEVPL_DEMUX_ASYNC_MFP_DEMUX_DATA_PROVIDER_HPP