[vlc-devel] [PATCH v1 29/33] opencv: use the filter push mode
Steve Lhomme
robux4 at ycbcr.xyz
Fri Sep 25 16:47:05 CEST 2020
---
modules/video_filter/opencv_example.cpp | 18 +++++++++---------
modules/video_filter/opencv_wrapper.c | 17 ++++++++---------
2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/modules/video_filter/opencv_example.cpp b/modules/video_filter/opencv_example.cpp
index 1334cd4c366..81c2e9c6e00 100644
--- a/modules/video_filter/opencv_example.cpp
+++ b/modules/video_filter/opencv_example.cpp
@@ -68,7 +68,7 @@ struct filter_sys_t
static int OpenFilter ( vlc_object_t * );
static void CloseFilter( vlc_object_t * );
-static picture_t *Filter( filter_t *, picture_t * );
+static int Filter( filter_t *, picture_t *, struct vlc_video_sink * );
/*****************************************************************************
* Module descriptor
@@ -108,7 +108,7 @@ static int OpenFilter( vlc_object_t *p_this )
p_sys->event_info.p_region = NULL;
p_sys->i_id = 0;
- p_filter->pf_video_filter = Filter;
+ p_filter->pf_video_filter_into = Filter;
//create the VIDEO_FILTER_EVENT_VARIABLE
vlc_value_t val;
@@ -151,17 +151,17 @@ static void CloseFilter( vlc_object_t *p_this )
/****************************************************************************
* Filter: Check for faces and raises an event when one is found.
****************************************************************************/
-static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
+static int Filter( filter_t *p_filter, picture_t *p_pic, struct vlc_video_sink *sink )
{
IplImage** p_img = NULL;
CvPoint pt1, pt2;
int scale = 1;
filter_sys_t *p_sys = static_cast<filter_sys_t *>(p_filter->p_sys);
-
- if ((!p_pic) )
+
+ if ( unlikely(!p_pic) )
{
msg_Err( p_filter, "no image array" );
- return NULL;
+ return VLC_EBADVAR;
}
//(hack) cast the picture_t to array of IplImage*
p_img = (IplImage**) p_pic;
@@ -170,7 +170,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
if ((!p_img[0])) //1st plane is 'I' i.e. greyscale
{
msg_Err( p_filter, "no image" );
- return NULL;
+ return VLC_EBADVAR;
}
//perform face detection
@@ -190,7 +190,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
p_sys->event_info.p_region = (video_filter_region_info_t*)
calloc( faces->total, sizeof(video_filter_region_info_t));
if( !p_sys->event_info.p_region )
- return NULL;
+ return VLC_EGENERIC;
p_sys->event_info.i_region_size = faces->total;
}
@@ -215,6 +215,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
else
msg_Err( p_filter, "No cascade - is opencv-haarcascade-file valid?" );
- return p_pic;
+ return vlc_video_sink_PutPicture( sink, p_pic );
}
diff --git a/modules/video_filter/opencv_wrapper.c b/modules/video_filter/opencv_wrapper.c
index f34de3f4e7c..b38ae205a04 100644
--- a/modules/video_filter/opencv_wrapper.c
+++ b/modules/video_filter/opencv_wrapper.c
@@ -48,7 +48,7 @@
static int Create ( vlc_object_t * );
static void Destroy ( vlc_object_t * );
-static picture_t* Filter( filter_t*, picture_t* );
+static int Filter( filter_t*, picture_t*, struct vlc_video_sink * );
static void ReleaseImages( filter_t* p_filter );
static void VlcPictureToIplImage( filter_t* p_filter, picture_t* p_in );
@@ -250,7 +250,7 @@ static int Create( vlc_object_t *p_this )
#endif
p_filter->p_sys = p_sys;
- p_filter->pf_video_filter = Filter;
+ p_filter->pf_video_filter_into = Filter;
return VLC_SUCCESS;
}
@@ -397,14 +397,14 @@ static void VlcPictureToIplImage( filter_t* p_filter, picture_t* p_in )
* This function send the currently rendered image to the internal opencv
* filter for processing.
*****************************************************************************/
-static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
+static int Filter( filter_t* p_filter, picture_t* p_pic, struct vlc_video_sink *sink )
{
filter_sys_t *p_sys = p_filter->p_sys;
picture_t* p_outpic = filter_NewPicture( p_filter );
if( p_outpic == NULL ) {
msg_Err( p_filter, "couldn't get a p_outpic!" );
picture_Release( p_pic );
- return NULL;
+ return VLC_ENOMEM;
}
// Make a copy if we want to show the original input
@@ -453,10 +453,9 @@ static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
#endif
if( p_sys->i_wrapper_output != NONE ) {
- return p_outpic;
- } else { // NONE
- picture_Release( p_outpic );
- return NULL;
- }
+ return vlc_video_sink_PutPicture( sink, p_outpic );
+
+ picture_Release( p_outpic );
+ return VLC_EGENERIC;
}
--
2.26.2
More information about the vlc-devel
mailing list