Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
e8c7b4dd by Steve Lhomme at 2024-07-05T11:10:27+00:00
screen: remove unneeded vlc_module.h include

We don't use module_need() or "video blending".

- - - - -
3f629df4 by Steve Lhomme at 2024-07-05T11:10:27+00:00
glblend: use the regular video filter callback setter

So it matches the same Open callback as the other video filters.

- - - - -
382e20ad by Steve Lhomme at 2024-07-05T11:10:27+00:00
video_filter/opengl: set the priority to 0

All video filters have a priority of 0 because they are loaded by name and
should never be picked as a fallback for other filters.

This video filter is either loaded by name from the command-line or
in vlc_gl_WrapOpenGLFilter().

- - - - -
09a3439a by Steve Lhomme at 2024-07-05T11:10:27+00:00
video_filter/opengl: use the regular video filter callback setter

So it matches the same Open callback as the other video filters.

- - - - -
739ea5a6 by Steve Lhomme at 2024-07-05T11:10:27+00:00
vout_subpictures: expand module_need_var locally

No functional changes.

- - - - -
eb8fa683 by Steve Lhomme at 2024-07-05T11:10:27+00:00
vlc_filter: use a single type to open all types of filters

Because of the filter chain, they must have a common way to open them.

Some types of filters may not be used by the filter chain (for example the text
renderer). But still need to be activated the same way. If this ever changes
They will need their own open callback type back.

- - - - -
3021f0dc by Steve Lhomme at 2024-07-05T11:10:27+00:00
filter: add a function to load filters

The activate function should match exactly vlc_filter_open, rather than use
a generic vlc_object_t loader. Then we don't have any dirty cast.

The code is similar to module_need, with better typing.

It's not possible to inline this because we need to call vlc_objres_clear()
for each module loaded unsuccessfully. It's not a public API.

- - - - -
12846506 by Steve Lhomme at 2024-07-05T11:10:27+00:00
filters: load "video blending" filters with vlc_filter_LoadModule()

- - - - -
a3e976b6 by Steve Lhomme at 2024-07-05T11:10:27+00:00
vout_subpictures: load "text renderer" filters with 
vlc_filter_LoadModule()

- - - - -
648cd883 by Steve Lhomme at 2024-07-05T11:10:27+00:00
filters: load "video converter" filters with vlc_filter_LoadModule()

- - - - -
2fba49b6 by Steve Lhomme at 2024-07-05T11:10:27+00:00
gl_util: load "video filter" filters with vlc_filter_LoadModule()

- - - - -
4628379a by Steve Lhomme at 2024-07-05T11:10:27+00:00
vlc_filter: add a function to unload a filter module

As well as an inline function to completely destroy a filter_t.

The close function is called and the deactivate is not, since there should be 
none.

- - - - -
10edd6b9 by Steve Lhomme at 2024-07-05T11:10:27+00:00
use vlc_filter_UnloadModule instead of multiple local calls

It's better suited for filter_t.

- - - - -
e89464c8 by Steve Lhomme at 2024-07-05T11:10:27+00:00
use vlc_filter_Delete instead of multiple local calls

It's better suited for filter_t.

- - - - -
188c3644 by Steve Lhomme at 2024-07-05T11:10:27+00:00
vlc_filter: remove unused filter_Close

Use vlc_filter_UnloadModule instead.

- - - - -
c50fdba6 by Steve Lhomme at 2024-07-05T11:10:27+00:00
remove unneeded vlc_modules.h includes

- - - - -
cb484052 by Steve Lhomme at 2024-07-05T11:10:27+00:00
includes: update warning

Only the first 3 elements are the same in filter_t and decoder_t.

This warning is probably wrong anyway.

- - - - -
2ed02541 by Steve Lhomme at 2024-07-05T11:10:27+00:00
filter_chain: expand vlc_module_load() locally

So we don't need an activate function with varargs. We can call the 
vlc_filter_open directly.

- - - - -
ea63eb9c by Steve Lhomme at 2024-07-05T11:10:27+00:00
filter_chain: assert that the loaded filter has a vlc_filter_operations

- - - - -
1773bcae by Steve Lhomme at 2024-07-05T11:10:27+00:00
filter_chain: set the p_module before loading the filter

Co-authored-by: Alexandre Janniaux <aja...@videolabs.io>

- - - - -
add11b9e by Steve Lhomme at 2024-07-05T11:10:27+00:00
filter_chain: don't continue loading filters if there's no memory

- - - - -
fe26ba9b by Steve Lhomme at 2024-07-05T11:10:27+00:00
filter_chain: use vlc_filter_LoadModule() in filter_chain_AppendInner()

Now they do the same.

- - - - -


21 changed files:

