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 static const char* format_to_name(void* ptr)
00030 {
00031 AVFormatContext* fc = (AVFormatContext*) ptr;
00032 if(fc->iformat) return fc->iformat->name;
00033 else if(fc->oformat) return fc->oformat->name;
00034 else return "NULL";
00035 }
00036
00037 static void *format_child_next(void *obj, void *prev)
00038 {
00039 AVFormatContext *s = obj;
00040 if (!prev && s->priv_data &&
00041 ((s->iformat && s->iformat->priv_class) ||
00042 s->oformat && s->oformat->priv_class))
00043 return s->priv_data;
00044 #if !FF_API_OLD_AVIO
00045 if (s->pb && s->pb->av_class && prev != s->pb)
00046 return s->pb;
00047 #endif
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 #if !FF_API_OLD_AVIO
00058 return &ffio_url_class;
00059 #else
00060 prev = (void *)&ifmt;
00061 #endif
00062
00063 while ((ifmt = av_iformat_next(ifmt)))
00064 if (ifmt->priv_class == prev)
00065 break;
00066
00067 if (!ifmt)
00068 while ((ofmt = av_oformat_next(ofmt)))
00069 if (ofmt->priv_class == prev)
00070 break;
00071 if (!ofmt)
00072 while (ifmt = av_iformat_next(ifmt))
00073 if (ifmt->priv_class)
00074 return ifmt->priv_class;
00075
00076 while (ofmt = av_oformat_next(ofmt))
00077 if (ofmt->priv_class)
00078 return ofmt->priv_class;
00079
00080 return NULL;
00081 }
00082
00083 #define OFFSET(x) offsetof(AVFormatContext,x)
00084 #define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
00085
00086 #define E AV_OPT_FLAG_ENCODING_PARAM
00087 #define D AV_OPT_FLAG_DECODING_PARAM
00088
00089 static const AVOption options[]={
00090 {"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D},
00091 #if FF_API_MUXRATE
00092 {"muxrate", "set mux rate", OFFSET(mux_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
00093 #endif
00094 {"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
00095 {"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
00096 {"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
00097 {"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
00098 {"nofillin", "do not fill in missing values that can be exactly calculated", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},
00099 {"noparse", "disable AVParsers, this needs nofillin too", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"},
00100 {"igndts", "ignore dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"},
00101 #if FF_API_FLAG_RTP_HINT
00102 {"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"},
00103 #endif
00104 {"discardcorrupt", "discard corrupted frames", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"},
00105 {"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, "fflags"},
00106 {"keepside", "dont merge side data", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"},
00107 {"latm", "enable RTP MP4A-LATM payload", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"},
00108 {"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
00109 {"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
00110 {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
00111 {"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D},
00112 {"fdebug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
00113 {"ts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
00114 {"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
00115 {"fer", "set error detection aggressivity", OFFSET(error_recognition), AV_OPT_TYPE_INT, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, D, "fer"},
00116 {"careful", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, D, "fer"},
00117 {"explode", "abort decoding on error recognition", 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_EXPLODE }, INT_MIN, INT_MAX, D, "fer"},
00118 {"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
00119 {"audio_preload", "microseconds by which audio packets should be interleaved earlier", OFFSET(audio_preload), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
00120 {"chunk_duration", "microseconds for each chunk", OFFSET(max_chunk_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
00121 {"chunk_size", "size in bytes for each chunk", OFFSET(max_chunk_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
00122 {NULL},
00123 };
00124
00125 #undef E
00126 #undef D
00127 #undef DEFAULT
00128
00129 static const AVClass av_format_context_class = {
00130 .class_name = "AVFormatContext",
00131 .item_name = format_to_name,
00132 .option = options,
00133 .version = LIBAVUTIL_VERSION_INT,
00134 .child_next = format_child_next,
00135 .child_class_next = format_child_class_next,
00136 };
00137
00138 static void avformat_get_context_defaults(AVFormatContext *s)
00139 {
00140 memset(s, 0, sizeof(AVFormatContext));
00141
00142 s->av_class = &av_format_context_class;
00143
00144 av_opt_set_defaults(s);
00145 }
00146
00147 AVFormatContext *avformat_alloc_context(void)
00148 {
00149 AVFormatContext *ic;
00150 ic = av_malloc(sizeof(AVFormatContext));
00151 if (!ic) return ic;
00152 avformat_get_context_defaults(ic);
00153 return ic;
00154 }
00155
00156 const AVClass *avformat_get_class(void)
00157 {
00158 return &av_format_context_class;
00159 }