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.
Unified · Split
| @@ -74,6 +74,10 @@ · 73 unmodified lines | ||
| 74 | 74 | * uses ff_thread_report/await_progress(). |
| 75 | 75 | */ |
| 76 | 76 | #define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6) |
| 77 | +/** | |
| 78 | + * Codec handles avctx->thread_count == 0 (auto) internally. | |
| 79 | + */ | |
| 80 | +#define FF_CODEC_CAP_AUTO_THREADS (1 << 7) | |
| 77 | 81 | |
| 78 | 82 | /** |
| 79 | 83 | * AVCodec.codec_tags termination value |
| @@ -237,6 +237,7 @@ AVCodec ff_libaom_av1_decoder = { · 236 unmodified lines | ||
| 237 | 237 | .close = aom_free, |
| 238 | 238 | .decode = aom_decode, |
| 239 | 239 | .capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1, |
| 240 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 240 | 241 | .profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), |
| 241 | 242 | .wrapper_name = "libaom", |
| 242 | 243 | }; |
| @@ -1346,6 +1346,7 @@ AVCodec ff_libaom_av1_encoder = { · 1345 unmodified lines | ||
| 1346 | 1346 | .encode2 = aom_encode, |
| 1347 | 1347 | .close = aom_free, |
| 1348 | 1348 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 1349 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 1349 | 1350 | .profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), |
| 1350 | 1351 | .priv_class = &class_aom, |
| 1351 | 1352 | .defaults = defaults, |
| @@ -485,7 +485,8 @@ AVCodec ff_libdav1d_decoder = { · 484 unmodified lines | ||
| 485 | 485 | .flush = libdav1d_flush, |
| 486 | 486 | .receive_frame = libdav1d_receive_frame, |
| 487 | 487 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 488 | − .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS, | |
| 488 | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SETS_PKT_DTS | | |
| 489 | + FF_CODEC_CAP_AUTO_THREADS, | |
| 489 | 490 | .priv_class = &libdav1d_class, |
| 490 | 491 | .wrapper_name = "libdav1d", |
| 491 | 492 | }; |
| @@ -222,6 +222,7 @@ AVCodec ff_libdavs2_decoder = { · 221 unmodified lines | ||
| 222 | 222 | .decode = davs2_decode_frame, |
| 223 | 223 | .flush = davs2_flush, |
| 224 | 224 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 225 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 225 | 226 | .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, |
| 226 | 227 | AV_PIX_FMT_NONE }, |
| 227 | 228 | .wrapper_name = "libdavs2", |
| @@ -341,7 +341,8 @@ AVCodec ff_libkvazaar_encoder = { · 340 unmodified lines | ||
| 341 | 341 | .encode2 = libkvazaar_encode, |
| 342 | 342 | .close = libkvazaar_close, |
| 343 | 343 | |
| 344 | − .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | |
| 344 | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP | | |
| 345 | + FF_CODEC_CAP_AUTO_THREADS, | |
| 345 | 346 | |
| 346 | 347 | .wrapper_name = "libkvazaar", |
| 347 | 348 | }; |
| @@ -448,7 +448,8 @@ AVCodec ff_libopenh264_encoder = { · 447 unmodified lines | ||
| 448 | 448 | .encode2 = svc_encode_frame, |
| 449 | 449 | .close = svc_encode_close, |
| 450 | 450 | .capabilities = AV_CODEC_CAP_AUTO_THREADS, |
| 451 | − .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | |
| 451 | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP | | |
| 452 | + FF_CODEC_CAP_AUTO_THREADS, | |
| 452 | 453 | .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, |
| 453 | 454 | AV_PIX_FMT_NONE }, |
| 454 | 455 | .defaults = svc_enc_defaults, |
| @@ -625,6 +625,6 @@ AVCodec ff_librav1e_encoder = { · 624 unmodified lines | ||
| 625 | 625 | .defaults = librav1e_defaults, |
| 626 | 626 | .pix_fmts = librav1e_pix_fmts, |
| 627 | 627 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 628 | − .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |
| 628 | + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS, | |
| 629 | 629 | .wrapper_name = "librav1e", |
| 630 | 630 | }; |
| @@ -561,6 +561,7 @@ AVCodec ff_libsvtav1_encoder = { · 560 unmodified lines | ||
| 561 | 561 | .receive_packet = eb_receive_packet, |
| 562 | 562 | .close = eb_enc_close, |
| 563 | 563 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 564 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 564 | 565 | .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, |
| 565 | 566 | AV_PIX_FMT_YUV420P10, |
| 566 | 567 | AV_PIX_FMT_NONE }, |
| @@ -254,6 +254,7 @@ AVCodec ff_libuavs3d_decoder = { · 253 unmodified lines | ||
| 254 | 254 | .close = libuavs3d_end, |
| 255 | 255 | .decode = libuavs3d_decode_frame, |
| 256 | 256 | .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 257 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 257 | 258 | .flush = libuavs3d_flush, |
| 258 | 259 | .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, |
| 259 | 260 | AV_PIX_FMT_YUV420P10LE, |
| @@ -362,6 +362,7 @@ AVCodec ff_libvpx_vp8_decoder = { · 361 unmodified lines | ||
| 362 | 362 | .close = vpx_free, |
| 363 | 363 | .decode = vpx_decode, |
| 364 | 364 | .capabilities = AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_DR1, |
| 365 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 365 | 366 | .wrapper_name = "libvpx", |
| 366 | 367 | }; |
| 367 | 368 | #endif /* CONFIG_LIBVPX_VP8_DECODER */ |
| @@ -383,6 +384,7 @@ AVCodec ff_libvpx_vp9_decoder = { · 15 unmodified lines | ||
| 383 | 384 | .close = vpx_free, |
| 384 | 385 | .decode = vpx_decode, |
| 385 | 386 | .capabilities = AV_CODEC_CAP_AUTO_THREADS, |
| 387 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 386 | 388 | .init_static_data = ff_vp9_init_static, |
| 387 | 389 | .profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles), |
| 388 | 390 | .wrapper_name = "libvpx", |
| @@ -1871,6 +1871,7 @@ AVCodec ff_libvpx_vp8_encoder = { · 1870 unmodified lines | ||
| 1871 | 1871 | .encode2 = vpx_encode, |
| 1872 | 1872 | .close = vpx_free, |
| 1873 | 1873 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 1874 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 1874 | 1875 | .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE }, |
| 1875 | 1876 | .priv_class = &class_vp8, |
| 1876 | 1877 | .defaults = defaults, |
| @@ -1901,6 +1902,7 @@ AVCodec ff_libvpx_vp9_encoder = { · 24 unmodified lines | ||
| 1901 | 1902 | .encode2 = vpx_encode, |
| 1902 | 1903 | .close = vpx_free, |
| 1903 | 1904 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 1905 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 1904 | 1906 | .profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles), |
| 1905 | 1907 | .priv_class = &class_vp9, |
| 1906 | 1908 | .defaults = defaults, |
| @@ -1204,6 +1204,7 @@ AVCodec ff_libx264_encoder = { · 1203 unmodified lines | ||
| 1204 | 1204 | .close = X264_close, |
| 1205 | 1205 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS | |
| 1206 | 1206 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 1207 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 1207 | 1208 | .priv_class = &x264_class, |
| 1208 | 1209 | .defaults = x264_defaults, |
| 1209 | 1210 | #if X264_BUILD < 153 |
| @@ -1211,11 +1212,11 @@ AVCodec ff_libx264_encoder = { · 1 unmodified line | ||
| 1211 | 1212 | #else |
| 1212 | 1213 | .pix_fmts = pix_fmts_all, |
| 1213 | 1214 | #endif |
| 1215 | + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS | |
| 1214 | 1216 | #if X264_BUILD >= 158 |
| 1215 | − .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, | |
| 1216 | −#else | |
| 1217 | − .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |
| 1217 | + | FF_CODEC_CAP_INIT_THREADSAFE | |
| 1218 | 1218 | #endif |
| 1219 | + , | |
| 1219 | 1220 | .wrapper_name = "libx264", |
| 1220 | 1221 | }; |
| 1221 | 1222 | #endif |
| @@ -1242,11 +1243,11 @@ AVCodec ff_libx264rgb_encoder = { · 20 unmodified lines | ||
| 1242 | 1243 | .priv_class = &rgbclass, |
| 1243 | 1244 | .defaults = x264_defaults, |
| 1244 | 1245 | .pix_fmts = pix_fmts_8bit_rgb, |
| 1246 | + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS | |
| 1245 | 1247 | #if X264_BUILD >= 158 |
| 1246 | − .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, | |
| 1247 | −#else | |
| 1248 | − .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |
| 1248 | + | FF_CODEC_CAP_INIT_THREADSAFE | |
| 1249 | 1249 | #endif |
| 1250 | + , | |
| 1250 | 1251 | .wrapper_name = "libx264", |
| 1251 | 1252 | }; |
| 1252 | 1253 | #endif |
| @@ -1273,7 +1274,7 @@ AVCodec ff_libx262_encoder = { · 20 unmodified lines | ||
| 1273 | 1274 | .priv_class = &X262_class, |
| 1274 | 1275 | .defaults = x264_defaults, |
| 1275 | 1276 | .pix_fmts = pix_fmts_8bit, |
| 1276 | − .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |
| 1277 | + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS, | |
| 1277 | 1278 | .wrapper_name = "libx264", |
| 1278 | 1279 | }; |
| 1279 | 1280 | #endif |
| @@ -702,5 +702,6 @@ AVCodec ff_libx265_encoder = { · 701 unmodified lines | ||
| 702 | 702 | .defaults = x265_defaults, |
| 703 | 703 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS | |
| 704 | 704 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 705 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 705 | 706 | .wrapper_name = "libx265", |
| 706 | 707 | }; |
| @@ -476,6 +476,7 @@ AVCodec ff_libxavs_encoder = { · 475 unmodified lines | ||
| 476 | 476 | .encode2 = XAVS_frame, |
| 477 | 477 | .close = XAVS_close, |
| 478 | 478 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 479 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 479 | 480 | .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, |
| 480 | 481 | .priv_class = &xavs_class, |
| 481 | 482 | .defaults = xavs_defaults, |
| @@ -295,6 +295,7 @@ AVCodec ff_libxavs2_encoder = { · 294 unmodified lines | ||
| 295 | 295 | .encode2 = xavs2_encode_frame, |
| 296 | 296 | .close = xavs2_close, |
| 297 | 297 | .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, |
| 298 | + .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | |
| 298 | 299 | .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, |
| 299 | 300 | AV_PIX_FMT_NONE }, |
| 300 | 301 | .priv_class = &libxavs2, |
| @@ -56,7 +56,7 @@ static void validate_thread_parameters(AVCodecContext *avctx) · 55 unmodified lines | ||
| 56 | 56 | } else if (avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS && |
| 57 | 57 | avctx->thread_type & FF_THREAD_SLICE) { |
| 58 | 58 | avctx->active_thread_type = FF_THREAD_SLICE; |
| 59 | − } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_AUTO_THREADS)) { | |
| 59 | + } else if (!(avctx->codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) { | |
| 60 | 60 | avctx->thread_count = 1; |
| 61 | 61 | avctx->active_thread_type = 0; |
| 62 | 62 | } |
| @@ -761,7 +761,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 760 unmodified lines | ||
| 761 | 761 | goto free_and_end; |
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | − if (!HAVE_THREADS && !(codec->capabilities & AV_CODEC_CAP_AUTO_THREADS)) | |
| 764 | + if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS)) | |
| 765 | 765 | avctx->thread_count = 1; |
| 766 | 766 | |
| 767 | 767 | if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) { |