]> git.sesse.net Git - ffmpeg/commitdiff
lavc: replace internal use of AV_CODEC_CAP_AUTO_THREADS with an internal cap
authorAnton Khirnov <anton@khirnov.net>
Tue, 9 Mar 2021 17:00:44 +0000 (18:00 +0100)
committerAnton Khirnov <anton@khirnov.net>
Tue, 16 Mar 2021 09:34:29 +0000 (10:34 +0100)
AV_CODEC_CAP_AUTO_THREADS was originally added in b4d44a45f9a 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.

18 files changed:
libavcodec/internal.h
libavcodec/libaomdec.c
libavcodec/libaomenc.c
libavcodec/libdav1d.c
libavcodec/libdavs2.c
libavcodec/libkvazaar.c
libavcodec/libopenh264enc.c
libavcodec/librav1e.c
libavcodec/libsvtav1.c
libavcodec/libuavs3d.c
libavcodec/libvpxdec.c
libavcodec/libvpxenc.c
libavcodec/libx264.c
libavcodec/libx265.c
libavcodec/libxavs.c
libavcodec/libxavs2.c
libavcodec/pthread.c
libavcodec/utils.c

index 400ea508ef136ca90f05bf79f731ac3c0c5f4883..b57b9968166f9032baa06ff84e9426b493a8fee5 100644 (file)
  * 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
index 1430a651fea1de67efa6d3e647bbb9c2eb68ceed..327a5e18fb6fde057627ea76cc2a954e8e0b1867 100644 (file)
@@ -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",
 };
index 9a26b5f9ef6d7eb7f96a075fb3fc7b7a31d7e2e3..f99fdc0b736d60d435f2c45cb870d09197bfcacc 100644 (file)
@@ -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,
index 383e4557b45b02f38312400e6955b152530f2edf..93aeab4cb1de27cb22e2616d0d59bdefac1267fa 100644 (file)
@@ -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",
 };
index 218f3ec2396baa6ed2a203296e2787a792558dbf..f6a03df373f177f3fea0059da4291f3ba9220cbb 100644 (file)
@@ -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",
index d94cf995c8183241a9d00f82327a31ae3ba69089..f75aa4eda306f339ff1c1d26ce44c87fc1edf81e 100644 (file)
@@ -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",
 };
index cf485663e1a51b8b211be5ec3d34ad45d3c6251d..cb5deb8b50fd1ac4e28689e7cbf5cc0939623310 100644 (file)
@@ -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,
index 2d5acc7d8e28efc6179e40f80523c2279828cc6d..bd930736647da0ce12291ab46a4fb37797e45d2a 100644 (file)
@@ -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",
 };
index eb6043bcac3ee80d0f95341915c1cdb733c1cd2a..4244ae1daa21f8b9cd99f4352171745af6d9b86b 100644 (file)
@@ -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 },
index d77cc2192d9a43dbf07e359e3c52516827335f55..6bc0ba09f0ab5b6ddfaf0677f61469bf32683e8f 100644 (file)
@@ -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,
index 86982325a7ed1a20f24cf4fcd4cd35a7a558ef57..8a4e4fd14907e04a819340d08533364064f95463 100644 (file)
@@ -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",
index 02df4fe87b33516a44e3a4452d8069b427309ea0..df79839df5760930052f4d93ef55f45e9dfd028d 100644 (file)
@@ -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,
index 212ed7d0154c60e00c54f749704d78f49688394e..f152e453ce2b7bc6d7f222a97d164aa99f30bd53 100644 (file)
@@ -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
index 686c205b6b5fba9115f3b2320a086240f2cd1437..d502f47662915be4a8d06153f4cb1e4f5a579498 100644 (file)
@@ -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",
 };
index 752ff66dfa37839bbdd4f15416f49ed9093ef56e..12d5a5eb9eacb6bd160da03af081d462cb6204bf 100644 (file)
@@ -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,
index 8519f6925a3fc9e004818308c2e3bb5f38b437ae..cd29d2b93873a214712c33d38ea084bfa8474b8d 100644 (file)
@@ -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,
index 572471586d3bfb416f30ee85b40c5b79e7891b8b..14b7cca4fea82ab270fe1c18286daf89d8498750 100644 (file)
@@ -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;
     }
index 66d286565b7b72b51284f6304c5960eadcd26fc1..5d220ada4ba9a177b031ff70ebe010ace2d5990a 100644 (file)
@@ -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) {