]> git.sesse.net Git - vlc/blob - modules/codec/avcodec/avcommon.h
avcommon: add an helper to parse private options
[vlc] / modules / codec / avcodec / avcommon.h
1 /*****************************************************************************
2  * avinit.h: common code for libav* initialization
3  *****************************************************************************
4  * Copyright (C) 2012 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Rafaël Carré <funman@videolanorg>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_avcodec.h>
29 #include <vlc_configuration.h>
30 #include <vlc_variables.h>
31
32 #ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
33 # include <libavformat/avformat.h>
34 static inline void vlc_init_avformat(void)
35 {
36     vlc_avcodec_lock();
37
38     av_register_all();
39
40     vlc_avcodec_unlock();
41 }
42 #endif
43
44 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
45 # include <libavcodec/avcodec.h>
46 static inline void vlc_init_avcodec(void)
47 {
48     vlc_avcodec_lock();
49
50 #if LIBAVCODEC_VERSION_MAJOR < 54
51     avcodec_init();
52 #endif
53     avcodec_register_all();
54
55     vlc_avcodec_unlock();
56 }
57 #endif
58
59 #ifdef HAVE_LIBAVUTIL_AVUTIL_H
60 # include <libavutil/avutil.h>
61 # if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 51, 7, 0 )
62 #  include <libavutil/dict.h>
63
64 #define AV_OPTIONS_TEXT     "FFmpeg advanced options."
65 #define AV_OPTIONS_LONGTEXT "FFmpeg advanced options, in the form {opt=val,opt2=val2} ."
66
67 static inline AVDictionary *vlc_av_get_options(const char *psz_opts)
68 {
69     AVDictionary *options = NULL;
70     config_chain_t *cfg;
71     config_ChainParseOptions(&cfg, psz_opts);
72     while (cfg) {
73         config_chain_t *next = cfg->p_next;
74         av_dict_set(&options, cfg->psz_name, cfg->psz_value,
75             AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
76         free(cfg);
77         cfg = next;
78     }
79     return options;
80 }
81 # endif
82 #endif