Merge remote-tracking branch 'libav/master'
[FFMpeg-mirror/mplayer-patches.git] / libavformat / options.c
blob3399dd43977366759677d70d9f5e9c142b36b1fb
1 /*
2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "avformat.h"
21 #include "avio_internal.h"
22 #include "libavutil/opt.h"
24 /**
25 * @file
26 * Options definition for AVFormatContext.
29 #include "options_table.h"
31 static const char* format_to_name(void* ptr)
33 AVFormatContext* fc = (AVFormatContext*) ptr;
34 if(fc->iformat) return fc->iformat->name;
35 else if(fc->oformat) return fc->oformat->name;
36 else return "NULL";
39 static void *format_child_next(void *obj, void *prev)
41 AVFormatContext *s = obj;
42 if (!prev && s->priv_data &&
43 ((s->iformat && s->iformat->priv_class) ||
44 s->oformat && s->oformat->priv_class))
45 return s->priv_data;
46 if (s->pb && s->pb->av_class && prev != s->pb)
47 return s->pb;
48 return NULL;
51 static const AVClass *format_child_class_next(const AVClass *prev)
53 AVInputFormat *ifmt = NULL;
54 AVOutputFormat *ofmt = NULL;
56 if (!prev)
57 return &ffio_url_class;
59 while ((ifmt = av_iformat_next(ifmt)))
60 if (ifmt->priv_class == prev)
61 break;
63 if (!ifmt)
64 while ((ofmt = av_oformat_next(ofmt)))
65 if (ofmt->priv_class == prev)
66 break;
67 if (!ofmt)
68 while (ifmt = av_iformat_next(ifmt))
69 if (ifmt->priv_class)
70 return ifmt->priv_class;
72 while (ofmt = av_oformat_next(ofmt))
73 if (ofmt->priv_class)
74 return ofmt->priv_class;
76 return NULL;
79 static const AVClass av_format_context_class = {
80 .class_name = "AVFormatContext",
81 .item_name = format_to_name,
82 .option = options,
83 .version = LIBAVUTIL_VERSION_INT,
84 .child_next = format_child_next,
85 .child_class_next = format_child_class_next,
88 static void avformat_get_context_defaults(AVFormatContext *s)
90 memset(s, 0, sizeof(AVFormatContext));
92 s->av_class = &av_format_context_class;
94 av_opt_set_defaults(s);
97 AVFormatContext *avformat_alloc_context(void)
99 AVFormatContext *ic;
100 ic = av_malloc(sizeof(AVFormatContext));
101 if (!ic) return ic;
102 avformat_get_context_defaults(ic);
103 return ic;
106 const AVClass *avformat_get_class(void)
108 return &av_format_context_class;