[vlc-commits] [Git][videolan/vlc][master] input_item: category: use a vlc_list

Thomas Guillem (@tguillem) gitlab at videolan.org
Thu Apr 21 12:16:54 UTC 2022



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
80dd05f9 by Thomas Guillem at 2022-04-21T11:59:15+00:00
input_item: category: use a vlc_list

Instead of the legacy array.

- - - - -


7 changed files:

- include/vlc_input_item.h
- modules/control/cli/player.c
- modules/gui/macosx/panels/VLCInformationWindowController.m
- modules/gui/ncurses.c
- modules/gui/qt/dialogs/mediainfo/info_panels.cpp
- modules/lua/libs/input.c
- src/input/item.c


Changes:

=====================================
include/vlc_input_item.h
=====================================
@@ -53,6 +53,7 @@ struct info_category_t
 {
     char   *psz_name;      /**< Name of this category */
     struct vlc_list infos; /**< Infos in the category */
+    struct vlc_list node;  /**< node, to put this category in a list */
 };
 
 /**
@@ -97,8 +98,7 @@ struct input_item_t
     vlc_tick_t i_duration;           /**< Duration in vlc ticks */
 
 
-    int        i_categories;         /**< Number of info categories */
-    info_category_t **pp_categories; /**< Pointer to the first info category */
+    struct vlc_list categories;      /**< List of categories */
 
     int         i_es;                /**< Number of es format descriptions */
     es_format_t **es;                /**< Es formats */