- include/vlc_codec.h
- include/vlc_filter.h
- modules/access/screen/screen.c
- modules/access/screen/win32.c
- modules/audio_filter/scaletempo.c
- modules/hw/d3d11/d3d11_surface.c
- modules/hw/d3d9/dxa9.c
- modules/video_filter/blendbench.c
- modules/video_filter/ci_filters.m
- modules/video_filter/deinterlace/glblend.c
- modules/video_filter/opencv_wrapper.c
- modules/video_filter/opengl.c
- modules/video_output/apple/VLCSampleBufferDisplay.m
- modules/video_output/opengl/gl_util.c
- src/audio_output/filters.c
- src/audio_output/meter.c
- src/libvlccore.sym
- src/misc/filter.c
- src/misc/filter_chain.c
- src/misc/image.c
- src/video_output/vout_subpictures.c


Changes:

=====================================
include/vlc_codec.h
=====================================
@@ -93,7 +93,7 @@ struct decoder_owner_callbacks
 };
 
 /*
- * BIG FAT WARNING : the code relies in the first 4 members of filter_t
+ * BIG FAT WARNING : the code relies in the first 3 members of filter_t
  * and decoder_t to be the same, so if you have anything to add, do it
  * at the end of the structure.
  */


=====================================
include/vlc_filter.h
=====================================
@@ -143,18 +143,12 @@ struct vlc_filter_operations
     void (*close)(filter_t *);
 };
 
-typedef int (*vlc_open_deinterlace)(filter_t *);
-typedef int (*vlc_video_converter_open)(filter_t *);
-typedef int (*vlc_video_filter_open)(filter_t *);
-typedef int (*vlc_video_text_renderer_open)(filter_t *);
-typedef int (*vlc_video_sub_filter_open)(filter_t *);
-typedef int (*vlc_video_sub_source_open)(filter_t *);
-typedef int (*vlc_video_blending_open)(filter_t *);
+typedef int (*vlc_filter_open)(filter_t *);
 
 
 #define set_deinterlace_callback( activate )     \
     {                                            \
-        vlc_open_deinterlace open__ = activate;  \
+        vlc_filter_open open__ = activate;       \
         (void) open__;                           \
         set_callback(activate)                   \
     }                                            \
@@ -163,7 +157,7 @@ typedef int (*vlc_video_blending_open)(filter_t *);
 
 #define set_callback_video_filter( activate )              \
     {                                                      \
-        vlc_video_filter_open open__ = activate;           \
+        vlc_filter_open open__ = activate;                 \
         (void) open__;                                     \
         set_callback(activate)                             \
     }                                                      \
@@ -171,7 +165,7 @@ typedef int (*vlc_video_blending_open)(filter_t *);
 
 #define set_callback_video_converter( activate, priority ) \
     {                                                      \
-        vlc_video_converter_open open__ = activate;        \
+        vlc_filter_open open__ = activate;                 \
         (void) open__;                                     \
         set_callback(activate)                             \
     }                                                      \
@@ -179,7 +173,7 @@ typedef int (*vlc_video_blending_open)(filter_t *);
 
 #define set_callback_text_renderer( activate, priority )   \
     {                                                      \
-        vlc_video_text_renderer_open open__ = activate;    \
+        vlc_filter_open open__ = activate;                 \
         (void) open__;                                     \
         set_callback(activate)                             \
     }                                                      \
@@ -187,7 +181,7 @@ typedef int (*vlc_video_blending_open)(filter_t *);
 
 #define set_callback_sub_filter( activate )                \
     {                                                      \
-        vlc_video_sub_filter_open open__ = activate;       \
+        vlc_filter_open open__ = activate;                 \
         (void) open__;                                     \
         set_callback(activate)                             \
     }                                                      \
@@ -195,7 +189,7 @@ typedef int (*vlc_video_blending_open)(filter_t *);
 
 #define set_callback_sub_source( activate, priority )      \
     {                                                      \
-        vlc_video_sub_source_open open__ = activate;       \
+        vlc_filter_open open__ = activate;                 \
         (void) open__;                                     \
         set_callback(activate)                             \
     }                                                      \
@@ -203,14 +197,14 @@ typedef int (*vlc_video_blending_open)(filter_t *);
 
 #define set_callback_video_blending( activate, priority )  \
     {                                                      \
-        vlc_video_blending_open open__ = activate;         \
+        vlc_filter_open open__ = activate;                 \
         (void) open__;                                     \
         set_callback(activate)                             \
     }                                                      \
     set_capability( "video blending", priority )
 
 /** Structure describing a filter
- * @warning BIG FAT WARNING : the code relies on the first 4 members of
+ * @warning BIG FAT WARNING : the code relies on the first 3 members of
  * filter_t and decoder_t to be the same, so if you have anything to add,
  * do it at the end of the structure.
  */
@@ -243,10 +237,14 @@ struct filter_t
     filter_owner_t      owner;
 };
 
