[MPlayer-cvslog] r23412 - in trunk: command.c m_property.c m_property.h
albeu
subversion at mplayerhq.hu
Wed May 30 00:14:41 CEST 2007
Author: albeu
Date: Wed May 30 00:14:41 2007
New Revision: 23412
Log:
Make all the info available via the metadata API available via properties.
Modified:
trunk/command.c
trunk/m_property.c
trunk/m_property.h
Modified: trunk/command.c
==============================================================================
--- trunk/command.c (original)
+++ trunk/command.c Wed May 30 00:14:41 2007
@@ -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
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_op
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
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,
Modified: trunk/m_property.c
==============================================================================
--- trunk/m_property.c (original)
+++ trunk/m_property.c Wed May 30 00:14:41 2007
@@ -331,3 +331,15 @@ int m_property_string_ro(m_option_t* pro
}
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);
+}
Modified: trunk/m_property.h
==============================================================================
--- trunk/m_property.h (original)
+++ trunk/m_property.h Wed May 30 00:14:41 2007
@@ -188,6 +188,9 @@ int m_property_double_ro(m_option_t* pro
/// 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);
+
///@}
///@}
More information about the MPlayer-cvslog
mailing list