From c5362c72da7dcd82e061bbd2e9242a9cd3a86229 Mon Sep 17 00:00:00 2001 From: albeu Date: Tue, 29 May 2007 22:14:41 +0000 Subject: Make all the info available via the metadata API available via properties. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@23412 b3059339-0415-0410-9bf9-f77b7e298cf2 --- command.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- m_property.c | 12 ++++++++ m_property.h | 3 ++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/command.c b/command.c index fd9e8b0811..dc2f5b5cbc 100644 --- a/command.c +++ b/command.c @@ -8,6 +8,7 @@ #include "stream/stream.h" #include "libmpdemux/demuxer.h" #include "libmpdemux/stheader.h" +#include "codec-cfg.h" #include "mplayer.h" #include "libvo/sub.h" #include "m_option.h" @@ -306,6 +307,41 @@ static int mp_property_length(m_option_t * prop, int action, void *arg, return m_property_double_ro(prop, action, arg, len); } +/// Demuxer meta data +static int mp_property_metadata(m_option_t * prop, int action, void *arg, + MPContext * mpctx) { + m_property_action_t* ka; + char* meta; + static m_option_t key_type = + { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL }; + if (!mpctx->demuxer) + return M_PROPERTY_UNAVAILABLE; + + switch(action) { + case M_PROPERTY_GET: + if(!arg) return M_PROPERTY_ERROR; + *(char***)arg = mpctx->demuxer->info; + return M_PROPERTY_OK; + case M_PROPERTY_KEY_ACTION: + if(!arg) return M_PROPERTY_ERROR; + ka = arg; + if(!(meta = demux_info_get(mpctx->demuxer,ka->key))) + return M_PROPERTY_UNKNOWN; + switch(ka->action) { + case M_PROPERTY_GET: + if(!ka->arg) return M_PROPERTY_ERROR; + *(char**)ka->arg = meta; + return M_PROPERTY_OK; + case M_PROPERTY_GET_TYPE: + if(!ka->arg) return M_PROPERTY_ERROR; + *(m_option_t**)ka->arg = &key_type; + return M_PROPERTY_OK; + } + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + + ///@} /// \defgroup AudioProperties Audio properties @@ -439,13 +475,22 @@ static int mp_property_audio_format(m_option_t * prop, int action, return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format); } +/// Audio codec name (RO) +static int mp_property_audio_codec(m_option_t * prop, int action, + void *arg, MPContext * mpctx) +{ + if (!mpctx->sh_audio || !mpctx->sh_audio->codec) + return M_PROPERTY_UNAVAILABLE; + return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name); +} + /// Audio bitrate (RO) static int mp_property_audio_bitrate(m_option_t * prop, int action, void *arg, MPContext * mpctx) { if (!mpctx->sh_audio) return M_PROPERTY_UNAVAILABLE; - return m_property_int_ro(prop, action, arg, mpctx->sh_audio->i_bps); + return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps); } /// Samplerate (RO) @@ -880,18 +925,54 @@ static int mp_property_vsync(m_option_t * prop, int action, void *arg, static int mp_property_video_format(m_option_t * prop, int action, void *arg, MPContext * mpctx) { + char* meta; if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; + switch(action) { + case M_PROPERTY_PRINT: + if (!arg) + return M_PROPERTY_ERROR; + switch(mpctx->sh_video->format) { + case 0x10000001: + meta = strdup ("mpeg1"); break; + case 0x10000002: + meta = strdup ("mpeg2"); break; + case 0x10000004: + meta = strdup ("mpeg4"); break; + case 0x10000005: + meta = strdup ("h264"); break; + default: + if(mpctx->sh_video->format >= 0x20202020) { + meta = malloc(5); + sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format); + } else { + meta = malloc(20); + sprintf (meta, "0x%08X", mpctx->sh_video->format); + } + } + *(char**)arg = meta; + return M_PROPERTY_OK; + } return m_property_int_ro(prop, action, arg, mpctx->sh_video->format); } +/// Video codec name (RO) +static int mp_property_video_codec(m_option_t * prop, int action, + void *arg, MPContext * mpctx) +{ + if (!mpctx->sh_video || !mpctx->sh_video->codec) + return M_PROPERTY_UNAVAILABLE; + return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name); +} + + /// Video bitrate (RO) static int mp_property_video_bitrate(m_option_t * prop, int action, void *arg, MPContext * mpctx) { if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; - return m_property_int_ro(prop, action, arg, mpctx->sh_video->i_bps); + return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps); } /// Video display width (RO) @@ -1318,6 +1399,8 @@ static m_option_t mp_properties[] = { M_OPT_MIN, 0, 0, NULL }, { "length", mp_property_length, CONF_TYPE_DOUBLE, 0, 0, 0, NULL }, + { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST, + 0, 0, 0, NULL }, // Audio { "volume", mp_property_volume, CONF_TYPE_FLOAT, @@ -1328,6 +1411,8 @@ static m_option_t mp_properties[] = { M_OPT_RANGE, -100, 100, NULL }, { "audio_format", mp_property_audio_format, CONF_TYPE_INT, 0, 0, 0, NULL }, + { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING, + 0, 0, 0, NULL }, { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL }, { "samplerate", mp_property_samplerate, CONF_TYPE_INT, @@ -1366,6 +1451,8 @@ static m_option_t mp_properties[] = { M_OPT_RANGE, 0, 1, NULL }, { "video_format", mp_property_video_format, CONF_TYPE_INT, 0, 0, 0, NULL }, + { "video_codec", mp_property_video_codec, CONF_TYPE_STRING, + 0, 0, 0, NULL }, { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL }, { "width", mp_property_width, CONF_TYPE_INT, diff --git a/m_property.c b/m_property.c index 61d2ac33df..20d5bbdbe7 100644 --- a/m_property.c +++ b/m_property.c @@ -331,3 +331,15 @@ int m_property_string_ro(m_option_t* prop,int action,void* arg,char* str) { } return M_PROPERTY_NOT_IMPLEMENTED; } + +int m_property_bitrate(m_option_t* prop,int action,void* arg,int rate) { + switch(action) { + case M_PROPERTY_PRINT: + if (!arg) + return M_PROPERTY_ERROR; + *(char**)arg = malloc (16); + sprintf(*(char**)arg, "%d kbps", rate*8/1000); + return M_PROPERTY_OK; + } + return m_property_int_ro(prop, action, arg, rate); +} diff --git a/m_property.h b/m_property.h index 2d29507f68..f2ab0feb44 100644 --- a/m_property.h +++ b/m_property.h @@ -188,6 +188,9 @@ int m_property_double_ro(m_option_t* prop,int action, /// get/print the string int m_property_string_ro(m_option_t* prop,int action,void* arg, char* str); +/// get/print a bitrate +int m_property_bitrate(m_option_t* prop,int action,void* arg,int rate); + ///@} ///@} -- cgit v1.2.3