-static inline void filter_Close( filter_t *p_filter )
+VLC_API module_t *vlc_filter_LoadModule(filter_t *, const char *cap,
+                                        const char *name, bool strict);
+VLC_API void vlc_filter_UnloadModule(filter_t *);
+
+static inline void vlc_filter_Delete(filter_t *p_filter)
 {
-    if ( p_filter->ops->close )
-        p_filter->ops->close( p_filter );
+    vlc_filter_UnloadModule(p_filter);
+    vlc_object_delete(p_filter);
 }
 
 /**


=====================================
modules/access/screen/screen.c
=====================================
@@ -31,7 +31,6 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_modules.h>                 /* module_need for "video blending" */
 #include <vlc_filter.h>
 #include <vlc_url.h>
 #include "screen.h"


=====================================
modules/access/screen/win32.c
=====================================
@@ -30,7 +30,6 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_modules.h>                 /* module_need for "video blending" */
 #include <vlc_filter.h>
 
 #include "screen.h"
@@ -184,9 +183,7 @@ void screen_CloseCapture( void *opaque )
 #ifdef SCREEN_MOUSE
     if( p_data->p_blend )
     {
-        filter_Close( p_data->p_blend );
-        module_unneed( p_data->p_blend, p_data->p_blend->p_module );
-        vlc_object_delete(p_data->p_blend);
+        vlc_filter_Delete( p_data->p_blend );
     }
 #endif
 
