int codec_init_ok = 0;
AVDictionary *tmp = NULL;
const AVPixFmtDescriptor *pixdesc;
+ AVCodecInternal *avci;
if (avcodec_is_open(avctx))
return 0;
ff_lock_avcodec(avctx, codec);
- avctx->internal = av_mallocz(sizeof(*avctx->internal));
- if (!avctx->internal) {
+ avci = av_mallocz(sizeof(*avci));
+ if (!avci) {
ret = AVERROR(ENOMEM);
goto end;
}
+ avctx->internal = avci;
- avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
- if (!avctx->internal->pool) {
+ avci->pool = av_mallocz(sizeof(*avci->pool));
+ if (!avci->pool) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->to_free = av_frame_alloc();
- if (!avctx->internal->to_free) {
+ avci->to_free = av_frame_alloc();
+ if (!avci->to_free) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->compat_decode_frame = av_frame_alloc();
- if (!avctx->internal->compat_decode_frame) {
+ avci->compat_decode_frame = av_frame_alloc();
+ if (!avci->compat_decode_frame) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->buffer_frame = av_frame_alloc();
- if (!avctx->internal->buffer_frame) {
+ avci->buffer_frame = av_frame_alloc();
+ if (!avci->buffer_frame) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->buffer_pkt = av_packet_alloc();
- if (!avctx->internal->buffer_pkt) {
+ avci->buffer_pkt = av_packet_alloc();
+ if (!avci->buffer_pkt) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->ds.in_pkt = av_packet_alloc();
- if (!avctx->internal->ds.in_pkt) {
+ avci->ds.in_pkt = av_packet_alloc();
+ if (!avci->ds.in_pkt) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->last_pkt_props = av_packet_alloc();
- if (!avctx->internal->last_pkt_props) {
+ avci->last_pkt_props = av_packet_alloc();
+ if (!avci->last_pkt_props) {
ret = AVERROR(ENOMEM);
goto free_and_end;
}
- avctx->internal->skip_samples_multiplier = 1;
+ avci->skip_samples_multiplier = 1;
if (codec->priv_data_size > 0) {
if (!avctx->priv_data) {
// 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);
- else if (avctx->width && avctx->height)
- ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
- if (ret < 0)
- goto free_and_end;
+ if (avctx->coded_width && avctx->coded_height)
+ ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
+ else if (avctx->width && avctx->height)
+ ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
+ if (ret < 0)
+ goto free_and_end;
}
if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
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;
+ }
avctx->codec = codec;
if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
}
if (HAVE_THREADS
- && !(avctx->internal->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
+ && !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
ret = ff_thread_init(avctx);
if (ret < 0) {
goto free_and_end;
"gray decoding requested but not enabled at configuration time\n");
if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME)
- || avctx->internal->frame_thread_encoder)) {
+ || avci->frame_thread_encoder)) {
ret = avctx->codec->init(avctx);
if (ret < 0) {
goto free_and_end;
(avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP)))
avctx->codec->close(avctx);
- if (HAVE_THREADS && avctx->internal->thread_ctx)
+ if (HAVE_THREADS && avci->thread_ctx)
ff_thread_free(avctx);
if (codec->priv_class && codec->priv_data_size)
av_dict_free(&tmp);
av_freep(&avctx->priv_data);
av_freep(&avctx->subtitle_header);
- if (avctx->internal) {
- av_frame_free(&avctx->internal->to_free);
- av_frame_free(&avctx->internal->compat_decode_frame);
- av_frame_free(&avctx->internal->buffer_frame);
- av_packet_free(&avctx->internal->buffer_pkt);
- av_packet_free(&avctx->internal->last_pkt_props);
-
- av_packet_free(&avctx->internal->ds.in_pkt);
+ if (avci) {
+ av_frame_free(&avci->to_free);
+ av_frame_free(&avci->compat_decode_frame);
+ av_frame_free(&avci->buffer_frame);
+ av_packet_free(&avci->buffer_pkt);
+ av_packet_free(&avci->last_pkt_props);
+
+ av_packet_free(&avci->ds.in_pkt);
ff_decode_bsfs_uninit(avctx);
- av_freep(&avctx->internal->pool);
+ av_freep(&avci->pool);
}
- av_freep(&avctx->internal);
+ av_freep(&avci);
+ avctx->internal = NULL;
avctx->codec = NULL;
goto end;
}
const char *avcodec_license(void)
{
#define LICENSE_PREFIX "libavcodec license: "
- return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+ return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
}
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
{
- static const enum AVCodecID map[AV_SAMPLE_FMT_NB][2] = {
+ static const enum AVCodecID map[][2] = {
[AV_SAMPLE_FMT_U8 ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
[AV_SAMPLE_FMT_S16 ] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
[AV_SAMPLE_FMT_S32 ] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
[AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
[AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
};
- if (fmt < 0 || fmt >= AV_SAMPLE_FMT_NB)
+ if (fmt < 0 || fmt >= FF_ARRAY_ELEMS(map))
return AV_CODEC_ID_NONE;
if (be < 0 || be > 1)
be = AV_NE(1, 0);