[vlc-devel] [PATCH 1/1] Provide file size in the stats from the status.xml (fixes ticket 8345)

Guillaume Gomez guillaume1.gomez at gmail.com
Thu Feb 25 16:29:42 CET 2016


Signed-off-by: Guillaume Gomez <guillaume1.gomez at gmail.com>
---
 include/vlc_input_item.h                |  3 +++
 modules/lua/libs/input.c                |  8 ++++++++
 share/lua/README.txt                    |  1 +
 share/lua/intf/modules/httprequests.lua |  6 ++++++
 src/input/item.c                        | 27 +++++++++++++++++++++++++++
 src/libvlccore.sym                      |  1 +
 6 files changed, 46 insertions(+)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 4391c72..4a71913 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -69,6 +69,8 @@ struct input_item_t
 
     mtime_t    i_duration;           /**< Duration in microseconds */
 
+    size_t     i_file_size;          /**< Size of file in bytes */
+
 
     int        i_categories;         /**< Number of info categories */
     info_category_t **pp_categories; /**< Pointer to the first info category */
@@ -221,6 +223,7 @@ VLC_API mtime_t input_item_GetDuration( input_item_t * p_i );
 VLC_API void input_item_SetDuration( input_item_t * p_i, mtime_t i_duration );
 VLC_API bool input_item_IsPreparsed( input_item_t *p_i );
 VLC_API bool input_item_IsArtFetched( input_item_t *p_i );
+VLC_API size_t input_item_GetFileSize( input_item_t * p_i );
 
 #define INPUT_META( name ) \
 static inline \
diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index be1adf3..9757cbb 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -306,6 +306,13 @@ static int vlclua_input_item_duration( lua_State *L )
     return 1;
 }
 
+static int vlclua_input_item_file_size( lua_State *L )
+{
+    size_t file_size = input_item_GetFileSize( vlclua_input_item_get_internal( L ) );
+    lua_pushinteger( L, file_size );
+    return 1;
+}
+
 static int vlclua_input_item_set_meta( lua_State *L )
 {
     input_item_t *p_item = vlclua_input_item_get_internal( L );
@@ -393,6 +400,7 @@ static const luaL_Reg vlclua_input_item_reg[] = {
     { "duration", vlclua_input_item_duration },
     { "stats", vlclua_input_item_stats },
     { "info", vlclua_input_item_info },
+    { "file_size", vlclua_input_item_file_size },
     { NULL, NULL }
 };
 
diff --git a/share/lua/README.txt b/share/lua/README.txt
index ebe44a3..a8f3f72 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -132,6 +132,7 @@ input.item(): Get the current input item. Input item methods are:
     .send_bitrate
     .played_abuffers
     .lost_abuffers
+    .file_size
 
 Messages
 --------
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index e060cc1..cc41606 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -455,6 +455,12 @@ getstatus = function (includecategories)
     s.version=vlc.misc.version()
     s.volume=vlc.volume.get()
 
+    if item then
+        s.filesize=item:file_size()
+    else
+        s.filesize=0
+    end
+
     if input then
         s.length=math.floor(vlc.var.get(input,"length") / 1000000)
         s.time=math.floor(vlc.var.get(input,"time") / 1000000)
diff --git a/src/input/item.c b/src/input/item.c
index b27beee..83b018c 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -26,6 +26,7 @@
 #endif
 #include <assert.h>
 #include <time.h>
+#include <sys/stat.h>
 
 #include <vlc_common.h>
 #include <vlc_url.h>
@@ -315,6 +316,22 @@ void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
 
     p_i->i_type = GuessType( p_i, &p_i->b_net );
 
+    p_i->i_file_size = 0;
+    if( p_i->i_type == ITEM_TYPE_FILE) {
+        const char *path = strstr(psz_uri, "://");
+
+        if (path != NULL) {
+            struct stat st;
+            const char *clear_path = strdup(path + 3);
+            vlc_uri_decode(clear_path);
+
+            if (stat(clear_path, &st) == 0) {
+                p_i->i_file_size = st.st_size;
+            }
+            free(clear_path);
+        }
+    }
+
     if( p_i->psz_name )
         ;
     else
@@ -368,6 +385,16 @@ void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
     vlc_mutex_unlock( &p_i->lock );
 }
 
+size_t input_item_GetFileSize( input_item_t *p_i )
+{
+    vlc_mutex_lock( &p_i->lock );
+
+    size_t i_file_size = p_i->i_file_size;
+
+    vlc_mutex_unlock( &p_i->lock );
+    return i_file_size;
+}
+
 mtime_t input_item_GetDuration( input_item_t *p_i )
 {
     vlc_mutex_lock( &p_i->lock );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index fa0aa71..34dddb9 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -178,6 +178,7 @@ input_item_Copy
 input_item_CopyOptions
 input_item_DelInfo
 input_item_GetDuration
+input_item_GetFileSize
 input_item_GetInfo
 input_item_GetMeta
 input_item_GetName
-- 
1.9.1



More information about the vlc-devel mailing list