@@ -310,7 +307,7 @@ static void RenderCursor( demux_t *p_demux, int i_x, int 
i_y,
             p_data->p_blend->fmt_in.video = p_sys->p_mouse->format;
             p_data->p_blend->fmt_out = p_sys->fmt;
             p_data->p_blend->p_module =
-                module_need( p_data->p_blend, "video blending", NULL, false );
+                vlc_filter_LoadModule( p_data->p_blend, "video blending", 
NULL, false );
             if( !p_data->p_blend->p_module )
             {
                 msg_Err( p_demux, "Could not load video blending module" );


=====================================
modules/audio_filter/scaletempo.c
=====================================
@@ -541,9 +541,7 @@ static void ClosePitch( filter_t *p_filter )
     vlc_object_t *p_aout = vlc_object_parent(p_filter);
     var_DelCallback( p_aout, "pitch-shift", PitchCallback, p_sys );
     var_Destroy( p_aout, "pitch-shift" );
-    filter_Close( p_sys->resampler );
-    module_unneed( p_sys->resampler, p_sys->resampler->p_module );
-    vlc_object_delete(p_sys->resampler);
+    vlc_filter_Delete( p_sys->resampler );
     Close( p_filter );
 }
 #endif


=====================================
modules/hw/d3d11/d3d11_surface.c
=====================================
@@ -31,7 +31,6 @@
 #include <vlc_common.h>
 #include <vlc_filter.h>
 #include <vlc_picture.h>
-#include <vlc_modules.h>
 
 #include <assert.h>
 
@@ -460,11 +459,7 @@ static void D3D11_RGBA(filter_t *p_filter, picture_t *src, 
picture_t *dst)
 
 static void DeleteFilter( filter_t * p_filter )
 {
-    if( p_filter->p_module )
-    {
-        filter_Close( p_filter );
-        module_unneed( p_filter, p_filter->p_module );
-    }
+    vlc_filter_UnloadModule( p_filter );
 
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );
@@ -503,7 +498,7 @@ static filter_t *CreateCPUtoGPUFilter( filter_t *p_this, 
const es_format_t *p_fm
     es_format_InitFromVideo( &p_filter->fmt_in,  &p_fmt_in->video );
     es_format_InitFromVideo( &p_filter->fmt_out, &p_fmt_in->video );
     p_filter->fmt_out.i_codec = p_filter->fmt_out.video.i_chroma = dst_chroma;
-    p_filter->p_module = module_need( p_filter, "video converter", NULL, false 
);
+    p_filter->p_module = vlc_filter_LoadModule( p_filter, "video converter", 
NULL, false );
 
     if( !p_filter->p_module )
     {


=====================================
modules/hw/d3d9/dxa9.c
=====================================
@@ -31,7 +31,6 @@
 #include <vlc_common.h>
 #include <vlc_filter.h>
 #include <vlc_picture.h>
-#include <vlc_modules.h>
 
 #include "d3d9_filters.h"
 
@@ -169,11 +168,7 @@ static void DXA9_NV12(filter_t *p_filter, picture_t *src, 
picture_t *dst)
 
 static void DeleteFilter( filter_t * p_filter )
 {
-    if( p_filter->p_module )
-    {
-        filter_Close( p_filter );
-        module_unneed( p_filter, p_filter->p_module );
-    }
+    vlc_filter_UnloadModule( p_filter );
 
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );
@@ -212,7 +207,7 @@ static filter_t *CreateFilter( filter_t *p_this, const 
es_format_t *p_fmt_in,
     es_format_InitFromVideo( &p_filter->fmt_in,  &p_fmt_in->video );
     es_format_InitFromVideo( &p_filter->fmt_out, &p_fmt_in->video );
     p_filter->fmt_out.i_codec = p_filter->fmt_out.video.i_chroma = dst_chroma;
-    p_filter->p_module = module_need( p_filter, "video converter", NULL, false 
);
+    p_filter->p_module = vlc_filter_LoadModule (p_filter, "video converter", 
NULL, false );
 
     if( !p_filter->p_module )
     {


=====================================
modules/video_filter/blendbench.c
=====================================
@@ -32,7 +32,6 @@
 #include <vlc_configuration.h>
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
-#include <vlc_modules.h>
 
 #include <vlc_filter.h>
 #include <vlc_picture.h>
@@ -243,7 +242,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t 
*p_pic )
     }
     p_blend->fmt_out.video = p_sys->p_base_image->format;
     p_blend->fmt_in.video = p_sys->p_blend_image->format;
-    p_blend->p_module = module_need( p_blend, "video blending", NULL, false );
+    p_blend->p_module = vlc_filter_LoadModule( p_blend, "video blending", 
NULL, false );
     if( !p_blend->p_module )
     {
         picture_Release( p_pic );
@@ -268,10 +267,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t 
*p_pic )
                   p_sys->p_blend_image->p[Y_PLANE].i_visible_pitch *
                   p_sys->p_blend_image->p[Y_PLANE].i_visible_lines );
 
-    filter_Close( p_blend );
-    module_unneed( p_blend, p_blend->p_module );
-
-    vlc_object_delete(p_blend);
+    vlc_filter_Delete( p_blend );
 
     p_sys->b_done = true;
     return p_pic;


=====================================
modules/video_filter/ci_filters.m
=====================================
@@ -31,7 +31,6 @@
 #include <vlc_filter.h>
 #include <vlc_picture.h>
 #include <vlc_plugin.h>
-#include <vlc_modules.h>
 #include <vlc_mouse.h>
 #include "filter_picture.h"
 #include "vt_utils.h"
@@ -530,15 +529,11 @@ cvpx_video_context_Destroy(void *priv)
 
     if (ctx->src_converter)
     {
-        filter_Close( ctx->src_converter );
-        module_unneed(ctx->src_converter, ctx->src_converter->p_module);
-        vlc_object_delete(ctx->src_converter);
+        vlc_filter_Delete( ctx->src_converter );
     }
     if (ctx->dst_converter)
     {
-        filter_Close( ctx->dst_converter );
-        module_unneed(ctx->dst_converter, ctx->dst_converter->p_module);
-        vlc_object_delete(ctx->dst_converter);
+        vlc_filter_Delete( ctx->dst_converter );
     }
 
     if (ctx->cvpx_pool)
@@ -566,7 +561,7 @@ CVPX_to_CVPX_converter_Create(filter_t *filter, bool 
to_rgba)
         converter->fmt_in.i_codec = VLC_CODEC_CVPX_BGRA;
     }
 
-    converter->p_module = module_need(converter, "video converter", NULL, 
false);
+    converter->p_module = vlc_filter_LoadModule(converter, "video converter", 
NULL, false);
     if (!converter->p_module)
     {
         vlc_object_delete(converter);


=====================================
modules/video_filter/deinterlace/glblend.c
=====================================
@@ -233,11 +233,9 @@ error:
     return VLC_EGENERIC;
 }
 
-static int OpenVideoFilter(vlc_object_t *obj)
+static int OpenVideoFilter(filter_t *filter)
 {
-    filter_t *filter = (filter_t*)obj;
-
-    char *mode = var_InheritString(obj, "deinterlace-mode");
+    char *mode = var_InheritString(filter, "deinterlace-mode");
     bool is_supported = !mode
         || !strcmp(mode, "auto")
         || !strcmp(mode, "blend");
@@ -258,8 +256,7 @@ vlc_module_begin()
     set_description("OpenGL blend deinterlace filter")
     set_subcategory(SUBCAT_VIDEO_VFILTER)
 
-    set_capability("video filter", 0)
-    set_callback(OpenVideoFilter)
+    set_callback_video_filter(OpenVideoFilter)
     add_shortcut("glblend")
 
     add_submodule()


=====================================
modules/video_filter/opencv_wrapper.c
=====================================
@@ -266,9 +266,7 @@ static void Destroy( filter_t* p_filter )
     ReleaseImages( p_filter );
 
     // Release the internal OpenCV filter.
-    filter_Close( p_sys->p_opencv );
-    module_unneed( p_sys->p_opencv, p_sys->p_opencv->p_module );
-    vlc_object_delete(p_sys->p_opencv);
+    vlc_filter_Delete( p_sys->p_opencv );
 
     free( p_sys );
 }


=====================================
modules/video_filter/opengl.c
=====================================
@@ -223,10 +223,8 @@ end:
 #endif
 }
 
