00001 /* 00002 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard 00003 * 00004 * This file is part of FFmpeg. 00005 * 00006 * FFmpeg is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * FFmpeg is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with FFmpeg; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 const AVClass av_format_context_class = { 00080 .class_name = "AVFormatContext", 00081 .item_name = format_to_name, 00082 .option = options, 00083 .version = LIBAVUTIL_VERSION_INT, 00084 .child_next = format_child_next, 00085 .child_class_next = format_child_class_next, 00086 }; 00087 00088 static void avformat_get_context_defaults(AVFormatContext *s) 00089 { 00090 memset(s, 0, sizeof(AVFormatContext)); 00091 00092 s->av_class = &av_format_context_class; 00093 00094 av_opt_set_defaults(s); 00095 } 00096 00097 AVFormatContext *avformat_alloc_context(void) 00098 { 00099 AVFormatContext *ic; 00100 ic = av_malloc(sizeof(AVFormatContext)); 00101 if (!ic) return ic; 00102 avformat_get_context_defaults(ic); 00103 return ic; 00104 } 00105 00106 const AVClass *avformat_get_class(void) 00107 { 00108 return &av_format_context_class; 00109 }