Implement zero-copy 8/10 bit encoding for macOS

This commit is contained in:
Cameron Gutman
2023-10-03 20:55:50 -05:00
parent e535706a09
commit c56ad91693
5 changed files with 38 additions and 22 deletions

View File

@@ -94,6 +94,8 @@ namespace video {
vaapi_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *);
util::Either<avcodec_buffer_t, int>
cuda_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *);
util::Either<avcodec_buffer_t, int>
vt_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *);
class avcodec_software_encode_device_t: public platf::avcodec_encode_device_t {
public:
@@ -930,10 +932,10 @@ namespace video {
static encoder_t videotoolbox {
"videotoolbox"sv,
std::make_unique<encoder_platform_formats_avcodec>(
AV_HWDEVICE_TYPE_NONE, AV_HWDEVICE_TYPE_NONE,
AV_HWDEVICE_TYPE_VIDEOTOOLBOX, AV_HWDEVICE_TYPE_NONE,
AV_PIX_FMT_VIDEOTOOLBOX,
AV_PIX_FMT_NV12, AV_PIX_FMT_NV12,
nullptr),
AV_PIX_FMT_NV12, AV_PIX_FMT_P010,
vt_init_avcodec_hardware_input_buffer),
{
// Common options
{
@@ -2634,6 +2636,20 @@ namespace video {
return hw_device_buf;
}
util::Either<avcodec_buffer_t, int>
vt_init_avcodec_hardware_input_buffer(platf::avcodec_encode_device_t *encode_device) {
avcodec_buffer_t hw_device_buf;
auto status = av_hwdevice_ctx_create(&hw_device_buf, AV_HWDEVICE_TYPE_VIDEOTOOLBOX, nullptr, nullptr, 0);
if (status < 0) {
char string[AV_ERROR_MAX_STRING_SIZE];
BOOST_LOG(error) << "Failed to create a VideoToolbox device: "sv << av_make_error_string(string, AV_ERROR_MAX_STRING_SIZE, status);
return -1;
}
return hw_device_buf;
}
#ifdef _WIN32
}
@@ -2712,6 +2728,8 @@ namespace video {
return platf::mem_type_e::cuda;
case AV_HWDEVICE_TYPE_NONE:
return platf::mem_type_e::system;
case AV_HWDEVICE_TYPE_VIDEOTOOLBOX:
return platf::mem_type_e::videotoolbox;
default:
return platf::mem_type_e::unknown;
}