Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
e4b9a58c
Commit
e4b9a58c
authored
May 19, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14578 from mshabunin:add-mfx-plugin
parents
b4ec8fe3
6fc6207e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
243 additions
and
12 deletions
+243
-12
CMakeLists.txt
modules/videoio/CMakeLists.txt
+6
-2
plugin.cmake
modules/videoio/cmake/plugin.cmake
+6
-4
cap_mfx_common.cpp
modules/videoio/src/cap_mfx_common.cpp
+0
-2
cap_mfx_plugin.cpp
modules/videoio/src/cap_mfx_plugin.cpp
+220
-0
videoio_registry.cpp
modules/videoio/src/videoio_registry.cpp
+2
-0
test_mfx.cpp
modules/videoio/test/test_mfx.cpp
+9
-4
No files found.
modules/videoio/CMakeLists.txt
View file @
e4b9a58c
...
...
@@ -64,9 +64,14 @@ if(DEFINED WINRT AND NOT DEFINED WINRT_8_0 AND NOT DEFINED ENABLE_WINRT_MODE_NAT
${
CMAKE_CURRENT_LIST_DIR
}
/src/cap_winrt/MediaStreamSink.hpp
)
endif
()
include
(
${
CMAKE_CURRENT_LIST_DIR
}
/cmake/plugin.cmake
)
set
(
tgts
)
if
(
TARGET ocv.3rdparty.mediasdk
)
if
(
"mfx"
IN_LIST VIDEOIO_PLUGIN_LIST
)
ocv_create_builtin_videoio_plugin
(
"opencv_videoio_intel_mfx"
ocv.3rdparty.mediasdk
"cap_mfx_common.cpp"
"cap_mfx_reader.cpp"
"cap_mfx_writer.cpp"
"cap_mfx_plugin.cpp"
)
else
()
list
(
APPEND videoio_srcs
${
CMAKE_CURRENT_LIST_DIR
}
/src/cap_mfx_common.cpp
${
CMAKE_CURRENT_LIST_DIR
}
/src/cap_mfx_reader.cpp
...
...
@@ -76,6 +81,7 @@ if(TARGET ocv.3rdparty.mediasdk)
${
CMAKE_CURRENT_LIST_DIR
}
/src/cap_mfx_reader.hpp
${
CMAKE_CURRENT_LIST_DIR
}
/src/cap_mfx_writer.hpp
)
list
(
APPEND tgts ocv.3rdparty.mediasdk
)
endif
()
endif
()
if
(
TARGET ocv.3rdparty.dshow
)
...
...
@@ -100,8 +106,6 @@ if(TARGET ocv.3rdparty.dc1394_2)
list
(
APPEND tgts ocv.3rdparty.dc1394_2
)
endif
()
include
(
${
CMAKE_CURRENT_LIST_DIR
}
/cmake/plugin.cmake
)
if
(
TARGET ocv.3rdparty.gstreamer
)
if
(
"gstreamer"
IN_LIST VIDEOIO_PLUGIN_LIST
)
ocv_create_builtin_videoio_plugin
(
"opencv_videoio_gstreamer"
ocv.3rdparty.gstreamer
"cap_gstreamer.cpp"
)
...
...
modules/videoio/cmake/plugin.cmake
View file @
e4b9a58c
function
(
ocv_create_builtin_videoio_plugin name target
videoio_src_file
)
function
(
ocv_create_builtin_videoio_plugin name target
)
ocv_debug_message
(
"ocv_create_builtin_videoio_plugin(
${
ARGV
}
)"
)
...
...
@@ -11,9 +11,11 @@ function(ocv_create_builtin_videoio_plugin name target videoio_src_file)
message
(
STATUS
"Video I/O: add builtin plugin '
${
name
}
'"
)
add_library
(
${
name
}
MODULE
"
${
CMAKE_CURRENT_LIST_DIR
}
/src/
${
videoio_src_file
}
"
)
foreach
(
src
${
ARGN
}
)
list
(
APPEND sources
"
${
CMAKE_CURRENT_LIST_DIR
}
/src/
${
src
}
"
)
endforeach
()
add_library
(
${
name
}
MODULE
${
sources
}
)
target_include_directories
(
${
name
}
PRIVATE
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
)
target_compile_definitions
(
${
name
}
PRIVATE BUILD_PLUGIN
)
target_link_libraries
(
${
name
}
PRIVATE
${
target
}
)
...
...
modules/videoio/src/cap_mfx_common.cpp
View file @
e4b9a58c
...
...
@@ -196,5 +196,3 @@ bool WriteBitstream::isOpened() const
{
return
output
.
is_open
();
}
//==================================================================================================
modules/videoio/src/cap_mfx_plugin.cpp
0 → 100644
View file @
e4b9a58c
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#if defined(BUILD_PLUGIN)
#include <string>
#include "cap_mfx_reader.hpp"
#include "cap_mfx_writer.hpp"
#include "plugin_api.hpp"
using
namespace
std
;
namespace
cv
{
static
CvResult
CV_API_CALL
cv_capture_open
(
const
char
*
filename
,
int
,
CV_OUT
CvPluginCapture
*
handle
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
*
handle
=
NULL
;
if
(
!
filename
)
return
CV_ERROR_FAIL
;
VideoCapture_IntelMFX
*
cap
=
0
;
try
{
if
(
filename
)
{
cap
=
new
VideoCapture_IntelMFX
(
string
(
filename
));
if
(
cap
->
isOpened
())
{
*
handle
=
(
CvPluginCapture
)
cap
;
return
CV_ERROR_OK
;
}
}
}
catch
(...)
{
}
if
(
cap
)
delete
cap
;
return
CV_ERROR_FAIL
;
}
static
CvResult
CV_API_CALL
cv_capture_release
(
CvPluginCapture
handle
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
VideoCapture_IntelMFX
*
instance
=
(
VideoCapture_IntelMFX
*
)
handle
;
delete
instance
;
return
CV_ERROR_OK
;
}
static
CvResult
CV_API_CALL
cv_capture_get_prop
(
CvPluginCapture
handle
,
int
prop
,
CV_OUT
double
*
val
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
if
(
!
val
)
return
CV_ERROR_FAIL
;
try
{
VideoCapture_IntelMFX
*
instance
=
(
VideoCapture_IntelMFX
*
)
handle
;
*
val
=
instance
->
getProperty
(
prop
);
return
CV_ERROR_OK
;
}
catch
(...)
{
return
CV_ERROR_FAIL
;
}
}
static
CvResult
CV_API_CALL
cv_capture_set_prop
(
CvPluginCapture
handle
,
int
prop
,
double
val
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
try
{
VideoCapture_IntelMFX
*
instance
=
(
VideoCapture_IntelMFX
*
)
handle
;
return
instance
->
setProperty
(
prop
,
val
)
?
CV_ERROR_OK
:
CV_ERROR_FAIL
;
}
catch
(...)
{
return
CV_ERROR_FAIL
;
}
}
static
CvResult
CV_API_CALL
cv_capture_grab
(
CvPluginCapture
handle
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
try
{
VideoCapture_IntelMFX
*
instance
=
(
VideoCapture_IntelMFX
*
)
handle
;
return
instance
->
grabFrame
()
?
CV_ERROR_OK
:
CV_ERROR_FAIL
;
}
catch
(...)
{
return
CV_ERROR_FAIL
;
}
}
static
CvResult
CV_API_CALL
cv_capture_retrieve
(
CvPluginCapture
handle
,
int
stream_idx
,
cv_videoio_retrieve_cb_t
callback
,
void
*
userdata
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
try
{
VideoCapture_IntelMFX
*
instance
=
(
VideoCapture_IntelMFX
*
)
handle
;
Mat
img
;
if
(
instance
->
retrieveFrame
(
stream_idx
,
img
))
return
callback
(
stream_idx
,
img
.
data
,
img
.
step
,
img
.
cols
,
img
.
rows
,
img
.
channels
(),
userdata
);
return
CV_ERROR_FAIL
;
}
catch
(...)
{
return
CV_ERROR_FAIL
;
}
}
static
CvResult
CV_API_CALL
cv_writer_open
(
const
char
*
filename
,
int
fourcc
,
double
fps
,
int
width
,
int
height
,
int
isColor
,
CV_OUT
CvPluginWriter
*
handle
)
{
VideoWriter_IntelMFX
*
wrt
=
0
;
try
{
wrt
=
new
VideoWriter_IntelMFX
(
filename
,
fourcc
,
fps
,
Size
(
width
,
height
),
isColor
);
if
(
wrt
->
isOpened
())
{
*
handle
=
(
CvPluginWriter
)
wrt
;
return
CV_ERROR_OK
;
}
}
catch
(...)
{
}
if
(
wrt
)
delete
wrt
;
return
CV_ERROR_FAIL
;
}
static
CvResult
CV_API_CALL
cv_writer_release
(
CvPluginWriter
handle
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
VideoWriter_IntelMFX
*
instance
=
(
VideoWriter_IntelMFX
*
)
handle
;
delete
instance
;
return
CV_ERROR_OK
;
}
static
CvResult
CV_API_CALL
cv_writer_get_prop
(
CvPluginWriter
/*handle*/
,
int
/*prop*/
,
CV_OUT
double
*
/*val*/
)
{
return
CV_ERROR_FAIL
;
}
static
CvResult
CV_API_CALL
cv_writer_set_prop
(
CvPluginWriter
/*handle*/
,
int
/*prop*/
,
double
/*val*/
)
{
return
CV_ERROR_FAIL
;
}
static
CvResult
CV_API_CALL
cv_writer_write
(
CvPluginWriter
handle
,
const
unsigned
char
*
data
,
int
step
,
int
width
,
int
height
,
int
cn
)
{
if
(
!
handle
)
return
CV_ERROR_FAIL
;
try
{
VideoWriter_IntelMFX
*
instance
=
(
VideoWriter_IntelMFX
*
)
handle
;
Mat
img
(
Size
(
width
,
height
),
CV_MAKETYPE
(
CV_8U
,
cn
),
const_cast
<
uchar
*>
(
data
),
step
);
instance
->
write
(
img
);
return
CV_ERROR_OK
;
}
catch
(...)
{
return
CV_ERROR_FAIL
;
}
}
static
const
OpenCV_VideoIO_Plugin_API_preview
plugin_api_v0
=
{
{
sizeof
(
OpenCV_VideoIO_Plugin_API_preview
),
ABI_VERSION
,
API_VERSION
,
CV_VERSION_MAJOR
,
CV_VERSION_MINOR
,
CV_VERSION_REVISION
,
CV_VERSION_STATUS
,
"MediaSDK OpenCV Video I/O plugin"
},
/* 1*/
CAP_INTEL_MFX
,
/* 2*/
cv_capture_open
,
/* 3*/
cv_capture_release
,
/* 4*/
cv_capture_get_prop
,
/* 5*/
cv_capture_set_prop
,
/* 6*/
cv_capture_grab
,
/* 7*/
cv_capture_retrieve
,
/* 8*/
cv_writer_open
,
/* 9*/
cv_writer_release
,
/* 10*/
cv_writer_get_prop
,
/* 11*/
cv_writer_set_prop
,
/* 12*/
cv_writer_write
};
}
// namespace
const
OpenCV_VideoIO_Plugin_API_preview
*
opencv_videoio_plugin_init_v0
(
int
requested_abi_version
,
int
requested_api_version
,
void
*
/*reserved=NULL*/
)
CV_NOEXCEPT
{
if
(
requested_abi_version
!=
0
)
return
NULL
;
if
(
requested_api_version
!=
0
)
return
NULL
;
return
&
cv
::
plugin_api_v0
;
}
#endif // BUILD_PLUGIN
modules/videoio/src/videoio_registry.cpp
View file @
e4b9a58c
...
...
@@ -70,6 +70,8 @@ static const struct VideoBackendInfo builtin_backends[] =
#ifdef HAVE_MFX // Media SDK
DECLARE_STATIC_BACKEND
(
CAP_INTEL_MFX
,
"INTEL_MFX"
,
MODE_CAPTURE_BY_FILENAME
|
MODE_WRITER
,
create_MFX_capture
,
0
,
create_MFX_writer
),
#elif defined(ENABLE_PLUGINS)
DECLARE_DYNAMIC_BACKEND
(
CAP_INTEL_MFX
,
"INTEL_MFX"
,
MODE_CAPTURE_BY_FILENAME
|
MODE_WRITER
),
#endif
// Apple platform
...
...
modules/videoio/test/test_mfx.cpp
View file @
e4b9a58c
...
...
@@ -4,12 +4,13 @@
#include "test_precomp.hpp"
#ifdef HAVE_MFX
namespace
opencv_test
{
namespace
{
TEST
(
videoio_mfx
,
read_invalid
)
{
if
(
!
videoio_registry
::
hasBackend
(
CAP_INTEL_MFX
))
throw
SkipTestException
(
"MediaSDK backend was not found"
);
VideoCapture
cap
;
ASSERT_NO_THROW
(
cap
.
open
(
"nonexistent-file"
,
CAP_INTEL_MFX
));
ASSERT_FALSE
(
cap
.
isOpened
());
...
...
@@ -20,6 +21,9 @@ TEST(videoio_mfx, read_invalid)
TEST
(
videoio_mfx
,
write_invalid
)
{
if
(
!
videoio_registry
::
hasBackend
(
CAP_INTEL_MFX
))
throw
SkipTestException
(
"MediaSDK backend was not found"
);
const
string
filename
=
cv
::
tempfile
(
".264"
);
VideoWriter
writer
;
bool
res
=
true
;
...
...
@@ -84,6 +88,9 @@ typedef testing::TestWithParam< Size_FPS_Ext > videoio_mfx;
TEST_P
(
videoio_mfx
,
read_write_raw
)
{
if
(
!
videoio_registry
::
hasBackend
(
CAP_INTEL_MFX
))
throw
SkipTestException
(
"MediaSDK backend was not found"
);
const
Size
FRAME_SIZE
=
get
<
0
>
(
GetParam
());
const
double
FPS
=
get
<
1
>
(
GetParam
());
const
char
*
ext
=
get
<
2
>
(
GetParam
());
...
...
@@ -144,5 +151,3 @@ INSTANTIATE_TEST_CASE_P(videoio, videoio_mfx,
testing
::
Values
(
".mpeg2"
,
".264"
,
".265"
)));
}}
// namespace
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment