[vlc-commits] [Git][videolan/vlc][master] 17 commits: input_item: add info_category_IsHidden

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Dec 10 09:12:42 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
179bba83 by Thomas Guillem at 2021-12-10T08:53:41+00:00
input_item: add info_category_IsHidden

- - - - -
40a3b66f by Thomas Guillem at 2021-12-10T08:53:41+00:00
lua: don't show hidden info categories

- - - - -
0cf0618c by Thomas Guillem at 2021-12-10T08:53:41+00:00
qt: don't show hidden info categories

- - - - -
4a4efdf5 by Thomas Guillem at 2021-12-10T08:53:41+00:00
ncurses: don't show hidden info categories

- - - - -
e2f291c8 by Thomas Guillem at 2021-12-10T08:53:41+00:00
macos: don't show hidden info categories

- - - - -
46f4ab44 by Thomas Guillem at 2021-12-10T08:53:41+00:00
cli: don't show hidden info categories

- - - - -
97a09be7 by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
item: add created_item field in vlc_readdir_helper_additem function

In the access modules, we would like to be able to send file properties such as size directly
to the input item. But no reference to this item is accessible.
This field will allow you to retrieve the item created by the function.

- - - - -
b9a43f1a by Thomas Guillem at 2021-12-10T08:53:41+00:00
input_item: add input_item_AddStat

An helper to add a ".stat" info as uint64_t.

- - - - -
8a3e1481 by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
smb2: get mtime and the size of the item

Get the mtime, ctime, atime and the size of the items scaned from "DirRead", and save in
the item struct.

Refs #25747

- - - - -
58b8582d by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
nfs: get mtime and the size of the item

Refs #25747

- - - - -
7190daf3 by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
sftp: get mtime and the size of the item

Refs #25747

- - - - -
b61aab5f by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
directory: get mtime and size of the item

Refs #25747

- - - - -
aebc87bf by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
dsm: get mtime and size for the item

Refs #25747

- - - - -
bd8183e3 by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
samba: get mtime and size of the item

Refs #25747

- - - - -
bcc79fbf by LE QUEC Nicolas at 2021-12-10T08:53:41+00:00
archive: get mtime and size of the item

Refs #25747

- - - - -
c9ab8bd8 by Thomas Guillem at 2021-12-10T08:53:41+00:00
libvlc: add libvlc_media_get_stat

This new function can be used to retrieve the mtime, ctime, atime and
size properties. More properties can be added in the future without
modifying this function.

Co-authored-by: LE QUEC Nicolas <Nicolas.Le_Quec at bordeaux-inp.fr>

Fixes #25747

- - - - -
21d27d8e by Thomas Guillem at 2021-12-10T08:53:41+00:00
test: media: test libvlc_media_get_stat()

- - - - -


20 changed files:

- include/vlc/libvlc_media.h
- include/vlc_input_item.h
- lib/libvlc.sym
- lib/media.c
- modules/access/directory.c
- modules/access/dsm/access.c
- modules/access/ftp.c
- modules/access/nfs.c
- modules/access/samba.c
- modules/access/sftp.c
- modules/access/smb2.c
- modules/access/unc.c
- 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
- modules/stream_extractor/archive.c
- src/input/item.c
- test/libvlc/media.c


Changes:

=====================================
include/vlc/libvlc_media.h
=====================================
@@ -211,6 +211,12 @@ typedef struct libvlc_media_slave_t
     unsigned int                    i_priority;
 } libvlc_media_slave_t;
 
+/**
+ * Type of stat that can be requested from libvlc_media_get_stat()
+ */
+#define libvlc_media_stat_mtime 0
+#define libvlc_media_stat_size 1
+
 /**
  * Callback prototype to open a custom bitstream input media.
  *
@@ -560,6 +566,22 @@ LIBVLC_API libvlc_event_manager_t *
 LIBVLC_API libvlc_time_t
    libvlc_media_get_duration( libvlc_media_t *p_md );
 
+/**
+ * Get a 'stat' value of media descriptor object item.
+ *
+ * \note 'stat' values are currently only parsed by directory accesses. This
+ * mean that only sub medias of a directory media, parsed with
+ * libvlc_media_parse_with_options() can have valid 'stat' properties.
+ * \version LibVLC 4.0.0 and later.
+ *
+ * \param p_md media descriptor object
+ * \param type a valid libvlc_media_stat_ define
+ * \param out field in which the value will be stored
+ * \return 1 on success, 0 if not found, -1 on error.
+ */
+LIBVLC_API int
+   libvlc_media_get_stat( libvlc_media_t *p_md, unsigned type, uint64_t *out );
+
 /**
  * Parse the media asynchronously with options.
  *


=====================================
include/vlc_input_item.h
=====================================
@@ -55,6 +55,16 @@ struct info_category_t
     struct vlc_list infos; /**< Infos in the category */
 };
 
+/**
+ * Returns true if the category is hidden
+ *
+ * Infos from hidden categories should not be displayed directly by UI modules.
+ */
+static inline bool info_category_IsHidden(info_category_t *cat)
+{
+    return cat->psz_name[0] == '.';
+}
+
 enum input_item_type_e
 {
     ITEM_TYPE_UNKNOWN,
@@ -335,6 +345,9 @@ VLC_API int input_item_DelInfo( input_item_t *p_i, const char *psz_cat, const ch
 VLC_API void input_item_ReplaceInfos( input_item_t *, info_category_t * );
 VLC_API void input_item_MergeInfos( input_item_t *, info_category_t * );
 
+#define input_item_AddStat(item, type, value) \
+    input_item_AddInfo(item, ".stat", type, "%" PRIu64, (uint64_t) value)
+
 /**
  * This function creates a new input_item_t with the provided information.
  *
@@ -582,10 +595,14 @@ VLC_API void vlc_readdir_helper_finish(struct vlc_readdir_helper *p_rdh, bool b_
  *        be valid.
  * \param i_type see \ref input_item_type_e
  * \param i_net see \ref input_item_net_type
+ * \param[out] created_item if an input item is created. The item should not be
+ * released and is valid until vlc_readdir_helper_finish() is called.
+ * \param status VLC_SUCCESS in case of success, an error otherwise. Parsing
+ * should be aborted in case of error.
  */
 VLC_API int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
                                        const char *psz_uri, const char *psz_flatpath,
                                        const char *psz_filename,
-                                       int i_type, int i_net);
+                                       int i_type, int i_net, input_item_t **created_item);
 
 #endif


=====================================
lib/libvlc.sym
=====================================
@@ -73,6 +73,7 @@ libvlc_media_duplicate
 libvlc_media_event_manager
 libvlc_media_get_codec_description
 libvlc_media_get_duration
+libvlc_media_get_stat
 libvlc_media_get_meta
 libvlc_media_get_mrl
 libvlc_media_get_state


=====================================
lib/media.c
=====================================
@@ -838,6 +838,43 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
     return from_mtime(input_item_GetDuration( p_md->p_input_item ));
 }
 
+int
+libvlc_media_get_stat( libvlc_media_t *p_md, unsigned type, uint64_t *out )
+{
+    assert( p_md );
+    assert( out );
+
+    if( !p_md->p_input_item )
+    {
+        libvlc_printerr( "No input item" );
+        return -1;
+    }
+
+    const char *name;
+    switch (type)
+    {
+        case libvlc_media_stat_mtime:   name = "mtime"; break;
+        case libvlc_media_stat_size:    name = "size"; break;
+        default:
+            libvlc_printerr( "unknown libvlc_media_stat" );
+            return -1;
+    };
+
+    char *str = input_item_GetInfo( p_md->p_input_item, ".stat", name );
+    if( str == NULL )
+        return 0;
+
+    char *end;
+    unsigned long long val = strtoull( str, &end, 10 );
+    free( str );
+
+    if( *end != '\0' )
+        return -1;
+
+    *out = val;
+    return 1;
+}
+
 static const input_preparser_callbacks_t input_preparser_callbacks = {
     .on_preparse_ended = input_item_preparse_ended,
     .on_subtree_added = input_item_subtree_added,


=====================================
modules/access/directory.c
=====================================
@@ -207,8 +207,15 @@ static int DirRead (stream_t *access, input_item_node_t *node)
             ret = VLC_ENOMEM;
             break;
         }
+        input_item_t *p_item;
         ret = vlc_readdir_helper_additem(&rdh, uri, NULL, entry, type,
-                                         ITEM_NET_UNKNOWN);
+                                         ITEM_NET_UNKNOWN, &p_item);
+
+        if (ret == VLC_SUCCESS && p_item && st.st_mtime >= 0 && st.st_size >= 0)
+        {
+            input_item_AddStat( p_item, "mtime", st.st_mtime );
+            input_item_AddStat( p_item, "size", st.st_size );
+        }
         free(uri);
     }
 


=====================================
modules/access/dsm/access.c
=====================================
@@ -118,7 +118,7 @@ static int get_address( stream_t *p_access );
 static int login( stream_t *p_access );
 static bool get_path( stream_t *p_access );
 static int add_item( stream_t *p_access,  struct vlc_readdir_helper *p_rdh,
-                     const char *psz_name, int i_type );
+                     const char *psz_name, int i_type, smb_stat *p_st );
 
 typedef struct
 {
@@ -576,7 +576,7 @@ static int Control( stream_t *p_access, int i_query, va_list args )
 }
 
 static int add_item( stream_t *p_access, struct vlc_readdir_helper *p_rdh,
-                     const char *psz_name, int i_type )
+                     const char *psz_name, int i_type, smb_stat *p_st )
 {
     char         *psz_uri;
     int           i_ret;
@@ -593,8 +593,14 @@ static int add_item( stream_t *p_access, struct vlc_readdir_helper *p_rdh,
     if( i_ret == -1 )
         return VLC_ENOMEM;
 
+    input_item_t *p_item;
     i_ret = vlc_readdir_helper_additem( p_rdh, psz_uri, NULL, psz_name, i_type,
-                                        ITEM_NET );
+                                        ITEM_NET, &p_item );
+    if ( i_ret == VLC_SUCCESS && p_item && p_st )
+    {
+        input_item_AddStat( p_item, "mtime", smb_stat_get( *p_st, SMB_STAT_MTIME ));
+        input_item_AddStat( p_item, "size", smb_stat_get( *p_st, SMB_STAT_SIZE ));
+    }
     free( psz_uri );
     return i_ret;
 }
@@ -621,7 +627,7 @@ static int BrowseShare( stream_t *p_access, input_item_node_t *p_node )
         if( psz_name[strlen( psz_name ) - 1] == '$')
             continue;
 
-        i_ret = add_item( p_access, &rdh, psz_name, ITEM_TYPE_DIRECTORY );
+        i_ret = add_item( p_access, &rdh, psz_name, ITEM_TYPE_DIRECTORY, NULL );
     }
 
     vlc_readdir_helper_finish( &rdh, i_ret == VLC_SUCCESS );
@@ -672,7 +678,7 @@ static int BrowseDirectory( stream_t *p_access, input_item_node_t *p_node )
 
         i_type = smb_stat_get( st, SMB_STAT_ISDIR ) ?
                  ITEM_TYPE_DIRECTORY : ITEM_TYPE_FILE;
-        i_ret = add_item( p_access, &rdh, psz_name, i_type );
+        i_ret = add_item( p_access, &rdh, psz_name, i_type, &st );
     }
 
     vlc_readdir_helper_finish( &rdh, i_ret == VLC_SUCCESS );


=====================================
modules/access/ftp.c
=====================================
@@ -999,7 +999,7 @@ static int DirRead (stream_t *p_access, input_item_node_t *p_current_node)
             msg_Err(p_access, "%s -> %s", p_sys->url.psz_path, ms.ptr);
 
             i_ret = vlc_readdir_helper_additem( &rdh, ms.ptr, NULL, psz_file,
-                                                type, ITEM_NET );
+                                                type, ITEM_NET, NULL );
             free(ms.ptr);
         }
         free( psz_line );


=====================================
modules/access/nfs.c
=====================================
@@ -363,8 +363,16 @@ DirRead(stream_t *p_access, input_item_node_t *p_node)
         default:
             i_type = ITEM_TYPE_UNKNOWN;
         }
+
+        input_item_t *p_item;
+
         i_ret = vlc_readdir_helper_additem(&rdh, psz_url, NULL, p_nfsdirent->name,
-                                           i_type, ITEM_NET);
+                                           i_type, ITEM_NET, &p_item);
+        if (i_ret == VLC_SUCCESS && p_item && p_nfsdirent->mtime.tv_sec >= 0)
+        {
+            input_item_AddStat(p_item, "mtime", p_nfsdirent->mtime.tv_sec);
+            input_item_AddStat(p_item, "size", p_nfsdirent->size);
+        }
         free(psz_url);
     }
 
@@ -394,7 +402,7 @@ MountRead(stream_t *p_access, input_item_node_t *p_node)
             break;
         }
         i_ret = vlc_readdir_helper_additem(&rdh, psz_url, NULL, psz_name,
-                                            ITEM_TYPE_DIRECTORY, ITEM_NET);
+                                            ITEM_TYPE_DIRECTORY, ITEM_NET, NULL);
         free(psz_url);
     }
 


=====================================
modules/access/samba.c
=====================================
@@ -169,9 +169,18 @@ static int DirRead (stream_t *p_access, input_item_node_t *p_node )
             i_ret = VLC_ENOMEM;
             break;
         }
+        struct stat st;
+        smbc_stat(uri, &st);
+
+        input_item_t *p_item;
         free(psz_encoded_name);
         i_ret = vlc_readdir_helper_additem(&rdh, uri, NULL, p_entry->name,
-                                           i_type, ITEM_NET);
+                                           i_type, ITEM_NET, &p_item);
+        if (i_ret == VLC_SUCCESS && p_item)
+        {
+            input_item_AddStat( p_item, "mtime", st.st_mtime );
+            input_item_AddStat( p_item, "size", st.st_size );
+        }
         free(uri);
     }
 


=====================================
modules/access/sftp.c
=====================================
@@ -670,8 +670,15 @@ static int DirRead (stream_t *p_access, input_item_node_t *p_current_node)
         free( psz_uri );
 
         int i_type = LIBSSH2_SFTP_S_ISDIR( attrs.permissions ) ? ITEM_TYPE_DIRECTORY : ITEM_TYPE_FILE;
+
+        input_item_t *p_item;
         i_ret = vlc_readdir_helper_additem( &rdh, psz_full_uri, NULL, psz_file,
-                                            i_type, ITEM_NET );
+                                            i_type, ITEM_NET, &p_item );
+        if (i_ret == VLC_SUCCESS && p_item)
+        {
+            input_item_AddStat(p_item, "mtime", attrs.mtime);
+            input_item_AddStat(p_item, "size", attrs.filesize);
+        }
         free( psz_full_uri );
     }
 


=====================================
modules/access/smb2.c
=====================================
@@ -374,7 +374,7 @@ vlc_smb2_get_url(vlc_url_t *url, const char *file)
 }
 
 static int AddItem(stream_t *access, struct vlc_readdir_helper *rdh,
-                   const char *name, int i_type)
+                   const char* name, int i_type, struct smb2_stat_64 *stats)
 {
     struct access_sys *sys = access->p_sys;
     char *name_encoded = vlc_uri_encode(name);
@@ -386,8 +386,15 @@ static int AddItem(stream_t *access, struct vlc_readdir_helper *rdh,
     if (url == NULL)
         return VLC_ENOMEM;
 
+    input_item_t *p_item; 
     int ret = vlc_readdir_helper_additem(rdh, url, NULL, name, i_type,
-                                         ITEM_NET);
+                                         ITEM_NET, &p_item);
+
+    if (ret == VLC_SUCCESS && p_item && stats)
+    {
+        input_item_AddStat( p_item, "mtime", stats->smb2_mtime);
+        input_item_AddStat( p_item, "size", stats->smb2_size);
+    }
     free(url);
     return ret;
 }
@@ -419,7 +426,7 @@ DirRead(stream_t *access, input_item_node_t *p_node)
             i_type = ITEM_TYPE_UNKNOWN;
             break;
         }
-        ret = AddItem(access, &rdh, smb2dirent->name, i_type);
+        ret = AddItem(access, &rdh, smb2dirent->name, i_type, &smb2dirent->st);
     }
 
     vlc_readdir_helper_finish(&rdh, ret == VLC_SUCCESS);
@@ -447,7 +454,7 @@ ShareEnum(stream_t *access, input_item_node_t *p_node)
        switch (info->type & 0x3)
        {
            case SHARE_TYPE_DISKTREE:
-               ret = AddItem(access, &rdh, info->name, ITEM_TYPE_DIRECTORY);
+               ret = AddItem(access, &rdh, info->name, ITEM_TYPE_DIRECTORY, NULL);
                break;
        }
     }


=====================================
modules/access/unc.c
=====================================
@@ -212,7 +212,7 @@ static int DirRead(stream_t *p_access, input_item_node_t *p_node)
                 free( psz_path );
 
                 i_ret = vlc_readdir_helper_additem( &rdh, psz_uri, NULL,
-                                    psz_name, ITEM_TYPE_DIRECTORY, ITEM_NET );
+                                    psz_name, ITEM_TYPE_DIRECTORY, ITEM_NET, NULL );
                 free( psz_name );
                 free( psz_uri );
             }


=====================================
modules/control/cli/player.c
=====================================
@@ -513,6 +513,9 @@ static int PlayerItemInfo(struct cli_client *cl, const char *const *args,
             info_category_t *category = item->pp_categories[i];
             info_t *info;
 
+            if (info_category_IsHidden(category))
+                continue;
+
             cli_printf(cl, "+----[ %s ]", category->psz_name);
             cli_printf(cl, "| ");
             info_foreach(info, &category->infos)


=====================================
modules/gui/macosx/panels/VLCInformationWindowController.m
=====================================
@@ -356,6 +356,9 @@
             info_category_t *cat = p_input->pp_categories[i];
             info_t *info;
 
+            if (info_category_IsHidden(cat))
+                continue;
+
             VLCCodecInformationTreeItem *subItem = [[VLCCodecInformationTreeItem alloc] init];
             subItem.propertyName = toNSStr(cat->psz_name);
 


=====================================
modules/gui/ncurses.c
=====================================
@@ -654,6 +654,9 @@ static int DrawInfo(intf_thread_t *intf)
         info_category_t *p_category = item->pp_categories[i];
         info_t *p_info;
 
+        if (info_category_IsHidden(p_category))
+            continue;
+
         if (sys->color) color_set(C_CATEGORY, NULL);
         MainBoxWrite(sys, l++, _("  [%s]"), p_category->psz_name);
         if (sys->color) color_set(C_DEFAULT, NULL);


=====================================
modules/gui/qt/dialogs/mediainfo/info_panels.cpp
=====================================
@@ -502,6 +502,9 @@ void InfoPanel::update( input_item_t *p_item)
 
     for( int i = 0; i< p_item->i_categories ; i++)
     {
+        if (info_category_IsHidden(p_item->pp_categories[i]))
+            continue;
+
         struct vlc_list *const head = &p_item->pp_categories[i]->infos;
 
         current_item = new QTreeWidgetItem();


=====================================
modules/lua/libs/input.c
=====================================
@@ -71,6 +71,9 @@ static int vlclua_input_item_info( lua_State *L )
         info_category_t *p_category = p_item->pp_categories[i];
         info_t *p_info;
 
+        if (info_category_IsHidden(p_category))
+            continue;
+
         lua_pushstring( L, p_category->psz_name );
         lua_newtable( L );
         info_foreach(p_info, &p_category->infos)


=====================================
modules/stream_extractor/archive.c
=====================================
@@ -547,12 +547,23 @@ static int ReadDir( stream_directory_t* p_directory, input_item_node_t* p_node )
         if( unlikely( !mrl ) )
             break;
 
+        input_item_t *p_item;
         if( vlc_readdir_helper_additem( &rdh, mrl, path, NULL, ITEM_TYPE_FILE,
-                                        ITEM_LOCAL ) )
+                                        ITEM_LOCAL, &p_item ) )
         {
             free( mrl );
             break;
         }
