From 6c8c71a125ce6aa0ba26b8046b2d7fe543e0c84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 22 Oct 2026 21:02:36 +0200 Subject: [PATCH 1/3] AvcDecoder: Keep the output clock going when a new stream is spliced on Burnout Legends feeds its intro movies to one decoder back to back, with no flush in between. Each new stream opens with a buffering period whose cpb_removal_delay is 0, which put our reconstructed clock 18 frames back, so every picture after it was held until the clock caught up, and then 20 came out of one decode. sceMpegAvcDecodeYCbCr converts every picture a decode reports into the caller's buffer list, which only has room for one, so mpeg.prx went on through stack garbage and crashed as the title screen came up. Such a buffering period now continues from the last access unit instead. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HW/AvcDecoder.cpp | 17 ++++++++++++++++- Core/HW/AvcDecoder.h | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Core/HW/AvcDecoder.cpp b/Core/HW/AvcDecoder.cpp index 2d808c100d..8944455416 100644 --- a/Core/HW/AvcDecoder.cpp +++ b/Core/HW/AvcDecoder.cpp @@ -169,6 +169,8 @@ void AvcDecoder::Flush() { timings_.clear(); lastTiming_ = AvcTiming(); bufferingTick_ = 0; + lastRemovalTick_ = 0; + removalStep_ = 2; firstTiming_ = true; nextIndex_ = 0; released_ = 0; @@ -429,11 +431,24 @@ int AvcDecoder::DecodePictures(const u8 *data, int size) { if (parser_->dts_ref_dts_delta != INT_MIN && parser_->pts_dts_delta != INT_MIN) { timed = true; if (parser_->dts_sync_point > 0) { - bufferingTick_ = firstTiming_ ? 0 : bufferingTick_ + parser_->dts_ref_dts_delta; + if (firstTiming_) { + bufferingTick_ = 0; + } else if (parser_->dts_ref_dts_delta > 0) { + bufferingTick_ += parser_->dts_ref_dts_delta; + } else { + // A new stream fed in without a flush (Burnout Legends' intro movies) starts its + // clock over. Carry on from the last access unit, or every picture after this + // one waits until the new clock catches up with the old one. + bufferingTick_ = lastRemovalTick_ + removalStep_; + } removalTick = bufferingTick_; } else { removalTick = bufferingTick_ + parser_->dts_ref_dts_delta; } + if (!firstTiming_ && removalTick > lastRemovalTick_) { + removalStep_ = removalTick - lastRemovalTick_; + } + lastRemovalTick_ = removalTick; firstTiming_ = false; outputTicks_[index] = removalTick + parser_->pts_dts_delta; lastTiming_.picTiming = true; diff --git a/Core/HW/AvcDecoder.h b/Core/HW/AvcDecoder.h index 192ffc6aa1..ff4608a351 100644 --- a/Core/HW/AvcDecoder.h +++ b/Core/HW/AvcDecoder.h @@ -138,6 +138,9 @@ private: std::map timings_; AvcTiming lastTiming_; s64 bufferingTick_ = 0; + // The last access unit's removal tick, and how far apart the last two were (2 ticks a frame). + s64 lastRemovalTick_ = 0; + s64 removalStep_ = 2; bool firstTiming_ = true; int nextIndex_ = 0; int released_ = 0; From ddfd3bcfb9f087344f5161273c8ad6bb70f02859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 22 Oct 2026 21:47:39 +0200 Subject: [PATCH 2/3] CmdLine: Take integer parameters in hex too, and refuse trailing junk They were read with sscanf("%d"), which stops at the first character it can't use, so --disable-hle=0x110 was accepted as 0 and quietly ran everything on our HLE. Now decimal or 0x hex, optionally signed, and the whole value has to parse. Up to 0xFFFFFFFF is taken, for full masks. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/CmdLine.cpp | 31 ++++++++++++++++++++++++++++++- unittest/UnitTest.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Core/CmdLine.cpp b/Core/CmdLine.cpp index 34651fb05e..1e1e8f3e8e 100644 --- a/Core/CmdLine.cpp +++ b/Core/CmdLine.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -51,6 +52,34 @@ enum class ParseParamResult { BadValue, }; +// Decimal, or hex with 0x, optionally signed. Not base 0, which would read a leading 0 as octal. +// Up to 0xFFFFFFFF is accepted so a full 32-bit mask can be given, and wraps into the int. +static bool ParseIntParam(const std::string &value, int *out) { + const char *p = value.c_str(); + bool negative = false; + if (*p == '-' || *p == '+') { + negative = *p == '-'; + p++; + } + int base = 10; + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { + base = 16; + p += 2; + } + // strtoull would take another sign or leading spaces here. + if (!isxdigit((unsigned char)*p)) { + return false; + } + char *end = nullptr; + errno = 0; + const unsigned long long magnitude = strtoull(p, &end, base); + if (*end != '\0' || errno == ERANGE || magnitude > (negative ? 0x80000000ULL : 0xFFFFFFFFULL)) { + return false; + } + *out = negative ? (int)(0 - (uint32_t)magnitude) : (int)(uint32_t)magnitude; + return true; +} + ParseParamResult SetValue(CommandLineOptions *options, const CommandLineParam ¶m, const std::string &value) { uint8_t *optionsPtr = reinterpret_cast(options); switch (param.type) { @@ -77,7 +106,7 @@ ParseParamResult SetValue(CommandLineOptions *options, const CommandLineParam &p { // Not std::stoi - that throws on junk, which takes the process down with no diagnostic. int v; - if (sscanf(value.c_str(), "%d", &v) != 1) { + if (!ParseIntParam(value, &v)) { PRINT_STDERR("Error: Invalid value for integer parameter --%s: '%s'.\n", param.longName, value.c_str()); return ParseParamResult::BadValue; } diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index da1860fb52..f82f42f424 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -3391,6 +3391,33 @@ bool TestCmdLine() { EXPECT_TRUE(options.memStickInserted.has_value()); EXPECT_FALSE(options.memStickInserted.value_or(true)); } + // Integers take decimal or 0x hex. A leading 0 is still decimal, and a full 32-bit mask wraps + // into the int rather than being refused. + { + const char *argv[] = { + "ppsspp", + "--disable-hle=0x110", + "--force-hle=0xFFFFFFFF", + "--cpu-mhz=0333", + "--resolution-scale=-2", + }; + int argc = ARRAY_SIZE(argv); + CommandLineOptions options; + EXPECT_EQ_INT((int)options.Parse(argc, argv, CmdLineMode::Headless), (int)CommandLineParseResult::Continue); + EXPECT_EQ_INT(options.disableHLE.value_or(0), 0x110); + EXPECT_EQ_INT(options.forceHLE.value_or(0), -1); + EXPECT_EQ_INT(options.lockedCPUSpeed.value_or(0), 333); + EXPECT_EQ_INT(options.resolutionScale.value_or(0), -2); + } + // Trailing junk used to be ignored, so 0x110 quietly meant 0. + { + const char *bad[] = { "--disable-hle=0x110junk", "--disable-hle=12abc", "--disable-hle=0x", "--disable-hle= 5", "--disable-hle=0x100000000", "--disable-hle=--1" }; + for (const char *arg : bad) { + const char *argv[] = { "ppsspp", arg }; + CommandLineOptions options; + EXPECT_EQ_INT((int)options.Parse(ARRAY_SIZE(argv), argv, CmdLineMode::Headless), (int)CommandLineParseResult::Error); + } + } // Test GL version override { const char *argv[] = { From 56c8d067af77d4085c85ffa2af32f094995feace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 22 Oct 2026 21:47:39 +0200 Subject: [PATCH 3/3] pspautotests: avchold covers a stream spliced on without a flush Updates the submodule for video/mp4/avchold's ref3b1hrdsplice, recorded on a PSP, which fails without the AvcDecoder fix on this branch: the pictures after the splice never come out. avchold and decodeend only test anything with Sony's mpeg and mp4 modules running, which headless never does for homebrew unless asked, and which CI doesn't have. docs/pspautotests.md now says how to run them (--disable-hle=0x110 and a memory stick with a firmware dump). Co-Authored-By: Claude Opus 5.5 (1M context) --- AGENTS.md | 2 +- docs/pspautotests.md | 26 ++++++++++++++++++++++++++ pspautotests | 2 +- test.py | 4 ++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9c4661f916..2e866443fc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,7 +17,7 @@ for it: | [docs/DebuggerThreading.md](docs/DebuggerThreading.md) | `Core_RunOnCPUThread` / `g_frameMutex` / shutdown-lock rules - required reading before touching debugger code | | [docs/HLEModules.md](docs/HLEModules.md) | Adding an HLE module or function, and the seven build files a new source file goes in | | [docs/translations.md](docs/translations.md) | Translating UI strings with Tools/langtool | -| [docs/pspautotests.md](docs/pspautotests.md) | Workflow for improving PPSSPP using pspautotests | +| [docs/pspautotests.md](docs/pspautotests.md) | Workflow for improving PPSSPP using pspautotests, and running the tests that need the real firmware modules (`--disable-hle`, a firmware memstick) | | [docs/pspautotests-hardware.md](docs/pspautotests-hardware.md) | Writing a new pspautotest, and running it on a real PSP over PSPLink to record its `.expected` | | [docs/frametest.md](docs/frametest.md) | Framedump rendering tests, and replaying a dump on a real PSP | | [docs/sceGe.md](docs/sceGe.md) | How the firmware queues display lists, what SIGNAL and FINISH interrupts do and in which order, and how `ProcessDLQueue()` keeps that order | diff --git a/docs/pspautotests.md b/docs/pspautotests.md index 24134285fc..052652f47b 100644 --- a/docs/pspautotests.md +++ b/docs/pspautotests.md @@ -57,6 +57,32 @@ Instead of a single PRX, you can pass a directory (e.g. `pspautotests/tests/thre same idea in emulated time, and both can be set at once. `--timeout` is the old name for `--timeout-wall`. - `--graphics=software` — uses software GPU backend (required for headless; no real GPU available). +### Tests that need the real firmware modules + +A pspautotest is homebrew, so headless runs every library on our HLE for it +(`iForceEnableHLE` in `headless/Headless.cpp`), even the ones the app runs from the firmware by +default. Some tests only mean anything against the real module: `video/mp4/avchold` and +`video/mpeg/decodeend` test the Media Engine through Sony's `libmp4.prx`, `mp4msv.prx` and +`mpeg.prx`, which call our `sceVideocodec` HLE. Run on our HLE, `avchold` reports +`0 samples, 0 decodes` for every stream (our sceMp4 is stubs: the log says `UNIMPL sceMp4Create`), +and it fails without exercising the decoder at all. + +To run them as the hardware does, pass both: + +- `--disable-hle=N`, the `DisableHLEFlags` bits (`Core/ConfigValues.h`) of the libraries to run + for real, in decimal or `0x` hex. sceMpeg is 0x10 and sceMp4 is 0x100, so the video tests take + `--disable-hle=0x110`. +- `--memstick=` pointing at a memory stick with a firmware dump in `PSP/NAND/flash0/kd`. `test.py` + otherwise hands headless the empty one beside the exe. Since the flag is explicit, headless exits + with an error naming the missing module rather than falling back to HLE. + +``` +python test.py video/mp4/avchold video/mpeg/decodeend --graphics=software --memstick= --disable-hle=0x110 +``` + +CI has no firmware dump, so these tests stay in `tests_next`, and a change to the video path +needs this run done by hand. + ### What you'll see **Passing test:** diff --git a/pspautotests b/pspautotests index 74cdeea078..51fc2c4d87 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 74cdeea078403a9d877b99e28c3cad85ba7f3d7f +Subproject commit 51fc2c4d87fc09df9e87a62e1755ae4816cda13a diff --git a/test.py b/test.py index d8b974add4..fe430cad47 100755 --- a/test.py +++ b/test.py @@ -675,9 +675,9 @@ tests_next = [ #"utility/savedata/saveemptyfilename", "utility/savedata/secureversion", "utility/savedata/sizes", - "video/mp4/avchold", + "video/mp4/avchold", # needs Sony's mp4 and mpeg modules: --disable-hle=0x110, see docs/pspautotests.md "video/mpeg/basic", - "video/mpeg/decodeend", + "video/mpeg/decodeend", # needs Sony's mpeg module, as avchold "video/mpeg/deletetiming", "video/pmf/pmf", "video/pmf_simple/pmf_simple",