2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * This file is part of FFmpeg.
6 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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"
24 #include "libavutil/internal.h"
25 #include "libavutil/opt.h"
29 * Options definition for AVFormatContext.
32 FF_DISABLE_DEPRECATION_WARNINGS
33 #include "options_table.h"
34 FF_ENABLE_DEPRECATION_WARNINGS
36 static const char* format_to_name(void* ptr)
38 AVFormatContext* fc = (AVFormatContext*) ptr;
39 if(fc->iformat) return fc->iformat->name;
40 else if(fc->oformat) return fc->oformat->name;
44 static void *format_child_next(void *obj, void *prev)
46 AVFormatContext *s = obj;
47 if (!prev && s->priv_data &&
48 ((s->iformat && s->iformat->priv_class) ||
49 s->oformat && s->oformat->priv_class))
51 if (s->pb && s->pb->av_class && prev != s->pb)
56 static const AVClass *format_child_class_next(const AVClass *prev)
58 AVInputFormat *ifmt = NULL;
59 AVOutputFormat *ofmt = NULL;
62 return &ff_avio_class;
64 while ((ifmt = av_iformat_next(ifmt)))
65 if (ifmt->priv_class == prev)
69 while ((ofmt = av_oformat_next(ofmt)))
70 if (ofmt->priv_class == prev)
73 while (ifmt = av_iformat_next(ifmt))
75 return ifmt->priv_class;
77 while (ofmt = av_oformat_next(ofmt))
79 return ofmt->priv_class;
84 static AVClassCategory get_category(void *ptr)
86 AVFormatContext* s = ptr;
87 if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
88 else return AV_CLASS_CATEGORY_MUXER;
91 static const AVClass av_format_context_class = {
92 .class_name = "AVFormatContext",
93 .item_name = format_to_name,
94 .option = avformat_options,
95 .version = LIBAVUTIL_VERSION_INT,
96 .child_next = format_child_next,
97 .child_class_next = format_child_class_next,
98 .category = AV_CLASS_CATEGORY_MUXER,
99 .get_category = get_category,
102 static int io_open_default(AVFormatContext *s, AVIOContext **pb,
103 const char *url, int flags, AVDictionary **options)
105 #if FF_API_OLD_OPEN_CALLBACKS
106 FF_DISABLE_DEPRECATION_WARNINGS
108 return s->open_cb(s, pb, url, flags, &s->interrupt_callback, options);
109 FF_ENABLE_DEPRECATION_WARNINGS
112 return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
115 static void io_close_default(AVFormatContext *s, AVIOContext *pb)
120 static void avformat_get_context_defaults(AVFormatContext *s)
122 memset(s, 0, sizeof(AVFormatContext));
124 s->av_class = &av_format_context_class;
126 s->io_open = io_open_default;
127 s->io_close = io_close_default;
129 av_opt_set_defaults(s);
132 AVFormatContext *avformat_alloc_context(void)
135 ic = av_malloc(sizeof(AVFormatContext));
137 avformat_get_context_defaults(ic);
139 ic->internal = av_mallocz(sizeof(*ic->internal));
141 avformat_free_context(ic);
144 ic->internal->offset = AV_NOPTS_VALUE;
145 ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
146 ic->internal->shortest_end = AV_NOPTS_VALUE;
151 enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx)
153 return ctx->duration_estimation_method;
156 const AVClass *avformat_get_class(void)
158 return &av_format_context_class;