+        if ( p_item )
+        {
+            time_t mtime = archive_entry_mtime( entry );
+            if( mtime >= 0 )
+                input_item_AddStat( p_item, "mtime", mtime );
+
+            int64_t size = archive_entry_size( entry );
+            if( size >= 0 )
+                input_item_AddStat( p_item, "size", size );
+        }
         free( mrl );
 
         if( archive_read_data_skip( p_arc ) )


=====================================
src/input/item.c
=====================================
@@ -1823,7 +1823,8 @@ void vlc_readdir_helper_finish(struct vlc_readdir_helper *p_rdh, bool b_success)
 
 int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
                                const char *psz_uri, const char *psz_flatpath,
-                               const char *psz_filename, int i_type, int i_net)
+                               const char *psz_filename, int i_type, int i_net,
+                               input_item_t **restrict created_item)
 {
     enum slave_type i_slave_type;
     struct rdh_slave *p_rdh_slave = NULL;
@@ -1869,7 +1870,11 @@ int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
     }
 
     if (rdh_file_is_ignored(p_rdh, psz_filename))
+    {
+        if (created_item != NULL)
+            *created_item = NULL;
         return VLC_SUCCESS;
+    }
 
     input_item_node_t *p_node = p_rdh->p_node;
 
@@ -1896,5 +1901,8 @@ int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
      * slaves will be ignored by rdh_file_is_ignored() */
     if (p_rdh_slave != NULL)
         p_rdh_slave->p_node = p_node;
+
+    if (created_item != NULL)
+        *created_item = p_item;
     return VLC_SUCCESS;
 }


=====================================
test/libvlc/media.c
=====================================
@@ -238,6 +238,21 @@ static void subitem_added(const libvlc_event_t *event, void *user_data)
             assert (!subitems_found[i]);
             assert (libvlc_media_get_type(m) == test_media_subitems_list[i].type);
             subitems_found[i] = true;
+
+            uint64_t value;
+            int ret;
+
+            ret = libvlc_media_get_stat(m, libvlc_media_stat_size, &value);
+            assert(ret == 1);
+            /* All files size are 0, directory size is either 4096 or 0 */
+            if (libvlc_media_get_type(m) == libvlc_media_type_directory)
+                assert(value == 4096 || value == 0);
+            else
+                assert(value == 0);
+
+            ret = libvlc_media_get_stat(m, libvlc_media_stat_mtime, &value);
+            /* Epoch timestamp of the commit that added test/samples/subitems */
+            assert(ret == 1 && value >= 1446796477);
         }
     }
     free (mrl);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/65d5911a1b3d166dd22c832db428a339e7ea1336...21d27d8ec9aa9a858dc4c0f7bed4d37df07a026e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/65d5911a1b3d166dd22c832db428a339e7ea1336...21d27d8ec9aa9a858dc4c0f7bed4d37df07a026e
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list