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
This commit is contained in:
Alexander Smorkalov 2025-06-04 16:30:50 +03:00 committed by GitHub
parent a2c381a82b
commit 9e18169959
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View File

@ -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()

View File

@ -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

View File

@ -16,7 +16,7 @@
#include "streaming/onevpl/onevpl_export.hpp"
#include <opencv2/gapi/streaming/onevpl/data_provider_interface.hpp>
#ifdef _WIN32
#ifdef HAVE_GAPI_MSMF
#define NOMINMAX
#include <mfapi.h>
#include <mfidl.h>
@ -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