[vlc-commits] opencv_wrapper: fix compilation

Zhao Zhili git at videolan.org
Sat May 26 18:07:14 CEST 2018


vlc | branch: master | Zhao Zhili <quinkblack at foxmail.com> | Fri Apr 27 10:10:36 2018 +0800| [03f6c6c2e90111a70880b7c590c78864cf9799d1] | committer: Jean-Baptiste Kempf

opencv_wrapper: fix compilation

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=03f6c6c2e90111a70880b7c590c78864cf9799d1
---

 modules/video_filter/opencv_wrapper.c | 110 +++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 54 deletions(-)

diff --git a/modules/video_filter/opencv_wrapper.c b/modules/video_filter/opencv_wrapper.c
index ed48fe1f67..ea1f96588c 100644
--- a/modules/video_filter/opencv_wrapper.c
+++ b/modules/video_filter/opencv_wrapper.c
@@ -151,11 +151,12 @@ typedef struct
 static int Create( vlc_object_t *p_this )
 {
     filter_t* p_filter = (filter_t*)p_this;
+    filter_sys_t *p_sys;
     char *psz_chroma, *psz_output;
 
     /* Allocate structure */
-    p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
-    if( p_filter->p_sys == NULL )
+    p_sys = malloc( sizeof( filter_sys_t ) );
+    if( p_sys == NULL )
         return VLC_ENOMEM;
 
     /* Load the internal OpenCV filter.
@@ -167,39 +168,38 @@ static int Create( vlc_object_t *p_this )
      * We don't need to set up video formats for this filter as it not
      * actually using a picture_t.
      */
-    p_filter->p_sys->p_opencv = vlc_object_create( p_filter, sizeof(filter_t) );
-    if( !p_filter->p_sys->p_opencv ) {
-        free( p_filter->p_sys );
+    p_sys->p_opencv = vlc_object_create( p_filter, sizeof(filter_t) );
+    if( !p_sys->p_opencv ) {
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
-    p_filter->p_sys->psz_inner_name = var_InheritString( p_filter, "opencv-filter-name" );
-    if( p_filter->p_sys->psz_inner_name )
-        p_filter->p_sys->p_opencv->p_module =
-            module_need( p_filter->p_sys->p_opencv,
+    p_sys->psz_inner_name = var_InheritString( p_filter, "opencv-filter-name" );
+    if( p_sys->psz_inner_name )
+        p_sys->p_opencv->p_module =
+            module_need( p_sys->p_opencv,
                          "opencv internal filter",
-                         p_filter->p_sys->psz_inner_name,
+                         p_sys->psz_inner_name,
                          true );
 
-    if( !p_filter->p_sys->p_opencv->p_module )
+    if( !p_sys->p_opencv->p_module )
     {
-        msg_Err( p_filter, "can't open internal opencv filter: %s", p_filter->p_sys->psz_inner_name );
-        free( p_filter->p_sys->psz_inner_name );
-        p_filter->p_sys->psz_inner_name = NULL;
-        vlc_object_release( p_filter->p_sys->p_opencv );
-        free( p_filter->p_sys );
+        msg_Err( p_filter, "can't open internal opencv filter: %s", p_sys->psz_inner_name );
+        free( p_sys->psz_inner_name );
+        vlc_object_release( p_sys->p_opencv );
+        free( p_sys );
 
         return VLC_ENOMOD;
     }
 
 
     /* Init structure */
-    p_filter->p_sys->p_image = image_HandlerCreate( p_filter );
+    p_sys->p_image = image_HandlerCreate( p_filter );
     for( int i = 0; i < VOUT_MAX_PLANES; i++ )
-        p_filter->p_sys->p_cv_image[i] = NULL;
-    p_filter->p_sys->p_proc_image = NULL;
-    p_filter->p_sys->p_to_be_freed = NULL;
-    p_filter->p_sys->i_cv_image_size = 0;
+        p_sys->p_cv_image[i] = NULL;
+    p_sys->p_proc_image = NULL;
+    p_sys->p_to_be_freed = NULL;
+    p_sys->i_cv_image_size = 0;
 
     /* Retrieve and apply config */
     psz_chroma = var_InheritString( p_filter, "opencv-chroma" );
@@ -207,16 +207,16 @@ static int Create( vlc_object_t *p_this )
     {
         msg_Err( p_filter, "configuration variable %s empty, using 'grey'",
                          "opencv-chroma" );
-        p_filter->p_sys->i_internal_chroma = GREY;
+        p_sys->i_internal_chroma = GREY;
     } else if( !strcmp( psz_chroma, "input" ) )
-        p_filter->p_sys->i_internal_chroma = CINPUT;
+        p_sys->i_internal_chroma = CINPUT;
     else if( !strcmp( psz_chroma, "I420" ) )
-        p_filter->p_sys->i_internal_chroma = GREY;
+        p_sys->i_internal_chroma = GREY;
     else if( !strcmp( psz_chroma, "RGB32" ) )
-        p_filter->p_sys->i_internal_chroma = RGB;
+        p_sys->i_internal_chroma = RGB;
     else {
         msg_Err( p_filter, "no valid opencv-chroma provided, using 'grey'" );
-        p_filter->p_sys->i_internal_chroma = GREY;
+        p_sys->i_internal_chroma = GREY;
     }
 
     free( psz_chroma );
@@ -226,33 +226,34 @@ static int Create( vlc_object_t *p_this )
     {
         msg_Err( p_filter, "configuration variable %s empty, using 'input'",
                          "opencv-output" );
-        p_filter->p_sys->i_wrapper_output = VINPUT;
+        p_sys->i_wrapper_output = VINPUT;
     } else if( !strcmp( psz_output, "none" ) )
-        p_filter->p_sys->i_wrapper_output = NONE;
+        p_sys->i_wrapper_output = NONE;
     else if( !strcmp( psz_output, "input" ) )
-        p_filter->p_sys->i_wrapper_output = VINPUT;
+        p_sys->i_wrapper_output = VINPUT;
     else if( !strcmp( psz_output, "processed" ) )
-        p_filter->p_sys->i_wrapper_output = PROCESSED;
+        p_sys->i_wrapper_output = PROCESSED;
     else {
         msg_Err( p_filter, "no valid opencv-output provided, using 'input'" );
-        p_filter->p_sys->i_wrapper_output = VINPUT;
+        p_sys->i_wrapper_output = VINPUT;
     }
     free( psz_output );
 
-    p_filter->p_sys->f_scale =
+    p_sys->f_scale =
         var_InheritFloat( p_filter, "opencv-scale" );
 
     msg_Info(p_filter, "Configuration: opencv-scale: %f, opencv-chroma: %d, "
         "opencv-output: %d, opencv-filter %s",
-        p_filter->p_sys->f_scale,
-        p_filter->p_sys->i_internal_chroma,
-        p_filter->p_sys->i_wrapper_output,
-        p_filter->p_sys->psz_inner_name);
+        p_sys->f_scale,
+        p_sys->i_internal_chroma,
+        p_sys->i_wrapper_output,
+        p_sys->psz_inner_name);
 
 #ifndef NDEBUG
     msg_Dbg( p_filter, "opencv_wrapper successfully started" );
 #endif
 
+    p_filter->p_sys = p_sys;
     p_filter->pf_video_filter = Filter;
 
     return VLC_SUCCESS;
@@ -266,14 +267,14 @@ static int Create( vlc_object_t *p_this )
 static void Destroy( vlc_object_t *p_this )
 {
     filter_t* p_filter = (filter_t*)p_this;
+    filter_sys_t *p_sys = p_filter->p_sys;
     ReleaseImages( p_filter );
 
     // Release the internal OpenCV filter.
-    module_unneed( p_filter->p_sys->p_opencv, p_filter->p_sys->p_opencv->p_module );
-    vlc_object_release( p_filter->p_sys->p_opencv );
-    p_filter->p_sys->p_opencv = NULL;
+    module_unneed( p_sys->p_opencv, p_sys->p_opencv->p_module );
+    vlc_object_release( p_sys->p_opencv );
 
-    free( p_filter->p_sys );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -403,6 +404,7 @@ static void VlcPictureToIplImage( filter_t* p_filter, picture_t* p_in )
  *****************************************************************************/
 static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
 {
+    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!" );
@@ -413,20 +415,20 @@ static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
     video_format_t fmt_out;
 
     // Make a copy if we want to show the original input
-    if (p_filter->p_sys->i_wrapper_output == VINPUT)
+    if (p_sys->i_wrapper_output == VINPUT)
         picture_Copy( p_outpic, p_pic );
 
     VlcPictureToIplImage( p_filter, p_pic );
     // Pass the image (as a pointer to the first IplImage*) to the
     // internal OpenCV filter for processing.
-    p_filter->p_sys->p_opencv->pf_video_filter( p_filter->p_sys->p_opencv, (picture_t*)&(p_filter->p_sys->p_cv_image[0]) );
+    p_sys->p_opencv->pf_video_filter( p_sys->p_opencv, (picture_t*)&(p_sys->p_cv_image[0]) );
 
-    if(p_filter->p_sys->i_wrapper_output == PROCESSED) {
+    if(p_sys->i_wrapper_output == PROCESSED) {
         // Processed video
-        if( (p_filter->p_sys->p_proc_image) &&
-            (p_filter->p_sys->p_proc_image->i_planes > 0) &&
-            (p_filter->p_sys->i_internal_chroma != CINPUT) ) {
-            //p_filter->p_sys->p_proc_image->format.i_chroma = VLC_CODEC_RGB24;
+        if( (p_sys->p_proc_image) &&
+            (p_sys->p_proc_image->i_planes > 0) &&
+            (p_sys->i_internal_chroma != CINPUT) ) {
+            //p_sys->p_proc_image->format.i_chroma = VLC_CODEC_RGB24;
 
             memset( &fmt_out, 0, sizeof(video_format_t) );
             fmt_out = p_pic->format;
@@ -438,16 +440,16 @@ static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
              * main video output error: pictures leaked, trying to workaround
              */
             picture_t* p_outpic_tmp = image_Convert(
-                        p_filter->p_sys->p_image,
-                        p_filter->p_sys->p_proc_image,
-                        &(p_filter->p_sys->p_proc_image->format),
+                        p_sys->p_image,
+                        p_sys->p_proc_image,
+                        &(p_sys->p_proc_image->format),
                         &fmt_out );
 
             picture_CopyPixels( p_outpic, p_outpic_tmp );
             CopyInfoAndRelease( p_outpic, p_outpic_tmp );
-        } else if( p_filter->p_sys->i_internal_chroma == CINPUT ) {
-            picture_CopyPixels( p_outpic, p_filter->p_sys->p_proc_image );
-            picture_CopyProperties( p_outpic, p_filter->p_sys->p_proc_image );
+        } else if( p_sys->i_internal_chroma == CINPUT ) {
+            picture_CopyPixels( p_outpic, p_sys->p_proc_image );
+            picture_CopyProperties( p_outpic, p_sys->p_proc_image );
         }
     }
 
@@ -458,7 +460,7 @@ static picture_t* Filter( filter_t* p_filter, picture_t* p_pic )
     msg_Dbg( p_filter, "Filter() done" );
 #endif
 
-    if( p_filter->p_sys->i_wrapper_output != NONE ) {
+    if( p_sys->i_wrapper_output != NONE ) {
         return p_outpic;
     } else { // NONE
         picture_Release( p_outpic );



More information about the vlc-commits mailing list