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 enum {
62 
63 };
64 
65 #define ITER_STATE_SHIFT 16
66 
67 static const AVClass *format_child_class_iterate(void **iter)
68 {
69  // we use the low 16 bits of iter as the value to be passed to
70  // av_(de)muxer_iterate()
71  void *val = (void*)(((uintptr_t)*iter) & ((1 << ITER_STATE_SHIFT) - 1));
72  unsigned int state = ((uintptr_t)*iter) >> ITER_STATE_SHIFT;
73  const AVClass *ret = NULL;
74 
76  ret = &ff_avio_class;
77  state++;
78  goto finish;
79  }
80 
81  if (state == CHILD_CLASS_ITER_MUX) {
82  const AVOutputFormat *ofmt;
83 
84  while ((ofmt = av_muxer_iterate(&val))) {
85  ret = ofmt->priv_class;
86  if (ret)
87  goto finish;
88  }
89 
90  val = NULL;
91  state++;
92  }
93 
95  const AVInputFormat *ifmt;
96 
97  while ((ifmt = av_demuxer_iterate(&val))) {
98  ret = ifmt->priv_class;
99  if (ret)
100  goto finish;
101  }
102  val = NULL;
103  state++;
104  }
105 
106 finish:
107  // make sure none av_(de)muxer_iterate does not set the high bits of val
108  av_assert0(!((uintptr_t)val >> ITER_STATE_SHIFT));
109  *iter = (void*)((uintptr_t)val | (state << ITER_STATE_SHIFT));
110  return ret;
111 }
112 
113 static AVClassCategory get_category(void *ptr)
114 {
115  AVFormatContext* s = ptr;
116  if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
117  else return AV_CLASS_CATEGORY_MUXER;
118 }
119 
121  .class_name = "AVFormatContext",
122  .item_name = format_to_name,
123  .option = avformat_options,
124  .version = LIBAVUTIL_VERSION_INT,
125  .child_next = format_child_next,
126  .child_class_iterate = format_child_class_iterate,
128  .get_category = get_category,
129 };
130 
132  const char *url, int flags, AVDictionary **options)
133 {
134  int loglevel;
135 
136  if (!strcmp(url, s->url) ||
137  s->iformat && !strcmp(s->iformat->name, "image2") ||
138  s->oformat && !strcmp(s->oformat->name, "image2")
139  ) {
140  loglevel = AV_LOG_DEBUG;
141  } else
142  loglevel = AV_LOG_INFO;
143 
144  av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
145 
146  return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
147 }
148 
150 {
151  return avio_close(pb);
152 }
153 
155 {
156  FFFormatContext *const si = av_mallocz(sizeof(*si));
158 
159  if (!si)
160  return NULL;
161 
162  s = &si->pub;
163  s->av_class = &av_format_context_class;
164  s->io_open = io_open_default;
165  s->io_close = ff_format_io_close_default;
166  s->io_close2= io_close2_default;
167 
169 
170  si->pkt = av_packet_alloc();
171  si->parse_pkt = av_packet_alloc();
172  if (!si->pkt || !si->parse_pkt) {
174  return NULL;
175  }
176 
177  si->offset = AV_NOPTS_VALUE;
179 
180  return s;
181 }
182 
184 {
186 }
187 
189 {
190  return &av_format_context_class;
191 }
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
opt.h
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1364
ITER_STATE_SHIFT
#define ITER_STATE_SHIFT
Definition: options.c:65
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1252
format_child_class_iterate
static const AVClass * format_child_class_iterate(void **iter)
Definition: options.c:67
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:188
AVFormatContext::duration_estimation_method
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:1588
ffio_open_whitelist
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:1225
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:551
ff_avio_class
const AVClass ff_avio_class
Definition: aviobuf.c:67
AVDictionary
Definition: dict.c:30
FFFormatContext::shortest_end
int64_t shortest_end
Timestamp of the end of the shortest stream.
Definition: internal.h:161
finish
static void finish(void)
Definition: movenc.c:342
val
static double val(void *priv, double ch)
Definition: aeval.c:76
CHILD_CLASS_ITER_DEMUX
@ CHILD_CLASS_ITER_DEMUX
Definition: options.c:60
avassert.h
AVInputFormat
Definition: avformat.h:650
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:622
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
FFFormatContext
Definition: internal.h:73
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
internal.h
CHILD_CLASS_ITER_MUX
@ CHILD_CLASS_ITER_MUX
Definition: options.c:59
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
avformat_options
static const AVOption avformat_options[]
Definition: options_table.h:36
AVDurationEstimationMethod
AVDurationEstimationMethod
The duration of a video can be estimated through various ways, and this enum can be used to know how ...
Definition: avformat.h:1180
AVOutputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:532
format_to_name
FF_DISABLE_DEPRECATION_WARNINGS static const FF_ENABLE_DEPRECATION_WARNINGS char * format_to_name(void *ptr)
Definition: options.c:37
options
const OptionDef options[]
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
state
static struct @320 state
FFFormatContext::parse_pkt
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
Definition: internal.h:125
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:154
AVClass::category
AVClassCategory category
Category used for visualization (like color) This is only set if the category is equal for all object...
Definition: log.h:114
ff_format_io_close_default
void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb)
Definition: utils.c:1843
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
av_demuxer_iterate
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
Definition: allformats.c:564
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:64
av_fmt_ctx_get_duration_estimation_method
enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext *ctx)
Returns the method used to set ctx->duration.
Definition: options.c:183
CHILD_CLASS_ITER_AVIO
@ CHILD_CLASS_ITER_AVIO
Definition: options.c:58
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
get_category
static AVClassCategory get_category(void *ptr)
Definition: options.c:113
AVClassCategory
AVClassCategory
Definition: log.h:28
AVOutputFormat
Definition: avformat.h:503
avio_internal.h
internal.h
io_close2_default
static int io_close2_default(AVFormatContext *s, AVIOContext *pb)
Definition: options.c:149
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
CHILD_CLASS_ITER_DONE
@ CHILD_CLASS_ITER_DONE
Definition: options.c:61
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
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:71
avformat.h
format_child_next
static void * format_child_next(void *obj, void *prev)
Definition: options.c:45
av_muxer_iterate
const AVOutputFormat * av_muxer_iterate(void **opaque)
Iterate over all registered muxers.
Definition: allformats.c:545
AV_CLASS_CATEGORY_MUXER
@ AV_CLASS_CATEGORY_MUXER
Definition: log.h:32
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:688
FFFormatContext::offset
int64_t offset
Offset to remap timestamps to be non-negative.
Definition: internal.h:143
io_open_default
static int io_open_default(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
Definition: options.c:131
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:82
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:132
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
options_table.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
FFFormatContext::pub
AVFormatContext pub
The public context.
Definition: internal.h:77
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:680
av_format_context_class
static const AVClass av_format_context_class
Definition: options.c:120