diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/av_common.c | 36 | ||||
-rw-r--r-- | common/av_common.h | 3 | ||||
-rw-r--r-- | common/av_opts.c | 55 | ||||
-rw-r--r-- | common/av_opts.h | 30 |
4 files changed, 39 insertions, 85 deletions
diff --git a/common/av_common.c b/common/av_common.c index d090ccfc50..e0a5da7726 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -20,6 +20,8 @@ #include <libavutil/common.h> #include <libavutil/log.h> #include <libavutil/dict.h> +#include <libavutil/opt.h> +#include <libavutil/error.h> #include <libavcodec/avcodec.h> #include "common/common.h" @@ -189,3 +191,37 @@ void mp_set_avdict(AVDictionary **dict, char **kv) for (int n = 0; kv && kv[n * 2]; n++) av_dict_set(dict, kv[n * 2 + 0], kv[n * 2 + 1], 0); } + +// For use with libav* APIs that take AVDictionaries of options. +// Print options remaining in the dict as unset. +void mp_avdict_print_unset(struct mp_log *log, int msgl, AVDictionary *dict) +{ + AVDictionaryEntry *t = NULL; + while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX))) + mp_msg(log, msgl, "Could not set AVOption %s='%s'\n", t->key, t->value); +} + +// kv is in the format as by OPT_KEYVALUELIST(): kv[0]=key0, kv[1]=val0, ... +// Set these options on given avobj (using av_opt_set..., meaning avobj must +// point to a struct that has AVClass as first member). +// Options which fail to set (error or not found) are printed to log. +// Returns: >=0 success, <0 failed to set an option +int mp_set_avopts(struct mp_log *log, void *avobj, char **kv) +{ + int success = 0; + for (int n = 0; kv && kv[n * 2]; n++) { + char *k = kv[n * 2 + 0]; + char *v = kv[n * 2 + 1]; + int r = av_opt_set(avobj, k, v, AV_OPT_SEARCH_CHILDREN); + if (r == AVERROR_OPTION_NOT_FOUND) { + mp_err(log, "AVOption '%s' not found.\n", k); + success = -1; + } else if (r < 0) { + char errstr[80]; + av_strerror(r, errstr, sizeof(errstr)); + mp_err(log, "Could not set AVOption %s='%s' (%s)\n", k, v, errstr); + success = -1; + } + } + return success; +} diff --git a/common/av_common.h b/common/av_common.h index 4afebe6662..3168d5310d 100644 --- a/common/av_common.h +++ b/common/av_common.h @@ -27,6 +27,7 @@ struct mp_decoder_list; struct demux_packet; struct AVDictionary; +struct mp_log; int mp_lavc_set_extradata(AVCodecContext *avctx, void *ptr, int size); void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st); @@ -38,5 +39,7 @@ void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type); int mp_codec_to_av_codec_id(const char *codec); const char *mp_codec_from_av_codec_id(int codec_id); void mp_set_avdict(struct AVDictionary **dict, char **kv); +void mp_avdict_print_unset(struct mp_log *log, int msgl, struct AVDictionary *d); +int mp_set_avopts(struct mp_log *log, void *avobj, char **kv); #endif diff --git a/common/av_opts.c b/common/av_opts.c deleted file mode 100644 index 777a1eec5a..0000000000 --- a/common/av_opts.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * AVOption parsing helper - * Copyright (C) 2008 Michael Niedermayer - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <stdlib.h> -#include <string.h> - -#include <libavutil/opt.h> - -#include "av_opts.h" - -int parse_avopts(void *v, char *str){ - char *start; - - if (!str) - return 0; - - start= str= strdup(str); - - while(str && *str){ - char *next_opt, *arg; - - next_opt= strchr(str, ','); - if(next_opt) *next_opt++= 0; - - arg = strchr(str, '='); - if(arg) *arg++= 0; - - if (av_opt_set(v, str, arg, AV_OPT_SEARCH_CHILDREN) < 0) { - free(start); - return -1; - } - str= next_opt; - } - - free(start); - return 0; -} diff --git a/common/av_opts.h b/common/av_opts.h deleted file mode 100644 index 640443a352..0000000000 --- a/common/av_opts.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * AVOption parsing helper - * Copyright (C) 2008 Michael Niedermayer - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_AV_OPTS_H -#define MPLAYER_AV_OPTS_H - -/** - * Parses str and sets AVOptions in v accordingly. - */ -int parse_avopts(void *v, char *str); - -#endif /* MPLAYER_AV_OPTS_H */ |