Merge pull request #2789 from univrsal/vlc-metadata-procs

vlc-video: Add procedure to receive media metadata
master
Jim 2020-05-03 12:29:59 -07:00 committed by GitHub
commit 7b3cf354b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 0 deletions

View File

@ -24,6 +24,7 @@ LIBVLC_MEDIA_NEW_LOCATION libvlc_media_new_location_;
LIBVLC_MEDIA_ADD_OPTION libvlc_media_add_option_;
LIBVLC_MEDIA_RELEASE libvlc_media_release_;
LIBVLC_MEDIA_RELEASE libvlc_media_retain_;
LIBVLC_MEDIA_GET_META libvlc_media_get_meta_;
/* libvlc media player */
LIBVLC_MEDIA_PLAYER_NEW libvlc_media_player_new_;
@ -41,6 +42,7 @@ LIBVLC_VIDEO_GET_SIZE libvlc_video_get_size_;
LIBVLC_MEDIA_PLAYER_EVENT_MANAGER libvlc_media_player_event_manager_;
LIBVLC_MEDIA_PLAYER_GET_STATE libvlc_media_player_get_state_;
LIBVLC_MEDIA_PLAYER_GET_LENGTH libvlc_media_player_get_length_;
LIBVLC_MEDIA_PLAYER_GET_MEDIA libvlc_media_player_get_media_;
/* libvlc media list */
LIBVLC_MEDIA_LIST_NEW libvlc_media_list_new_;
@ -99,6 +101,7 @@ static bool load_vlc_funcs(void)
LOAD_VLC_FUNC(libvlc_media_add_option);
LOAD_VLC_FUNC(libvlc_media_release);
LOAD_VLC_FUNC(libvlc_media_retain);
LOAD_VLC_FUNC(libvlc_media_get_meta);
/* libvlc media player */
LOAD_VLC_FUNC(libvlc_media_player_new);
@ -116,6 +119,7 @@ static bool load_vlc_funcs(void)
LOAD_VLC_FUNC(libvlc_media_player_event_manager);
LOAD_VLC_FUNC(libvlc_media_player_get_state);
LOAD_VLC_FUNC(libvlc_media_player_get_length);
LOAD_VLC_FUNC(libvlc_media_player_get_media);
/* libvlc media list */
LOAD_VLC_FUNC(libvlc_media_list_new);

View File

