[vlc-commits] [Git][videolan/vlc][master] 3 commits: vlc_input_item: Create the 'input_item_GetInfoLocked' function
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Jul 16 15:23:15 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
a779726a by Benjamin Arnaud at 2022-07-16T14:30:00+00:00
vlc_input_item: Create the 'input_item_GetInfoLocked' function
- - - - -
514aa4af by Benjamin Arnaud at 2022-07-16T14:30:00+00:00
vlc_playlist: Add FILE_SIZE and FILE_MODIFIED sort keys
- - - - -
2d2808c3 by Benjamin Arnaud at 2022-07-16T14:30:00+00:00
playlist/sort: Add FILE_SIZE and FILE_MODIFIED support
Co-authored-by: Pierre Lamot <pierre at videolabs.io>
- - - - -
5 changed files:
- include/vlc_input_item.h
- include/vlc_playlist.h
- src/input/item.c
- src/libvlccore.sym
- src/playlist/sort.c
Changes:
=====================================
include/vlc_input_item.h
=====================================
@@ -340,6 +340,7 @@ INPUT_META(DiscTotal)
#define input_item_GetArtURL input_item_GetArtworkURL
VLC_API char * input_item_GetInfo( input_item_t *p_i, const char *psz_cat,const char *psz_name ) VLC_USED;
+VLC_API char * input_item_GetInfoLocked( input_item_t *p_i, const char *psz_cat,const char *psz_name );
VLC_API int input_item_AddInfo( input_item_t *p_i, const char *psz_cat, const char *psz_name, const char *psz_format, ... ) VLC_FORMAT( 4, 5 );
VLC_API int input_item_DelInfo( input_item_t *p_i, const char *psz_cat, const char *psz_name );
VLC_API void input_item_ReplaceInfos( input_item_t *, info_category_t * );
=====================================
include/vlc_playlist.h
=====================================
@@ -138,6 +138,8 @@ enum vlc_playlist_sort_key
VLC_PLAYLIST_SORT_KEY_DISC_NUMBER,
VLC_PLAYLIST_SORT_KEY_URL,
VLC_PLAYLIST_SORT_KEY_RATING,
+ VLC_PLAYLIST_SORT_KEY_FILE_SIZE,
+ VLC_PLAYLIST_SORT_KEY_FILE_MODIFIED
};
enum vlc_playlist_sort_order
=====================================
src/input/item.c
=====================================
@@ -695,6 +695,19 @@ char *input_item_GetInfo( input_item_t *p_i,
{
vlc_mutex_lock( &p_i->lock );
+ char * result = input_item_GetInfoLocked( p_i, psz_cat, psz_name );
+
+ vlc_mutex_unlock( &p_i->lock );
+
+ return result;
+}
+
+char *input_item_GetInfoLocked( input_item_t *p_i,
+ const char *psz_cat,
+ const char *psz_name )
+{
+ vlc_mutex_assert( &p_i->lock );
+
const info_category_t *p_cat = InputItemFindCat( p_i, psz_cat );
if( p_cat )
{
@@ -702,11 +715,10 @@ char *input_item_GetInfo( input_item_t *p_i,
if( p_info && p_info->psz_value )
{
char *psz_ret = strdup( p_info->psz_value );
- vlc_mutex_unlock( &p_i->lock );
return psz_ret;
}
}
- vlc_mutex_unlock( &p_i->lock );
+
return strdup( "" );
}
=====================================
src/libvlccore.sym
=====================================
@@ -190,6 +190,7 @@ input_item_CreateFilename
input_item_DelInfo
input_item_GetDuration
input_item_GetInfo
+input_item_GetInfoLocked
input_item_GetMeta
input_item_GetMetaLocked
input_item_GetName
=====================================
src/playlist/sort.c
=====================================
@@ -52,6 +52,8 @@ struct vlc_playlist_item_meta {
bool has_track_number;
bool has_disc_number;
bool has_rating;
+ int64_t file_size;
+ int64_t file_modified;
};
static int
@@ -68,6 +70,29 @@ vlc_playlist_item_meta_CopyString(const char **to, const char *from)
return VLC_SUCCESS;
}
+static int
+vlc_playlist_item_meta_GetNumber(const char * str, int64_t * to)
+{
+ // NOTE: When we have an empty string we apply the default value.
+ if (*str == '\0')
+ {
+ *to = 0;
+
+ return VLC_SUCCESS;
+ }
+
+ char *end;
+
+ int64_t value = strtoull(str, &end, 10);
+
+ if (*end != '\0')
+ return VLC_EGENERIC;
+
+ *to = value;
+
+ return VLC_SUCCESS;
+}
+
static int
vlc_playlist_item_meta_InitField(struct vlc_playlist_item_meta *meta,
enum vlc_playlist_sort_key key)
@@ -154,6 +179,32 @@ vlc_playlist_item_meta_InitField(struct vlc_playlist_item_meta *meta,
meta->rating = atoll(str);
return VLC_SUCCESS;
}
+ case VLC_PLAYLIST_SORT_KEY_FILE_SIZE:
+ {
+ char *str = input_item_GetInfoLocked(media, ".stat", "size");
+
+ if (str == NULL)
+ return VLC_EGENERIC;
+
+ int result = vlc_playlist_item_meta_GetNumber(str, &(meta->file_size));
+
+ free(str);
+
+ return result;
+ }
+ case VLC_PLAYLIST_SORT_KEY_FILE_MODIFIED:
+ {
+ char *str = input_item_GetInfoLocked(media, ".stat", "mtime");
+
+ if (str == NULL)
+ return VLC_EGENERIC;
+
+ int result = vlc_playlist_item_meta_GetNumber(str, &(meta->file_modified));
+
+ free(str);
+
+ return result;
+ }
default:
assert(!"Unknown sort key");
vlc_assert_unreachable();
@@ -305,6 +356,10 @@ CompareMetaByKey(const struct vlc_playlist_item_meta *a,
case VLC_PLAYLIST_SORT_KEY_RATING:
return CompareOptionalIntegers(a->has_rating, a->rating,
b->has_rating, b->rating);
+ case VLC_PLAYLIST_SORT_KEY_FILE_SIZE:
+ return CompareIntegers(a->file_size, b->file_size);
+ case VLC_PLAYLIST_SORT_KEY_FILE_MODIFIED:
+ return CompareIntegers(a->file_modified, b->file_modified);
default:
assert(!"Unknown sort key");
vlc_assert_unreachable();
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5d956e61a15ce6ce86b6b2d9424c1aeb766cc41a...2d2808c3424b7fa1797b891bbc635c22f83a499c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5d956e61a15ce6ce86b6b2d9424c1aeb766cc41a...2d2808c3424b7fa1797b891bbc635c22f83a499c
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