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 "libavutil/opt.h"
24 
30 #include "options_table.h"
31 
32 static const char* format_to_name(void* ptr)
33 {
34  AVFormatContext* fc = (AVFormatContext*) ptr;
35  if(fc->iformat) return fc->iformat->name;
36  else if(fc->oformat) return fc->oformat->name;
37  else return "NULL";
38 }
39 
40 static void *format_child_next(void *obj, void *prev)
41 {
42  AVFormatContext *s = obj;
43  if (!prev && s->priv_data &&
44  ((s->iformat && s->iformat->priv_class) ||
45  s->oformat && s->oformat->priv_class))
46  return s->priv_data;
47  if (s->pb && s->pb->av_class && prev != s->pb)
48  return s->pb;
49  return NULL;
50 }
51 
52 static const AVClass *format_child_class_next(const AVClass *prev)
53 {
54  AVInputFormat *ifmt = NULL;
55  AVOutputFormat *ofmt = NULL;
56 
57  if (!prev)
58  return &ffio_url_class;
59 
60  while ((ifmt = av_iformat_next(ifmt)))
61  if (ifmt->priv_class == prev)
62  break;
63 
64  if (!ifmt)
65  while ((ofmt = av_oformat_next(ofmt)))
66  if (ofmt->priv_class == prev)
67  break;
68  if (!ofmt)
69  while (ifmt = av_iformat_next(ifmt))
70  if (ifmt->priv_class)
71  return ifmt->priv_class;
72 
73  while (ofmt = av_oformat_next(ofmt))
74  if (ofmt->priv_class)
75  return ofmt->priv_class;
76 
77  return NULL;
78 }
79 
81  .class_name = "AVFormatContext",
82  .item_name = format_to_name,
83  .option = avformat_options,
84  .version = LIBAVUTIL_VERSION_INT,
85  .child_next = format_child_next,
86  .child_class_next = format_child_class_next,
87 };
88 
90 {
91  memset(s, 0, sizeof(AVFormatContext));
92 
94 
96 }
97 
99 {
100  AVFormatContext *ic;
101  ic = av_malloc(sizeof(AVFormatContext));
102  if (!ic) return ic;
104 
105  ic->internal = av_mallocz(sizeof(*ic->internal));
106  if (!ic->internal) {
108  return NULL;
109  }
110 
111  return ic;
112 }
113 
115 {
116  return &av_format_context_class;
117 }
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
static const AVClass av_format_context_class
Definition: options.c:80
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:544
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1256
Format I/O context.
Definition: avformat.h:922
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:38
AVOptions.
static void avformat_get_context_defaults(AVFormatContext *s)
Definition: options.c:89
const AVClass * av_class
A class for private options.
Definition: avio.h:81
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:98
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:550
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:114
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:941
static const AVOption avformat_options[]
Definition: options_table.h:33
static const AVClass * format_child_class_next(const AVClass *prev)
Definition: options.c:52
const char * name
Definition: avformat.h:446
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:474
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
const AVClass ffio_url_class
Definition: aviobuf.c:58
NULL
Definition: eval.c:55
AVIOContext * pb
I/O context.
Definition: avformat.h:964
Describe the class of an AVClass context structure.
Definition: log.h:33
static void * format_child_next(void *obj, void *prev)
Definition: options.c:40
const AVClass * av_class
A class for logging and AVOptions.
Definition: avformat.h:927
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:2424
Main libavformat public API header.
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:934
void * priv_data
Format private data.
Definition: avformat.h:950
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:525
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:205
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
static const char * format_to_name(void *ptr)
Definition: options.c:32