yading@11: /* yading@11: * Copyright (c) 2000, 2001, 2002 Fabrice Bellard yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: #include "avformat.h" yading@11: #include "avio_internal.h" yading@11: #include "libavutil/opt.h" yading@11: yading@11: /** yading@11: * @file yading@11: * Options definition for AVFormatContext. yading@11: */ yading@11: yading@11: #include "options_table.h" yading@11: yading@11: static const char* format_to_name(void* ptr) yading@11: { yading@11: AVFormatContext* fc = (AVFormatContext*) ptr; yading@11: if(fc->iformat) return fc->iformat->name; yading@11: else if(fc->oformat) return fc->oformat->name; yading@11: else return "NULL"; yading@11: } yading@11: yading@11: static void *format_child_next(void *obj, void *prev) yading@11: { yading@11: AVFormatContext *s = obj; yading@11: if (!prev && s->priv_data && yading@11: ((s->iformat && s->iformat->priv_class) || yading@11: s->oformat && s->oformat->priv_class)) yading@11: return s->priv_data; yading@11: if (s->pb && s->pb->av_class && prev != s->pb) yading@11: return s->pb; yading@11: return NULL; yading@11: } yading@11: yading@11: static const AVClass *format_child_class_next(const AVClass *prev) yading@11: { yading@11: AVInputFormat *ifmt = NULL; yading@11: AVOutputFormat *ofmt = NULL; yading@11: yading@11: if (!prev) yading@11: return &ffio_url_class; yading@11: yading@11: while ((ifmt = av_iformat_next(ifmt))) yading@11: if (ifmt->priv_class == prev) yading@11: break; yading@11: yading@11: if (!ifmt) yading@11: while ((ofmt = av_oformat_next(ofmt))) yading@11: if (ofmt->priv_class == prev) yading@11: break; yading@11: if (!ofmt) yading@11: while (ifmt = av_iformat_next(ifmt)) yading@11: if (ifmt->priv_class) yading@11: return ifmt->priv_class; yading@11: yading@11: while (ofmt = av_oformat_next(ofmt)) yading@11: if (ofmt->priv_class) yading@11: return ofmt->priv_class; yading@11: yading@11: return NULL; yading@11: } yading@11: yading@11: static AVClassCategory get_category(void *ptr) yading@11: { yading@11: AVFormatContext* s = ptr; yading@11: if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER; yading@11: else return AV_CLASS_CATEGORY_MUXER; yading@11: } yading@11: yading@11: static const AVClass av_format_context_class = { yading@11: .class_name = "AVFormatContext", yading@11: .item_name = format_to_name, yading@11: .option = options, yading@11: .version = LIBAVUTIL_VERSION_INT, yading@11: .child_next = format_child_next, yading@11: .child_class_next = format_child_class_next, yading@11: .category = AV_CLASS_CATEGORY_MUXER, yading@11: .get_category = get_category, yading@11: }; yading@11: yading@11: static void avformat_get_context_defaults(AVFormatContext *s) yading@11: { yading@11: memset(s, 0, sizeof(AVFormatContext)); yading@11: yading@11: s->av_class = &av_format_context_class; yading@11: yading@11: av_opt_set_defaults(s); yading@11: } yading@11: yading@11: AVFormatContext *avformat_alloc_context(void) yading@11: { yading@11: AVFormatContext *ic; yading@11: ic = av_malloc(sizeof(AVFormatContext)); yading@11: if (!ic) return ic; yading@11: avformat_get_context_defaults(ic); yading@11: return ic; yading@11: } yading@11: yading@11: enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx) yading@11: { yading@11: return ctx->duration_estimation_method; yading@11: } yading@11: yading@11: const AVClass *avformat_get_class(void) yading@11: { yading@11: return &av_format_context_class; yading@11: }