FFmpeg
options.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 #include "avformat.h"
21 #include "avio_internal.h"
22 #include "internal.h"
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/opt.h"
27 
28 /**
29  * @file
30  * Options definition for AVFormatContext.
31  */
32 
34 #include "options_table.h"
36 
37 static const char* format_to_name(void* ptr)
38 {
40  if(fc->iformat) return fc->iformat->name;
41  else if(fc->oformat) return fc->oformat->name;
42  else return "NULL";
43 }
44 
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;
52  if (s->pb && s->pb->av_class && prev != s->pb)
53  return s->pb;
54  return NULL;
55 }
56 
57 #if FF_API_CHILD_CLASS_NEXT
58 static const AVClass *format_child_class_next(const AVClass *prev)
59 {
60  const AVInputFormat *ifmt = NULL;
61  const AVOutputFormat *ofmt = NULL;
62  void *ifmt_iter = NULL, *ofmt_iter = NULL;
63 
64  if (!prev)
65  return &ff_avio_class;
66 
67  while ((ifmt = av_demuxer_iterate(&ifmt_iter)))
68  if (ifmt->priv_class == prev)
69  break;
70 
71  if (!ifmt) {
72  ifmt_iter = NULL;
73  while ((ofmt = av_muxer_iterate(&ofmt_iter)))
74  if (ofmt->priv_class == prev)
75  break;
76  }
77  if (!ofmt) {
78  ofmt_iter = NULL;
79  while ((ifmt = av_demuxer_iterate(&ifmt_iter)))
80  if (ifmt->priv_class)
81  return ifmt->priv_class;
82  }
83 
84  while ((ofmt = av_muxer_iterate(&ofmt_iter)))
85  if (ofmt->priv_class)
86  return ofmt->priv_class;
87 
88  return NULL;
89 }
90 #endif
91 
92 enum {
97 
98 };
99 
100 #define ITER_STATE_SHIFT 16
101 
102 static const AVClass *format_child_class_iterate(void **iter)
103 {
104  // we use the low 16 bits of iter as the value to be passed to
105  // av_(de)muxer_iterate()
106  void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1));
107  unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT;
108  const AVClass *ret = NULL;
109 
110  if (state == CHILD_CLASS_ITER_AVIO) {
111  ret = &ff_avio_class;
112  state++;
113  goto finish;
114  }
115 
116  if (state == CHILD_CLASS_ITER_MUX) {
117  const AVOutputFormat *ofmt;
118 
119  while ((ofmt = av_muxer_iterate(&val))) {
120  ret = ofmt->priv_class;
121  if (ret)
122  goto finish;
123  }
124 
125  val = NULL;
126  state++;
127  }
128 
129  if (state == CHILD_CLASS_ITER_DEMUX) {
130  const AVInputFormat *ifmt;
131 
132  while ((ifmt = av_demuxer_iterate(&val))) {
133  ret = ifmt->priv_class;
134  if (ret)
135  goto finish;
136  }
137  val = NULL;
138  state++;
139  }
140 
141 finish:
142  // make sure none av_(de)muxer_iterate does not set the high bits of val
143  av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT));
144  *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT));
145  return ret;
146 }
147 
148 static AVClassCategory get_category(void *ptr)
149 {
150  AVFormatContext* s = ptr;
151  if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
152  else return AV_CLASS_CATEGORY_MUXER;
153 }
154 
156  .class_name = "AVFormatContext",
157  .item_name = format_to_name,
158  .option = avformat_options,
159  .version = LIBAVUTIL_VERSION_INT,
160  .child_next = format_child_next,
161 #if FF_API_CHILD_CLASS_NEXT
162  .child_class_next = format_child_class_next,
163 #endif
164  .child_class_iterate = format_child_class_iterate,
166  .get_category = get_category,
167 };
168 
170  const char *url, int flags, AVDictionary **options)
171 {
172  int loglevel;
173 
174  if (!strcmp(url, s->url) ||
175  s->iformat && !strcmp(s->iformat->name, "image2") ||
176  s->oformat && !strcmp(s->oformat->name, "image2")
177  ) {
178  loglevel = AV_LOG_DEBUG;
179  } else
180  loglevel = AV_LOG_INFO;
181 
182  av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
183 
184 #if FF_API_OLD_OPEN_CALLBACKS
186  if (s->open_cb)
187  return s->open_cb(s, pb, url, flags, &s->interrupt_callback, options);
189 #endif
190 
191  return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
192 }
193 
195 {
196  avio_close(pb);
197 }
198 
200 {
201  memset(s, 0, sizeof(AVFormatContext));
202 
204 
207 
209 }
210 
212 {
213  AVFormatContext *ic;
214  AVFormatInternal *internal;
215  ic = av_malloc(sizeof(AVFormatContext));
216  if (!ic) return ic;
217 
218  internal = av_mallocz(sizeof(*internal));
219  if (!internal) {
220  av_free(ic);
221  return NULL;
222  }
224  ic->internal = internal;
228 
229  return ic;
230 }
231 
233 {
234  return ctx->duration_estimation_method;
235 }
236 
238 {
239  return &av_format_context_class;
240 }
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Definition: avformat.h:1937
#define NULL
Definition: coverity.c:32
Bytestream IO Context.
Definition: avio.h:161
static const AVClass av_format_context_class
Definition: options.c:155
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1633
enum AVDurationEstimationMethod duration_estimation_method
The duration field can be estimated through various ways, and this field can be used to know how the ...
Definition: avformat.h:1742
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1357
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1808
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:675
enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext *ctx)
Returns the method used to set ctx->duration.
Definition: options.c:232
int64_t offset
Offset to remap timestamps to be non-negative.
Definition: internal.h:106
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
Format I/O context.
Definition: avformat.h:1355
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define ITER_STATE_SHIFT
Definition: options.c:100
static const AVClass * format_child_class_iterate(void **iter)
Definition: options.c:102
#define av_malloc(s)
AVOptions.
static void io_close_default(AVFormatContext *s, AVIOContext *pb)
Definition: options.c:194
AVDurationEstimationMethod
The duration of a video can be estimated through various ways, and this enum can be used to know how ...
Definition: avformat.h:1333
static void avformat_get_context_defaults(AVFormatContext *s)
Definition: options.c:199
const AVClass * av_class
A class for private options.
Definition: avio.h:174
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:211
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:677
static void finish(void)
Definition: movenc.c:345
static AVClassCategory get_category(void *ptr)
Definition: options.c:148
char * protocol_whitelist
&#39;,&#39; separated list of allowed protocols.
Definition: avformat.h:1915
const AVClass ff_avio_class
Definition: aviobuf.c:73
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:237
int raw_packet_buffer_remaining_size
Definition: internal.h:99
#define av_log(a,...)
const AVOutputFormat * av_muxer_iterate(void **opaque)
Iterate over all registered muxers.
Definition: allformats.c:533
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:550
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1171
ff_const59 struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1367
char * url
input or output URL.
Definition: avformat.h:1451
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
static const AVOption avformat_options[]
Definition: options_table.h:36
simple assert() macros that are a bit more flexible than ISO C assert().
AVClassCategory category
Category used for visualization (like color) This is only set if the category is equal for all object...
Definition: log.h:133
common internal API header
static struct @322 state
int64_t shortest_end
Timestamp of the end of the shortest stream.
Definition: internal.h:124
const char * name
Definition: avformat.h:500
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
static const AVOption options[]
Definition: options.c:37
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:528
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
Definition: allformats.c:550
ff_const59 struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1374
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
AVIOContext * pb
I/O context.
Definition: avformat.h:1397
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition: avformat.h:1943
Describe the class of an AVClass context structure.
Definition: log.h:67
static void * format_child_next(void *obj, void *prev)
Definition: options.c:45
const AVClass * av_class
A class for logging and AVOptions.
Definition: avformat.h:1360
#define RAW_PACKET_BUFFER_SIZE
Remaining size available for raw_packet_buffer, in bytes.
Definition: internal.h:98
int ffio_open_whitelist(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
Definition: aviobuf.c:1144
#define flags(name, subs,...)
Definition: cbs_av1.c:560
Main libavformat public API header.
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
FF_DISABLE_DEPRECATION_WARNINGS static FF_ENABLE_DEPRECATION_WARNINGS const char * format_to_name(void *ptr)
Definition: options.c:37
#define av_free(p)
AVClassCategory
Definition: log.h:29
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:85
void * priv_data
Format private data.
Definition: avformat.h:1383
char * protocol_blacklist
&#39;,&#39; separated list of disallowed protocols.
Definition: avformat.h:1950
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:652
static int io_open_default(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
Definition: options.c:169
static double val(void *priv, double ch)
Definition: aeval.c:76
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248