[vlc-commits] [Git][videolan/vlc][master] 7 commits: input: rename INPUT_TYPE_NONE

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Oct 3 12:59:15 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
01065349 by Thomas Guillem at 2024-10-03T12:19:02+00:00
input: rename INPUT_TYPE_NONE

- - - - -
095b30af by Thomas Guillem at 2024-10-03T12:19:02+00:00
input: log when type is playback

- - - - -
34c05377 by Thomas Guillem at 2024-10-03T12:19:02+00:00
input: invert preparsing checks

Resulting in the following changes when thumbnailing:
 - no renderer
 - no stats
 - no sout
 - no titles
 - no title info

- - - - -
11a8a733 by Thomas Guillem at 2024-10-03T12:19:02+00:00
input: refactor preparsing check

- - - - -
12eb76c1 by Thomas Guillem at 2024-10-03T12:19:02+00:00
input: rework input_Create arguments

This will allow adding extra params easily, like:
 - bool parse_subitems (to remove input_item_t.i_preparse_depth)
 - bool interact (to remove input_item_t.b_preparse_interact)

- - - - -
fd2cf597 by Thomas Guillem at 2024-10-03T12:19:02+00:00
medialibrary: use a static for cbs struct

- - - - -
8871a103 by Thomas Guillem at 2024-10-03T12:19:02+00:00
input: rework input_item_Parse arguments

And put the vlc_object_t argument in 1st, to behave like most API.

cf. 9c57c2ccb991047d8132deaa1875a2501fcaac20

This will allow adding extra params easily, like:
 - bool parse_subitems (to remove input_item_t.i_preparse_depth)
 - bool interact (to remove input_item_t.b_preparse_interact)

- - - - -


14 changed files:

- include/vlc_input_item.h
- modules/gui/macosx/library/VLCInputItem.m
- modules/misc/medialibrary/MetadataExtractor.cpp
- modules/misc/medialibrary/fs/directory.cpp
- src/input/decoder.c
- src/input/es_out.c
- src/input/event.h
- src/input/input.c
- src/input/input_internal.h
- src/input/parse.c
- src/input/test/es_out.c
- src/input/thumbnailer.c
- src/player/input.c
- src/preparser/preparser.c


Changes:

=====================================
include/vlc_input_item.h
=====================================
@@ -464,6 +464,16 @@ typedef struct input_item_parser_cbs_t
                                  size_t count, void *userdata);
 } input_item_parser_cbs_t;
 
+/**
+ * input item parser configuration struct
+ */
+struct input_item_parser_cfg {
+    /** Callbacks to be notified of the end of the parsing, can't be NULL */
+    const input_item_parser_cbs_t *cbs;
+    /** Opaque data used by parser callbacks */
+    void *cbs_data;
+};
+
 /**
  * Parse an item asynchronously
  *
@@ -471,17 +481,16 @@ typedef struct input_item_parser_cbs_t
  * input_item_parser_id_Interrupt() before receiving the on_ended() event in
  * order to interrupt it.
  *
- * @param item the item to parse
  * @param parent the parent obj
- * @param cbs callbacks to be notified of the end of the parsing
- * @param userdata opaque data used by parser callbacks
+ * @param item the item to parse
+ * @param cfg pointer to a configuration struct, can't be NULL
  *
  * @return a parser instance or NULL in case of error, the parser needs to be
  * released with input_item_parser_id_Release()
  */
 VLC_API input_item_parser_id_t *
