00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "avformat.h"
00021 #include "avio_internal.h"
00022 #include "libavutil/opt.h"
00023
00029 #include "options_table.h"
00030
00031 static const char* format_to_name(void* ptr)
00032 {
00033 AVFormatContext* fc = (AVFormatContext*) ptr;
00034 if(fc->iformat) return fc->iformat->name;
00035 else if(fc->oformat) return fc->oformat->name;
00036 else return "NULL";
00037 }
00038
00039 static void *format_child_next(void *obj, void *prev)
00040 {
00041 AVFormatContext *s = obj;
00042 if (!prev && s->priv_data &&
00043 ((s->iformat && s->iformat->priv_class) ||
00044 s->oformat && s->oformat->priv_class))
00045 return s->priv_data;
00046 if (s->pb && s->pb->av_class && prev != s->pb)
00047 return s->pb;
00048 return NULL;
00049 }
00050
00051 static const AVClass *format_child_class_next(const AVClass *prev)
00052 {
00053 AVInputFormat *ifmt = NULL;
00054 AVOutputFormat *ofmt = NULL;
00055
00056 if (!prev)
00057 return &ffio_url_class;
00058
00059 while ((ifmt = av_iformat_next(ifmt)))
00060 if (ifmt->priv_class == prev)
00061 break;
00062
00063 if (!ifmt)
00064 while ((ofmt = av_oformat_next(ofmt)))
00065 if (ofmt->priv_class == prev)
00066 break;
00067 if (!ofmt)
00068 while (ifmt = av_iformat_next(ifmt))
00069 if (ifmt->priv_class)
00070 return ifmt->priv_class;
00071
00072 while (ofmt = av_oformat_next(ofmt))
00073 if (ofmt->priv_class)
00074 return ofmt->priv_class;
00075
00076 return NULL;
00077 }
00078
00079 static AVClassCategory get_category(void *ptr)
00080 {
00081 AVFormatContext* s = ptr;
00082 if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
00083 else return AV_CLASS_CATEGORY_MUXER;
00084 }
00085
00086 static const AVClass av_format_context_class = {
00087 .class_name = "AVFormatContext",
00088 .item_name = format_to_name,
00089 .option = options,
00090 .version = LIBAVUTIL_VERSION_INT,
00091 .child_next = format_child_next,
00092 .child_class_next = format_child_class_next,
00093 .category = AV_CLASS_CATEGORY_MUXER,
00094 .get_category = get_category,
00095 };
00096
00097 static void avformat_get_context_defaults(AVFormatContext *s)
00098 {
00099 memset(s, 0, sizeof(AVFormatContext));
00100
00101 s->av_class = &av_format_context_class;
00102
00103 av_opt_set_defaults(s);
00104 }
00105
00106 AVFormatContext *avformat_alloc_context(void)
00107 {
00108 AVFormatContext *ic;
00109 ic = av_malloc(sizeof(AVFormatContext));
00110 if (!ic) return ic;
00111 avformat_get_context_defaults(ic);
00112 return ic;
00113 }
00114
00115 enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx)
00116 {
00117 return ctx->duration_estimation_method;
00118 }
00119
00120 const AVClass *avformat_get_class(void)
00121 {
00122 return &av_format_context_class;
00123 }