From eb67a45ca82bc01ac843c853fd3c17f2a90e0250 Mon Sep 17 00:00:00 2001 From: ameerj Date: Mon, 26 Oct 2020 23:07:36 -0400 Subject: video_core: NVDEC Implementation This commit aims to implement the NVDEC (Nvidia Decoder) functionality, with video frame decoding being handled by the FFmpeg library. The process begins with Ioctl commands being sent to the NVDEC and VIC (Video Image Composer) emulated devices. These allocate the necessary GPU buffers for the frame data, along with providing information on the incoming video data. A Submit command then signals the GPU to process and decode the frame data. To decode the frame, the respective codec's header must be manually composed from the information provided by NVDEC, then sent with the raw frame data to the ffmpeg library. Currently, H264 and VP9 are supported, with VP9 having some minor artifacting issues related mainly to the reference frame composition in its uncompressed header. Async GPU is not properly implemented at the moment. Co-Authored-By: David <25727384+ogniK5377@users.noreply.github.com> --- src/video_core/command_classes/codecs/codec.h | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/video_core/command_classes/codecs/codec.h (limited to 'src/video_core/command_classes/codecs/codec.h') diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h new file mode 100644 index 000000000..2e56daf29 --- /dev/null +++ b/src/video_core/command_classes/codecs/codec.h @@ -0,0 +1,68 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "common/common_funcs.h" +#include "common/common_types.h" +#include "video_core/command_classes/nvdec_common.h" + +extern "C" { +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic ignored "-Wconversion" +#endif +#include +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif +} + +namespace Tegra { +class GPU; +struct VicRegisters; + +namespace Decoder { +class H264; +class VP9; +} // namespace Decoder + +class Codec { +public: + explicit Codec(GPU& gpu); + ~Codec(); + + /// Sets NVDEC video stream codec + void SetTargetCodec(NvdecCommon::VideoCodec codec); + + /// Populate NvdecRegisters state with argument value at the provided offset + void StateWrite(u32 offset, u64 arguments); + + /// Call decoders to construct headers, decode AVFrame with ffmpeg + void Decode(); + + /// Returns most recently decoded frame + AVFrame* GetCurrentFrame(); + const AVFrame* GetCurrentFrame() const; + + /// Returns the value of current_codec + NvdecCommon::VideoCodec GetCurrentCodec() const; + +private: + bool initialized{}; + NvdecCommon::VideoCodec current_codec{NvdecCommon::VideoCodec::None}; + + AVCodec* av_codec{nullptr}; + AVCodecContext* av_codec_ctx{nullptr}; + AVFrame* av_frame{nullptr}; + + GPU& gpu; + std::unique_ptr h264_decoder; + std::unique_ptr vp9_decoder; + + NvdecCommon::NvdecRegisters state{}; +}; + +} // namespace Tegra -- cgit v1.2.3 From c04203b786d87ecb66811341e7ea776452664e91 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 27 Oct 2020 02:09:17 -0400 Subject: nvdec: Tidy up header includes Prevents a few unnecessary inclusions. --- src/video_core/command_classes/codecs/codec.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/video_core/command_classes/codecs/codec.h') diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index 2e56daf29..cb67094f6 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h @@ -5,8 +5,6 @@ #pragma once #include -#include -#include "common/common_funcs.h" #include "common/common_types.h" #include "video_core/command_classes/nvdec_common.h" -- cgit v1.2.3 From 4f0f481f63d0d5587a6d6d319f9815de87ed79ec Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 30 Oct 2020 16:13:29 -0400 Subject: nvdec: Make use of [[nodiscard]] where applicable Prevents bugs from occurring where the results of a function are accidentally discarded --- src/video_core/command_classes/codecs/codec.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/video_core/command_classes/codecs/codec.h') diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index cb67094f6..5bbe6a332 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h @@ -42,11 +42,11 @@ public: void Decode(); /// Returns most recently decoded frame - AVFrame* GetCurrentFrame(); - const AVFrame* GetCurrentFrame() const; + [[nodiscard]] AVFrame* GetCurrentFrame(); + [[nodiscard]] const AVFrame* GetCurrentFrame() const; /// Returns the value of current_codec - NvdecCommon::VideoCodec GetCurrentCodec() const; + [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const; private: bool initialized{}; -- cgit v1.2.3 From eab041866b7c766aa38258aecef8a00c03612459 Mon Sep 17 00:00:00 2001 From: ameerj Date: Wed, 25 Nov 2020 17:10:44 -0500 Subject: Queue decoded frames, cleanup decoders --- src/video_core/command_classes/codecs/codec.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/video_core/command_classes/codecs/codec.h') diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index 5bbe6a332..c26b59fde 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/common_types.h" #include "video_core/command_classes/nvdec_common.h" @@ -22,6 +23,9 @@ namespace Tegra { class GPU; struct VicRegisters; +void av_frame_deleter(AVFrame* ptr); +using AVFramePtr = std::unique_ptr; + namespace Decoder { class H264; class VP9; @@ -41,9 +45,8 @@ public: /// Call decoders to construct headers, decode AVFrame with ffmpeg void Decode(); - /// Returns most recently decoded frame - [[nodiscard]] AVFrame* GetCurrentFrame(); - [[nodiscard]] const AVFrame* GetCurrentFrame() const; + /// Returns next decoded frame + [[nodiscard]] AVFramePtr GetCurrentFrame(); /// Returns the value of current_codec [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const; @@ -54,13 +57,13 @@ private: AVCodec* av_codec{nullptr}; AVCodecContext* av_codec_ctx{nullptr}; - AVFrame* av_frame{nullptr}; GPU& gpu; std::unique_ptr h264_decoder; std::unique_ptr vp9_decoder; NvdecCommon::NvdecRegisters state{}; + std::queue av_frames{}; }; } // namespace Tegra -- cgit v1.2.3 From c9e3abe2060760d71c83a1574559b6e479e637d2 Mon Sep 17 00:00:00 2001 From: ameerj Date: Thu, 26 Nov 2020 00:18:26 -0500 Subject: Address PR feedback remove some redundant moves, make deleter match naming guidelines. Co-Authored-By: LC <712067+lioncash@users.noreply.github.com> --- src/video_core/command_classes/codecs/codec.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/video_core/command_classes/codecs/codec.h') diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index c26b59fde..0c6dde405 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h @@ -23,8 +23,8 @@ namespace Tegra { class GPU; struct VicRegisters; -void av_frame_deleter(AVFrame* ptr); -using AVFramePtr = std::unique_ptr; +void AVFrameDeleter(AVFrame* ptr); +using AVFramePtr = std::unique_ptr; namespace Decoder { class H264; -- cgit v1.2.3 From 4681e1ea9ea749646488d05d45327f57c4b321f2 Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 14 Nov 2020 18:35:34 -0500 Subject: codec: Fix `pragma GCC diagnostic pop` missing corresponding push --- src/video_core/command_classes/codecs/codec.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/video_core/command_classes/codecs/codec.h') diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index 5bbe6a332..ee5d62540 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h @@ -10,6 +10,7 @@ extern "C" { #if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif #include -- cgit v1.2.3