-input_item_Parse(input_item_t *item, vlc_object_t *parent,
-                 const input_item_parser_cbs_t *cbs, void *userdata) VLC_USED;
+input_item_Parse(vlc_object_t *parent, input_item_t *item,
+                 const struct input_item_parser_cfg *cfg) VLC_USED;
 
 /**
  * Interrupts & cancels the parsing


=====================================
modules/gui/macosx/library/VLCInputItem.m
=====================================
@@ -520,10 +520,12 @@ static const struct vlc_metadata_cbs preparseCallbacks = {
 
 - (void)parseInputItem
 {
-    _p_parserID = input_item_Parse(_vlcInputItem,
-                                   VLC_OBJECT(getIntf()),
-                                   &parserCallbacks,
-                                   (__bridge void *) self);
+    const struct input_item_parser_cfg cfg = {
+        .cbs = &parserCallbacks,
+        .cbs_data = (__bridge void *) self,
+    };
+
+    _p_parserID = input_item_Parse(VLC_OBJECT(getIntf()), _vlcInputItem, &cfg);
 }
 
 - (void)cancelParsing


=====================================
modules/misc/medialibrary/MetadataExtractor.cpp
=====================================
@@ -227,16 +227,20 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
     if ( ctx.inputItem == nullptr )
         return medialibrary::parser::Status::Fatal;
 
-    const input_item_parser_cbs_t cbs = {
+    static const input_item_parser_cbs_t cbs = {
         &MetadataExtractor::onParserEnded,
         &MetadataExtractor::onParserSubtreeAdded,
         &MetadataExtractor::onAttachmentsAdded,
     };
+
+    const struct input_item_parser_cfg cfg= {
+        .cbs = &cbs,
+        .cbs_data = std::addressof( ctx ),
+    };
     m_currentCtx = &ctx;
     ctx.inputItem->i_preparse_depth = 1;
     ctx.inputParser = {
-        input_item_Parse( ctx.inputItem.get(), m_obj, &cbs,
-                          std::addressof( ctx ) ),
+        input_item_Parse( m_obj, ctx.inputItem.get(), &cfg ),
         &input_item_parser_id_Release
     };
     if ( ctx.inputParser == nullptr )


=====================================
modules/misc/medialibrary/fs/directory.cpp
=====================================
@@ -170,7 +170,12 @@ static bool request_metadata_sync( libvlc_int_t *libvlc, input_item_t *media,
         nullptr,
     };
 
-    auto inputParser = vlc::wrap_cptr( input_item_Parse( media, VLC_OBJECT( libvlc ), &cbs, &req ),
+    const struct input_item_parser_cfg cfg= {
+        .cbs = &cbs,
+        .cbs_data = &req,
+    };
+
+    auto inputParser = vlc::wrap_cptr( input_item_Parse( VLC_OBJECT( libvlc ), media, &cfg ),
                                        &input_item_parser_id_Release );
 
     if ( inputParser == nullptr )


=====================================
src/input/decoder.c
=====================================
@@ -2276,7 +2276,7 @@ vlc_input_decoder_Create( vlc_object_t *p_parent, const es_format_t *fmt, const
         .clock = clock,
         .resource = p_resource,
         .sout = NULL,
-        .input_type = INPUT_TYPE_NONE,
+        .input_type = INPUT_TYPE_PLAYBACK,
         .cbs = NULL, .cbs_data = NULL,
     };
     return decoder_New( p_parent, &cfg );


=====================================
src/input/es_out.c
=====================================
@@ -803,7 +803,7 @@ static int EsOutSetRecord(es_out_sys_t *p_sys, bool b_record, const char *dir_pa
             .clock = NULL,
             .resource = input_priv(p_input)->p_resource,
             .sout = p_sys->p_sout_record,
-            .input_type = INPUT_TYPE_NONE,
+            .input_type = INPUT_TYPE_PLAYBACK,
             .cc_decoder = p_sys->cc_decoder,
             .cbs = &decoder_cbs,
             .cbs_data = p_es,
@@ -2331,7 +2331,7 @@ static void EsOutCreateDecoder(es_out_sys_t *p_sys, es_out_id_t *p_es)
                 .clock = NULL,
                 .resource = priv->p_resource,
                 .sout = p_sys->p_sout_record,
-                .input_type = INPUT_TYPE_NONE,
+                .input_type = INPUT_TYPE_PLAYBACK,
                 .cc_decoder = p_sys->cc_decoder,
                 .cbs = &decoder_cbs,
                 .cbs_data = p_es,


=====================================
src/input/event.h
=====================================
@@ -31,8 +31,8 @@ static inline void input_SendEvent(input_thread_t *p_input,
                                    const struct vlc_input_event *event)
 {
     input_thread_private_t *priv = input_priv(p_input);
-    if(priv->events_cb)
-        priv->events_cb(p_input, event, priv->events_data);
+    if (priv->cbs != NULL && priv->cbs->on_event != NULL)
+        priv->cbs->on_event(p_input, event, priv->cbs_data);
 }
 
 /*****************************************************************************


=====================================
src/input/input.c
=====================================
@@ -207,12 +207,11 @@ input_item_t *input_GetItem( input_thread_t *p_input )
 }
 
 #undef input_Create
-input_thread_t *input_Create( vlc_object_t *p_parent,
-                              input_thread_events_cb events_cb, void *events_data,
-                              input_item_t *p_item, enum input_type type,
-                              input_resource_t *p_resource,
-                              vlc_renderer_item_t *p_renderer )
+input_thread_t * input_Create( vlc_object_t *p_parent, input_item_t *p_item,
+                               const struct vlc_input_thread_cfg *cfg )
 {
+    assert(cfg != NULL);
+
     /* Allocate descriptor */
     input_thread_private_t *priv;
 
