w_align = 64;
h_align = 64;
}
+ break;
case AV_PIX_FMT_RGB555:
if (s->codec_id == AV_CODEC_ID_RPZA) {
w_align = 4;
h_align = 4;
}
+ break;
case AV_PIX_FMT_PAL8:
case AV_PIX_FMT_BGR8:
case AV_PIX_FMT_RGB8:
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
{
- int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
+ int chroma_shift = desc->log2_chroma_w;
int linesize_align[AV_NUM_DATA_POINTERS];
int align;
int unaligned;
AVPicture picture;
int stride_align[AV_NUM_DATA_POINTERS];
- const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1 + 1;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
+ const int pixel_size = desc->comp[0].step_minus1 + 1;
avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
buf->linesize[i] = 0;
}
if (size[1] && !size[2])
- ff_set_systematic_pal2((uint32_t *)buf->data[1], s->pix_fmt);
+ avpriv_set_systematic_pal2((uint32_t *)buf->data[1], s->pix_fmt);
buf->width = s->width;
buf->height = s->height;
buf->pix_fmt = s->pix_fmt;
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
{
AVFrame temp_pic;
- int i;
+ int i, ret;
av_assert0(s->codec_type == AVMEDIA_TYPE_VIDEO);
pic->data[i] = pic->base[i] = NULL;
pic->opaque = NULL;
/* Allocate new frame */
- if (s->get_buffer(s, pic))
- return -1;
+ if ((ret = s->get_buffer(s, pic)))
+ return ret;
/* Copy image data from old buffer to new buffer */
av_picture_copy((AVPicture *)pic, (AVPicture *)&temp_pic, s->pix_fmt, s->width,
s->height);
}
#endif
+int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
+{
+ int ret = 0;
+
+ entangled_thread_counter--;
+ /* Release any user-supplied mutex. */
+ if (ff_lockmgr_cb) {
+ (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
+ }
+
+ ret = avcodec_open2(avctx, codec, options);
+
+ /* If there is a user-supplied mutex locking routine, call it. */
+ if (ff_lockmgr_cb) {
+ if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
+ return -1;
+ }
+ entangled_thread_counter++;
+ return ret;
+}
+
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
{
int ret = 0;
return 0;
if ((!codec && !avctx->codec)) {
- av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
+ av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
return AVERROR(EINVAL);
}
if ((codec && avctx->codec && codec != avctx->codec)) {
av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
- "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
+ "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
return AVERROR(EINVAL);
}
if (!codec)
/* If there is a user-supplied mutex locking routine, call it. */
if (ff_lockmgr_cb) {
- if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
- return -1;
+ if ((ret = (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN)) < 0)
+ return ret;
}
entangled_thread_counter++;
if (entangled_thread_counter != 1) {
- av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
- ret = -1;
+ av_log(avctx, AV_LOG_ERROR, "Insufficient thread locking around avcodec_open/close()\n");
+ ret = AVERROR(EINVAL);
goto end;
}
if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
goto free_and_end;
- if (codec->capabilities & CODEC_CAP_EXPERIMENTAL)
- if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
- av_log(avctx, AV_LOG_ERROR, "Codec is experimental but experimental codecs are not enabled, try -strict -2\n");
- ret = -1;
- goto free_and_end;
- }
-
//We only call avcodec_set_dimensions() for non h264 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)){
if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
&& ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
|| av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
- av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
+ av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
avcodec_set_dimensions(avctx, 0, 0);
}
}
if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
&& avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
- av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
+ av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
ret = AVERROR(EINVAL);
goto free_and_end;
}
avctx->frame_number = 0;
avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
+ if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
+ avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
+ const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
+ AVCodec *codec2;
+ av_log(NULL, 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 & CODEC_CAP_EXPERIMENTAL))
+ av_log(NULL, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
+ codec_string, codec2->name);
+ ret = AVERROR_EXPERIMENTAL;
+ goto free_and_end;
+ }
+
if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
(!avctx->time_base.num || !avctx->time_base.den)) {
avctx->time_base.num = 1;
}
}
if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
- av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
+ char buf[128];
+ snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
+ av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
+ (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
ret = AVERROR(EINVAL);
goto free_and_end;
}
if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
&& !((avctx->codec_id == AV_CODEC_ID_MJPEG || avctx->codec_id == AV_CODEC_ID_LJPEG)
&& avctx->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL)) {
- av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n");
+ char buf[128];
+ snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
+ av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
+ (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
ret = AVERROR(EINVAL);
goto free_and_end;
}
if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
break;
if (avctx->codec->supported_samplerates[i] == 0) {
- av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
+ av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
+ avctx->sample_rate);
ret = AVERROR(EINVAL);
goto free_and_end;
}
}
if (avctx->codec->channel_layouts) {
if (!avctx->channel_layout) {
- av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
+ av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
} else {
for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
if (avctx->channel_layout == avctx->codec->channel_layouts[i])
break;
if (avctx->codec->channel_layouts[i] == 0) {
- av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
+ char buf[512];
+ av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
+ av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
ret = AVERROR(EINVAL);
goto free_and_end;
}
}
}
if (avctx->channel_layout && avctx->channels) {
- if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
- av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
+ int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
+ if (channels != avctx->channels) {
+ char buf[512];
+ av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
+ av_log(avctx, AV_LOG_ERROR,
+ "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
+ buf, channels, avctx->channels);
ret = AVERROR(EINVAL);
goto free_and_end;
}
if (!avctx->channels)
avctx->channels = channels;
else if (channels != avctx->channels) {
+ char buf[512];
+ av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
av_log(avctx, AV_LOG_WARNING,
- "channel layout does not match number of channels\n");
+ "Channel layout '%s' with %d channels does not match specified number of channels %d: "
+ "ignoring specified channel layout\n",
+ buf, channels, avctx->channels);
avctx->channel_layout = 0;
}
}
return ret;
}
-#if FF_API_OLD_DECODE_AUDIO
+#if FF_API_OLD_ENCODE_AUDIO
int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
uint8_t *buf, int buf_size,
const short *samples)
{
AVPacket pkt;
- AVFrame frame0;
+ AVFrame frame0 = { 0 };
AVFrame *frame;
int ret, samples_size, got_packet;
}
}
+static int add_metadata_from_side_data(AVCodecContext *avctx, AVFrame *frame)
+{
+ int size, ret = 0;
+ const uint8_t *side_metadata;
+ const uint8_t *end;
+
+ av_dict_free(&avctx->metadata);
+ side_metadata = av_packet_get_side_data(avctx->pkt,
+ AV_PKT_DATA_STRINGS_METADATA, &size);
+ if (!side_metadata)
+ goto end;
+ end = side_metadata + size;
+ while (side_metadata < end) {
+ const uint8_t *key = side_metadata;
+ const uint8_t *val = side_metadata + strlen(key) + 1;
+ int ret = av_dict_set(&frame->metadata, key, val, 0);
+ if (ret < 0)
+ break;
+ side_metadata = val + strlen(val) + 1;
+ }
+end:
+ avctx->metadata = frame->metadata;
+ return ret;
+}
+
int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
int *got_picture_ptr,
const AVPacket *avpkt)
if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
return AVERROR(EINVAL);
+ avcodec_get_frame_defaults(picture);
+
if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
int did_split = av_packet_split_side_data(&tmp);
apply_param_change(avctx, &tmp);
if (!picture->height) picture->height = avctx->height;
if (picture->format == AV_PIX_FMT_NONE) picture->format = avctx->pix_fmt;
}
+ add_metadata_from_side_data(avctx, picture);
emms_c(); //needed to avoid an emms_c() call before every return;
return AVERROR(EINVAL);
}
+ avcodec_get_frame_defaults(frame);
+
if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
uint8_t *side;
int side_size;
if (!frame->sample_rate)
frame->sample_rate = avctx->sample_rate;
}
+ add_metadata_from_side_data(avctx, frame);
side= av_packet_get_side_data(avctx->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
if(side && side_size>=10) {
/* many decoders assign whole AVFrames, thus overwriting extended_data;
* make sure it's set correctly; assume decoders that actually use
* extended_data are doing it correctly */
- planar = av_sample_fmt_is_planar(frame->format);
- channels = av_get_channel_layout_nb_channels(frame->channel_layout);
- if (!(planar && channels > AV_NUM_DATA_POINTERS))
- frame->extended_data = frame->data;
+ if (*got_frame_ptr) {
+ planar = av_sample_fmt_is_planar(frame->format);
+ channels = av_get_channel_layout_nb_channels(frame->channel_layout);
+ if (!(planar && channels > AV_NUM_DATA_POINTERS))
+ frame->extended_data = frame->data;
+ } else {
+ frame->extended_data = NULL;
+ }
return ret;
}
memset(sub, 0, sizeof(AVSubtitle));
}
+av_cold int ff_codec_close_recursive(AVCodecContext *avctx)
+{
+ int ret = 0;
+
+ entangled_thread_counter--;
+ /* Release any user-supplied mutex. */
+ if (ff_lockmgr_cb) {
+ (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
+ }
+
+ ret = avcodec_close(avctx);
+
+ /* If there is a user-supplied mutex locking routine, call it. */
+ if (ff_lockmgr_cb) {
+ if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
+ return -1;
+ }
+ entangled_thread_counter++;
+ return ret;
+}
+
av_cold int avcodec_close(AVCodecContext *avctx)
{
/* If there is a user-supplied mutex locking routine, call it. */
avctx->internal->byte_buffer_size = 0;
av_freep(&avctx->internal->byte_buffer);
av_freep(&avctx->internal);
+ av_dict_free(&avctx->metadata);
}
if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
}
}
-AVCodec *avcodec_find_encoder(enum AVCodecID id)
+static AVCodec *find_encdec(enum AVCodecID id, int encoder)
{
AVCodec *p, *experimental = NULL;
p = first_avcodec;
id= remap_deprecated_codec_id(id);
while (p) {
- if (av_codec_is_encoder(p) && p->id == id) {
+ if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
+ p->id == id) {
if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
experimental = p;
} else
return experimental;
}
+AVCodec *avcodec_find_encoder(enum AVCodecID id)
+{
+ return find_encdec(id, 1);
+}
+
AVCodec *avcodec_find_encoder_by_name(const char *name)
{
AVCodec *p;
AVCodec *avcodec_find_decoder(enum AVCodecID id)
{
- AVCodec *p, *experimental=NULL;
- p = first_avcodec;
- id= remap_deprecated_codec_id(id);
- while (p) {
- if (av_codec_is_decoder(p) && p->id == id) {
- if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
- experimental = p;
- } else
- return p;
- }
- p = p->next;
- }
- return experimental;
+ return find_encdec(id, 0);
}
AVCodec *avcodec_find_decoder_by_name(const char *name)