From 1967a2e0d465d1530d5dc0f33de2fd960a61fe8f Mon Sep 17 00:00:00 2001 From: rcaridade145 Date: Wed, 29 Apr 2026 16:20:30 +0100 Subject: [PATCH] Document and clean commit --- src/Cafe/OS/libs/h264_avc/H264Dec.cpp | 58 ++++++------------- .../OS/libs/h264_avc/H264DecBackendAVC.cpp | 4 ++ .../OS/libs/h264_avc/parser/H264Parser.cpp | 1 - 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/Cafe/OS/libs/h264_avc/H264Dec.cpp b/src/Cafe/OS/libs/h264_avc/H264Dec.cpp index d5feae04..5fffe2b1 100644 --- a/src/Cafe/OS/libs/h264_avc/H264Dec.cpp +++ b/src/Cafe/OS/libs/h264_avc/H264Dec.cpp @@ -32,16 +32,16 @@ namespace H264 { struct { - MEMPTR ptr{nullptr}; - uint32be length{0}; + MEMPTR ptr{ nullptr }; + uint32be length{ 0 }; float64be timestamp; - } BitStream; + }BitStream; struct { - MEMPTR outputFunc{nullptr}; - uint8be outputPerFrame{0}; // whats the default? - MEMPTR userMemoryParam{nullptr}; - } Param; + MEMPTR outputFunc{ nullptr }; + uint8be outputPerFrame{ 0 }; // whats the default? + MEMPTR userMemoryParam{ nullptr }; + }Param; // misc uint32be sessionHandle; @@ -49,7 +49,7 @@ namespace H264 struct { uint32 numFramesInFlight{0}; - } decoderState; + }decoderState; }; uint32 H264DECMemoryRequirement(uint32 codecProfile, uint32 codecLevel, uint32 width, uint32 height, uint32be* sizeRequirementOut) @@ -189,31 +189,11 @@ namespace H264 return H264DEC_STATUS::BAD_STREAM; } - - size_t EBSPtoRBSP(uint8_t* dst, const uint8_t* src, size_t size) - { - size_t j = 0; - int zeroCount = 0; - - for (size_t i = 0; i < size; i++) - { - if (zeroCount == 2 && src[i] == 0x03) - { - zeroCount = 0; - continue; // skip emulation prevention byte - } - - dst[j++] = src[i]; - - if (src[i] == 0) - zeroCount++; - else - zeroCount = 0; - } - - return j; - } - + /** + * Changed to detect 3 or 4 emulation prevention bytes. + * The "escape character" is 0x03 - also known as emulation_prevention_three_byte + * ([0x000001][first NAL unit]) | ([0x000001][second NAL unit]) | ([0x000001][third NAL unit]) + */ H264DEC_STATUS H264DECGetImageSize( uint8* stream, uint32 length, @@ -337,7 +317,7 @@ namespace H264 std::unordered_map sDecoderSessions; std::mutex sDecoderSessionsMutex; - std::atomic_uint32_t sCurrentSessionHandle{1}; + std::atomic_uint32_t sCurrentSessionHandle{ 1 }; H264DecoderBackend* CreateAVCDecoder(); @@ -526,7 +506,7 @@ namespace H264 /* +0x44 */ MEMPTR imagePtr; /* +0x48 */ uint32 vuiEnable; - /* +0x4C */ MPTR vuiPtr; + /* +0x4C */ MPTR vuiPtr; /* +0x50 */ sint32 unused[10]; }; @@ -653,7 +633,7 @@ namespace H264 maxLength -= startCodeOffset; // parse NAL data - while (true) + while(true) { if (nalStream.isEndOfStream()) break; @@ -714,7 +694,7 @@ namespace H264 class : public COSModule { - public: + public: std::string_view GetName() override { return "h264"; @@ -744,10 +724,10 @@ namespace H264 cafeExportRegister("h264", H264DECCheckDecunitLength, LogType::H264); }; - } s_COSh264Module; + }s_COSh264Module; COSModule* GetModule() { return &s_COSh264Module; } -} // namespace H264 +} diff --git a/src/Cafe/OS/libs/h264_avc/H264DecBackendAVC.cpp b/src/Cafe/OS/libs/h264_avc/H264DecBackendAVC.cpp index 203efcb3..dbaeb2ac 100644 --- a/src/Cafe/OS/libs/h264_avc/H264DecBackendAVC.cpp +++ b/src/Cafe/OS/libs/h264_avc/H264DecBackendAVC.cpp @@ -195,6 +195,10 @@ namespace H264 cemu_assert(s_dec_op.u4_frame_decoded_flag); + /** + * While testing Cod:Ghosts i found that ih264d may not consume the entire buffer. + * So transformed into a Log not an assert. + */ if (s_dec_op.u4_num_bytes_consumed < decodedSlice.dataToDecode.m_length) { // log instead of asserting diff --git a/src/Cafe/OS/libs/h264_avc/parser/H264Parser.cpp b/src/Cafe/OS/libs/h264_avc/parser/H264Parser.cpp index 9b98f6e6..23f58699 100644 --- a/src/Cafe/OS/libs/h264_avc/parser/H264Parser.cpp +++ b/src/Cafe/OS/libs/h264_avc/parser/H264Parser.cpp @@ -163,7 +163,6 @@ bool parseNAL_seq_parameter_set_rbsp(h264ParserState_t* h264ParserState, h264Par if (h264ParserState->sps.frame_mbs_only_flag == 0) { h264ParserState->sps.mb_adaptive_frame_field_flag = nalStream.readBit(); - //cemu_assert_debug(false); } else h264ParserState->sps.mb_adaptive_frame_field_flag = 0; // default is zero?