00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avcodec.h"
00028 #include "internal.h"
00029 #include "libavutil/avassert.h"
00030 #include "libavutil/opt.h"
00031 #include <float.h>
00032
00033 #include "options_table.h"
00034
00035 static const char* context_to_name(void* ptr) {
00036 AVCodecContext *avc= ptr;
00037
00038 if(avc && avc->codec && avc->codec->name)
00039 return avc->codec->name;
00040 else
00041 return "NULL";
00042 }
00043
00044 static void *codec_child_next(void *obj, void *prev)
00045 {
00046 AVCodecContext *s = obj;
00047 if (!prev && s->codec && s->codec->priv_class && s->priv_data)
00048 return s->priv_data;
00049 return NULL;
00050 }
00051
00052 static const AVClass *codec_child_class_next(const AVClass *prev)
00053 {
00054 AVCodec *c = NULL;
00055
00056
00057 while (prev && (c = av_codec_next(c)))
00058 if (c->priv_class == prev)
00059 break;
00060
00061
00062 while (c = av_codec_next(c))
00063 if (c->priv_class)
00064 return c->priv_class;
00065 return NULL;
00066 }
00067
00068 static const AVClass av_codec_context_class = {
00069 .class_name = "AVCodecContext",
00070 .item_name = context_to_name,
00071 .option = options,
00072 .version = LIBAVUTIL_VERSION_INT,
00073 .log_level_offset_offset = offsetof(AVCodecContext, log_level_offset),
00074 .child_next = codec_child_next,
00075 .child_class_next = codec_child_class_next,
00076 };
00077
00078 #if FF_API_ALLOC_CONTEXT
00079 void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){
00080 AVCodec c= {0};
00081 c.type= codec_type;
00082 avcodec_get_context_defaults3(s, &c);
00083 }
00084 #endif
00085
00086 int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){
00087 int flags=0;
00088 memset(s, 0, sizeof(AVCodecContext));
00089
00090 s->av_class = &av_codec_context_class;
00091
00092 s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN;
00093 if(s->codec_type == AVMEDIA_TYPE_AUDIO)
00094 flags= AV_OPT_FLAG_AUDIO_PARAM;
00095 else if(s->codec_type == AVMEDIA_TYPE_VIDEO)
00096 flags= AV_OPT_FLAG_VIDEO_PARAM;
00097 else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE)
00098 flags= AV_OPT_FLAG_SUBTITLE_PARAM;
00099 av_opt_set_defaults2(s, flags, flags);
00100
00101 s->time_base = (AVRational){0,1};
00102 s->get_buffer = avcodec_default_get_buffer;
00103 s->release_buffer = avcodec_default_release_buffer;
00104 s->get_format = avcodec_default_get_format;
00105 s->execute = avcodec_default_execute;
00106 s->execute2 = avcodec_default_execute2;
00107 s->sample_aspect_ratio = (AVRational){0,1};
00108 s->pix_fmt = PIX_FMT_NONE;
00109 s->sample_fmt = AV_SAMPLE_FMT_NONE;
00110 s->timecode_frame_start = -1;
00111
00112 s->reget_buffer = avcodec_default_reget_buffer;
00113 s->reordered_opaque = AV_NOPTS_VALUE;
00114 if(codec && codec->priv_data_size){
00115 if(!s->priv_data){
00116 s->priv_data= av_mallocz(codec->priv_data_size);
00117 if (!s->priv_data) {
00118 return AVERROR(ENOMEM);
00119 }
00120 }
00121 if(codec->priv_class){
00122 *(const AVClass**)s->priv_data = codec->priv_class;
00123 av_opt_set_defaults(s->priv_data);
00124 }
00125 }
00126 if (codec && codec->defaults) {
00127 int ret;
00128 const AVCodecDefault *d = codec->defaults;
00129 while (d->key) {
00130 ret = av_opt_set(s, d->key, d->value, 0);
00131 av_assert0(ret >= 0);
00132 d++;
00133 }
00134 }
00135 return 0;
00136 }
00137
00138 AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
00139 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
00140
00141 if(avctx==NULL) return NULL;
00142
00143 if(avcodec_get_context_defaults3(avctx, codec) < 0){
00144 av_free(avctx);
00145 return NULL;
00146 }
00147
00148 return avctx;
00149 }
00150
00151 #if FF_API_ALLOC_CONTEXT
00152 AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){
00153 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
00154
00155 if(avctx==NULL) return NULL;
00156
00157 avcodec_get_context_defaults2(avctx, codec_type);
00158
00159 return avctx;
00160 }
00161
00162 void avcodec_get_context_defaults(AVCodecContext *s){
00163 avcodec_get_context_defaults2(s, AVMEDIA_TYPE_UNKNOWN);
00164 }
00165
00166 AVCodecContext *avcodec_alloc_context(void){
00167 return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);
00168 }
00169 #endif
00170
00171 int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
00172 {
00173 if (avcodec_is_open(dest)) {
00174 av_log(dest, AV_LOG_ERROR,
00175 "Tried to copy AVCodecContext %p into already-initialized %p\n",
00176 src, dest);
00177 return AVERROR(EINVAL);
00178 }
00179 memcpy(dest, src, sizeof(*dest));
00180
00181
00182 dest->priv_data = NULL;
00183 dest->codec = NULL;
00184 dest->slice_offset = NULL;
00185 dest->hwaccel = NULL;
00186 dest->thread_opaque = NULL;
00187 dest->internal = NULL;
00188
00189
00190 dest->rc_eq = NULL;
00191 dest->extradata = NULL;
00192 dest->intra_matrix = NULL;
00193 dest->inter_matrix = NULL;
00194 dest->rc_override = NULL;
00195 if (src->rc_eq) {
00196 dest->rc_eq = av_strdup(src->rc_eq);
00197 if (!dest->rc_eq)
00198 return AVERROR(ENOMEM);
00199 }
00200
00201 #define alloc_and_copy_or_fail(obj, size, pad) \
00202 if (src->obj && size > 0) { \
00203 dest->obj = av_malloc(size + pad); \
00204 if (!dest->obj) \
00205 goto fail; \
00206 memcpy(dest->obj, src->obj, size); \
00207 if (pad) \
00208 memset(((uint8_t *) dest->obj) + size, 0, pad); \
00209 }
00210 alloc_and_copy_or_fail(extradata, src->extradata_size,
00211 FF_INPUT_BUFFER_PADDING_SIZE);
00212 alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);
00213 alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0);
00214 alloc_and_copy_or_fail(rc_override, src->rc_override_count * sizeof(*src->rc_override), 0);
00215 #undef alloc_and_copy_or_fail
00216
00217 return 0;
00218
00219 fail:
00220 av_freep(&dest->rc_override);
00221 av_freep(&dest->intra_matrix);
00222 av_freep(&dest->inter_matrix);
00223 av_freep(&dest->extradata);
00224 av_freep(&dest->rc_eq);
00225 return AVERROR(ENOMEM);
00226 }
00227
00228 const AVClass *avcodec_get_class(void)
00229 {
00230 return &av_codec_context_class;
00231 }
00232
00233 #define FOFFSET(x) offsetof(AVFrame,x)
00234
00235 static const AVOption frame_options[]={
00236 {"best_effort_timestamp", "", FOFFSET(best_effort_timestamp), AV_OPT_TYPE_INT64, {.dbl = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, 0},
00237 {"pkt_pos", "", FOFFSET(pkt_pos), AV_OPT_TYPE_INT64, {.dbl = -1 }, INT64_MIN, INT64_MAX, 0},
00238 {"sample_aspect_ratio", "", FOFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0, INT_MAX, 0},
00239 {"width", "", FOFFSET(width), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00240 {"height", "", FOFFSET(height), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00241 {"format", "", FOFFSET(format), AV_OPT_TYPE_INT, {.dbl = -1 }, 0, INT_MAX, 0},
00242 {"channel_layout", "", FOFFSET(channel_layout), AV_OPT_TYPE_INT64, {.dbl = 0 }, 0, INT64_MAX, 0},
00243 {"sample_rate", "", FOFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00244 {NULL},
00245 };
00246
00247 static const AVClass av_frame_class = {
00248 .class_name = "AVFrame",
00249 .item_name = NULL,
00250 .option = frame_options,
00251 .version = LIBAVUTIL_VERSION_INT,
00252 };
00253
00254 const AVClass *avcodec_get_frame_class(void)
00255 {
00256 return &av_frame_class;
00257 }
00258
00259 #define SROFFSET(x) offsetof(AVSubtitleRect,x)
00260
00261 static const AVOption subtitle_rect_options[]={
00262 {"x", "", SROFFSET(x), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00263 {"y", "", SROFFSET(y), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00264 {"w", "", SROFFSET(w), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00265 {"h", "", SROFFSET(h), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00266 {"type", "", SROFFSET(type), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0},
00267 {"forced", "", SROFFSET(forced), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, 0},
00268 {NULL},
00269 };
00270
00271 static const AVClass av_subtitle_rect_class = {
00272 .class_name = "AVSubtitleRect",
00273 .item_name = NULL,
00274 .option = subtitle_rect_options,
00275 .version = LIBAVUTIL_VERSION_INT,
00276 };
00277
00278 const AVClass *avcodec_get_subtitle_rect_class(void)
00279 {
00280 return &av_subtitle_rect_class;
00281 }