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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.5 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
2024-04-05 01:58:29 +02:00
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2020-10-26 23:07:36 -04:00
#pragma once
#include <span>
2020-10-26 23:07:36 -04:00
#include <vector>
2023-06-24 21:58:23 -04:00
2020-10-26 23:07:36 -04:00
#include "common/common_types.h"
2023-06-24 21:58:23 -04:00
#include "common/scratch_buffer.h"
2024-04-05 01:58:29 +02:00
#include "video_core/host1x/codecs/decoder.h"
#include "video_core/host1x/codec_types.h"
2022-01-30 10:31:13 +01:00
#include "video_core/host1x/nvdec_common.h"
2020-10-26 23:07:36 -04:00
namespace Tegra {
2022-01-30 22:26:01 +01:00
namespace Host1x {
class Host1x;
} // namespace Host1x
2024-04-05 01:58:29 +02:00
namespace Decoders {
2020-10-26 23:07:36 -04:00
class H264BitWriter {
public:
H264BitWriter();
~H264BitWriter();
/// The following Write methods are based on clause 9.1 in the H.264 specification.
/// WriteSe and WriteUe write in the Exp-Golomb-coded syntax
void WriteU(s32 value, s32 value_sz);
void WriteSe(s32 value);
2020-10-27 02:50:03 -04:00
void WriteUe(u32 value);
2020-10-26 23:07:36 -04:00
/// Finalize the bitstream
void End();
/// append a bit to the stream, equivalent value to the state parameter
void WriteBit(bool state);
/// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification
/// Writes the scaling matrices of the sream
void WriteScalingList(std::span<const u8> list, s32 start, s32 count);
2020-10-26 23:07:36 -04:00
/// Return the bitstream as a vector.
[[nodiscard]] std::vector<u8>& GetByteArray();
[[nodiscard]] const std::vector<u8>& GetByteArray() const;
2020-10-26 23:07:36 -04:00
private:
void WriteBits(s32 value, s32 bit_count);
void WriteExpGolombCodedInt(s32 value);
void WriteExpGolombCodedUInt(u32 value);
[[nodiscard]] s32 GetFreeBufferBits();
2020-10-26 23:07:36 -04:00
void Flush();
s32 buffer_size{8};
s32 buffer{};
s32 buffer_pos{};
std::vector<u8> byte_array;
};
2024-04-05 01:58:29 +02:00
class H264 final : public Decoder {
public:
explicit H264(Host1x::Host1x& host1x, const Host1x::NvdecCommon::NvdecRegisters& regs, s32 id);
2024-04-05 01:58:29 +02:00
~H264() override;
H264(const H264&) = delete;
H264& operator=(const H264&) = delete;
H264(H264&&) = delete;
H264& operator=(H264&&) = delete;
/// Compose the H264 frame for FFmpeg decoding
[[nodiscard]] std::span<const u8> ComposeFrame() override;
std::tuple<u64, u64> GetProgressiveOffsets() override;
std::tuple<u64, u64, u64, u64> GetInterlacedOffsets() override;
bool IsInterlaced() override;
std::string_view GetCurrentCodecName() const override {
return "H264";
}
private:
H264DecoderContext current_context{};
std::array<u8, 64> scan_scratch;
Common::ScratchBuffer<u8> frame_scratch;
bool is_first_frame{true};
2020-10-26 23:07:36 -04:00
};
2024-04-05 01:58:29 +02:00
} // namespace Decoders
2020-10-26 23:07:36 -04:00
} // namespace Tegra