mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-27 11:04:23 +01:00
vp8: Implement header composition
Enables frame decoding with FFmpeg
This commit is contained in:
parent
b39b33b1fe
commit
d35391b9f4
@ -185,7 +185,7 @@ void Codec::Decode() {
|
|||||||
case Tegra::NvdecCommon::VideoCodec::H264:
|
case Tegra::NvdecCommon::VideoCodec::H264:
|
||||||
return h264_decoder->ComposeFrameHeader(state, is_first_frame);
|
return h264_decoder->ComposeFrameHeader(state, is_first_frame);
|
||||||
case Tegra::NvdecCommon::VideoCodec::VP8:
|
case Tegra::NvdecCommon::VideoCodec::VP8:
|
||||||
return vp8_decoder->ComposeFrameHeader(state, is_first_frame);
|
return vp8_decoder->ComposeFrameHeader(state);
|
||||||
case Tegra::NvdecCommon::VideoCodec::VP9:
|
case Tegra::NvdecCommon::VideoCodec::VP9:
|
||||||
vp9_decoder->ComposeFrameHeader(state);
|
vp9_decoder->ComposeFrameHeader(state);
|
||||||
vp9_hidden_frame = vp9_decoder->WasFrameHidden();
|
vp9_hidden_frame = vp9_decoder->WasFrameHidden();
|
||||||
|
@ -6,15 +6,50 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "video_core/command_classes/codecs/vp8.h"
|
#include "video_core/command_classes/codecs/vp8.h"
|
||||||
|
#include "video_core/gpu.h"
|
||||||
|
#include "video_core/memory_manager.h"
|
||||||
|
|
||||||
namespace Tegra::Decoder {
|
namespace Tegra::Decoder {
|
||||||
VP8::VP8(GPU& gpu_) : gpu(gpu_) {}
|
VP8::VP8(GPU& gpu_) : gpu(gpu_) {}
|
||||||
|
|
||||||
VP8::~VP8() = default;
|
VP8::~VP8() = default;
|
||||||
|
|
||||||
const std::vector<u8>& VP8::ComposeFrameHeader(const NvdecCommon::NvdecRegisters& state,
|
const std::vector<u8>& VP8::ComposeFrameHeader(const NvdecCommon::NvdecRegisters& state) {
|
||||||
bool is_first_frame) {
|
VP8PictureInfo info;
|
||||||
return {};
|
gpu.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo));
|
||||||
|
|
||||||
|
const bool is_key_frame = info.key_frame == 1u;
|
||||||
|
const auto bitstream_size = static_cast<size_t>(info.vld_buffer_size);
|
||||||
|
const size_t header_size = is_key_frame ? 10u : 3u;
|
||||||
|
frame.resize(header_size + bitstream_size);
|
||||||
|
|
||||||
|
// Based on page 30 of the VP8 specification.
|
||||||
|
// https://datatracker.ietf.org/doc/rfc6386/
|
||||||
|
frame[0] = is_key_frame ? 0u : 1u; // 1-bit frame type (0: keyframe, 1: interframes).
|
||||||
|
frame[0] |= static_cast<u8>((info.version & 7u) << 1u); // 3-bit version number
|
||||||
|
frame[0] |= static_cast<u8>(1u << 4u); // 1-bit show_frame flag
|
||||||
|
|
||||||
|
// The next 19-bits are the first partition size
|
||||||
|
frame[0] |= static_cast<u8>((info.first_part_size & 7u) << 5u);
|
||||||
|
frame[1] = static_cast<u8>((info.first_part_size & 0x7f8u) >> 3u);
|
||||||
|
frame[2] = static_cast<u8>((info.first_part_size & 0x7f800u) >> 11u);
|
||||||
|
|
||||||
|
if (is_key_frame) {
|
||||||
|
frame[3] = 0x9du;
|
||||||
|
frame[4] = 0x01u;
|
||||||
|
frame[5] = 0x2au;
|
||||||
|
// TODO(ameerj): Horizontal/Vertical Scale
|
||||||
|
// 16 bits: (2 bits Horizontal Scale << 14) | Width (14 bits)
|
||||||
|
frame[6] = static_cast<u8>(info.frame_width & 0xff);
|
||||||
|
frame[7] = static_cast<u8>(((info.frame_width >> 8) & 0x3f));
|
||||||
|
// 16 bits:(2 bits Vertical Scale << 14) | Height (14 bits)
|
||||||
|
frame[8] = static_cast<u8>(info.frame_height & 0xff);
|
||||||
|
frame[9] = static_cast<u8>(((info.frame_height >> 8) & 0x3f));
|
||||||
|
}
|
||||||
|
const u64 bitstream_offset = state.frame_bitstream_offset;
|
||||||
|
gpu.MemoryManager().ReadBlock(bitstream_offset, frame.data() + header_size, bitstream_size);
|
||||||
|
|
||||||
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Tegra::Decoder
|
} // namespace Tegra::Decoder
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "video_core/command_classes/nvdec_common.h"
|
#include "video_core/command_classes/nvdec_common.h"
|
||||||
|
|
||||||
@ -20,11 +22,53 @@ public:
|
|||||||
|
|
||||||
/// Compose the VP8 header of the frame for FFmpeg decoding
|
/// Compose the VP8 header of the frame for FFmpeg decoding
|
||||||
[[nodiscard]] const std::vector<u8>& ComposeFrameHeader(
|
[[nodiscard]] const std::vector<u8>& ComposeFrameHeader(
|
||||||
const NvdecCommon::NvdecRegisters& state, bool is_first_frame = false);
|
const NvdecCommon::NvdecRegisters& state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<u8> frame;
|
std::vector<u8> frame;
|
||||||
GPU& gpu;
|
GPU& gpu;
|
||||||
|
|
||||||
|
struct VP8PictureInfo {
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(14);
|
||||||
|
u16 frame_width; // actual frame width
|
||||||
|
u16 frame_height; // actual frame height
|
||||||
|
u8 key_frame;
|
||||||
|
u8 version;
|
||||||
|
union {
|
||||||
|
u8 raw;
|
||||||
|
BitField<0, 2, u8> tile_format;
|
||||||
|
BitField<2, 3, u8> gob_height;
|
||||||
|
BitField<5, 3, u8> reserverd_surface_format;
|
||||||
|
};
|
||||||
|
u8 error_conceal_on; // 1: error conceal on; 0: off
|
||||||
|
u32 first_part_size; // the size of first partition(frame header and mb header partition)
|
||||||
|
u32 hist_buffer_size; // in units of 256
|
||||||
|
u32 vld_buffer_size; // in units of 1
|
||||||
|
// Current frame buffers
|
||||||
|
std::array<u32, 2> frame_stride; // [y_c]
|
||||||
|
u32 luma_top_offset; // offset of luma top field in units of 256
|
||||||
|
u32 luma_bot_offset; // offset of luma bottom field in units of 256
|
||||||
|
u32 luma_frame_offset; // offset of luma frame in units of 256
|
||||||
|
u32 chroma_top_offset; // offset of chroma top field in units of 256
|
||||||
|
u32 chroma_bot_offset; // offset of chroma bottom field in units of 256
|
||||||
|
u32 chroma_frame_offset; // offset of chroma frame in units of 256
|
||||||
|
|
||||||
|
INSERT_PADDING_BYTES_NOINIT(0x1c); // NvdecDisplayParams
|
||||||
|
|
||||||
|
// Decode picture buffer related
|
||||||
|
s8 current_output_memory_layout;
|
||||||
|
// output NV12/NV24 setting. index 0: golden; 1: altref; 2: last
|
||||||
|
std::array<s8, 3> output_memory_layout;
|
||||||
|
|
||||||
|
u8 segmentation_feature_data_update;
|
||||||
|
INSERT_PADDING_BYTES_NOINIT(3);
|
||||||
|
|
||||||
|
// ucode return result
|
||||||
|
u32 result_value;
|
||||||
|
std::array<u32, 8> partition_offset;
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(3);
|
||||||
|
};
|
||||||
|
static_assert(sizeof(VP8PictureInfo) == 0xc0, "PictureInfo is an invalid size");
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Decoder
|
} // namespace Decoder
|
||||||
|
@ -50,7 +50,10 @@ struct NvdecRegisters {
|
|||||||
u64 h264_last_surface_chroma_offset; ///< 0x0858
|
u64 h264_last_surface_chroma_offset; ///< 0x0858
|
||||||
std::array<u64, 17> surface_luma_offset; ///< 0x0860
|
std::array<u64, 17> surface_luma_offset; ///< 0x0860
|
||||||
std::array<u64, 17> surface_chroma_offset; ///< 0x08E8
|
std::array<u64, 17> surface_chroma_offset; ///< 0x08E8
|
||||||
INSERT_PADDING_WORDS_NOINIT(132); ///< 0x0970
|
INSERT_PADDING_WORDS_NOINIT(68); ///< 0x0970
|
||||||
|
u64 vp8_prob_data_offset; ///< 0x0A80
|
||||||
|
u64 vp8_header_partition_buf_offset; ///< 0x0A88
|
||||||
|
INSERT_PADDING_WORDS_NOINIT(60); ///< 0x0A90
|
||||||
u64 vp9_entropy_probs_offset; ///< 0x0B80
|
u64 vp9_entropy_probs_offset; ///< 0x0B80
|
||||||
u64 vp9_backward_updates_offset; ///< 0x0B88
|
u64 vp9_backward_updates_offset; ///< 0x0B88
|
||||||
u64 vp9_last_frame_segmap_offset; ///< 0x0B90
|
u64 vp9_last_frame_segmap_offset; ///< 0x0B90
|
||||||
@ -81,6 +84,8 @@ ASSERT_REG_POSITION(h264_last_surface_luma_offset, 0x10A);
|
|||||||
ASSERT_REG_POSITION(h264_last_surface_chroma_offset, 0x10B);
|
ASSERT_REG_POSITION(h264_last_surface_chroma_offset, 0x10B);
|
||||||
ASSERT_REG_POSITION(surface_luma_offset, 0x10C);
|
ASSERT_REG_POSITION(surface_luma_offset, 0x10C);
|
||||||
ASSERT_REG_POSITION(surface_chroma_offset, 0x11D);
|
ASSERT_REG_POSITION(surface_chroma_offset, 0x11D);
|
||||||
|
ASSERT_REG_POSITION(vp8_prob_data_offset, 0x150);
|
||||||
|
ASSERT_REG_POSITION(vp8_header_partition_buf_offset, 0x151);
|
||||||
ASSERT_REG_POSITION(vp9_entropy_probs_offset, 0x170);
|
ASSERT_REG_POSITION(vp9_entropy_probs_offset, 0x170);
|
||||||
ASSERT_REG_POSITION(vp9_backward_updates_offset, 0x171);
|
ASSERT_REG_POSITION(vp9_backward_updates_offset, 0x171);
|
||||||
ASSERT_REG_POSITION(vp9_last_frame_segmap_offset, 0x172);
|
ASSERT_REG_POSITION(vp9_last_frame_segmap_offset, 0x172);
|
||||||
|
Loading…
Reference in New Issue
Block a user