Xbox Cloud Gaming app for PS5 Homebrew
C
feat(media): implement hardware video decoding via libSceVideodec2 on PS5 and HWAccel on desktop
Rafael Abud Ferreira5a6339a1e674
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 1e443d0..b9fa1e0 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -181,7 +181,7 @@ else()endif()add_executable(xcloud-cli src/app/cli_main.cpp)- target_link_libraries(xcloud-cli PRIVATE xcloud_stream xcloud_media xcloud_ui xc_ffmpeg)+ target_link_libraries(xcloud-cli PRIVATE xcloud_stream xcloud_media xcloud_ui xcloud_backends_null xc_ffmpeg)enable_testing()add_executable(xcloud-tests tests/test_main.cpp)diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex c4b0190..175ca1e 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -105,9 +105,13 @@ void loadAutoplay() {if (opt == "wishlisttest") g_autoplay.wishlistTest = true;if (opt == "vibetest") g_autoplay.vibeTest = true;if (opt == "vktest") g_autoplay.vkTest = true;- if (opt == "cpudisplay") g_autoplay.cpuDisplay = true;- if (opt == "hwdecode") g_autoplay.hwDecode = true;- if (opt == "droptest") g_autoplay.dropTest = true;+ if (opt == "hwdecode") { g_autoplay.preferHwDecode = true; g_autoplay.swDecode = false; g_autoplay.hwDecode = true; }+ if (opt == "swdecode") { g_autoplay.preferHwDecode = false; g_autoplay.swDecode = true; }+ if (opt.rfind("decoder=", 0) == 0) {+ std::string d = opt.substr(8);+ if (d == "hw" || d == "hardware") { g_autoplay.preferHwDecode = true; g_autoplay.swDecode = false; }+ else if (d == "sw" || d == "software") { g_autoplay.preferHwDecode = false; g_autoplay.swDecode = true; }+ }if (opt == "kbhints") ui::g_keyboardHints = g_autoplay.kbHints = true; // the hints and slots as with a keyboard (screenshots)if (opt.rfind("loss=", 0) == 0) g_autoplay.videoLoss = std::atoi(opt.c_str() + 5);if (opt == "ai") g_autoplay.upscaler = 1;diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex 12a579e..5b41606 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -58,6 +58,8 @@ struct Autoplay {bool restore = false; // restore: Anime4K Restore before the upscalebool dropTest = false; // droptest: the connection dropped at 20 sbool hwDecode = false; // hwdecode: the hardware decoder alongside, logged+ bool preferHwDecode = true; // hardware video decoding preferred by default+ bool swDecode = false; // swdecode: force software CPU decodingbool vibeTest = false; // each motor alone, with a notificationbool imeTest = false; // open the system keyboard on the home screenbool menuTest = false; // in the game: open the menu, switch to 720pdiff --git a/src/app/desktop_selftest.cpp b/src/app/desktop_selftest.cppindex 277f915..9b459cf 100644--- a/src/app/desktop_selftest.cpp+++ b/src/app/desktop_selftest.cpp@@ -343,6 +343,21 @@ int desktopSelftest(const std::string& dir) {bool barsOk = screenshot(dir, "3-video.png", shot);for (int b = 0; b < 8 && barsOk; ++b) barsOk = barMatches(shot, b, 540);check(barsOk, "colour bars through drawYuv420 + pump (3-video.png)");++ // An NV12 video frame (hardware decoder format) through drawNv12.+ std::vector<uint8_t> nv12Uv(static_cast<size_t>(bars.w) * (bars.h / 2));+ for (size_t i = 0; i < bars.u.size(); ++i) {+ nv12Uv[i * 2] = bars.u[i];+ nv12Uv[i * 2 + 1] = bars.v[i];+ }+ {+ std::lock_guard<std::mutex> lock(display::frameMutex());+ display::drawNv12(bars.y.data(), nv12Uv.data(), bars.w, bars.w, bars.w, bars.h, false);+ display::present();+ }+ bool nv12Ok = screenshot(dir, "3-video-nv12.png", shot);+ for (int b = 0; b < 8 && nv12Ok; ++b) nv12Ok = barMatches(shot, b, 540);+ check(nv12Ok, "colour bars through drawNv12 + pump (3-video-nv12.png)");check(display::lastPresentId() > 0, "present ids counted");if (dc.upscalers) {display::setSharpness(176);diff --git a/src/app/settings.cpp b/src/app/settings.cppindex 0e510a5..efa8396 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -66,6 +66,7 @@ bool Settings::load(const std::string& path) {sharpness = static_cast<int>(std::clamp<int64_t>((*j)["sharpness"].asInt(sharpness), 0, 3));deband = static_cast<int>(std::clamp<int64_t>((*j)["deband"].asInt(deband), 0, 3));upscaler = static_cast<int>(std::clamp<int64_t>((*j)["upscaler"].asInt(upscaler), 0, 3));+ videoDecoder = static_cast<int>(std::clamp<int64_t>((*j)["videoDecoder"].asInt(videoDecoder), 0, 1));// "deadzone": one for both sticks, until each could have its own.int both = static_cast<int>(std::clamp<int64_t>((*j)["deadzone"].asInt(15), 0, 50));deadzoneLeft = static_cast<int>(std::clamp<int64_t>((*j)["deadzoneLeft"].asInt(both), 0, 50));@@ -130,6 +131,7 @@ bool Settings::load(const std::string& path) {p.sharpness = static_cast<int>(std::clamp<int64_t>(obj["sharpness"].asInt(sharpness), 0, 3));p.deband = static_cast<int>(std::clamp<int64_t>(obj["deband"].asInt(deband), 0, 3));p.upscaler = static_cast<int>(std::clamp<int64_t>(obj["upscaler"].asInt(upscaler), 0, 3));+ p.videoDecoder = static_cast<int>(std::clamp<int64_t>(obj["videoDecoder"].asInt(videoDecoder), 0, 1));int resDef = resolution == "720p" ? 1 : resolution == "1440p" ? 2 : 0;p.resolution = static_cast<int>(std::clamp<int64_t>(obj["resolution"].asInt(resDef), 0, 2));p.deadzoneLeft = static_cast<int>(std::clamp<int64_t>(obj["deadzoneLeft"].asInt(deadzoneLeft), 0, 50));@@ -162,6 +164,7 @@ GameProfile Settings::defaultProfile() const {p.sharpness = sharpness;p.deband = deband;p.upscaler = upscaler;+ p.videoDecoder = videoDecoder;p.resolution = resolution == "720p" ? 1 : resolution == "1440p" ? 2 : 0;p.deadzoneLeft = deadzoneLeft;p.deadzoneRight = deadzoneRight;@@ -223,6 +226,7 @@ bool Settings::save(const std::string& path) const {v.set("sharpness", sharpness);v.set("deband", deband);v.set("upscaler", upscaler);+ v.set("videoDecoder", videoDecoder);v.set("deadzoneLeft", deadzoneLeft);v.set("deadzoneRight", deadzoneRight);v.set("triggerStrength", triggerStrength);@@ -267,6 +271,7 @@ bool Settings::save(const std::string& path) const {obj.set("sharpness", p.sharpness);obj.set("deband", p.deband);obj.set("upscaler", p.upscaler);+ obj.set("videoDecoder", p.videoDecoder);obj.set("resolution", p.resolution);obj.set("deadzoneLeft", p.deadzoneLeft);obj.set("deadzoneRight", p.deadzoneRight);diff --git a/src/app/settings.h b/src/app/settings.hindex c078c81..25b5d34 100644--- a/src/app/settings.h+++ b/src/app/settings.h@@ -26,6 +26,7 @@ struct GameProfile {int deband = 3; // 0 off, 1 low, 2 high, 3 autoint upscaler = 2; // 0 FSR 1, 1 Anime4K, 2 FSR + clean, 3 Anime4K + cleanint resolution = 0; // 0 1080p, 1 720p, 2 1440p+ int videoDecoder = 0; // 0 Hardware, 1 Software// Controller: dead zone (percent), triggers, confirm buttonint deadzoneLeft = 15, deadzoneRight = 15;int triggerStrength = 2; // 0 off .. 4 max@@ -79,6 +80,7 @@ struct Settings {// Upscaling to the 4K display (GPU): 0 FSR 1, 1 Anime4K, 2 FSR and 3// Anime4K after Anime4K Restore (the clean-up of compression artefacts).int upscaler = 2;+ int videoDecoder = 0; // 0 Hardware, 1 Software// Controller: stick dead zone (percent), vibration in the triggers,// Circle as the confirm button (Xbox A).int deadzoneLeft = 15, deadzoneRight = 15; // percent, each stick's owndiff --git a/src/app/stream_player.cpp b/src/app/stream_player.cppindex 5d55318..6fb0c03 100644--- a/src/app/stream_player.cpp+++ b/src/app/stream_player.cpp@@ -93,6 +93,8 @@ struct StreamPlayer::Impl {int simulatedLoss = 0;int maxBitrateMbps = 0;bool hwProbe = false;+ bool preferHwDecode = true;+ std::atomic<bool> isHwDecode{false};static void atomicMax(std::atomic<uint64_t>& a, uint64_t v) {uint64_t cur = a;@@ -281,18 +283,19 @@ struct StreamPlayer::Impl {void videoLoop() {platform::setThreadAffinity(platform::ThreadRole::VideoDecode, "xcloud_vdec");media::VideoDecoder decoder;- if (!decoder.init(decodeThreads)) {+ if (!decoder.init(decodeThreads, preferHwDecode)) {end("could not start the H.264 decoder");return;}+ isHwDecode = decoder.isHardware();VideoFrame frame;std::vector<uint8_t>& au = frame.data;// Timings of the frames handed to the decoder, by RTP timestamp:// pictures can come out later than their input.std::deque<stream::FrameMetadata> inFlight;media::HwDecoder hw;- bool hwOk = hwProbe && hw.init(1920, 1088);- if (hwProbe) XC_LOGI("hwdec: probe %s", hwOk ? "running" : "failed to start");+ bool hwOk = hwProbe && !decoder.isHardware() && hw.init(1920, 1088);+ if (hwProbe && !decoder.isHardware()) XC_LOGI("hwdec: probe %s", hwOk ? "running" : "failed to start");uint64_t hwUs = 0, hwMaxUs = 0, hwPictures = 0, hwCalls = 0, hwLogAt = platform::nowMs() + 1000;constexpr uint64_t kShownRing = 8;std::pair<uint64_t, uint64_t> inScreenQueue[kShownRing] = {}; // present id, arrival us@@ -344,6 +347,7 @@ struct StreamPlayer::Impl {if (inFlight.size() > 16) inFlight.pop_front();uint64_t t0 = platform::nowUs();bool ok = decoder.decode(au.data(), au.size(), pic, frame.rtpTimestamp);+ isHwDecode = decoder.isHardware();uint64_t t1 = platform::nowUs();bool known = false;if (ok) {@@ -390,14 +394,22 @@ struct StreamPlayer::Impl {}bool screenshot = saveSnapshotIfAsked(pic);std::lock_guard<std::mutex> lock(display::frameMutex());- if (decodedFrames == 1) XC_LOGI("first draw %dx%d", pic.width, pic.height);+ if (decodedFrames == 1) {+ XC_LOGI("first draw %dx%d (%s, %s)", pic.width, pic.height,+ pic.format == media::Picture::Format::Nv12 ? "NV12" : "YUV420P",+ decoder.isHardware() ? "hardware" : "software");+ }uint64_t t2 = platform::nowUs();// Try acquire with zero wait first; if not ready, wait for swapchain image.- bool drawn = display::drawYuv420(pic.y, pic.u, pic.v, pic.strideY, pic.strideU, pic.strideV,- pic.width, pic.height, false);+ auto drawPic = [](const media::Picture& p, bool wait) {+ if (p.format == media::Picture::Format::Nv12) {+ return display::drawNv12(p.y, p.u, p.strideY, p.strideU, p.width, p.height, wait);+ }+ return display::drawYuv420(p.y, p.u, p.v, p.strideY, p.strideU, p.strideV, p.width, p.height, wait);+ };+ bool drawn = drawPic(pic, false);if (!drawn) {- drawn = display::drawYuv420(pic.y, pic.u, pic.v, pic.strideY, pic.strideU, pic.strideV,- pic.width, pic.height, true);+ drawn = drawPic(pic, true);}if (!drawn) {++lateFrames;@@ -650,11 +662,14 @@ struct StreamPlayer::Impl {screenPath = path.substr(0, path.rfind('/') + 1) + "screen.ppm";int w = pic.width / 2, h = pic.height / 2;std::vector<uint8_t> rgb(static_cast<size_t>(w) * h * 3);+ const bool isNv12 = (pic.format == media::Picture::Format::Nv12);for (int y = 0; y < h; ++y)for (int x = 0; x < w; ++x) {int c = (pic.y[(2 * y) * pic.strideY + 2 * x] - 16) * 1192;- int d = pic.u[y * pic.strideU + x] - 128;- int e = pic.v[y * pic.strideV + x] - 128;+ int d = isNv12 ? (pic.u[y * pic.strideU + 2 * x] - 128)+ : (pic.u[y * pic.strideU + x] - 128);+ int e = isNv12 ? (pic.u[y * pic.strideU + 2 * x + 1] - 128)+ : (pic.v[y * pic.strideV + x] - 128);auto clamp = [](int v) { return static_cast<uint8_t>(v < 0 ? 0 : v > 255 ? 255 : v); };uint8_t* o = &rgb[(static_cast<size_t>(y) * w + x) * 3];o[0] = clamp((c + 1836 * e + 512) >> 10);@@ -864,6 +879,8 @@ void StreamPlayer::requestSnapshot(const std::string& path) {void StreamPlayer::stop() { impl_->stop(); }void StreamPlayer::setHwDecodeProbe(bool on) { impl_->hwProbe = on; }+void StreamPlayer::setPreferHwDecode(bool on) { impl_->preferHwDecode = on; }+bool StreamPlayer::preferHwDecode() const { return impl_->preferHwDecode; }void StreamPlayer::setDecodeThreads(int threads) { impl_->decodeThreads = std::max(1, threads); }void StreamPlayer::setMaxBitrate(int mbps) { impl_->maxBitrateMbps = std::clamp(mbps, 0, 50); }@@ -882,6 +899,7 @@ StreamPlayer::Stats StreamPlayer::stats() const {st.lateFrames = impl_->lateFrames;st.width = static_cast<int>(impl_->pictureSize >> 16);st.height = static_cast<int>(impl_->pictureSize & 0xFFFF);+ st.isHwDecode = impl_->isHwDecode.load();// Timings since the previous call.uint64_t dc = impl_->decodeCalls.exchange(0), du = impl_->decodeUs.exchange(0);uint64_t rc = impl_->drawCalls.exchange(0), ru = impl_->drawUs.exchange(0);diff --git a/src/app/stream_player.h b/src/app/stream_player.hindex ccb0b0b..933c14e 100644--- a/src/app/stream_player.h+++ b/src/app/stream_player.h@@ -84,6 +84,7 @@ public:uint64_t displayAvgUs = 0, displayMaxUs = 0;// The pictures' average quantiser since the last call (lower: finer); -1 none.double qpAvg = -1;+ bool isHwDecode = false;};Stats stats() const;// Before start(): H.264 decoder threads (more than 1 = frame threading).@@ -95,6 +96,10 @@ public:// Before start(): also run every frame through the PS5's hardware// decoder and log how it does (the picture still comes from FFmpeg).void setHwDecodeProbe(bool on);+ // Before start(): prefer hardware video decoding (libSceVideodec2 on PS5,+ // FFmpeg HWAccel on Desktop) with automatic software CPU fallback.+ void setPreferHwDecode(bool on);+ bool preferHwDecode() const;// Recent presentation frametimes (ms, up to 60 frames)void getRecentFrametimes(std::vector<float>& out) const;diff --git a/src/app/worker.cpp b/src/app/worker.cppindex 22f39a1..a58bdbf 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -162,6 +162,18 @@ std::string stream(xcloud::GssvClient& gssv) {player.setHwDecodeProbe(g_autoplay.hwDecode);{std::lock_guard<std::mutex> lock(g_settingsMutex);+ bool hasCustom = false;+ GameProfile prof = g_settings.profileForGame(g_stageProduct, g_stageTitle, &hasCustom);+ bool preferHw = true;+ if (g_autoplay.swDecode) {+ preferHw = false;+ } else if (g_autoplay.preferHwDecode) {+ preferHw = (hasCustom ? (prof.videoDecoder == 0) : (g_settings.videoDecoder == 0));+ } else {+ preferHw = false;+ }+ player.setPreferHwDecode(preferHw);+ XC_LOGI("stream: video decoder %s", preferHw ? "hardware preferred" : "software (CPU)");player.setMicGain(g_settings.micGainFactor());player.setMicEnabled(g_settings.micEnabled);int cap = g_autoplay.bitrateMbps > 0 ? g_autoplay.bitrateMbps : g_settings.maxBitrateMbps;@@ -265,7 +277,7 @@ std::string stream(xcloud::GssvClient& gssv) {auto st = player.stats();XC_LOGI("stream: %llu frames, %llu decoded, %llu skipped, %llu failed, %llu resets, %llu kf req, ""%llu queued, %llu audio; rtp %llu pkts, %llu lost, %llu recovered, %llu nacks, "- "%llu frames dropped; %llu kbps (remb %llu); %llu rumble; decode %.1f/%.1f ms, draw %.1f/%.1f ms, %llu late; "+ "%llu frames dropped; %llu kbps (remb %llu); %llu rumble; decode %.1f/%.1f ms (%s), draw %.1f/%.1f ms, %llu late; ""rtt %d ms; %dx%d; on screen %.1f/%.1f ms after arrival; qp %.1f",static_cast<unsigned long long>(st.videoFrames), static_cast<unsigned long long>(st.decodedFrames),static_cast<unsigned long long>(st.droppedFrames), static_cast<unsigned long long>(st.decodeFailures),@@ -275,7 +287,8 @@ std::string stream(xcloud::GssvClient& gssv) {static_cast<unsigned long long>(st.rtpRecovered), static_cast<unsigned long long>(st.rtpNacks),static_cast<unsigned long long>(st.rtpDroppedFrames), static_cast<unsigned long long>(st.rtpKbps),static_cast<unsigned long long>(st.rembKbps), static_cast<unsigned long long>(st.vibrations),- st.decodeAvgUs / 1000.0, st.decodeMaxUs / 1000.0, st.drawAvgUs / 1000.0, st.drawMaxUs / 1000.0,+ st.decodeAvgUs / 1000.0, st.decodeMaxUs / 1000.0, st.isHwDecode ? "HW" : "SW",+ st.drawAvgUs / 1000.0, st.drawMaxUs / 1000.0,static_cast<unsigned long long>(st.lateFrames), st.rttMs, st.width, st.height,st.displayAvgUs / 1000.0, st.displayMaxUs / 1000.0, st.qpAvg);if (st.rttMs > 0 && (bestRtt < 0 || st.rttMs < bestRtt)) bestRtt = st.rttMs;@@ -297,6 +310,7 @@ std::string stream(xcloud::GssvClient& gssv) {uint64_t lost = st.rtpLost - last.rtpLost, got = st.rtpPackets - last.rtpPackets;info.lossPct = got + lost ? 100.0 * lost / (got + lost) : 0;info.decodeMs = st.decodeAvgUs / 1000.0;+ info.isHwDecode = st.isHwDecode;info.onScreenMs = st.displayAvgUs / 1000.0;info.width = st.width;info.height = st.height;diff --git a/src/display/display.h b/src/display/display.hindex 2d64f7a..6f54ab5 100644--- a/src/display/display.h+++ b/src/display/display.h@@ -43,6 +43,8 @@ void idleWait(uint32_t ms);// returns false and draws nothing.bool drawYuv420(const uint8_t* y, const uint8_t* u, const uint8_t* v, int strideY, int strideU, int strideV,int width, int height, bool wait);+bool drawNv12(const uint8_t* y, const uint8_t* uv, int strideY, int strideUV,+ int width, int height, bool wait);// A picture laid over every video frame drawYuv420() draws from now on (the// in-game menu, the statistics): `w` x `h` RGBA pixels at (x, y), blended atdiff --git a/src/display/display_null.cpp b/src/display/display_null.cppindex 642ff3f..27b73fc 100644--- a/src/display/display_null.cpp+++ b/src/display/display_null.cpp@@ -16,7 +16,14 @@ std::mutex& frameMutex() {bool init(bool) { return true; }void shutdown() {}void present() { platform::sleepMs(16); }-bool drawYuv420(const uint8_t*, const uint8_t*, const uint8_t*, int, int, int, int, int, bool) { return true; }+bool drawYuv420(const uint8_t* y, const uint8_t* u, const uint8_t* v, int strideY, int strideU, int strideV, int width, int height, bool) {+ if (!y || !u || !v || width <= 0 || height <= 0 || strideY < width) return false;+ return true;+}+bool drawNv12(const uint8_t* y, const uint8_t* uv, int strideY, int strideUV, int width, int height, bool) {+ if (!y || !uv || width <= 0 || height <= 0 || strideY < width || strideUV < width) return false;+ return true;+}void drawRgba(const uint32_t*) {}void pump() {}void idleWait(uint32_t ms) { platform::sleepMs(ms); }diff --git a/src/display/display_ps5.cpp b/src/display/display_ps5.cppindex 2614804..cc60a66 100644--- a/src/display/display_ps5.cpp+++ b/src/display/display_ps5.cpp@@ -430,6 +430,25 @@ void drawRgba(const uint32_t* pixels) {});}+bool drawNv12(const uint8_t* y, const uint8_t* uv, int strideY, int strideUV,+ int width, int height, bool wait) {+ if (gpu::ready()) return gpu::drawNv12(y, uv, strideY, strideUV, width, height, wait);+ if (!g_mappedMemory || width <= 0 || height <= 0) return false;+ int cw = (width + 1) / 2, ch = (height + 1) / 2;+ std::vector<uint8_t> u(static_cast<size_t>(cw) * ch);+ std::vector<uint8_t> v(static_cast<size_t>(cw) * ch);+ for (int r = 0; r < ch; ++r) {+ const uint8_t* src = uv + static_cast<size_t>(r) * strideUV;+ uint8_t* du = &u[static_cast<size_t>(r) * cw];+ uint8_t* dv = &v[static_cast<size_t>(r) * cw];+ for (int c = 0; c < cw; ++c) {+ du[c] = src[c * 2];+ dv[c] = src[c * 2 + 1];+ }+ }+ return drawYuv420(y, u.data(), v.data(), strideY, cw, cw, width, height, wait);+}+bool drawYuv420(const uint8_t* y, const uint8_t* u, const uint8_t* v, int strideY, int strideU, int strideV,int width, int height, bool wait) {if (gpu::ready()) return gpu::drawYuv420(y, u, v, strideY, strideU, strideV, width, height, wait);diff --git a/src/display/display_sdl.cpp b/src/display/display_sdl.cppindex c2b5a74..faf5d40 100644--- a/src/display/display_sdl.cpp+++ b/src/display/display_sdl.cpp@@ -318,6 +318,29 @@ void drawRgba(const uint32_t* pixels) {g_back.rgba.assign(pixels, pixels + static_cast<size_t>(kWidth) * kHeight);}+bool drawNv12(const uint8_t* y, const uint8_t* uv, int strideY, int strideUV,+ int width, int height, bool) {+ if (!y || !uv || width <= 0 || height <= 0 || strideY < width || strideUV < width) return false;+ const int cw = (width + 1) / 2, ch = (height + 1) / 2;+ g_back.kind = Kind::Video;+ g_back.width = width, g_back.height = height;+ g_back.y.resize(static_cast<size_t>(width) * height);+ g_back.u.resize(static_cast<size_t>(cw) * ch);+ g_back.v.resize(static_cast<size_t>(cw) * ch);+ for (int r = 0; r < height; ++r)+ std::memcpy(&g_back.y[static_cast<size_t>(r) * width], y + static_cast<size_t>(r) * strideY, width);+ for (int r = 0; r < ch; ++r) {+ const uint8_t* src = uv + static_cast<size_t>(r) * strideUV;+ uint8_t* du = &g_back.u[static_cast<size_t>(r) * cw];+ uint8_t* dv = &g_back.v[static_cast<size_t>(r) * cw];+ for (int c = 0; c < cw; ++c) {+ du[c] = src[c * 2];+ dv[c] = src[c * 2 + 1];+ }+ }+ return true;+}+bool drawYuv420(const uint8_t* y, const uint8_t* u, const uint8_t* v, int strideY, int strideU, int strideV,int width, int height, bool) {// Never waits for the screen: the mailbox keeps the newest frame.diff --git a/src/display/gpu.cpp b/src/display/gpu.cppindex fa44ae1..957d949 100644--- a/src/display/gpu.cpp+++ b/src/display/gpu.cpp@@ -27,6 +27,7 @@#include "display/shaders/easu.spv.h"#include "display/shaders/rcas.spv.h"#include "display/shaders/yuv2rgb.spv.h"+#include "display/shaders/nv122rgb.spv.h"#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wmissing-field-initializers"@@ -130,7 +131,7 @@ struct State {uint64_t presented = 0; // the last present idVkSampler nearest = VK_NULL_HANDLE, linear = VK_NULL_HANDLE;- Pipeline yuv, easu, rcas;+ Pipeline yuv, nv12, easu, rcas;// Anime4K x2 (S): four convolutions at the picture's size, then the// depth-to-space into the 2x image (or straight into upscaled when the// display box is already 2x); in place of EASU when chosen.@@ -143,10 +144,10 @@ struct State {VkDescriptorSet restoreSets[4]{};bool restoreReady = false;VkDescriptorPool descriptors = VK_NULL_HANDLE;- VkDescriptorSet yuvSet = VK_NULL_HANDLE, easuVideoSet = VK_NULL_HANDLE, easuUiSet = VK_NULL_HANDLE;+ VkDescriptorSet yuvSet = VK_NULL_HANDLE, nv12Set = VK_NULL_HANDLE, easuVideoSet = VK_NULL_HANDLE, easuUiSet = VK_NULL_HANDLE;VkDescriptorSet rcasSets[8]{};- Image luma, chromaU, chromaV, rgb; // the video picture, at its size+ Image luma, chromaU, chromaV, chromaUV, rgb; // the video picture, at its sizeImage features[2]; // Anime4K's feature maps, ping-pongedImage a4k; // 2x intermediate when the display box != 2x streamImage ui, upscaled, overlay;@@ -706,9 +707,11 @@ bool createPipelines() {const VkDescriptorType sampled = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, storage = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;const VkDescriptorSetLayoutBinding yuv[] = {binding(0, sampled), binding(1, sampled), binding(2, sampled),binding(3, storage)};+ const VkDescriptorSetLayoutBinding nv12[] = {binding(0, sampled), binding(1, sampled), binding(2, storage)};const VkDescriptorSetLayoutBinding easu[] = {binding(0, sampled), binding(1, storage)};const VkDescriptorSetLayoutBinding rcas[] = {binding(0, storage), binding(1, sampled), binding(2, storage)};if (!createPipeline(g.yuv, kShader_yuv2rgb, sizeof kShader_yuv2rgb, yuv, 4, 20) ||+ !createPipeline(g.nv12, kShader_nv122rgb, sizeof kShader_nv122rgb, nv12, 3, 20) ||!createPipeline(g.easu, kShader_easu, sizeof kShader_easu, easu, 2, 64) ||!createPipeline(g.rcas, kShader_rcas, sizeof kShader_rcas, rcas, 3, 24)) {XC_LOGE("gpu: the FSR pipelines");@@ -738,6 +741,7 @@ bool createPipelines() {pool.pPoolSizes = sizes;if (vkCreateDescriptorPool(g.device, &pool, nullptr, &g.descriptors) != VK_SUCCESS) return false;g.yuvSet = allocateSet(g.yuv);+ g.nv12Set = allocateSet(g.nv12);g.easuVideoSet = allocateSet(g.easu);g.easuUiSet = allocateSet(g.easu);for (uint32_t i = 0; i < 8; ++i) g.rcasSets[i] = allocateSet(g.rcas);@@ -806,6 +810,7 @@ bool videoImages(uint32_t w, uint32_t h) {destroyImage(g.luma);destroyImage(g.chromaU);destroyImage(g.chromaV);+ destroyImage(g.chromaUV);destroyImage(g.rgb);destroyImage(g.features[0]);destroyImage(g.features[1]);@@ -815,6 +820,7 @@ bool videoImages(uint32_t w, uint32_t h) {if (!createImage(g.luma, VK_FORMAT_R8_UNORM, w, h, upload) ||!createImage(g.chromaU, VK_FORMAT_R8_UNORM, cw, ch, upload) ||!createImage(g.chromaV, VK_FORMAT_R8_UNORM, cw, ch, upload) ||+ !createImage(g.chromaUV, VK_FORMAT_R8G8_UNORM, cw, ch, upload) ||!createImage(g.rgb, VK_FORMAT_R8G8B8A8_UNORM, w, h,VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) {XC_LOGE("gpu: video images %ux%u", w, h);@@ -824,6 +830,9 @@ bool videoImages(uint32_t w, uint32_t h) {writeSampled(g.yuvSet, 1, g.chromaU.view, g.linear);writeSampled(g.yuvSet, 2, g.chromaV.view, g.linear);writeStorage(g.yuvSet, 3, g.rgb.view);+ writeSampled(g.nv12Set, 0, g.luma.view, g.linear);+ writeSampled(g.nv12Set, 1, g.chromaUV.view, g.linear);+ writeStorage(g.nv12Set, 2, g.rgb.view);writeSampled(g.easuVideoSet, 0, g.rgb.view, g.linear);if (g.a4kReady) {if (!createImage(g.features[0], VK_FORMAT_R16G16B16A16_SFLOAT, w, h, VK_IMAGE_USAGE_STORAGE_BIT) ||@@ -1092,12 +1101,12 @@ bool init(const Wsi& wsi) {void shutdown() {if (g.device) {if (vkDeviceWaitIdle) vkDeviceWaitIdle(g.device);- for (Image* img : {&g.luma, &g.chromaU, &g.chromaV, &g.rgb, &g.features[0], &g.features[1], &g.a4k, &g.ui,+ for (Image* img : {&g.luma, &g.chromaU, &g.chromaV, &g.chromaUV, &g.rgb, &g.features[0], &g.features[1], &g.a4k, &g.ui,&g.upscaled, &g.overlay})destroyImage(*img);for (Buffer* buf : {&g.staging, &g.overlayStaging, &g.readback}) destroyBuffer(*buf);if (g.descriptors && vkDestroyDescriptorPool) vkDestroyDescriptorPool(g.device, g.descriptors, nullptr);- for (Pipeline* p : {&g.yuv, &g.easu, &g.rcas, &g.a4kD2s}) destroyPipeline(*p);+ for (Pipeline* p : {&g.yuv, &g.nv12, &g.easu, &g.rcas, &g.a4kD2s}) destroyPipeline(*p);for (int i = 0; i < 4; ++i) {destroyPipeline(g.a4kConv[i]);destroyPipeline(g.restoreConv[i]);@@ -1161,6 +1170,39 @@ bool drawYuv420(const uint8_t* y, const uint8_t* u, const uint8_t* v, int stridereturn true;}+bool drawNv12(const uint8_t* y, const uint8_t* uv, int strideY, int strideUV,+ int width, int height, bool wait) {+ if (!y || !uv || width <= 0 || height <= 0 || strideY < width || strideUV < width) return false;+ size_t ySize = static_cast<size_t>(strideY) * height;+ size_t uvSize = static_cast<size_t>(strideUV) * ((height + 1) / 2);+ if (ySize + uvSize > g.staging.size) return false;+ if (!beginFrame(wait)) return false;+ if (!videoImages(static_cast<uint32_t>(width), static_cast<uint32_t>(height))) return false;+ std::memcpy(g.staging.map, y, ySize);+ std::memcpy(g.staging.map + ySize, uv, uvSize);+ copyToImage(g.staging, 0, static_cast<uint32_t>(strideY), g.luma);+ copyToImage(g.staging, ySize, static_cast<uint32_t>(strideUV / 2), g.chromaUV);+ bool overlay = false;+ recordOverlay(overlay);+ barrier(g.rgb.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);+ memoryBarrier(); // the planes copied+ vkCmdBindPipeline(g.cmd, VK_PIPELINE_BIND_POINT_COMPUTE, g.nv12.pipeline);+ vkCmdBindDescriptorSets(g.cmd, VK_PIPELINE_BIND_POINT_COMPUTE, g.nv12.layout, 0, 1, &g.nv12Set, 0, nullptr);+ int deband = g_deband;+ struct {+ uint32_t iterations;+ float threshold, radius, grain;+ uint32_t frame;+ } yuvPc{deband >= 2 ? 2u : deband == 1 ? 1u : 0u, deband >= 2 ? 0.016f : 0.008f, 16.0f,+ deband >= 2 ? 0.005f : 0.003f, ++g_frame};+ vkCmdPushConstants(g.cmd, g.nv12.layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof yuvPc, &yuvPc);+ vkCmdDispatch(g.cmd, (g.rgb.w + 7) / 8, (g.rgb.h + 7) / 8, 1);+ memoryBarrier();+ if (g_restore) recordRestore(g.rgb.w, g.rgb.h);+ recordUpscale(g.easuVideoSet, g.rgb.w, g.rgb.h, g_sharpness, overlay, g_upscaler == 1);+ return true;+}+void drawRgba(const uint32_t* pixels) {if (!beginFrame(true)) return;std::memcpy(g.staging.map, pixels, kUiW * kUiH * 4);diff --git a/src/display/gpu.h b/src/display/gpu.hindex b9e45cc..dce2e1d 100644--- a/src/display/gpu.h+++ b/src/display/gpu.h@@ -40,6 +40,8 @@ void probe(int frames);// swapchain image is free yet.bool drawYuv420(const uint8_t* y, const uint8_t* u, const uint8_t* v, int strideY, int strideU, int strideV,int width, int height, bool wait);+bool drawNv12(const uint8_t* y, const uint8_t* uv, int strideY, int strideUV,+ int width, int height, bool wait);void drawRgba(const uint32_t* pixels); // 1920x1080, 0xAABBGGRRvoid present();diff --git a/src/display/shaders/nv122rgb.comp b/src/display/shaders/nv122rgb.compnew file mode 100644index 0000000..6865a8d--- /dev/null+++ b/src/display/shaders/nv122rgb.comp@@ -0,0 +1,63 @@+#version 450+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// A decoded H.264 picture in NV12 (BT.709, limited range, 4:2:0 with the default+// chroma siting: on the even luma columns, between two luma rows) to RGB,+// debanded first.+layout(local_size_x = 8, local_size_y = 8) in;+layout(binding = 0) uniform sampler2D lumaTex; // linear R8_UNORM+layout(binding = 1) uniform sampler2D chromaUVTex;// linear R8G8_UNORM+layout(binding = 2, rgba8) uniform writeonly image2D rgbOut;+layout(push_constant) uniform Constants {+ uint iterations; // 0: no deband+ float threshold; // largest step smoothed, in 0..1 units (divided by the iteration)+ float radius; // in luma pixels (times the iteration)+ float grain; // luma noise amplitude+ uint frame; // moves the random pattern each frame+} pc;++vec2 lumaSize, chromaSize;++// Y, U, V at a luma position (pixel units, centres at .0).+vec3 yuvAt(vec2 q) {+ float y = texture(lumaTex, (q + 0.5) / lumaSize).r;+ // Chroma sample i sits on luma column 2i and halfway between luma rows+ // 2j and 2j + 1: in chroma texels, luma (x, y) is at (x / 2, y / 2 - 0.25).+ vec2 c = (vec2(q.x * 0.5, q.y * 0.5 - 0.25) + 0.5) / chromaSize;+ vec2 uv = texture(chromaUVTex, c).rg;+ return vec3(y, uv.r, uv.g);+}++float hash(vec2 p) {+ vec3 p3 = fract(vec3(p.xyx) * 0.1031);+ p3 += dot(p3, p3.yzx + 33.33);+ return fract((p3.x + p3.y) * p3.z);+}++void main() {+ ivec2 p = ivec2(gl_GlobalInvocationID.xy);+ ivec2 size = imageSize(rgbOut);+ if (p.x >= size.x || p.y >= size.y) return;+ lumaSize = vec2(textureSize(lumaTex, 0));+ chromaSize = vec2(textureSize(chromaUVTex, 0));+ vec2 q = vec2(p);+ vec3 yuv = yuvAt(q);+ if (pc.iterations > 0u) {+ vec2 seed = q + float(pc.frame % 64u) * vec2(17.0, 31.0);+ for (uint i = 1u; i <= pc.iterations; ++i) {+ float fi = float(i);+ float dist = pc.radius * fi * hash(seed + fi * 13.7);+ float angle = 6.2831853 * hash(seed.yx + fi * 41.3);+ vec2 d = vec2(cos(angle), sin(angle)) * dist;+ vec3 avg = 0.25 * (yuvAt(q + d) + yuvAt(q - d) + yuvAt(q + vec2(-d.y, d.x)) + yuvAt(q + vec2(d.y, -d.x)));+ vec3 diff = abs(yuv - avg);+ yuv = mix(avg, yuv, greaterThan(diff, vec3(pc.threshold / fi)));+ }+ yuv.x += (hash(seed * 1.37 + 7.0) - 0.5) * pc.grain;+ }+ float l = (yuv.x - 16.0 / 255.0) * (255.0 / 219.0);+ float u = yuv.y - 128.0 / 255.0, v = yuv.z - 128.0 / 255.0;+ float s = 255.0 / 224.0;+ vec3 rgb = vec3(l + 1.5748 * s * v, l - 0.1873 * s * u - 0.4681 * s * v, l + 1.8556 * s * u);+ imageStore(rgbOut, p, vec4(clamp(rgb, 0.0, 1.0), 1.0));+}diff --git a/src/display/shaders/nv122rgb.spv.h b/src/display/shaders/nv122rgb.spv.hnew file mode 100644index 0000000..d9fc094--- /dev/null+++ b/src/display/shaders/nv122rgb.spv.h@@ -0,0 +1,252 @@+ // 1116.2.0+ #pragma once+const uint32_t kShader_nv122rgb[] = {+ 0x07230203,0x00010600,0x0008000b,0x00000161,0x00000000,0x00020011,0x00000001,0x00020011,+ 0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,+ 0x00000000,0x00000001,0x000c000f,0x00000005,0x00000004,0x6e69616d,0x00000000,0x00000017,+ 0x0000001e,0x00000034,0x00000038,0x00000068,0x00000070,0x00000098,0x00060010,0x00000004,+ 0x00000011,0x00000008,0x00000008,0x00000001,0x00030003,0x00000002,0x000001c2,0x00040005,+ 0x00000004,0x6e69616d,0x00000000,0x00050005,0x0000000c,0x41767579,0x66762874,0x00003b32,+ 0x00030005,0x0000000b,0x00000071,0x00050005,0x00000010,0x68736168,0x32667628,0x0000003b,+ 0x00030005,0x0000000f,0x00000070,0x00030005,0x00000013,0x00000079,0x00040005,0x00000017,+ 0x616d756c,0x00786554,0x00050005,0x0000001e,0x616d756c,0x657a6953,0x00000000,0x00030005,+ 0x00000027,0x00000063,0x00050005,0x00000034,0x6f726863,0x6953616d,0x0000657a,0x00030005,+ 0x00000037,0x00007675,0x00050005,0x00000038,0x6f726863,0x5655616d,0x00786554,0x00030005,+ 0x00000046,0x00003370,0x00030005,0x00000065,0x00000070,0x00080005,0x00000068,0x475f6c67,+ 0x61626f6c,0x766e496c,0x7461636f,0x496e6f69,0x00000044,0x00040005,0x0000006d,0x657a6973,+ 0x00000000,0x00040005,0x00000070,0x4f626772,0x00007475,0x00030005,0x0000008f,0x00000071,+ 0x00030005,0x00000092,0x00767579,0x00040005,0x00000093,0x61726170,0x0000006d,0x00050005,+ 0x00000096,0x736e6f43,0x746e6174,0x00000073,0x00060006,0x00000096,0x00000000,0x72657469,+ 0x6f697461,0x0000736e,0x00060006,0x00000096,0x00000001,0x65726874,0x6c6f6873,0x00000064,+ 0x00050006,0x00000096,0x00000002,0x69646172,0x00007375,0x00050006,0x00000096,0x00000003,+ 0x69617267,0x0000006e,0x00050006,0x00000096,0x00000004,0x6d617266,0x00000065,0x00030005,+ 0x00000098,0x00006370,0x00040005,0x0000009f,0x64656573,0x00000000,0x00030005,0x000000ad,+ 0x00000069,0x00030005,0x000000b7,0x00006966,0x00040005,0x000000ba,0x74736964,0x00000000,+ 0x00040005,0x000000c7,0x61726170,0x0000006d,0x00040005,0x000000ca,0x6c676e61,0x00000065,+ 0x00040005,0x000000d3,0x61726170,0x0000006d,0x00030005,0x000000d6,0x00000064,0x00030005,+ 0x000000de,0x00677661,0x00040005,0x000000e2,0x61726170,0x0000006d,0x00040005,0x000000e7,+ 0x61726170,0x0000006d,0x00040005,0x000000f2,0x61726170,0x0000006d,0x00040005,0x000000fd,+ 0x61726170,0x0000006d,0x00040005,0x00000101,0x66666964,0x00000000,0x00040005,0x0000011a,+ 0x61726170,0x0000006d,0x00030005,0x00000125,0x0000006c,0x00030005,0x0000012c,0x00000075,+ 0x00030005,0x00000131,0x00000076,0x00030005,0x00000135,0x00000073,0x00030005,0x00000137,+ 0x00626772,0x00040047,0x00000017,0x00000021,0x00000000,0x00040047,0x00000017,0x00000022,+ 0x00000000,0x00040047,0x00000038,0x00000021,0x00000001,0x00040047,0x00000038,0x00000022,+ 0x00000000,0x00040047,0x00000068,0x0000000b,0x0000001c,0x00030047,0x00000070,0x00000019,+ 0x00040047,0x00000070,0x00000021,0x00000002,0x00040047,0x00000070,0x00000022,0x00000000,+ 0x00030047,0x00000096,0x00000002,0x00050048,0x00000096,0x00000000,0x00000023,0x00000000,+ 0x00050048,0x00000096,0x00000001,0x00000023,0x00000004,0x00050048,0x00000096,0x00000002,+ 0x00000023,0x00000008,0x00050048,0x00000096,0x00000003,0x00000023,0x0000000c,0x00050048,+ 0x00000096,0x00000004,0x00000023,0x00000010,0x00020013,0x00000002,0x00030021,0x00000003,+ 0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,+ 0x00040020,0x00000008,0x00000007,0x00000007,0x00040017,0x00000009,0x00000006,0x00000003,+ 0x00040021,0x0000000a,0x00000009,0x00000008,0x00040021,0x0000000e,0x00000006,0x00000008,+ 0x00040020,0x00000012,0x00000007,0x00000006,0x00090019,0x00000014,0x00000006,0x00000001,+ 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000015,0x00000014,+ 0x00040020,0x00000016,0x00000000,0x00000015,0x0004003b,0x00000016,0x00000017,0x00000000,+ 0x0004002b,0x00000006,0x0000001a,0x3f000000,0x00040020,0x0000001d,0x00000006,0x00000007,+ 0x0004003b,0x0000001d,0x0000001e,0x00000006,0x00040017,0x00000021,0x00000006,0x00000004,+ 0x0004002b,0x00000006,0x00000022,0x00000000,0x00040015,0x00000024,0x00000020,0x00000000,+ 0x0004002b,0x00000024,0x00000025,0x00000000,0x0004002b,0x00000024,0x0000002b,0x00000001,+ 0x0004002b,0x00000006,0x0000002f,0x3e800000,0x0004003b,0x0000001d,0x00000034,0x00000006,+ 0x0004003b,0x00000016,0x00000038,0x00000000,0x00040020,0x00000045,0x00000007,0x00000009,+ 0x0004002b,0x00000006,0x00000049,0x3dd32618,0x0004002b,0x00000006,0x0000004f,0x420551ec,+ 0x0004002b,0x00000024,0x0000005b,0x00000002,0x00040015,0x00000062,0x00000020,0x00000001,+ 0x00040017,0x00000063,0x00000062,0x00000002,0x00040020,0x00000064,0x00000007,0x00000063,+ 0x00040017,0x00000066,0x00000024,0x00000003,0x00040020,0x00000067,0x00000001,0x00000066,+ 0x0004003b,0x00000067,0x00000068,0x00000001,0x00040017,0x00000069,0x00000024,0x00000002,+ 0x00090019,0x0000006e,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000002,+ 0x00000004,0x00040020,0x0000006f,0x00000000,0x0000006e,0x0004003b,0x0000006f,0x00000070,+ 0x00000000,0x00020014,0x00000073,0x00040020,0x00000074,0x00000007,0x00000062,0x0004002b,+ 0x00000062,0x00000087,0x00000000,0x0007001e,0x00000096,0x00000024,0x00000006,0x00000006,+ 0x00000006,0x00000024,0x00040020,0x00000097,0x00000009,0x00000096,0x0004003b,0x00000097,+ 0x00000098,0x00000009,0x00040020,0x00000099,0x00000009,0x00000024,0x0004002b,0x00000062,+ 0x000000a1,0x00000004,0x0004002b,0x00000024,0x000000a4,0x00000040,0x0004002b,0x00000006,+ 0x000000a7,0x41880000,0x0004002b,0x00000006,0x000000a8,0x41f80000,0x0005002c,0x00000007,+ 0x000000a9,0x000000a7,0x000000a8,0x00040020,0x000000ac,0x00000007,0x00000024,0x0004002b,+ 0x00000062,0x000000bb,0x00000002,0x00040020,0x000000bc,0x00000009,0x00000006,0x0004002b,+ 0x00000006,0x000000c3,0x415b3333,0x0004002b,0x00000006,0x000000cb,0x40c90fdb,0x0004002b,+ 0x00000006,0x000000cf,0x42253333,0x0004002b,0x00000062,0x00000109,0x00000001,0x00040017,+ 0x0000010f,0x00000073,0x00000003,0x0004002b,0x00000006,0x00000115,0x3faf5c29,0x0004002b,+ 0x00000006,0x00000117,0x40e00000,0x0004002b,0x00000062,0x0000011d,0x00000003,0x0004002b,+ 0x00000006,0x00000128,0x3d808081,0x0004002b,0x00000006,0x0000012a,0x3f950a85,0x0004002b,+ 0x00000006,0x0000012f,0x3f008081,0x0004002b,0x00000006,0x00000136,0x3f91b6db,0x0004002b,+ 0x00000006,0x00000139,0x3fc9930c,0x0004002b,0x00000006,0x00000140,0x3e3fcb92,0x0004002b,+ 0x00000006,0x00000146,0x3eefaace,0x0004002b,0x00000006,0x0000014d,0x3fed844d,0x0004002b,+ 0x00000006,0x00000157,0x3f800000,0x0004002b,0x00000024,0x0000015f,0x00000008,0x0006002c,+ 0x00000066,0x00000160,0x0000015f,0x0000015f,0x0000002b,0x00050036,0x00000002,0x00000004,+ 0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000064,0x00000065,0x00000007,+ 0x0004003b,0x00000064,0x0000006d,0x00000007,0x0004003b,0x00000008,0x0000008f,0x00000007,+ 0x0004003b,0x00000045,0x00000092,0x00000007,0x0004003b,0x00000008,0x00000093,0x00000007,+ 0x0004003b,0x00000008,0x0000009f,0x00000007,0x0004003b,0x000000ac,0x000000ad,0x00000007,+ 0x0004003b,0x00000012,0x000000b7,0x00000007,0x0004003b,0x00000012,0x000000ba,0x00000007,+ 0x0004003b,0x00000008,0x000000c7,0x00000007,0x0004003b,0x00000012,0x000000ca,0x00000007,+ 0x0004003b,0x00000008,0x000000d3,0x00000007,0x0004003b,0x00000008,0x000000d6,0x00000007,+ 0x0004003b,0x00000045,0x000000de,0x00000007,0x0004003b,0x00000008,0x000000e2,0x00000007,+ 0x0004003b,0x00000008,0x000000e7,0x00000007,0x0004003b,0x00000008,0x000000f2,0x00000007,+ 0x0004003b,0x00000008,0x000000fd,0x00000007,0x0004003b,0x00000045,0x00000101,0x00000007,+ 0x0004003b,0x00000008,0x0000011a,0x00000007,0x0004003b,0x00000012,0x00000125,0x00000007,+ 0x0004003b,0x00000012,0x0000012c,0x00000007,0x0004003b,0x00000012,0x00000131,0x00000007,+ 0x0004003b,0x00000012,0x00000135,0x00000007,0x0004003b,0x00000045,0x00000137,0x00000007,+ 0x0004003d,0x00000066,0x0000006a,0x00000068,0x0007004f,0x00000069,0x0000006b,0x0000006a,+ 0x0000006a,0x00000000,0x00000001,0x0004007c,0x00000063,0x0000006c,0x0000006b,0x0003003e,+ 0x00000065,0x0000006c,0x0004003d,0x0000006e,0x00000071,0x00000070,0x00040068,0x00000063,+ 0x00000072,0x00000071,0x0003003e,0x0000006d,0x00000072,0x00050041,0x00000074,0x00000075,+ 0x00000065,0x00000025,0x0004003d,0x00000062,0x00000076,0x00000075,0x00050041,0x00000074,+ 0x00000077,0x0000006d,0x00000025,0x0004003d,0x00000062,0x00000078,0x00000077,0x000500af,+ 0x00000073,0x00000079,0x00000076,0x00000078,0x000400a8,0x00000073,0x0000007a,0x00000079,+ 0x000300f7,0x0000007c,0x00000000,0x000400fa,0x0000007a,0x0000007b,0x0000007c,0x000200f8,+ 0x0000007b,0x00050041,0x00000074,0x0000007d,0x00000065,0x0000002b,0x0004003d,0x00000062,+ 0x0000007e,0x0000007d,0x00050041,0x00000074,0x0000007f,0x0000006d,0x0000002b,0x0004003d,+ 0x00000062,0x00000080,0x0000007f,0x000500af,0x00000073,0x00000081,0x0000007e,0x00000080,+ 0x000200f9,0x0000007c,0x000200f8,0x0000007c,0x000700f5,0x00000073,0x00000082,0x00000079,+ 0x00000005,0x00000081,0x0000007b,0x000300f7,0x00000084,0x00000000,0x000400fa,0x00000082,+ 0x00000083,0x00000084,0x000200f8,0x00000083,0x000100fd,0x000200f8,0x00000084,0x0004003d,+ 0x00000015,0x00000086,0x00000017,0x00040064,0x00000014,0x00000088,0x00000086,0x00050067,+ 0x00000063,0x00000089,0x00000088,0x00000087,0x0004006f,0x00000007,0x0000008a,0x00000089,+ 0x0003003e,0x0000001e,0x0000008a,0x0004003d,0x00000015,0x0000008b,0x00000038,0x00040064,+ 0x00000014,0x0000008c,0x0000008b,0x00050067,0x00000063,0x0000008d,0x0000008c,0x00000087,+ 0x0004006f,0x00000007,0x0000008e,0x0000008d,0x0003003e,0x00000034,0x0000008e,0x0004003d,+ 0x00000063,0x00000090,0x00000065,0x0004006f,0x00000007,0x00000091,0x00000090,0x0003003e,+ 0x0000008f,0x00000091,0x0004003d,0x00000007,0x00000094,0x0000008f,0x0003003e,0x00000093,+ 0x00000094,0x00050039,0x00000009,0x00000095,0x0000000c,0x00000093,0x0003003e,0x00000092,+ 0x00000095,0x00050041,0x00000099,0x0000009a,0x00000098,0x00000087,0x0004003d,0x00000024,+ 0x0000009b,0x0000009a,0x000500ac,0x00000073,0x0000009c,0x0000009b,0x00000025,0x000300f7,+ 0x0000009e,0x00000000,0x000400fa,0x0000009c,0x0000009d,0x0000009e,0x000200f8,0x0000009d,+ 0x0004003d,0x00000007,0x000000a0,0x0000008f,0x00050041,0x00000099,0x000000a2,0x00000098,+ 0x000000a1,0x0004003d,0x00000024,0x000000a3,0x000000a2,0x00050089,0x00000024,0x000000a5,+ 0x000000a3,0x000000a4,0x00040070,0x00000006,0x000000a6,0x000000a5,0x0005008e,0x00000007,+ 0x000000aa,0x000000a9,0x000000a6,0x00050081,0x00000007,0x000000ab,0x000000a0,0x000000aa,+ 0x0003003e,0x0000009f,0x000000ab,0x0003003e,0x000000ad,0x0000002b,0x000200f9,0x000000ae,+ 0x000200f8,0x000000ae,0x000400f6,0x000000b0,0x000000b1,0x00000000,0x000200f9,0x000000b2,+ 0x000200f8,0x000000b2,0x0004003d,0x00000024,0x000000b3,0x000000ad,0x00050041,0x00000099,+ 0x000000b4,0x00000098,0x00000087,0x0004003d,0x00000024,0x000000b5,0x000000b4,0x000500b2,+ 0x00000073,0x000000b6,0x000000b3,0x000000b5,0x000400fa,0x000000b6,0x000000af,0x000000b0,+ 0x000200f8,0x000000af,0x0004003d,0x00000024,0x000000b8,0x000000ad,0x00040070,0x00000006,+ 0x000000b9,0x000000b8,0x0003003e,0x000000b7,0x000000b9,0x00050041,0x000000bc,0x000000bd,+ 0x00000098,0x000000bb,0x0004003d,0x00000006,0x000000be,0x000000bd,0x0004003d,0x00000006,+ 0x000000bf,0x000000b7,0x00050085,0x00000006,0x000000c0,0x000000be,0x000000bf,0x0004003d,+ 0x00000007,0x000000c1,0x0000009f,0x0004003d,0x00000006,0x000000c2,0x000000b7,0x00050085,+ 0x00000006,0x000000c4,0x000000c2,0x000000c3,0x00050050,0x00000007,0x000000c5,0x000000c4,+ 0x000000c4,0x00050081,0x00000007,0x000000c6,0x000000c1,0x000000c5,0x0003003e,0x000000c7,+ 0x000000c6,0x00050039,0x00000006,0x000000c8,0x00000010,0x000000c7,0x00050085,0x00000006,+ 0x000000c9,0x000000c0,0x000000c8,0x0003003e,0x000000ba,0x000000c9,0x0004003d,0x00000007,+ 0x000000cc,0x0000009f,0x0007004f,0x00000007,0x000000cd,0x000000cc,0x000000cc,0x00000001,+ 0x00000000,0x0004003d,0x00000006,0x000000ce,0x000000b7,0x00050085,0x00000006,0x000000d0,+ 0x000000ce,0x000000cf,0x00050050,0x00000007,0x000000d1,0x000000d0,0x000000d0,0x00050081,+ 0x00000007,0x000000d2,0x000000cd,0x000000d1,0x0003003e,0x000000d3,0x000000d2,0x00050039,+ 0x00000006,0x000000d4,0x00000010,0x000000d3,0x00050085,0x00000006,0x000000d5,0x000000cb,+ 0x000000d4,0x0003003e,0x000000ca,0x000000d5,0x0004003d,0x00000006,0x000000d7,0x000000ca,+ 0x0006000c,0x00000006,0x000000d8,0x00000001,0x0000000e,0x000000d7,0x0004003d,0x00000006,+ 0x000000d9,0x000000ca,0x0006000c,0x00000006,0x000000da,0x00000001,0x0000000d,0x000000d9,+ 0x00050050,0x00000007,0x000000db,0x000000d8,0x000000da,0x0004003d,0x00000006,0x000000dc,+ 0x000000ba,0x0005008e,0x00000007,0x000000dd,0x000000db,0x000000dc,0x0003003e,0x000000d6,+ 0x000000dd,0x0004003d,0x00000007,0x000000df,0x0000008f,0x0004003d,0x00000007,0x000000e0,+ 0x000000d6,0x00050081,0x00000007,0x000000e1,0x000000df,0x000000e0,0x0003003e,0x000000e2,+ 0x000000e1,0x00050039,0x00000009,0x000000e3,0x0000000c,0x000000e2,0x0004003d,0x00000007,+ 0x000000e4,0x0000008f,0x0004003d,0x00000007,0x000000e5,0x000000d6,0x00050083,0x00000007,+ 0x000000e6,0x000000e4,0x000000e5,0x0003003e,0x000000e7,0x000000e6,0x00050039,0x00000009,+ 0x000000e8,0x0000000c,0x000000e7,0x00050081,0x00000009,0x000000e9,0x000000e3,0x000000e8,+ 0x0004003d,0x00000007,0x000000ea,0x0000008f,0x00050041,0x00000012,0x000000eb,0x000000d6,+ 0x0000002b,0x0004003d,0x00000006,0x000000ec,0x000000eb,0x0004007f,0x00000006,0x000000ed,+ 0x000000ec,0x00050041,0x00000012,0x000000ee,0x000000d6,0x00000025,0x0004003d,0x00000006,+ 0x000000ef,0x000000ee,0x00050050,0x00000007,0x000000f0,0x000000ed,0x000000ef,0x00050081,+ 0x00000007,0x000000f1,0x000000ea,0x000000f0,0x0003003e,0x000000f2,0x000000f1,0x00050039,+ 0x00000009,0x000000f3,0x0000000c,0x000000f2,0x00050081,0x00000009,0x000000f4,0x000000e9,+ 0x000000f3,0x0004003d,0x00000007,0x000000f5,0x0000008f,0x00050041,0x00000012,0x000000f6,+ 0x000000d6,0x0000002b,0x0004003d,0x00000006,0x000000f7,0x000000f6,0x00050041,0x00000012,+ 0x000000f8,0x000000d6,0x00000025,0x0004003d,0x00000006,0x000000f9,0x000000f8,0x0004007f,+ 0x00000006,0x000000fa,0x000000f9,0x00050050,0x00000007,0x000000fb,0x000000f7,0x000000fa,+ 0x00050081,0x00000007,0x000000fc,0x000000f5,0x000000fb,0x0003003e,0x000000fd,0x000000fc,+ 0x00050039,0x00000009,0x000000fe,0x0000000c,0x000000fd,0x00050081,0x00000009,0x000000ff,+ 0x000000f4,0x000000fe,0x0005008e,0x00000009,0x00000100,0x000000ff,0x0000002f,0x0003003e,+ 0x000000de,0x00000100,0x0004003d,0x00000009,0x00000102,0x00000092,0x0004003d,0x00000009,+ 0x00000103,0x000000de,0x00050083,0x00000009,0x00000104,0x00000102,0x00000103,0x0006000c,+ 0x00000009,0x00000105,0x00000001,0x00000004,0x00000104,0x0003003e,0x00000101,0x00000105,+ 0x0004003d,0x00000009,0x00000106,0x000000de,0x0004003d,0x00000009,0x00000107,0x00000092,+ 0x0004003d,0x00000009,0x00000108,0x00000101,0x00050041,0x000000bc,0x0000010a,0x00000098,+ 0x00000109,0x0004003d,0x00000006,0x0000010b,0x0000010a,0x0004003d,0x00000006,0x0000010c,+ 0x000000b7,0x00050088,0x00000006,0x0000010d,0x0000010b,0x0000010c,0x00060050,0x00000009,+ 0x0000010e,0x0000010d,0x0000010d,0x0000010d,0x000500ba,0x0000010f,0x00000110,0x00000108,+ 0x0000010e,0x000600a9,0x00000009,0x00000111,0x00000110,0x00000107,0x00000106,0x0003003e,+ 0x00000092,0x00000111,0x000200f9,0x000000b1,0x000200f8,0x000000b1,0x0004003d,0x00000024,+ 0x00000112,0x000000ad,0x00050080,0x00000024,0x00000113,0x00000112,0x00000109,0x0003003e,+ 0x000000ad,0x00000113,0x000200f9,0x000000ae,0x000200f8,0x000000b0,0x0004003d,0x00000007,+ 0x00000114,0x0000009f,0x0005008e,0x00000007,0x00000116,0x00000114,0x00000115,0x00050050,+ 0x00000007,0x00000118,0x00000117,0x00000117,0x00050081,0x00000007,0x00000119,0x00000116,+ 0x00000118,0x0003003e,0x0000011a,0x00000119,0x00050039,0x00000006,0x0000011b,0x00000010,+ 0x0000011a,0x00050083,0x00000006,0x0000011c,0x0000011b,0x0000001a,0x00050041,0x000000bc,+ 0x0000011e,0x00000098,0x0000011d,0x0004003d,0x00000006,0x0000011f,0x0000011e,0x00050085,+ 0x00000006,0x00000120,0x0000011c,0x0000011f,0x00050041,0x00000012,0x00000121,0x00000092,+ 0x00000025,0x0004003d,0x00000006,0x00000122,0x00000121,0x00050081,0x00000006,0x00000123,+ 0x00000122,0x00000120,0x00050041,0x00000012,0x00000124,0x00000092,0x00000025,0x0003003e,+ 0x00000124,0x00000123,0x000200f9,0x0000009e,0x000200f8,0x0000009e,0x00050041,0x00000012,+ 0x00000126,0x00000092,0x00000025,0x0004003d,0x00000006,0x00000127,0x00000126,0x00050083,+ 0x00000006,0x00000129,0x00000127,0x00000128,0x00050085,0x00000006,0x0000012b,0x00000129,+ 0x0000012a,0x0003003e,0x00000125,0x0000012b,0x00050041,0x00000012,0x0000012d,0x00000092,+ 0x0000002b,0x0004003d,0x00000006,0x0000012e,0x0000012d,0x00050083,0x00000006,0x00000130,+ 0x0000012e,0x0000012f,0x0003003e,0x0000012c,0x00000130,0x00050041,0x00000012,0x00000132,+ 0x00000092,0x0000005b,0x0004003d,0x00000006,0x00000133,0x00000132,0x00050083,0x00000006,+ 0x00000134,0x00000133,0x0000012f,0x0003003e,0x00000131,0x00000134,0x0003003e,0x00000135,+ 0x00000136,0x0004003d,0x00000006,0x00000138,0x00000125,0x0004003d,0x00000006,0x0000013a,+ 0x00000135,0x00050085,0x00000006,0x0000013b,0x00000139,0x0000013a,0x0004003d,0x00000006,+ 0x0000013c,0x00000131,0x00050085,0x00000006,0x0000013d,0x0000013b,0x0000013c,0x00050081,+ 0x00000006,0x0000013e,0x00000138,0x0000013d,0x0004003d,0x00000006,0x0000013f,0x00000125,+ 0x0004003d,0x00000006,0x00000141,0x00000135,0x00050085,0x00000006,0x00000142,0x00000140,+ 0x00000141,0x0004003d,0x00000006,0x00000143,0x0000012c,0x00050085,0x00000006,0x00000144,+ 0x00000142,0x00000143,0x00050083,0x00000006,0x00000145,0x0000013f,0x00000144,0x0004003d,+ 0x00000006,0x00000147,0x00000135,0x00050085,0x00000006,0x00000148,0x00000146,0x00000147,+ 0x0004003d,0x00000006,0x00000149,0x00000131,0x00050085,0x00000006,0x0000014a,0x00000148,+ 0x00000149,0x00050083,0x00000006,0x0000014b,0x00000145,0x0000014a,0x0004003d,0x00000006,+ 0x0000014c,0x00000125,0x0004003d,0x00000006,0x0000014e,0x00000135,0x00050085,0x00000006,+ 0x0000014f,0x0000014d,0x0000014e,0x0004003d,0x00000006,0x00000150,0x0000012c,0x00050085,+ 0x00000006,0x00000151,0x0000014f,0x00000150,0x00050081,0x00000006,0x00000152,0x0000014c,+ 0x00000151,0x00060050,0x00000009,0x00000153,0x0000013e,0x0000014b,0x00000152,0x0003003e,+ 0x00000137,0x00000153,0x0004003d,0x0000006e,0x00000154,0x00000070,0x0004003d,0x00000063,+ 0x00000155,0x00000065,0x0004003d,0x00000009,0x00000156,0x00000137,0x00060050,0x00000009,+ 0x00000158,0x00000022,0x00000022,0x00000022,0x00060050,0x00000009,0x00000159,0x00000157,+ 0x00000157,0x00000157,0x0008000c,0x00000009,0x0000015a,0x00000001,0x0000002b,0x00000156,+ 0x00000158,0x00000159,0x00050051,0x00000006,0x0000015b,0x0000015a,0x00000000,0x00050051,+ 0x00000006,0x0000015c,0x0000015a,0x00000001,0x00050051,0x00000006,0x0000015d,0x0000015a,+ 0x00000002,0x00070050,0x00000021,0x0000015e,0x0000015b,0x0000015c,0x0000015d,0x00000157,+ 0x00040063,0x00000154,0x00000155,0x0000015e,0x000100fd,0x00010038,0x00050036,0x00000009,+ 0x0000000c,0x00000000,0x0000000a,0x00030037,0x00000008,0x0000000b,0x000200f8,0x0000000d,+ 0x0004003b,0x00000012,0x00000013,0x00000007,0x0004003b,0x00000008,0x00000027,0x00000007,+ 0x0004003b,0x00000008,0x00000037,0x00000007,0x0004003d,0x00000015,0x00000018,0x00000017,+ 0x0004003d,0x00000007,0x00000019,0x0000000b,0x00050050,0x00000007,0x0000001b,0x0000001a,+ 0x0000001a,0x00050081,0x00000007,0x0000001c,0x00000019,0x0000001b,0x0004003d,0x00000007,+ 0x0000001f,0x0000001e,0x00050088,0x00000007,0x00000020,0x0000001c,0x0000001f,0x00070058,+ 0x00000021,0x00000023,0x00000018,0x00000020,0x00000002,0x00000022,0x00050051,0x00000006,+ 0x00000026,0x00000023,0x00000000,0x0003003e,0x00000013,0x00000026,0x00050041,0x00000012,+ 0x00000028,0x0000000b,0x00000025,0x0004003d,0x00000006,0x00000029,0x00000028,0x00050085,+ 0x00000006,0x0000002a,0x00000029,0x0000001a,0x00050041,0x00000012,0x0000002c,0x0000000b,+ 0x0000002b,0x0004003d,0x00000006,0x0000002d,0x0000002c,0x00050085,0x00000006,0x0000002e,+ 0x0000002d,0x0000001a,0x00050083,0x00000006,0x00000030,0x0000002e,0x0000002f,0x00050050,+ 0x00000007,0x00000031,0x0000002a,0x00000030,0x00050050,0x00000007,0x00000032,0x0000001a,+ 0x0000001a,0x00050081,0x00000007,0x00000033,0x00000031,0x00000032,0x0004003d,0x00000007,+ 0x00000035,0x00000034,0x00050088,0x00000007,0x00000036,0x00000033,0x00000035,0x0003003e,+ 0x00000027,0x00000036,0x0004003d,0x00000015,0x00000039,0x00000038,0x0004003d,0x00000007,+ 0x0000003a,0x00000027,0x00070058,0x00000021,0x0000003b,0x00000039,0x0000003a,0x00000002,+ 0x00000022,0x0007004f,0x00000007,0x0000003c,0x0000003b,0x0000003b,0x00000000,0x00000001,+ 0x0003003e,0x00000037,0x0000003c,0x0004003d,0x00000006,0x0000003d,0x00000013,0x00050041,+ 0x00000012,0x0000003e,0x00000037,0x00000025,0x0004003d,0x00000006,0x0000003f,0x0000003e,+ 0x00050041,0x00000012,0x00000040,0x00000037,0x0000002b,0x0004003d,0x00000006,0x00000041,+ 0x00000040,0x00060050,0x00000009,0x00000042,0x0000003d,0x0000003f,0x00000041,0x000200fe,+ 0x00000042,0x00010038,0x00050036,0x00000006,0x00000010,0x00000000,0x0000000e,0x00030037,+ 0x00000008,0x0000000f,0x000200f8,0x00000011,0x0004003b,0x00000045,0x00000046,0x00000007,+ 0x0004003d,0x00000007,0x00000047,0x0000000f,0x0008004f,0x00000009,0x00000048,0x00000047,+ 0x00000047,0x00000000,0x00000001,0x00000000,0x0005008e,0x00000009,0x0000004a,0x00000048,+ 0x00000049,0x0006000c,0x00000009,0x0000004b,0x00000001,0x0000000a,0x0000004a,0x0003003e,+ 0x00000046,0x0000004b,0x0004003d,0x00000009,0x0000004c,0x00000046,0x0004003d,0x00000009,+ 0x0000004d,0x00000046,0x0008004f,0x00000009,0x0000004e,0x0000004d,0x0000004d,0x00000001,+ 0x00000002,0x00000000,0x00060050,0x00000009,0x00000050,0x0000004f,0x0000004f,0x0000004f,+ 0x00050081,0x00000009,0x00000051,0x0000004e,0x00000050,0x00050094,0x00000006,0x00000052,+ 0x0000004c,0x00000051,0x0004003d,0x00000009,0x00000053,0x00000046,0x00060050,0x00000009,+ 0x00000054,0x00000052,0x00000052,0x00000052,0x00050081,0x00000009,0x00000055,0x00000053,+ 0x00000054,0x0003003e,0x00000046,0x00000055,0x00050041,0x00000012,0x00000056,0x00000046,+ 0x00000025,0x0004003d,0x00000006,0x00000057,0x00000056,0x00050041,0x00000012,0x00000058,+ 0x00000046,0x0000002b,0x0004003d,0x00000006,0x00000059,0x00000058,0x00050081,0x00000006,+ 0x0000005a,0x00000057,0x00000059,0x00050041,0x00000012,0x0000005c,0x00000046,0x0000005b,+ 0x0004003d,0x00000006,0x0000005d,0x0000005c,0x00050085,0x00000006,0x0000005e,0x0000005a,+ 0x0000005d,0x0006000c,0x00000006,0x0000005f,0x00000001,0x0000000a,0x0000005e,0x000200fe,+ 0x0000005f,0x00010038+};diff --git a/src/media/decoder.cpp b/src/media/decoder.cppindex 3e2af1f..d8037d9 100644--- a/src/media/decoder.cpp+++ b/src/media/decoder.cpp@@ -8,6 +8,7 @@ extern "C" {#include <libavcodec/avcodec.h>#include <libavutil/channel_layout.h>#include <libavutil/cpu.h>+#include <libavutil/hwcontext.h>#include <libavutil/log.h>#include <libavutil/error.h>#include <libavutil/video_enc_params.h>@@ -91,52 +92,171 @@ void disableSimd() {// --- Video ---------------------------------------------------------------------VideoDecoder::~VideoDecoder() { freeAll(ctx_, frame_, packet_); }+static enum AVPixelFormat getHwFormat(AVCodecContext* ctx, const enum AVPixelFormat* pix_fmts) {+ auto* self = static_cast<VideoDecoder*>(ctx->opaque);+ if (self && self->hwPixFmt() >= 0) {+ for (const enum AVPixelFormat* p = pix_fmts; *p != AV_PIX_FMT_NONE; ++p) {+ if (static_cast<int>(*p) == self->hwPixFmt()) return *p;+ }+ // Hardware format not supported by the codec for this stream; fall back to software+ self->setHardware(false);+ }+ for (const enum AVPixelFormat* p = pix_fmts; *p != AV_PIX_FMT_NONE; ++p) {+ if (*p == AV_PIX_FMT_YUV420P || *p == AV_PIX_FMT_YUVJ420P || *p == AV_PIX_FMT_NV12) return *p;+ }+ return AV_PIX_FMT_NONE;+}++VideoDecoder::~VideoDecoder() {+ freeAll(ctx_, frame_, packet_);+ if (swFrame_) av_frame_free(&swFrame_);+ if (hwDeviceCtx_) {+ auto* ref = reinterpret_cast<AVBufferRef*>(hwDeviceCtx_);+ av_buffer_unref(&ref);+ hwDeviceCtx_ = nullptr;+ }+}-bool VideoDecoder::init(int threads) {+bool VideoDecoder::init(int threads, bool preferHw) {installLogCallback();+ preferHw_ = preferHw;+ isHw_ = false;+ consecutiveHwErrors_ = 0;++ // 1. Hardware video decoder (PS5 libSceVideodec2 via HwDecoder)+ if (preferHw_) {+ if (hw_.init(1920, 1088)) {+ isHw_ = true;+ XC_LOGI("h264 decoder: hardware decoder (libSceVideodec2) active");+ } else {+ XC_LOGI("h264 decoder: hardware decoder not available");+ }+ }++ // 2. FFmpeg context (primary software decoder or fallback)const AVCodec* codec = avcodec_find_decoder(AV_CODEC_ID_H264);if (!codec) {XC_LOGE("no H.264 decoder in this FFmpeg build");- return false;+ return isHw_;}ctx_ = avcodec_alloc_context3(codec);frame_ = av_frame_alloc();packet_ = av_packet_alloc();- if (!ctx_ || !frame_ || !packet_) return false;+ if (!ctx_ || !frame_ || !packet_) return isHw_;++ // 3. If hardware requested and PS5 hardware decoder is not available, try FFmpeg HWAccel+ if (preferHw_ && !isHw_) {+ static const struct {+ enum AVHWDeviceType devType;+ enum AVPixelFormat pixFmt;+ } kHwConfigs[] = {+ {AV_HWDEVICE_TYPE_VAAPI, AV_PIX_FMT_VAAPI},+ {AV_HWDEVICE_TYPE_CUDA, AV_PIX_FMT_CUDA},+ {AV_HWDEVICE_TYPE_VDPAU, AV_PIX_FMT_VDPAU},+ };+ for (const auto& cfg : kHwConfigs) {+ AVBufferRef* hwCtx = nullptr;+ int rc = av_hwdevice_ctx_create(&hwCtx, cfg.devType, nullptr, nullptr, 0);+ if (rc >= 0 && hwCtx) {+ hwDeviceCtx_ = hwCtx;+ hwPixFmt_ = cfg.pixFmt;+ swFrame_ = av_frame_alloc();+ ctx_->hw_device_ctx = av_buffer_ref(hwCtx);+ ctx_->opaque = this;+ ctx_->get_format = getHwFormat;+ isHw_ = true;+ XC_LOGI("h264 decoder: FFmpeg hardware acceleration (%s) active",+ av_hwdevice_get_type_name(cfg.devType));+ break;+ }+ }+ }+ctx_->flags2 |= AV_CODEC_FLAG2_FAST;ctx_->thread_count = std::max(1, threads);- if (threads > 1) {- // xCloud sends one slice per picture, so slice threads would idle:- // decode several pictures at once instead, one frame of latency per- // extra thread. (LOW_DELAY would turn frame threading off.)+ if (threads > 1 && !isHw_) {ctx_->thread_type = FF_THREAD_FRAME;} else {ctx_->flags |= AV_CODEC_FLAG_LOW_DELAY;ctx_->thread_type = FF_THREAD_SLICE;}- XC_LOGI("h264 decoder: cpu flags 0x%x, %d thread(s)", av_get_cpu_flags(), ctx_->thread_count);- // The quantiser of each picture, for the quality measure (lastQp()).+ XC_LOGI("h264 decoder: cpu flags 0x%x, %d thread(s), mode: %s",+ av_get_cpu_flags(), ctx_->thread_count, isHw_ ? "Hardware" : "Software");ctx_->export_side_data |= AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS;int rc = avcodec_open2(ctx_, codec, nullptr);+ if (rc < 0 && isHw_ && !hw_.ready()) {+ XC_LOGW("h264 decoder: avcodec_open2 with hwaccel failed (%s), retrying software", averr(rc).c_str());+ isHw_ = false;+ if (swFrame_) { av_frame_free(&swFrame_); swFrame_ = nullptr; }+ if (hwDeviceCtx_) {+ auto* ref = reinterpret_cast<AVBufferRef*>(hwDeviceCtx_);+ av_buffer_unref(&ref);+ hwDeviceCtx_ = nullptr;+ }+ avcodec_free_context(&ctx_);+ ctx_ = avcodec_alloc_context3(codec);+ if (!ctx_) return false;+ ctx_->flags2 |= AV_CODEC_FLAG2_FAST;+ ctx_->thread_count = std::max(1, threads);+ ctx_->flags |= AV_CODEC_FLAG_LOW_DELAY;+ ctx_->thread_type = FF_THREAD_SLICE;+ ctx_->export_side_data |= AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS;+ rc = avcodec_open2(ctx_, codec, nullptr);+ }if (rc < 0) {XC_LOGE("avcodec_open2(h264): %s", averr(rc).c_str());- return false;+ if (!hw_.ready()) return false;}return true;}bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_t tag) {- // An empty packet means "end of stream" to libavcodec and would switch it- // to draining for good; the RTP depacketizer emits them after packet loss.pending_ = false;- if (!ctx_ || len == 0) return false;+ if (!data || len == 0) return false;++ // --- Path 1: PS5 Hardware Decoder (libSceVideodec2) ---+ if (isHw_ && hw_.ready()) {+ HwDecoder::Picture hp;+ bool ok = hw_.decode(data, len, tag, hp);+ if (ok && !hp.error) {+ consecutiveHwErrors_ = 0;+ needsKeyframe_ = false;+ out.format = Picture::Format::Nv12;+ out.width = hp.width;+ out.height = (hp.height == 1088) ? 1080 : hp.height;+ out.strideY = hp.pitchBytes;+ out.strideU = hp.pitchBytes;+ out.strideV = 0;+ out.y = hp.data;+ out.u = hp.data + hp.pitchBytes * hp.height;+ out.v = nullptr;+ out.tag = static_cast<uint32_t>(hp.pts);+ if (!profileLogged_) {+ profileLogged_ = true;+ XC_LOGI("hwdec stream active: %ux%u (pitch %u, nv12)", out.width, out.height, out.strideY);+ }+ return true;+ }++ needsKeyframe_ = true;+ ++consecutiveHwErrors_;+ if (failuresLogged_++ < 20) {+ XC_LOGW("hwdec: frame decode failed (consecutive: %d, len: %zu)", consecutiveHwErrors_, len);+ }+ if (consecutiveHwErrors_ >= 5) {+ XC_LOGE("hwdec: consecutive decode errors, falling back to CPU software decoder");+ isHw_ = false;+ if (ctx_) avcodec_flush_buffers(ctx_);+ }+ // Fall back to CPU FFmpeg decode for this packet+ }++ if (!ctx_) return false;packet_->data = const_cast<uint8_t*>(data);packet_->size = static_cast<int>(len);packet_->pts = tag;int rc = avcodec_send_packet(ctx_, packet_);if (rc == AVERROR_EOF) {- // Drained anyway: reset and retry once.avcodec_flush_buffers(ctx_);rc = avcodec_send_packet(ctx_, packet_);}@@ -159,15 +279,25 @@ bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_return false;}if (sent == AVERROR(EAGAIN)) {- // The decoder was full and didn't take this packet: now that a- // picture came out, hand it over again (it used to be lost, and the- // pictures after it decoded against a missing reference).int again = avcodec_send_packet(ctx_, packet_);if (again < 0) {needsKeyframe_ = true;if (failuresLogged_++ < 20) XC_LOGI("h264 packet dropped: %s (%zu bytes)", averr(again).c_str(), len);}}++ AVFrame* targetFrame = frame_;+ if (hwDeviceCtx_ && frame_->format == hwPixFmt_ && swFrame_) {+ int trans = av_hwframe_transfer_data(swFrame_, frame_, 0);+ if (trans < 0) {+ needsKeyframe_ = true;+ XC_LOGW("ffmpeg: av_hwframe_transfer_data failed: %s", averr(trans).c_str());+ return false;+ }+ targetFrame = swFrame_;+ targetFrame->pts = frame_->pts;+ }+if (AVFrameSideData* sd = av_frame_get_side_data(frame_, AV_FRAME_DATA_VIDEO_ENC_PARAMS)) {auto* par = reinterpret_cast<AVVideoEncParams*>(sd->data);double sum = 0;@@ -179,23 +309,38 @@ bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_} else if (frame_->flags & AV_FRAME_FLAG_KEY) {needsKeyframe_ = false;}- if (frame_->format != AV_PIX_FMT_YUV420P && frame_->format != AV_PIX_FMT_YUVJ420P) {- if (failuresLogged_++ < 20) XC_LOGW("unexpected pixel format %d", frame_->format);++ if (targetFrame->format == AV_PIX_FMT_NV12) {+ out.format = Picture::Format::Nv12;+ out.y = targetFrame->data[0];+ out.u = targetFrame->data[1];+ out.v = nullptr;+ out.strideY = targetFrame->linesize[0];+ out.strideU = targetFrame->linesize[1];+ out.strideV = 0;+ out.width = targetFrame->width;+ out.height = targetFrame->height;+ } else if (targetFrame->format == AV_PIX_FMT_YUV420P || targetFrame->format == AV_PIX_FMT_YUVJ420P) {+ out.format = Picture::Format::Yuv420p;+ out.y = targetFrame->data[0];+ out.u = targetFrame->data[1];+ out.v = targetFrame->data[2];+ out.strideY = targetFrame->linesize[0];+ out.strideU = targetFrame->linesize[1];+ out.strideV = targetFrame->linesize[2];+ out.width = targetFrame->width;+ out.height = targetFrame->height;+ } else {+ if (failuresLogged_++ < 20) XC_LOGW("unexpected pixel format %d", targetFrame->format);return false;}- out.y = frame_->data[0];- out.u = frame_->data[1];- out.v = frame_->data[2];- out.strideY = frame_->linesize[0];- out.strideU = frame_->linesize[1];- out.strideV = frame_->linesize[2];- out.width = frame_->width;- out.height = frame_->height;+if (!profileLogged_) {profileLogged_ = true;- XC_LOGI("h264 stream: profile %d, level %d", ctx_->profile, ctx_->level);+ XC_LOGI("h264 stream: profile %d, level %d (%s)", ctx_->profile, ctx_->level,+ out.format == Picture::Format::Nv12 ? "NV12" : "YUV420P");}- out.tag = frame_->pts == AV_NOPTS_VALUE ? 0 : static_cast<uint32_t>(frame_->pts);+ out.tag = targetFrame->pts == AV_NOPTS_VALUE ? 0 : static_cast<uint32_t>(targetFrame->pts);return true;}diff --git a/src/media/decoder.h b/src/media/decoder.hindex 88b3cfd..281b417 100644--- a/src/media/decoder.h+++ b/src/media/decoder.h@@ -12,15 +12,22 @@ struct AVCodecContext;struct AVFrame;struct AVPacket;+#include "media/hw_decoder.h"+namespace xc::media {-// A decoded picture in planar YUV 4:2:0; the planes stay valid until the-// next call to VideoDecoder::decode.+// A decoded picture in planar YUV 4:2:0 or semi-planar NV12; the planes stay+// valid until the next call to VideoDecoder::decode.struct Picture {+ enum class Format : uint8_t {+ Yuv420p = 0,+ Nv12 = 1,+ };+ Format format = Format::Yuv420p;const uint8_t* y = nullptr;- const uint8_t* u = nullptr;- const uint8_t* v = nullptr;- int strideY = 0, strideU = 0, strideV = 0;+ const uint8_t* u = nullptr; // In NV12: points to interleaved UV plane+ const uint8_t* v = nullptr; // In NV12: unused (nullptr)+ int strideY = 0, strideU = 0, strideV = 0; // In NV12: strideU is UV row pitchint width = 0, height = 0;// The `tag` the access unit it came from was decoded with.uint32_t tag = 0;@@ -42,7 +49,9 @@ public:// `threads` > 1 enables slice threading (frame threading would add a// frame of latency per thread).- bool init(int threads = 1);+ // `preferHw` enables hardware video decoding (libSceVideodec2 on PS5,+ // FFmpeg HWAccel on Desktop) with automatic software CPU fallback.+ bool init(int threads = 1, bool preferHw = true);// One Annex-B access unit in; true with `out` filled when a picture is// ready. A false return without a picture is normal at stream start.// `tag` travels with the access unit and comes back on its picture@@ -56,11 +65,22 @@ public:// The quantiser of the last picture (its macroblocks' average, as the// encoder set it): lower is finer. -1 before any.double lastQp() const { return lastQp_; }+ // Whether hardware acceleration is currently active.+ bool isHardware() const { return isHw_; }+ int hwPixFmt() const { return hwPixFmt_; }+ void setHardware(bool hw) { isHw_ = hw; }private:AVCodecContext* ctx_ = nullptr;AVFrame* frame_ = nullptr;AVPacket* packet_ = nullptr;+ AVFrame* swFrame_ = nullptr;+ void* hwDeviceCtx_ = nullptr; // AVBufferRef*+ int hwPixFmt_ = -1; // enum AVPixelFormat+ HwDecoder hw_;+ bool preferHw_ = true;+ bool isHw_ = false;+ int consecutiveHwErrors_ = 0;bool needsKeyframe_ = true;bool profileLogged_ = false;bool pending_ = false;diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex fda89d3..26aa4ae 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -62,16 +62,16 @@ constexpr int kResolutionOrder[3] = {1, 0, 2};// stream (resolution, a desktop's display mode, 120 Hz, bitrate, region, network test);// the controller, keyboard and queue-ready alert; support and updates last. A group starts at each// kSettingsGroupStart.-constexpr int kSettingsCount = 19;-constexpr int kSettingsOrder[kSettingsCount] = {0, 8, 17, 1, 13, 9, 10, 2, 18, 14, 12, 3, 15, 4, 5, 6, 16, 19, 7};-constexpr bool kSettingsGroupStart[kSettingsCount] = {false, false, false, true, false, false, false, false, false,+constexpr int kSettingsCount = 20;+constexpr int kSettingsOrder[kSettingsCount] = {0, 8, 17, 1, 20, 13, 9, 10, 2, 18, 14, 12, 3, 15, 4, 5, 6, 16, 19, 7};+constexpr bool kSettingsGroupStart[kSettingsCount] = {false, false, false, true, false, false, false, false, false, false,true, false, false, false, false, false, false, false, true, false};// The game settings' rows on screen (ids: 0 profile, 1 upscaler, 2// sharpness, 3 block smoothing, 4 resolution, 5 dead zone, 6 triggers, 7// confirm, 8 120 Hz, 9 keyboard keys, 10 back to the default, 11 controller-// buttons, 12 gyro aiming, 13 touchpad as mouse, 14 game language).-constexpr int kGameRowOrder[15] = {0, 4, 8, 14, 1, 2, 3, 5, 6, 7, 12, 11, 13, 9, 10};-constexpr bool kGameGroupStart[15] = {false, true, false, false, true, false, false, true, false, false, false, false, false, false, true};+// buttons, 12 gyro aiming, 13 touchpad as mouse, 14 game language, 15 video decoder).+constexpr int kGameRowOrder[16] = {0, 4, 8, 15, 14, 1, 2, 3, 5, 6, 7, 12, 11, 13, 9, 10};+constexpr bool kGameGroupStart[16] = {false, true, false, false, false, true, false, false, true, false, false, false, false, false, false, true};// The keyboard keys' screen: two columns of inputs, then "Reset to default".constexpr int kKeysPerColumn = input::kKeyActions / 2;// Updates on a desktop: the newest release's page (the app doesn't install it there).@@ -1828,6 +1828,8 @@ std::vector<std::string> AppUi::settingOptions(int row) const {out = {tr(Str::RunTest)};} else if (row == 19) {out = {tr(Str::SupportKoFi)};+ } else if (row == 20) {+ out = {tr(Str::VideoDecoderHw), tr(Str::VideoDecoderSw)};} else if (row == 8) {out.push_back(loginCountryOffText());for (const char* country : kLoginCountries) out.push_back(loginCountryName(country));@@ -1856,6 +1858,7 @@ int AppUi::settingSelected(int row) const {if (row == 13) return settings_.fullscreen ? 1 : 0;if (row == 15) return std::clamp(settings_.gyroMode, 0, 2);if (row == 16) return settings_.queueReadyAlert ? 1 : 0;+ if (row == 20) return std::clamp(settings_.videoDecoder, 0, 1);if (row == 10) {if (settings_.maxBitrateMbps <= 0) return 0;int closest = 1;@@ -1916,6 +1919,8 @@ void AppUi::applySetting(int row, int index) {settings_.gameVolume = kVolumes[index];} else if (row == 16) {settings_.queueReadyAlert = (index == 1);+ } else if (row == 20) {+ settings_.videoDecoder = index;} else if (row == 8) {settings_.loginCountry = index == 0 ? std::string() : kLoginCountries[index - 1];} else {@@ -2664,6 +2669,11 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {dirty_ = true;break;}+ case 15: // Video decoder (0 Hardware, 1 Software)+ activeGameProfile_.videoDecoder = (activeGameProfile_.videoDecoder == 0 ? 1 : 0);+ activeGameHasCustom_ = true;+ dirty_ = true;+ break;default: break;}}@@ -2755,6 +2765,11 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {dirty_ = true;break;}+ case 15:+ activeGameProfile_.videoDecoder = (activeGameProfile_.videoDecoder == 0 ? 1 : 0);+ activeGameHasCustom_ = true;+ dirty_ = true;+ break;case 9: // Keyboard keys: their own screen, on this game'sopenTester(Tester::Keys);settings_.keyMap = activeGameProfile_.keyMap;@@ -4524,17 +4539,18 @@ void AppUi::drawError(Canvas& c) {void AppUi::drawSettings(Canvas& c) {drawBackground(c);drawTopBar(c);- fonts_.bold.draw(c, tr(Str::Settings), kMargin, 146, 52, kWhite);+ fonts_.bold.draw(c, tr(Str::Settings), kMargin, 136, 48, kWhite);const char* labels[kSettingRows] = {tr(Str::Language), tr(Str::Resolution), tr(Str::Region),tr(Str::Deadzone), tr(Str::TriggerRumble), tr(Str::ConfirmButton),tr(Str::LightBar), tr(Str::Updates), tr(Str::LoginCountry),tr(Str::HighRefresh), tr(Str::BitrateCap), tr(Str::GameVolume),tr(Str::KeyboardKeys), tr(Str::DisplayMode), tr(Str::ControllerButtons),tr(Str::Gyro), tr(Str::QueueReadyNotification),- tr(Str::CheckSignIn), tr(Str::NetworkTest), tr(Str::SupportProject)};- constexpr int kRowW = 1200, kRowH = 36, kGap = 3, kGroupGap = 7, kRowPx = 24;+ tr(Str::CheckSignIn), tr(Str::NetworkTest), tr(Str::SupportProject),+ tr(Str::VideoDecoder)};+ constexpr int kRowW = 1200, kRowH = 34, kGap = 2, kGroupGap = 6, kRowPx = 23;Rect rows[kSettingRows]; // by row id- int y = 200;+ int y = 190;for (const auto& [i, groupStart] : visibleSettingsRows(caps_)) { // what caps_ rules out is hiddenif (groupStart) y += kGroupGap;Rect r{kMargin, y, kRowW, kRowH};@@ -4621,13 +4637,14 @@ void AppUi::drawSettings(Canvas& c) {Str::SettingDescCheckSignIn,Str::SettingDescNetworkTest,Str::SettingDescSupportProject,+ Str::SettingDescVideoDecoder,};if (settingsRow_ >= 0 && settingsRow_ < kSettingRows) {- int dy = 936;+ int dy = 925;const char* desc = tr(kSettingDescs[settingsRow_]);for (const auto& line : fonts_.regular.wrap(desc, 22, kRowW, 3)) {fonts_.regular.draw(c, line, kMargin, dy, 22, kDim);- dy += 28;+ dy += 26;}}@@ -5604,7 +5621,7 @@ void AppUi::drawGameSettings(Canvas& c) {}}constexpr int kModalW = 1140, kModalH = 960;- constexpr int kRowH = 46, kGap = 5, kGroupGap = 10;+ constexpr int kRowH = 43, kGap = 4, kGroupGap = 8;// The rows caps_ allows; the panel loses the height of those it hides// (the same as ever with all of them, "Reset to default" or not).const auto rows = visibleGameSettingsRows(caps_, activeGameHasCustom_, activeGameMouseSupported_);@@ -5615,7 +5632,7 @@ void AppUi::drawGameSettings(Canvas& c) {const int modalH = kModalH - static_cast<int>(all.size() - most.size()) * (kRowH + kGap) -(groups(all) - groups(most)) * kGroupGap;Rect panel = drawModal(c, kModalW, modalH, title);- int y = panel.y + 106;+ int y = panel.y + 92;for (int pos = 0; pos < static_cast<int>(rows.size()); ++pos) {const int i = rows[static_cast<size_t>(pos)].row;@@ -5723,6 +5740,10 @@ void AppUi::drawGameSettings(Canvas& c) {}break;}+ case 15:+ label = tr(Str::VideoDecoder);+ value = activeGameProfile_.videoDecoder == 1 ? tr(Str::VideoDecoderSw) : tr(Str::VideoDecoderHw);+ break;default: break;}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex b8b0a5d..79810b0 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -128,6 +128,7 @@ struct SettingsChoice {int sharpness = 0;int deband = 3;int upscaler = 2;+ int videoDecoder = 0; // 0 Hardware, 1 Softwarebool highRefresh = false; // 120 Hz output while a game streamsint maxBitrateMbps = 0; // 0 automatic, else 5 / 10 / 15 / 20 / 25 / 30 / 35 / 40 / 45 / 50int gameVolume = 100; // percent: 25 / 50 / 75 / 100 / 150@@ -192,10 +193,10 @@ std::vector<SettingsRowPos> visibleGameSettingsRows(const UiCaps& caps, bool cus// The largest stick dead zone Settings offers, in percent of the travel.constexpr int kMaxDeadzone = 30;-constexpr int kSettingRows = 20; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,+constexpr int kSettingRows = 21; // language, resolution, region, dead zone, triggers, confirm, light bar, updates,// sign-in country, 120 Hz output, bitrate cap, game volume, keyboard keys,// display mode (a desktop's window), controller buttons, gyro aiming, queue chime,- // check sign-in, network test, support project+ // check sign-in, network test, support project, video decoderstruct SignInStage {std::string name;diff --git a/src/ui/settings_choice.cpp b/src/ui/settings_choice.cppindex 66caf65..103a595 100644--- a/src/ui/settings_choice.cpp+++ b/src/ui/settings_choice.cpp@@ -27,6 +27,7 @@ SettingsChoice choiceFromSettings(const app::Settings& s) {c.sharpness = s.sharpness;c.deband = s.deband;c.upscaler = s.upscaler;+ c.videoDecoder = s.videoDecoder;c.highRefresh = s.highRefresh;c.maxBitrateMbps = s.maxBitrateMbps;c.gameVolume = s.gameVolume;@@ -59,6 +60,7 @@ void applyChoice(const SettingsChoice& c, app::Settings& s) {s.sharpness = c.sharpness;s.deband = c.deband;s.upscaler = c.upscaler;+ s.videoDecoder = c.videoDecoder;s.highRefresh = c.highRefresh;s.maxBitrateMbps = c.maxBitrateMbps;s.gameVolume = c.gameVolume;diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex 425d909..504dce6 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -402,7 +402,7 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {if (info.width > 0) frames = std::to_string(info.width) + "x" + std::to_string(info.height) + " " + frames;line(Str::StatFrameRate, frames);line(Str::StatLoss, fmt("%.1f %%", info.lossPct));- line(Str::StatDecode, info.decodeMs > 0 ? fmt("%.1f ms", info.decodeMs) : none);+ line(Str::StatDecode, info.decodeMs > 0 ? (fmt("%.1f ms", info.decodeMs) + (info.isHwDecode ? " (HW)" : " (SW)")) : none);line(Str::StatOnScreen, info.onScreenMs > 0 ? fmt("%.1f ms", info.onScreenMs) : none);// The controllers: numbered pads, each connected one with its user.@@ -535,7 +535,7 @@ Canvas StreamMenu::renderStats(const StreamInfo& info) const {}if (info.decodeMs > 0) {if (!text.empty()) text += " ";- text += "Dec " + fmt("%.1f ms", info.decodeMs);+ text += "Dec " + fmt("%.1f ms", info.decodeMs) + (info.isHwDecode ? " HW" : " SW");}}if ((statsMask_ & StatsMic) && !micMuted_) {diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.hindex b49f890..a8b0586 100644--- a/src/ui/stream_menu.h+++ b/src/ui/stream_menu.h@@ -20,6 +20,7 @@ struct StreamInfo {int rttMs = -1;double fps = 0, mbps = 0, lossPct = 0, decodeMs = 0;double onScreenMs = 0; // network arrival to on the TV (GPU path); 0 = unknown+ bool isHwDecode = false;int width = 0, height = 0; // of the decoded picturedouble qp = -1; // the pictures' average quantiser (lower: finer); -1 unknownbool degraded = false; // frames lost / video stalled / round trip far up, in the last secondsdiff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex a42346a..691ae08 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -411,6 +411,10 @@ constexpr Column kEnglish = {"Web Control", // WebControlTitle"Connect from your phone", // WebControlSubtitle"Connect to the same Wi-Fi to type search, remap buttons or download logs.", // WebControlDesc+ "Video Decoder", // VideoDecoder+ "Hardware (Recommended)", // VideoDecoderHw+ "Software (CPU)", // VideoDecoderSw+ "Selects hardware decoding (libSceVideodec2 on PS5, HWAccel on Desktop) or CPU software decoding", // SettingDescVideoDecoder};constexpr Column kPortugueseBR = {@@ -792,6 +796,10 @@ constexpr Column kPortugueseBR = {"Configuração Web", // WebControlTitle"Acesse pelo celular", // WebControlSubtitle"Conecte no mesmo Wi-Fi para pesquisar, remapear botões ou baixar logs.", // WebControlDesc+ "Decodificação de Vídeo", // VideoDecoder+ "Hardware (Recomendado)", // VideoDecoderHw+ "Software (CPU)", // VideoDecoderSw+ "Seleciona decodificação por hardware (libSceVideodec2 no PS5, HWAccel no Desktop) ou por software (CPU)", // SettingDescVideoDecoder};constexpr Column kSpanish = {@@ -1173,6 +1181,10 @@ constexpr Column kSpanish = {"Control Web", // WebControlTitle"Conectar desde el móvil", // WebControlSubtitle"Conéctate al mismo Wi-Fi para buscar, reasignar botones o descargar registros.", // WebControlDesc+ "Decodificación de vídeo", // VideoDecoder+ "Hardware (Recomendado)", // VideoDecoderHw+ "Software (CPU)", // VideoDecoderSw+ "Selecciona decodificación por hardware (libSceVideodec2 en PS5, HWAccel en Desktop) o software (CPU)", // SettingDescVideoDecoder};constexpr Column kFrench = {@@ -1554,6 +1566,10 @@ constexpr Column kFrench = {"Contrôle Web", // WebControlTitle"Connexion mobile", // WebControlSubtitle"Connectez-vous au même Wi-Fi pour la recherche, remapper ou télécharger les logs.", // WebControlDesc+ "Décodage vidéo", // VideoDecoder+ "Matériel (Recommandé)", // VideoDecoderHw+ "Logiciel (CPU)", // VideoDecoderSw+ "Sélectionne le décodage matériel (libSceVideodec2 sur PS5, HWAccel sur Desktop) ou logiciel (CPU)", // SettingDescVideoDecoder};constexpr Column kGerman = {@@ -1935,6 +1951,10 @@ constexpr Column kGerman = {"Web-Steuerung", // WebControlTitle"Über Smartphone verbinden", // WebControlSubtitle"Mit demselben WLAN verbinden, um zu suchen, Tasten zu belegen oder Logs zu laden.", // WebControlDesc+ "Videodekodierung", // VideoDecoder+ "Hardware (Empfohlen)", // VideoDecoderHw+ "Software (CPU)", // VideoDecoderSw+ "Wählt Hardware-Dekodierung (libSceVideodec2 auf PS5, HWAccel auf Desktop) oder Software-Dekodierung (CPU)", // SettingDescVideoDecoder};constexpr Column kItalian = {@@ -2316,6 +2336,10 @@ constexpr Column kItalian = {"Controllo Web", // WebControlTitle"Connetti dallo smartphone", // WebControlSubtitle"Connettiti allo stesso Wi-Fi per cercare, rimappare i pulsanti o scaricare i log.", // WebControlDesc+ "Decodifica video", // VideoDecoder+ "Hardware (Consigliato)", // VideoDecoderHw+ "Software (CPU)", // VideoDecoderSw+ "Seleziona decodifica hardware (libSceVideodec2 su PS5, HWAccel su Desktop) o software (CPU)", // SettingDescVideoDecoder};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 541e9d7..fcc30c2 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -388,6 +388,10 @@ enum class Str {WebControlTitle,WebControlSubtitle,WebControlDesc,+ VideoDecoder,+ VideoDecoderHw,+ VideoDecoderSw,+ SettingDescVideoDecoder,Count};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 3d5f4ae..93e8a83 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -346,6 +346,7 @@ static void testSettingsChoiceRoundTrip() {s.circleConfirms = true;s.lightBarMode = 1, s.lightBarColour = 0xFF112233;s.sharpness = 3, s.deband = 1, s.upscaler = 0;+ s.videoDecoder = 1;s.highRefresh = true;s.maxBitrateMbps = 15, s.gameVolume = 150;assignKey(s.keyMap, KeyAction::A, 0, 'E');@@ -364,6 +365,7 @@ static void testSettingsChoiceRoundTrip() {ui::SettingsChoice c = ui::choiceFromSettings(s);CHECK(c.language == static_cast<int>(ui::Language::PortugueseBR));CHECK(c.resolution == 1 && c.triggerProfile == 2 && c.lightBarColour == 0xFF112233u && !c.fullscreen);+ CHECK(c.videoDecoder == 1);CHECK(!c.queueReadyAlert && c.titlePlaytime.at("game1") == 3600);xc::app::Settings back; // defaults, then what the screen carries@@ -381,6 +383,7 @@ static void testSettingsChoiceRoundTrip() {CHECK(back.circleConfirms == s.circleConfirms);CHECK(back.lightBarMode == s.lightBarMode && back.lightBarColour == s.lightBarColour);CHECK(back.sharpness == s.sharpness && back.deband == s.deband && back.upscaler == s.upscaler);+ CHECK(back.videoDecoder == s.videoDecoder);CHECK(back.highRefresh == s.highRefresh);CHECK(back.maxBitrateMbps == s.maxBitrateMbps && back.gameVolume == s.gameVolume);CHECK(back.queueReadyAlert == s.queueReadyAlert && back.titlePlaytime == s.titlePlaytime);@@ -431,6 +434,7 @@ static void testPerGameSettings() {s.sharpness = 1;s.deband = 2;s.upscaler = 0;+ s.videoDecoder = 0;s.deadzoneLeft = 12;s.deadzoneRight = 18;s.triggerStrength = 3;@@ -438,7 +442,7 @@ static void testPerGameSettings() {// Default profile reflects global settings.auto def = s.defaultProfile();- CHECK(def.sharpness == 1 && def.deband == 2 && def.upscaler == 0);+ CHECK(def.sharpness == 1 && def.deband == 2 && def.upscaler == 0 && def.videoDecoder == 0);CHECK(def.deadzoneLeft == 12 && def.deadzoneRight == 18 && def.triggerStrength == 3);CHECK(!def.circleConfirms);CHECK(!def.highRefresh); // off unless chosen@@ -448,13 +452,14 @@ static void testPerGameSettings() {bool hasCustom = true;auto prof1 = s.profileForGame("GAME1", "", &hasCustom);CHECK(!hasCustom);- CHECK(prof1.sharpness == 1 && prof1.deadzoneLeft == 12);+ CHECK(prof1.sharpness == 1 && prof1.deadzoneLeft == 12 && prof1.videoDecoder == 0);// Add per-game profile for GAME1.xc::app::GameProfile p1;p1.sharpness = 3;p1.deband = 0;p1.upscaler = 3;+ p1.videoDecoder = 1; // override global HW with SWp1.deadzoneLeft = 5;p1.deadzoneRight = 8;p1.triggerStrength = 1;@@ -470,18 +475,19 @@ static void testPerGameSettings() {CHECK(hasCustom);CHECK(prof1Custom.sharpness == 3 && prof1Custom.upscaler == 3 && prof1Custom.circleConfirms);CHECK(prof1Custom.deadzoneLeft == 5 && prof1Custom.triggerStrength == 1 && prof1Custom.touchpadMouse);+ CHECK(prof1Custom.videoDecoder == 1);CHECK(prof1Custom.locale == "pt-BR");hasCustom = true;auto prof2 = s.profileForGame("GAME2", "", &hasCustom);CHECK(!hasCustom);- CHECK(prof2.sharpness == 1 && !prof2.circleConfirms && !prof2.touchpadMouse && prof2.locale.empty());+ CHECK(prof2.sharpness == 1 && !prof2.circleConfirms && !prof2.touchpadMouse && prof2.locale.empty() && prof2.videoDecoder == 0);// Title ID fallback when productId is empty.s.perGame["CONSOLE_SERVER_1"] = p1;auto consoleProf = s.profileForGame("", "CONSOLE_SERVER_1", &hasCustom);CHECK(hasCustom);- CHECK(consoleProf.sharpness == 3 && consoleProf.circleConfirms && consoleProf.locale == "pt-BR");+ CHECK(consoleProf.sharpness == 3 && consoleProf.circleConfirms && consoleProf.locale == "pt-BR" && consoleProf.videoDecoder == 1);// Save to disk and reload.CHECK(s.desktopFullscreen); // a desktop window starts fullscreen unless chosen otherwise@@ -495,14 +501,14 @@ static void testPerGameSettings() {auto loadedP1 = reloaded.profileForGame("GAME1", "", &hasCustom);CHECK(hasCustom);CHECK(loadedP1.sharpness == 3 && loadedP1.upscaler == 3 && loadedP1.circleConfirms);- CHECK(loadedP1.highRefresh && loadedP1.touchpadMouse && loadedP1.locale == "pt-BR");+ CHECK(loadedP1.highRefresh && loadedP1.touchpadMouse && loadedP1.locale == "pt-BR" && loadedP1.videoDecoder == 1);CHECK(loadedP1.deadzoneLeft == 5 && loadedP1.deadzoneRight == 8 && loadedP1.triggerStrength == 1);// Remove game profile restores default.reloaded.perGame.erase("GAME1");auto afterErase = reloaded.profileForGame("GAME1", "", &hasCustom);CHECK(!hasCustom);- CHECK(afterErase.sharpness == reloaded.sharpness && afterErase.locale.empty());+ CHECK(afterErase.sharpness == reloaded.sharpness && afterErase.locale.empty() && afterErase.videoDecoder == reloaded.videoDecoder);std::remove(path.c_str());}@@ -2061,44 +2067,44 @@ static void testVisibleSettingsRows() {};const ui::UiCaps ps5;auto all = ui::visibleSettingsRows(ps5);- CHECK((ids(all) == std::vector<int>{0, 8, 17, 1, 9, 10, 2, 18, 14, 12, 3, 15, 4, 5, 6, 16, 19, 7}));- CHECK((groups(all) == std::vector<bool>{false, false, false, true, false, false, false, false, true, false, false, false, false, false, false, false, true, false}));+ CHECK((ids(all) == std::vector<int>{0, 8, 17, 1, 20, 9, 10, 2, 18, 14, 12, 3, 15, 4, 5, 6, 16, 19, 7}));+ CHECK((groups(all) == std::vector<bool>{false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false}));ui::UiCaps pc;pc.lightBar = pc.triggerRumble = pc.adaptiveTriggers = pc.gyro = pc.touchpad = false;pc.upscalers = pc.sharpen = pc.deband = pc.highRefresh = pc.console = pc.selfUpdate = false;pc.openUrl = true;auto desk = ui::visibleSettingsRows(pc);- CHECK((ids(desk) == std::vector<int>{0, 8, 17, 1, 10, 2, 18, 14, 12, 3, 5, 16, 19, 7}));- CHECK((groups(desk) == std::vector<bool>{false, false, false, true, false, false, false, true, false, false, false, false, true, false}));+ CHECK((ids(desk) == std::vector<int>{0, 8, 17, 1, 20, 10, 2, 18, 14, 12, 3, 5, 16, 19, 7}));+ CHECK((groups(desk) == std::vector<bool>{false, false, false, true, false, false, false, false, true, false, false, false, false, true, false}));// The desktop app's window: Display mode after the resolution, in the stream's group.ui::UiCaps win = pc;win.desktopWindow = true;auto w = ui::visibleSettingsRows(win);- CHECK((ids(w) == std::vector<int>{0, 8, 17, 1, 13, 10, 2, 18, 14, 12, 3, 5, 16, 19, 7}));- CHECK((groups(w) == std::vector<bool>{false, false, false, true, false, false, false, false, true, false, false, false, false, true, false}));+ CHECK((ids(w) == std::vector<int>{0, 8, 17, 1, 20, 13, 10, 2, 18, 14, 12, 3, 5, 16, 19, 7}));+ CHECK((groups(w) == std::vector<bool>{false, false, false, true, false, false, false, false, false, true, false, false, false, false, true, false}));ui::UiCaps xbox = pc; // an Xbox pad: impulse triggers, no light barxbox.triggerRumble = true;auto x = ids(ui::visibleSettingsRows(xbox));CHECK(std::find(x.begin(), x.end(), 4) != x.end() && std::find(x.begin(), x.end(), 6) == x.end());// A game's settings.- CHECK((ids(ui::visibleGameSettingsRows(ps5, true, false)) == std::vector<int>{0, 4, 8, 14, 1, 2, 3, 5, 6, 7, 12, 11, 9, 10}));- CHECK((ids(ui::visibleGameSettingsRows(ps5, true, true)) == std::vector<int>{0, 4, 8, 14, 1, 2, 3, 5, 6, 7, 12, 11, 13, 9, 10}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, true, false)) == std::vector<int>{0, 4, 8, 15, 14, 1, 2, 3, 5, 6, 7, 12, 11, 9, 10}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, true, true)) == std::vector<int>{0, 4, 8, 15, 14, 1, 2, 3, 5, 6, 7, 12, 11, 13, 9, 10}));CHECK((groups(ui::visibleGameSettingsRows(ps5, true, true)) ==- std::vector<bool>{false, true, false, false, true, false, false, true, false, false, false, false, false, false, true}));- CHECK((ids(ui::visibleGameSettingsRows(ps5, false)) == std::vector<int>{0, 4, 8, 14, 1, 2, 3, 5, 6, 7, 12, 11, 9}));+ std::vector<bool>{false, true, false, false, false, true, false, false, true, false, false, false, false, false, false, true}));+ CHECK((ids(ui::visibleGameSettingsRows(ps5, false)) == std::vector<int>{0, 4, 8, 15, 14, 1, 2, 3, 5, 6, 7, 12, 11, 9}));ui::UiCaps noTouch = ps5;noTouch.touchpad = false;- CHECK((ids(ui::visibleGameSettingsRows(noTouch, true, true)) == std::vector<int>{0, 4, 8, 14, 1, 2, 3, 5, 6, 7, 12, 11, 9, 10}));+ CHECK((ids(ui::visibleGameSettingsRows(noTouch, true, true)) == std::vector<int>{0, 4, 8, 15, 14, 1, 2, 3, 5, 6, 7, 12, 11, 9, 10}));auto game = ui::visibleGameSettingsRows(pc, false);- CHECK((ids(game) == std::vector<int>{0, 4, 14, 5, 7, 11, 9}));- CHECK((groups(game) == std::vector<bool>{false, true, false, true, false, false, false}));+ CHECK((ids(game) == std::vector<int>{0, 4, 15, 14, 5, 7, 11, 9}));+ CHECK((groups(game) == std::vector<bool>{false, true, false, false, true, false, false, false}));// How far down the autoplay tests walk to each row (autoplay.cpp's downsTo).- CHECK(ui::settingsRowPosition(ps5, 1) == 3 && ui::settingsRowPosition(ps5, 3) == 10);- CHECK(ui::settingsRowPosition(ps5, 16) == 15);- CHECK(ui::settingsRowPosition(ps5, 5) == 13 && ui::settingsRowPosition(ps5, 6) == 14);- CHECK(ui::settingsRowPosition(ps5, 12) == 9 && ui::settingsRowPosition(ps5, 14) == 8);- CHECK(ui::settingsRowPosition(ps5, 7) == 17 && ui::settingsRowPosition(ps5, 19) == 16 && ui::settingsRowPosition(ps5, 2) == 6);- CHECK(ui::settingsRowPosition(pc, 5) == 10 && ui::settingsRowPosition(pc, 6) == -1 && ui::settingsRowPosition(pc, 4) == -1);+ CHECK(ui::settingsRowPosition(ps5, 1) == 3 && ui::settingsRowPosition(ps5, 3) == 11);+ CHECK(ui::settingsRowPosition(ps5, 16) == 16);+ CHECK(ui::settingsRowPosition(ps5, 5) == 14 && ui::settingsRowPosition(ps5, 6) == 15);+ CHECK(ui::settingsRowPosition(ps5, 12) == 10 && ui::settingsRowPosition(ps5, 14) == 9);+ CHECK(ui::settingsRowPosition(ps5, 7) == 18 && ui::settingsRowPosition(ps5, 19) == 17 && ui::settingsRowPosition(ps5, 2) == 7);+ CHECK(ui::settingsRowPosition(pc, 5) == 11 && ui::settingsRowPosition(pc, 6) == -1 && ui::settingsRowPosition(pc, 4) == -1);}// The controller's glyphs by pad kind (ui/pad_glyphs.h).@@ -2190,6 +2196,45 @@ static void testNullBackends() {CHECK(!display::canSwitchRefresh() && !display::setHighRefresh(true) && !display::bringUpTest(1));}+static void testVideoDecoder() {+ media::VideoDecoder dec;+ CHECK(dec.init(1, false));+ CHECK(!dec.isHardware());+ CHECK(dec.needsKeyframe());++ media::Picture pic;+ CHECK(!dec.decode(nullptr, 0, pic));+ CHECK(!dec.decode(nullptr, 100, pic));+ uint8_t garbage[16] = {0, 0, 0, 1, 0xFF, 0xFF, 0xFF, 0xFF};+ CHECK(!dec.decode(garbage, 0, pic));+ CHECK(!dec.decode(garbage, sizeof garbage, pic));+ CHECK(dec.needsKeyframe());++ // Hardware init preference test (on non-PS5 desktop without HW device it gracefully stays/falls back to software)+ media::VideoDecoder hwDec;+ CHECK(hwDec.init(1, true));++ // splitAccessUnits tests+ std::vector<uint8_t> stream = {0, 0, 0, 1, 9, 0x10, 0, 0, 0, 1, 7, 0x42, 0, 0, 0, 1, 8, 0xCE, 0, 0, 0, 1, 5, 0x88};+ auto aus = media::splitAccessUnits(stream.data(), stream.size());+ CHECK(!aus.empty());+}++static void testDrawNv12() {+ // Boundary and parameter checks+ CHECK(!display::drawNv12(nullptr, nullptr, 0, 0, 0, 0, false));+ CHECK(!display::drawNv12(nullptr, nullptr, 1920, 1920, 1920, 1080, false));+ uint8_t dummy[16] = {};+ CHECK(!display::drawNv12(dummy, dummy, 10, 10, -1, 1080, false));+ CHECK(!display::drawNv12(dummy, dummy, 10, 10, 1920, -1, false));+ CHECK(!display::drawNv12(dummy, dummy, 100, 100, 1920, 1080, false)); // stride < width++ // Valid dummy frame in null display backend+ std::vector<uint8_t> y(1920 * 1080, 128);+ std::vector<uint8_t> uv(1920 * 540, 128);+ CHECK(display::drawNv12(y.data(), uv.data(), 1920, 1920, 1920, 1080, false));+}+// --- M1 input / audio backends (pure parts, null backends) ----------------// The audio queue: bounded at ~250 ms (cut back to 140 ms, oldest first),@@ -3509,6 +3554,8 @@ int main() {testPadMap();testTeredo();testBlock1Features();+ testVideoDecoder();+ testDrawNv12();if (g_failures) {std::fprintf(stderr, "%d failure(s)\n", g_failures);return 1;