diff --git a/guest/bundle/src/RgfxVideoDriver.cpp b/guest/bundle/src/RgfxVideoDriver.cpp index 53a5ccc93..aa5cf404b 100644 --- a/guest/bundle/src/RgfxVideoDriver.cpp +++ b/guest/bundle/src/RgfxVideoDriver.cpp @@ -1112,7 +1112,21 @@ uint64_t answer(int entry, uint64_t a0, uint64_t a1, uint64_t a2) : fi->sub_id == kCodecHevc ? RGFX_VIDEO_CODEC_HEVC : 0; if (codec != 0) { - context->session = rgfx::video::openSession(codec, RGFX_VIDEO_DECODE); + // An H.264 stream of a coded size the host does not decode is refused here, where + // VideoToolbox hears of it and turns to its software decoder: AppleGVA's H.264 + // decoder hears of no failure later (RgfxVideoStatus.hpp). + if (codec == RGFX_VIDEO_CODEC_H264 && + !rgfx::video::sizeTaken(rgfx::video::hostCodec(codec, RGFX_VIDEO_DECODE), + fi->width, fi->height)) { + static std::atomic said; + if (!said.exchange(true)) + os_log_error(OS_LOG_DEFAULT, + "RGFX: video: an H.264 decode of %ux%u refused at its create: " + "the host decodes no picture of its coded size", + fi->width, fi->height); + } else { + context->session = rgfx::video::openSession(codec, RGFX_VIDEO_DECODE); + } if (!context->session) { // The contexts made before it go with their sessions, which leave the // live ones. diff --git a/guest/bundle/src/RgfxVideoStatus.hpp b/guest/bundle/src/RgfxVideoStatus.hpp index 6d155bf7f..8a2e2b95f 100644 --- a/guest/bundle/src/RgfxVideoStatus.hpp +++ b/guest/bundle/src/RgfxVideoStatus.hpp @@ -23,7 +23,9 @@ * host, 2026-11-07, every picture failed on the host). Its pipelines schedule their commands one * at a time and keep no decode's result (read from AppleGVA's code on macOS 26.7.1). So an H.264 * schedule does not wait for the host, as waiting would only cost: its frames reach the guest as - * decoded, as AppleGVA leaves no way to say otherwise. + * decoded, as AppleGVA leaves no way to say otherwise. What the driver can tell before the first + * picture, a coded size the host does not decode (sizeTaken), it refuses at the context's create, + * which fails the client's session create, so VideoToolbox decodes the stream in software. */ #ifndef RGFX_VIDEO_STATUS_HPP_ @@ -31,6 +33,8 @@ #include +#include "reims_graphics_wire.h" + namespace rgfx::video { // A query's status: a command is still decoding, or it is done. @@ -62,6 +66,20 @@ inline bool scheduleFails(bool sent, bool hostFailed) return !sent || hostFailed; } +// Whether the host decodes pictures of `width` x `height` coded samples, by its caps (`caps`, null +// for none): within its least and largest coded size, where it names them. +inline bool sizeTaken(const RgfxVideoCodecCaps *caps, uint32_t width, uint32_t height) +{ + if (!caps) + return false; + const uint32_t size[2] = {width, height}; + for (int i = 0; i < 2; i++) + if ((caps->min_size[i] && size[i] < caps->min_size[i]) || + (caps->max_size[i] && size[i] > caps->max_size[i])) + return false; + return true; +} + } // namespace rgfx::video #endif diff --git a/guest/bundle/tests/video_driver_tests.cpp b/guest/bundle/tests/video_driver_tests.cpp index 01bf25f61..974b784a3 100644 --- a/guest/bundle/tests/video_driver_tests.cpp +++ b/guest/bundle/tests/video_driver_tests.cpp @@ -418,14 +418,17 @@ FunctionInfo decodeH264() return f; } -// Makes the contexts of `n` decodes of `codec` (H.264's unless named): CreateContexts' answer, -// the contexts in `contexts`. -uint64_t makeContexts(uint32_t n, std::vector &contexts, uint64_t codec = kCodecH264) +// Makes the contexts of `n` decodes of `codec` (H.264's unless named), of `width` x `height` +// coded samples (1280x720 unless named): CreateContexts' answer, the contexts in `contexts`. +uint64_t makeContexts(uint32_t n, std::vector &contexts, uint64_t codec = kCodecH264, + uint32_t width = 1280, uint32_t height = 720) { static std::vector infos; static std::vector list; FunctionInfo f = decodeH264(); f.sub_id = codec; + f.width = width; + f.height = height; infos.assign(n, f); list.clear(); for (const FunctionInfo &f : infos) @@ -452,6 +455,54 @@ void checkFailedCreate() CHECK(g_opened[0]->forgotten == 0, "the closed session's outputs forgotten"); } +// An H.264 decode of a coded size outside the host's (144 to 8192 samples a side here) is refused +// at its create, with no session opened, as are the contexts made before it in the same create; +// one of the host's least and largest sizes is made. An HEVC decode of any size is made: its +// pictures are held to the host's sizes as they are scheduled, which AppleGVA reports. +void checkH264SizeAtCreate() +{ + const struct { + uint32_t width, height; + uint64_t want; + } cases[] = { + {8193, 720, kUnsupported}, {1280, 8208, kUnsupported}, {128, 720, kUnsupported}, + {1280, 128, kUnsupported}, {144, 144, kOk}, {8192, 8192, kOk}, + }; + for (const auto &c : cases) { + g_opened.clear(); + std::vector contexts; + CHECK(makeContexts(1, contexts, kCodecH264, c.width, c.height) == c.want, + "an H.264 create of %ux%u", c.width, c.height); + CHECK(g_opened.size() == (c.want == kOk ? 1u : 0u), "%zu sessions opened for %ux%u", + g_opened.size(), c.width, c.height); + CHECK((contexts[0] != nullptr) == (c.want == kOk), "the context of %ux%u", c.width, c.height); + if (contexts[0]) { + ContextDelete del = {1, 0, &contexts[0]}; + CHECK(call(kDeleteContexts, &del) == kOk, "DeleteContexts"); + } + } + // A create of two H.264 decodes whose second is of a size the host does not decode: the + // first's session goes with it. + { + static FunctionInfo infos[2]; + infos[0] = infos[1] = decodeH264(); + infos[1].width = 8193; + const FunctionInfo *list[2] = {&infos[0], &infos[1]}; + void *contexts[2] = {}; + ContextInfo info = {2, 0, list, contexts}; + ContextInit init = {&info, nullptr}; + g_opened.clear(); + CHECK(call(kCreateContexts, &init) == kUnsupported, "a create whose second decode is too wide"); + CHECK(g_opened.size() == 1 && g_opened[0]->closed, "the first decode's session left open"); + CHECK(contexts[0] == nullptr && contexts[1] == nullptr, "a context handed back"); + } + g_opened.clear(); + std::vector contexts; + CHECK(makeContexts(1, contexts, kCodecHevc, 8193, 720) == kOk, "an HEVC create of 8193x720"); + ContextDelete del = {1, 0, &contexts[0]}; + CHECK(call(kDeleteContexts, &del) == kOk, "DeleteContexts"); +} + // DeleteContexts closes each context's session, which a later FreePixelBufferPool no longer // reaches; the contexts still open are reached. void checkDelete() @@ -1370,6 +1421,7 @@ int main() g_driver = createDriver(); checkPoolsPerDriver(); checkFailedCreate(); + checkH264SizeAtCreate(); checkDelete(); checkUnsentDecode(); checkTileLanding();