2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "avio_internal.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/opt.h"
30 * Options definition for AVFormatContext.
33 FF_DISABLE_DEPRECATION_WARNINGS
34 #include "options_table.h"
35 FF_ENABLE_DEPRECATION_WARNINGS
37 static const char* format_to_name(void* ptr)
39 AVFormatContext* fc = (AVFormatContext*) ptr;
40 if(fc->iformat) return fc->iformat->name;
41 else if(fc->oformat) return fc->oformat->name;
45 static void *format_child_next(void *obj, void *prev)
47 AVFormatContext *s = obj;
48 if (!prev && s->priv_data &&
49 ((s->iformat && s->iformat->priv_class) ||
50 s->oformat && s->oformat->priv_class))
52 if (s->pb && s->pb->av_class && prev != s->pb)
57 static const AVClass *format_child_class_next(const AVClass *prev)
59 AVInputFormat *ifmt = NULL;
60 AVOutputFormat *ofmt = NULL;
63 return &ff_avio_class;
65 while ((ifmt = av_iformat_next(ifmt)))
66 if (ifmt->priv_class == prev)
70 while ((ofmt = av_oformat_next(ofmt)))
71 if (ofmt->priv_class == prev)
74 while (ifmt = av_iformat_next(ifmt))
76 return ifmt->priv_class;
78 while (ofmt = av_oformat_next(ofmt))
80 return ofmt->priv_class;
85 static const AVClass av_format_context_class = {
86 .class_name = "AVFormatContext",
87 .item_name = format_to_name,
88 .option = avformat_options,
89 .version = LIBAVUTIL_VERSION_INT,
90 .child_next = format_child_next,
91 .child_class_next = format_child_class_next,
94 static int io_open_default(AVFormatContext *s, AVIOContext **pb,
95 const char *url, int flags, AVDictionary **options)
97 AVDictionary *opts_local = NULL;
101 options = &opts_local;
103 if (s->protocol_whitelist) {
104 ret = av_dict_set(options, "protocol_whitelist", s->protocol_whitelist, 0);
108 if (s->protocol_blacklist) {
109 ret = av_dict_set(options, "protocol_blacklist", s->protocol_blacklist, 0);
113 ret = avio_open2(pb, url, flags, &s->interrupt_callback, options);
115 av_dict_free(&opts_local);
119 static void io_close_default(AVFormatContext *s, AVIOContext *pb)
124 static void avformat_get_context_defaults(AVFormatContext *s)
126 memset(s, 0, sizeof(AVFormatContext));
128 s->av_class = &av_format_context_class;
130 s->io_open = io_open_default;
131 s->io_close = io_close_default;
133 av_opt_set_defaults(s);
136 AVFormatContext *avformat_alloc_context(void)
139 ic = av_malloc(sizeof(AVFormatContext));
141 avformat_get_context_defaults(ic);
143 ic->internal = av_mallocz(sizeof(*ic->internal));
145 avformat_free_context(ic);
148 ic->internal->offset = AV_NOPTS_VALUE;
153 const AVClass *avformat_get_class(void)
155 return &av_format_context_class;