@@ -231,7 +230,7 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
 
     char * psz_name = input_item_GetName( p_item );
     const char *type_str;
-    switch (type)
+    switch (cfg->type)
     {
         case INPUT_TYPE_PREPARSING:
             type_str = "preparsing ";
@@ -240,7 +239,7 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
             type_str = "thumbnailing ";
             break;
         default:
-            type_str = "";
+            type_str = "playback";
             break;
     }
     msg_Dbg( p_input, "Creating an input for %s'%s'", type_str, psz_name);
@@ -250,9 +249,9 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
     input_item_ApplyOptions( VLC_OBJECT(p_input), p_item );
 
     /* Init Common fields */
-    priv->events_cb = events_cb;
-    priv->events_data = events_data;
-    priv->type = type;
+    priv->cbs = cfg->cbs;
+    priv->cbs_data = cfg->cbs_data;
+    priv->type = cfg->type;
     priv->i_start = 0;
     priv->i_stop  = 0;
     priv->i_title_offset = input_priv(p_input)->i_seekpoint_offset = 0;
@@ -264,8 +263,8 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
     TAB_INIT( priv->i_attachment, priv->attachment );
     priv->p_sout   = NULL;
     priv->b_out_pace_control = priv->type == INPUT_TYPE_THUMBNAILING;
-    priv->p_renderer = p_renderer && priv->type != INPUT_TYPE_PREPARSING ?
-                vlc_renderer_item_hold( p_renderer ) : NULL;
+    priv->p_renderer = cfg->renderer && priv->type == INPUT_TYPE_PLAYBACK ?
+                vlc_renderer_item_hold( cfg->renderer ) : NULL;
 
     priv->viewpoint_changed = false;
     /* Fetch the viewpoint from the mediaplayer or the playlist if any */
@@ -286,8 +285,7 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
 
     /* setup the preparse depth of the item
      * if we are preparsing, use the i_preparse_depth of the parent item */
-    if( priv->type == INPUT_TYPE_PREPARSING
-     || priv->type == INPUT_TYPE_THUMBNAILING )
+    if( priv->type != INPUT_TYPE_PLAYBACK )
     {
         p_input->obj.logger = NULL;
         p_input->obj.no_interact = true;
@@ -327,8 +325,8 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
     priv->slave   = NULL;
 
     /* */
-    if( p_resource )
-        priv->p_resource = input_resource_Hold( p_resource );
+    if( cfg->resource )
+        priv->p_resource = input_resource_Hold( cfg->resource );
     else
         priv->p_resource = input_resource_New( VLC_OBJECT( p_input ) );
     input_resource_SetInput( priv->p_resource, p_input );
@@ -350,7 +348,7 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
     input_item_SetESNowPlaying( p_item, NULL );
 
     /* */
-    if( priv->type != INPUT_TYPE_PREPARSING && var_InheritBool( p_input, "stats" ) )
+    if( priv->type == INPUT_TYPE_PLAYBACK && var_InheritBool( p_input, "stats" ) )
         priv->stats = input_stats_Create();
     else
         priv->stats = NULL;
@@ -759,7 +757,7 @@ static int InitSout( input_thread_t * p_input )
 {
     input_thread_private_t *priv = input_priv(p_input);
 
-    if( priv->type == INPUT_TYPE_PREPARSING )
+    if( priv->type != INPUT_TYPE_PLAYBACK )
         return VLC_SUCCESS;
 
     /* Find a usable sout and attach it to p_input */
@@ -845,7 +843,7 @@ static void InitTitle( input_thread_t * p_input, bool had_titles )
     input_thread_private_t *priv = input_priv(p_input);
     input_source_t *p_master = priv->master;
 
-    if( priv->type == INPUT_TYPE_PREPARSING )
+    if( priv->type != INPUT_TYPE_PLAYBACK )
         return;
 
     vlc_mutex_lock( &priv->p_item->lock );
@@ -1361,7 +1359,7 @@ static int Init( input_thread_t * p_input )
         }
     }
 
