lavc: replace internal use of AV_CODEC_CAP_AUTO_THREADS with an internal cap

AV_CODEC_CAP_AUTO_THREADS was originally added in b4d44a45f9 to mark
codecs that spawn threads internally and are able to select an optimal
threads count by themselves (all such codecs are wrappers around
external libraries). It is used by lavc generic code to check whether it
should handle thread_count=0 itself or pass the zero directly to the
codec implementation. Within this meaning, it is clearly supposed to be
an internal cap rather than a public one, since from the viewpoint of a
libavcodec user, lavc ALWAYS handles thread_count=0. Whether it happens
in the generic code or within the codec internals is not a meaningful
difference for the caller.

External aspects of this flag will be dealt with in the following
commit.
pull/371/head
Anton Khirnov 4 years ago
parent b60fe9508f
commit 8a129077cc
  1. 4
      libavcodec/internal.h
  2. 1
      libavcodec/libaomdec.c
  3. 1
      libavcodec/libaomenc.c
  4. 3
      libavcodec/libdav1d.c
  5. 1
      libavcodec/libdavs2.c
  6. 3
      libavcodec/libkvazaar.c
  7. 3
      libavcodec/libopenh264enc.c
  8. 2
      libavcodec/librav1e.c
  9. 1
      libavcodec/libsvtav1.c
  10. 1
      libavcodec/libuavs3d.c
  11. 2
      libavcodec/libvpxdec.c
  12. 2
      libavcodec/libvpxenc.c
  13. 15
      libavcodec/libx264.c
  14. 1
      libavcodec/libx265.c
  15. 1
      libavcodec/libxavs.c
  16. 1
      libavcodec/libxavs2.c
  17. 2
      libavcodec/pthread.c
  18. 2
      libavcodec/utils.c

@ -74,6 +74,10 @@
* uses ff_thread_report/await_progress().
*/
#define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6)
/**
* Codec handles avctx->thread_count == 0 (auto) internally.
*/
#define FF_CODEC_CAP_AUTO_THREADS (1 << 7)
/**
* AVCodec.codec_tags termination value

@ -237,6 +237,7 @@ AVCodec ff_libaom_av1_decoder = {
.close = aom_free,
.decode = aom_decode,
.capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
.wrapper_name = "libaom",
};

@ -1346,6 +1346,7 @@ AVCodec ff_libaom_av1_encoder = {
.encode2 = aom_encode,
.close = aom_free,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
.priv_class = &class_aom,
.defaults = defaults,

@ -485,7 +485,8 @@ AVCodec ff_libdav1d_decoder = {
.flush = libdav1d_flush,
.receive_frame = libdav1d_receive_frame,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS |
FF_CODEC_CAP_AUTO_THREADS,
.priv_class = &libdav1d_class,
.wrapper_name = "libdav1d",
};

@ -222,6 +222,7 @@ AVCodec ff_libdavs2_decoder = {
.decode = davs2_decode_frame,
.flush = davs2_flush,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
.wrapper_name = "libdavs2",

@ -341,7 +341,8 @@ AVCodec ff_libkvazaar_encoder = {
.encode2 = libkvazaar_encode,
.close = libkvazaar_close,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_AUTO_THREADS,
.wrapper_name = "libkvazaar",
};

@ -448,7 +448,8 @@ AVCodec ff_libopenh264_encoder = {
.encode2 = svc_encode_frame,
.close = svc_encode_close,
.capabilities = AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
.defaults = svc_enc_defaults,

@ -625,6 +625,6 @@ AVCodec ff_librav1e_encoder = {
.defaults = librav1e_defaults,
.pix_fmts = librav1e_pix_fmts,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
.wrapper_name = "librav1e",
};

@ -561,6 +561,7 @@ AVCodec ff_libsvtav1_encoder = {
.receive_packet = eb_receive_packet,
.close = eb_enc_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUV420P10,
AV_PIX_FMT_NONE },

@ -254,6 +254,7 @@ AVCodec ff_libuavs3d_decoder = {
.close = libuavs3d_end,
.decode = libuavs3d_decode_frame,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.flush = libuavs3d_flush,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUV420P10LE,

@ -362,6 +362,7 @@ AVCodec ff_libvpx_vp8_decoder = {
.close = vpx_free,
.decode = vpx_decode,
.capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.wrapper_name = "libvpx",
};
#endif /* CONFIG_LIBVPX_VP8_DECODER */
@ -383,6 +384,7 @@ AVCodec ff_libvpx_vp9_decoder = {
.close = vpx_free,
.decode = vpx_decode,
.capabilities = AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.init_static_data = ff_vp9_init_static,
.profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
.wrapper_name = "libvpx",

@ -1871,6 +1871,7 @@ AVCodec ff_libvpx_vp8_encoder = {
.encode2 = vpx_encode,
.close = vpx_free,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE },
.priv_class = &class_vp8,
.defaults = defaults,
@ -1901,6 +1902,7 @@ AVCodec ff_libvpx_vp9_encoder = {
.encode2 = vpx_encode,
.close = vpx_free,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles),
.priv_class = &class_vp9,
.defaults = defaults,

@ -1204,6 +1204,7 @@ AVCodec ff_libx264_encoder = {
.close = X264_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS |
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.priv_class = &x264_class,
.defaults = x264_defaults,
#if X264_BUILD < 153
@ -1211,11 +1212,11 @@ AVCodec ff_libx264_encoder = {
#else
.pix_fmts = pix_fmts_all,
#endif
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
#if X264_BUILD >= 158
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
#else
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
| FF_CODEC_CAP_INIT_THREADSAFE
#endif
,
.wrapper_name = "libx264",
};
#endif
@ -1242,11 +1243,11 @@ AVCodec ff_libx264rgb_encoder = {
.priv_class = &rgbclass,
.defaults = x264_defaults,
.pix_fmts = pix_fmts_8bit_rgb,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
#if X264_BUILD >= 158
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
#else
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
| FF_CODEC_CAP_INIT_THREADSAFE
#endif
,
.wrapper_name = "libx264",
};
#endif
@ -1273,7 +1274,7 @@ AVCodec ff_libx262_encoder = {
.priv_class = &X262_class,
.defaults = x264_defaults,
.pix_fmts = pix_fmts_8bit,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
.wrapper_name = "libx264",
};
#endif

@ -702,5 +702,6 @@ AVCodec ff_libx265_encoder = {
.defaults = x265_defaults,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS |
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.wrapper_name = "libx265",
};

@ -476,6 +476,7 @@ AVCodec ff_libxavs_encoder = {
.encode2 = XAVS_frame,
.close = XAVS_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
.priv_class = &xavs_class,
.defaults = xavs_defaults,

@ -295,6 +295,7 @@ AVCodec ff_libxavs2_encoder = {
.encode2 = xavs2_encode_frame,
.close = xavs2_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },
.priv_class = &libxavs2,

@ -56,7 +56,7 @@ static void validate_thread_parameters(AVCodecContext *avctx)
} else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS &&
avctx->thread_type & FF_THREAD_SLICE) {
avctx->active_thread_type = FF_THREAD_SLICE;
} else if (!(avctx->codec->capabilities & AV_CODEC_CAP_AUTO_THREADS)) {
} else if (!(avctx->codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) {
avctx->thread_count = 1;
avctx->active_thread_type = 0;
}

@ -761,7 +761,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
goto free_and_end;
}
}
if (!HAVE_THREADS && !(codec->capabilities & AV_CODEC_CAP_AUTO_THREADS))
if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
avctx->thread_count = 1;
if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {

Loading…
Cancel
Save