/* * AVCodecContext functions for libavcodec * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** * @file * AVCodecContext functions for libavcodec
*/
/** * Maximum size in bytes of extradata. * This value was chosen such that every bit of the buffer is * addressable by a 32-bit signed integer as used by get_bits.
*/ #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
{
size_t i;
for (i = 0; i < count; i++) {
size_t offset = i * size; int r = func(c, FF_PTR_ADD((char *)arg, offset)); if (ret)
ret[i] = r;
}
emms_c(); return 0;
}
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
{ int i;
for (i = 0; i < count; i++) { int r = func(c, arg, i, 0); if (ret)
ret[i] = r;
}
emms_c(); return 0;
}
if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL);
// set the whitelist from provided options dict, // so we can check it immediately
e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL; if (e) {
ret = av_opt_set(avctx, e->key, e->value, 0); if (ret < 0) return ret;
}
if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist); return AVERROR(EINVAL);
}
avci = av_codec_is_decoder(codec) ?
ff_decode_internal_alloc() :
ff_encode_internal_alloc(); if (!avci) {
ret = AVERROR(ENOMEM); goto end;
}
avctx->internal = avci;
avci->buffer_frame = av_frame_alloc();
avci->buffer_pkt = av_packet_alloc(); if (!avci->buffer_frame || !avci->buffer_pkt) {
ret = AVERROR(ENOMEM); goto free_and_end;
}
if (codec2->priv_data_size > 0) { if (!avctx->priv_data) {
avctx->priv_data = av_mallocz(codec2->priv_data_size); if (!avctx->priv_data) {
ret = AVERROR(ENOMEM); goto free_and_end;
} if (codec->priv_class) {
*(const AVClass **)avctx->priv_data = codec->priv_class;
av_opt_set_defaults(avctx->priv_data);
}
}
} else {
avctx->priv_data = NULL;
}
ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN); if (ret < 0) goto free_and_end;
// only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
(avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) { if (avctx->coded_width && avctx->coded_height)
ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); elseif (avctx->width && avctx->height)
ret = ff_set_dimensions(avctx, avctx->width, avctx->height); if (ret < 0) goto free_and_end;
}
if (avctx->sample_rate < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
ret = AVERROR(EINVAL); goto free_and_end;
} if (avctx->block_align < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid block align: %d\n", avctx->block_align);
ret = AVERROR(EINVAL); goto free_and_end;
}
/* AV_CODEC_CAP_CHANNEL_CONF is a decoder-only flag; so the code below
* in particular checks that nb_channels is set for all audio encoders. */ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && !avctx->ch_layout.nb_channels
&& !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
av_log(avctx, AV_LOG_ERROR, "%s requires channel layout to be set\n",
av_codec_is_decoder(codec) ? "Decoder" : "Encoder");
ret = AVERROR(EINVAL); goto free_and_end;
} if (avctx->ch_layout.nb_channels && !av_channel_layout_check(&avctx->ch_layout)) {
av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
ret = AVERROR(EINVAL); goto free_and_end;
} if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels);
ret = AVERROR(EINVAL); goto free_and_end;
}
if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { constchar *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder"; const AVCodec *codec2;
av_log(avctx, AV_LOG_ERROR, "The %s '%s' is experimental but experimental codecs are not enabled, " "add '-strict %d' if you want to use it.\n",
codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id); if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
codec_string, codec2->name);
ret = AVERROR_EXPERIMENTAL; goto free_and_end;
}
if (av_codec_is_encoder(avctx->codec)) { int caps = avctx->codec->capabilities;
if (!(caps & AV_CODEC_CAP_ENCODER_FLUSH)) { // Only encoders that explicitly declare support for it can be // flushed. Otherwise, this is a no-op.
av_log(avctx, AV_LOG_WARNING, "Ignoring attempt to flush encoder " "that doesn't support it\n"); return;
}
ff_encode_flush_buffers(avctx);
} else
ff_decode_flush_buffers(avctx);
avci->draining = 0;
avci->draining_done = 0; if (avci->buffer_frame)
av_frame_unref(avci->buffer_frame); if (avci->buffer_pkt)
av_packet_unref(avci->buffer_pkt);
av_refstruct_unref(&avci->pool);
av_refstruct_pool_uninit(&avci->progress_frame_pool); if (av_codec_is_decoder(avctx->codec))
ff_decode_internal_uninit(avctx);
for (i = 0; i < avctx->nb_coded_side_data; i++)
av_freep(&avctx->coded_side_data[i].data);
av_freep(&avctx->coded_side_data);
avctx->nb_coded_side_data = 0;
av_frame_side_data_free(&avctx->decoded_side_data,
&avctx->nb_decoded_side_data);
av_bprint_chars(&bprint, '(', 1);
len = bprint.len;
/* The following check ensures that '(' has been written * and therefore allows us to erase it if it turns out
* to be unnecessary. */ if (!av_bprint_is_complete(&bprint)) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.