-    if( priv->type != INPUT_TYPE_PREPARSING && priv->p_sout )
+    if( priv->type == INPUT_TYPE_PLAYBACK && priv->p_sout )
     {
         priv->b_out_pace_control = sout_StreamIsSynchronous(priv->p_sout);
         msg_Dbg( p_input, "starting in %ssync mode",
@@ -2529,9 +2527,9 @@ static demux_t *InputDemuxNew( input_thread_t *p_input, es_out_t *p_es_out,
     vlc_object_t *obj = VLC_OBJECT(p_input);
 
     /* create the underlying access stream */
+    bool preparsing = priv->type == INPUT_TYPE_PREPARSING;
     stream_t *p_stream = stream_AccessNew( obj, p_input, p_es_out,
-                                           priv->type == INPUT_TYPE_PREPARSING,
-                                           url );
+                                           preparsing, url );
     if( p_stream == NULL )
         return NULL;
 
@@ -2566,7 +2564,7 @@ static demux_t *InputDemuxNew( input_thread_t *p_input, es_out_t *p_es_out,
 
     /* create a regular demux with the access stream created */
     demux_t *demux = demux_NewAdvanced( obj, p_input, psz_demux, url, p_stream,
-                                        p_es_out, priv->type == INPUT_TYPE_PREPARSING );
+                                        p_es_out, preparsing );
     if( demux != NULL )
         return demux;
 
@@ -2783,7 +2781,7 @@ static int InputSourceInit( input_source_t *in, input_thread_t *p_input,
 
     /* get attachment
      * FIXME improve for preparsing: move it after GET_META and check psz_arturl */
-    if( input_priv(p_input)->type != INPUT_TYPE_PREPARSING )
+    if( input_priv(p_input)->type == INPUT_TYPE_PLAYBACK )
     {
         if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
                            &in->title, &in->i_title,


=====================================
src/input/input_internal.h
=====================================
@@ -49,7 +49,7 @@ typedef struct input_thread_t
  *****************************************************************************/
 
 enum input_type {
-    INPUT_TYPE_NONE,
+    INPUT_TYPE_PLAYBACK,
     INPUT_TYPE_PREPARSING,
     INPUT_TYPE_THUMBNAILING,
 };
@@ -321,10 +321,20 @@ struct vlc_input_event
     };
 };
 
-typedef void (*input_thread_events_cb)( input_thread_t *input,
-                                        const struct vlc_input_event *event,
-                                        void *userdata);
+struct vlc_input_thread_callbacks
+{
+    void (*on_event)(input_thread_t *input, const struct vlc_input_event *event,
+                     void *userdata);
+};
 
+struct vlc_input_thread_cfg
+{
+    enum input_type type;
+    input_resource_t *resource;
+    vlc_renderer_item_t *renderer;
+    const struct vlc_input_thread_callbacks *cbs;
+    void *cbs_data;
+};
 /**
  * Create a new input_thread_t.
  *
@@ -332,19 +342,13 @@ typedef void (*input_thread_events_cb)( input_thread_t *input,
  * adding callback on the variables/events you want to monitor.
  *
  * \param p_parent a vlc_object
- * \param events_cb the events virtual table
- * \param events_data an opaque given to the events callbacks (\p events_cb)
  * \param p_item an input item
- * \param type the type of task the input is created for (thumbnailing, playback, ...)
- * \param p_resource an optional input ressource
- * \param p_renderer an optional renderer object to render the input to
+ * \param cfg pointer to a configuration struct, mandatory
  * \return a pointer to the spawned input thread
  */
-input_thread_t * input_Create( vlc_object_t *p_parent,
-                               input_thread_events_cb events_cb, void *events_data,
-                               input_item_t *, enum input_type type,
-                               input_resource_t *, vlc_renderer_item_t* p_renderer ) VLC_USED;
-#define input_Create(a,b,c,d,e,f,g) input_Create(VLC_OBJECT(a),b,c,d,e,f,g)
+input_thread_t * input_Create( vlc_object_t *p_parent, input_item_t *item,
+                               const struct vlc_input_thread_cfg *cfg ) VLC_USED;
+#define input_Create(a,b,c) input_Create(VLC_OBJECT(a),b,c)
 
 int input_Start( input_thread_t * );
 
@@ -433,8 +437,8 @@ typedef struct input_thread_private_t
 {
     struct input_thread_t input;
 
-    input_thread_events_cb events_cb;
-    void *events_data;
+    const struct vlc_input_thread_callbacks *cbs;
+    void *cbs_data;
 
     enum input_type type;
 


=====================================
src/input/parse.c
=====================================
@@ -88,19 +88,28 @@ input_item_parser_InputEvent(input_thread_t *input,
 }
 
 input_item_parser_id_t *
-input_item_Parse(input_item_t *item, vlc_object_t *obj,
-                 const input_item_parser_cbs_t *cbs, void *userdata)
+input_item_Parse(vlc_object_t *obj, input_item_t *item,
+                 const struct input_item_parser_cfg *cfg)
 {
-    assert(cbs && cbs->on_ended);
+    assert(cfg != NULL && cfg->cbs != NULL && cfg->cbs->on_ended);
     input_item_parser_id_t *parser = malloc(sizeof(*parser));
     if (!parser)
         return NULL;
 
     parser->state = INIT_S;
-    parser->cbs = cbs;
-    parser->userdata = userdata;
-    parser->input = input_Create(obj, input_item_parser_InputEvent, parser,
-                                 item, INPUT_TYPE_PREPARSING, NULL, NULL);
+    parser->cbs = cfg->cbs;
+    parser->userdata = cfg->cbs_data;
+
+    static const struct vlc_input_thread_callbacks input_cbs = {
+        .on_event = input_item_parser_InputEvent,
+    };
+
+    const struct vlc_input_thread_cfg input_cfg = {
+        .type = INPUT_TYPE_PREPARSING,
+        .cbs = &input_cbs,
+        .cbs_data = parser,
+    };
+    parser->input = input_Create(obj, item, &input_cfg );
     if (!parser->input || input_Start(parser->input))
     {
         if (parser->input)


=====================================
src/input/test/es_out.c
=====================================
@@ -73,7 +73,7 @@ vlc_input_decoder_Create(vlc_object_t *parent, const es_format_t *fmt, const cha
         .clock = clock,
         .resource = p_resource,
         .sout = NULL,
-        .input_type = INPUT_TYPE_NONE,
+        .input_type = INPUT_TYPE_PLAYBACK,
         .cbs = NULL, .cbs_data = NULL,
     };
     return vlc_input_decoder_New(parent, &cfg);
@@ -367,7 +367,7 @@ int main(void)
     input_source_t *source = InputSourceNew();
 
     struct vlc_input_es_out *out =
-        input_EsOutNew(input, source, 1.f, INPUT_TYPE_NONE);
+        input_EsOutNew(input, source, 1.f, INPUT_TYPE_PLAYBACK);
     assert(out != NULL);
 
     es_out_SetMode(out, ES_OUT_MODE_AUTO);


=====================================
src/input/thumbnailer.c
=====================================
@@ -170,9 +170,18 @@ RunnableRun(void *userdata)
 
     vlc_tick_t now = vlc_tick_now();
 
+    static const struct vlc_input_thread_callbacks cbs = {
+        .on_event = on_thumbnailer_input_event,
+    };
+
+    const struct vlc_input_thread_cfg cfg = {
+        .type = INPUT_TYPE_THUMBNAILING,
+        .cbs = &cbs,
+        .cbs_data = task,
+    };
+
     input_thread_t* input =
-            input_Create( thumbnailer->parent, on_thumbnailer_input_event, task,
-                          task->item, INPUT_TYPE_THUMBNAILING, NULL, NULL );
+            input_Create( thumbnailer->parent, task->item, &cfg );
     if (!input)
         goto error;
 


=====================================
src/player/input.c
=====================================
@@ -1136,9 +1136,19 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
     input->ml.pos = -1.f;
     input->ml.has_audio_tracks = input->ml.has_video_tracks = false;
 
-    input->thread = input_Create(player, input_thread_Events, input, item,
-                                 INPUT_TYPE_NONE, player->resource,
-                                 player->renderer);
+    static const struct vlc_input_thread_callbacks cbs = {
+        .on_event = input_thread_Events,
+    };
+
+    const struct vlc_input_thread_cfg cfg = {
+        .type = INPUT_TYPE_PLAYBACK,
+        .resource = player->resource,
+        .renderer = player->renderer,
+        .cbs = &cbs,
+        .cbs_data = input,
+    };
+
+    input->thread = input_Create(player, item, &cfg);
     if (!input->thread)
     {
         free(input);


=====================================
src/preparser/preparser.c
=====================================
@@ -221,7 +221,11 @@ Parse(struct task *task, vlc_tick_t deadline)
     };
 
     vlc_object_t *obj = task->preparser->owner;
-    task->parser = input_item_Parse(task->item, obj, &cbs, task);
+    const struct input_item_parser_cfg cfg = {
+        .cbs = &cbs,
+        .cbs_data = task,
+    };
+    task->parser = input_item_Parse(obj, task->item, &cfg);
     if (!task->parser)
     {
         atomic_store_explicit(&task->preparse_status, ITEM_PREPARSE_FAILED,



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0b2a6f48bd062d9b77164e14d731aa79abed3ae1...8871a103254df1349e369a6cd990e8adf7980667

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0b2a6f48bd062d9b77164e14d731aa79abed3ae1...8871a103254df1349e369a6cd990e8adf7980667
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list