diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/command_classes/codecs/codec.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp index 02d309170..1949a8cf3 100644 --- a/src/video_core/command_classes/codecs/codec.cpp +++ b/src/video_core/command_classes/codecs/codec.cpp | |||
| @@ -23,6 +23,14 @@ namespace Tegra { | |||
| 23 | namespace { | 23 | namespace { |
| 24 | constexpr AVPixelFormat PREFERRED_GPU_FMT = AV_PIX_FMT_NV12; | 24 | constexpr AVPixelFormat PREFERRED_GPU_FMT = AV_PIX_FMT_NV12; |
| 25 | constexpr AVPixelFormat PREFERRED_CPU_FMT = AV_PIX_FMT_YUV420P; | 25 | constexpr AVPixelFormat PREFERRED_CPU_FMT = AV_PIX_FMT_YUV420P; |
| 26 | constexpr std::array PREFERRED_GPU_DECODERS = {AV_HWDEVICE_TYPE_CUDA, | ||
| 27 | #ifdef _WIN32 | ||
| 28 | AV_HWDEVICE_TYPE_D3D11VA, AV_HWDEVICE_TYPE_DXVA2, | ||
| 29 | #elif linux | ||
| 30 | AV_HWDEVICE_TYPE_VDPAU, | ||
| 31 | #endif | ||
| 32 | // last resort for Linux Flatpak (w/ NVIDIA) | ||
| 33 | AV_HWDEVICE_TYPE_VULKAN}; | ||
| 26 | 34 | ||
| 27 | void AVPacketDeleter(AVPacket* ptr) { | 35 | void AVPacketDeleter(AVPacket* ptr) { |
| 28 | av_packet_free(&ptr); | 36 | av_packet_free(&ptr); |
| @@ -61,6 +69,19 @@ Codec::~Codec() { | |||
| 61 | av_buffer_unref(&av_gpu_decoder); | 69 | av_buffer_unref(&av_gpu_decoder); |
| 62 | } | 70 | } |
| 63 | 71 | ||
| 72 | // List all the currently available hwcontext in ffmpeg | ||
| 73 | static std::vector<AVHWDeviceType> ListSupportedContexts() { | ||
| 74 | std::vector<AVHWDeviceType> contexts{}; | ||
| 75 | enum AVHWDeviceType current_device_type = AV_HWDEVICE_TYPE_NONE; | ||
| 76 | do { | ||
| 77 | current_device_type = av_hwdevice_iterate_types(current_device_type); | ||
| 78 | // filter out VA-API since we will try that first if supported | ||
| 79 | if (current_device_type != AV_HWDEVICE_TYPE_VAAPI) | ||
| 80 | contexts.push_back(current_device_type); | ||
| 81 | } while (current_device_type != AV_HWDEVICE_TYPE_NONE); | ||
| 82 | return contexts; | ||
| 83 | } | ||
| 84 | |||
| 64 | #ifdef LIBVA_FOUND | 85 | #ifdef LIBVA_FOUND |
| 65 | // List all the currently loaded Linux modules | 86 | // List all the currently loaded Linux modules |
| 66 | static std::vector<std::string> ListLinuxKernelModules() { | 87 | static std::vector<std::string> ListLinuxKernelModules() { |
| @@ -122,16 +143,12 @@ bool Codec::CreateGpuAvDevice() { | |||
| 122 | av_dict_free(&hwdevice_options); | 143 | av_dict_free(&hwdevice_options); |
| 123 | #endif | 144 | #endif |
| 124 | static constexpr auto HW_CONFIG_METHOD = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX; | 145 | static constexpr auto HW_CONFIG_METHOD = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX; |
| 125 | static constexpr std::array GPU_DECODER_TYPES{ | 146 | static const auto supported_contexts = ListSupportedContexts(); |
| 126 | #ifdef linux | 147 | for (const auto& type : PREFERRED_GPU_DECODERS) { |
| 127 | AV_HWDEVICE_TYPE_VDPAU, | 148 | if (std::none_of(supported_contexts.begin(), supported_contexts.end(), |
| 128 | #endif | 149 | [&type](const auto& context) { return context == type; })) { |
| 129 | AV_HWDEVICE_TYPE_CUDA, | 150 | continue; |
| 130 | #ifdef _WIN32 | 151 | } |
| 131 | AV_HWDEVICE_TYPE_D3D11VA, | ||
| 132 | #endif | ||
| 133 | }; | ||
| 134 | for (const auto& type : GPU_DECODER_TYPES) { | ||
| 135 | const int hwdevice_res = av_hwdevice_ctx_create(&av_gpu_decoder, type, nullptr, nullptr, 0); | 152 | const int hwdevice_res = av_hwdevice_ctx_create(&av_gpu_decoder, type, nullptr, nullptr, 0); |
| 136 | if (hwdevice_res < 0) { | 153 | if (hwdevice_res < 0) { |
| 137 | LOG_DEBUG(Service_NVDRV, "{} av_hwdevice_ctx_create failed {}", | 154 | LOG_DEBUG(Service_NVDRV, "{} av_hwdevice_ctx_create failed {}", |