Libav
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 Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 #include "url.h"
24 
25 #include "libavutil/internal.h"
26 #include "libavutil/opt.h"
27 
34 #include "options_table.h"
36 
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 
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 static const AVClass *format_child_class_next(const AVClass *prev)
58 {
59  AVInputFormat *ifmt = NULL;
60  AVOutputFormat *ofmt = NULL;
61 
62  if (!prev)
63  return &ff_avio_class;
64 
65  while ((ifmt = av_iformat_next(ifmt)))
66  if (ifmt->priv_class == prev)
67  break;
68 
69  if (!ifmt)
70  while ((ofmt = av_oformat_next(ofmt)))
71  if (ofmt->priv_class == prev)
72  break;
73  if (!ofmt)
74  while (ifmt = av_iformat_next(ifmt))
75  if (ifmt->priv_class)
76  return ifmt->priv_class;
77 
78  while (ofmt = av_oformat_next(ofmt))
79  if (ofmt->priv_class)
80  return ofmt->priv_class;
81 
82  return NULL;
83 }
84 
86  .class_name = "AVFormatContext",
87  .item_name = format_to_name,
88  .option = avformat_options,
89  .version = LIBAVUTIL_VERSION_INT,
90  .child_next = format_child_next,
91  .child_class_next = format_child_class_next,
92 };
93 
95  const char *url, int flags, AVDictionary **options)
96 {
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;
117 }
118 
120 {
121  avio_close(pb);
122 }
123 
125 {
126  memset(s, 0, sizeof(AVFormatContext));
127 
129 
132 
134 }
135 
137 {
138  AVFormatContext *ic;
139  ic = av_malloc(sizeof(AVFormatContext));
140  if (!ic) return ic;
142 
143  ic->internal = av_mallocz(sizeof(*ic->internal));
144  if (!ic->internal) {
146  return NULL;
147  }
149 
150  return ic;
151 }
152 
154 {
155  return &av_format_context_class;
156 }
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:1270
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
Bytestream IO Context.
Definition: avio.h:104
static const AVClass av_format_context_class
Definition: options.c:85
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1181
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:599
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1243
int64_t offset
Offset to remap timestamps to be non-negative.
Definition: internal.h:87
Format I/O context.
Definition: avformat.h:940
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:39
AVOptions.
static void io_close_default(AVFormatContext *s, AVIOContext *pb)
Definition: options.c:119
static void avformat_get_context_defaults(AVFormatContext *s)
Definition: options.c:124
const AVClass * av_class
A class for private options.
Definition: avio.h:117
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:136
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:554
static void finish(void)
Definition: movenc.c:338
char * protocol_whitelist
A comma-separated list of protocol names that can be used internally by libavformat.
Definition: avformat.h:1294
static int flags
Definition: log.c:50
const AVClass ff_avio_class
Definition: aviobuf.c:97
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:153
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:959
const OptionDef options[]
Definition: avconv_opt.c:2447
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:983
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:175
static const AVOption avformat_options[]
Definition: options_table.h:33
static const AVClass * format_child_class_next(const AVClass *prev)
Definition: options.c:57
common internal API header
const char * name
Definition: avformat.h:450
AVOutputFormat * av_oformat_next(const AVOutputFormat *f)
If f is NULL, returns the first registered output format, if f is non-NULL, returns the next register...
Definition: format.c:47
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:478
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
NULL
Definition: eval.c:55
AVIOContext * pb
I/O context.
Definition: avformat.h:982
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition: avformat.h:1276
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:68
Describe the class of an AVClass context structure.
Definition: log.h:34
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:945
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:933
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:2594
Main libavformat public API header.
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
FF_DISABLE_DEPRECATION_WARNINGS static FF_ENABLE_DEPRECATION_WARNINGS const char * format_to_name(void *ptr)
Definition: options.c:37
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:952
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
void * priv_data
Format private data.
Definition: avformat.h:968
char * protocol_blacklist
A comma-separated list of protocol names that will not be used internally by libavformat.
Definition: avformat.h:1285
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:529
unbuffered private I/O API
static int io_open_default(AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
Definition: options.c:94
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
AVInputFormat * av_iformat_next(const AVInputFormat *f)
If f is NULL, returns the first registered input format, if f is non-NULL, returns the next registere...
Definition: format.c:39
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235