Lines Matching refs:avctx

115 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
121 if (avcodec_is_open(avctx))
124 if (!codec && !avctx->codec) {
125 av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
128 if (codec && avctx->codec && codec != avctx->codec) {
129 av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
130 "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
134 codec = avctx->codec;
137 if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
138 (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
139 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
143 avctx->codec_type = codec->type;
144 avctx->codec_id = codec->id;
145 avctx->codec = codec;
147 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
155 avctx->internal = avci;
167 if (!avctx->priv_data) {
168 avctx->priv_data = av_mallocz(codec2->priv_data_size);
169 if (!avctx->priv_data) {
174 *(const AVClass **)avctx->priv_data = codec->priv_class;
175 av_opt_set_defaults(avctx->priv_data);
178 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, options)) < 0)
181 avctx->priv_data = NULL;
183 if ((ret = av_opt_set_dict(avctx, options)) < 0)
186 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
187 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
193 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
194 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
195 if (avctx->coded_width && avctx->coded_height)
196 ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
197 else if (avctx->width && avctx->height)
198 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
203 if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
204 && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
205 || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
206 av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
207 ff_set_dimensions(avctx, 0, 0);
210 if (avctx->width > 0 && avctx->height > 0) {
211 if (av_image_check_sar(avctx->width, avctx->height,
212 avctx->sample_aspect_ratio) < 0) {
213 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
214 avctx->sample_aspect_ratio.num,
215 avctx->sample_aspect_ratio.den);
216 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
220 if (avctx->sample_rate < 0) {
221 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
225 if (avctx->block_align < 0) {
226 av_log(avctx, AV_LOG_ERROR, "Invalid block align: %d\n", avctx->block_align);
234 if (avctx->channel_layout && !avctx->channels)
235 avctx->channels = av_popcount64(avctx->channel_layout);
237 if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) ||
238 (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
239 avctx->ch_layout.u.mask != avctx->channel_layout))) {
240 if (avctx->channel_layout) {
241 av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
243 avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
244 avctx->ch_layout.nb_channels = avctx->channels;
250 if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
251 av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels);
256 avctx->frame_number = 0;
257 avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
259 if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
260 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
263 av_log(avctx, AV_LOG_ERROR,
269 av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
275 if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
276 (!avctx->time_base.num || !avctx->time_base.den)) {
277 avctx->time_base.num = 1;
278 avctx->time_base.den = avctx->sample_rate;
281 if (av_codec_is_encoder(avctx->codec))
282 ret = ff_encode_preinit(avctx);
284 ret = ff_decode_preinit(avctx);
288 if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) {
289 ret = ff_frame_thread_encoder_init(avctx);
295 && !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
298 ret = ff_thread_init(avctx);
305 avctx->thread_count = 1;
307 if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
311 ret = codec2->init(avctx);
323 if (av_codec_is_decoder(avctx->codec)) {
324 if (!avctx->bit_rate)
325 avctx->bit_rate = get_bit_rate(avctx);
330 avctx->channels = avctx->ch_layout.nb_channels;
331 avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
332 avctx->ch_layout.u.mask : 0;
335 if (avctx->channel_layout) {
336 int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
337 if (!avctx->channels)
338 avctx->channels = channels;
339 else if (channels != avctx->channels) {
341 av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
342 av_log(avctx, AV_LOG_WARNING,
345 buf, channels, avctx->channels);
346 avctx->channel_layout = 0;
349 if (avctx->channels && avctx->channels < 0 ||
350 avctx->channels > FF_SANE_NB_CHANNELS) {
354 if (avctx->bits_per_coded_sample < 0) {
362 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
363 avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
367 av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
373 avcodec_close(avctx);
377 void avcodec_flush_buffers(AVCodecContext *avctx)
379 AVCodecInternal *avci = avctx->internal;
381 if (av_codec_is_encoder(avctx->codec)) {
382 int caps = avctx->codec->capabilities;
387 av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder "
400 avctx->pts_correction_last_pts =
401 avctx->pts_correction_last_dts = INT64_MIN;
412 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
413 ff_thread_flush(avctx);
414 else if (ffcodec(avctx->codec)->flush)
415 ffcodec(avctx->codec)->flush(avctx);
440 av_cold int avcodec_close(AVCodecContext *avctx)
444 if (!avctx)
447 if (avcodec_is_open(avctx)) {
448 AVCodecInternal *avci = avctx->internal;
451 avci->frame_thread_encoder && avctx->thread_count > 1) {
452 ff_frame_thread_encoder_free(avctx);
455 ff_thread_free(avctx);
456 if (avci->needs_close && ffcodec(avctx->codec)->close)
457 ffcodec(avctx->codec)->close(avctx);
476 if (avctx->hwaccel && avctx->hwaccel->uninit)
477 avctx->hwaccel->uninit(avctx);
484 av_freep(&avctx->internal);
487 for (i = 0; i < avctx->nb_coded_side_data; i++)
488 av_freep(&avctx->coded_side_data[i].data);
489 av_freep(&avctx->coded_side_data);
490 avctx->nb_coded_side_data = 0;
492 av_buffer_unref(&avctx->hw_frames_ctx);
493 av_buffer_unref(&avctx->hw_device_ctx);
495 if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
496 av_opt_free(avctx->priv_data);
497 av_opt_free(avctx);
498 av_freep(&avctx->priv_data);
499 if (av_codec_is_encoder(avctx->codec)) {
500 av_freep(&avctx->extradata);
501 avctx->extradata_size = 0;
502 } else if (av_codec_is_decoder(avctx->codec))
503 av_freep(&avctx->subtitle_header);
505 avctx->codec = NULL;
506 avctx->active_thread_type = 0;