[vlc-devel] [PATCH 09/14] medialib: Allow playback preferences to be get/set as batches
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Mon Sep 23 11:44:52 CEST 2019
---
include/vlc_media_library.h | 36 +++++++-
modules/misc/medialibrary/medialib.cpp | 106 +++++++++++++++++++++++
modules/misc/medialibrary/medialibrary.h | 2 +
src/misc/medialibrary.c | 8 ++
4 files changed, 151 insertions(+), 1 deletion(-)
diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index cc9c6b394c..78b44f6538 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -455,6 +455,8 @@ enum vlc_ml_control
VLC_ML_MEDIA_INCREASE_PLAY_COUNT, /**< arg1: media id; can fail */
VLC_ML_MEDIA_GET_MEDIA_PLAYBACK_STATE, /**< arg1: media id; arg2: vlc_ml_playback_state; arg3: char**; */
VLC_ML_MEDIA_SET_MEDIA_PLAYBACK_STATE, /**< arg1: media id; arg2: vlc_ml_playback_state; arg3: const char*; */
+ VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES, /**< arg1: media id; arg2(out): vlc_ml_playback_states_all* */
+ VLC_ML_MEDIA_SET_ALL_MEDIA_PLAYBACK_STATES, /**< arg1: media id; arg2: const vlc_ml_playback_states_all* */
VLC_ML_MEDIA_SET_THUMBNAIL, /**< arg1: media id; arg2: const char*; arg3: vlc_ml_thumbnail_size_t */
VLC_ML_MEDIA_GENERATE_THUMBNAIL, /**< arg1: media id; arg2: vlc_ml_thumbnail_size_t; arg3: width; arg4: height; arg5: position */
VLC_ML_MEDIA_ADD_EXTERNAL_MRL, /**< arg1: media id; arg2: const char*; arg3: type(vlc_ml_file_type_t) */
@@ -493,6 +495,21 @@ enum vlc_ml_playback_state
VLC_ML_PLAYBACK_STATE_APP_SPECIFIC,
};
+typedef struct vlc_ml_playback_states_all
+{
+ float progress;
+ float rate;
+ float zoom;
+ int current_title;
+ int current_video_track;
+ int current_audio_track;
+ int current_subtitle_track;
+ char* aspect_ratio;
+ char* crop;
+ char* deinterlace;
+ char* video_filter;
+} vlc_ml_playback_states_all;
+
enum vlc_ml_event_type
{
/**
@@ -785,6 +802,7 @@ VLC_API void vlc_ml_show_list_release( vlc_ml_show_list_t* p_list );
VLC_API void vlc_ml_genre_list_release( vlc_ml_genre_list_t* p_list );
VLC_API void vlc_ml_playlist_list_release( vlc_ml_playlist_list_t* p_list );
VLC_API void vlc_ml_entry_point_list_release( vlc_ml_entry_point_list_t* p_list );
+VLC_API void vlc_ml_playback_states_all_release( vlc_ml_playback_states_all* prefs );
static inline vlc_ml_query_params_t vlc_ml_query_params_create()
{
@@ -880,6 +898,20 @@ static inline int vlc_ml_media_set_playback_state( vlc_medialibrary_t* p_ml, int
return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_MEDIA_PLAYBACK_STATE, i_media_id, i_state, psz_value );
}
+static inline int vlc_ml_media_get_all_playback_pref( vlc_medialibrary_t* p_ml,
+ int64_t i_media_id,
+ vlc_ml_playback_states_all* prefs )
+{
+ return vlc_ml_control( p_ml,VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES, i_media_id, prefs );
+}
+
+static inline int vlc_ml_media_set_all_playback_states( vlc_medialibrary_t* p_ml,
+ int64_t i_media_id,
+ const vlc_ml_playback_states_all* prefs )
+{
+ return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_ALL_MEDIA_PLAYBACK_STATES, i_media_id, prefs );
+}
+
static inline int vlc_ml_media_set_thumbnail( vlc_medialibrary_t* p_ml, int64_t i_media_id,
const char* psz_mrl, vlc_ml_thumbnail_size_t sizeType )
{
@@ -1353,7 +1385,8 @@ static inline size_t vlc_ml_count_playlist_media( vlc_medialibrary_t* p_ml, cons
vlc_ml_show_list_t*: vlc_ml_show_list_release, \
vlc_ml_genre_list_t*: vlc_ml_genre_list_release, \
vlc_ml_playlist_list_t*: vlc_ml_playlist_list_release, \
- vlc_ml_entry_point_list_t*: vlc_ml_entry_point_list_release \
+ vlc_ml_entry_point_list_t*: vlc_ml_entry_point_list_release, \
+ vlc_ml_playback_states_all*: vlc_ml_playback_states_all_release \
)( OBJ )
#else
static inline void vlc_ml_release( vlc_ml_show_t* show ) { vlc_ml_show_release( show ); }
@@ -1371,6 +1404,7 @@ static inline void vlc_ml_release( vlc_ml_show_list_t* list ) { vlc_ml_show_list
static inline void vlc_ml_release( vlc_ml_genre_list_t* list ) { vlc_ml_genre_list_release( list ); }
static inline void vlc_ml_release( vlc_ml_playlist_list_t* list ) { vlc_ml_playlist_list_release( list ); }
static inline void vlc_ml_release( vlc_ml_entry_point_list_t* list ) { vlc_ml_entry_point_list_release( list ); }
+static inline void vlc_ml_release( vlc_ml_playback_states_all* prefs ) { vlc_ml_playback_states_all_release( prefs ); }
#endif
#endif /* VLC_MEDIA_LIBRARY_H */
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index a10a6acb65..9cf425fdad 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -504,6 +504,8 @@ int MediaLibrary::Control( int query, va_list args )
case VLC_ML_MEDIA_INCREASE_PLAY_COUNT:
case VLC_ML_MEDIA_GET_MEDIA_PLAYBACK_STATE:
case VLC_ML_MEDIA_SET_MEDIA_PLAYBACK_STATE:
+ case VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES:
+ case VLC_ML_MEDIA_SET_ALL_MEDIA_PLAYBACK_STATES:
case VLC_ML_MEDIA_SET_THUMBNAIL:
case VLC_ML_MEDIA_GENERATE_THUMBNAIL:
case VLC_ML_MEDIA_ADD_EXTERNAL_MRL:
@@ -967,6 +969,67 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media, int meta, char** r
return VLC_SUCCESS;
}
+int MediaLibrary::getMeta( const medialibrary::IMedia& media,
+ vlc_ml_playback_states_all* res )
+{
+ auto metas = media.metadata();
+ res->progress = -1.f;
+ res->rate = .0f;
+ res->zoom = -1.f;
+ res->current_title = -1;
+ // For tracks, -1 means disabled, so we can't use it for "unset"
+ res->current_video_track = res->current_audio_track =
+ res->current_subtitle_track = -2;
+ res->aspect_ratio = res->crop = res->deinterlace =
+ res->video_filter = nullptr;
+ for ( const auto& meta : metas )
+ {
+#define COPY_META( field ) res->field = strdup( meta.second.c_str() ); \
+ if ( res->field == nullptr ) return VLC_ENOMEM;
+
+ switch ( meta.first )
+ {
+ case medialibrary::IMedia::MetadataType::Progress:
+ res->progress = atof( meta.second.c_str() );
+ break;
+ case medialibrary::IMedia::MetadataType::Speed:
+ res->rate = atof( meta.second.c_str() );
+ break;
+ case medialibrary::IMedia::MetadataType::Title:
+ res->current_title = atoi( meta.second.c_str() );
+ break;
+ case medialibrary::IMedia::MetadataType::VideoTrack:
+ res->current_video_track = atoi( meta.second.c_str() );
+ break;
+ case medialibrary::IMedia::MetadataType::AspectRatio:
+ COPY_META( aspect_ratio );
+ break;
+ case medialibrary::IMedia::MetadataType::Zoom:
+ res->zoom = atof( meta.second.c_str() );
+ break;
+ case medialibrary::IMedia::MetadataType::Crop:
+ COPY_META( crop );
+ break;
+ case medialibrary::IMedia::MetadataType::Deinterlace:
+ COPY_META( deinterlace );
+ break;
+ case medialibrary::IMedia::MetadataType::VideoFilter:
+ COPY_META( video_filter );
+ break;
+ case medialibrary::IMedia::MetadataType::AudioTrack:
+ res->current_audio_track = atoi( meta.second.c_str() );
+ break;
+ case medialibrary::IMedia::MetadataType::SubtitleTrack:
+ res->current_subtitle_track = atoi( meta.second.c_str() );
+ break;
+ default:
+ break;
+ }
+#undef COPY_META
+ }
+ return VLC_SUCCESS;
+}
+
int MediaLibrary::setMeta( medialibrary::IMedia& media, int meta, const char* value )
{
bool res;
@@ -979,6 +1042,39 @@ int MediaLibrary::setMeta( medialibrary::IMedia& media, int meta, const char* va
return VLC_SUCCESS;
}
+int MediaLibrary::setMeta( medialibrary::IMedia& media,
+ const vlc_ml_playback_states_all* values )
+{
+ using MT = medialibrary::IMedia::MetadataType;
+ std::unordered_map<MT, std::string> metas;
+ if ( values->progress >= .0f )
+ metas[MT::Progress] = std::to_string( values->progress );
+ if ( values->rate != .0f )
+ metas[MT::Speed] = std::to_string( values->rate );
+ if ( values->zoom != .0f )
+ metas[MT::Zoom] = std::to_string( values->zoom );
+ if ( values->current_title >= 0 )
+ metas[MT::Title] = std::to_string( values->current_title );
+ if ( values->aspect_ratio != nullptr )
+ metas[MT::AspectRatio] = values->aspect_ratio;
+ if ( values->crop != nullptr )
+ metas[MT::Crop] = values->crop;
+ if ( values->deinterlace != nullptr )
+ metas[MT::Deinterlace] = values->deinterlace;
+ if ( values->video_filter != nullptr )
+ metas[MT::VideoFilter] = values->video_filter;
+ if ( values->current_video_track != -2 )
+ metas[MT::VideoTrack] = std::to_string( values->current_video_track );
+ if ( values->current_audio_track != -2 )
+ metas[MT::AudioTrack] = std::to_string( values->current_audio_track );
+ if ( values->current_subtitle_track != -2 )
+ metas[MT::SubtitleTrack] = std::to_string( values->current_subtitle_track );
+
+ if ( media.setMetadata( std::move( metas ) ) == false )
+ return VLC_EGENERIC;
+ return VLC_SUCCESS;
+}
+
int MediaLibrary::controlMedia( int query, va_list args )
{
auto mediaId = va_arg( args, int64_t );
@@ -1003,6 +1099,16 @@ int MediaLibrary::controlMedia( int query, va_list args )
auto value = va_arg( args, const char* );
return setMeta( *m, meta, value );
}
+ case VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES:
+ {
+ auto res = va_arg( args, vlc_ml_playback_states_all* );
+ return getMeta( *m, res );
+ }
+ case VLC_ML_MEDIA_SET_ALL_MEDIA_PLAYBACK_STATES:
+ {
+ auto res = va_arg( args, const vlc_ml_playback_states_all* );
+ return setMeta( *m, res );
+ }
case VLC_ML_MEDIA_SET_THUMBNAIL:
{
auto mrl = va_arg( args, const char* );
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index ccab3e0d84..6aa865bca0 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -143,7 +143,9 @@ public:
private:
int controlMedia( int query, va_list args );
int getMeta( const medialibrary::IMedia& media, int meta, char** result );
+ int getMeta( const medialibrary::IMedia& media, vlc_ml_playback_states_all* result );
int setMeta( medialibrary::IMedia& media, int meta, const char* value );
+ int setMeta( medialibrary::IMedia& media, const vlc_ml_playback_states_all* values );
int filterListChildrenQuery( int query, int parentType );
int listAlbums( int listQuery, const medialibrary::QueryParameters* paramsPtr,
const char* pattern, uint32_t nbItems, uint32_t offset, va_list args );
diff --git a/src/misc/medialibrary.c b/src/misc/medialibrary.c
index f100f29b81..b1ce7907f3 100644
--- a/src/misc/medialibrary.c
+++ b/src/misc/medialibrary.c
@@ -339,6 +339,14 @@ void vlc_ml_entry_point_list_release( vlc_ml_entry_point_list_t* p_list )
free( p_list );
}
+void vlc_ml_playback_states_all_release( vlc_ml_playback_states_all* prefs )
+{
+ free( prefs->aspect_ratio );
+ free( prefs->crop );
+ free( prefs->deinterlace );
+ free( prefs->video_filter );
+}
+
void* vlc_ml_get( vlc_medialibrary_t* p_ml, int i_query, ... )
{
assert( p_ml != NULL );
--
2.20.1
More information about the vlc-devel
mailing list