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/internal.h"
25 #include "libavutil/opt.h"
26 
27 /**
28  * @file
29  * Options definition for AVFormatContext.
30  */
31 
33 #include "options_table.h"
35 
36 static const char* format_to_name(void* ptr)
37 {
39  if(fc->iformat) return fc->iformat->name;
40  else if(fc->oformat) return fc->oformat->name;
41  else return "NULL";
42 }
43 
44 static void *format_child_next(void *obj, void *prev)
45 {
46  AVFormatContext *s = obj;
47  if (!prev && s->priv_data &&
48  ((s->iformat && s->iformat->priv_class) ||
49  s->oformat && s->oformat->priv_class))
50  return s->priv_data;
51  if (s->pb && s->pb->av_class && prev != s->pb)
52  return s->pb;
53  return NULL;
54 }
55 
56 static const AVClass *format_child_class_next(const AVClass *prev)
57 {
58  AVInputFormat *ifmt = NULL;
59  AVOutputFormat *ofmt = NULL;
60 
61  if (!prev)
62  return &ff_avio_class;
63 
64  while ((ifmt = av_iformat_next(ifmt)))
65  if (ifmt->priv_class == prev)
66  break;
67 
68  if (!ifmt)
69  while ((ofmt = av_oformat_next(ofmt)))
70  if (ofmt->priv_class == prev)
71  break;
72  if (!ofmt)
73  while (ifmt = av_iformat_next(ifmt))
74  if (ifmt->priv_class)
75  return ifmt->priv_class;
76 
77  while (ofmt = av_oformat_next(ofmt))
78  if (ofmt->priv_class)
79  return ofmt->priv_class;
80 
81  return NULL;
82 }
83 
84 static AVClassCategory get_category(void *ptr)
85 {
86  AVFormatContext* s = ptr;
87  if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
88  else return AV_CLASS_CATEGORY_MUXER;
89 }
90 
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,
99  .get_category = get_category,
100 };
101 
103  const char *url, int flags, AVDictionary **options)
104 {
105  int loglevel;
106 
107  if (!strcmp(url, s->url) ||
108  s->iformat && !strcmp(s->iformat->name, "image2") ||
109  s->oformat && !strcmp(s->oformat->name, "image2")
110  ) {
111  loglevel = AV_LOG_DEBUG;
112  } else
113  loglevel = AV_LOG_INFO;
114 
115  av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
116 
117 #if FF_API_OLD_OPEN_CALLBACKS
119  if (s->open_cb)
120  return s->open_cb(s, pb, url, flags, &s->interrupt_callback, options);
122 #endif
123 
124  return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
125 }
126 
128 {
129  avio_close(pb);
130 }
131 
133 {
134  memset(s, 0, sizeof(AVFormatContext));
135 
136  s->av_class = &av_format_context_class;
137 
138  s->io_open = io_open_default;
139  s->io_close = io_close_default;
140 
142 }
143 
145 {
146  AVFormatContext *ic;
147  ic = av_malloc(sizeof(AVFormatContext));
148  if (!ic) return ic;
150 
151  ic->internal = av_mallocz(sizeof(*ic->internal));
152  if (!ic->internal) {
154  return NULL;
155  }
159 
160  return ic;
161 }
162 
164 {
166 }
167 
169 {
170  return &av_format_context_class;
171 }
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:85
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:1305
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1185
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:168
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:1729
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:1158
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:555
ff_avio_class
const AVClass ff_avio_class
Definition: aviobuf.c:69
AVDictionary
Definition: dict.c:30
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1795
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
avformat_get_context_defaults
static void avformat_get_context_defaults(AVFormatContext *s)
Definition: options.c:132
AVFormatInternal::raw_packet_buffer_remaining_size
int raw_packet_buffer_remaining_size
Definition: internal.h:101
AVFormatInternal::offset
int64_t offset
Offset to remap timestamps to be non-negative.
Definition: internal.h:108
AVInputFormat
Definition: avformat.h:640
RAW_PACKET_BUFFER_SIZE
#define RAW_PACKET_BUFFER_SIZE
Remaining size available for raw_packet_buffer, in bytes.
Definition: internal.h:100
AVFormatInternal::shortest_end
int64_t shortest_end
Timestamp of the end of the shortest stream.
Definition: internal.h:126
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:655
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ctx
AVFormatContext * ctx
Definition: movenc.c:48
io_close_default
static void io_close_default(AVFormatContext *s, AVIOContext *pb)
Definition: options.c:127
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:34
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
internal.h
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
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:1320
AVOutputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:524
format_to_name
FF_DISABLE_DEPRECATION_WARNINGS static const FF_ENABLE_DEPRECATION_WARNINGS char * format_to_name(void *ptr)
Definition: options.c:36
options
const OptionDef options[]
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:144
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:130
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
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:163
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
get_category
static AVClassCategory get_category(void *ptr)
Definition: options.c:84
AVClassCategory
AVClassCategory
Definition: log.h:29
AVOutputFormat
Definition: avformat.h:495
avio_internal.h
internal.h
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:236
format_child_class_next
static const AVClass * format_child_class_next(const AVClass *prev)
Definition: options.c:56
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:72
avformat.h
format_child_next
static void * format_child_next(void *obj, void *prev)
Definition: options.c:44
AV_CLASS_CATEGORY_MUXER
@ AV_CLASS_CATEGORY_MUXER
Definition: log.h:33
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:4414
io_open_default
static int io_open_default(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
Definition: options.c:102
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
options_table.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:670
av_format_context_class
static const AVClass av_format_context_class
Definition: options.c:91