=====================================
modules/control/cli/player.c
=====================================
@@ -508,9 +508,9 @@ static int PlayerItemInfo(struct cli_client *cl, const char *const *args,
     if (item != NULL)
     {
         vlc_mutex_lock(&item->lock);
-        for (int i = 0; i < item->i_categories; i++)
+        info_category_t *category;
+        vlc_list_foreach(category, &item->categories, node)
         {
-            info_category_t *category = item->pp_categories[i];
             info_t *info;
 
             if (info_category_IsHidden(category))


=====================================
modules/gui/macosx/panels/VLCInformationWindowController.m
=====================================
@@ -352,8 +352,8 @@
         // build list of streams
         NSMutableArray *streams = [NSMutableArray array];
 
-        for (int i = 0; i < p_input->i_categories; i++) {
-            info_category_t *cat = p_input->pp_categories[i];
+        info_category_t *cat;
+        vlc_list_foreach(cat, &p_input->categories, node) {
             info_t *info;
 
             if (info_category_IsHidden(cat))


=====================================
modules/gui/ncurses.c
=====================================
@@ -649,8 +649,8 @@ static int DrawInfo(intf_thread_t *intf)
         return 0;
 
     vlc_mutex_lock(&item->lock);
-    for (int i = 0; i < item->i_categories; i++) {
-        info_category_t *p_category = item->pp_categories[i];
+    info_category_t *p_category;
+    vlc_list_foreach(p_category, &item->categories, node) {
         info_t *p_info;
 
         if (info_category_IsHidden(p_category))


=====================================
modules/gui/qt/dialogs/mediainfo/info_panels.cpp
=====================================
@@ -500,15 +500,16 @@ void InfoPanel::update( input_item_t *p_item)
 
     vlc_mutex_locker locker( &p_item->lock );
 
-    for( int i = 0; i< p_item->i_categories ; i++)
+    info_category_t *cat;
+    vlc_list_foreach(cat, &p_item->categories, node)
     {
-        if (info_category_IsHidden(p_item->pp_categories[i]))
+        if (info_category_IsHidden(cat))
             continue;
 
-        struct vlc_list *const head = &p_item->pp_categories[i]->infos;
+        struct vlc_list *const head = &cat->infos;
 
         current_item = new QTreeWidgetItem();
-        current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
+        current_item->setText( 0, qfu(cat->psz_name) );
         InfoTree->addTopLevelItem( current_item );
 
         for (info_t *info = vlc_list_first_entry_or_null(head, info_t, node);


=====================================
modules/lua/libs/input.c
=====================================
@@ -62,13 +62,17 @@ static input_item_t* vlclua_input_item_get_internal( lua_State *L );
 static int vlclua_input_item_info( lua_State *L )
 {
     input_item_t *p_item = vlclua_input_item_get_internal( L );
-    int i_cat;
     int i;
-    i_cat = p_item->i_categories;
+    int i_cat = 0;
+
+    info_category_t *p_category;
+    vlc_list_foreach( p_category, &p_item->categories, node )
+        i_cat++;
+
     lua_createtable( L, 0, i_cat );
-    for( i = 0; i < i_cat; i++ )
+
+    vlc_list_foreach( p_category, &p_item->categories, node )
     {
-        info_category_t *p_category = p_item->pp_categories[i];
         info_t *p_info;
 
         if (info_category_IsHidden(p_category))


=====================================
src/input/item.c
=====================================
@@ -483,9 +483,9 @@ void input_item_Release( input_item_t *p_item )
         vlc_epg_Delete( p_item->pp_epg[i] );
     TAB_CLEAN( p_item->i_epg, p_item->pp_epg );
 
-    for( int i = 0; i < p_item->i_categories; i++ )
-        info_category_Delete( p_item->pp_categories[i] );
-    TAB_CLEAN( p_item->i_categories, p_item->pp_categories );
+    info_category_t *cat;
+    vlc_list_foreach( cat, &p_item->categories, node )
+        info_category_Delete( cat );
 
     for( int i = 0; i < p_item->i_slaves; i++ )
         input_item_slave_Delete( p_item->pp_slaves[i] );
@@ -664,19 +664,17 @@ int input_item_AddSlave(input_item_t *p_item, input_item_slave_t *p_slave)
 }
 
 static info_category_t *InputItemFindCat( input_item_t *p_item,
-                                          int *pi_index, const char *psz_cat )
+                                          const char *psz_cat )
 {
     vlc_mutex_assert( &p_item->lock );
-    for( int i = 0; i < p_item->i_categories && psz_cat; i++ )
-    {
-        info_category_t *p_cat = p_item->pp_categories[i];
+    if( !psz_cat )
+        return NULL;
 
+    info_category_t *p_cat;
+    vlc_list_foreach( p_cat, &p_item->categories, node )
+    {
         if( !strcmp( p_cat->psz_name, psz_cat ) )
-        {
-            if( pi_index )
-                *pi_index = i;
             return p_cat;
-        }
     }
     return NULL;
 }
@@ -697,7 +695,7 @@ char *input_item_GetInfo( input_item_t *p_i,
 {
     vlc_mutex_lock( &p_i->lock );
 
-    const info_category_t *p_cat = InputItemFindCat( p_i, NULL, psz_cat );
+    const info_category_t *p_cat = InputItemFindCat( p_i, psz_cat );
     if( p_cat )
     {
         info_t *p_info = info_category_FindInfo( p_cat, psz_name );
@@ -719,13 +717,13 @@ static int InputItemVaAddInfo( input_item_t *p_i,
 {
     vlc_mutex_assert( &p_i->lock );
 
-    info_category_t *p_cat = InputItemFindCat( p_i, NULL, psz_cat );
+    info_category_t *p_cat = InputItemFindCat( p_i, psz_cat );
     if( !p_cat )
     {
         p_cat = info_category_New( psz_cat );
         if( !p_cat )
             return VLC_ENOMEM;
-        TAB_APPEND(p_i->i_categories, p_i->pp_categories, p_cat);
+        vlc_list_append( &p_cat->node, &p_i->categories );
     }
     info_t *p_info = info_category_VaAddInfo( p_cat, psz_name, psz_format, args );
     if( !p_info || !p_info->psz_value )
@@ -761,8 +759,7 @@ int input_item_DelInfo( input_item_t *p_i,
                         const char *psz_name )
 {
     vlc_mutex_lock( &p_i->lock );
-    int i_cat;
-    info_category_t *p_cat = InputItemFindCat( p_i, &i_cat, psz_cat );
+    info_category_t *p_cat = InputItemFindCat( p_i, psz_cat );
     if( !p_cat )
     {
         vlc_mutex_unlock( &p_i->lock );
@@ -782,8 +779,8 @@ int input_item_DelInfo( input_item_t *p_i,
     else
     {
         /* Remove the complete categorie */
+        vlc_list_remove( &p_cat->node );
         info_category_Delete( p_cat );
-        TAB_ERASE(p_i->i_categories, p_i->pp_categories, i_cat);
     }
     vlc_mutex_unlock( &p_i->lock );
 
@@ -795,15 +792,15 @@ int input_item_DelInfo( input_item_t *p_i,
 void input_item_ReplaceInfos( input_item_t *p_item, info_category_t *p_cat )
 {
     vlc_mutex_lock( &p_item->lock );
-    int i_cat;
-    info_category_t *p_old = InputItemFindCat( p_item, &i_cat, p_cat->psz_name );
+    info_category_t *p_old = InputItemFindCat( p_item, p_cat->psz_name );
     if( p_old )
     {
+        vlc_list_add_after( &p_cat->node, &p_old->node );
+        vlc_list_remove( &p_old->node );
         info_category_Delete( p_old );
-        p_item->pp_categories[i_cat] = p_cat;
     }
     else
-        TAB_APPEND(p_item->i_categories, p_item->pp_categories, p_cat);
+        vlc_list_append( &p_cat->node, &p_item->categories );
     vlc_mutex_unlock( &p_item->lock );
 
     vlc_event_send( &p_item->event_manager,
@@ -813,7 +810,7 @@ void input_item_ReplaceInfos( input_item_t *p_item, info_category_t *p_cat )
 void input_item_MergeInfos( input_item_t *p_item, info_category_t *p_cat )
 {
     vlc_mutex_lock( &p_item->lock );
-    info_category_t *p_old = InputItemFindCat( p_item, NULL, p_cat->psz_name );
+    info_category_t *p_old = InputItemFindCat( p_item, p_cat->psz_name );
     if( p_old )
     {
         info_t *info;
@@ -824,7 +821,7 @@ void input_item_MergeInfos( input_item_t *p_item, info_category_t *p_cat )
         info_category_Delete( p_cat );
     }
     else
-        TAB_APPEND(p_item->i_categories, p_item->pp_categories, p_cat);
+        vlc_list_append( &p_cat->node, &p_item->categories );
     vlc_mutex_unlock( &p_item->lock );
 
     vlc_event_send( &p_item->event_manager,
@@ -1062,7 +1059,7 @@ input_item_NewExt( const char *psz_uri, const char *psz_name,
     p_input->opaques = NULL;
 
     p_input->i_duration = duration;
-    TAB_INIT( p_input->i_categories, p_input->pp_categories );
+    vlc_list_init( &p_input->categories );
     TAB_INIT( p_input->i_es, p_input->es );
     p_input->p_stats = NULL;
     TAB_INIT( p_input->i_epg, p_input->pp_epg );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/80dd05f9215ce2487b9feb431138575e4ca74962

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/80dd05f9215ce2487b9feb431138575e4ca74962
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