OSDN Git Service

codecs: Disable AC3/EAC3
[android-x86/external-stagefright-plugins.git] / utils / ffmpeg_cmdutils.c
1 #if 1
2 #include "config.h"
3 #include "libavutil/log.h"
4 #include "libavutil/opt.h"
5 #include "libavformat/avformat.h"
6
7 AVDictionary *format_opts, *codec_opts;
8
9 /*
10 void print_error(const char *filename, int err)
11 {
12     char errbuf[128];
13     const char *errbuf_ptr = errbuf;
14
15     if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
16         errbuf_ptr = strerror(AVUNERROR(err));
17     av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
18 }
19 */
20
21 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
22 {
23     int ret = avformat_match_stream_specifier(s, st, spec);
24     if (ret < 0)
25         av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
26     return ret;
27 }
28
29 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
30                                 AVFormatContext *s, AVStream *st, AVCodec *codec)
31 {
32     AVDictionary    *ret = NULL;
33     AVDictionaryEntry *t = NULL;
34     int            flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
35                                       : AV_OPT_FLAG_DECODING_PARAM;
36     char          prefix = 0;
37     const AVClass    *cc = avcodec_get_class();
38
39     if (!codec)
40         codec            = s->oformat ? avcodec_find_encoder(codec_id)
41                                       : avcodec_find_decoder(codec_id);
42
43     switch (st->codec->codec_type) {
44     case AVMEDIA_TYPE_VIDEO:
45         prefix = 'v';
46         flags |= AV_OPT_FLAG_VIDEO_PARAM;
47         break;
48     case AVMEDIA_TYPE_AUDIO:
49         prefix = 'a';
50         flags |= AV_OPT_FLAG_AUDIO_PARAM;
51         break;
52     case AVMEDIA_TYPE_SUBTITLE:
53         prefix = 's';
54         flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
55         break;
56     default:
57         break;
58     }
59
60     while ((t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX))) {
61         char *p = strchr(t->key, ':');
62
63         /* check stream specification in opt name */
64         if (p)
65             switch (check_stream_specifier(s, st, p + 1)) {
66             case  1: *p = 0; break;
67             case  0:         continue;
68             default:         return NULL;
69             }
70
71         if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
72             (codec && codec->priv_class &&
73              av_opt_find(&codec->priv_class, t->key, NULL, flags,
74                          AV_OPT_SEARCH_FAKE_OBJ)))
75             av_dict_set(&ret, t->key, t->value, 0);
76         else if (t->key[0] == prefix &&
77                  av_opt_find(&cc, t->key + 1, NULL, flags,
78                              AV_OPT_SEARCH_FAKE_OBJ))
79             av_dict_set(&ret, t->key + 1, t->value, 0);
80
81         if (p)
82             *p = ':';
83     }
84     return ret;
85 }
86
87 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
88                                            AVDictionary *codec_opts)
89 {
90     unsigned int i;
91     AVDictionary **opts;
92
93     if (!s->nb_streams)
94         return NULL;
95     opts = av_mallocz(s->nb_streams * sizeof(*opts));
96     if (!opts) {
97         av_log(NULL, AV_LOG_ERROR,
98                "Could not alloc memory for stream options.\n");
99         return NULL;
100     }
101     for (i = 0; i < s->nb_streams; i++)
102         opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id,
103                                     s, s->streams[i], NULL);
104     return opts;
105 }
106
107 #else
108 #define FFMPEG_DATADIR "/system/usr/ffmpeg"
109 #include "cmdutils.c" /* external/ffmpeg/cmdutils.c */
110 #endif