aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/decode.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-03-09 11:35:47 +0100
committerAnton Khirnov <anton@khirnov.net>2021-03-16 11:09:36 +0100
commit20aec597d05f1930dbd4e4c5ab8ee837dea5b5f3 (patch)
treecda182ebc54fc312e735d7ce8643fd8203146fcb /libavcodec/decode.c
parentdbb1dfabb70ef0607367763806bd1dd843f8a65f (diff)
downloadffmpeg-20aec597d05f1930dbd4e4c5ab8ee837dea5b5f3.tar.gz
lavc: factor decoder validation/setup from avcodec_open2()
Diffstat (limited to 'libavcodec/decode.c')
-rw-r--r--libavcodec/decode.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 5f7e9bda3e..c8e9be3a13 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2004,3 +2004,44 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret;
}
+
+int ff_decode_preinit(AVCodecContext *avctx)
+{
+ /* if the decoder init function was already called previously,
+ * free the already allocated subtitle_header before overwriting it */
+ av_freep(&avctx->subtitle_header);
+
+#if FF_API_THREAD_SAFE_CALLBACKS
+FF_DISABLE_DEPRECATION_WARNINGS
+ if ((avctx->thread_type & FF_THREAD_FRAME) &&
+ avctx->get_buffer2 != avcodec_default_get_buffer2 &&
+ !avctx->thread_safe_callbacks) {
+ av_log(avctx, AV_LOG_WARNING, "Requested frame threading with a "
+ "custom get_buffer2() implementation which is not marked as "
+ "thread safe. This is not supported anymore, make your "
+ "callback thread-safe.\n");
+ }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+ if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
+ av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
+ avctx->codec->max_lowres);
+ avctx->lowres = avctx->codec->max_lowres;
+ }
+
+ avctx->pts_correction_num_faulty_pts =
+ avctx->pts_correction_num_faulty_dts = 0;
+ avctx->pts_correction_last_pts =
+ avctx->pts_correction_last_dts = INT64_MIN;
+
+ if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
+ && avctx->codec_descriptor->type == AVMEDIA_TYPE_VIDEO)
+ av_log(avctx, AV_LOG_WARNING,
+ "gray decoding requested but not enabled at configuration time\n");
+ if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
+ avctx->export_side_data |= AV_CODEC_EXPORT_DATA_MVS;
+ }
+
+ return 0;
+}