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 {"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
00116 {"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},
00117 {"chunk_duration", "microseconds for each chunk", OFFSET(max_chunk_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
00118 {"chunk_size", "size in bytes for each chunk", OFFSET(max_chunk_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E},
00119
00120
00121 {"f_err_detect", "set error detection flags (deprecated; use err_detect, save via avconv)", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
00122 {"err_detect", "set error detection flags", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
00123 {"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"},
00124 {"bitstream", "detect bitstream specification deviations", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, D, "err_detect"},
00125 {"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BUFFER }, INT_MIN, INT_MAX, D, "err_detect"},
00126 {"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_EXPLODE }, INT_MIN, INT_MAX, D, "err_detect"},
00127 {"careful", "consider things that violate the spec and have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CAREFUL }, INT_MIN, INT_MAX, D, "err_detect"},
00128 {"compliant", "consider all spec non compliancies as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_COMPLIANT }, INT_MIN, INT_MAX, D, "err_detect"},
00129 {"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, D, "err_detect"},
00130 {NULL},
00131 };
00132
00133 #undef E
00134 #undef D
00135 #undef DEFAULT
00136
00137 static const AVClass av_format_context_class = {
00138 .class_name = "AVFormatContext",
00139 .item_name = format_to_name,
00140 .option = options,
00141 .version = LIBAVUTIL_VERSION_INT,
00142 .child_next = format_child_next,
00143 .child_class_next = format_child_class_next,
00144 };
00145
00146 static void avformat_get_context_defaults(AVFormatContext *s)
00147 {
00148 memset(s, 0, sizeof(AVFormatContext));
00149
00150 s->av_class = &av_format_context_class;
00151
00152 av_opt_set_defaults(s);
00153 }
00154
00155 AVFormatContext *avformat_alloc_context(void)
00156 {
00157 AVFormatContext *ic;
00158 ic = av_malloc(sizeof(AVFormatContext));
00159 if (!ic) return ic;
00160 avformat_get_context_defaults(ic);
00161 return ic;
00162 }
00163
00164 const AVClass *avformat_get_class(void)
00165 {
00166 return &av_format_context_class;
00167 }