2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-10-27 03:07:36 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2021-09-08 19:09:01 +00:00
|
|
|
#include <string_view>
|
2020-11-25 22:10:44 +00:00
|
|
|
#include <queue>
|
2022-01-30 09:31:13 +00:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/host1x/nvdec_common.h"
|
2020-10-27 03:07:36 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
2020-11-14 23:35:34 +00:00
|
|
|
#pragma GCC diagnostic push
|
2020-10-27 03:07:36 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Wconversion"
|
|
|
|
#endif
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Tegra {
|
|
|
|
class GPU;
|
|
|
|
|
2020-11-26 05:18:26 +00:00
|
|
|
void AVFrameDeleter(AVFrame* ptr);
|
|
|
|
using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>;
|
2020-11-25 22:10:44 +00:00
|
|
|
|
2020-10-27 03:07:36 +00:00
|
|
|
namespace Decoder {
|
|
|
|
class H264;
|
2021-11-13 00:28:21 +00:00
|
|
|
class VP8;
|
2020-10-27 03:07:36 +00:00
|
|
|
class VP9;
|
|
|
|
} // namespace Decoder
|
|
|
|
|
|
|
|
class Codec {
|
|
|
|
public:
|
2022-01-30 09:31:13 +00:00
|
|
|
explicit Codec(GPU& gpu, const Host1x::NvdecCommon::NvdecRegisters& regs);
|
2020-10-27 03:07:36 +00:00
|
|
|
~Codec();
|
|
|
|
|
2021-06-29 04:54:54 +00:00
|
|
|
/// Initialize the codec, returning success or failure
|
|
|
|
void Initialize();
|
|
|
|
|
2020-10-27 03:07:36 +00:00
|
|
|
/// Sets NVDEC video stream codec
|
2022-01-30 09:31:13 +00:00
|
|
|
void SetTargetCodec(Host1x::NvdecCommon::VideoCodec codec);
|
2020-10-27 03:07:36 +00:00
|
|
|
|
|
|
|
/// Call decoders to construct headers, decode AVFrame with ffmpeg
|
|
|
|
void Decode();
|
|
|
|
|
2020-11-25 22:10:44 +00:00
|
|
|
/// Returns next decoded frame
|
|
|
|
[[nodiscard]] AVFramePtr GetCurrentFrame();
|
2020-10-27 03:07:36 +00:00
|
|
|
|
|
|
|
/// Returns the value of current_codec
|
2022-01-30 09:31:13 +00:00
|
|
|
[[nodiscard]] Host1x::NvdecCommon::VideoCodec GetCurrentCodec() const;
|
2021-08-07 19:12:15 +00:00
|
|
|
|
2021-06-29 04:54:54 +00:00
|
|
|
/// Return name of the current codec
|
|
|
|
[[nodiscard]] std::string_view GetCurrentCodecName() const;
|
2020-10-27 03:07:36 +00:00
|
|
|
|
|
|
|
private:
|
2021-08-08 03:57:22 +00:00
|
|
|
void InitializeAvCodecContext();
|
|
|
|
|
2021-08-07 19:12:15 +00:00
|
|
|
void InitializeGpuDecoder();
|
|
|
|
|
|
|
|
bool CreateGpuAvDevice();
|
2021-08-04 03:43:11 +00:00
|
|
|
|
2020-10-27 03:07:36 +00:00
|
|
|
bool initialized{};
|
2022-01-30 09:31:13 +00:00
|
|
|
Host1x::NvdecCommon::VideoCodec current_codec{Host1x::NvdecCommon::VideoCodec::None};
|
2020-10-27 03:07:36 +00:00
|
|
|
|
2022-01-20 11:09:17 +00:00
|
|
|
const AVCodec* av_codec{nullptr};
|
2020-10-27 03:07:36 +00:00
|
|
|
AVCodecContext* av_codec_ctx{nullptr};
|
2021-08-07 19:12:15 +00:00
|
|
|
AVBufferRef* av_gpu_decoder{nullptr};
|
2020-10-27 03:07:36 +00:00
|
|
|
|
|
|
|
GPU& gpu;
|
2022-01-30 09:31:13 +00:00
|
|
|
const Host1x::NvdecCommon::NvdecRegisters& state;
|
2020-10-27 03:07:36 +00:00
|
|
|
std::unique_ptr<Decoder::H264> h264_decoder;
|
2021-11-13 00:28:21 +00:00
|
|
|
std::unique_ptr<Decoder::VP8> vp8_decoder;
|
2020-10-27 03:07:36 +00:00
|
|
|
std::unique_ptr<Decoder::VP9> vp9_decoder;
|
|
|
|
|
2020-11-25 22:10:44 +00:00
|
|
|
std::queue<AVFramePtr> av_frames{};
|
2020-10-27 03:07:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Tegra
|