@ -35,6 +35,8 @@ typedef void (*LIBVLC_MEDIA_ADD_OPTION)(libvlc_media_t *p_md,
const char *options);
typedef void (*LIBVLC_MEDIA_RETAIN)(libvlc_media_t *p_md);
typedef void (*LIBVLC_MEDIA_RELEASE)(libvlc_media_t *p_md);
typedef char *(*LIBVLC_MEDIA_GET_META)(libvlc_media_t *p_md,
libvlc_meta_t e_meta);
/* libvlc media player */
typedef libvlc_media_player_t *(*LIBVLC_MEDIA_PLAYER_NEW)(
@ -71,6 +73,8 @@ typedef libvlc_state_t (*LIBVLC_MEDIA_PLAYER_GET_STATE)(
libvlc_media_player_t *p_mi);
typedef libvlc_time_t (*LIBVLC_MEDIA_PLAYER_GET_LENGTH)(
libvlc_media_player_t *p_mi);
typedef libvlc_media_t *(*LIBVLC_MEDIA_PLAYER_GET_MEDIA)(
libvlc_media_player_t *p_mi);
/* libvlc media list */
typedef libvlc_media_list_t *(*LIBVLC_MEDIA_LIST_NEW)(
@ -118,6 +122,7 @@ extern LIBVLC_MEDIA_NEW_LOCATION libvlc_media_new_location_;
extern LIBVLC_MEDIA_ADD_OPTION libvlc_media_add_option_;
extern LIBVLC_MEDIA_RELEASE libvlc_media_release_;
extern LIBVLC_MEDIA_RETAIN libvlc_media_retain_;
extern LIBVLC_MEDIA_GET_META libvlc_media_get_meta_;
/* libvlc media player */
extern LIBVLC_MEDIA_PLAYER_NEW libvlc_media_player_new_;
@ -135,6 +140,7 @@ extern LIBVLC_VIDEO_GET_SIZE libvlc_video_get_size_;
extern LIBVLC_MEDIA_PLAYER_EVENT_MANAGER libvlc_media_player_event_manager_;
extern LIBVLC_MEDIA_PLAYER_GET_STATE libvlc_media_player_get_state_;
extern LIBVLC_MEDIA_PLAYER_GET_LENGTH libvlc_media_player_get_length_;
extern LIBVLC_MEDIA_PLAYER_GET_MEDIA libvlc_media_player_get_media_;
/* libvlc media list */
extern LIBVLC_MEDIA_LIST_NEW libvlc_media_list_new_;

View File

@ -276,6 +276,61 @@ static enum audio_format convert_vlc_audio_format(char *format)
/* ------------------------------------------------------------------------- */
static void vlcs_get_metadata(void *data, calldata_t *cd)
{
struct vlc_source *vlcs = data;
const char *data_id = calldata_string(cd, "tag_id");
if (!vlcs || !data_id)
return;
libvlc_media_t *media =
libvlc_media_player_get_media_(vlcs->media_player);
if (!media)
return;
#define VLC_META(media, cd, did, tid, tag) \
else if (strcmp(did, tid) == 0) \
{ \
calldata_set_string(cd, "tag_data", \
libvlc_media_get_meta_(media, tag)); \
}
if (strcmp(data_id, "title") == 0)
calldata_set_string(cd, "tag_data",
libvlc_media_get_meta_(media,
libvlc_meta_Title));
VLC_META(media, cd, data_id, "artist", libvlc_meta_Artist)
VLC_META(media, cd, data_id, "genre", libvlc_meta_Genre)
VLC_META(media, cd, data_id, "copyright", libvlc_meta_Copyright)
VLC_META(media, cd, data_id, "album", libvlc_meta_Album)
VLC_META(media, cd, data_id, "track_number", libvlc_meta_TrackNumber)
VLC_META(media, cd, data_id, "description", libvlc_meta_Description)
VLC_META(media, cd, data_id, "rating", libvlc_meta_Rating)
VLC_META(media, cd, data_id, "date", libvlc_meta_Date)
VLC_META(media, cd, data_id, "setting", libvlc_meta_Setting)
VLC_META(media, cd, data_id, "url", libvlc_meta_URL)
VLC_META(media, cd, data_id, "language", libvlc_meta_Language)
VLC_META(media, cd, data_id, "now_playing", libvlc_meta_NowPlaying)
VLC_META(media, cd, data_id, "publisher", libvlc_meta_Publisher)
VLC_META(media, cd, data_id, "encoded_by", libvlc_meta_EncodedBy)
VLC_META(media, cd, data_id, "artwork_url", libvlc_meta_ArtworkURL)
VLC_META(media, cd, data_id, "track_id", libvlc_meta_TrackID)
VLC_META(media, cd, data_id, "track_total", libvlc_meta_TrackTotal)
VLC_META(media, cd, data_id, "director", libvlc_meta_Director)
VLC_META(media, cd, data_id, "season", libvlc_meta_Season)
VLC_META(media, cd, data_id, "episode", libvlc_meta_Episode)
VLC_META(media, cd, data_id, "show_name", libvlc_meta_ShowName)
VLC_META(media, cd, data_id, "actors", libvlc_meta_Actors)
VLC_META(media, cd, data_id, "album_artist", libvlc_meta_AlbumArtist)
VLC_META(media, cd, data_id, "disc_number", libvlc_meta_DiscNumber)
VLC_META(media, cd, data_id, "disc_total", libvlc_meta_DiscTotal)
#undef VLC_META
}
/* ------------------------------------------------------------------------- */
static const char *vlcs_get_name(void *unused)
{
UNUSED_PARAMETER(unused);
@ -895,6 +950,11 @@ static void *vlcs_create(obs_data_t *settings, obs_source_t *source)
libvlc_event_attach_(event_manager, libvlc_MediaPlayerOpening,
vlcs_started, c);
proc_handler_t *ph = obs_source_get_proc_handler(source);
proc_handler_add(
ph, "void get_metadata(in string tag_id out string tag_data)",
vlcs_get_metadata, c);
obs_source_update(source, NULL);
UNUSED_PARAMETER(settings);