yading@11
|
1 /*
|
yading@11
|
2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
yading@11
|
3 *
|
yading@11
|
4 * This file is part of FFmpeg.
|
yading@11
|
5 *
|
yading@11
|
6 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
8 * License as published by the Free Software Foundation; either
|
yading@11
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
10 *
|
yading@11
|
11 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
14 * Lesser General Public License for more details.
|
yading@11
|
15 *
|
yading@11
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
17 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
19 */
|
yading@11
|
20 #include "avformat.h"
|
yading@11
|
21 #include "avio_internal.h"
|
yading@11
|
22 #include "libavutil/opt.h"
|
yading@11
|
23
|
yading@11
|
24 /**
|
yading@11
|
25 * @file
|
yading@11
|
26 * Options definition for AVFormatContext.
|
yading@11
|
27 */
|
yading@11
|
28
|
yading@11
|
29 #include "options_table.h"
|
yading@11
|
30
|
yading@11
|
31 static const char* format_to_name(void* ptr)
|
yading@11
|
32 {
|
yading@11
|
33 AVFormatContext* fc = (AVFormatContext*) ptr;
|
yading@11
|
34 if(fc->iformat) return fc->iformat->name;
|
yading@11
|
35 else if(fc->oformat) return fc->oformat->name;
|
yading@11
|
36 else return "NULL";
|
yading@11
|
37 }
|
yading@11
|
38
|
yading@11
|
39 static void *format_child_next(void *obj, void *prev)
|
yading@11
|
40 {
|
yading@11
|
41 AVFormatContext *s = obj;
|
yading@11
|
42 if (!prev && s->priv_data &&
|
yading@11
|
43 ((s->iformat && s->iformat->priv_class) ||
|
yading@11
|
44 s->oformat && s->oformat->priv_class))
|
yading@11
|
45 return s->priv_data;
|
yading@11
|
46 if (s->pb && s->pb->av_class && prev != s->pb)
|
yading@11
|
47 return s->pb;
|
yading@11
|
48 return NULL;
|
yading@11
|
49 }
|
yading@11
|
50
|
yading@11
|
51 static const AVClass *format_child_class_next(const AVClass *prev)
|
yading@11
|
52 {
|
yading@11
|
53 AVInputFormat *ifmt = NULL;
|
yading@11
|
54 AVOutputFormat *ofmt = NULL;
|
yading@11
|
55
|
yading@11
|
56 if (!prev)
|
yading@11
|
57 return &ffio_url_class;
|
yading@11
|
58
|
yading@11
|
59 while ((ifmt = av_iformat_next(ifmt)))
|
yading@11
|
60 if (ifmt->priv_class == prev)
|
yading@11
|
61 break;
|
yading@11
|
62
|
yading@11
|
63 if (!ifmt)
|
yading@11
|
64 while ((ofmt = av_oformat_next(ofmt)))
|
yading@11
|
65 if (ofmt->priv_class == prev)
|
yading@11
|
66 break;
|
yading@11
|
67 if (!ofmt)
|
yading@11
|
68 while (ifmt = av_iformat_next(ifmt))
|
yading@11
|
69 if (ifmt->priv_class)
|
yading@11
|
70 return ifmt->priv_class;
|
yading@11
|
71
|
yading@11
|
72 while (ofmt = av_oformat_next(ofmt))
|
yading@11
|
73 if (ofmt->priv_class)
|
yading@11
|
74 return ofmt->priv_class;
|
yading@11
|
75
|
yading@11
|
76 return NULL;
|
yading@11
|
77 }
|
yading@11
|
78
|
yading@11
|
79 static AVClassCategory get_category(void *ptr)
|
yading@11
|
80 {
|
yading@11
|
81 AVFormatContext* s = ptr;
|
yading@11
|
82 if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
|
yading@11
|
83 else return AV_CLASS_CATEGORY_MUXER;
|
yading@11
|
84 }
|
yading@11
|
85
|
yading@11
|
86 static const AVClass av_format_context_class = {
|
yading@11
|
87 .class_name = "AVFormatContext",
|
yading@11
|
88 .item_name = format_to_name,
|
yading@11
|
89 .option = options,
|
yading@11
|
90 .version = LIBAVUTIL_VERSION_INT,
|
yading@11
|
91 .child_next = format_child_next,
|
yading@11
|
92 .child_class_next = format_child_class_next,
|
yading@11
|
93 .category = AV_CLASS_CATEGORY_MUXER,
|
yading@11
|
94 .get_category = get_category,
|
yading@11
|
95 };
|
yading@11
|
96
|
yading@11
|
97 static void avformat_get_context_defaults(AVFormatContext *s)
|
yading@11
|
98 {
|
yading@11
|
99 memset(s, 0, sizeof(AVFormatContext));
|
yading@11
|
100
|
yading@11
|
101 s->av_class = &av_format_context_class;
|
yading@11
|
102
|
yading@11
|
103 av_opt_set_defaults(s);
|
yading@11
|
104 }
|
yading@11
|
105
|
yading@11
|
106 AVFormatContext *avformat_alloc_context(void)
|
yading@11
|
107 {
|
yading@11
|
108 AVFormatContext *ic;
|
yading@11
|
109 ic = av_malloc(sizeof(AVFormatContext));
|
yading@11
|
110 if (!ic) return ic;
|
yading@11
|
111 avformat_get_context_defaults(ic);
|
yading@11
|
112 return ic;
|
yading@11
|
113 }
|
yading@11
|
114
|
yading@11
|
115 enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx)
|
yading@11
|
116 {
|
yading@11
|
117 return ctx->duration_estimation_method;
|
yading@11
|
118 }
|
yading@11
|
119
|
yading@11
|
120 const AVClass *avformat_get_class(void)
|
yading@11
|
121 {
|
yading@11
|
122 return &av_format_context_class;
|
yading@11
|
123 }
|