-static int OpenOpenGL(vlc_object_t *obj)
+static int OpenOpenGL(filter_t *filter)
 {
-    filter_t *filter = (filter_t *)obj;
-
     filter_sys_t *sys
         = filter->p_sys
         = malloc(sizeof *sys);
@@ -240,7 +238,7 @@ static int OpenOpenGL(vlc_object_t *obj)
 
     struct vlc_decoder_device *device = filter_HoldDecoderDevice(filter);
 
-    sys->gl = CreateGL(obj, device, width, height);
+    sys->gl = CreateGL(VLC_OBJECT(filter), device, width, height);
 
     /* The vlc_gl_t instance must have hold the device if it needs it. */
     if (device)
@@ -248,13 +246,13 @@ static int OpenOpenGL(vlc_object_t *obj)
 
     if (sys->gl == NULL)
     {
-        msg_Err(obj, "Failed to create opengl context");
+        msg_Err(filter, "Failed to create opengl context");
         goto gl_create_failure;
     }
 
     if (vlc_gl_MakeCurrent (sys->gl) != VLC_SUCCESS)
     {
-        msg_Err(obj, "Failed to gl make current");
+        msg_Err(filter, "Failed to gl make current");
         assert(false);
         goto make_current_failure;
     }
@@ -262,7 +260,7 @@ static int OpenOpenGL(vlc_object_t *obj)
     struct vlc_gl_api *api = &sys->api;
     if (vlc_gl_api_Init(api, sys->gl) != VLC_SUCCESS)
     {
-        msg_Err(obj, "Failed to init vlc_gl_api");
+        msg_Err(filter, "Failed to init vlc_gl_api");
         goto gl_api_failure;
     }
 
@@ -270,7 +268,7 @@ static int OpenOpenGL(vlc_object_t *obj)
                                       &filter->fmt_in.video);
     if (!sys->interop)
     {
-        msg_Err(obj, "Could not create interop");
+        msg_Err(filter, "Could not create interop");
         goto gl_interop_failure;
     }
 
@@ -278,7 +276,7 @@ static int OpenOpenGL(vlc_object_t *obj)
         var_InheritString(filter, OPENGL_CFG_PREFIX "filter");
     if (!glfilters_config)
     {
-        msg_Err(obj, "No filters requested");
+        msg_Err(filter, "No filters requested");
         goto filter_config_failure;
     }
 
@@ -286,7 +284,7 @@ static int OpenOpenGL(vlc_object_t *obj)
     sys->filters = vlc_gl_filters_New(sys->gl, api, sys->interop, 
ORIENT_NORMAL);
     if (!sys->filters)
     {
-        msg_Err(obj, "Could not create filters");
+        msg_Err(filter, "Could not create filters");
         free(glfilters_config);
         goto filters_new_failure;
     }
@@ -296,7 +294,7 @@ static int OpenOpenGL(vlc_object_t *obj)
     ret = LoadFilters(sys, glfilters_config);
     if (ret != VLC_SUCCESS)
     {
-        msg_Err(obj, "Could not load filters: %s", glfilters_config);
+        msg_Err(filter, "Could not load filters: %s", glfilters_config);
         free(glfilters_config);
         goto filters_load_failure;
     }
@@ -314,7 +312,7 @@ static int OpenOpenGL(vlc_object_t *obj)
     ret = vlc_gl_filters_InitFramebuffers(sys->filters);
     if (ret != VLC_SUCCESS)
     {
-        msg_Err(obj, "Could not init filters framebuffers");
+        msg_Err(filter, "Could not init filters framebuffers");
         goto init_framebuffer_failure;
     }
 
@@ -365,9 +363,8 @@ vlc_module_begin()
     set_shortname( N_("opengl") )
     set_description( N_("Opengl filter executor") )
     set_subcategory( SUBCAT_VIDEO_VFILTER )
-    set_capability( "video filter", 1 )
     add_shortcut( "opengl" )
