From 8054c034b883b23e68fd8c9ca64749e9776f9fcf Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 23 May 2015 15:26:55 +0200 Subject: command: add protocol-list property Fixes #1972. --- DOCS/interface-changes.rst | 1 + DOCS/man/input.rst | 6 ++++++ player/command.c | 16 ++++++++++++++++ stream/stream.c | 27 +++++++++++++++++++++------ stream/stream.h | 1 + 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 41395bfc4a..aff7aa2926 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -20,6 +20,7 @@ Interface changes :: --- mpv 0.10.0 will be released --- + - add protocol-list property - deprecate audio-samplerate and audio-channels properties (audio-params sub-properties are the replacement) - add audio-params and audio-out-params properties diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index ce61654399..4806ac466e 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1778,6 +1778,12 @@ Property list Return the working directory of the mpv process. Can be useful for JSON IPC users, because the command line player usually works with relative paths. +``protocol-list`` + List of protocol prefixes potentially recognized by the player. They are + returned without trailing ``://`` suffix (which is still always required). + In some cases, the protocol will not actually be supported (consider + ``https`` if ffmpeg is not compiled with TLS support). + ``mpv-version`` Return the mpv version/copyright string. Depending on how the binary was built, it might contain either a release version, or just a git hash. diff --git a/player/command.c b/player/command.c index 9ae3880b31..25b9a90e4a 100644 --- a/player/command.c +++ b/player/command.c @@ -3063,6 +3063,20 @@ static int mp_property_cwd(void *ctx, struct m_property *prop, return M_PROPERTY_NOT_IMPLEMENTED; } +static int mp_property_protocols(void *ctx, struct m_property *prop, + int action, void *arg) +{ + switch (action) { + case M_PROPERTY_GET: + *(char ***)arg = stream_get_proto_list(); + return M_PROPERTY_OK; + case M_PROPERTY_GET_TYPE: + *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; + return M_PROPERTY_OK; + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + static int mp_property_version(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3465,6 +3479,8 @@ static const struct m_property mp_properties[] = { {"working-directory", mp_property_cwd}, + {"protocol-list", mp_property_protocols}, + {"mpv-version", mp_property_version}, {"mpv-configuration", mp_property_configuration}, diff --git a/stream/stream.c b/stream/stream.c index cfdf67be14..d6521586b5 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -1024,11 +1024,10 @@ int mp_cancel_get_fd(struct mp_cancel *c) return c->wakeup_pipe[0]; } -void stream_print_proto_list(struct mp_log *log) +char **stream_get_proto_list(void) { - int count = 0; - - mp_info(log, "Protocols:\n\n"); + char **list = NULL; + int num = 0; for (int i = 0; stream_list[i]; i++) { const stream_info_t *stream_info = stream_list[i]; @@ -1039,9 +1038,25 @@ void stream_print_proto_list(struct mp_log *log) if (*stream_info->protocols[j] == '\0') continue; - mp_info(log, " %s://\n", stream_info->protocols[j]); - count++; + MP_TARRAY_APPEND(NULL, list, num, + talloc_strdup(NULL, stream_info->protocols[j])); } } + MP_TARRAY_APPEND(NULL, list, num, NULL); + return list; +} + +void stream_print_proto_list(struct mp_log *log) +{ + int count = 0; + + mp_info(log, "Protocols:\n\n"); + char **list = stream_get_proto_list(); + for (int i = 0; list[i]; i++) { + mp_info(log, " %s://\n", list[i]); + count++; + talloc_free(list[i]); + } + talloc_free(list); mp_info(log, "\nTotal: %d protocols\n", count); } diff --git a/stream/stream.h b/stream/stream.h index 7b4751450c..cda5c7434e 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -289,5 +289,6 @@ void mp_setup_av_network_options(struct AVDictionary **dict, struct MPOpts *opts); void stream_print_proto_list(struct mp_log *log); +char **stream_get_proto_list(void); #endif /* MPLAYER_STREAM_H */ -- cgit v1.2.3