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