-    set_callback( OpenOpenGL )
+    set_callback_video_filter( OpenOpenGL )
     add_module_list( "opengl-filter", "opengl filter", NULL,
                      FILTER_LIST_TEXT, FILTER_LIST_LONGTEXT )
     add_module( "opengl-gl", "opengl offscreen", "", "OpenGL provider",


=====================================
modules/video_output/apple/VLCSampleBufferDisplay.m
=====================================
@@ -29,7 +29,6 @@
 #include <vlc_common.h>
 #include <vlc_filter.h>
 #include <vlc_plugin.h>
-#include <vlc_modules.h>
 #include <vlc_vout_display.h>
 #include <vlc_atomic.h>
 
@@ -84,7 +83,7 @@ CreateCVPXConverter(vout_display_t *vd)
     converter->fmt_out.video.i_chroma =
     converter->fmt_out.i_codec = VLC_CODEC_CVPX_BGRA;
 
-    converter->p_module = module_need(converter, "video converter", NULL, 
false);
+    converter->p_module = vlc_filter_LoadModule(converter, "video converter", 
NULL, false);
     if (!converter->p_module)
     {
         vlc_object_delete(converter);
@@ -101,11 +100,7 @@ static void DeleteCVPXConverter( filter_t * p_converter )
     if (!p_converter)
         return;
 
-    if( p_converter->p_module )
-    {
-        filter_Close( p_converter );
-        module_unneed( p_converter, p_converter->p_module );
-    }
+    vlc_filter_UnloadModule( p_converter );
 
     es_format_Clean( &p_converter->fmt_in );
     es_format_Clean( &p_converter->fmt_out );


=====================================
modules/video_output/opengl/gl_util.c
=====================================
@@ -215,7 +215,7 @@ vlc_gl_WrapOpenGLFilter(filter_t *filter, const char 
*opengl_filter_name)
     var_SetString(filter, "opengl-filter", opengl_filter_name);
 
     filter->p_cfg = NULL;
-    module_t *module = module_need(filter, "video filter", "opengl", true);
+    module_t *module = vlc_filter_LoadModule(filter, "video filter", "opengl", 
true);
     filter->p_cfg = prev_chain;
 
     var_Destroy(filter, "opengl-filter");


=====================================
src/audio_output/filters.c
=====================================
@@ -124,13 +124,6 @@ static filter_t *FindResampler (vlc_object_t *obj,
     return filter;
 }
 
-static void aout_FilterDestroy(filter_t *filter)
-{
-    filter_Close(filter);
-    module_unneed(filter, filter->p_module);
-    vlc_object_delete(filter);
-}
-
 /**
  * Destroys a chain of audio filters.
  */
@@ -140,7 +133,7 @@ static void aout_FiltersPipelineDestroy(struct aout_filter 
*tab, unsigned n)
     {
         filter_t *p_filter = tab[i].f;
 
-        aout_FilterDestroy(p_filter);
+        vlc_filter_Delete(p_filter);
         if (tab[i].vout != NULL)
             vout_Close(tab[i].vout);
         if (tab[i].clock != NULL)
@@ -486,7 +479,7 @@ static int AppendFilter(vlc_object_t *obj, const char 
*type, const char *name,
                                     max - 1, infmt, &filter->fmt_in.audio))
     {
         msg_Err (filter, "cannot add user %s \"%s\" (skipped)", type, name);
-        aout_FilterDestroy(filter);
+        vlc_filter_Delete(filter);
         if (owner_sys.vout != NULL)
             vout_Close(owner_sys.vout);
         if (owner_sys.clock != NULL)


=====================================
src/audio_output/meter.c
=====================================
@@ -26,7 +26,6 @@
 
 #include <vlc_common.h>
 #include <vlc_configuration.h>
-#include <vlc_modules.h>
 #include <vlc_aout.h>
 #include "aout_internal.h"
 
@@ -137,9 +136,7 @@ vlc_audio_meter_RemovePlugin(struct vlc_audio_meter *meter, 
vlc_audio_meter_plug
 
     if (plugin->filter != NULL)
     {
-        filter_Close(plugin->filter);
-        module_unneed(plugin->filter, plugin->filter->p_module);
-        vlc_object_delete(plugin->filter);
+        vlc_filter_Delete(plugin->filter);
     }
 
     if (plugin->cfg != NULL)
@@ -167,9 +164,7 @@ vlc_audio_meter_Reset(struct vlc_audio_meter *meter, const 
audio_sample_format_t
     {
         if (plugin->filter != NULL)
         {
-            filter_Close(plugin->filter);
-            module_unneed(plugin->filter, plugin->filter->p_module);
-            vlc_object_delete(plugin->filter);
+            vlc_filter_Delete(plugin->filter);
             plugin->filter = NULL;
         }
         plugin->last_date = VLC_TICK_INVALID;


=====================================
src/libvlccore.sym
=====================================
@@ -135,6 +135,8 @@ filter_chain_ForEach
 filter_ConfigureBlend
 filter_DeleteBlend
 filter_NewBlend
+vlc_filter_LoadModule
+vlc_filter_UnloadModule
 FromCharset
 vlc_find_iso639
 vlc_http_auth_Init


=====================================
src/misc/filter.c
=====================================
@@ -132,8 +132,7 @@ int filter_ConfigureBlend( vlc_blender_t *p_blend,
         !video_format_IsSameChroma( &p_blend->fmt_in.video, p_src ) )
     {
         /* The chroma is not the same, we need to reload the blend module */
-        filter_Close( p_blend );
-        module_unneed( p_blend, p_blend->p_module );
+        vlc_filter_UnloadModule( p_blend );
         p_blend->p_module = NULL;
     }
 
@@ -150,7 +149,7 @@ int filter_ConfigureBlend( vlc_blender_t *p_blend,
 
     /* */
     if( !p_blend->p_module )
-        p_blend->p_module = module_need( p_blend, "video blending", NULL, 
false );
+        p_blend->p_module = vlc_filter_LoadModule( p_blend, "video blending", 
NULL, false );
     if( !p_blend->p_module )
         return VLC_EGENERIC;
     assert( p_blend->ops != NULL );
@@ -170,13 +169,7 @@ int filter_Blend( vlc_blender_t *p_blend,
 
 void filter_DeleteBlend( vlc_blender_t *p_blend )
 {
-    if( p_blend->p_module )
-    {
-        filter_Close( p_blend );
-        module_unneed( p_blend, p_blend->p_module );
-    }
-
-    vlc_object_delete(p_blend);
+    vlc_filter_Delete( p_blend );
 }
 
 /* */


=====================================
src/misc/filter_chain.c
=====================================
@@ -33,6 +33,90 @@
 #include <libvlc.h>
 #include <assert.h>
 
+module_t *vlc_filter_LoadModule(filter_t *p_filter, const char *capability,
+                                const char *name, bool strict)
+{
+    const bool b_force_backup = p_filter->obj.force; /* FIXME: remove this */
+
+    if (name == NULL || name[0] == '\0')
+        name = "any";
+
+    /* Find matching modules */
+    module_t **mods;
+    size_t strict_total;
+    ssize_t total = vlc_module_match(capability, name, strict,
+                                     &mods, &strict_total);
+
+    if (unlikely(total < 0))
+        return NULL;
+
+    struct vlc_logger *log = p_filter->obj.logger;
+
+    vlc_debug(log, "looking for %s module matching \"%s\": %zd candidates",
+              capability, name, total);
+
+    p_filter->p_module = NULL;
+    for (size_t i = 0; i < (size_t)total; i++) {
+        module_t *cand = mods[i];
+        int ret = VLC_EGENERIC;
+        vlc_filter_open cb = vlc_module_map(log, cand);
+
+        if (cb == NULL)
+            continue;
+
+        p_filter->p_module = cand;
+        p_filter->obj.force = i < strict_total;
+        ret = cb(p_filter);
+        if (ret == VLC_SUCCESS)
+        {
+            vlc_debug(log, "using %s module \"%s\"", capability,
+                        module_get_object(cand));
+            assert( p_filter->ops != NULL );
+            break;
+        }
+
+        vlc_objres_clear(&p_filter->obj);
+        p_filter->p_module = NULL;
+
+        if (ret == VLC_ETIMEOUT)
+            break;
+        if (ret == VLC_ENOMEM)
+        {
+            free(mods);
+            return NULL;
+        }
+    }
+
+    if (p_filter->p_module == NULL)
+        vlc_debug(log, "no %s modules matched with name %s", capability, name);
+
+    free(mods);
+    if (p_filter->p_module != NULL) {
+        var_Create(p_filter, "module-name", VLC_VAR_STRING);
+        var_SetString(p_filter, "module-name", 
module_get_object(p_filter->p_module));
+    }
+
+    p_filter->obj.force = b_force_backup;
+    return p_filter->p_module;
+}
+
+void vlc_filter_UnloadModule(filter_t *p_filter)
+{
+    if (likely(p_filter->p_module))
+    {
+        if ( p_filter->ops->close )
+            p_filter->ops->close( p_filter );
+
+        msg_Dbg(p_filter, "removing \"%s\" module \"%s\"", 
module_get_capability(p_filter->p_module),
+                module_get_object(p_filter->p_module));
+        var_Destroy(p_filter, "module-name");
+
+        p_filter->p_module = NULL;
+    }
+
+    vlc_objres_clear(&p_filter->obj);
+}
+
 typedef struct chained_filter_t
 {
     /* Public part of the filter structure */
@@ -252,54 +336,13 @@ static filter_t *filter_chain_AppendInner( filter_chain_t 
*chain,
             goto error;
         module_name = name_chained;
     }
-    else if (name == NULL || name[0] != '\0')
-        module_name = "any";
 
-    struct vlc_logger *logger = vlc_object_logger(chain->obj);
-    module_t **modules;
-    size_t strict_total;
-    ssize_t count = vlc_module_match(capability, module_name, name != NULL,
-                                     &modules, &strict_total);
+    filter->p_module =
+        vlc_filter_LoadModule(filter, capability, module_name, name != NULL);
 
-    if (count < 0)
-    {
-        free(name_chained);
-        goto error;
-    }
-
-    vlc_debug(logger, "looking for %s module matching \"%s\": %zd candidates",
-              capability, module_name, count);
-    free(name_chained);
-
-    int ret = VLC_ENOTSUP;
-    for (size_t i = 0; i < (size_t)count; ++i)
-    {
-        module_t *mod = modules[i];
-        int (*activate)(filter_t *) = vlc_module_map(logger, mod);
-        if (activate == NULL)
-            continue;
-
-        filter->p_module = mod;
-        filter->obj.force = i < strict_total;
-        ret = (*activate)(filter);
-        switch (ret)
-        {
-            case VLC_SUCCESS:
-                goto done;
-            case VLC_ENOMEM:
-                goto error;
-            default:
-                vlc_objres_clear(&filter->obj);
-                continue;
-        }
-    }
-
-   if (ret != VLC_SUCCESS)
+   if (filter->p_module == NULL)
       goto error;
 
-done:
-    assert( filter->ops != NULL );
-
     vlc_list_append( &chained->node, &chain->filter_list );
 
     vlc_mouse_Init( &chained->mouse );
@@ -344,8 +387,7 @@ void filter_chain_DeleteFilter( filter_chain_t *chain, 
filter_t *filter )
     /* Remove it from the chain */
     vlc_list_remove( &chained->node );
 
-    filter_Close( filter );
-    module_unneed( filter, filter->p_module );
+    vlc_filter_UnloadModule( filter );
 
     msg_Dbg( chain->obj, "Filter %p removed from chain", (void *)filter );
     FilterDeletePictures( &chained->pending );


=====================================
src/misc/image.c
=====================================
@@ -768,7 +768,7 @@ static filter_t *CreateConverter( vlc_object_t *p_this,
 
     p_filter->fmt_out.i_codec = p_fmt_out->i_chroma;
     p_filter->vctx_in = p_vctx_in;
-    p_filter->p_module = module_need( p_filter, "video converter", NULL, false 
);
+    p_filter->p_module = vlc_filter_LoadModule( p_filter, "video converter", 
NULL, false );
 
     if( !p_filter->p_module )
     {
@@ -783,11 +783,7 @@ static filter_t *CreateConverter( vlc_object_t *p_this,
 
 static void DeleteConverter( filter_t * p_filter )
 {
-    if( p_filter->p_module )
-    {
-        filter_Close( p_filter );
-        module_unneed( p_filter, p_filter->p_module );
-    }
+    vlc_filter_UnloadModule( p_filter );
 
     es_format_Clean( &p_filter->fmt_in );
     es_format_Clean( &p_filter->fmt_out );


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -33,7 +33,6 @@
 #include <limits.h>
 
 #include <vlc_common.h>
-#include <vlc_modules.h>
 #include <vlc_filter.h>
 #include <vlc_spu.h>
 #include <vlc_vector.h>
@@ -290,16 +289,6 @@ static ssize_t spu_GetFreeChannelId(spu_t *spu, enum 
vlc_vout_order *order)
     return VOUT_SPU_CHANNEL_INVALID;
 }
 
-static void FilterRelease(filter_t *filter)
-{
-    if (filter->p_module)
-    {
-        filter_Close(filter);
-        module_unneed(filter, filter->p_module);
-    }
-    vlc_object_delete(filter);
-}
-
 static int spu_get_attachments(filter_t *filter,
                                input_attachment_t ***attachment_ptr,
                                int *attachment_count)
@@ -337,7 +326,13 @@ static filter_t *SpuRenderCreateAndLoadText(spu_t *spu)
         .sys = spu
     };
 
-    text->p_module = module_need_var(text, "text renderer", "text-renderer");
+    char *list = var_InheritString(VLC_OBJECT(text), "text-renderer");
+    if (unlikely(list != NULL))
+    {
+        text->p_module = vlc_filter_LoadModule(text, "text renderer", list, 
false);
+        free(list);
+    }
+
     if (!text->p_module)
     {
         vlc_object_delete(text);
@@ -371,7 +366,7 @@ static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t 
*object,
     scale->fmt_out.video.i_height =
     scale->fmt_out.video.i_visible_height = require_resize ? 16 : 32;
 
-    scale->p_module = module_need(scale, "video converter", NULL, false);
+    scale->p_module = vlc_filter_LoadModule(scale, "video converter", NULL, 
false);
     if (!scale->p_module)
     {
         vlc_object_delete(scale);
@@ -1818,13 +1813,13 @@ static void spu_Cleanup(spu_t *spu)
     spu_private_t *sys = spu->p;
 
     if (sys->text)
-        FilterRelease(sys->text);
+        vlc_filter_Delete(sys->text);
 
     if (sys->scale_yuvp)
-        FilterRelease(sys->scale_yuvp);
+        vlc_filter_Delete(sys->scale_yuvp);
 
     if (sys->scale)
-        FilterRelease(sys->scale);
+        vlc_filter_Delete(sys->scale);
 
     filter_chain_ForEach(sys->source_chain, SubSourceClean, spu);
     if (sys->vout)
@@ -1980,7 +1975,7 @@ void spu_Attach(spu_t *spu, input_thread_t *input)
 
         vlc_mutex_lock(&spu->p->textlock);
         if (spu->p->text)
-            FilterRelease(spu->p->text);
+            vlc_filter_Delete(spu->p->text);
         spu->p->text = SpuRenderCreateAndLoadText(spu);
         vlc_mutex_unlock(&spu->p->textlock);
     }



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/4d3b7c01a7343899ced35bc335245f9f6cc091d1...fe26ba9b11d30b8ca2f6682fef47dbed0c1f51c3

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/compare/4d3b7c01a7343899ced35bc335245f9f6cc091d1...fe26ba9b11d30b8ca2f6682fef47dbed0c1f51c3
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to