mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 00:07:33 +00:00
commands: change property mechanism to use talloc strings
This commit is contained in:
parent
774bb252aa
commit
c5364305be
115
command.c
115
command.c
@ -277,9 +277,9 @@ static int mp_property_loop(m_option_t *prop, int action, void *arg,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg) return M_PROPERTY_ERROR;
|
if (!arg) return M_PROPERTY_ERROR;
|
||||||
if (opts->loop_times < 0)
|
if (opts->loop_times < 0)
|
||||||
*(char**)arg = strdup("off");
|
*(char**)arg = talloc_strdup(NULL, "off");
|
||||||
else if (opts->loop_times == 0)
|
else if (opts->loop_times == 0)
|
||||||
*(char**)arg = strdup("inf");
|
*(char**)arg = talloc_strdup(NULL, "inf");
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
@ -563,7 +563,6 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
|
|||||||
struct MPOpts *opts = &mpctx->opts;
|
struct MPOpts *opts = &mpctx->opts;
|
||||||
int angle = -1;
|
int angle = -1;
|
||||||
int angles;
|
int angles;
|
||||||
char *angle_name = NULL;
|
|
||||||
|
|
||||||
if (mpctx->demuxer)
|
if (mpctx->demuxer)
|
||||||
angle = demuxer_get_current_angle(mpctx->demuxer);
|
angle = demuxer_get_current_angle(mpctx->demuxer);
|
||||||
@ -582,11 +581,7 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
|
|||||||
case M_PROPERTY_PRINT: {
|
case M_PROPERTY_PRINT: {
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
angle_name = calloc(1, 64);
|
*(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
|
||||||
if (!angle_name)
|
|
||||||
return M_PROPERTY_UNAVAILABLE;
|
|
||||||
snprintf(angle_name, 64, "%d/%d", angle, angles);
|
|
||||||
*(char **) arg = angle_name;
|
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
case M_PROPERTY_SET:
|
case M_PROPERTY_SET:
|
||||||
@ -626,7 +621,6 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
|
|||||||
|
|
||||||
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
|
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
|
||||||
"Angle: %d/%d", angle, angles);
|
"Angle: %d/%d", angle, angles);
|
||||||
free(angle_name);
|
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +777,7 @@ static int mp_property_mute(m_option_t *prop, int action, void *arg,
|
|||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
if (mpctx->edl_muted) {
|
if (mpctx->edl_muted) {
|
||||||
*(char **) arg = strdup(mp_gtext("enabled (EDL)"));
|
*(char **) arg = talloc_strdup(NULL, mp_gtext("enabled (EDL)"));
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -852,8 +846,8 @@ static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
|
|||||||
switch(action) {
|
switch(action) {
|
||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if(!arg) return M_PROPERTY_ERROR;
|
if(!arg) return M_PROPERTY_ERROR;
|
||||||
*(char**)arg = malloc(16);
|
*(char**)arg = talloc_asprintf(NULL, "%d kHz",
|
||||||
sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
|
mpctx->sh_audio->samplerate/1000);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
|
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
|
||||||
@ -871,14 +865,14 @@ static int mp_property_channels(m_option_t *prop, int action, void *arg,
|
|||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
switch (mpctx->sh_audio->channels) {
|
switch (mpctx->sh_audio->channels) {
|
||||||
case 1:
|
case 1:
|
||||||
*(char **) arg = strdup("mono");
|
*(char **) arg = talloc_strdup(NULL, "mono");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
*(char **) arg = strdup("stereo");
|
*(char **) arg = talloc_strdup(NULL, "stereo");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*(char **) arg = malloc(32);
|
*(char **) arg = talloc_asprintf(NULL, "%d channels",
|
||||||
sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
|
mpctx->sh_audio->channels);
|
||||||
}
|
}
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
@ -906,15 +900,15 @@ static int mp_property_balance(m_option_t *prop, int action, void *arg,
|
|||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
mixer_getbalance(&mpctx->mixer, &bal);
|
mixer_getbalance(&mpctx->mixer, &bal);
|
||||||
if (bal == 0.f)
|
if (bal == 0.f)
|
||||||
*str = strdup("center");
|
*str = talloc_strdup(NULL, "center");
|
||||||
else if (bal == -1.f)
|
else if (bal == -1.f)
|
||||||
*str = strdup("left only");
|
*str = talloc_strdup(NULL, "left only");
|
||||||
else if (bal == 1.f)
|
else if (bal == 1.f)
|
||||||
*str = strdup("right only");
|
*str = talloc_strdup(NULL, "right only");
|
||||||
else {
|
else {
|
||||||
unsigned right = (bal + 1.f) / 2.f * 100.f;
|
unsigned right = (bal + 1.f) / 2.f * 100.f;
|
||||||
*str = malloc(sizeof("left xxx%, right xxx%"));
|
*str = talloc_asprintf(NULL, "left %d%%, right %d%%",
|
||||||
sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
|
100 - right, right);
|
||||||
}
|
}
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
@ -956,7 +950,7 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg,
|
|||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
|
|
||||||
if (current_id < 0)
|
if (current_id < 0)
|
||||||
*(char **) arg = strdup(mp_gtext("disabled"));
|
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
|
||||||
else {
|
else {
|
||||||
char lang[40];
|
char lang[40];
|
||||||
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
|
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
|
||||||
@ -978,8 +972,7 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg,
|
|||||||
else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
|
else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
|
||||||
mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
|
mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
|
||||||
#endif
|
#endif
|
||||||
*(char **) arg = malloc(64);
|
*(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
|
||||||
snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
|
|
||||||
}
|
}
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
|
|
||||||
@ -1028,12 +1021,10 @@ static int mp_property_video(m_option_t *prop, int action, void *arg,
|
|||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
|
|
||||||
if (current_id < 0)
|
if (current_id < 0)
|
||||||
*(char **) arg = strdup(mp_gtext("disabled"));
|
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
|
||||||
else {
|
else {
|
||||||
char lang[40];
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
|
||||||
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
|
mp_gtext("unknown"));
|
||||||
*(char **) arg = malloc(64);
|
|
||||||
snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
|
|
||||||
}
|
}
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
|
|
||||||
@ -1178,9 +1169,9 @@ static int mp_property_yuv_colorspace(m_option_t *prop, int action,
|
|||||||
return M_PROPERTY_UNAVAILABLE;
|
return M_PROPERTY_UNAVAILABLE;
|
||||||
char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
|
char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
|
||||||
if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
|
if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
|
||||||
*(char **)arg = strdup("Unknown");
|
*(char **)arg = talloc_strdup(NULL, mp_gtext("unknown"));
|
||||||
else
|
else
|
||||||
*(char**)arg = strdup(names[colorspace]);
|
*(char**)arg = talloc_strdup(NULL, names[colorspace]);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
case M_PROPERTY_SET:
|
case M_PROPERTY_SET:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
@ -1327,7 +1318,8 @@ static int mp_property_framedropping(m_option_t *prop, int action,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
*(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
|
*(char **) arg = talloc_strdup(NULL,
|
||||||
|
frame_dropping == 1 ? mp_gtext("enabled") :
|
||||||
(frame_dropping == 2 ? mp_gtext("hard") :
|
(frame_dropping == 2 ? mp_gtext("hard") :
|
||||||
mp_gtext("disabled")));
|
mp_gtext("disabled")));
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
@ -1414,20 +1406,19 @@ static int mp_property_video_format(m_option_t *prop, int action,
|
|||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
switch(mpctx->sh_video->format) {
|
switch(mpctx->sh_video->format) {
|
||||||
case 0x10000001:
|
case 0x10000001:
|
||||||
meta = strdup ("mpeg1"); break;
|
meta = talloc_strdup(NULL, "mpeg1"); break;
|
||||||
case 0x10000002:
|
case 0x10000002:
|
||||||
meta = strdup ("mpeg2"); break;
|
meta = talloc_strdup(NULL, "mpeg2"); break;
|
||||||
case 0x10000004:
|
case 0x10000004:
|
||||||
meta = strdup ("mpeg4"); break;
|
meta = talloc_strdup(NULL, "mpeg4"); break;
|
||||||
case 0x10000005:
|
case 0x10000005:
|
||||||
meta = strdup ("h264"); break;
|
meta = talloc_strdup(NULL, "h264"); break;
|
||||||
default:
|
default:
|
||||||
if(mpctx->sh_video->format >= 0x20202020) {
|
if(mpctx->sh_video->format >= 0x20202020) {
|
||||||
meta = malloc(5);
|
meta = talloc_asprintf(NULL, "%.4s",
|
||||||
sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
|
(char *) &mpctx->sh_video->format);
|
||||||
} else {
|
} else {
|
||||||
meta = malloc(20);
|
meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
|
||||||
sprintf (meta, "0x%08X", mpctx->sh_video->format);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(char**)arg = meta;
|
*(char**)arg = meta;
|
||||||
@ -1537,8 +1528,6 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
*(char **) arg = malloc(64);
|
|
||||||
(*(char **) arg)[63] = 0;
|
|
||||||
char *sub_name = NULL;
|
char *sub_name = NULL;
|
||||||
if (mpctx->subdata)
|
if (mpctx->subdata)
|
||||||
sub_name = mpctx->subdata->filename;
|
sub_name = mpctx->subdata->filename;
|
||||||
@ -1551,7 +1540,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
|
|||||||
if (sub_name) {
|
if (sub_name) {
|
||||||
const char *tmp = mp_basename(sub_name);
|
const char *tmp = mp_basename(sub_name);
|
||||||
|
|
||||||
snprintf(*(char **) arg, 63, "(%d) %s%s",
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
|
||||||
mpctx->set_of_sub_pos + 1,
|
mpctx->set_of_sub_pos + 1,
|
||||||
strlen(tmp) < 20 ? "" : "...",
|
strlen(tmp) < 20 ? "" : "...",
|
||||||
strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
|
strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
|
||||||
@ -1562,7 +1551,8 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
|
|||||||
if (vo_spudec && opts->sub_id >= 0) {
|
if (vo_spudec && opts->sub_id >= 0) {
|
||||||
unsigned char lang[3];
|
unsigned char lang[3];
|
||||||
if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
|
if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
|
||||||
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
|
||||||
|
opts->sub_id, lang);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1576,14 +1566,15 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
|
|||||||
&& d_sub->sh && opts->sub_id >= 0) {
|
&& d_sub->sh && opts->sub_id >= 0) {
|
||||||
const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
|
const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
|
||||||
if (!lang) lang = mp_gtext("unknown");
|
if (!lang) lang = mp_gtext("unknown");
|
||||||
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
|
||||||
|
opts->sub_id, lang);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vo_vobsub && vobsub_id >= 0) {
|
if (vo_vobsub && vobsub_id >= 0) {
|
||||||
const char *language = mp_gtext("unknown");
|
const char *language = mp_gtext("unknown");
|
||||||
language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
|
language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
|
||||||
snprintf(*(char **) arg, 63, "(%d) %s",
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
|
||||||
vobsub_id, language ? language : mp_gtext("unknown"));
|
vobsub_id, language ? language : mp_gtext("unknown"));
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
@ -1595,16 +1586,17 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
|
|||||||
lang[0] = code >> 8;
|
lang[0] = code >> 8;
|
||||||
lang[1] = code;
|
lang[1] = code;
|
||||||
lang[2] = 0;
|
lang[2] = 0;
|
||||||
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
|
||||||
|
opts->sub_id, lang);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (opts->sub_id >= 0) {
|
if (opts->sub_id >= 0) {
|
||||||
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
|
*(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
|
||||||
mp_gtext("unknown"));
|
mp_gtext("unknown"));
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
snprintf(*(char **) arg, 63, mp_gtext("disabled"));
|
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
|
|
||||||
case M_PROPERTY_SET:
|
case M_PROPERTY_SET:
|
||||||
@ -1737,22 +1729,21 @@ static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
*(char **) arg = malloc(64);
|
char *sourcename;
|
||||||
(*(char **) arg)[63] = 0;
|
switch (sub_source(mpctx)) {
|
||||||
switch (sub_source(mpctx))
|
|
||||||
{
|
|
||||||
case SUB_SOURCE_SUBS:
|
case SUB_SOURCE_SUBS:
|
||||||
snprintf(*(char **) arg, 63, mp_gtext("file"));
|
sourcename = mp_gtext("file");
|
||||||
break;
|
break;
|
||||||
case SUB_SOURCE_VOBSUB:
|
case SUB_SOURCE_VOBSUB:
|
||||||
snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
|
sourcename = mp_gtext("vobsub");
|
||||||
break;
|
break;
|
||||||
case SUB_SOURCE_DEMUX:
|
case SUB_SOURCE_DEMUX:
|
||||||
snprintf(*(char **) arg, 63, mp_gtext("embedded"));
|
sourcename = mp_gtext("embedded");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf(*(char **) arg, 63, mp_gtext("disabled"));
|
sourcename = mp_gtext("disabled");
|
||||||
}
|
}
|
||||||
|
*(char **)arg = talloc_strdup(NULL, sourcename);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
case M_PROPERTY_SET:
|
case M_PROPERTY_SET:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
@ -1840,9 +1831,7 @@ static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
|
|||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
if (is_cur_source)
|
if (is_cur_source)
|
||||||
return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
|
return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
|
||||||
*(char **) arg = malloc(64);
|
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
|
||||||
(*(char **) arg)[63] = 0;
|
|
||||||
snprintf(*(char **) arg, 63, mp_gtext("disabled"));
|
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
case M_PROPERTY_SET:
|
case M_PROPERTY_SET:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
@ -1923,7 +1912,7 @@ static int mp_property_sub_alignment(m_option_t *prop, int action,
|
|||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
M_PROPERTY_CLAMP(prop, sub_alignment);
|
M_PROPERTY_CLAMP(prop, sub_alignment);
|
||||||
*(char **) arg = strdup(mp_gtext(name[sub_alignment]));
|
*(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
case M_PROPERTY_SET:
|
case M_PROPERTY_SET:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
@ -2482,7 +2471,7 @@ static int show_property_osd(MPContext *mpctx, const char *pname)
|
|||||||
int index = p - property_osd_display;
|
int index = p - property_osd_display;
|
||||||
set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
|
set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
|
||||||
1, opts->osd_duration, p->osd_msg, val);
|
1, opts->osd_duration, p->osd_msg, val);
|
||||||
free(val);
|
talloc_free(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -2822,7 +2811,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
|||||||
}
|
}
|
||||||
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
|
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
|
||||||
cmd->args[0].v.s, tmp);
|
cmd->args[0].v.s, tmp);
|
||||||
free(tmp);
|
talloc_free(tmp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "talloc.h"
|
||||||
#include "m_struct.h"
|
#include "m_struct.h"
|
||||||
#include "m_option.h"
|
#include "m_option.h"
|
||||||
#include "input/input.h"
|
#include "input/input.h"
|
||||||
@ -111,7 +112,9 @@ static int fill_menu (menu_t* menu)
|
|||||||
if ((e = calloc (1, sizeof (list_entry_t))) != NULL) {
|
if ((e = calloc (1, sizeof (list_entry_t))) != NULL) {
|
||||||
e->cid = cid + 1;
|
e->cid = cid + 1;
|
||||||
e->p.next = NULL;
|
e->p.next = NULL;
|
||||||
e->p.txt = demuxer_chapter_display_name(demuxer, cid);
|
char *str = demuxer_chapter_display_name(demuxer, cid);
|
||||||
|
e->p.txt = strdup(str);
|
||||||
|
talloc_free(str);
|
||||||
start_time = demuxer_chapter_time(demuxer, cid, NULL);
|
start_time = demuxer_chapter_time(demuxer, cid, NULL);
|
||||||
if (start_time >= 0) {
|
if (start_time >= 0) {
|
||||||
char timestr[13];
|
char timestr[13];
|
||||||
|
@ -1468,18 +1468,16 @@ char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter)
|
|||||||
{
|
{
|
||||||
char *chapter_name = demuxer_chapter_name(demuxer, chapter);
|
char *chapter_name = demuxer_chapter_name(demuxer, chapter);
|
||||||
if (chapter_name) {
|
if (chapter_name) {
|
||||||
char *tmp = malloc(strlen(chapter_name) + 14);
|
char *tmp = talloc_asprintf(NULL, "(%d) %s", chapter + 1, chapter_name);
|
||||||
snprintf(tmp, 63, "(%d) %s", chapter + 1, chapter_name);
|
|
||||||
free(chapter_name);
|
free(chapter_name);
|
||||||
return tmp;
|
return tmp;
|
||||||
} else {
|
} else {
|
||||||
int chapter_num = demuxer_chapter_count(demuxer);
|
int chapter_num = demuxer_chapter_count(demuxer);
|
||||||
char tmp[30];
|
|
||||||
if (chapter_num <= 0)
|
if (chapter_num <= 0)
|
||||||
sprintf(tmp, "(%d)", chapter + 1);
|
return talloc_asprintf(NULL, "(%d)", chapter + 1);
|
||||||
else
|
else
|
||||||
sprintf(tmp, "(%d) of %d", chapter + 1, chapter_num);
|
return talloc_asprintf(NULL, "(%d) of %d", chapter + 1,
|
||||||
return strdup(tmp);
|
chapter_num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
64
m_option.c
64
m_option.c
@ -29,8 +29,8 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "talloc.h"
|
||||||
#include "m_option.h"
|
#include "m_option.h"
|
||||||
//#include "m_config.h"
|
|
||||||
#include "mp_msg.h"
|
#include "mp_msg.h"
|
||||||
#include "stream/url.h"
|
#include "stream/url.h"
|
||||||
#include "libavutil/avstring.h"
|
#include "libavutil/avstring.h"
|
||||||
@ -64,34 +64,6 @@ static void copy_opt(const m_option_t *opt, void *dst, const void *src)
|
|||||||
memcpy(dst, src, opt->type->size);
|
memcpy(dst, src, opt->type->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper for the print funcs (from man printf)
|
|
||||||
static char *dup_printf(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
/* Guess we need no more than 50 bytes. */
|
|
||||||
int n, size = 50;
|
|
||||||
char *p;
|
|
||||||
va_list ap;
|
|
||||||
if ((p = malloc(size)) == NULL)
|
|
||||||
return NULL;
|
|
||||||
while (1) {
|
|
||||||
/* Try to print in the allocated space. */
|
|
||||||
va_start(ap, fmt);
|
|
||||||
n = vsnprintf(p, size, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
/* If that worked, return the string. */
|
|
||||||
if (n > -1 && n < size)
|
|
||||||
return p;
|
|
||||||
/* Else try again with more space. */
|
|
||||||
if (n > -1) /* glibc 2.1 */
|
|
||||||
size = n + 1; /* precisely what is needed */
|
|
||||||
else /* glibc 2.0 */
|
|
||||||
size *= 2; /* twice the old size */
|
|
||||||
if ((p = realloc(p, size)) == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Flag
|
// Flag
|
||||||
|
|
||||||
#define VAL(x) (*(int *)(x))
|
#define VAL(x) (*(int *)(x))
|
||||||
@ -144,9 +116,9 @@ static int parse_flag(const m_option_t *opt, const char *name,
|
|||||||
static char *print_flag(const m_option_t *opt, const void *val)
|
static char *print_flag(const m_option_t *opt, const void *val)
|
||||||
{
|
{
|
||||||
if (VAL(val) == opt->min)
|
if (VAL(val) == opt->min)
|
||||||
return strdup("no");
|
return talloc_strdup(NULL, "no");
|
||||||
else
|
else
|
||||||
return strdup("yes");
|
return talloc_strdup(NULL, "yes");
|
||||||
}
|
}
|
||||||
|
|
||||||
const m_option_type_t m_option_type_flag = {
|
const m_option_type_t m_option_type_flag = {
|
||||||
@ -210,8 +182,8 @@ static int parse_int(const m_option_t *opt, const char *name,
|
|||||||
static char *print_int(const m_option_t *opt, const void *val)
|
static char *print_int(const m_option_t *opt, const void *val)
|
||||||
{
|
{
|
||||||
if (opt->type->size == sizeof(int64_t))
|
if (opt->type->size == sizeof(int64_t))
|
||||||
return dup_printf("%"PRId64, *(const int64_t *)val);
|
return talloc_asprintf(NULL, "%"PRId64, *(const int64_t *)val);
|
||||||
return dup_printf("%d", VAL(val));
|
return talloc_asprintf(NULL, "%d", VAL(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
const m_option_type_t m_option_type_int = {
|
const m_option_type_t m_option_type_int = {
|
||||||
@ -317,7 +289,7 @@ static char *print_choice(const m_option_t *opt, const void *val)
|
|||||||
struct m_opt_choice_alternatives *alt;
|
struct m_opt_choice_alternatives *alt;
|
||||||
for (alt = opt->priv; alt->name; alt++)
|
for (alt = opt->priv; alt->name; alt++)
|
||||||
if (alt->value == v)
|
if (alt->value == v)
|
||||||
return strdup(alt->name);
|
return talloc_strdup(NULL, alt->name);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,7 +367,7 @@ static int parse_double(const m_option_t *opt, const char *name,
|
|||||||
static char *print_double(const m_option_t *opt, const void *val)
|
static char *print_double(const m_option_t *opt, const void *val)
|
||||||
{
|
{
|
||||||
opt = NULL;
|
opt = NULL;
|
||||||
return dup_printf("%f", VAL(val));
|
return talloc_asprintf(NULL, "%f", VAL(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
const m_option_type_t m_option_type_double = {
|
const m_option_type_t m_option_type_double = {
|
||||||
@ -427,7 +399,7 @@ static int parse_float(const m_option_t *opt, const char *name,
|
|||||||
static char *print_float(const m_option_t *opt, const void *val)
|
static char *print_float(const m_option_t *opt, const void *val)
|
||||||
{
|
{
|
||||||
opt = NULL;
|
opt = NULL;
|
||||||
return dup_printf("%f", VAL(val));
|
return talloc_asprintf(NULL, "%f", VAL(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
const m_option_type_t m_option_type_float = {
|
const m_option_type_t m_option_type_float = {
|
||||||
@ -485,7 +457,7 @@ static int parse_position(const m_option_t *opt, const char *name,
|
|||||||
|
|
||||||
static char *print_position(const m_option_t *opt, const void *val)
|
static char *print_position(const m_option_t *opt, const void *val)
|
||||||
{
|
{
|
||||||
return dup_printf("%"PRId64, (int64_t)VAL(val));
|
return talloc_asprintf(NULL, "%"PRId64, (int64_t)VAL(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
const m_option_type_t m_option_type_position = {
|
const m_option_type_t m_option_type_position = {
|
||||||
@ -538,7 +510,7 @@ static int parse_str(const m_option_t *opt, const char *name,
|
|||||||
|
|
||||||
static char *print_str(const m_option_t *opt, const void *val)
|
static char *print_str(const m_option_t *opt, const void *val)
|
||||||
{
|
{
|
||||||
return (val && VAL(val) && strlen(VAL(val)) > 0) ? strdup(VAL(val)) : NULL;
|
return (val && VAL(val)) ? talloc_strdup(NULL, VAL(val)) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_str(const m_option_t *opt, void *dst, const void *src)
|
static void copy_str(const m_option_t *opt, void *dst, const void *src)
|
||||||
@ -825,23 +797,17 @@ static void copy_str_list(const m_option_t *opt, void *dst, const void *src)
|
|||||||
static char *print_str_list(const m_option_t *opt, const void *src)
|
static char *print_str_list(const m_option_t *opt, const void *src)
|
||||||
{
|
{
|
||||||
char **lst = NULL;
|
char **lst = NULL;
|
||||||
char *ret = NULL, *last = NULL;
|
char *ret = NULL;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!(src && VAL(src)))
|
if (!(src && VAL(src)))
|
||||||
return NULL;
|
return NULL;
|
||||||
lst = VAL(src);
|
lst = VAL(src);
|
||||||
|
|
||||||
for (i = 0; lst[i]; i++) {
|
for (int i = 0; lst[i]; i++) {
|
||||||
if (last) {
|
if (ret)
|
||||||
ret = dup_printf("%s,%s", last, lst[i]);
|
ret = talloc_strdup_append_buffer(ret, ",");
|
||||||
free(last);
|
ret = talloc_strdup_append_buffer(ret, lst[i]);
|
||||||
} else
|
|
||||||
ret = strdup(lst[i]);
|
|
||||||
last = ret;
|
|
||||||
}
|
}
|
||||||
if (last && last != ret)
|
|
||||||
free(last);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr)
|
|||||||
if (opt->type->print)
|
if (opt->type->print)
|
||||||
return opt->type->print(opt, val_ptr);
|
return opt->type->print(opt, val_ptr);
|
||||||
else
|
else
|
||||||
return (char *)-1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper around \ref m_option_type::copy.
|
// Helper around \ref m_option_type::copy.
|
||||||
|
33
m_property.c
33
m_property.c
@ -27,6 +27,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "talloc.h"
|
||||||
#include "m_option.h"
|
#include "m_option.h"
|
||||||
#include "m_property.h"
|
#include "m_property.h"
|
||||||
#include "mp_msg.h"
|
#include "mp_msg.h"
|
||||||
@ -69,7 +70,6 @@ int m_property_do(const m_option_t *prop_list, const char *name,
|
|||||||
{
|
{
|
||||||
const m_option_t *opt;
|
const m_option_t *opt;
|
||||||
void *val;
|
void *val;
|
||||||
char *str;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@ -92,10 +92,10 @@ int m_property_do(const m_option_t *prop_list, const char *name,
|
|||||||
}
|
}
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
str = m_option_print(opt, val);
|
char *str = m_option_print(opt, val);
|
||||||
free(val);
|
free(val);
|
||||||
*(char **)arg = str == (char *)-1 ? NULL : str;
|
*(char **)arg = str;
|
||||||
return str != (char *)-1;
|
return str != NULL;
|
||||||
case M_PROPERTY_PARSE:
|
case M_PROPERTY_PARSE:
|
||||||
// try the property own parsing func
|
// try the property own parsing func
|
||||||
if ((r = do_action(prop_list, name, M_PROPERTY_PARSE, arg, ctx)) !=
|
if ((r = do_action(prop_list, name, M_PROPERTY_PARSE, arg, ctx)) !=
|
||||||
@ -200,7 +200,7 @@ char *m_properties_expand_string(const m_option_t *prop_list, char *str,
|
|||||||
memcpy(ret + pos, p, l);
|
memcpy(ret + pos, p, l);
|
||||||
pos += l;
|
pos += l;
|
||||||
if (fr)
|
if (fr)
|
||||||
free(p), fr = 0;
|
talloc_free(p), fr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret[pos] = 0;
|
ret[pos] = 0;
|
||||||
@ -290,7 +290,7 @@ int m_property_flag_ro(const m_option_t *prop, int action,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return 0;
|
return 0;
|
||||||
*(char **)arg = strdup((var > prop->min) ?
|
*(char **)arg = talloc_strdup(NULL, (var > prop->min) ?
|
||||||
mp_gtext("enabled") : mp_gtext("disabled"));
|
mp_gtext("enabled") : mp_gtext("disabled"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -323,8 +323,7 @@ int m_property_float_ro(const m_option_t *prop, int action,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return 0;
|
return 0;
|
||||||
*(char **)arg = malloc(20);
|
*(char **)arg = talloc_asprintf(NULL, "%.2f", var);
|
||||||
sprintf(*(char **)arg, "%.2f", var);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||||
@ -357,8 +356,7 @@ int m_property_delay(const m_option_t *prop, int action,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return 0;
|
return 0;
|
||||||
*(char **)arg = malloc(20);
|
*(char **)arg = talloc_asprintf(NULL, "%d ms", ROUND((*var) * 1000));
|
||||||
sprintf(*(char **)arg, "%d ms", ROUND((*var) * 1000));
|
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
return m_property_float_range(prop, action, arg, var);
|
return m_property_float_range(prop, action, arg, var);
|
||||||
@ -377,8 +375,7 @@ int m_property_double_ro(const m_option_t *prop, int action,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return 0;
|
return 0;
|
||||||
*(char **)arg = malloc(20);
|
*(char **)arg = talloc_asprintf(NULL, "%.2f", var);
|
||||||
sprintf(*(char **)arg, "%.2f", var);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||||
@ -397,13 +394,12 @@ int m_property_time_ro(const m_option_t *prop, int action,
|
|||||||
s -= h * 3600;
|
s -= h * 3600;
|
||||||
m = s / 60;
|
m = s / 60;
|
||||||
s -= m * 60;
|
s -= m * 60;
|
||||||
*(char **) arg = malloc(20);
|
|
||||||
if (h > 0)
|
if (h > 0)
|
||||||
sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s);
|
*(char **)arg = talloc_asprintf(NULL, "%d:%02d:%02d", h, m, s);
|
||||||
else if (m > 0)
|
else if (m > 0)
|
||||||
sprintf(*(char **) arg, "%d:%02d", m, s);
|
*(char **)arg = talloc_asprintf(NULL, "%d:%02d", m, s);
|
||||||
else
|
else
|
||||||
sprintf(*(char **) arg, "%d", s);
|
*(char **)arg = talloc_asprintf(NULL, "%d", s);
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,7 +418,7 @@ int m_property_string_ro(const m_option_t *prop, int action, void *arg,
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return 0;
|
return 0;
|
||||||
*(char **)arg = str ? strdup(str) : NULL;
|
*(char **)arg = talloc_strdup(NULL, str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||||
@ -434,8 +430,7 @@ int m_property_bitrate(const m_option_t *prop, int action, void *arg, int rate)
|
|||||||
case M_PROPERTY_PRINT:
|
case M_PROPERTY_PRINT:
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return M_PROPERTY_ERROR;
|
return M_PROPERTY_ERROR;
|
||||||
*(char **)arg = malloc(16);
|
*(char **)arg = talloc_asprintf(NULL, "%d kbps", rate * 8 / 1000);
|
||||||
sprintf(*(char **)arg, "%d kbps", rate * 8 / 1000);
|
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
return m_property_int_ro(prop, action, arg, rate);
|
return m_property_int_ro(prop, action, arg, rate);
|
||||||
|
@ -3308,7 +3308,7 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
|
|||||||
{
|
{
|
||||||
if (!mpctx->chapters || !mpctx->sh_video)
|
if (!mpctx->chapters || !mpctx->sh_video)
|
||||||
return demuxer_chapter_display_name(mpctx->demuxer, chapter);
|
return demuxer_chapter_display_name(mpctx->demuxer, chapter);
|
||||||
return strdup(mpctx->chapters[chapter].name);
|
return talloc_strdup(NULL, mpctx->chapters[chapter].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,
|
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,
|
||||||
|
Loading…
Reference in New Issue
Block a user