Files
eden/src/video_core/host1x/codecs/codec.h
T

93 lines
2.3 KiB
C++
Raw Normal View History

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