Commit | Line | Data |
---|---|---|
708ec8fb SS |
1 | /* |
2 | * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | |
3 | * | |
2912e87a | 4 | * This file is part of Libav. |
708ec8fb | 5 | * |
2912e87a | 6 | * Libav is free software; you can redistribute it and/or |
708ec8fb SS |
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. | |
10 | * | |
2912e87a | 11 | * Libav is distributed in the hope that it will be useful, |
708ec8fb SS |
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. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
2912e87a | 17 | * License along with Libav; if not, write to the Free Software |
708ec8fb SS |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | */ | |
20 | #include "avformat.h" | |
32caa7b1 | 21 | #include "avio_internal.h" |
33c859c1 | 22 | #include "internal.h" |
ec4c4839 | 23 | #include "url.h" |
f046c3b5 VG |
24 | |
25 | #include "libavutil/internal.h" | |
6ed04040 | 26 | #include "libavutil/opt.h" |
708ec8fb SS |
27 | |
28 | /** | |
ba87f080 | 29 | * @file |
708ec8fb SS |
30 | * Options definition for AVFormatContext. |
31 | */ | |
32 | ||
f046c3b5 | 33 | FF_DISABLE_DEPRECATION_WARNINGS |
56266971 | 34 | #include "options_table.h" |
f046c3b5 | 35 | FF_ENABLE_DEPRECATION_WARNINGS |
56266971 | 36 | |
708ec8fb SS |
37 | static const char* format_to_name(void* ptr) |
38 | { | |
39 | AVFormatContext* fc = (AVFormatContext*) ptr; | |
40 | if(fc->iformat) return fc->iformat->name; | |
41 | else if(fc->oformat) return fc->oformat->name; | |
42 | else return "NULL"; | |
43 | } | |
44 | ||
641c7afe AK |
45 | static void *format_child_next(void *obj, void *prev) |
46 | { | |
47 | AVFormatContext *s = obj; | |
48 | if (!prev && s->priv_data && | |
49 | ((s->iformat && s->iformat->priv_class) || | |
50 | s->oformat && s->oformat->priv_class)) | |
51 | return s->priv_data; | |
32caa7b1 AK |
52 | if (s->pb && s->pb->av_class && prev != s->pb) |
53 | return s->pb; | |
641c7afe AK |
54 | return NULL; |
55 | } | |
56 | ||
57 | static const AVClass *format_child_class_next(const AVClass *prev) | |
05e84c95 | 58 | { |
05e84c95 AK |
59 | AVInputFormat *ifmt = NULL; |
60 | AVOutputFormat *ofmt = NULL; | |
641c7afe | 61 | |
caf27e37 | 62 | if (!prev) |
c86d8aed | 63 | return &ff_avio_class; |
caf27e37 LB |
64 | |
65 | while ((ifmt = av_iformat_next(ifmt))) | |
641c7afe AK |
66 | if (ifmt->priv_class == prev) |
67 | break; | |
caf27e37 LB |
68 | |
69 | if (!ifmt) | |
70 | while ((ofmt = av_oformat_next(ofmt))) | |
71 | if (ofmt->priv_class == prev) | |
72 | break; | |
73 | if (!ofmt) | |
641c7afe AK |
74 | while (ifmt = av_iformat_next(ifmt)) |
75 | if (ifmt->priv_class) | |
76 | return ifmt->priv_class; | |
77 | ||
caf27e37 LB |
78 | while (ofmt = av_oformat_next(ofmt)) |
79 | if (ofmt->priv_class) | |
80 | return ofmt->priv_class; | |
641c7afe | 81 | |
05e84c95 AK |
82 | return NULL; |
83 | } | |
84 | ||
f0029cbc AK |
85 | static const AVClass av_format_context_class = { |
86 | .class_name = "AVFormatContext", | |
87 | .item_name = format_to_name, | |
b5a13865 | 88 | .option = avformat_options, |
f0029cbc | 89 | .version = LIBAVUTIL_VERSION_INT, |
641c7afe AK |
90 | .child_next = format_child_next, |
91 | .child_class_next = format_child_class_next, | |
f0029cbc | 92 | }; |
708ec8fb | 93 | |
9f61abc8 AK |
94 | static int io_open_default(AVFormatContext *s, AVIOContext **pb, |
95 | const char *url, int flags, AVDictionary **options) | |
96 | { | |
ec4c4839 AK |
97 | AVDictionary *opts_local = NULL; |
98 | int ret; | |
99 | ||
100 | if (!options) | |
101 | options = &opts_local; | |
102 | ||
103 | if (s->protocol_whitelist) { | |
104 | ret = av_dict_set(options, "protocol_whitelist", s->protocol_whitelist, 0); | |
105 | if (ret < 0) | |
106 | goto finish; | |
107 | } | |
108 | if (s->protocol_blacklist) { | |
109 | ret = av_dict_set(options, "protocol_blacklist", s->protocol_blacklist, 0); | |
110 | if (ret < 0) | |
111 | goto finish; | |
112 | } | |
113 | ret = avio_open2(pb, url, flags, &s->interrupt_callback, options); | |
114 | finish: | |
115 | av_dict_free(&opts_local); | |
116 | return ret; | |
9f61abc8 AK |
117 | } |
118 | ||
119 | static void io_close_default(AVFormatContext *s, AVIOContext *pb) | |
120 | { | |
121 | avio_close(pb); | |
122 | } | |
123 | ||
708ec8fb SS |
124 | static void avformat_get_context_defaults(AVFormatContext *s) |
125 | { | |
126 | memset(s, 0, sizeof(AVFormatContext)); | |
127 | ||
128 | s->av_class = &av_format_context_class; | |
129 | ||
9f61abc8 AK |
130 | s->io_open = io_open_default; |
131 | s->io_close = io_close_default; | |
132 | ||
708ec8fb SS |
133 | av_opt_set_defaults(s); |
134 | } | |
135 | ||
88a28965 | 136 | AVFormatContext *avformat_alloc_context(void) |
708ec8fb SS |
137 | { |
138 | AVFormatContext *ic; | |
139 | ic = av_malloc(sizeof(AVFormatContext)); | |
140 | if (!ic) return ic; | |
141 | avformat_get_context_defaults(ic); | |
33c859c1 AK |
142 | |
143 | ic->internal = av_mallocz(sizeof(*ic->internal)); | |
144 | if (!ic->internal) { | |
145 | avformat_free_context(ic); | |
146 | return NULL; | |
147 | } | |
9deaec78 | 148 | ic->internal->offset = AV_NOPTS_VALUE; |
33c859c1 | 149 | |
708ec8fb SS |
150 | return ic; |
151 | } | |
fb4ca26b AK |
152 | |
153 | const AVClass *avformat_get_class(void) | |
154 | { | |
155 | return &av_format_context_class; | |
156 | } |