diff --git a/CB1/config/owned-sources.json b/CB1/config/owned-sources.json index f6fb6506ae..009807b9f6 100644 --- a/CB1/config/owned-sources.json +++ b/CB1/config/owned-sources.json @@ -1,5 +1,5 @@ { - "src/dvbridge_fel.c": "7b291b3509f393a239a604b4e70c8d7323c725391e548264dd5dc8dc55859d0f", + "src/dvbridge_fel.c": "d3a129feffdd0a858ee15469c334aef51323e508b61337024c47c08bce4461ac", "src/dvbridge_gl_pack.h": "2ccd974503fbcbb33678ee2eff076a7a086bcd1796efa97010a1eebb901143f5", "src/dvbridge_gl_pack.c": "e872527f20d4e56c1da39a1d591c829bc54174ad8fb2fa94c61cfe2a0043d996", "src/cb1_circuit.c": "b3dc96ad27a802680811858862f67c4921f595ce042e3df6cd19c286f8872e56", @@ -63,7 +63,7 @@ "src/cb1_trim_math.h": "178b7ef0b567b61c7d73cea702971b10299a04931367c090be0a3c8561c8cfcc", "src/cb1_transport_glsl.h": "1d775ef6306e76a831fc192ef9c7b7989fef97cb5c001903f2ab674e89445566", "src/cb1_composite_glsl.h": "65e462c80246b0e44ecf31f5f957a53cc48dd9924009b3461cd008fbdc124916", - "src/dvbridge_fel.h": "2986af5b358c4692a9e804e6fccd13c05dfed88722b401e3f061b516f9cce517", + "src/dvbridge_fel.h": "fa744fa8e4b8f4a0ee1eb364351dfc56cde0b975074fd0e3f57635793b5b424f", "src/cb1_master_ipt.c": "2793976a1a49187658ab0c6f3eb4c3cdce056b61497ac2939612c4bba49b5ea6", "src/cb1_master_ipt.h": "3efb1f79bf2340c10ada773267b792b5d5e33256e7ae73055b19f80fdb5a3ae1", "src/cb1_master_ipt_shader.h": "92e41f052f975a44bb3404a5ec8f44380729b070507af918c40f40d52f446e95", diff --git a/CB1/src/dvbridge_fel.c b/CB1/src/dvbridge_fel.c index 713bd3ce8d..9dc91f5c9d 100644 --- a/CB1/src/dvbridge_fel.c +++ b/CB1/src/dvbridge_fel.c @@ -593,13 +593,23 @@ static bool submit(struct dvbridge_fel *f, const AVPacket *packet, if (result == AVERROR(EAGAIN)) { if (source && !received_enhancement && source->enhancement_pts != AV_NOPTS_VALUE) goto fail; - if (!source && !received_enhancement)f->epoch_uncertain = true; + if (!source && !received_enhancement) + f->epoch_uncertain = true; + if (!source && f->synchronizing) { + /* All EL from this AU has been examined. Before the + * first accepted anchor these BL identities are preroll. */ + f->num_times = 0; + if (++f->preroll_packets > 1024) + goto fail; + } return true; /* Submit EL when a decoded BL requests its matching picture. */ } goto fail; } const unsigned limit = f->mel_deferred ? MEL_PACKET_MAX : QUEUE_MAX; - if (f->mel_deferred && !f->el_started && + /* A renewed base decoder may accept more input before returning a + * picture. Give queued EL a chance to decode before rejecting the AU. */ + if ((!f->source_timed || (f->mel_deferred && !f->el_started)) && (f->num_packets >= limit || (size_t)copy->size > PACKET_BYTES_MAX - f->packet_bytes)) if (!pump(f)) { av_packet_free(©); @@ -670,9 +680,6 @@ static bool submit(struct dvbridge_fel *f, const AVPacket *packet, * time. Never use this shortcut for a BL with reordered pictures. */ if (!common_key && !el_idr) { av_packet_free(©); - f->num_times = 0; - if (++f->preroll_packets > 1024) - goto fail; continue; } f->anchor_pts = packet->pts; @@ -698,11 +705,15 @@ bool dvbridge_fel_submit_source(struct dvbridge_fel *f, const AVPacket *packet, return source && submit(f, packet, source); } -bool dvbridge_fel_drain(struct dvbridge_fel *f) +bool dvbridge_fel_drain(struct dvbridge_fel *f, const char **reason) { + if (reason) + *reason = NULL; if (!f) return false; if (f->synchronizing) { + if (reason && !f->failed && f->base_order.seen && !f->enhancement_order.seen) + *reason = "no enhancement video received before drain"; f->failed = true; return false; /* EOF cannot supply the missing random-access picture. */ } diff --git a/CB1/src/dvbridge_fel.h b/CB1/src/dvbridge_fel.h index dab40edfa7..d62ec2d17e 100644 --- a/CB1/src/dvbridge_fel.h +++ b/CB1/src/dvbridge_fel.h @@ -22,7 +22,8 @@ struct dvbridge_fel_source { }; bool dvbridge_fel_submit_source(struct dvbridge_fel *fel, const AVPacket *packet, const struct dvbridge_fel_source *source); -bool dvbridge_fel_drain(struct dvbridge_fel *fel); +/* Optional reason is set only when the final drain identifies a specific fault. */ +bool dvbridge_fel_drain(struct dvbridge_fel *fel, const char **reason); /* 1: exact pair, 0: need input, 2: discard preroll, -1: missing pair / failure. */ int dvbridge_fel_take(struct dvbridge_fel *fel, int64_t pts, AVFrame **frame); /* Disc playback may return 3 for a matched, validated RPU that needs no residual. diff --git a/CB1/tests/fel_queue.c b/CB1/tests/fel_queue.c index 4a85711255..cb516dda93 100644 --- a/CB1/tests/fel_queue.c +++ b/CB1/tests/fel_queue.c @@ -184,6 +184,42 @@ int main(void) assert(!dvbridge_fel_device(f, renewed)); assert(dvbridge_fel_device(f, device) && !dvbridge_fel_failed(f)); av_buffer_unref(&renewed); + + /* A cut or seek can start with BL alone. Such pictures cannot be shown + * before the first usable EL anchor, even if the prefix spans the map. */ + AVPacket *bare = av_packet_alloc(); + assert(bare && av_new_packet(bare, sizeof(synthetic_base)) == 0); + memcpy(bare->data, synthetic_base, sizeof(synthetic_base)); + for (int anchor = 0; anchor <= 1; ++anchor) { + dvbridge_fel_reset(f); + unsigned before = submissions; + for (int i = 0; i < 74; ++i) { + bare->pts = bare->dts = i * 41708; + assert(dvbridge_fel_submit(f, bare)); + AVFrame *discarded = NULL; + assert(dvbridge_fel_take(f, bare->pts, &discarded) == 2 && !discarded); + } + assert(submissions == before); + if (anchor) { + p->pts = p->dts = 74 * 41708; + assert(dvbridge_fel_submit(f, p)); + AVFrame *exact = NULL; + assert(dvbridge_fel_take(f, bare->pts, &exact) == 2 && !exact); + assert(dvbridge_fel_take(f, p->pts, &exact) == 1 && exact->pts == p->pts); + av_frame_free(&exact); + } else { + const char *reason = NULL; + assert(!dvbridge_fel_drain(f, &reason) && dvbridge_fel_failed(f)); + assert(reason && !strcmp(reason, "no enhancement video received before drain")); + } + } + /* Missing EL cannot turn an unbounded input into endless preroll. */ + dvbridge_fel_reset(f); + for (int i = 0; i <= 1024; ++i) { + bare->pts = bare->dts = i * 41708; + assert(dvbridge_fel_submit(f, bare) == (i < 1024)); + } + av_packet_free(&bare); dvbridge_fel_reset(f); assert(frame->pts == 4 * 41708 && frame->buf[0]); /* downstream ref survives seek */ av_frame_free(&frame); @@ -191,7 +227,7 @@ int main(void) assert(dvbridge_fel_submit(f, p)); assert(dvbridge_fel_take(f, 0, &frame) == 1); av_frame_free(&frame); - assert(dvbridge_fel_drain(f)); + assert(dvbridge_fel_drain(f, NULL)); assert(dvbridge_fel_take(f, 1, &frame) == -1 && !frame); assert(!dvbridge_fel_submit(f, p)); dvbridge_fel_reset(f); @@ -201,7 +237,7 @@ int main(void) assert(dvbridge_fel_submit(f, p)); } assert(submissions == queued); - assert(dvbridge_fel_drain(f)); /* EOF must submit and retain all deferred pictures. */ + assert(dvbridge_fel_drain(f, NULL)); /* EOF must submit and retain all deferred pictures. */ for (int i = 0; i < 3; ++i) { assert(dvbridge_fel_take(f, i * 41708, &frame) == 1 && frame->pts == i * 41708); av_frame_free(&frame); @@ -246,6 +282,33 @@ int main(void) avcodec_parameters_free(¶meters); assert(f && dvbridge_fel_device(f, device)); assert(initialized_pool == 41); /* Fixed pools retain the existing 32+4 headroom. */ + /* A renewed BL decoder can accept another input window before its next + * output. Decode compressed EL on pressure, then deliver every exact pair. */ + p->pts = p->dts = 0; + assert(dvbridge_fel_submit(f, p)); + assert(dvbridge_fel_take(f, 0, &frame) == 1); + av_frame_free(&frame); + before = submissions; + for (unsigned i = 1; i <= QUEUE_MAX; ++i) { + p->pts = p->dts = i * 41708; + assert(dvbridge_fel_submit(f, p)); + } + assert(submissions == before); + p->pts = p->dts = (QUEUE_MAX + 1) * 41708; + assert(dvbridge_fel_submit(f, p)); + for (unsigned i = 1; i <= QUEUE_MAX + 1; ++i) { + int64_t pts = i * 41708; + assert(dvbridge_fel_take(f, pts, &frame) == 1 && frame->pts == pts); + av_frame_free(&frame); + } + /* With both stages full and no base consumption, the bound still holds. */ + dvbridge_fel_reset(f); + for (unsigned i = 0; i < 2 * QUEUE_MAX; ++i) { + p->pts = p->dts = i * 41708; + assert(dvbridge_fel_submit(f, p)); + } + p->pts = p->dts = 2 * QUEUE_MAX * 41708; + assert(!dvbridge_fel_submit(f, p) && dvbridge_fel_failed(f)); dvbridge_fel_destroy(f); parameters = avcodec_parameters_alloc(); parameters->codec_type = AVMEDIA_TYPE_VIDEO; diff --git a/CB1/tests/fel_source_time.c b/CB1/tests/fel_source_time.c index 5e2426c8d3..cb58b5fc98 100644 --- a/CB1/tests/fel_source_time.c +++ b/CB1/tests/fel_source_time.c @@ -104,7 +104,7 @@ int main(void) assert(submit_source(f,packet,&tail)); assert(dvbridge_fel_take(f,5000,&frame)==1&&frame&&frame->pts==5000); av_frame_free(&frame); - assert(dvbridge_fel_drain(f)); + assert(dvbridge_fel_drain(f, NULL)); dvbridge_fel_reset(f); // A genuinely decoded leading picture is exact despite a later RAP PTS. f->source_timed=true;f->anchor_pts=100;f->num_times=1; diff --git a/CB1/tests/gui_coverage_alpha.cpp b/CB1/tests/gui_coverage_alpha.cpp index 527de57493..b35a4b3345 100644 --- a/CB1/tests/gui_coverage_alpha.cpp +++ b/CB1/tests/gui_coverage_alpha.cpp @@ -7,7 +7,8 @@ #endif namespace Drawing { struct CWinSystemBase { - bool m_guiCompositing=true; + bool m_guiCompositing=true,nativeSDR=false; + bool UsesNativeSDRBT2020() const {return nativeSDR;} virtual bool IsHdrComposite()const{return m_guiCompositing;} virtual bool UseGuiCoverageAlpha()const @@NATIVE_POLICY@@ }; @@ -23,12 +24,13 @@ enum class ShaderMethodGLES {SM_FONTS,SM_FONTS_SHADER_CLIP,SM_MULTI_111R_111R_BL GLuint fontProgram,textureProgram,inputTexture; struct RenderBase{virtual ~RenderBase()=default;}; struct CRenderSystemGLES:RenderBase { + std::array colour{.8f,.8f,.8f}; bool ScissorsCanEffectClipping(){return true;} void ResetScissors(){} void EnableGUIShader(ShaderMethodGLES method){ GLuint p=method==ShaderMethodGLES::SM_FONTS?fontProgram:textureProgram; glUseProgram(p);glUniform1i(glGetUniformLocation(p,"m_samp0"),0); - glUniform4f(glGetUniformLocation(p,"test_colour"),.8,.8,.8,1); - glUniform4f(glGetUniformLocation(p,"m_unicol"),.8,.8,.8,1); + glUniform4f(glGetUniformLocation(p,"test_colour"),colour[0],colour[1],colour[2],1); + glUniform4f(glGetUniformLocation(p,"m_unicol"),colour[0],colour[1],colour[2],1); } } render; struct Texture { @@ -75,7 +77,8 @@ GLuint guiProgram(const std::string& fragment){ GLint linked;glGetProgramiv(p,GL_LINK_STATUS,&linked);assert(linked);return p; } std::string read(const std::string& path){std::ifstream f(path);std::stringstream s;s<& colour={.8f,.8f,.8f}){ + render.colour=colour; glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D,inputTexture); const float pixel[]={1,1,1,alpha};glTexSubImage2D(GL_TEXTURE_2D,0,0,0,1,1,GL_RGBA,GL_FLOAT,pixel); if(font){CGUIFontTTFGLES glyph;assert(glyph.FirstBegin());} @@ -104,13 +107,13 @@ int main(int argc,char**argv){ GLuint target=texture(width,height,film.data());finalFramebuffer=framebuffer(target); unsigned failures=0; auto check=[&](bool pass,const char* reason){if(!pass){std::cerr< m_playerLedGui{},m_playerLedSubtitles{}; void SetProjection(const GLfloat* p){m_proj=p;} void SetInputPQ(bool p){m_inputPQ=p;} - void SetSDRBT2020(bool wide){m_sdrBT2020=wide;} + void SetSDRBT2020(bool wide,bool premultiplied=false){m_sdrBT2020=wide;m_unpremultiplyGui=premultiplied;} void SetOutputRange(float s,float o){m_outputScale=s;m_outputOffset=o;} void SetPlayerLed(float peak=0,const std::array& guiMatrix={}, const std::array& subMatrix={}) diff --git a/config/cb1-patch-index.json b/config/cb1-patch-index.json index 60d54a502f..c4074c93ee 100644 --- a/config/cb1-patch-index.json +++ b/config/cb1-patch-index.json @@ -191,6 +191,22 @@ "drivers/net/wireless/mediatek/mt76/mt792x.h": "Track the held join ROC per interface." } }, + "projects/Generic/patches/linux/0103-wifi-mt76-mt7925-keep-join-roc-until-authorized.patch": { + "summary": "Keep the MT7925 join ROC until the station is authorized (mainline ac22c8c723c6)", + "component": "linux", + "files": { + "drivers/net/wireless/mediatek/mt76/mt7925/main.c": "Keep the join ROC after a successful non-MLO association and release it on authorization, disassociation or station removal." + } + }, + "projects/Generic/patches/linux/0104-wifi-mt76-mt7925-track-join-roc-ownership.patch": { + "summary": "Release the MT7925 non-MLO association channel only while the grant belongs to that interface", + "component": "linux", + "files": { + "drivers/net/wireless/mediatek/mt76/mt7925/main.c": "Track successful association grants and serialize release with new channel requests and timer expiry.", + "drivers/net/wireless/mediatek/mt76/mt7925/mcu.c": "Arm the expiry timer before publishing the firmware grant.", + "drivers/net/wireless/mediatek/mt76/mt792x.h": "Keep the active MT7925 association owner on the shared PHY." + } + }, "projects/Generic/patches/linux/linux-9900-00-drivers__gpu__drm__i915__display__intel_atomic.c.patch": { "summary": "Expose the validated Dolby Vision connector control", "component": "linux", @@ -1044,6 +1060,15 @@ "xbmc/cores/VideoSourceSideData.h": "Provide lightweight automatic DV diagnostics in the normal Kodi log.; Present native HDR10+ and convert reconstructed Dolby Vision to HDR10+." } }, + "projects/Generic/patches/kodi/kodi-9998-hdmi-dts-capability.patch": { + "owner": "Respect DTS descriptors from complete HDMI ELD on ALSA sinks.", + "files": { + "xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp": "Publish HDMI DTS core and HD independently while preserving the legacy fallback for unavailable capability data.", + "xbmc/cores/AudioEngine/Sinks/AESinkALSA.h": "Pass DTS capability data through the existing ELD control reading path.", + "xbmc/cores/AudioEngine/Utils/AEELDParser.cpp": "Validate the HDMI baseline and descriptor bounds and decode DTS core and HD support.", + "xbmc/cores/AudioEngine/Utils/AEELDParser.h": "Return DTS capabilities when the ELD descriptors provide enough evidence." + } + }, "projects/Generic/patches/kodi/kodi-9991-cb1-audio.patch": { "summary": "Consolidated native CB1 audio ownership", "component": "kodi", @@ -1925,7 +1950,7 @@ "owner": "Keep the Stable video settings and LLDV output readable.", "files": { "addons/resource.language.en_gb/resources/strings.po": "Keep subordinate labels consistent.", - "addons/skin.estuary/xml/DialogTextViewer.xml": "Lay out the optional LLDV display facts using Estuary’s native dialog controls.", + "addons/skin.estuary/xml/DialogTextViewer.xml": "Lay out the optional LLDV display facts using Estuary’s native dialog controls.", "addons/skin.estuary/xml/Includes.xml": "Show optional inline format notes in the compact select list.", "addons/skin.estuary/xml/Includes_DialogSelect.xml": "Show EDID diagnostics beside the LLDV format list.", "system/settings/settings.xml": "Group playback and scaling settings and expose SDR controls only for applicable defaults.", @@ -1933,7 +1958,7 @@ "xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp": "Keep asynchronous preparation enabled and present CPU-packed LLDV in scanout order.", "xbmc/dialogs/DVPlaybackModes.cpp": "Keep connector diagnostics outside the selectable items.", "xbmc/dialogs/GUIDialogPlayerProcessInfo.cpp": "Show the signal, HDMI format and one coordinate pair per primary.", - "xbmc/dialogs/GUIDialogSelect.cpp": "Open Kodi’s native text viewer without closing the LLDV selector." + "xbmc/dialogs/GUIDialogSelect.cpp": "Open Kodi’s native text viewer without closing the LLDV selector." } }, "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-stable-playback-circuits.patch": { @@ -2121,10 +2146,24 @@ "xbmc/windowing/gbm/drm/DRMAtomic.h": "Return the confirmation from the same atomic transaction." } }, + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hdr10-fallback-mode.patch": { + "owner": "Keep the selected cadence on a usable display mode when Dolby Vision startup falls back to HDR10.", + "files": { + "xbmc/cores/VideoPlayer/VideoPlayer.cpp": "Use the shared playback mode choice before opening the decoder.", + "xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp": "Replace an unusable default mode for automatic HDR10 recovery with a usable mode at the same refresh rate.", + "xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h": "Carry decoded source identity into the shared choice.", + "xbmc/windowing/gbm/WinSystemGbm.cpp": "Collect eligible physical timings on the display owner.", + "xbmc/windowing/gbm/WinSystemGbm.h": "Expose eligible timing values to the display owner.", + "xbmc/settings/DisplaySettings.cpp": "Copy mode identity and update the desktop resolution under the catalogue lock.", + "xbmc/settings/DisplaySettings.h": "Expose locked resolution catalogue access.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp": "Publish and invalidate eligible timings with the display capabilities, and match the requested mode to that snapshot.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.h": "Keep the timing snapshot with the existing capability state." + } + }, "projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch": { "owner": "Restore the enabled output bit on an active Alder Lake-P HDMI audio route.", "files": { - "sound/hda/codecs/hdmi/intelhdmi.c": "Check the selected pin's control register during Intel route fixup and preserve its audio mode." + "sound/hda/codecs/hdmi/hdmi.c": "Restore the active Alder Lake-P pin during PCM setup and HDMI link refresh, preserving the audio mode." } }, "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-y444-scanout.patch": { @@ -2279,7 +2318,7 @@ "projects/Generic/patches/linux/linux-9973-intel-legacy-lldv.patch": { "owner": "Reuse the experimental packed LLDV path on additional Intel HDMI engines.", "files": { - "drivers/gpu/drm/i915/display/intel_hdmi.c": "Admit Display9–12 and Battlemage under the existing link guards, with bounded connector diagnostics." + "drivers/gpu/drm/i915/display/intel_hdmi.c": "Admit Display9–12 and Battlemage under the existing link guards, with bounded connector diagnostics." } }, "projects/Generic/patches/linux/linux-9972-rx550-lldv.patch": { @@ -2297,5 +2336,68 @@ "xbmc/windowing/gbm/WinSystemGbmGLESContext.h": "Expose the playback-rate compatibility check.", "xbmc/settings/SettingConditions.cpp": "Report the playback timing restriction in Quick Switch." } + }, + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-startup-timing-fallback.patch": { + "summary": "Use the existing per-file HDR10 fallback when the default LLDV circuit cannot use the playback timing", + "component": "kodi", + "files": { + "xbmc/cores/VideoPlayer/VideoPlayer.cpp": "Resolve the fallback before opening the video decoder.", + "xbmc/windowing/gbm/WinSystemGbm.cpp": "Use the same timing criteria for the current mode and candidate modes.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp": "Require a confirmed LLDV transport refusal and an admissible HDR10 output.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.h": "Expose the shared startup fallback check." + } + }, + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-preserve-native-sdr-bt2020.patch": { + "owner": "Preserve native SDR BT.2020 on a capable GBM HDMI output.", + "files": { + "system/shaders/GL/1.5/gl_gui_composite.frag": "Convert straight SDR GUI colors to the video gamut while retaining coverage.", + "system/shaders/GLES/2.0/gles_gui_composite.frag": "Recover straight native SDR GUI colors before transfer and gamut conversion.", + "xbmc/guilib/GUIFontTTFGL.cpp": "Use the same coverage policy as GLES for translucent glyphs.", + "xbmc/guilib/GUITextureGL.cpp": "Retain coverage in native SDR textures and translucent quads.", + "xbmc/guilib/GUITextureGLES.cpp": "Retain coverage in native SDR translucent quads.", + "xbmc/rendering/RenderSystem.h": "Refresh GUI shader color state without restarting rendering.", + "xbmc/rendering/gl/RenderSystemGL.cpp": "Refresh the GUI range define when the composition target changes.", + "xbmc/rendering/gl/RenderSystemGL.h": "Expose the GL GUI shader color-state refresh.", + "xbmc/rendering/gles/RenderSystemGLES.cpp": "Refresh the GUI range define when the composition target changes.", + "xbmc/rendering/gles/RenderSystemGLES.h": "Expose the GLES GUI shader color-state refresh.", + "xbmc/rendering/gles/GuiCompositeShaderGLES.h": "Track whether the SDR compositor receives premultiplied GUI colors.", + "xbmc/application/Application.cpp": "Negotiate output and GUI composition before either layer draws.", + "xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp": "Use the negotiated SDR gamut in every native GL YUV shader.", + "xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.h": "Track the compiled native SDR gamut and include the existing buffer types.", + "xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp": "Use the negotiated SDR gamut in the filtered, progressive and field shaders.", + "xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h": "Track the compiled native SDR gamut.", + "xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererUtil.cpp": "Convert PQ bitmap palettes to sRGB before SDR GUI composition.", + "xbmc/rendering/gl/GuiCompositeShaderGL.cpp": "Bind the SDR composite mode uniform.", + "xbmc/rendering/gl/GuiCompositeShaderGL.h": "Expose the SDR composite mode.", + "xbmc/rendering/gles/GuiCompositeShaderGLES.cpp": "Reuse the SDR gamma path for native BT.2020.", + "xbmc/windowing/WinSystem.h": "Give the renderer access to the negotiated gamut and initialize it before GUI rendering.", + "xbmc/windowing/gbm/WinSystemGbm.cpp": "Negotiate and commit native SDR BT.2020 with the same framebuffer.", + "xbmc/windowing/gbm/WinSystemGbm.h": "Own the negotiated and accepted native SDR gamut.", + "xbmc/windowing/gbm/WinSystemGbmGLContext.cpp": "Select the SDR compositor for native BT.2020.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp": "Reuse SDR gamut conversion for native GUI and subtitle composition." + } + }, + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-reuse-gbm-front-buffer.patch": { + "summary": "Probe the already locked GBM buffer during output setup", + "component": "kodi", + "files": { + "xbmc/windowing/gbm/GBMUtils.cpp": "Return the latest retained front buffer without acquiring it again.", + "xbmc/windowing/gbm/GBMUtils.h": "Expose a non-owning accessor for the retained front buffer.", + "xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp": "Reuse the buffer when validating float output." + } + }, + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-logical-video-screenshot.patch": { + "owner": "Capture native video from decoded Master, HDR10 and SDR outputs and decline unsupported DV carriers.", + "files": { + "xbmc/rendering/capture/CaptureBlit.cpp": "Choose the video readback and crop logical pixels with their native stride.", + "xbmc/rendering/capture/CaptureBlit.h": "Declare the video capture operation.", + "xbmc/rendering/capture/CapturePixels.h": "Keep the decoded buffer alive for an offset visible region.", + "xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp": "Serve the video tap and retain the composite leg of a paired screenshot.", + "xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp": "Guard video-only screenshots of composed frames.", + "xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.h": "Guard video-only screenshots of composed frames.", + "xbmc/windowing/gbm/DVBridgeCapture.h": "Guard video-only screenshots of composed frames.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.h": "Guard video-only screenshots of composed frames.", + "xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp": "Refresh paused native captures and select the correctly decoded video output." + } } } diff --git a/config/cb1-source-lock.json b/config/cb1-source-lock.json index 076a2d2c04..d25437c80b 100644 --- a/config/cb1-source-lock.json +++ b/config/cb1-source-lock.json @@ -92,7 +92,7 @@ "projects/Generic/filesystem/usr/bin/dv-diagnostics": "ee77b1f0c9a93a1ebd8680229b6b94b7cfcdd07b651e7eed07d38c6a3df2bdaf", "projects/Generic/patches/linux/linux-9910-common-dv-policy.patch": "591d0e319966276f5b236a959fdd35fd5a81e57d4208bf589b28ad8fcf4c82d1", "packages/sysutils/busybox/config/busybox-init.conf": "747ef97a8bc053add17961092bab59d27f6528f165694cd098a5bd51a5f701c8", - "projects/Generic/linux/7.2.6/linux.x86_64.conf": "39f78e93e1dfa2feb77fa7210b9fefef7e4d727c532864fdf49cd1cdbc36eccb", + "projects/Generic/linux/7.2.6/linux.x86_64.conf": "a288a1839c84c3a11f764af13c310ac0e9f644fb575501272e457ef78bae6b02", "projects/Generic/patches/linux/linux-9900-01-drivers__gpu__drm__i915__display__intel_display.c.patch": "3fda480544ce48c2dd9e8e2b39e7bf98bc735521bd3a85fc13644106835fe028", "projects/Generic/patches/linux/linux-9900-04-drivers__gpu__drm__i915__display__intel_display_types.h.patch": "fb6e6206ce6033e6331b02945ace84aad60c09d83380bb102fca328a5ad54199", "packages/graphics/nvidia-open-kernel-modules/patches/nvidia-open-kernel-modules-9004-native-static-hdr-depth.patch": "51610661b374b74863149071d756f38f63b51da0c86eed4fac702139866c8d04", @@ -107,7 +107,7 @@ "scripts/image": "9e3a399d7423e163a5dca09a75e9887062d7686ca29e9752e61ffde8c04a742e", "projects/Generic/patches/linux/linux-9920-amd-dcn-native-dv.patch": "53f3f7e692a2dfc05e6064a0d89d195ed2b7e316934bdcf5ccec1356d55a32b2", "projects/Generic/patches/ffmpeg/ffmpeg-9900-08-pgs-authoring.patch": "f6c9a7501706d01b45daa6ab5bbf2fecdccdfc3f06c4915b370a3c26c20931bb", - "tests/cb1/test_bitmap_subtitles.py": "becfe6330ab20a4775d409535e5e026da6f238cd360400b95a0d7a2013fbc47a", + "tests/cb1/test_bitmap_subtitles.py": "7725fac23c888d8caadb4a5952c99dda07df2d69648b823db46c56da67dac76c", "tests/cb1/test_bluray_menu_source.py": "309633a6f959e0687af8ee86fbb6081ffb4de875e85c2055edb79317de0ffd05", "tests/cb1/test_hdr10plus_dovi_mode.py": "ac87339f564cbb599df6dabb6f52917b64272a47bc50009f91ae02f5eb5d9836", "tests/cb1/test_native_video_producer.py": "1c37a8e750fd6f0e480a790410be7cb5bb6298386a2e5777e98a17551c97263e", @@ -123,7 +123,7 @@ "tests/cb1/test_dual_carriage.py": "dcc57a32d28964d733d5f4438a98afc2b10cc0833669c52f30442edcd836eead", "tests/cb1/test_joined_headers.py": "672e9636c920b03fba8cd5dcdf1b0b2aac930978b296e3c8e2dcc8d41c473119", "tests/cb1/test_dovi_association_updates.py": "2281ca7f2e7795ac35807e996f009696256eb1f2ec34fbe761404186bb9172c0", - "tests/cb1/test_dv_uhd_mode.py": "c6f625f55f8afa45c06e0ca9751c2890421593d46e64c61e180e83c762930ffc", + "tests/cb1/test_dv_uhd_mode.py": "c8f905d77faf6a7cafb454dc6a4d7e1e274607d27cf63789a18cd22bcaebc54e", "tests/cb1/test_auto_view_mode.py": "211362a9f8a51fa5261cc6fa73fe84524d1c3d510d2862a4e22be1db2fafe9ee", "tests/cb1/test_cmv40.py": "9fc8d881623af68f808a02d16af047f2fe54233bb195584d126cdf8490f540b6", "tests/cb1/test_nvidia_packet_bytes.py": "e2fdad7450ede6c78d71472e7f17f3c7ced183043e446ade3cc30b6aa78c9936", @@ -181,7 +181,7 @@ "tests/cb1/test_bdj_controls.py": "727f56eb29988a6f5992a34d8cd564a69ddd5593d218fce34cbc56a489088915", "tests/cb1/BdjControls.java": "44b02c5b0583fe6282644867ce4e6a3ecdc7a03b4afb00a9f2b9d909730bfdea", "packages/multimedia/libbluray/patches/0002-bdj-video-and-stream-controls.patch": "11c7993c844830fda36c068f006211ecabf39b9b083f5cb673a193e13f78bc8e", - "tests/cb1/test_fel_terminal.py": "4fc999da077ccca06b44f566dbc3e97d07aad8e93ba066d77de3455a6e08e9ab", + "tests/cb1/test_fel_terminal.py": "5f33a562a0dd470006e87b0805d37db2b53d73d8179465afd7c18a80f35b690c", "tests/cb1/test_mel_reference_history.py": "af43b5024f201579b3fd238eb0154556358151ce201dfe2c2175ca2b72f13643", "tests/cb1/test_optional_gui.py": "cd34349c3b323eb87c51c024bd71ca7e98757e1f501c70340c21bca26554800a", "tests/cb1/test_software_dv_import.py": "539cc08623dd1f54c98e117525eff4e4fe99ca7a18f79550ef3ff3784d4e2e90", @@ -205,7 +205,7 @@ "packages/multimedia/libbluray/patches/0002-navigation-read-boundary.patch": "d8e1e9a0a8675f8b8f4928ba377389629c870e3e99c1cc0c50ab562edebed3b7", "tests/cb1/test_libbluray_read_boundary.py": "ed67aa52cf379b1717979b894825d80664fcbd11d985eedf6423801219551f61", "tests/cb1/test_master_nlq_bound.py": "72db6453bb4b97ca2eb1497bc8c89ff548fd6b46f2722cab3ed5c26759b4f3e9", - "tests/cb1/test_mode_hold.py": "05f735f74d519f0a8c4d405a5b870d810571a798373161e0187cada1aab2832d", + "tests/cb1/test_mode_hold.py": "2418deee2eb1ab697af06eeaa900baaa2e4bac9bbb74f451eef28e5096dde0d9", "tests/cb1/test_stage.py": "951269a7645ec84bbc3dabbb13e84119a6c111d708929855a055002ea05aeb5e", "tests/cb1/test_dovi_selection_diagnostics.py": "c8a05988532140a4ecfd993ebc0124bb21f021bcf1419152c139590e67bce8fc", "tests/cb1/test_bluray_still_source.py": "db966bee9dbbd93f4dd0d4c2b9bcbfa21bb956328f310d87b449c314b195a8ef", @@ -214,9 +214,9 @@ "tests/cb1/test_bluray_navigation_drain.py": "1ffd4050d99c38b51d5d61b209ad9b4370a7c7af04c85844ca8c9fb8ba2ce1b8", "tests/cb1/test_bluray_video_window.py": "db8b191acece4e078689ad0c40c9bf3f8b4ade70a01b75250de3f2f740dac036", "tests/cb1/test_bluray_video_disposition.py": "5cc2b24a37319347270afdacc92f86534917725cff2e830b2b256153af614602", - "tests/cb1/test_decode_startup_diagnostics.py": "cbb5ac8150755df8a1e85f66b015a0a69ceb66bc5a32b7fb4a70c1c3bc169a4f", + "tests/cb1/test_decode_startup_diagnostics.py": "d76d2020744acd99577ddc72263f4777e2a89c6beaf2613faa5c5f6c3f3d6ba2", "tests/cb1/test_bluray_image_root.py": "f0a6a37b799d386cd28304a7b65adcc163f757ec7a44b4a6db5e3225af7e0dcb", - "tests/cb1/test_bluray_display_capabilities.py": "70805149f89fd3ab6b5640236fa31270954b0cf4052f1a6134bf845819901957", + "tests/cb1/test_bluray_display_capabilities.py": "0aa81084211675718ea3f3b805de83b2011634852e97d3efbc984de6ba08e747", "tests/cb1/test_bluray_bdj_capability.py": "c03f4d3b59e2f6d5ac0e76a356b468aca28475763f7427545790f12cf92d450e", "tests/cb1/test_bluray_navigation_open.py": "47be9a4f06b98f5e8430cb44ce2e54e5c8e46c16f5b590945b718e909bd58e65", "tests/cb1/test_bluray_subtitle_retirement.py": "9ff58dc4e6c2e79be7c948616e92f501849846850228a57a168320a4462048e2", @@ -267,20 +267,20 @@ "tests/cb1/test_libbluray_hardening.py": "635c48c9563ed3564e72136698084fb3d9d60ef724012edc929de7a5109e48bd", "tests/cb1/libbluray_sound.c": "1ca2f7984bec5d8c4ede87e253b40b7f059239d0d8527b9020dfb4ce15b82050", "tests/cb1/libbluray_bits.c": "daa983e9cda4a75e481fbcfea21f07c3127c2039dc6be1f1fc8c1690265b6afc", - "projects/Generic/linux/linux.x86_64.conf": "ea55e0eeb8e3268bd9be2c71aacf2981dc27e925bea8a98a3da903bbf899794e", + "projects/Generic/linux/linux.x86_64.conf": "674d2e8c339076a4f00adf0496a455f9c7ae4c3f0a2dcafe8948f0043db6f21d", "tests/cb1/test_cec_support.py": "e7e1f689ed0498366a25e43fdbc3cf1844c3bd77b2c0b8969db32c05bf4093b0", "docs/cb1/CEC.md": "77cd87903b98a066e7d157b24d010dd25c2858ec874dfc34b0174312d3de01cd", "docs/cb1/GBM-COLOUR-SETTINGS.md": "026865f9df4c00b716dbedf2ad6822c0f68d95d6c4bd4c5948240e45edccc8f0", "projects/Generic/patches/kodi/kodi-9996-gbm-colour-preferences.patch": "bbbce54a81ce00e459f60c3d2d2129e53325f04211267a851015ed404322936a", - "tests/cb1/gbm_colour_owner.cpp": "b750eae25d4fdc4c296c8458c5fdc604e7872d9bdf21ead50fc9082046a5bbda", + "tests/cb1/gbm_colour_owner.cpp": "bdc53ac0ba221e41038deb4ffcb914bb0fcbafbb0dd75c3c6777683bed18012f", "tests/cb1/gbm_colour_transition.cpp": "8acaee4e7d99350bccad52a9e46c0250c98c90ed79bfca3ad2117adce14037d4", - "tests/cb1/test_gbm_colour_owner.py": "7cd5f28b565aeb5b5a8fa863d57091ef17bce5b8d7b47ae0d299bb0a2a81703d", - "tests/cb1/test_gbm_colour_transition.py": "bebe89795baa7e470c3ae5e2e5e660e665641d86ac881823a2840c8f98069b5f", + "tests/cb1/test_gbm_colour_owner.py": "8cb86baa0011037764789c54fa266881efd11d31adbe312e8df63856a592f897", + "tests/cb1/test_gbm_colour_transition.py": "346aac7db58fee98fbda826b7e3d609172e96e7b32ca194781aa5c68869f13e9", "tests/cb1/test_hdr10plus_atomic.py": "783241ac78270e1896c4bf46ac3353d5d76658a7e9ac074a03ef6c91f9e7d9e8", "tests/cb1/test_native_render_receipt.py": "3eb513c09dafc2e6fe101f3b5c2b72b1e8fa014f9125698a0af8e7ff136010e8", "tests/cb1/test_ordinary_gui_transfer.py": "1e502440841fe984327ee172b5b1eaa29f26fedf176a3ec5911f4341530b2711", "projects/Generic/patches/kodi/kodi-9997-gbm-colour-buffer-lifetime.patch": "1cc1ba2c54ea1bae5915b30f60aa94433e5018501156010b2153a25f9945a08c", - "tests/cb1/gbm_colour_buffer.cpp": "f409310817293f383d64da4e2aced64ff452f54e1ac3f9692cce230443eb3615", + "tests/cb1/gbm_colour_buffer.cpp": "0d7281b511f4a9a69917974ffec74230c0b1d87090c730c3b7a3480bf65d6f27", "tests/cb1/test_gbm_colour_buffer.py": "ec923225bc98eb85b4e9d13c9ec24d53805cd3aada16cf35cfad7491785af3ee", "tests/cb1/test_source_chroma.py": "c33538c5dcc18656379116772f88dc6309a88f4e074a777a4be886f144162d07", "projects/Generic/filesystem/usr/share/kodi/media/cb1-glass.png": "1cd03200df33574d2cf1a0c5baac776cf8ad4fe623b62e202a22e9ed0961350b", @@ -291,7 +291,7 @@ "docs/superpowers/plans/2026-11-09-sdr-hlg-player-info.md": "932455791c9443ebe66e911b550ee33e1d40311fff694a40e15cbd17b8ace86a", "tests/cb1/test_sdr_hlg_routes.py": "e75d6534a7b7ae1cbac8b5c24efbd0c1951379e03a39059371577c120bb639d6", "tests/cb1/test_sdr_display_transition.py": "b963a22052a03cdd3d41761a34f2c7a4064607d3afaf80e09041d2a02ad40624", - "tests/cb1/test_sdr_gui_transfer.py": "e109d3b5064d4209ab49e6c755fe58aaa6cae0f8f520caadaa0c1cb299aee840", + "tests/cb1/test_sdr_gui_transfer.py": "927c361406e4b51aecbe5c9c777e9ff73abb75ae04302f194941894146f8a5ca", "projects/Generic/filesystem/usr/share/kodi/media/cb1-card.png": "d248cfeb28cdb4f96e58271ba284761a1bddc1b94ff90faad7f6d1998696e19b", "tests/cb1/test_process_info_skin_recovery.py": "6815868ef0f35491bd829ba6047044832fe7261fdacbc99aa44c64eb66ad96bc", "tests/cb1/test_async_output_admission.py": "50fbf4521a59d094d409123297c328f09bfc4e78b6a9b1b25d4af2a138ce09a8", @@ -311,26 +311,26 @@ "packages/mediacenter/kodi/cb1/src/dvbridge_policy.h": "560dbfb112f687461ef9f394d867188724dbbd74135329876325fde4cc793392", "packages/mediacenter/kodi/cb1/src/cb1_hdr10_ingress.c": "cb704114ed95ebc2d6c50aa410f71ec1eb1a74f6c94bfd18d66c09b0e1331032", "packages/mediacenter/kodi/cb1/src/dvbridge_policy.c": "372986bc8bacd0cb68ca4af440a0b255e2954b1f357cfe84a3fbb9199b8b561d", - "packages/mediacenter/kodi/cb1/config/owned-sources.json": "13ac6679cdab12ad76654db35cef6f8d7326fcb16da7cbbcc7553681020d8bfa", - "tests/cb1/test_diagnostics_runtime.py": "95ce20fb327621ec2676b28a137b641d1728b06b3edfe08998edcb43991d93e7", + "packages/mediacenter/kodi/cb1/config/owned-sources.json": "d4cec89fe7beebdb28620a1e1a126e0c6511ff6bc74470b4f38852f2a8d3e9e9", + "tests/cb1/test_diagnostics_runtime.py": "75efc9e92b934bfc2690a7e3b184d68a07bea8dfeffcd92b98a65d254bfa2232", "tests/cb1/test_fel_facts.py": "39717d8a179e5f2f71798f5a9382a6476aba23dfaf0047e7513387aaebc5461c", "packages/mediacenter/kodi/cb1/src/dvbridge_render.c": "c08a48036ce3ea5c082f54036a7def395cf44af859053a9998ea64bfe30bb4dc", "packages/mediacenter/kodi/cb1/src/cb1_circuit.h": "0257bdfe0ae6c0963b3dd91b0548e518e24e1ec46dba446222dff87cca113045", - "README.md": "557958a2ee5139ef01dd2448328a7e8262496c8f5029da5ee93e1a6380978d96", + "README.md": "ddf562a445a5cbad38d03ddd3a8ab2c35f0a5a582c45451d399be39daa18c4b3", "docs/cb1/README.md": "b8166be7406bafc10c001562fe67bf6406eeaa6e875c9a92a6f6d4ec334d31d1", "docs/cb1/RELEASE-RC4-PREVIEW-UPDATE3.md": "29c6368b9f8d424e3a56f0fddbfccc714b79762e1ba8a540d712e7f55781ebdb", "tests/cb1/test_sdr_capture_color.py": "8d49acfc46e627d12a3d073d6b550fb67d72ed0151f37fbcb1ddf5c0e7f491ef", - "tests/cb1/test_master_screenshot.py": "9cc89a63ff08af27f78ae4863163b2fd509552389925e9fd79ee09996a5317d6", + "tests/cb1/test_master_screenshot.py": "af7438014d42f5ae707fb2c7d0a61cecb7047e09ebfbdf6fd7ab87c4e10c483b", "tests/cb1/test_master_recovery.py": "171e6d9dc6644f578aabd9fca42ee9cf9ffeb01d87db4077fb9250002db32e6b", - "tests/cb1/test_native_spatial_contract.py": "6b2fac6fda998ec065ec5218077e35d7bcb822916bf6edcc407ab6baea9ac638", + "tests/cb1/test_native_spatial_contract.py": "f2ea5b3fa96e727500ae25fd0984422a710945a193b49bd2582f57c2ab7e70c2", "tests/cb1/test_vaapi_egl_probe.py": "1732ba41d1d9771b5e8de2570f3432bda2e82107c34570c6154bc239c166365e", "tests/cb1/test_frame_packing_gap.py": "b2b76548ad7a2f74db3d54233ea5929be494dbb85e256e06b1bb0a70612a8b32", "tests/cb1/test_sdr_native_surface.py": "228f351b42b5c0e2c4e7662e4a84cbf4e402cdd5f38196bd6809037571cdf601", "tests/cb1/test_process_info_pending.py": "018eda5214da1fec3caf2a772e198fb20fe74778f6a7bf9f9e3593d3e6b81b8f", "tests/cb1/test_native_video_telemetry.py": "c10e8392d2a917064aa75cc84e2344209c1529779ab111a1cd32585aaee40128", - "tests/cb1/test_sdr_live_settings.py": "e589520efc97458668fbf15f578636fd12f10586aad8fbcfb5f427c976999913", + "tests/cb1/test_sdr_live_settings.py": "b3b869704061203c77b874f343dd5e978fbfdd98f2d66c7adc1801263af2e7e4", "tests/cb1/test_sdr_applied_metadata.py": "828d531ee9d0c6418f7d600b4947691b51ce487b6265c1b3c2b7e67eacd5cf85", - "tests/cb1/test_output_supersession.py": "82f522f5366babde399c232dcbf4b8281d5b3e027ee9824b7183ddd7232a82c8", + "tests/cb1/test_output_supersession.py": "9828a78d552cb5defe8f629c2cef048f7b98c5887c78f40be5cb7f1b2d05bc31", "projects/Generic/patches/linux/linux-9943-intel-hdmi-scdc-diagnostics.patch": "5d6822eb4ddbada4c9751f6c0392d86eba93d55e531e60b7819e0f8a0afffc87", "tests/cb1/test_hdmi_scdc_diagnostics.py": "b82425e1906205f8e6d6685a634f3fa8b3c83def89660c13a7bb691f04612bd2", "projects/Generic/patches/linux/linux-9944-intel-hdmi-deferred-link-check.patch": "e73a5a3c32a8a83781dcf693bf6f096921526b910ab7373a17ddde8b62bb425b", @@ -343,7 +343,7 @@ "tests/cb1/test_sdr_direct_integration.py": "e4845b25655a02e42d0199e90878b4a1a7fab57d8b49594139bd80c9858d2bc1", "tests/cb1/test_sdr_render.py": "6c5cbdd57b424333a5e51ad87a82272e296318bfc5d4bcbc5171ef21d99bf258", "tests/cb1/sdr_direct_owners.cpp": "20f892bba6e379292998d3c031bc07552cda4dabc9aa793b781a7578b406a679", - "CB1/tests/gui_coverage_alpha.cpp": "a80d942dd1b705bdff7281ac48ba648e9a74847dff580054109eb6c58b175ad8", + "CB1/tests/gui_coverage_alpha.cpp": "f0e2113976cffe282fec7ce527ae09c8c7f0a45ee8f5979978ba682f36f5470e", "tests/cb1/process_info_structure.json": "e4fbec1933bc9d91b9fcc9bc3c630d43d99fc75292e69542aed6215a76c1b305", "tests/cb1/test_fel_upscaling.py": "6ca5c876fd82694a657e461f30d2a486d43898f243b789c31fc91ceef897fd13", "tests/cb1/test_gui_coverage_alpha.py": "54960062fc34c8220a558ac9df73c5ec801ff08c5f9476bd595148e8ad321d72", @@ -360,12 +360,12 @@ "packages/graphics/nvidia-pascal-modeset/patches/nvidia-pascal-modeset-9007-player-led-lab.patch": "a9ccc0f168cce398277c0f9f3652527b525b96da6e6a1d0d39aeb9567fab97d5", "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzz-lldv-format.patch": "30ac4d651d33e3db112681a1c2d936db9f3b21c1d6bf2a380ad09f262f2eca28", "projects/Generic/patches/linux/linux-9945-lldv-format-lab.patch": "b44fb2b3c825ee0ae4757c3e3df92d0ef2e9836b0813c5591e0bcc1b5fb38dc9", - "tests/cb1/test_lldv_format.py": "86b65567ab271959ed3ffc8cfe2c15ab7141477a7e87eef33425b187f349bb03", + "tests/cb1/test_lldv_format.py": "10cbf4013d755f72a3b8d9adbac1cadbe4d5fa0c9ffae70ce37057427ad7d935", "tests/cb1/test_lldv_player_info.py": "7303e656eb1852428b01d5fc5386c149461fd23948c80e8d754139edeeb8031e", "tests/cb1/test_pascal_hdr10_scanout.py": "d065254563c1a94c03d08cd24dd9c47a6269f868c741cc1dc67788c9e0fd6ed4", "tests/cb1/test_output_window_teardown.py": "e5927c0750c9544b44c6be08d307ac9dc2d0f5cfb691c6048be31f6e2126e987", "packages/graphics/nvidia-pascal-modeset/patches/nvidia-pascal-modeset-9008-optional-vsif-reference.patch": "5b1f0fea996844004f837559ce7acd714a23bbf5017a1cf12f1950c23bfceeb7", - "config/cb1-patch-index.json": "b3f061223d76db253c41633adc5bf2432156e79a81e91e97fd45b2d93c3d7ab9", + "config/cb1-patch-index.json": "6df9a0dce9012ae3f9c82b7113d5e67c8ce5cf3169d40511453153237b966569", "projects/Generic/patches/linux/linux-9948-intel-hdmi-ready-recovery.patch": "c10f4aa258ca6d2be95a175006389362ccfad3566cff1e892f0b162faf486780", "projects/Generic/patches/linux/linux-9970-rx550-native-dv.patch": "27964d48331d2e49380d1104c40e1e857d02a75671148ca206929a757f218b3b", "tests/cb1/test_bluray_overlay_order.py": "538775e911baa402d135669964fb31e021a121bf66ee06d95e1068777a9bf27c", @@ -448,13 +448,14 @@ "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-native-sdr-shader-colorimetry.patch": "415a293a2615900f7e32a3d72d6b43d7b4aa604020912e2c2d28ed3076332f2d", "projects/Generic/patches/kodi/kodi-9998-blur-label-dirty-region.patch": "ce5919154dec4d314318ea15ebfb59c5dbdabfad5484c96eebed25d1ab2fe5dc", "tests/cb1/test_blurred_label_region.py": "2f80f19b5b8e543e32f732c2cd607aed82e728c636687b4b0fca81baaf0a77bf", - "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hybrid-input-preference.patch": "513b41ff820c3dac3c59e74366e182cdd56d43e06976ce112b0cbf9ec25c3805", - "tests/cb1/test_hybrid_source_preference.py": "029283d430070226f4ca4adedf18d1b9e5fc18d56c7a4e36a9c9b61d8b90f954", + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hybrid-input-preference.patch": "20e56e02e1852a5a4f82b61ac475bb37c156b3aded2bf101a8e33e787d518a9f", + "tests/cb1/test_hybrid_source_preference.py": "f83f973c48a16869f0cc7d719cc7bd768068b289db8ef8b3f441182d44d92c76", "projects/Generic/patches/kodi/kodi-9998-background-playback.patch": "a3399f38cee9cbecd97d97f635f145b942807cca0979f959e7c46017a1b4ffd6", "projects/Generic/patches/kodi/kodi-9998-blur-font-style.patch": "a8c40d82c2fd2b2426feb79b1c9bf64f9a8477e5868f94c64964cae046e8fb23", "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-rejected-transport.patch": "7a0a7f1d79d73108fd6ed814480ac0dc3cf2428d460a392eb7ee70ebf71e55f6", - "projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch": "1d7e9547641029841c9cae4d2ff8c21841cf929b5e41e65a45f90c4a6a6e56b9", - "tests/cb1/test_intel_hdmi_pin_out.py": "726fd74c4a135d30705631b986792aafa171b1e08794627e93b83e063b5810fe", + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hdr10-fallback-mode.patch": "8b1db692fce5f47853dbdac5377f3df0f086771f5e43e6690b1158fe9b637fd0", + "projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch": "cc3fed08eb2e54a3f3ddc5e4ee666cfdfe052419b15ecae3e85a59352b8823e8", + "tests/cb1/test_intel_hdmi_pin_out.py": "1b540ed458e20d13a417632ee67109a55204d7286f63b1995a2208127b54427c", "tests/cb1/amd_dv_versions.c": "a1fbcb0d09bffd2523281ebe32bba1e132630aa4ffc70ce539272d4336593dec", "tests/cb1/test_amd_capability_diagnostics.py": "9e7a6ca7797070e86f83665c9cc267aa6f266c00cb5bbbec0074d823e7552478", "tests/cb1/test_vegam_transport.py": "3afbfe65d4d8357e2c51a847df9aa7fbd9b5d6d562aaec0276d042e6c9e252a8", @@ -477,7 +478,19 @@ "projects/Generic/patches/linux/linux-9977-amd-native-lldv-remaining.patch": "707b63dc296935c4ae3fa84cbe5ac8402b082726bbf663539824413656bc0e04", "tests/cb1/test_nvidia_native_lldv_formats.py": "796c7dbf1e20a06408026a4174a5e22c5cf33133b86965f34aab35227fa0468b", "projects/Generic/patches/linux/linux-9978-amd-native-lldv-y444.patch": "ac731ef8997b977dca1a06c319e1dda129f63581147500f079b7aed1dc8d5370", - "tests/cb1/test_amd_lldv_formats.py": "fb10e14e34ef3df637d6d9f1edcadb56b525247da9fc44205f2b43ad375132e8" + "tests/cb1/test_amd_lldv_formats.py": "fb10e14e34ef3df637d6d9f1edcadb56b525247da9fc44205f2b43ad375132e8", + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-startup-timing-fallback.patch": "6dc9b092664d1e2f9f2692bc1264b464167efc638a0bb6e887fce172bc36578c", + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-preserve-native-sdr-bt2020.patch": "951d25bc723b9322ee5881edb0cc570241dfd799e9a9fb9a56457a4dfe1ad165", + "CB1/tests/gui_final_hdr10.cpp": "1b53eb00e24ae9810b838f8fbbfebbda9d49c93d1538eece6176a9a975cc6020", + "projects/Generic/patches/kodi/kodi-9998-hdmi-dts-capability.patch": "c7aec078b96ce9dcf8b8418990ee2c552147c28b4a988a0ee267c8dc4eb13492", + "tests/cb1/test_alsa_hdmi_dts.py": "1ce66212dc04b075ed74c3e089acd38c176320c6991ea1cf53bb216f4cd5340e", + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-reuse-gbm-front-buffer.patch": "fb6816dc55ed91ad35747f4c7a7ffd76d20d16427ce7e2dbf3101e4cf14b172a", + "tests/cb1/test_gbm_front_buffer.py": "45e7e92170798d801dac03e0decd2bf47b860d75b115bc9063c43f5d4b191f52", + "projects/Generic/patches/linux/0103-wifi-mt76-mt7925-keep-join-roc-until-authorized.patch": "69765cc5aba260fdf236945818815bc102a20426ec35d29f4a7519a187225b2d", + "projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-logical-video-screenshot.patch": "3f9b1186d7089d24c1720c9481ed6903f8e17a4b7d7372e86274d52dda2e9362", + "projects/Generic/patches/linux/0104-wifi-mt76-mt7925-track-join-roc-ownership.patch": "959074567d193b64107070207fce565164f1cae63df2dea1f37eee93438e8d9f", + "tests/cb1/test_mt7925_roc.py": "ebd1df398e41d912fc018d97b269ffa2b11ac10fb1d9ef79ce89ebdaa5426cf9", + "tests/cb1/mt7925_roc.c": "0f4154d64644eeed97fe50e71a1d5b69c47c278e444a132c7133eb42bd5dee69" }, "staging": { "projects/Generic/patches/ffmpeg/ffmpeg-9900-04-ts-dovi-layer.patch": { @@ -618,11 +631,11 @@ }, "packages/mediacenter/kodi/cb1/src/dvbridge_fel.c": { "source": "src/dvbridge_fel.c", - "sha256": "7b291b3509f393a239a604b4e70c8d7323c725391e548264dd5dc8dc55859d0f" + "sha256": "d3a129feffdd0a858ee15469c334aef51323e508b61337024c47c08bce4461ac" }, "packages/mediacenter/kodi/cb1/src/dvbridge_fel.h": { "source": "src/dvbridge_fel.h", - "sha256": "2986af5b358c4692a9e804e6fccd13c05dfed88722b401e3f061b516f9cce517" + "sha256": "fa744fa8e4b8f4a0ee1eb364351dfc56cde0b975074fd0e3f57635793b5b424f" }, "packages/mediacenter/kodi/cb1/src/dvbridge_fel_seek.h": { "source": "src/dvbridge_fel_seek.h", @@ -718,7 +731,7 @@ }, "packages/mediacenter/kodi/cb1/config/owned-sources.json": { "source": "config/owned-sources.json", - "sha256": "13ac6679cdab12ad76654db35cef6f8d7326fcb16da7cbbcc7553681020d8bfa" + "sha256": "d4cec89fe7beebdb28620a1e1a126e0c6511ff6bc74470b4f38852f2a8d3e9e9" }, "packages/mediacenter/kodi/cb1-model/contract/cb1_l1l3_bundle.h": { "source": "models/l1l3/contract/cb1_l1l3_bundle.h", diff --git a/packages/linux-firmware/kernel-firmware/firmwares/x86_64.dat b/packages/linux-firmware/kernel-firmware/firmwares/x86_64.dat index 45ed61bb41..8d9fb9b2eb 100644 --- a/packages/linux-firmware/kernel-firmware/firmwares/x86_64.dat +++ b/packages/linux-firmware/kernel-firmware/firmwares/x86_64.dat @@ -7,6 +7,7 @@ qca/*00000302.bin qca/*00190200.bin mediatek/*MT7961*.bin mediatek/*MT7922*.bin +mediatek/mt7925/*.bin rt2561.bin rt2561s.bin rt2661.bin diff --git a/packages/mediacenter/kodi/cb1/config/owned-sources.json b/packages/mediacenter/kodi/cb1/config/owned-sources.json index f6fb6506ae..009807b9f6 100644 --- a/packages/mediacenter/kodi/cb1/config/owned-sources.json +++ b/packages/mediacenter/kodi/cb1/config/owned-sources.json @@ -1,5 +1,5 @@ { - "src/dvbridge_fel.c": "7b291b3509f393a239a604b4e70c8d7323c725391e548264dd5dc8dc55859d0f", + "src/dvbridge_fel.c": "d3a129feffdd0a858ee15469c334aef51323e508b61337024c47c08bce4461ac", "src/dvbridge_gl_pack.h": "2ccd974503fbcbb33678ee2eff076a7a086bcd1796efa97010a1eebb901143f5", "src/dvbridge_gl_pack.c": "e872527f20d4e56c1da39a1d591c829bc54174ad8fb2fa94c61cfe2a0043d996", "src/cb1_circuit.c": "b3dc96ad27a802680811858862f67c4921f595ce042e3df6cd19c286f8872e56", @@ -63,7 +63,7 @@ "src/cb1_trim_math.h": "178b7ef0b567b61c7d73cea702971b10299a04931367c090be0a3c8561c8cfcc", "src/cb1_transport_glsl.h": "1d775ef6306e76a831fc192ef9c7b7989fef97cb5c001903f2ab674e89445566", "src/cb1_composite_glsl.h": "65e462c80246b0e44ecf31f5f957a53cc48dd9924009b3461cd008fbdc124916", - "src/dvbridge_fel.h": "2986af5b358c4692a9e804e6fccd13c05dfed88722b401e3f061b516f9cce517", + "src/dvbridge_fel.h": "fa744fa8e4b8f4a0ee1eb364351dfc56cde0b975074fd0e3f57635793b5b424f", "src/cb1_master_ipt.c": "2793976a1a49187658ab0c6f3eb4c3cdce056b61497ac2939612c4bba49b5ea6", "src/cb1_master_ipt.h": "3efb1f79bf2340c10ada773267b792b5d5e33256e7ae73055b19f80fdb5a3ae1", "src/cb1_master_ipt_shader.h": "92e41f052f975a44bb3404a5ec8f44380729b070507af918c40f40d52f446e95", diff --git a/packages/mediacenter/kodi/cb1/src/dvbridge_fel.c b/packages/mediacenter/kodi/cb1/src/dvbridge_fel.c index 713bd3ce8d..9dc91f5c9d 100644 --- a/packages/mediacenter/kodi/cb1/src/dvbridge_fel.c +++ b/packages/mediacenter/kodi/cb1/src/dvbridge_fel.c @@ -593,13 +593,23 @@ static bool submit(struct dvbridge_fel *f, const AVPacket *packet, if (result == AVERROR(EAGAIN)) { if (source && !received_enhancement && source->enhancement_pts != AV_NOPTS_VALUE) goto fail; - if (!source && !received_enhancement)f->epoch_uncertain = true; + if (!source && !received_enhancement) + f->epoch_uncertain = true; + if (!source && f->synchronizing) { + /* All EL from this AU has been examined. Before the + * first accepted anchor these BL identities are preroll. */ + f->num_times = 0; + if (++f->preroll_packets > 1024) + goto fail; + } return true; /* Submit EL when a decoded BL requests its matching picture. */ } goto fail; } const unsigned limit = f->mel_deferred ? MEL_PACKET_MAX : QUEUE_MAX; - if (f->mel_deferred && !f->el_started && + /* A renewed base decoder may accept more input before returning a + * picture. Give queued EL a chance to decode before rejecting the AU. */ + if ((!f->source_timed || (f->mel_deferred && !f->el_started)) && (f->num_packets >= limit || (size_t)copy->size > PACKET_BYTES_MAX - f->packet_bytes)) if (!pump(f)) { av_packet_free(©); @@ -670,9 +680,6 @@ static bool submit(struct dvbridge_fel *f, const AVPacket *packet, * time. Never use this shortcut for a BL with reordered pictures. */ if (!common_key && !el_idr) { av_packet_free(©); - f->num_times = 0; - if (++f->preroll_packets > 1024) - goto fail; continue; } f->anchor_pts = packet->pts; @@ -698,11 +705,15 @@ bool dvbridge_fel_submit_source(struct dvbridge_fel *f, const AVPacket *packet, return source && submit(f, packet, source); } -bool dvbridge_fel_drain(struct dvbridge_fel *f) +bool dvbridge_fel_drain(struct dvbridge_fel *f, const char **reason) { + if (reason) + *reason = NULL; if (!f) return false; if (f->synchronizing) { + if (reason && !f->failed && f->base_order.seen && !f->enhancement_order.seen) + *reason = "no enhancement video received before drain"; f->failed = true; return false; /* EOF cannot supply the missing random-access picture. */ } diff --git a/packages/mediacenter/kodi/cb1/src/dvbridge_fel.h b/packages/mediacenter/kodi/cb1/src/dvbridge_fel.h index dab40edfa7..d62ec2d17e 100644 --- a/packages/mediacenter/kodi/cb1/src/dvbridge_fel.h +++ b/packages/mediacenter/kodi/cb1/src/dvbridge_fel.h @@ -22,7 +22,8 @@ struct dvbridge_fel_source { }; bool dvbridge_fel_submit_source(struct dvbridge_fel *fel, const AVPacket *packet, const struct dvbridge_fel_source *source); -bool dvbridge_fel_drain(struct dvbridge_fel *fel); +/* Optional reason is set only when the final drain identifies a specific fault. */ +bool dvbridge_fel_drain(struct dvbridge_fel *fel, const char **reason); /* 1: exact pair, 0: need input, 2: discard preroll, -1: missing pair / failure. */ int dvbridge_fel_take(struct dvbridge_fel *fel, int64_t pts, AVFrame **frame); /* Disc playback may return 3 for a matched, validated RPU that needs no residual. diff --git a/projects/Generic/linux/7.2.6/linux.x86_64.conf b/projects/Generic/linux/7.2.6/linux.x86_64.conf index a934c5f592..df8c0a4a62 100644 --- a/projects/Generic/linux/7.2.6/linux.x86_64.conf +++ b/projects/Generic/linux/7.2.6/linux.x86_64.conf @@ -2814,8 +2814,9 @@ CONFIG_MT7921E=m # CONFIG_MT7921S is not set CONFIG_MT7921U=m # CONFIG_MT7996E is not set +CONFIG_MT7925_COMMON=m # CONFIG_MT7925E is not set -# CONFIG_MT7925U is not set +CONFIG_MT7925U=m CONFIG_WLAN_VENDOR_MICROCHIP=y # CONFIG_WILC1000_SDIO is not set # CONFIG_WLAN_VENDOR_PURELIFI is not set diff --git a/projects/Generic/linux/linux.x86_64.conf b/projects/Generic/linux/linux.x86_64.conf index be035b1125..b4778dd55e 100644 --- a/projects/Generic/linux/linux.x86_64.conf +++ b/projects/Generic/linux/linux.x86_64.conf @@ -2813,8 +2813,9 @@ CONFIG_MT7921E=m # CONFIG_MT7921S is not set CONFIG_MT7921U=m # CONFIG_MT7996E is not set +CONFIG_MT7925_COMMON=m # CONFIG_MT7925E is not set -# CONFIG_MT7925U is not set +CONFIG_MT7925U=m CONFIG_WLAN_VENDOR_MICROCHIP=y # CONFIG_WILC1000_SDIO is not set # CONFIG_WLAN_VENDOR_PURELIFI is not set diff --git a/projects/Generic/patches/kodi/kodi-9998-hdmi-dts-capability.patch b/projects/Generic/patches/kodi/kodi-9998-hdmi-dts-capability.patch new file mode 100644 index 0000000000..766e664684 --- /dev/null +++ b/projects/Generic/patches/kodi/kodi-9998-hdmi-dts-capability.patch @@ -0,0 +1,249 @@ +diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp +index 486a42a..bb58c10 100644 +--- a/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp ++++ b/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp +@@ -1385,6 +1385,7 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev + CAEDeviceInfo info; + info.m_deviceName = device; + info.m_deviceType = AEDeviceTypeFromName(device); ++ AEELDDtsCapabilities dts{true, true}; + + if (cardNr >= 0) + { +@@ -1444,7 +1445,7 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev + controlMonitor->Add(strHwName, SND_CTL_ELEM_IFACE_PCM, dev, "ELD"); + #endif + +- if (!GetELD(hctl, dev, info, badHDMI)) ++ if (!GetELD(hctl, dev, info, badHDMI, dts)) + CLog::Log(LOGDEBUG, + "CAESinkALSA - Unable to obtain ELD information for device \"{}\" (not " + "supported by device, or kernel older than 3.2)", +@@ -1601,14 +1602,20 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev + + if (info.m_deviceType == AE_DEVTYPE_HDMI) + { +- // we don't trust ELD information and push back our supported formats explicitly ++ // Use complete HDMI ELD for DTS and keep the legacy list for other codecs. + info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_AC3); +- info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTSHD); +- info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTSHD_MA); +- info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTSHD_CORE); +- info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTS_1024); +- info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTS_2048); +- info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTS_512); ++ if (dts.hd) ++ { ++ info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTSHD); ++ info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTSHD_MA); ++ } ++ if (dts.core) ++ { ++ info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTSHD_CORE); ++ info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTS_1024); ++ info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTS_2048); ++ info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_DTS_512); ++ } + info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_EAC3); + info.m_streamTypes.push_back(CAEStreamInfo::STREAM_TYPE_TRUEHD); + +@@ -1621,7 +1628,11 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev + list.push_back(info); + } + +-bool CAESinkALSA::GetELD(snd_hctl_t *hctl, int device, CAEDeviceInfo& info, bool& badHDMI) ++bool CAESinkALSA::GetELD(snd_hctl_t* hctl, ++ int device, ++ CAEDeviceInfo& info, ++ bool& badHDMI, ++ AEELDDtsCapabilities& dts) + { + badHDMI = false; + +@@ -1664,11 +1675,8 @@ bool CAESinkALSA::GetELD(snd_hctl_t *hctl, int device, CAEDeviceInfo& info, bool + if (!dataLength) + badHDMI = true; + else +- CAEELDParser::Parse( +- (const uint8_t*)snd_ctl_elem_value_get_bytes(control), +- dataLength, +- info +- ); ++ dts = CAEELDParser::Parse(static_cast(snd_ctl_elem_value_get_bytes(control)), ++ dataLength, info).value_or(dts); + + info.m_deviceType = AE_DEVTYPE_HDMI; + return true; +diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkALSA.h b/xbmc/cores/AudioEngine/Sinks/AESinkALSA.h +index 90c5321..2952ebe 100644 +--- a/xbmc/cores/AudioEngine/Sinks/AESinkALSA.h ++++ b/xbmc/cores/AudioEngine/Sinks/AESinkALSA.h +@@ -16,6 +16,8 @@ + + #include + ++struct AEELDDtsCapabilities; ++ + #define AE_MIN_PERIODSIZE 256 + + class CAESinkALSA : public IAESink +@@ -93,7 +95,11 @@ private: + static std::string GetParamFromName(const std::string &name, const std::string ¶m); + static void EnumerateDevice(AEDeviceInfoList &list, const std::string &device, const std::string &description, snd_config_t *config); + static bool SoundDeviceExists(const std::string& device); +- static bool GetELD(snd_hctl_t *hctl, int device, CAEDeviceInfo& info, bool& badHDMI); ++ static bool GetELD(snd_hctl_t* hctl, ++ int device, ++ CAEDeviceInfo& info, ++ bool& badHDMI, ++ AEELDDtsCapabilities& dts); + + static void sndLibErrorHandler(const char *file, int line, const char *function, int err, const char *fmt, ...); + }; +diff --git a/xbmc/cores/AudioEngine/Utils/AEELDParser.cpp b/xbmc/cores/AudioEngine/Utils/AEELDParser.cpp +index 345c4f1..e0d67c8 100644 +--- a/xbmc/cores/AudioEngine/Utils/AEELDParser.cpp ++++ b/xbmc/cores/AudioEngine/Utils/AEELDParser.cpp +@@ -12,6 +12,7 @@ + #include "utils/EndianSwap.h" + + #include ++#include + #include + #include + #include +@@ -21,7 +22,7 @@ + typedef struct + { + uint8_t eld_ver; +- uint8_t baseline_eid_len; ++ uint8_t baseline_eld_len; + uint8_t cea_edid_ver; + uint8_t monitor_name_length; + uint8_t sad_count; +@@ -42,7 +43,7 @@ typedef struct + std::string monitor_name; + } ELDHeader; + +-#define ELD_VER_CEA_816D 2 ++#define ELD_VER_CEA_861D 2 + #define ELD_VER_PARTIAL 31 + + #define ELD_EDID_VER_NONE 0 +@@ -72,14 +73,20 @@ typedef struct + #define CEA_861_FORMAT_WMAPRO 14 + #define CEA_861_FORMAT_RESERVED2 15 + +-void CAEELDParser::Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info) ++std::optional CAEELDParser::Parse(const uint8_t* data, ++ size_t length, ++ CAEDeviceInfo& info) + { ++ constexpr size_t ELD_FIXED_BYTES = 20; ++ if (length < ELD_FIXED_BYTES) ++ return std::nullopt; ++ + ELDHeader header; + header.eld_ver = (data[0 ] & 0xF8) >> 3; +- if (header.eld_ver != ELD_VER_CEA_816D && header.eld_ver != ELD_VER_PARTIAL) +- return; ++ if (header.eld_ver != ELD_VER_CEA_861D && header.eld_ver != ELD_VER_PARTIAL) ++ return std::nullopt; + +- header.baseline_eid_len = data[2 ]; ++ header.baseline_eld_len = data[2 ]; + header.cea_edid_ver = (data[4 ] & 0xE0) >> 5; + header.monitor_name_length = data[4 ] & 0x1F; + header.sad_count = (data[5 ] & 0xF0) >> 4; +@@ -101,6 +108,10 @@ void CAEELDParser::Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info + header.mfg_name[3] = '\0'; + header.product_code = Endian_SwapLE16(*((const uint16_t*)(data + 18))); + ++ const size_t sadStart = ELD_FIXED_BYTES + header.monitor_name_length; ++ if (sadStart > length) ++ return std::nullopt; ++ + switch (header.conn_type) + { + case ELD_CONN_TYPE_HDMI: info.m_deviceType = AE_DEVTYPE_HDMI; break; +@@ -110,9 +121,9 @@ void CAEELDParser::Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info + info.m_displayNameExtra = header.mfg_name; + if (header.monitor_name_length <= 16) + { +- header.monitor_name.assign((const char *)(data + 20), header.monitor_name_length); ++ header.monitor_name.assign((const char*)(data + ELD_FIXED_BYTES), header.monitor_name_length); + header.monitor_name.erase(std::find_if(header.monitor_name.rbegin(), header.monitor_name.rend(), +- [](char c) { return !std::isspace(c); }) ++ [](unsigned char c) { return !std::isspace(c); }) + .base(), + header.monitor_name.end()); + if (!header.monitor_name.empty()) +@@ -170,13 +181,26 @@ void CAEELDParser::Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info + info.m_channels += AE_CH_BROC; + } + +- const uint8_t *sad = data + 20 + header.monitor_name_length; +- for(uint8_t i = 0; i < header.sad_count; ++i) ++ const size_t sadEnd = sadStart + 3 * header.sad_count; ++ if (sadEnd > length) ++ return std::nullopt; ++ ++ // Baseline length excludes the four-byte header and is measured in words. ++ const size_t baselineBytes = 4 + 4 * header.baseline_eld_len; ++ // A filled four-bit SAD count may have lost descriptors from the EDID. ++ bool complete = header.eld_ver == ELD_VER_CEA_861D && ++ header.conn_type == ELD_CONN_TYPE_HDMI && ++ header.cea_edid_ver >= ELD_EDID_VER_CEA_861 && ++ header.cea_edid_ver <= ELD_EDID_VER_CEA_861_BCD && header.monitor_name_length <= 16 && ++ header.sad_count > 0 && header.sad_count < 15 && sadEnd <= baselineBytes && baselineBytes <= length; ++ AEELDDtsCapabilities dts{}; ++ for (size_t offset = sadStart; offset < sadEnd; offset += 3) + { +- uint8_t offset = i * 3; +- uint8_t formatCode = (sad[offset + 0] >> 3) & 0xF; +- //uint8_t channelCount = (sad[offset + 0] & 0x7) + 1; +- //uint8_t sampleRates = sad[offset + 1]; ++ const uint8_t formatCode = (data[offset] >> 3) & 0xF; ++ if (formatCode == CEA_861_FORMAT_RESERVED1 || !(data[offset + 1] & 0x7F)) ++ complete = false; ++ dts.core |= formatCode == CEA_861_FORMAT_DTS; ++ dts.hd |= formatCode == CEA_861_FORMAT_DTSHD; + + AEDataFormat fmt = AE_FMT_INVALID; + switch (formatCode) +@@ -196,4 +220,8 @@ void CAEELDParser::Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info + if (std::ranges::find(info.m_dataFormats, fmt) == info.m_dataFormats.end()) + info.m_dataFormats.push_back(fmt); + } ++ ++ if (!complete) ++ return std::nullopt; ++ return dts; + } +diff --git a/xbmc/cores/AudioEngine/Utils/AEELDParser.h b/xbmc/cores/AudioEngine/Utils/AEELDParser.h +index 1e8bfb1..c124036 100644 +--- a/xbmc/cores/AudioEngine/Utils/AEELDParser.h ++++ b/xbmc/cores/AudioEngine/Utils/AEELDParser.h +@@ -9,12 +9,21 @@ + #pragma once + + #include ++#include + #include + + class CAEDeviceInfo; + ++struct AEELDDtsCapabilities ++{ ++ bool core; ++ bool hd; ++}; ++ + class CAEELDParser { + public: +- static void Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info); ++ static std::optional Parse(const uint8_t* data, ++ size_t length, ++ CAEDeviceInfo& info); + }; + diff --git a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-preserve-native-sdr-bt2020.patch b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-preserve-native-sdr-bt2020.patch new file mode 100644 index 0000000000..4f3818edac --- /dev/null +++ b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-preserve-native-sdr-bt2020.patch @@ -0,0 +1,792 @@ +Subject: [PATCH] GBM: preserve native SDR BT.2020 when the HDMI link supports it + +--- a/system/shaders/GL/1.5/gl_gui_composite.frag ++++ b/system/shaders/GL/1.5/gl_gui_composite.frag +@@ -11,6 +11,7 @@ + in vec2 v_tex; + out vec4 fragColor; + uniform sampler2D u_samp; ++uniform bool u_sdrBT2020; + uniform float u_sdrPeak; // SDR peak in normalized PQ (e.g. 100/10000 = 0.01) + + // ST2084 (PQ) constants +@@ -43,26 +44,25 @@ + if (gui.a == 0.0) + discard; + +- // sRGB -> linear (IEC 61966-2-1 piecewise EOTF) +- vec3 linear = mix(gui.rgb / 12.92, +- pow((gui.rgb + 0.055) / 1.055, vec3(2.4)), +- step(0.04045, gui.rgb)); ++ // Native SDR stores true coverage and premultiplied sRGB in its GUI FBO. ++ // Convert straight colors and pass coverage to the final SRC_ALPHA blend. ++ vec3 rgb = u_sdrBT2020 ? clamp(gui.rgb / gui.a, 0.0, 1.0) : gui.rgb; ++ vec3 linear = mix(rgb / 12.92, ++ pow((rgb + 0.055) / 1.055, vec3(2.4)), ++ step(0.04045, rgb)); + + // BT.709 -> BT.2020 gamut mapping + linear = bt709_to_bt2020 * linear; + +- // scale to PQ luminance range: SDR content at u_sdrPeak of 10000 nits +- linear *= u_sdrPeak; +- +- // linear -> PQ +- vec3 pq = forwardPQ(linear); ++ vec3 result = u_sdrBT2020 ? pow(max(linear, vec3(0.0)), vec3(1.0 / 2.4)) : ++ forwardPQ(linear * u_sdrPeak); + + // Limited-range encoding at the BO write boundary. Canonical normalized + // ratios (bit-depth-agnostic in float space; BO write quantizes to the + // active surface bit depth). + #ifdef KODI_LIMITED_RANGE +- pq = pq * ((235.0 - 16.0) / 255.0) + (16.0 / 255.0); ++ result = result * ((235.0 - 16.0) / 255.0) + (16.0 / 255.0); + #endif + +- fragColor = vec4(pq, gui.a); ++ fragColor = vec4(result, gui.a); + } +--- a/system/shaders/GLES/2.0/gles_gui_composite.frag ++++ b/system/shaders/GLES/2.0/gles_gui_composite.frag +@@ -16,6 +16,7 @@ + uniform highp float u_ootfGamma; // HLG OOTF or negative SDR target gamma + // PQ: 0.0 (use LUT path instead) + uniform bool u_sdrBT2020; ++uniform bool u_unpremultiplyGui; + uniform bool u_inputPQ; // CB1 subtitle layer already contains BT.2020 PQ. + uniform highp vec2 u_outputRange; // CB1 exact bit-depth scale and black code. + uniform highp float u_playerLedScale; +@@ -53,11 +54,13 @@ + return; + } + ++ // Convert the native SDR GUI's straight colors before the final SRC_ALPHA blend. ++ highp vec3 rgb = u_unpremultiplyGui ? clamp(gui.rgb / gui.a, 0.0, 1.0) : gui.rgb; + // sRGB -> linear via LUT (IEC 61966-2-1 EOTF, replaces inline pow) + highp vec3 linear = vec3( +- texture2D(u_lutDegamma, vec2(gui.r, 0.5)).r, +- texture2D(u_lutDegamma, vec2(gui.g, 0.5)).r, +- texture2D(u_lutDegamma, vec2(gui.b, 0.5)).r ++ texture2D(u_lutDegamma, vec2(rgb.r, 0.5)).r, ++ texture2D(u_lutDegamma, vec2(rgb.g, 0.5)).r, ++ texture2D(u_lutDegamma, vec2(rgb.b, 0.5)).r + ); + + if (u_playerLedScale > 0.0) +--- a/xbmc/guilib/GUIFontTTFGL.cpp ++++ b/xbmc/guilib/GUIFontTTFGL.cpp +@@ -140,7 +140,7 @@ + // alpha blend that approximately matches SDR perceived translucency. It + // is a "close enough" compromise; a mathematically correct fix would + // require linear-light compositing (too expensive on typical ARM GPUs). +- if (CServiceBroker::GetWinSystem()->IsHdrComposite()) ++ if (!CServiceBroker::GetWinSystem()->UseGuiCoverageAlpha()) + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + else + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); +--- a/xbmc/guilib/GUITextureGL.cpp ++++ b/xbmc/guilib/GUITextureGL.cpp +@@ -93,7 +93,7 @@ + // coverage alpha; HDR FBO composite uses a compensated squared-alpha + // blend because the FBO is color-transformed to PQ before composite, + // and alpha blending in non-linear space is mathematically wrong. +- if (CServiceBroker::GetWinSystem()->IsHdrComposite()) ++ if (!CServiceBroker::GetWinSystem()->UseGuiCoverageAlpha()) + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, + GL_ONE_MINUS_SRC_ALPHA); + else +@@ -282,7 +282,10 @@ + + if (blending) + { +- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ++ if (CServiceBroker::GetWinSystem()->UsesNativeSDRBT2020()) ++ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); ++ else ++ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + } + else +--- a/xbmc/guilib/GUITextureGLES.cpp ++++ b/xbmc/guilib/GUITextureGLES.cpp +@@ -295,7 +295,10 @@ + + if (blending) + { +- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ++ if (CServiceBroker::GetWinSystem()->UsesNativeSDRBT2020()) ++ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); ++ else ++ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + } + else +--- a/xbmc/rendering/RenderSystem.h ++++ b/xbmc/rendering/RenderSystem.h +@@ -56,6 +56,7 @@ + virtual bool ResetRenderSystem(int width, int height) = 0; + + virtual bool BeginRender() = 0; ++ virtual void UpdateGUIShaderColorState() {} + virtual bool EndRender() = 0; + virtual void PresentRender(bool rendered, bool videoLayer) = 0; + virtual void InvalidateColorBuffer() {} +--- a/xbmc/rendering/gl/RenderSystemGL.cpp ++++ b/xbmc/rendering/gl/RenderSystemGL.cpp +@@ -263,7 +263,12 @@ + return false; + + m_GUIElementCount = 0; ++ UpdateGUIShaderColorState(); ++ return true; ++} + ++void CRenderSystemGL::UpdateGUIShaderColorState() ++{ + bool useLimited = CServiceBroker::GetWinSystem()->UseLimitedColor() && + !CServiceBroker::GetWinSystem()->IsHdrComposite(); + +@@ -274,7 +279,6 @@ + } + + m_limitedColorRange = useLimited; +- return true; + } + + bool CRenderSystemGL::EndRender() +--- a/xbmc/rendering/gl/RenderSystemGL.h ++++ b/xbmc/rendering/gl/RenderSystemGL.h +@@ -73,6 +73,7 @@ + bool ResetRenderSystem(int width, int height) override; + + bool BeginRender() override; ++ void UpdateGUIShaderColorState() override; + bool EndRender() override; + void PresentRender(bool rendered, bool videoLayer) override; + void InvalidateColorBuffer() override; +--- a/xbmc/rendering/gles/RenderSystemGLES.cpp ++++ b/xbmc/rendering/gles/RenderSystemGLES.cpp +@@ -177,7 +177,12 @@ + return false; + + m_GUIElementCount = 0; ++ UpdateGUIShaderColorState(); ++ return true; ++} + ++void CRenderSystemGLES::UpdateGUIShaderColorState() ++{ + const bool useLimited = CServiceBroker::GetWinSystem()->UseLimitedColor() && + !CServiceBroker::GetWinSystem()->IsHdrComposite(); + const bool usePQ = CServiceBroker::GetWinSystem()->GetGfxContext().IsTransferPQ(); +@@ -191,8 +196,6 @@ + + InitialiseShaders(); + } +- +- return true; + } + + bool CRenderSystemGLES::EndRender() +--- a/xbmc/rendering/gles/RenderSystemGLES.h ++++ b/xbmc/rendering/gles/RenderSystemGLES.h +@@ -93,6 +93,7 @@ + bool ResetRenderSystem(int width, int height) override; + + bool BeginRender() override; ++ void UpdateGUIShaderColorState() override; + bool EndRender() override; + void PresentRender(bool rendered, bool videoLayer) override; + void InvalidateColorBuffer() override; +--- a/xbmc/rendering/gles/GuiCompositeShaderGLES.h ++++ b/xbmc/rendering/gles/GuiCompositeShaderGLES.h +@@ -22,7 +22,11 @@ + + void SetProjection(const GLfloat* proj) { m_proj = proj; } + void SetInputPQ(bool value) { m_inputPQ = value; } +- void SetSDRBT2020(bool value) { m_sdrBT2020 = value; } ++ void SetSDRBT2020(bool value, bool premultiplied = false) ++ { ++ m_sdrBT2020 = value; ++ m_unpremultiplyGui = premultiplied; ++ } + void SetOutputRange(float scale, float offset) { m_outputScale = scale; m_outputOffset = offset; } + + bool CreateLUTs(int colorTransfer, float sdrGamma = 2.4f); +@@ -57,7 +61,7 @@ + GLuint m_lutDegammaTexId{0}; + GLuint m_lutTFTexId{0}; + float m_ootfGamma{0.0f}; +- bool m_inputPQ{false}, m_sdrBT2020{false}; ++ bool m_inputPQ{false}, m_sdrBT2020{false}, m_unpremultiplyGui{false}; + float m_outputScale{1.0f}, m_outputOffset{0.0f}; + + GLint m_hPos{-1}; +@@ -67,7 +71,7 @@ + GLint m_hLutTF{-1}; + GLint m_hProj{-1}; + GLint m_hOotfGamma{-1}; +- GLint m_hInputPQ{-1}, m_hSDRBT2020{-1}; ++ GLint m_hInputPQ{-1}, m_hSDRBT2020{-1}, m_hUnpremultiplyGui{-1}; + GLint m_hOutputRange{-1}; + GLint m_hPlayerLedScale{-1}, m_hPlayerLedGui{-1}, m_hPlayerLedSubtitles{-1}; + float m_playerLedScale{}; +--- a/xbmc/application/Application.cpp ++++ b/xbmc/application/Application.cpp +@@ -935,7 +935,7 @@ + CServiceBroker::GetGUI()->GetWindowManager().HasDirtyRegions())) + m_skipGuiRender = false; + const bool guiWillRender = appPower->GetRenderGUI() && !m_skipGuiRender; +- bool compositing = CServiceBroker::GetWinSystem()->BeginGuiComposite(guiWillRender); ++ bool compositing = CServiceBroker::GetWinSystem()->BeginFrameGuiComposite(guiWillRender); + + if (guiWillRender) + { +--- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp +@@ -1014,6 +1014,7 @@ + // create regular progressive scan shader + // if single pass, create GLSLOutput helper and pass it to YUV2RGB shader + EShaderFormat shaderFormat = GetShaderFormat(); ++ const auto dstPrimaries = m_passthroughHDR || m_shaderSDRBT2020 ? m_srcPrimaries : AVCOL_PRI_BT709; + std::shared_ptr out; + m_toneMapMethod = m_videoSettings.m_ToneMapMethod; + if (m_renderQuality == RQ_SINGLEPASS) +@@ -1027,7 +1028,7 @@ + { + m_pYUVShader = new YUV2RGBFilterShader4( + m_textureTarget == GL_TEXTURE_RECTANGLE, shaderFormat, m_nonLinStretch, +- m_passthroughHDR ? m_srcPrimaries : AVColorPrimaries::AVCOL_PRI_BT709, m_srcPrimaries, ++ dstPrimaries, m_srcPrimaries, + m_toneMap, m_toneMapMethod, m_scalingMethod, out); + if (!m_cmsOn) + m_pYUVShader->SetConvertFullColorRange(m_fullRange); +@@ -1053,7 +1054,7 @@ + m_pYUVShader = new YUV2RGBProgressiveShader( + m_textureTarget == GL_TEXTURE_RECTANGLE, shaderFormat, + m_nonLinStretch && m_renderQuality == RQ_SINGLEPASS, +- m_passthroughHDR ? m_srcPrimaries : AVColorPrimaries::AVCOL_PRI_BT709, m_srcPrimaries, ++ dstPrimaries, m_srcPrimaries, + m_toneMap, m_toneMapMethod, out, + m_intermediateGammaCorrection && m_renderQuality == RQ_MULTIPASS); + +@@ -1117,7 +1118,7 @@ + + bool CLinuxRendererGL::IsGuiLayer() + { +- return !m_hdrFboActive; ++ return !m_hdrFboActive && !CServiceBroker::GetWinSystem()->UsesNativeSDRBT2020(); + } + + bool CLinuxRendererGL::Render(unsigned int flags, int renderBuffer) +@@ -2795,6 +2796,7 @@ + VideoPicture tmp{}; + tmp.color_space = toneMap ? AVCOL_SPC_UNSPECIFIED : buf.m_srcColSpace; + tmp.color_transfer = buf.m_srcColTransfer; ++ tmp.color_primaries = buf.m_srcPrimaries; + tmp.iWidth = m_sourceWidth; + tmp.iHeight = m_sourceHeight; + tmp.colorBits = buf.m_srcBits; +@@ -2805,6 +2807,12 @@ + { + const CPictureBuffer& buf = m_buffers[index]; + const ETONEMAPMETHOD& toneMapMethod = m_videoSettings.m_ToneMapMethod; ++ const bool wide = CServiceBroker::GetWinSystem()->UsesNativeSDRBT2020(); ++ if (wide != m_shaderSDRBT2020) ++ { ++ m_shaderSDRBT2020 = wide; ++ m_reloadShaders = true; ++ } + + if (buf.m_srcPrimaries != m_srcPrimaries) + { +--- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.h ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.h +@@ -14,6 +14,8 @@ + + #include "FrameBufferObject.h" + #include "cores/VideoSettings.h" ++#include "cores/VideoPlayer/DVDCodecs/Video/DVMetadataBuffer.h" ++#include "cores/VideoPlayer/Interface/TimingConstants.h" + #include "RenderInfo.h" + #include "BaseRenderer.h" + #include "ColorManager.h" +@@ -225,6 +227,7 @@ + ETONEMAPMETHOD m_toneMapMethod = VS_TONEMAPMETHOD_OFF; + bool m_passthroughHDR = false; + bool m_hdrFboActive{false}; ++ bool m_shaderSDRBT2020{false}; + bool m_pboSupported = true; + bool m_pboUsed = false; + bool m_nonLinStretch = false; +--- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp +@@ -1304,6 +1304,8 @@ + } + + EShaderFormat shaderFormat = GetShaderFormat(); ++ const auto dstPrimaries = ++ m_passthroughHDR || m_shaderSDRBT2020 ? m_srcPrimaries : AVCOL_PRI_BT709; + m_toneMapMethod = m_videoSettings.m_ToneMapMethod; + + // Try single-pass filter shader for FAST scalers on GLES 3.1+ +@@ -1312,7 +1314,7 @@ + m_scalingMethod == VS_SCALINGMETHOD_SPLINE36_FAST)) + { + m_pYUVProgShader = new YUV2RGBFilterShader( +- shaderFormat, m_passthroughHDR ? m_srcPrimaries : AVColorPrimaries::AVCOL_PRI_BT709, ++ shaderFormat, dstPrimaries, + m_srcPrimaries, m_toneMap, m_toneMapMethod, m_scalingMethod, m_useDithering); + // TODO: GL gates this on !m_cmsOn. Add when CMS is ported to GLES. + m_pYUVProgShader->SetConvertFullColorRange(m_fullRange); +@@ -1339,14 +1341,14 @@ + + // Fall back to regular progressive shader + m_pYUVProgShader = new YUV2RGBProgressiveShader( +- shaderFormat, m_passthroughHDR ? m_srcPrimaries : AVColorPrimaries::AVCOL_PRI_BT709, ++ shaderFormat, dstPrimaries, + m_srcPrimaries, m_toneMap, m_toneMapMethod, m_useDithering); + m_pYUVProgShader->SetConvertFullColorRange(m_fullRange); + + CLog::Log(LOGINFO, "GLES: Selecting YUV 2 RGB shader"); + + m_pYUVBobShader = new YUV2RGBBobShader( +- shaderFormat, m_passthroughHDR ? m_srcPrimaries : AVColorPrimaries::AVCOL_PRI_BT709, ++ shaderFormat, dstPrimaries, + m_srcPrimaries, m_toneMap, m_toneMapMethod, m_useDithering); + m_pYUVBobShader->SetConvertFullColorRange(m_fullRange); + +@@ -3115,13 +3117,19 @@ + + bool CLinuxRendererGLES::IsGuiLayer() + { +- return !m_hdrFboActive; ++ return !m_hdrFboActive && !CServiceBroker::GetWinSystem()->UsesNativeSDRBT2020(); + } + + void CLinuxRendererGLES::CheckVideoParameters(int index) + { + const CPictureBuffer& buf = m_buffers[index]; + const ETONEMAPMETHOD& toneMapMethod = m_videoSettings.m_ToneMapMethod; ++ const bool wide = CServiceBroker::GetWinSystem()->UsesNativeSDRBT2020(); ++ if (wide != m_shaderSDRBT2020) ++ { ++ m_shaderSDRBT2020 = wide; ++ m_reloadShaders = true; ++ } + + if (buf.m_srcPrimaries != m_srcPrimaries) + { +@@ -3148,6 +3156,7 @@ + VideoPicture tmp{}; + tmp.color_space = toneMap ? AVCOL_SPC_UNSPECIFIED : buf.m_srcColSpace; + tmp.color_transfer = buf.m_srcColTransfer; ++ tmp.color_primaries = buf.m_srcPrimaries; + tmp.iWidth = m_sourceWidth; + tmp.iHeight = m_sourceHeight; + // Keep Adaptive on the format already selected for this source depth. +--- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h +@@ -294,6 +294,7 @@ + // HDR FBO compositing: when active, IsGuiLayer() returns false so + // video renders separately from GUI via RenderUpdateVideo() + bool m_hdrFboActive{false}; ++ bool m_shaderSDRBT2020{false}; + + private: + void ClearBackBuffer(); +--- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererUtil.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererUtil.cpp +@@ -297,6 +297,8 @@ + gbm && gbm->IsDVBridgeScreenshotSDR()) + return true; // The SDR compositor expects sRGB overlays, including PQ bitmap palettes. + #endif ++ if (winSystem->UsesNativeSDRBT2020()) ++ return true; // The SDR BT.2020 compositor takes an sRGB GUI layer. + const bool destinationIsPQ = + winSystem->IsHdrComposite() || winSystem->GetEotf() != KODI::UTILS::Eotf::TRADITIONAL_SDR; + return !destinationIsPQ; +@@ -311,6 +313,8 @@ + cb1PQ = window->HasDVBridgeScreenshot(); + #endif + auto* window = CServiceBroker::GetWinSystem(); ++ if (window->UsesNativeSDRBT2020()) ++ return 1u; // The compositor applies the output range after gamut conversion. + return (ShouldConvertPQPaletteToSRGB(true) ? 1u : 0u) | + (window->IsHdrComposite() && window->UseLimitedColor() && !cb1PQ ? 2u : 0u); + } +--- a/xbmc/rendering/gl/GuiCompositeShaderGL.cpp ++++ b/xbmc/rendering/gl/GuiCompositeShaderGL.cpp +@@ -23,6 +23,7 @@ + m_hSamp = glGetUniformLocation(ProgramHandle(), "u_samp"); + m_hProj = glGetUniformLocation(ProgramHandle(), "u_proj"); + m_hSdrPeak = glGetUniformLocation(ProgramHandle(), "u_sdrPeak"); ++ m_hSDRBT2020 = glGetUniformLocation(ProgramHandle(), "u_sdrBT2020"); + + glUseProgram(ProgramHandle()); + glUniform1i(m_hSamp, 0); +@@ -35,5 +36,6 @@ + glUniformMatrix4fv(m_hProj, 1, GL_FALSE, m_proj); + + glUniform1f(m_hSdrPeak, m_sdrPeak); ++ glUniform1i(m_hSDRBT2020, m_sdrBT2020); + return true; + } +--- a/xbmc/rendering/gl/GuiCompositeShaderGL.h ++++ b/xbmc/rendering/gl/GuiCompositeShaderGL.h +@@ -19,6 +19,7 @@ + + void SetProjection(const GLfloat* proj) { m_proj = proj; } + void SetSdrPeak(float peak) { m_sdrPeak = peak; } ++ void SetSDRBT2020(bool enabled) { m_sdrBT2020 = enabled; } + + GLint GetPosLoc() { return m_hPos; } + GLint GetTexLoc() { return m_hTex; } +@@ -36,4 +37,6 @@ + GLint m_hSamp{-1}; + GLint m_hProj{-1}; + GLint m_hSdrPeak{-1}; ++ bool m_sdrBT2020{false}; ++ GLint m_hSDRBT2020{-1}; + }; +--- a/xbmc/rendering/gles/GuiCompositeShaderGLES.cpp ++++ b/xbmc/rendering/gles/GuiCompositeShaderGLES.cpp +@@ -65,6 +65,7 @@ + m_hOotfGamma = glGetUniformLocation(ProgramHandle(), "u_ootfGamma"); + m_hInputPQ = glGetUniformLocation(ProgramHandle(), "u_inputPQ"); + m_hSDRBT2020 = glGetUniformLocation(ProgramHandle(), "u_sdrBT2020"); ++ m_hUnpremultiplyGui = glGetUniformLocation(ProgramHandle(), "u_unpremultiplyGui"); + m_hOutputRange = glGetUniformLocation(ProgramHandle(), "u_outputRange"); + m_hPlayerLedScale = glGetUniformLocation(ProgramHandle(), "u_playerLedScale"); + m_hPlayerLedGui = glGetUniformLocation(ProgramHandle(), "u_playerLedGui"); +@@ -84,6 +85,7 @@ + glUniform1f(m_hOotfGamma, m_ootfGamma); + glUniform1i(m_hInputPQ, m_inputPQ); + glUniform1i(m_hSDRBT2020, m_sdrBT2020); ++ glUniform1i(m_hUnpremultiplyGui, m_unpremultiplyGui); + glUniform2f(m_hOutputRange, m_outputScale, m_outputOffset); + glUniform1f(m_hPlayerLedScale, m_playerLedScale); + if (m_playerLedScale > 0) +@@ -195,10 +197,10 @@ + return false; + } + +- if (colorTransfer == AVCOL_TRC_GAMMA22) ++ if (colorTransfer == AVCOL_TRC_GAMMA22 || colorTransfer == AVCOL_TRC_BT2020_10) + { + if (!std::isfinite(sdrGamma) || sdrGamma < 1.8f || sdrGamma > 2.8f) return false; +- // Negative selects BT.709 SDR in the shared compositor; no PQ/HLG LUT. ++ // Negative selects SDR in the shared compositor; no PQ/HLG LUT. + m_ootfGamma = -sdrGamma; + } + else if (colorTransfer == AVCOL_TRC_SMPTE2084) +--- a/xbmc/windowing/WinSystem.h ++++ b/xbmc/windowing/WinSystem.h +@@ -238,10 +238,13 @@ + /*! + * \brief Set colorimetry (BT.709, BT.2020, etc). Passing nullptr as the + * parameter resets to "Default" (display then decides based on rez). Native +- * YUV shaders set sdrToBT709 when they render SDR into the BT.709 gamut. ++ * YUV shaders set nativeSDRShader when the window system can choose their SDR output gamut. + * + */ +- virtual void SetColorimetry(const VideoPicture* videoPicture, bool sdrToBT709 = false) {} ++ virtual void SetColorimetry(const VideoPicture* videoPicture, bool nativeSDRShader = false) {} ++ ++ //! The native shader and GUI compositor are rendering this frame in SDR BT.2020. ++ virtual bool UsesNativeSDRBT2020() const { return false; } + + /*! + * \brief Set the HDR metadata. Passing nullptr as the parameter should +@@ -275,6 +278,7 @@ + // guiWillRender: hint that GUI rendering is about to fire this frame. + // When false, implementations should skip FBO bind/clear since no GUI + // draws will land in the FBO this frame. ++ virtual bool BeginFrameGuiComposite(bool guiWillRender) { return BeginGuiComposite(guiWillRender); } + virtual bool BeginGuiComposite(bool guiWillRender) { return false; } + virtual bool CanReuseGuiComposite() const { return false; } + virtual void EndGuiComposite() {} +@@ -287,7 +291,7 @@ + // alpha blend (see CGUIFontTTFGLES::FirstBegin). + virtual bool IsHdrComposite() const { return false; } + // Native HDR keeps its perceived-translucency compensation by default. +- virtual bool UseGuiCoverageAlpha() const { return !IsHdrComposite(); } ++ virtual bool UseGuiCoverageAlpha() const { return UsesNativeSDRBT2020() || !IsHdrComposite(); } + + /*! + * \brief Gets debug info from video renderer for use in "Debug Info OSD" (Alt + O) +--- a/xbmc/windowing/gbm/WinSystemGbm.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbm.cpp +@@ -24,6 +24,7 @@ + #include "messaging/ApplicationMessenger.h" + #include "guilib/GUIComponent.h" + #include "guilib/GUIWindowManager.h" ++#include "rendering/RenderSystem.h" + #include "settings/DisplaySettings.h" + #include "settings/Settings.h" + #include "settings/SettingsComponent.h" +@@ -1122,6 +1123,12 @@ + DeferConnectorPreferences(); + + auto atomic = std::dynamic_pointer_cast(m_DRM); ++ bool wideTransition = false; ++ if (!StageNativeSDRSignal(rendered, wideTransition)) ++ { ++ if (auto gui = CServiceBroker::GetGUI()) gui->GetWindowManager().MarkDirty(); ++ return false; ++ } + const bool transactional = rendered && atomic && (carrier || atomic->HasColorRangeTransition()); + struct gbm_bo* bo = nullptr; + +@@ -1147,6 +1154,19 @@ + if (atomic->LastPageAccepted()) surface.EndTransactionalMode(); + } + ++ if (rendered && atomic) ++ { ++ if (atomic->LastPageAccepted()) ++ m_nativeSDRSubmitted = m_nativeSDRActive; ++ else if (wideTransition) ++ { ++ // Retain the previous framebuffer and render the next frame into BT.709. ++ m_queuedColorspace.reset(); ++ m_nativeSDRRejected = true; ++ if (auto gui = CServiceBroker::GetGUI()) gui->GetWindowManager().MarkDirty(); ++ } ++ } ++ + if (ConnectorPreferencesAllowed()) + { + UpdateDriverLimitedRange(); +@@ -1296,8 +1316,22 @@ + : m_DRM->FindGuiPlane(current->GetFormat(), current->GetModifier()); + } + +-void CWinSystemGbm::SetColorimetry(const VideoPicture* videoPicture, bool sdrToBT709) ++void CWinSystemGbm::SetColorimetry(const VideoPicture* videoPicture, bool nativeSDRShader) + { ++ const bool nativeSDR = nativeSDRShader && videoPicture && ++ videoPicture->hdrType == StreamHdrType::HDR_TYPE_NONE && ++ videoPicture->color_transfer != AVCOL_TRC_SMPTE2084 && ++ videoPicture->color_transfer != AVCOL_TRC_ARIB_STD_B67; ++ m_nativeSDRSource = nativeSDR && videoPicture->color_primaries == AVCOL_PRI_BT2020; ++ m_nativeSDRRejected = false; ++ if (!m_nativeSDRSource) ++ m_nativeSDRActive = false; ++ if (!m_nativeSDRSource && m_nativeSDRCompositor) ++ { ++ SetGuiCompositing(0); ++ m_nativeSDRCompositor = false; ++ } ++ + m_queuedColorspace.reset(); + auto drm = std::dynamic_pointer_cast(m_DRM); + if (!drm) +@@ -1317,9 +1351,7 @@ + if (videoPicture) + { + colorimetry = KODI::UTILS::GetColorimetry(*videoPicture); +- if (sdrToBT709 && videoPicture->hdrType == StreamHdrType::HDR_TYPE_NONE && +- videoPicture->color_transfer != AVCOL_TRC_SMPTE2084 && +- videoPicture->color_transfer != AVCOL_TRC_ARIB_STD_B67) ++ if (nativeSDR) + colorimetry = KODI::UTILS::Colorimetry::BT709_YCC; + } + +@@ -1328,6 +1360,105 @@ + ApplyColorspace(); + } + ++std::optional CWinSystemGbm::NativeSDRBT2020Colorspace() const ++{ ++ const auto drm = std::dynamic_pointer_cast(m_DRM); ++ auto* connector = drm ? drm->GetConnector() : nullptr; ++ if (!connector || !connector->IsConnected() || !connector->GetType().starts_with("HDMI") || ++ !connector->SupportsProperty("Colorspace") || ++ connector->IsPropertyImmutable("Colorspace").value_or(false) || !m_info) ++ return {}; ++ ++ const auto target = IsYuvRequested() ? KODI::UTILS::Colorimetry::BT2020_YCC : ++ KODI::UTILS::Colorimetry::BT2020_RGB; ++ if (!m_info->SupportsColorimetry(target)) ++ return {}; ++ return connector->GetPropertyEnumValue("Colorspace", ColorimetryMap.at(target)); ++} ++ ++bool CWinSystemGbm::BeginFrameGuiComposite(bool guiWillRender) ++{ ++ const bool wasNative = m_nativeSDRCompositor; ++ // Only the renderer that owns a single RGB scanout can compose both layers ++ // into BT.2020. Keep the existing CMS and CB1 transport owners independent. ++ const bool wide = m_nativeSDRSource && !m_nativeSDRRejected && ConnectorPreferencesAllowed() && ++ m_DRM && m_DRM->GetVideoPlane() && !m_DRM->GetGuiPlane() && ++ !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( ++ "videoscreen.cmsenabled") && ++ NativeSDRBT2020Colorspace().has_value(); ++ if (wide && (!m_nativeSDRCompositor || !IsHdrComposite())) ++ m_nativeSDRCompositor = SetGuiCompositing(AVCOL_TRC_BT2020_10); ++ else if (!wide && m_nativeSDRCompositor) ++ { ++ SetGuiCompositing(0); ++ m_nativeSDRCompositor = false; ++ } ++ ++ const bool compositing = BeginGuiComposite(guiWillRender); ++ m_nativeSDRActive = wide && m_nativeSDRCompositor && compositing; ++ if (wide && !m_nativeSDRActive) ++ { ++ SetGuiCompositing(0); ++ m_nativeSDRCompositor = false; ++ m_nativeSDRRejected = true; ++ } ++ if (wasNative != m_nativeSDRCompositor) ++ { ++ // BeginRender ran before negotiation. Match the GUI shaders to the FBO ++ // so the first frame also applies display range only once. ++ GetRenderSystem()->UpdateGUIShaderColorState(); ++ } ++ return compositing; ++} ++ ++bool CWinSystemGbm::StageNativeSDRSignal(bool rendered, bool& wideTransition) ++{ ++ wideTransition = false; ++ if (!m_nativeSDRSubmitted && (!rendered || (!m_nativeSDRActive && !m_nativeSDRRejected))) ++ return true; ++ ++ const bool wide = rendered ? m_nativeSDRActive.load() : m_nativeSDRSubmitted; ++ const auto drm = std::dynamic_pointer_cast(m_DRM); ++ auto* connector = drm ? drm->GetConnector() : nullptr; ++ if (!connector || !connector->SupportsProperty("Colorspace")) ++ { ++ m_nativeSDRSubmitted = false; ++ return !wide; ++ } ++ ++ const auto committed = connector->GetPropertyValue("Colorspace"); ++ if (wide) ++ { ++ const auto target = NativeSDRBT2020Colorspace(); ++ if (!target || !drm->AddProperty(connector, "Colorspace", *target)) ++ { ++ m_queuedColorspace.reset(); ++ m_nativeSDRRejected = true; ++ return false; ++ } ++ m_queuedColorspace = target; ++ } ++ else ++ { ++ // An earlier wide request may have replaced the ordinary BT.709 request ++ // before it was accepted, even when no wide frame was ever submitted. ++ if (!m_nativeSDRSubmitted && m_queuedColorspace && m_queuedColorspace == committed) ++ return true; ++ ApplyColorspace(); ++ if (!m_queuedColorspace) ++ return false; ++ } ++ ++ const bool tagChanged = m_queuedColorspace != committed; ++ wideTransition = wide && (tagChanged || !drm->IsSelectedModeCommitted()); ++ // Never attach a framebuffer in the new gamut to the old atomic request. ++ if (tagChanged || wideTransition) ++ drm->SetColorRangeTransition(); ++ if (tagChanged) ++ drm->RequestModeset(); ++ return true; ++} ++ + void CWinSystemGbm::ApplyColorspace() + { + m_queuedColorspace.reset(); +@@ -1388,9 +1519,11 @@ + CLog::LogF(LOGDEBUG, "setting connector colorspace to {} (source {}, {} output)", + KODI::UTILS::ColorimetryToString(scanoutColorimetry), + KODI::UTILS::ColorimetryToString(colorimetry), yuv ? "YCbCr" : "RGB"); +- drm->AddProperty(connector, "Colorspace", colorspace.value()); +- m_queuedColorspace = colorspace; +- drm->SetActive(true); ++ if (drm->AddProperty(connector, "Colorspace", *colorspace)) ++ { ++ m_queuedColorspace = colorspace; ++ drm->SetActive(true); ++ } + } + } + +--- a/xbmc/windowing/gbm/WinSystemGbm.h ++++ b/xbmc/windowing/gbm/WinSystemGbm.h +@@ -104,8 +104,13 @@ + + bool SetVideoOutput(const VideoPicture* videoPicture) override; + +- void SetColorimetry(const VideoPicture* videoPicture, bool sdrToBT709 = false) override; +- KODI::UTILS::Colorimetry GetColorimetry() const override { return m_colorimetry; } ++ void SetColorimetry(const VideoPicture* videoPicture, bool nativeSDRShader = false) override; ++ KODI::UTILS::Colorimetry GetColorimetry() const override ++ { ++ return m_nativeSDRActive ? KODI::UTILS::Colorimetry::BT2020_YCC : m_colorimetry; ++ } ++ bool UsesNativeSDRBT2020() const override { return m_nativeSDRActive; } ++ bool BeginFrameGuiComposite(bool guiWillRender) override; + KODI::UTILS::Eotf GetEotf() const override { return m_eotf; } + bool SetHDR(const VideoPicture* videoPicture) override; + bool IsHDRDisplay() override; +@@ -213,6 +218,9 @@ + //! True if >8 bit video in the active HDMI mode does not fit as RGB, but does as YCbCr + bool ContentNeedsSubsampling() const; + ++ std::optional NativeSDRBT2020Colorspace() const; ++ bool StageNativeSDRSignal(bool rendered, bool& wideTransition); ++ + bool IsYuvRequested() const; + bool IsYuvFormatCommitted(const CDRMConnector& connector) const; + bool IsYuvFormat(const CDRMConnector& connector, std::optional current) const; +@@ -256,6 +264,12 @@ + std::string m_colorFormatFailedMode; + std::string m_currentModeId; + ++ bool m_nativeSDRSource{false}; ++ bool m_nativeSDRCompositor{false}; ++ std::atomic m_nativeSDRActive{false}; ++ bool m_nativeSDRSubmitted{false}; ++ bool m_nativeSDRRejected{false}; ++ + //! Whether the "Colorspace" tag was last set for a YCbCr output + bool m_scanoutYuv{false}; + // Claim no 3D display formats until an entire DRM mode enumeration proves them. +--- a/xbmc/windowing/gbm/WinSystemGbmGLContext.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbmGLContext.cpp +@@ -246,6 +246,8 @@ + m_compositeShader.reset(); + } + ++ if (m_compositeShader) ++ m_compositeShader->SetSDRBT2020(colorTransfer == AVCOL_TRC_BT2020_10); + return m_guiCompositing; + } + +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +@@ -1232,6 +1232,8 @@ + m_guiCompositing = false; + return false; + } ++ const bool nativeSDR = colorTransfer == AVCOL_TRC_BT2020_10; ++ m_compositeShader->SetSDRBT2020(nativeSDR, nativeSDR); + m_guiSDRGamma = gamma; + } + else +@@ -1640,7 +1642,10 @@ + m_compositeShader->SetInputPQ(false); + m_compositeShader->SetOutputRange(1.0f, 0.0f); + m_compositeShader->SetPlayerLed(); +- m_compositeShader->SetSDRBT2020(false); ++#ifdef HAVE_DVBRIDGE ++ if (m_sdrConversion) ++ m_compositeShader->SetSDRBT2020(false); ++#endif + + glDisableVertexAttribArray(posLoc); + glDisableVertexAttribArray(texLoc); diff --git a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hybrid-input-preference.patch b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hybrid-input-preference.patch index 077e019805..993ef3e9c7 100644 --- a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hybrid-input-preference.patch +++ b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hybrid-input-preference.patch @@ -327,12 +327,20 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb } if (result == VC_PICTURE) { -@@ -928,20 +952,35 @@ +@@ -928,20 +952,42 @@ } if (result == VC_EOF || (m_codecControlFlags & DVD_CODEC_CTRL_DRAIN)) - if (!dvbridge_fel_drain(m_dvFel.get())) +- if (!dvbridge_fel_drain(m_dvFel.get())) - return VC_FATAL; ++ { ++ const char* reason = nullptr; ++ if (!dvbridge_fel_drain(m_dvFel.get(), &reason)) ++ { ++ if (reason && !m_hints.preferHybridHDR10Plus) ++ CLog::Log(LOGERROR, "DV FEL: {}; choose Kodi Default to play the Profile 7 HDR10 base", reason); + break; ++ } ++ } paired = emit(); + if (paired == VC_FATAL) + break; @@ -369,7 +377,7 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb if (result == VC_PICTURE && m_dvNativeOutput) ReportDVStartup(1, "base-decoded"); #endif -@@ -1313,6 +1352,13 @@ +@@ -1313,6 +1359,13 @@ return VC_REOPEN; } @@ -383,7 +391,7 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb void CDVDVideoCodecFFmpeg::CaptureSourceSideData(VideoPicture* pVideoPicture) { // Capture original native source facts before any bridge/AI/output mutation. -@@ -1331,11 +1377,48 @@ +@@ -1331,11 +1384,48 @@ else m_sourceLightMetadata.reset(); } @@ -433,7 +441,7 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb } bool CDVDVideoCodecFFmpeg::GetPictureCommon(VideoPicture* pVideoPicture) -@@ -1553,11 +1636,18 @@ +@@ -1553,11 +1643,18 @@ if (pVideoPicture->hdrType == StreamHdrType::HDR_TYPE_DOLBYVISION) pVideoPicture->doviSourceBinding = m_dvSourceOwner.NextPicture(); #endif @@ -456,7 +464,7 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb pVideoPicture->hasLightMetadata, 0.0,0.0, pVideoPicture->hasLightMetadata ? pVideoPicture->lightMetadata.MaxCLL : 0u, -@@ -1565,7 +1655,7 @@ +@@ -1565,7 +1662,7 @@ const auto& sourceMastering = pVideoPicture->displayMetadata; auto& sourceInfo = pVideoPicture->doviSourceInfo; sourceInfo.informationGeneration = m_videoProcessingGeneration; @@ -465,7 +473,7 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb sourceInfo.mastering = pVideoPicture->hasDisplayMetadata && sourceMastering.has_luminance && sourceMastering.max_luminance.den > 0 && sourceMastering.min_luminance.den > 0; if (sourceInfo.mastering) -@@ -1626,7 +1716,8 @@ +@@ -1626,7 +1723,8 @@ { // COPY_OPAQUE follows the AU through native reordering and VAAPI references. // The ordinary paired path still validates/synchronizes EL before Kodi drops it. @@ -475,7 +483,7 @@ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xb pVideoPicture->iFlags |= DVP_FLAG_DROPPED; const auto* raw = av_frame_get_side_data(m_pFrame, AV_FRAME_DATA_DOVI_RPU_BUFFER); if ((m_dvVideoWindow && m_pFrame->opaque != &presentableDVPacket && -@@ -1958,12 +2049,15 @@ +@@ -1958,12 +2056,15 @@ unsigned CDVDVideoCodecFFmpeg::GetHDR10AIBufferCount() const { diff --git a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-logical-video-screenshot.patch b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-logical-video-screenshot.patch new file mode 100644 index 0000000000..cb0e317d25 --- /dev/null +++ b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-logical-video-screenshot.patch @@ -0,0 +1,353 @@ +diff --git a/xbmc/rendering/capture/CaptureBlit.cpp b/xbmc/rendering/capture/CaptureBlit.cpp +--- a/xbmc/rendering/capture/CaptureBlit.cpp ++++ b/xbmc/rendering/capture/CaptureBlit.cpp +@@ -18,7 +18,17 @@ + #include "windowing/GraphicContext.h" + #include "windowing/WinSystem.h" + ++#ifdef HAVE_DVBRIDGE ++#include "windowing/gbm/DVBridgeCapture.h" ++ ++extern "C" ++{ ++#include ++} ++#endif ++ + #include ++#include + #include + #include + #include +@@ -56,15 +66,51 @@ + } + + // Move a readback buffer's pixels and shape into a delivered CaptureResult. +-void FillResult(CaptureResult& result, ReadbackBuffer& buffer) +-{ +- result.pixels = std::make_shared(std::move(buffer.pixels)); ++void FillResult(CaptureResult& result, ReadbackBuffer& buffer, std::size_t offset = 0) ++{ ++ result.pixels = std::make_shared(std::move(buffer.pixels), offset); + result.width = buffer.width; + result.height = buffer.height; + result.stride = buffer.stride; + result.format = buffer.format; + } + } // namespace ++ ++bool CCaptureBlit::Capture(const CRect& visible, const CaptureSpec& spec, CaptureResult& result) ++{ ++#ifdef HAVE_DVBRIDGE ++ auto& window = *CServiceBroker::GetWinSystem(); ++ if (spec.cadence == CaptureCadence::ONESHOT && spec.format == CaptureFormat::NATIVE && ++ !spec.width && !spec.height && KODI::WINDOWING::GBM::HasDVBridgeScreenshot(window)) ++ { ++ int x0, y0, x1, y1, fbHeight; ++ ReadbackBuffer buffer; ++ if (!ClampToOutput(visible, x0, y0, x1, y1, fbHeight) || ++ !KODI::WINDOWING::GBM::ReadDVBridgeScreenshot(window, buffer, true) || !buffer.pixels || ++ buffer.width != static_cast(window.GetGfxContext().GetWidth()) || ++ buffer.height != static_cast(fbHeight)) ++ return false; ++ ++ // Crop the decoded image: an odd left edge can split a TV-led carrier pair. ++ const int pixelBytes = av_image_get_linesize(buffer.format, 1, 0); ++ const auto pitch = static_cast(std::abs(static_cast(buffer.stride))); ++ if (pixelBytes <= 0 || pitch < buffer.width * static_cast(pixelBytes)) ++ return false; ++ const int firstRow = buffer.stride < 0 ? fbHeight - y1 : y0; ++ const std::size_t offset = firstRow * pitch + x0 * static_cast(pixelBytes); ++ buffer.width = static_cast(x1 - x0); ++ buffer.height = static_cast(y1 - y0); ++ // Source mastering and light levels do not describe a reconstructed or tone-mapped image. ++ result.hasDisplayMetadata = false; ++ result.hasLightMetadata = false; ++ FillResult(result, buffer, offset); ++ return true; ++ } ++#endif ++ const unsigned int width = spec.width ? spec.width : static_cast(visible.Width()); ++ const unsigned int height = spec.height ? spec.height : static_cast(visible.Height()); ++ return Blit(visible, width, height, spec.format) && Read(result); ++} + + #if defined(HAS_GL) || HAS_GLES == 3 + +diff --git a/xbmc/rendering/capture/CaptureBlit.h b/xbmc/rendering/capture/CaptureBlit.h +--- a/xbmc/rendering/capture/CaptureBlit.h ++++ b/xbmc/rendering/capture/CaptureBlit.h +@@ -39,6 +39,9 @@ + CCaptureBlit(const CCaptureBlit&) = delete; + CCaptureBlit& operator=(const CCaptureBlit&) = delete; + ++ //! Capture the visible video region before overlays, respecting native logical pixels. ++ bool Capture(const CRect& visible, const CaptureSpec& spec, CaptureResult& result); ++ + //! \brief Copy srcRect (display coordinates, top-left origin) scaled to width x height. + //! NATIVE keeps the output depth in the copy; BGRA8 requantizes to 8-bit during it. + bool Blit(const CRect& srcRect, +diff --git a/xbmc/rendering/capture/CapturePixels.h b/xbmc/rendering/capture/CapturePixels.h +--- a/xbmc/rendering/capture/CapturePixels.h ++++ b/xbmc/rendering/capture/CapturePixels.h +@@ -52,11 +52,15 @@ + class CHeapCapturePixels : public ICapturePixels + { + public: +- explicit CHeapCapturePixels(std::unique_ptr buffer) : m_buffer(std::move(buffer)) {} +- const uint8_t* Lock() override { return m_buffer.get(); } ++ explicit CHeapCapturePixels(std::unique_ptr buffer, std::size_t offset = 0) ++ : m_buffer(std::move(buffer)), m_offset(offset) ++ { ++ } ++ const uint8_t* Lock() override { return m_buffer ? m_buffer.get() + m_offset : nullptr; } + + private: + std::unique_ptr m_buffer; ++ std::size_t m_offset; + }; + + //! swscale source pointer for a capture buffer whose stride may be negative +diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp +--- a/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp +@@ -972,29 +972,21 @@ + + for (const auto& request : requests) + { +- const unsigned int width = +- request->spec.width ? request->spec.width : static_cast(visible.Width()); +- const unsigned int height = +- request->spec.height ? request->spec.height : static_cast(visible.Height()); +- + CaptureResult result; +- if (m_captureBlit->Blit(visible, width, height, request->spec.format) && +- m_captureBlit->Read(result)) ++ // The ordinary video readback retains the mastering metadata of its source. ++ result.hasDisplayMetadata = m_picture.hasDisplayMetadata; ++ result.displayMetadata = m_picture.displayMetadata; ++ result.hasLightMetadata = m_picture.hasLightMetadata; ++ result.lightMetadata = m_picture.lightMetadata; ++ if (m_captureBlit->Capture(visible, request->spec, result)) + { + result.color = GetOutputColorMetadata(*CServiceBroker::GetWinSystem()); +- // the presented PQ is the content's during passthrough, so carry its +- // mastering metadata verbatim: the source peak an SDR tonemap needs. +- // NOTE: m_picture, not m_pConfigPicture, which Configure() has already +- // reset by the time this frame reaches CONFIGURED. +- result.hasDisplayMetadata = m_picture.hasDisplayMetadata; +- result.displayMetadata = m_picture.displayMetadata; +- result.hasLightMetadata = m_picture.hasLightMetadata; +- result.lightMetadata = m_picture.lightMetadata; + result.content = CaptureContent::VIDEO; // this tap delivers video-only + captureService->Complete(request, std::move(result)); + } +- else ++ else if (request->spec.content != CaptureContent::BOTH) + captureService->Fail(request); ++ // BOTH remains latched for the independent composite tap on this frame. + } + } + +diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp +--- a/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp +@@ -24,6 +24,7 @@ + #include + #include + #include "dvbridge_placebo.h" ++#include "dvbridge_metadata_bounds.h" + #include "dvbridge_cache.h" + #include "cb1_hdr10plus_dovi.h" + #include "cb1_lldv_cpu.h" +@@ -2538,7 +2539,22 @@ + return texture ? pl_opengl_unwrap(m_gl->gpu, texture, nullptr, nullptr, nullptr) : 0; + } + +-bool CDVBridgeGLES::ReadScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out) ++bool CDVBridgeGLES::UsesMasterSourceCarrier(dvbridge_mode mode, bool masterIPT, ++ const CDVMetadataBuffer& metadata) ++{ ++ if (mode != DVBRIDGE_MODE_MASTER_REFERENCE) ++ return false; ++ if (!masterIPT) ++ return true; ++ // Master keeps an authored IPT source in its native encoding. Converted YCC ++ // uses the output IPT matrices, which the source-metadata reader cannot decode. ++ if (!dvbridge_metadata_bounds(metadata.Data(), metadata.Size())) ++ return false; ++ const auto* parsed = reinterpret_cast(metadata.Data()); ++ return av_dovi_get_color(parsed)->signal_color_space == 2; ++} ++ ++bool CDVBridgeGLES::ReadScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out, bool videoOnly) + { + using namespace KODI::RENDERING::CAPTURE; + const auto failed = [&](const char* stage, int format = -1) { +@@ -2554,9 +2570,17 @@ + const bool master=m_effectiveMode==DVBRIDGE_MODE_MASTER_REFERENCE; + const bool sdr=m_effectiveMode==DVBRIDGE_MODE_SDR; + if (!m_prepared) return failed("unprepared"); ++ // Master can bake a cached GUI or subtitles into the carrier before the video tap. ++ const bool nativeOverlay = m_nativeOverlayEnabled && m_nativeOverlay.rect[0] < m_nativeOverlay.rect[2] && ++ m_nativeOverlay.rect[1] < m_nativeOverlay.rect[3]; ++ if (videoOnly && (m_guiComposed || nativeOverlay)) ++ { ++ CLog::Log(LOGWARNING, "CB1 video screenshot unavailable: the prepared picture includes an overlay"); ++ return false; ++ } + if (!m_scanout) return failed("no-scanout"); + if ((master || sdr) && !m_direct) return failed("direct-target"); +- const auto framebuffer=master || sdr ? m_scanoutFramebuffer : GetPQFramebuffer(); ++ const auto framebuffer=master || sdr ? m_scanoutFramebuffer : GetPQFramebuffer(!videoOnly); + if (!master && !sdr && !framebuffer) return failed("direct-target"); + GLint previous=0; + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING,&previous); +@@ -3207,7 +3231,7 @@ + return m_packed || Failure("hdr10-resolve"); + } + +-unsigned int CDVBridgeGLES::GetPQFramebuffer() ++unsigned int CDVBridgeGLES::GetPQFramebuffer(bool forGUI) + { + const auto texture = m_playerLed && m_prepared && m_playerLedPicture ? + pl_opengl_unwrap(m_gl->gpu, m_playerLedPicture, nullptr, nullptr, nullptr) : GetPQTexture(); +@@ -3221,7 +3245,7 @@ + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); + const bool valid = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE; + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, previous); +- if (valid && m_live) m_guiComposed = true; ++ if (valid && m_live && forGUI) m_guiComposed = true; + return valid ? m_framebuffer : 0; + } + +diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.h b/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.h +--- a/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.h ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.h +@@ -42,7 +42,13 @@ + public: + void InvalidateScreenshot() { ++m_nativeOverlayRevision; } + bool ScreenshotSDR() const { return m_prepared && m_direct && m_effectiveMode==DVBRIDGE_MODE_SDR; } +- bool ReadScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out); ++ static bool UsesMasterSourceCarrier(dvbridge_mode mode, bool masterIPT, ++ const CDVMetadataBuffer& metadata); ++ bool UsesMasterSourceCarrier() const ++ { ++ return UsesMasterSourceCarrier(m_effectiveMode, m_requested.masterIPT, m_pendingMetadata); ++ } ++ bool ReadScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out, bool videoOnly = false); + static constexpr bool CanComposeSDRGUI(bool enabled, bool hdr10, bool capture, + int width, int height, unsigned pqDraws) + { +@@ -234,7 +240,7 @@ + bool PrepareHardware(const Layer& base, const AVFrame* enhancement, + const CDVMetadataBuffer& metadata, dvbridge_geometry geometry, bool allowPacked = false); + unsigned int GetPQTexture() const; +- unsigned int GetPQFramebuffer(); ++ unsigned int GetPQFramebuffer(bool forGUI = true); + bool GetHDR10OutputTarget(unsigned& framebuffer, unsigned& bits) + { + if (!m_hdr10 || !m_prepared || !m_direct || !m_scanout) return false; +diff --git a/xbmc/windowing/gbm/DVBridgeCapture.h b/xbmc/windowing/gbm/DVBridgeCapture.h +--- a/xbmc/windowing/gbm/DVBridgeCapture.h ++++ b/xbmc/windowing/gbm/DVBridgeCapture.h +@@ -8,5 +8,6 @@ + { + bool HasDVBridgeScreenshot(CWinSystemBase& window); + bool IsDVBridgeScreenshotSDR(CWinSystemBase& window); +-bool ReadDVBridgeScreenshot(CWinSystemBase& window, KODI::RENDERING::CAPTURE::ReadbackBuffer& out); ++bool ReadDVBridgeScreenshot(CWinSystemBase& window, KODI::RENDERING::CAPTURE::ReadbackBuffer& out, ++ bool videoOnly = false); + } +diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +@@ -172,7 +172,7 @@ + { + return HasDVBridgeScreenshot() && m_sdrConversion; + } +- bool ReadDVBridgeScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out); ++ bool ReadDVBridgeScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out, bool videoOnly = false); + bool RenderDVBridge(const CDVBridgeGLES::Layer& layer, std::shared_ptr enhancement, + DVBRIDGE::SourceBinding enhancementBinding, + const CDVMetadataBuffer& metadata, +diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +@@ -3280,7 +3280,7 @@ + return gbm && gbm->IsDVBridgeScreenshotSDR(); + } + +-bool CWinSystemGbmGLESContext::ReadDVBridgeScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out) ++bool CWinSystemGbmGLESContext::ReadDVBridgeScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out, bool videoOnly) + { + if (!m_dvFrame || !m_dvBridge) + { +@@ -3293,13 +3293,16 @@ + m_guiCompositing, m_guiWillRender, m_nWidth, m_nHeight); + return false; + } +- return m_dvBridge->ReadScreenshot(out); +-} +- +-bool KODI::WINDOWING::GBM::ReadDVBridgeScreenshot(CWinSystemBase& window, KODI::RENDERING::CAPTURE::ReadbackBuffer& out) ++ // The other DV outputs have a packed carrier or display-linear RGB. Neither is BT.2020 PQ. ++ if (videoOnly && !m_hdrConversion && !m_dvBridge->UsesMasterSourceCarrier()) ++ return false; ++ return m_dvBridge->ReadScreenshot(out, videoOnly); ++} ++ ++bool KODI::WINDOWING::GBM::ReadDVBridgeScreenshot(CWinSystemBase& window, KODI::RENDERING::CAPTURE::ReadbackBuffer& out, bool videoOnly) + { + auto* gbm = dynamic_cast(&window); +- return gbm && gbm->ReadDVBridgeScreenshot(out); ++ return gbm && gbm->ReadDVBridgeScreenshot(out, videoOnly); + } + + bool CWinSystemGbmGLESContext::CB1AsyncAvailable() const +@@ -3372,10 +3375,33 @@ + if (!CB1AsyncAvailable()) return false; + } + const auto capture = CServiceBroker::GetCaptureService(); +- const bool capturing = capture && !capture->TakeActive( ++ const auto preferences = DVBRIDGE::FrameOutputSettings( ++ !layer.sourceInfo.profile && layer.hdr10PlusSource, ++ !layer.sourceInfo.profile && layer.hlg); ++ bool capturing = capture && !capture->TakeActive( + KODI::RENDERING::CAPTURE::CaptureContent::COMPOSITE).empty(); + const bool masterCapture=capturing && m_dvSelection.policy.mode==DVBRIDGE_MODE_MASTER_REFERENCE; +- if (masterCapture) m_dvBridge->InvalidateScreenshot(); ++ if (masterCapture) ++ m_dvBridge->InvalidateScreenshot(); ++ else if (capture && (m_hdrConversion || m_dvSelection.policy.mode == DVBRIDGE_MODE_MASTER_REFERENCE)) ++ { ++ // A paused frame may already have been consumed by scanout. ++ using namespace KODI::RENDERING::CAPTURE; ++ const auto requests = capture->TakeActive(CaptureContent::VIDEO); ++ if (!requests.empty()) ++ { ++ const auto& spec = requests.front()->spec; ++ if (spec.cadence == CaptureCadence::ONESHOT && spec.format == CaptureFormat::NATIVE && ++ !spec.width && !spec.height && (m_hdrConversion || CDVBridgeGLES::UsesMasterSourceCarrier( ++ m_dvSelection.policy.mode, preferences.masterIPT, metadata))) ++ { ++ m_dvBridge->InvalidateScreenshot(); ++ // Direct HDR10 writes scanout only. Prepare its PQ RGB target for the video tap. ++ if (m_hdrConversion && !m_sdrConversion) ++ capturing = true; ++ } ++ } ++ } + const bool guiAvailable = m_guiWillRender || CanReuseGuiComposite(); + const bool overlayFree = (!capturing || masterCapture) && + (!guiAvailable || GetGUIElementCount() == 0) && !m_dvOverlays; +@@ -3384,9 +3410,6 @@ + m_previousSourceStream == layer.binding.stream && + DVBRIDGE::ContinuousPresentationPicture(layer.pts, m_previousSourcePts) && + m_dvSelection.reason == DVBRIDGE::OutputReason::None; +- const auto preferences = DVBRIDGE::FrameOutputSettings( +- !layer.sourceInfo.profile && layer.hdr10PlusSource, +- !layer.sourceInfo.profile && layer.hlg); + m_masterFramePeriodNs=m_continuousFrameEligible && + m_dvSelection.policy.mode==DVBRIDGE_MODE_MASTER_REFERENCE ? + DVBRIDGE::MasterFramePeriodNs(CServiceBroker::GetDataCacheCore().GetVideoFps()) : 0; diff --git a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hdr10-fallback-mode.patch b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hdr10-fallback-mode.patch new file mode 100644 index 0000000000..d29f9ce9d3 --- /dev/null +++ b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-hdr10-fallback-mode.patch @@ -0,0 +1,428 @@ +diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.cpp b/xbmc/cores/VideoPlayer/VideoPlayer.cpp +index 0b1c250..e5b4225 100644 +--- a/xbmc/cores/VideoPlayer/VideoPlayer.cpp ++++ b/xbmc/cores/VideoPlayer/VideoPlayer.cpp +@@ -4817,8 +4817,8 @@ bool CVideoPlayer::OpenVideoStream(CDVDStreamInfo& hint, bool reset) + if (!pMenus) + { + const RESOLUTION res = playerLedStartupResolution ? *playerLedStartupResolution : +- CResolutionUtils::ChooseBestResolution(static_cast(framerate), hint.width, +- hint.height, !hint.stereo_mode.empty()); ++ CRenderManager::ChoosePlaybackResolution(framerate, hint.width, hint.height, ++ !hint.stereo_mode.empty(), nativeDV); + #ifdef HAVE_DVBRIDGE + using HDRSignal = DVBRIDGE::NativeHDRSignal; + auto hdrSignal = HDRSignal::None; +diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp +index 4b23854..abc5f4b 100644 +--- a/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp +@@ -28,11 +28,11 @@ + #include "windowing/GraphicContext.h" + #include "windowing/WinSystem.h" + ++#include + #include + #include + #include + #ifdef CB1_HAS_HDR10_AI +-#include "cores/VideoPlayer/DVDCodecs/Video/DVOutputSettings.h" + #include "guilib/GUIComponent.h" + #include "guilib/GUIWindowManager.h" + #include "guilib/WindowIDs.h" +@@ -41,7 +41,9 @@ + #endif + #endif + #ifdef HAVE_DVBRIDGE ++#include "cores/VideoPlayer/DVDCodecs/Video/DVOutputSettings.h" + #include "cores/VideoPlayer/DVDCodecs/Video/DVPlaybackPolicy.h" ++#include "settings/DisplaySettings.h" + #endif + #if defined(HAVE_GBM) && defined(HAS_GLES) + #include "windowing/gbm/WinSystemGbmGLESContext.h" +@@ -1006,22 +1008,39 @@ void CRenderManager::SetViewMode(int iViewMode) + m_playerPort->VideoParamsChange(); + } + +-RESOLUTION CRenderManager::ChoosePlaybackResolution(double fps, int width, int height, bool stereo, +- bool nativeDV, bool atStartup) ++RESOLUTION CRenderManager::ChoosePlaybackResolution(double fps, ++ int width, ++ int height, ++ bool stereo, ++ bool nativeDV, ++ bool atStartup, ++ const VideoPicture* picture) + { + #ifdef HAVE_DVBRIDGE ++ const KODI::WINDOWING::GBM::CWinSystemGbmGLESContext* window = nullptr; + const auto advanced = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings(); + if (nativeDV && !stereo && !CResolutionUtils::HasWhitelist() && + advanced->m_videoAdjustRefreshOverrides.empty()) +- if (const auto* window = dynamic_cast( +- CServiceBroker::GetWinSystem())) +- if (const auto resolution = window->PlayerLedResolution(fps, atStartup)) +- return *resolution; ++ window = dynamic_cast( ++ CServiceBroker::GetWinSystem()); ++ if (window) ++ if (const auto resolution = window->PlayerLedResolution(fps, atStartup)) ++ return *resolution; + #else + (void)nativeDV; + (void)atStartup; ++ (void)picture; ++#endif ++ const RESOLUTION chosen = CResolutionUtils::ChooseBestResolution(fps, width, height, stereo); ++#ifdef HAVE_DVBRIDGE ++ // When the startup fallback is active, the empty whitelist's desktop size floor ++ // can hide usable HDR10 modes on an 8K display. Keep the refresh Kodi selected. ++ if (window && (!picture || picture->doviSourceInfo.profile || ++ picture->hdrType == StreamHdrType::HDR_TYPE_DOLBYVISION) && ++ DVBRIDGE::FrameOutputSettings().hdr10TransportFallback) ++ return window->ChooseHDR10FallbackResolution(chosen); + #endif +- return CResolutionUtils::ChooseBestResolution(fps, width, height, stereo); ++ return chosen; + } + + RESOLUTION CRenderManager::GetResolution() +@@ -1035,7 +1054,7 @@ RESOLUTION CRenderManager::GetResolution() + if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOPLAYER_ADJUSTREFRESHRATE) != ADJUST_REFRESHRATE_OFF) + { + res = ChoosePlaybackResolution(m_fps, m_picture.iWidth, m_picture.iHeight, +- !m_picture.stereoMode.empty(), m_nativeDVRate); ++ !m_picture.stereoMode.empty(), m_nativeDVRate, false, &m_picture); + } + + return res; +@@ -1304,8 +1323,9 @@ void CRenderManager::UpdateResolution() + { + if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOPLAYER_ADJUSTREFRESHRATE) != ADJUST_REFRESHRATE_OFF && m_fps > 0.0f) + { +- const RESOLUTION res = ChoosePlaybackResolution(m_fps, m_picture.iWidth, m_picture.iHeight, +- !m_picture.stereoMode.empty(), m_nativeDVRate); ++ const RESOLUTION res = ++ ChoosePlaybackResolution(m_fps, m_picture.iWidth, m_picture.iHeight, ++ !m_picture.stereoMode.empty(), m_nativeDVRate, false, &m_picture); + #ifdef HAVE_DVBRIDGE + // Carry the stream's intent when this later request performs the modeset. + const auto previous = DVBRIDGE::guiModeChangeResolution; +diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h b/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h +index 7f36a0e..e6cc20f 100644 +--- a/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h +@@ -94,7 +94,8 @@ public: + + RESOLUTION GetResolution(); + static RESOLUTION ChoosePlaybackResolution(double fps, int width, int height, bool stereo, +- bool nativeDV, bool atStartup = false); ++ bool nativeDV, bool atStartup = false, ++ const VideoPicture* picture = nullptr); + void UpdateResolution(); + void TriggerUpdateResolution(float fps, int width, int height, std::string &stereomode, + bool nativeDV = false); +diff --git a/xbmc/settings/DisplaySettings.cpp b/xbmc/settings/DisplaySettings.cpp +index 50d5efc..c31f479 100644 +--- a/xbmc/settings/DisplaySettings.cpp ++++ b/xbmc/settings/DisplaySettings.cpp +@@ -515,6 +515,27 @@ RESOLUTION_INFO& CDisplaySettings::GetResolutionInfo(RESOLUTION resolution) + return GetResolutionInfo((size_t)resolution); + } + ++RESOLUTION_INFO CDisplaySettings::GetResolutionInfoCopy(RESOLUTION resolution) const ++{ ++ std::unique_lock lock(m_critical); ++ if (resolution <= RES_INVALID || static_cast(resolution) >= m_resolutions.size()) ++ return EmptyResolution; ++ ++ return m_resolutions[resolution]; ++} ++ ++void CDisplaySettings::SetDesktopResolutionInfo(const RESOLUTION_INFO& resolution) ++{ ++ std::unique_lock lock(m_critical); ++ m_resolutions[RES_DESKTOP] = resolution; ++} ++ ++size_t CDisplaySettings::ResolutionInfoSize() const ++{ ++ std::unique_lock lock(m_critical); ++ return m_resolutions.size(); ++} ++ + void CDisplaySettings::AddResolutionInfo(const RESOLUTION_INFO &resolution) + { + std::unique_lock lock(m_critical); +@@ -987,6 +1008,7 @@ void CDisplaySettings::SettingOptionsMonitorsFiller(const SettingConstPtr& setti + + void CDisplaySettings::ClearCustomResolutions() + { ++ std::unique_lock lock(m_critical); + if (m_resolutions.size() > RES_CUSTOM) + { + std::vector::iterator firstCustom = m_resolutions.begin()+RES_CUSTOM; +diff --git a/xbmc/settings/DisplaySettings.h b/xbmc/settings/DisplaySettings.h +index b983b3f..c359848 100644 +--- a/xbmc/settings/DisplaySettings.h ++++ b/xbmc/settings/DisplaySettings.h +@@ -66,7 +66,9 @@ public: + const RESOLUTION_INFO& GetResolutionInfo(RESOLUTION resolution) const; + RESOLUTION_INFO& GetResolutionInfo(size_t index); + RESOLUTION_INFO& GetResolutionInfo(RESOLUTION resolution); +- size_t ResolutionInfoSize() const { return m_resolutions.size(); } ++ RESOLUTION_INFO GetResolutionInfoCopy(RESOLUTION resolution) const; ++ void SetDesktopResolutionInfo(const RESOLUTION_INFO& resolution); ++ size_t ResolutionInfoSize() const; + void AddResolutionInfo(const RESOLUTION_INFO &resolution); + + const RESOLUTION_INFO& GetCurrentResolutionInfo() const { return GetResolutionInfo(m_currentResolution); } +diff --git a/xbmc/windowing/gbm/WinSystemGbm.cpp b/xbmc/windowing/gbm/WinSystemGbm.cpp +index 5b4835d..282c336 100644 +--- a/xbmc/windowing/gbm/WinSystemGbm.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbm.cpp +@@ -351,7 +351,7 @@ void CWinSystemGbm::UpdateResolutions() + + CServiceBroker::GetWinSystem()->GetGfxContext().ResetOverscan(current); + CDisplaySettings::GetInstance().AddResolutionInfo(current); +- CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP) = current; ++ CDisplaySettings::GetInstance().SetDesktopResolutionInfo(current); + + CLog::Log(LOGINFO, "Found resolution {}x{} with {}x{}{} @ {:f} Hz{}", current.iWidth, + current.iHeight, current.iScreenWidth, current.iScreenHeight, +@@ -371,7 +371,7 @@ void CWinSystemGbm::UpdateResolutions() + current.iWidth == res.iWidth && current.iHeight == res.iHeight && + current.fRefreshRate == res.fRefreshRate && current.dwFlags == res.dwFlags) + { +- CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP) = res; ++ CDisplaySettings::GetInstance().SetDesktopResolutionInfo(res); + } + + // The layout matters as much as the geometry here: without it a half 3D mode prints +@@ -999,27 +999,51 @@ bool CWinSystemGbm::RefreshDisplayInfoForVideo() + return true; + } + ++namespace ++{ ++double DVOutputTimingRate(const drmModeModeInfo* mode) ++{ ++ if (!mode || !mode->hdisplay || (mode->hdisplay & 1) || !mode->vdisplay || ++ mode->hdisplay > 3840 || mode->vdisplay > 2160 || ++ uint64_t(mode->hdisplay) * mode->vdisplay < 5 * 3072u || ++ (mode->flags & (DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLSCAN))) ++ return 0.0; ++ const double rate = mode->htotal && mode->vtotal ++ ? mode->clock * 1000.0 / mode->htotal / mode->vtotal ++ : 0.0; ++ return CResolutionUtils::IsCB1RefreshRate(rate) ? rate : 0.0; ++} ++} // namespace ++ + bool CWinSystemGbm::SupportsDVOutputMode(bool requireCurrentMode) const + { + if (!m_DRM) return false; +- const auto usable = [](const drmModeModeInfo* mode) { +- if (!mode || !mode->hdisplay || (mode->hdisplay & 1) || !mode->vdisplay || +- mode->hdisplay > 3840 || mode->vdisplay > 2160 || +- uint64_t(mode->hdisplay) * mode->vdisplay < 5 * 3072u || +- (mode->flags & (DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLSCAN))) return false; +- const double rate = mode->htotal && mode->vtotal ? +- mode->clock * 1000.0 / mode->htotal / mode->vtotal : 0.0; +- return CResolutionUtils::IsCB1RefreshRate(rate); +- }; +- if (usable(m_DRM->GetSelectedMode())) return true; ++ if (DVOutputTimingRate(m_DRM->GetSelectedMode())) return true; + if (requireCurrentMode) return false; + auto* connector = m_DRM->GetConnector(); + if (!connector || !connector->IsConnected()) return false; + for (int i = 0; i < connector->GetModesCount(); ++i) +- if (usable(connector->GetModeForIndex(i))) return true; ++ if (DVOutputTimingRate(connector->GetModeForIndex(i))) return true; + return false; + } + ++std::vector CWinSystemGbm::GetDVOutputTimings() const ++{ ++ std::vector timings; ++ auto* connector = m_DRM ? m_DRM->GetConnector() : nullptr; ++ if (!connector || !connector->IsConnected()) ++ return timings; ++ ++ for (int index = 0; index < connector->GetModesCount(); ++index) ++ { ++ const auto* mode = connector->GetModeForIndex(index); ++ const double refresh = DVOutputTimingRate(mode); ++ if (refresh > 0.0 && !(mode->flags & DRM_MODE_FLAG_3D_MASK) && mode->vscan <= 1) ++ timings.push_back({index, mode->hdisplay, mode->vdisplay, refresh}); ++ } ++ return timings; ++} ++ + bool CWinSystemGbm::SupportsNativeDVOutput(bool requireCurrentMode) const + { + if (!m_info || !m_info->SupportsStandardDolbyVision() || +diff --git a/xbmc/windowing/gbm/WinSystemGbm.h b/xbmc/windowing/gbm/WinSystemGbm.h +index b0c60dd..09cc0ae 100644 +--- a/xbmc/windowing/gbm/WinSystemGbm.h ++++ b/xbmc/windowing/gbm/WinSystemGbm.h +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + #include + +@@ -132,6 +133,16 @@ public: + std::vector GetConnectedOutputs() override; + + protected: ++#ifdef HAVE_DVBRIDGE ++ struct DVOutputTiming ++ { ++ int index; ++ int width; ++ int height; ++ double refresh; ++ }; ++ std::vector GetDVOutputTimings() const; ++#endif + virtual bool ConnectorPreferencesAllowed() const { return true; } + void DeferConnectorPreferences(); + void ApplyColorspace(); +diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +index 123cbc9..9cc88ca 100644 +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +@@ -1751,6 +1751,9 @@ void CWinSystemGbmGLESContext::RefreshDVOutputCapabilities() + const auto previous = [&] { + std::lock_guard lock(m_dvCapabilityMutex); + auto prior = m_dvLldvStatus; ++ if (lldvStatus.connectorId != prior.connectorId || ++ lldvStatus.edidGeneration != prior.edidGeneration) ++ m_dvOutputTimings.clear(); + m_dvLldvStatus = lldvStatus; + return prior; + }(); +@@ -1809,6 +1812,7 @@ void CWinSystemGbmGLESContext::RefreshDVOutputCapabilities() + } + const bool availableNativeDV = SupportsNativeDVOutput(false); + const bool availableHDR10 = SupportsHDR10Conversion(false); ++ auto timings = GetDVOutputTimings(); + std::lock_guard lock(m_dvCapabilityMutex); + if (lldvStatus.edidGeneration != previous.edidGeneration || + lldvStatus.connectorId != previous.connectorId || +@@ -1833,6 +1837,7 @@ void CWinSystemGbmGLESContext::RefreshDVOutputCapabilities() + m_dvCapabilities = caps; + m_dvAvailableNativeDV = availableNativeDV; + m_dvAvailableHDR10 = availableHDR10; ++ m_dvOutputTimings = std::move(timings); + if (DVBRIDGE::DiagnosticsEnabled()) + { + try +@@ -1853,6 +1858,62 @@ void CWinSystemGbmGLESContext::RefreshDVOutputCapabilities() + } + } + ++bool CWinSystemGbmGLESContext::SupportsDVOutputTiming(RESOLUTION resolution) const ++{ ++ if (resolution < RES_DESKTOP) ++ return false; ++ ++ const auto mode = CDisplaySettings::GetInstance().GetResolutionInfoCopy(resolution); ++ if (mode.dwFlags & D3DPRESENTFLAG_MODEMASK) ++ return false; ++ ++ const auto* end = mode.strId.data() + mode.strId.size(); ++ int index = -1; ++ const auto parsed = std::from_chars(mode.strId.data(), end, index); ++ if (parsed.ec != std::errc{} || parsed.ptr != end || index < 0) ++ return false; ++ ++ // The connector's mode indices can change before Kodi rebuilds its resolution catalogue. ++ std::lock_guard lock(m_dvCapabilityMutex); ++ return std::ranges::any_of(m_dvOutputTimings, [&](const DVOutputTiming& timing) { ++ return timing.index == index && timing.width == mode.iScreenWidth && ++ timing.height == mode.iScreenHeight && std::abs(timing.refresh - mode.fRefreshRate) < 0.01; ++ }); ++} ++ ++RESOLUTION CWinSystemGbmGLESContext::ChooseHDR10FallbackResolution(RESOLUTION chosen) const ++{ ++ const auto advanced = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings(); ++ if (SupportsDVOutputTiming(chosen) || CResolutionUtils::HasWhitelist() || ++ !advanced->m_videoAdjustRefreshOverrides.empty()) ++ return chosen; ++ ++ const auto& display = CDisplaySettings::GetInstance(); ++ const auto original = display.GetResolutionInfoCopy(chosen); ++ std::vector candidates; ++ GetGfxContext().GetAllowedResolutions(candidates); ++ RESOLUTION best = chosen; ++ int bestArea = 0; ++ for (const RESOLUTION candidate : candidates) ++ { ++ const auto mode = display.GetResolutionInfoCopy(candidate); ++ if (std::abs(mode.fRefreshRate - original.fRefreshRate) < 0.01f && ++ SupportsDVOutputTiming(candidate)) ++ { ++ const int area = mode.iScreenWidth * mode.iScreenHeight; ++ if (area > bestArea) ++ { ++ best = candidate; ++ bestArea = area; ++ } ++ } ++ } ++ if (best != chosen) ++ CLog::Log(LOGDEBUG, "CB1 HDR10 fallback: selected {} (original mode {})", ++ display.GetResolutionInfoCopy(best).strMode, original.strMode); ++ return best; ++} ++ + bool CWinSystemGbmGLESContext::CanRetainDVSource() const + { + const auto preferences = DVBRIDGE::FrameOutputSettings(); +@@ -4001,6 +4062,10 @@ bool CWinSystemGbmGLESContext::DestroyWindowSystem() + if (!RetireDVContext()) return false; + SelectPascalHDRMode(PascalHDRMode::None); + m_pascalHDRScanout.reset(); ++ { ++ std::lock_guard lock(m_dvCapabilityMutex); ++ m_dvOutputTimings.clear(); ++ } + if (!CWinSystemGbmEGLContext::DestroyWindowSystem()) return false; + std::lock_guard lock(m_dvCapabilityMutex); + const auto generation = m_dvCapabilities.generation + 1; +@@ -4063,7 +4128,8 @@ bool CWinSystemGbmGLESContext::CreateContext() + const auto generation = m_dvCapabilities.generation + 1; + m_dvCapabilities = {}; + m_dvAvailableNativeDV = m_dvAvailableHDR10 = false; +- m_dvLldvStatus = {}; ++ m_dvOutputTimings.clear(); ++ m_dvLldvStatus = {}; + m_dvCapabilities.generation = generation; + m_dvImportBinding = {}; + m_dvImportUsable = false; +diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +index 29a1cbc..d03f1f4 100644 +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +@@ -96,6 +96,8 @@ public: + DVBRIDGE::OutputCapabilities GetDVOutputCapabilities(const VideoPicture* picture, + bool allowModeSwitch = false) const; + bool CanRetainDVSource() const; ++ bool SupportsDVOutputTiming(RESOLUTION resolution) const; ++ RESOLUTION ChooseHDR10FallbackResolution(RESOLUTION chosen) const; + bool CompleteDVModeSwitch(const VideoPicture& picture); + std::optional PlayerLedResolution(double fps, bool atStartup = false) const; + int PlayerLedResolutionReason(RESOLUTION resolution, int preference) const; +@@ -301,6 +303,7 @@ private: + #endif + DVBRIDGE::OutputCapabilities m_dvCapabilities; + bool m_dvAvailableNativeDV{}, m_dvAvailableHDR10{}; ++ std::vector m_dvOutputTimings; + std::atomic m_hdr10MaxBpc{0}; + DVBRIDGE::LldvConnectorStatus m_dvLldvStatus{}; + XbmcThreads::EndTime<> m_lldvEdidRefresh; diff --git a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-startup-timing-fallback.patch b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-startup-timing-fallback.patch new file mode 100644 index 0000000000..e48a9986a7 --- /dev/null +++ b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-lldv-startup-timing-fallback.patch @@ -0,0 +1,253 @@ +diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.cpp b/xbmc/cores/VideoPlayer/VideoPlayer.cpp +index e5b4225..436d4db 100644 +--- a/xbmc/cores/VideoPlayer/VideoPlayer.cpp ++++ b/xbmc/cores/VideoPlayer/VideoPlayer.cpp +@@ -4755,7 +4755,7 @@ bool CVideoPlayer::OpenVideoStream(CDVDStreamInfo& hint, bool reset) + return DVD_TIME_BASE / CDVDCodecUtils::NormalizeFrameduration( + (double)DVD_TIME_BASE * hint.fpsscale / (hint.fpsrate * (hint.interlaced ? 2 : 1))); + }; +- std::optional playerLedStartupResolution; ++ bool dvStartupModeSet = false; + + #ifdef HAVE_DVBRIDGE + const auto settings = CServiceBroker::GetSettingsComponent()->GetSettings(); +@@ -4768,26 +4768,6 @@ bool CVideoPlayer::OpenVideoStream(CDVDStreamInfo& hint, bool reset) + CServiceBroker::GetWinSystem()); + const auto preferences = DVBRIDGE::FrameOutputSettings(); + const auto mode = preferences.Policy().mode; +- if (window && !m_HasVideo && !pMenus && !hint.interlaced && +- mode == DVBRIDGE_MODE_PLAYER_LED && !preferences.hdr10TransportFallback) +- { +- const bool adjustRefresh = m_playerOptions.fullscreen && +- window->GetGfxContext().IsFullScreenRoot() && +- settings->GetInt(CSettings::SETTING_VIDEOPLAYER_ADJUSTREFRESHRATE) != ADJUST_REFRESHRATE_OFF; +- if (adjustRefresh && hint.fpsrate && hint.fpsscale) +- playerLedStartupResolution = CRenderManager::ChoosePlaybackResolution( +- streamFrameRate(), hint.width, hint.height, false, WantsNativePresentation(hint), true); +- +- if ((!adjustRefresh || playerLedStartupResolution) && +- window->PlayerLedResolutionReason(playerLedStartupResolution.value_or(RES_INVALID), +- preferences.lldvFormat) == +- DVBRIDGE::LLDV_DRIVER_REJECTED_LABEL) +- { +- const auto caps = window->GetDVOutputCapabilities(nullptr, true); +- if (caps.hdr10 && !caps.HDR10DepthLimited()) +- DVBRIDGE::UsePlayerLedStartupFallback(); +- } +- } + if (window && (mode == DVBRIDGE_MODE_HDR10_BASIC || mode == DVBRIDGE_MODE_HDR10_EXPERT) && + window->GetDVOutputCapabilities(nullptr, true).HDR10DepthLimited()) + { +@@ -4799,6 +4779,45 @@ bool CVideoPlayer::OpenVideoStream(CDVDStreamInfo& hint, bool reset) + m_bAbortRequest = true; + return false; + } ++ const bool tryPlayerLed = mode == DVBRIDGE_MODE_PLAYER_LED && !preferences.hdr10TransportFallback; ++ if (window && !m_HasVideo && !pMenus && !hint.interlaced && ++ (tryPlayerLed || preferences.hdr10TransportFallback)) ++ { ++ const bool adjustRefresh = m_playerOptions.fullscreen && ++ window->GetGfxContext().IsFullScreenRoot() && ++ settings->GetInt(CSettings::SETTING_VIDEOPLAYER_ADJUSTREFRESHRATE) != ADJUST_REFRESHRATE_OFF; ++ if (adjustRefresh && hint.fpsrate && hint.fpsscale) ++ { ++ // The file startup request already waits for the GUI. Select and apply its ++ // catalogue index in that same operation so hotplug cannot reuse the index. ++ auto setStartupMode = [&] { ++ auto resolution = CRenderManager::ChoosePlaybackResolution( ++ streamFrameRate(), hint.width, hint.height, false, WantsNativePresentation(hint), true); ++ if (tryPlayerLed) ++ { ++ if (const auto fallback = ++ window->PlayerLedStartupHDR10Resolution(resolution, preferences.lldvFormat)) ++ { ++ resolution = *fallback; ++ DVBRIDGE::UsePlayerLedStartupFallback(); ++ } ++ } ++ const auto previous = DVBRIDGE::guiModeChangeResolution; ++ DVBRIDGE::guiModeChangeResolution = ++ WantsNativePresentation(hint) ? static_cast(resolution) : -1; ++ window->GetGfxContext().SetVideoResolution(resolution, false); ++ DVBRIDGE::guiModeChangeResolution = previous; ++ dvStartupModeSet = true; ++ }; ++ MESSAGING::ThreadMessageCallback callback{ ++ [](void* payload) { (*static_cast(payload))(); }, ++ &setStartupMode}; ++ CServiceBroker::GetAppMessenger()->SendMsg(TMSG_CALLBACK, -1, -1, &callback); ++ } ++ else if (!adjustRefresh && tryPlayerLed && ++ window->PlayerLedStartupHDR10Resolution(RES_INVALID, preferences.lldvFormat)) ++ DVBRIDGE::UsePlayerLedStartupFallback(); ++ } + } + #endif + +@@ -4814,11 +4833,10 @@ bool CVideoPlayer::OpenVideoStream(CDVDStreamInfo& hint, bool reset) + const bool nativeDV = !hint.preferHybridHDR10Plus && WantsNativePresentation(hint); + // Disc navigation can reopen video while the GUI is joining this thread. + // Let the render thread change the mode without a synchronous GUI message. +- if (!pMenus) ++ if (!pMenus && !dvStartupModeSet) + { +- const RESOLUTION res = playerLedStartupResolution ? *playerLedStartupResolution : +- CRenderManager::ChoosePlaybackResolution(framerate, hint.width, hint.height, +- !hint.stereo_mode.empty(), nativeDV); ++ const RESOLUTION res = CRenderManager::ChoosePlaybackResolution( ++ framerate, hint.width, hint.height, !hint.stereo_mode.empty(), nativeDV); + #ifdef HAVE_DVBRIDGE + using HDRSignal = DVBRIDGE::NativeHDRSignal; + auto hdrSignal = HDRSignal::None; +diff --git a/xbmc/windowing/gbm/WinSystemGbm.cpp b/xbmc/windowing/gbm/WinSystemGbm.cpp +index 282c336..29d4b97 100644 +--- a/xbmc/windowing/gbm/WinSystemGbm.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbm.cpp +@@ -1006,7 +1006,8 @@ double DVOutputTimingRate(const drmModeModeInfo* mode) + if (!mode || !mode->hdisplay || (mode->hdisplay & 1) || !mode->vdisplay || + mode->hdisplay > 3840 || mode->vdisplay > 2160 || + uint64_t(mode->hdisplay) * mode->vdisplay < 5 * 3072u || +- (mode->flags & (DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLSCAN))) ++ mode->vscan > 1 || ++ (mode->flags & (DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_3D_MASK))) + return 0.0; + const double rate = mode->htotal && mode->vtotal + ? mode->clock * 1000.0 / mode->htotal / mode->vtotal +@@ -1038,7 +1039,7 @@ std::vector CWinSystemGbm::GetDVOutputTimings() c + { + const auto* mode = connector->GetModeForIndex(index); + const double refresh = DVOutputTimingRate(mode); +- if (refresh > 0.0 && !(mode->flags & DRM_MODE_FLAG_3D_MASK) && mode->vscan <= 1) ++ if (refresh > 0.0) + timings.push_back({index, mode->hdisplay, mode->vdisplay, refresh}); + } + return timings; +diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +index 9cc88ca..d78c422 100644 +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp +@@ -1858,12 +1858,8 @@ void CWinSystemGbmGLESContext::RefreshDVOutputCapabilities() + } + } + +-bool CWinSystemGbmGLESContext::SupportsDVOutputTiming(RESOLUTION resolution) const ++bool CWinSystemGbmGLESContext::SupportsDVOutputTiming(const RESOLUTION_INFO& mode) const + { +- if (resolution < RES_DESKTOP) +- return false; +- +- const auto mode = CDisplaySettings::GetInstance().GetResolutionInfoCopy(resolution); + if (mode.dwFlags & D3DPRESENTFLAG_MODEMASK) + return false; + +@@ -1883,13 +1879,12 @@ bool CWinSystemGbmGLESContext::SupportsDVOutputTiming(RESOLUTION resolution) con + + RESOLUTION CWinSystemGbmGLESContext::ChooseHDR10FallbackResolution(RESOLUTION chosen) const + { ++ const auto& display = CDisplaySettings::GetInstance(); ++ const auto original = display.GetResolutionInfoCopy(chosen); + const auto advanced = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings(); +- if (SupportsDVOutputTiming(chosen) || CResolutionUtils::HasWhitelist() || ++ if (SupportsDVOutputTiming(original) || CResolutionUtils::HasWhitelist() || + !advanced->m_videoAdjustRefreshOverrides.empty()) + return chosen; +- +- const auto& display = CDisplaySettings::GetInstance(); +- const auto original = display.GetResolutionInfoCopy(chosen); + std::vector candidates; + GetGfxContext().GetAllowedResolutions(candidates); + RESOLUTION best = chosen; +@@ -1898,7 +1893,7 @@ RESOLUTION CWinSystemGbmGLESContext::ChooseHDR10FallbackResolution(RESOLUTION ch + { + const auto mode = display.GetResolutionInfoCopy(candidate); + if (std::abs(mode.fRefreshRate - original.fRefreshRate) < 0.01f && +- SupportsDVOutputTiming(candidate)) ++ SupportsDVOutputTiming(mode)) + { + const int area = mode.iScreenWidth * mode.iScreenHeight; + if (area > bestArea) +@@ -1958,7 +1953,7 @@ std::optional CWinSystemGbmGLESContext::PlayerLedResolution(double f + std::optional rejected; + for (size_t index = RES_DESKTOP; index < settings.ResolutionInfoSize(); ++index) + { +- const auto& mode = settings.GetResolutionInfo(index); ++ const auto mode = settings.GetResolutionInfoCopy(static_cast(index)); + if (mode.iWidth == 3840 && mode.iHeight == 2160 && + mode.iScreenWidth == 3840 && mode.iScreenHeight == 2160 && + std::abs(mode.fRefreshRate - wanted) < 0.01 && +@@ -1976,26 +1971,45 @@ std::optional CWinSystemGbmGLESContext::PlayerLedResolution(double f + + int CWinSystemGbmGLESContext::PlayerLedResolutionReason(RESOLUTION resolution, int preference) const + { ++ const auto id = CDisplaySettings::GetInstance().GetResolutionInfoCopy(resolution).strId; ++ int modeIndex = -1; ++ const auto end = id.data() + id.size(); ++ const auto parsed = std::from_chars(id.data(), end, modeIndex); ++ const bool validIndex = parsed.ec == std::errc{} && parsed.ptr == end && modeIndex >= 0; ++ + std::lock_guard lock(m_dvCapabilityMutex); + if (resolution == RES_INVALID) + return DVBRIDGE::LldvUnavailableLabel(m_dvLldvStatus, preference, false); + +- const auto& id = CDisplaySettings::GetInstance().GetResolutionInfo(resolution).strId; +- int modeIndex = -1; +- const auto end = id.data() + id.size(); +- const auto parsed = std::from_chars(id.data(), end, modeIndex); +- if (parsed.ec != std::errc{} || parsed.ptr != end || modeIndex < 0) +- return 41212; + const auto& modes = m_dvLldvStatus.modeRejections; +- const auto mode = std::ranges::find(modes, modeIndex, &std::pair::first); +- if (mode == modes.end()) +- return 41212; ++ const auto mode = validIndex ? std::ranges::find(modes, modeIndex, &std::pair::first) ++ : modes.end(); + auto target = m_dvLldvStatus; +- target.currentTiming = true; +- target.currentRejected = mode->second; ++ target.currentTiming = mode != modes.end(); ++ target.currentRejected = target.currentTiming ? mode->second : 0; + return DVBRIDGE::LldvUnavailableLabel(target, preference, false); + } + ++std::optional CWinSystemGbmGLESContext::PlayerLedStartupHDR10Resolution( ++ RESOLUTION resolution, int preference) const ++{ ++ constexpr int timingUnavailable = 41212; ++ const int reason = PlayerLedResolutionReason(resolution, preference); ++ if (reason != DVBRIDGE::LLDV_DRIVER_REJECTED_LABEL && reason != timingUnavailable) ++ return std::nullopt; ++ ++ const bool allowModeSwitch = resolution != RES_INVALID; ++ const auto target = allowModeSwitch ? ChooseHDR10FallbackResolution(resolution) : RES_INVALID; ++ if (allowModeSwitch && ++ !SupportsDVOutputTiming(CDisplaySettings::GetInstance().GetResolutionInfoCopy(target))) ++ return std::nullopt; ++ ++ const auto caps = GetDVOutputCapabilities(nullptr, allowModeSwitch); ++ if (!caps.hdr10 || caps.HDR10DepthLimited()) ++ return std::nullopt; ++ return target; ++} ++ + bool CWinSystemGbmGLESContext::CompleteDVModeSwitch(const VideoPicture& picture) + { + auto drm = std::dynamic_pointer_cast(m_DRM); +diff --git a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +index d03f1f4..faf85ba 100644 +--- a/xbmc/windowing/gbm/WinSystemGbmGLESContext.h ++++ b/xbmc/windowing/gbm/WinSystemGbmGLESContext.h +@@ -96,11 +96,13 @@ public: + DVBRIDGE::OutputCapabilities GetDVOutputCapabilities(const VideoPicture* picture, + bool allowModeSwitch = false) const; + bool CanRetainDVSource() const; +- bool SupportsDVOutputTiming(RESOLUTION resolution) const; ++ bool SupportsDVOutputTiming(const RESOLUTION_INFO& mode) const; + RESOLUTION ChooseHDR10FallbackResolution(RESOLUTION chosen) const; + bool CompleteDVModeSwitch(const VideoPicture& picture); + std::optional PlayerLedResolution(double fps, bool atStartup = false) const; + int PlayerLedResolutionReason(RESOLUTION resolution, int preference) const; ++ std::optional PlayerLedStartupHDR10Resolution(RESOLUTION resolution, ++ int preference) const; + bool LldvSupportsPlaybackTiming(double fps, bool requireCurrentMode = false) const; + bool DVModeSwitchDeferred() + { diff --git a/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-reuse-gbm-front-buffer.patch b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-reuse-gbm-front-buffer.patch new file mode 100644 index 0000000000..e4eb9d2bd8 --- /dev/null +++ b/projects/Generic/patches/kodi/kodi-9999-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-reuse-gbm-front-buffer.patch @@ -0,0 +1,41 @@ +diff --git a/xbmc/windowing/gbm/GBMUtils.h b/xbmc/windowing/gbm/GBMUtils.h +--- a/xbmc/windowing/gbm/GBMUtils.h ++++ b/xbmc/windowing/gbm/GBMUtils.h +@@ -143,6 +143,8 @@ + * @return CGBMSurfaceBuffer* A pointer to a CGBMSurfaceBuffer object + */ + CGBMSurfaceBuffer& LockFrontBuffer(); ++ // Reuse the front buffer when the drawable has not swapped again. ++ gbm_bo* GetLockedFrontBuffer() const; + + // Blocking atomic presentation only: retain the current scanout on failure. + gbm_bo* LockTransactionalBuffer(); +diff --git a/xbmc/windowing/gbm/GBMUtils.cpp b/xbmc/windowing/gbm/GBMUtils.cpp +--- a/xbmc/windowing/gbm/GBMUtils.cpp ++++ b/xbmc/windowing/gbm/GBMUtils.cpp +@@ -114,6 +114,13 @@ + return *m_buffers.back(); + } + ++gbm_bo* CGBMUtils::CGBMDevice::CGBMSurface::GetLockedFrontBuffer() const ++{ ++ if (!m_buffers.empty()) ++ return m_buffers.back()->Get(); ++ return m_scanoutBuffer ? m_scanoutBuffer->Get() : nullptr; ++} ++ + CGBMUtils::CGBMDevice::CGBMSurface::CGBMSurfaceBuffer::CGBMSurfaceBuffer(gbm_surface* surface) + : m_surface(surface), m_buffer(gbm_surface_lock_front_buffer(surface)) + { +diff --git a/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp b/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp +--- a/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp ++++ b/xbmc/windowing/gbm/WinSystemGbmEGLContext.cpp +@@ -431,7 +431,7 @@ + if (!m_dvOutputSurface && HasFloatOutput()) + { + auto drm = std::dynamic_pointer_cast(m_DRM); +- if (!drm || !drm->TestFramebuffer(m_GBM->GetDevice().GetSurface().LockFrontBuffer().Get())) ++ if (!drm || !drm->TestFramebuffer(m_GBM->GetDevice().GetSurface().GetLockedFrontBuffer())) + return reject(); + } + // No new drawable exists when only a same-format policy value changes. diff --git a/projects/Generic/patches/linux/0103-wifi-mt76-mt7925-keep-join-roc-until-authorized.patch b/projects/Generic/patches/linux/0103-wifi-mt76-mt7925-keep-join-roc-until-authorized.patch new file mode 100644 index 0000000000..22749db621 --- /dev/null +++ b/projects/Generic/patches/linux/0103-wifi-mt76-mt7925-keep-join-roc-until-authorized.patch @@ -0,0 +1,104 @@ +From ac22c8c723c62013dd45b74e32249fc877c86fe0 Mon Sep 17 00:00:00 2001 +From: Mark Anthony Agarro +Date: Mon, 5 Oct 2026 20:14:25 -0700 +Subject: [PATCH] wifi: mt76: mt7925: keep the join ROC until the station is + authorized + +When a non-MLO station associates, mgd_complete_tx() aborts the join ROC +as soon as the association succeeds, which is right before the supplicant +sends message 2 of the 4-way handshake. With the abort that close to +message 2, the adapter acknowledges nothing the AP sends for the next +several ms: the AP sends message 3 and its seven retries within about +5 ms, none is acknowledged, and the handshake ends with reason 15 +(4WAY_HANDSHAKE_TIMEOUT). + +Keep the ROC after a successful (re)association on a non-MLD station +interface and release it when the station is authorized, on +disassociation, or when the station is removed. The ROC timer still ends +it if none of that happens. MLD interfaces keep the old behaviour: there +the ROC that is active at this point is the MLO ROC set up by +mt7925_mac_set_links(), and holding it makes mt7925_set_mlo_roc() fail +with -EBUSY in the link activation work, which leaves one link instead of +two. + +Tested by a reporter on an MT7925U (USB) against a FRITZ!Box 5690 Pro on +a 6 GHz-only, non-MLO SSID, kernel 7.2.3, from traces and monitor +captures taken in separate runs: + + handshakes first M3 acked abort before M2 + unpatched 8 of 84 0 of 83 84 of 84 + this patch 30 of 30 31 of 31 0 of 30 + +With the patch the AP sends message 3 once and the adapter acknowledges +it straight away; the ROC is released right after the station is +authorized. A 20 ms delay after the abort instead of this change gave +15 of 15, which points at the abort timing and not at the delay. + +Tested here on an MT7925 and an MT7927 (PCIe), kernel 7.3.0-rc4: on a +non-MLO SSID neither build showed the failure (1 stalled handshake in 110 +unpatched, none patched), so no effect could be measured there. On an MLO +connection the change is inert: 16 of 16 link activations succeeded in +two rounds per build, with two active links and the same ROC order as +before. + +Not tested: other APs, other USB parts, MT7927 over USB, MLO connections +beyond the check above. + +Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") +Reported-by: Mark Junker +Closes: https://github.com/morrownr/mt76/issues/106 +Tested-by: Mark Junker +Signed-off-by: Mark Anthony Agarro +Signed-off-by: Devin Wittmayer +Link: https://patch.msgid.link/20261006031425.20922-1-lucid_duck@justthetip.ca +Signed-off-by: Felix Fietkau +--- + drivers/net/wireless/mediatek/mt76/mt7925/main.c | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) + +diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c +index 9f080da..0adca55 100644 +--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c ++++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c +@@ -1220,6 +1220,13 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, + struct ieee80211_sta *sta, enum mt76_sta_event ev) + { + struct ieee80211_link_sta *link_sta = &sta->deflink; ++ struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; ++ ++ if (mvif->roc_join_held && !sta->tdls && ++ (ev == MT76_STA_EVENT_AUTHORIZE || ev == MT76_STA_EVENT_DISASSOC)) { ++ mvif->roc_join_held = false; ++ mt7925_abort_roc(mvif->phy, &mvif->bss_conf); ++ } + + if (ev != MT76_STA_EVENT_ASSOC) + return 0; +@@ -1369,6 +1376,7 @@ void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, + + if (vif->type == NL80211_IFTYPE_STATION) { + mvif->wep_sta = NULL; ++ mvif->roc_join_held = false; + ewma_rssi_init(&mvif->bss_conf.rssi); + } + +@@ -2020,6 +2028,19 @@ static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw, + { + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + ++ /* Keep the join ROC until the station is authorized, so that it ++ * covers the 4-way handshake. mt7925_mac_sta_event() releases it. ++ * On MLD, the active ROC is the MLO ROC, which must be released ++ * before the link activation work sets its own. ++ */ ++ if (vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) && ++ info->success && ++ (info->subtype == IEEE80211_STYPE_ASSOC_REQ || ++ info->subtype == IEEE80211_STYPE_REASSOC_REQ)) { ++ mvif->roc_join_held = true; ++ return; ++ } ++ + mt7925_abort_roc(mvif->phy, &mvif->bss_conf); + } + diff --git a/projects/Generic/patches/linux/0104-wifi-mt76-mt7925-track-join-roc-ownership.patch b/projects/Generic/patches/linux/0104-wifi-mt76-mt7925-track-join-roc-ownership.patch new file mode 100644 index 0000000000..d5a84d9c36 --- /dev/null +++ b/projects/Generic/patches/linux/0104-wifi-mt76-mt7925-track-join-roc-ownership.patch @@ -0,0 +1,199 @@ +mt76: mt7925: release only the active non-MLO association grant + +Linux 7.2.6 can authorize an open station before mgd_complete_tx(). +Remember the successful association grant at prepare time. Its firmware +timer and any later grant invalidate that ownership before a delayed +authorization can cancel an off-channel request. Serialize expiry with +grant allocation, including a timer worker delayed past the next grant. + +diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c +--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c ++++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c +@@ -511,19 +511,28 @@ + void mt7925_roc_work(struct work_struct *work) + { + struct mt792x_phy *phy; ++ bool notify; + + phy = (struct mt792x_phy *)container_of(work, struct mt792x_phy, + roc_work); + +- if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) ++ mt792x_mutex_acquire(phy->dev); ++ /* An earlier timer's worker may run after a new grant. */ ++ if (timer_pending(&phy->roc_timer) || ++ !test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) { ++ mt792x_mutex_release(phy->dev); + return; +- +- mt792x_mutex_acquire(phy->dev); ++ } ++ ++ /* Managed association does not request a mac80211 off-channel ROC. */ ++ notify = !phy->roc_join_owner; ++ phy->roc_join_owner = NULL; + ieee80211_iterate_active_interfaces(phy->mt76->hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7925_roc_iter, phy); + mt792x_mutex_release(phy->dev); +- ieee80211_remain_on_channel_expired(phy->mt76->hw); ++ if (notify) ++ ieee80211_remain_on_channel_expired(phy->mt76->hw); + } + + static int mt7925_abort_roc(struct mt792x_phy *phy, +@@ -540,6 +549,29 @@ + mt792x_mutex_release(phy->dev); + + return err; ++} ++ ++/* Only the association which acquired the PHY may release its channel. */ ++static void mt7925_abort_join_roc(struct mt792x_vif *mvif) ++{ ++ struct mt792x_phy *phy = mvif->phy; ++ ++ mt792x_mutex_acquire(phy->dev); ++ if (phy->roc_join_owner == &mvif->bss_conf && ++ test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state)) { ++ phy->roc_join_owner = NULL; ++ timer_delete_sync(&phy->roc_timer); ++ mt7925_mcu_abort_roc(phy, &mvif->bss_conf, phy->roc_token_id); ++ } ++ mt792x_mutex_release(phy->dev); ++} ++ ++static bool mt7925_is_legacy_assoc(struct ieee80211_vif *vif, ++ struct ieee80211_prep_tx_info *info) ++{ ++ return vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) && ++ (info->subtype == IEEE80211_STYPE_ASSOC_REQ || ++ info->subtype == IEEE80211_STYPE_REASSOC_REQ); + } + + static int mt7925_set_roc(struct mt792x_phy *phy, +@@ -553,6 +585,7 @@ + if (test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state)) + return -EBUSY; + ++ phy->roc_join_owner = NULL; + phy->roc_grant = false; + + err = mt7925_mcu_set_roc(phy, mconf, chan, duration, type, +@@ -562,7 +595,7 @@ + goto out; + } + +- if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) { ++ if (!wait_event_timeout(phy->roc_wait, smp_load_acquire(&phy->roc_grant), 4 * HZ)) { + mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id); + clear_bit(MT76_STATE_ROC, &phy->mt76->state); + err = -ETIMEDOUT; +@@ -581,6 +614,7 @@ + if (WARN_ON_ONCE(test_and_set_bit(MT76_STATE_ROC, &phy->mt76->state))) + return -EBUSY; + ++ phy->roc_join_owner = NULL; + phy->roc_grant = false; + + err = mt7925_mcu_set_mlo_roc(phy, mconf, sel_links, 5, ++phy->roc_token_id); +@@ -589,7 +623,7 @@ + goto out; + } + +- if (!wait_event_timeout(phy->roc_wait, phy->roc_grant, 4 * HZ)) { ++ if (!wait_event_timeout(phy->roc_wait, smp_load_acquire(&phy->roc_grant), 4 * HZ)) { + mt7925_mcu_abort_roc(phy, mconf, phy->roc_token_id); + clear_bit(MT76_STATE_ROC, &phy->mt76->state); + err = -ETIMEDOUT; +@@ -1222,11 +1256,9 @@ + struct ieee80211_link_sta *link_sta = &sta->deflink; + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + +- if (mvif->roc_join_held && !sta->tdls && +- (ev == MT76_STA_EVENT_AUTHORIZE || ev == MT76_STA_EVENT_DISASSOC)) { +- mvif->roc_join_held = false; +- mt7925_abort_roc(mvif->phy, &mvif->bss_conf); +- } ++ if (!sta->tdls && ++ (ev == MT76_STA_EVENT_AUTHORIZE || ev == MT76_STA_EVENT_DISASSOC)) ++ mt7925_abort_join_roc(mvif); + + if (ev != MT76_STA_EVENT_ASSOC) + return 0; +@@ -1376,7 +1408,6 @@ + + if (vif->type == NL80211_IFTYPE_STATION) { + mvif->wep_sta = NULL; +- mvif->roc_join_held = false; + ewma_rssi_init(&mvif->bss_conf.rssi); + } + +@@ -2014,11 +2045,15 @@ + struct mt792x_dev *dev = mt792x_hw_dev(hw); + u16 duration = info->duration ? info->duration : + jiffies_to_msecs(HZ); ++ int err; + + mt792x_mutex_acquire(dev); +- mt7925_set_roc(mvif->phy, &mvif->bss_conf, +- mvif->bss_conf.mt76.ctx->def.chan, duration, +- MT7925_ROC_REQ_JOIN); ++ err = mt7925_set_roc(mvif->phy, &mvif->bss_conf, ++ mvif->bss_conf.mt76.ctx->def.chan, duration, ++ MT7925_ROC_REQ_JOIN); ++ /* Open networks can authorize before mgd_complete_tx(). */ ++ if (!err && mt7925_is_legacy_assoc(vif, info)) ++ mvif->phy->roc_join_owner = &mvif->bss_conf; + mt792x_mutex_release(dev); + } + +@@ -2028,16 +2063,9 @@ + { + struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + +- /* Keep the join ROC until the station is authorized, so that it +- * covers the 4-way handshake. mt7925_mac_sta_event() releases it. +- * On MLD, the active ROC is the MLO ROC, which must be released +- * before the link activation work sets its own. +- */ +- if (vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) && +- info->success && +- (info->subtype == IEEE80211_STYPE_ASSOC_REQ || +- info->subtype == IEEE80211_STYPE_REASSOC_REQ)) { +- mvif->roc_join_held = true; ++ if (mt7925_is_legacy_assoc(vif, info)) { ++ if (!info->success) ++ mt7925_abort_join_roc(mvif); + return; + } + +diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c ++++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +@@ -331,11 +331,12 @@ + ieee80211_iterate_active_interfaces_atomic(hw, + IEEE80211_IFACE_ITER_RESUME_ALL, + mt7925_mcu_roc_iter, grant); +- dev->phy.roc_grant = true; +- wake_up(&dev->phy.roc_wait); + duration = le32_to_cpu(grant->max_interval); + mod_timer(&dev->phy.roc_timer, + jiffies + msecs_to_jiffies(duration)); ++ /* Expiry work checks this timer when the waiter releases the mutex. */ ++ smp_store_release(&dev->phy.roc_grant, true); ++ wake_up(&dev->phy.roc_wait); + } + + static void +diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h +--- a/drivers/net/wireless/mediatek/mt76/mt792x.h ++++ b/drivers/net/wireless/mediatek/mt76/mt792x.h +@@ -226,6 +226,7 @@ + struct work_struct roc_work; + struct timer_list roc_timer; + wait_queue_head_t roc_wait; ++ struct mt792x_bss_conf *roc_join_owner; /* MT7925 non-MLO association */ + u8 roc_token_id; + bool roc_grant; + }; diff --git a/projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch b/projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch index a7e882c48c..6fc73c2d0b 100644 --- a/projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch +++ b/projects/Generic/patches/linux/linux-9949-intel-hdmi-pin-out.patch @@ -1,33 +1,55 @@ -diff --git a/sound/hda/codecs/hdmi/intelhdmi.c b/sound/hda/codecs/hdmi/intelhdmi.c ---- a/sound/hda/codecs/hdmi/intelhdmi.c -+++ b/sound/hda/codecs/hdmi/intelhdmi.c -@@ -481,9 +481,26 @@ - hda_nid_t cvt_nid) - { - if (per_pin) { -- haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid); -- snd_hda_set_dev_select(codec, per_pin->pin_nid, -- per_pin->dev_id); -+ struct hdmi_spec *spec = codec->spec; -+ hda_nid_t pin = per_pin->pin_nid; -+ int err; +diff --git a/sound/hda/codecs/hdmi/hdmi.c b/sound/hda/codecs/hdmi/hdmi.c +--- a/sound/hda/codecs/hdmi/hdmi.c ++++ b/sound/hda/codecs/hdmi/hdmi.c +@@ -1130,6 +1130,34 @@ + return NULL; + } + ++/* A link change can reset an active Alder Lake-P HDMI audio pin. */ ++static void adlp_restore_pin_out(struct hda_codec *codec, ++ struct hdmi_spec_per_pin *per_pin) ++{ ++ struct hdmi_spec *spec = codec->spec; ++ hda_nid_t pin = per_pin->pin_nid; ++ int ctl; + -+ haswell_verify_D0(codec, per_pin->cvt_nid, pin); -+ err = snd_hda_set_dev_select(codec, pin, per_pin->dev_id); ++ if (codec->core.vendor_id != 0x8086281c || !per_pin->setup || !per_pin->channels || ++ !per_pin->sink_eld.eld_valid || per_pin->pcm_idx < 0 || ++ !test_bit(per_pin->pcm_idx, &spec->pcm_in_use)) ++ return; + -+ /* Alder Lake-P can lose output enable when the HDMI link changes. */ -+ if (codec->core.vendor_id == 0x8086281c && !err && -+ per_pin->sink_eld.eld_valid && per_pin->pcm_idx >= 0 && -+ test_bit(per_pin->pcm_idx, &spec->pcm_in_use) && -+ snd_hda_get_dev_select(codec, pin) == per_pin->dev_id) { -+ int ctl = snd_hda_codec_read(codec, pin, 0, -+ AC_VERB_GET_PIN_WIDGET_CONTROL, 0); ++ if (snd_hda_set_dev_select(codec, pin, per_pin->dev_id)) ++ return; + -+ if (ctl >= 0 && !(ctl & PIN_OUT)) -+ snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, -+ ctl | PIN_OUT); -+ } ++ /* A single-entry HDMI pin has no device selector to read back. */ ++ if (snd_hda_get_dev_select(codec, pin) != per_pin->dev_id && ++ (per_pin->dev_id || per_pin->sink_eld.info.conn_type != 0 || ++ snd_hdac_read_parm_uncached(&codec->core, pin, AC_PAR_DEVLIST_LEN) != 0)) ++ return; + - intel_verify_pin_cvt_connect(codec, per_pin); - intel_not_share_assigned_cvt(codec, per_pin->pin_nid, - per_pin->dev_id, per_pin->mux_idx); ++ ctl = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); ++ if (ctl >= 0 && !(ctl & PIN_OUT)) ++ snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, ++ ctl | PIN_OUT); ++} ++ + /* update per_pin ELD from the given new ELD; + * setup info frame and notification accordingly + * also notify ELD kctl and report jack status changes +@@ -1222,6 +1250,8 @@ + pin_cvt_fixup(codec, per_pin, 0); + snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); + } ++ ++ adlp_restore_pin_out(codec, per_pin); + + if (eld_changed && pcm_idx >= 0) + snd_ctl_notify(codec->card, +@@ -1700,6 +1730,7 @@ + } + + snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); ++ adlp_restore_pin_out(codec, per_pin); + } + if (spec->dyn_pin_out) { + snd_hda_set_dev_select(codec, per_pin->pin_nid, diff --git a/tests/cb1/gbm_colour_buffer.cpp b/tests/cb1/gbm_colour_buffer.cpp index e659ec86d2..018abc00c9 100644 --- a/tests/cb1/gbm_colour_buffer.cpp +++ b/tests/cb1/gbm_colour_buffer.cpp @@ -135,6 +135,12 @@ struct Window { std::shared_ptr m_DRM=std::make_shared(); std::shared_ptr m_GBM=std::make_shared(); std::shared_ptr m_videoLayerBridge; + bool m_nativeSDRActive=false,m_nativeSDRSubmitted=false,m_nativeSDRRejected=false; + std::optional m_queuedColorspace; + bool StageNativeSDRSignal(bool rendered, bool& wideTransition) { + wideTransition=rendered && m_nativeSDRActive && static_cast(*m_DRM).range; + return true; + } bool ConnectorPreferencesAllowed(){return true;} void DeferConnectorPreferences(){assert(false);} void UpdateDriverLimitedRange(){}void RetryConnectorProperties(){} @@ -179,6 +185,17 @@ int main(){ assert(drm->calls==calls&&window.m_GBM->m_pendingBuffer->Get()==borrowed); assert(CServiceBroker::GetGUI()->dirty==dirty+1); window.m_GBM->CompleteTransactionalBuffer(false); + window.m_nativeSDRActive=true; + window.FlipPage(true,false,true); + assert(window.m_nativeSDRSubmitted); + auto* previousWide=displayed; + drm->range=true;drm->accept=false; + window.FlipPage(true,false,true); + assert(displayed==previousWide && previousWide->locked); + assert(window.m_nativeSDRRejected && "a refused new gamut tag needs fallback after an accepted wide frame"); + window.m_nativeSDRActive=false;drm->range=true;drm->accept=true; + window.FlipPage(true,false,true); + assert(displayed!=previousWide && !window.m_nativeSDRSubmitted); using namespace DVBRIDGE; CDVBridgeState state; auto* before=displayed; diff --git a/tests/cb1/gbm_colour_owner.cpp b/tests/cb1/gbm_colour_owner.cpp index ea3d4c01d9..f88a0969e3 100644 --- a/tests/cb1/gbm_colour_owner.cpp +++ b/tests/cb1/gbm_colour_owner.cpp @@ -20,8 +20,9 @@ struct CSettings {static constexpr const char* SETTING_VIDEOSCREEN_LIMITEDRANGE= namespace KODI::MESSAGING {struct ThreadMessageCallback {void (*callback)(void*);void* owner;};} struct Setting {bool defaultValue=true;bool IsDefault() const {return defaultValue;}}; struct Settings { - bool legacy=false;std::map values;Setting range; - bool GetBool(const char*) const {return legacy;}int GetInt(const char* id){return values[id];} + bool legacy=false,cms=false;std::map values;Setting range; + bool GetBool(std::string_view id) const {return id=="videoscreen.cmsenabled" ? cms : legacy;} + int GetInt(const char* id){return values[id];} std::shared_ptr GetSetting(const char*) {return std::shared_ptr(&range,[](auto*){});} void SetInt(const char* id,int value) {values[id]=value;range.defaultValue=false;} void SetBool(const char*,bool value) {legacy=value;} @@ -35,7 +36,8 @@ struct CDRMConnector { std::map> enums{ {"Broadcast RGB",{{"Automatic",0},{"Full",1},{"Limited 16:235",2}}}, {"color format",{{"AUTO",0},{"RGB",1},{"YUV 4:4:4",2},{"YUV 4:2:2",3},{"YUV 4:2:0",4}}}}; - std::string type="HDMI-A";int frl=0;uint32_t highestClock=594000;bool immutable=false; + std::string type="HDMI-A";int frl=0;uint32_t highestClock=594000;bool immutable=false,connected=true; + bool IsConnected() const {return connected;} bool SupportsProperty(const char* property) const {return cache.count(property);} std::optional GetPropertyValue(const char* property) const { auto it=cache.find(property);if(it==cache.end()) return {};return it->second;} @@ -50,6 +52,8 @@ struct CDRMConnector { }; struct CDRMUtils { virtual ~CDRMUtils()=default;CDRMConnector connector;uint32_t clock=594000; + bool videoPlane=true,guiPlane=false; + bool GetVideoPlane() const {return videoPlane;} bool GetGuiPlane() const {return guiPlane;} bool fellBack=false;int modesets=0; CDRMConnector* GetConnector() {return &connector;} virtual bool LastCommitFellBack() const {return fellBack;} @@ -60,7 +64,10 @@ struct CDRMAtomic : CDRMUtils { std::map pending;bool accepted=true,addSuccess=true; bool AddProperty(CDRMConnector*,const char* name,uint64_t value) { if(!addSuccess)return false;pending[name]=value;return true;} - bool rangeTransition=false;void SetColorRangeTransition(){rangeTransition=true;} + bool modeCommitted=true; + bool rangeTransition=false; + bool IsSelectedModeCommitted() const {return modeCommitted;} + void SetColorRangeTransition(){rangeTransition=true;} bool LastPageAccepted() const {return accepted;} void SetActive(bool) {} void Commit(bool accept,bool fallback=false) { accepted=accept;fellBack=fallback; @@ -72,15 +79,31 @@ enum class Colorimetry {DEFAULT,SMPTE_170M_YCC,BT709_YCC,XVYCC_601,XVYCC_709,SYC const char* ColorimetryToString(Colorimetry) {return "colorimetry";} } enum class StreamHdrType {HDR_TYPE_NONE, HDR_TYPE_HDR10}; -constexpr int AVCOL_TRC_SMPTE2084=16, AVCOL_TRC_ARIB_STD_B67=18; -struct VideoPicture {int colorBits=10;StreamHdrType hdrType=StreamHdrType::HDR_TYPE_NONE;int color_transfer=1;KODI::UTILS::Colorimetry color=KODI::UTILS::Colorimetry::BT2020_YCC;}; +constexpr int AVCOL_TRC_BT2020_10=14, AVCOL_TRC_SMPTE2084=16, AVCOL_TRC_ARIB_STD_B67=18; +constexpr int AVCOL_PRI_BT709=1, AVCOL_PRI_BT2020=9; +struct VideoPicture {int colorBits=10;StreamHdrType hdrType=StreamHdrType::HDR_TYPE_NONE;int color_transfer=1; + int color_primaries=AVCOL_PRI_BT2020;KODI::UTILS::Colorimetry color=KODI::UTILS::Colorimetry::BT2020_YCC;}; namespace KODI::UTILS {Colorimetry GetColorimetry(const VideoPicture& picture){return picture.color;}} +struct DisplayInfo { + bool wideRgb=true,wideYcc=true; + bool SupportsColorimetry(KODI::UTILS::Colorimetry color) const { + return color==KODI::UTILS::Colorimetry::BT2020_RGB ? wideRgb : wideYcc;} +}; template std::map make_map(std::initializer_list> values) {return {values};} // NATIVE_CONSTANTS struct CWinSystemGbm { bool allowed=true;int colorSpaceApplications=0; std::shared_ptr m_DRM=std::make_shared();Blob m_hdrBlob; bool ConnectorPreferencesAllowed() const {return allowed;} + bool BeginFrameGuiComposite(bool); + std::unique_ptr m_info=std::make_unique(); + bool compositorAvailable=true,fboAvailable=true; + int guiTransfer=0; + struct RenderSystem {int refreshes=0;void UpdateGUIShaderColorState(){++refreshes;}} gui; + RenderSystem* GetRenderSystem() {return &gui;} + bool SetGuiCompositing(int transfer) {guiTransfer=compositorAvailable ? transfer : 0;return guiTransfer;} + bool BeginGuiComposite(bool) {return IsHdrComposite() && fboAvailable;} + bool IsHdrComposite() const {return guiTransfer!=0;} void DeferConnectorPreferences();bool UseLimitedColor();void ApplyColorspace();void SetColorimetry(const VideoPicture*, bool sdrToBT709=false); std::optional m_queuedColorspace; @@ -110,6 +133,61 @@ int main() { assert(drm->pending.at("Colorspace")==3 && "BT.709 pixels need BT.709 YCbCr signalling"); w.m_colorFormat=1;w.ApplyConnectorProperties();w.SetColorimetry(&picture, true); assert(drm->pending.at("Colorspace")==0 && "BT.709 RGB must not carry a BT.2020 tag"); + CWinSystemGbm wide; + auto wd=std::dynamic_pointer_cast(wide.m_DRM); + wd->connector.cache["Colorspace"]=0; + wd->connector.enums["Colorspace"]=drm->connector.enums["Colorspace"]; + wide.SetColorimetry(&picture, true); + bool wideTransition=false; + assert(wide.BeginFrameGuiComposite(true) && wide.m_nativeSDRActive); + assert(wide.gui.refreshes==1); + assert(wide.StageNativeSDRSignal(true, wideTransition)); + assert(wd->pending.at("Colorspace")==1 && wd->rangeTransition && wideTransition); + wd->Commit(true); + wide.m_nativeSDRSubmitted=true; + assert(wide.StageNativeSDRSignal(true, wideTransition) && !wideTransition && !wd->rangeTransition); + wd->modeCommitted=false; + assert(wide.StageNativeSDRSignal(true, wideTransition) && wideTransition && wd->rangeTransition); + wd->modeCommitted=true; + wd->Commit(true); + wide.m_colorFormat=3; + wide.ApplyConnectorProperties(); + assert(wide.BeginFrameGuiComposite(true) && wide.StageNativeSDRSignal(true, wideTransition)); + assert(wide.gui.refreshes==1); + assert(wd->pending.at("Colorspace")==2 && wd->rangeTransition && wideTransition); + wd->Commit(true); + // The requested wire encoding needs matching display and connector support. + wide.m_info->wideYcc=false; + assert(!wide.BeginFrameGuiComposite(true) && !wide.m_nativeSDRActive); + assert(wide.gui.refreshes==2); + assert(wide.StageNativeSDRSignal(true, wideTransition) && wd->pending.at("Colorspace")==3 && wd->rangeTransition && !wideTransition); + wd->Commit(true); + wide.m_nativeSDRSubmitted=false; + wide.m_info->wideYcc=true; + wd->connector.enums["Colorspace"].erase("BT2020_YCC"); + assert(!wide.BeginFrameGuiComposite(true) && wide.StageNativeSDRSignal(true, wideTransition)); + wide.m_colorFormat=1;wide.ApplyConnectorProperties(); + wd->connector.connected=false; + assert(!wide.BeginFrameGuiComposite(true)); + wd->connector.connected=true; + wd->guiPlane=true; + assert(!wide.BeginFrameGuiComposite(true)); + wd->guiPlane=false; + CServiceBroker::GetSettingsComponent()->cms=true; + assert(!wide.BeginFrameGuiComposite(true)); + CServiceBroker::GetSettingsComponent()->cms=false; + wide.fboAvailable=false; + assert(!wide.BeginFrameGuiComposite(true) && !wide.m_nativeSDRActive); + assert(wide.StageNativeSDRSignal(true, wideTransition) && wd->pending.at("Colorspace")==0); + wide.fboAvailable=true; + wide.SetColorimetry(&picture, true); + assert(wide.BeginFrameGuiComposite(true)); + wd->addSuccess=false; + assert(!wide.StageNativeSDRSignal(true, wideTransition)); + assert(!wide.BeginFrameGuiComposite(true) && !wide.m_nativeSDRActive); + wd->addSuccess=true; + wd->connector.cache["Colorspace"]=2; // The previous output was wide YCbCr. + assert(wide.StageNativeSDRSignal(true, wideTransition) && wd->pending.at("Colorspace")==0 && wd->rangeTransition); assert(w.m_contentBits==10); for (const int transfer : {AVCOL_TRC_SMPTE2084, AVCOL_TRC_ARIB_STD_B67}) { diff --git a/tests/cb1/mt7925_roc.c b/tests/cb1/mt7925_roc.c new file mode 100644 index 0000000000..892e86c734 --- /dev/null +++ b/tests/cb1/mt7925_roc.c @@ -0,0 +1,206 @@ +/* Compile with the replayed MT7925 callbacks inserted at DRIVER. */ +#include +#include +#include +#include +#include + +typedef unsigned char u8; +typedef unsigned short u16; +struct work_struct { int dummy; }; +struct ieee80211_channel { int dummy; }; +struct ieee80211_hw { int dummy; }; +struct mt76_phy { unsigned long state; struct ieee80211_hw *hw; }; +struct mt792x_phy { + struct mt76_phy *mt76; + struct mt792x_dev *dev; + struct work_struct roc_work; + bool roc_timer, roc_grant; + u8 roc_token_id; + struct mt792x_bss_conf *roc_join_owner; +}; +struct mt792x_dev { struct mt792x_phy phy; struct { struct ieee80211_hw *hw; } mt76; }; +struct mt76_dev { int dummy; }; +struct mt792x_bss_conf { + struct { struct context { struct { struct ieee80211_channel *chan; } def; } *ctx; } mt76; +}; +struct mt792x_vif { struct mt792x_bss_conf bss_conf; struct mt792x_phy *phy; bool roc_join_held; }; +struct ieee80211_vif { struct mt792x_vif *drv_priv; int type; bool mld; }; +struct ieee80211_sta { struct ieee80211_link_sta { int id; } deflink; bool tdls; void *drv_priv; }; +struct mt792x_sta { int deflink_id; }; +struct ieee80211_prep_tx_info { int subtype, duration; bool success; }; +enum mt76_sta_event { MT76_STA_EVENT_ASSOC, MT76_STA_EVENT_AUTHORIZE, MT76_STA_EVENT_DISASSOC }; +enum mt7925_roc_req { MT7925_ROC_REQ_JOIN, MT7925_ROC_REQ_ROC }; +enum ieee80211_roc_type { OFFCHANNEL }; +enum { IEEE80211_STYPE_ASSOC_REQ, IEEE80211_STYPE_REASSOC_REQ, NL80211_IFTYPE_STATION }; + +static struct mt792x_dev device; +static struct mt76_phy radio; +static struct context ctx; +static struct mt792x_vif ifdata[2]; +static struct ieee80211_vif vif[2]; +static bool locked, fail_grant, woke_without_timer, worker_running; +static int aborted, expired; +#define MT76_STATE_ROC 0 +#define HZ 1000 +#define jiffies_to_msecs(x) (x) +#define mt792x_hw_dev(...) (&device) +#define mt792x_hw_phy(...) (&device.phy) +#define mt76_hw(...) (radio.hw) +#define ieee80211_vif_is_mld(v) ((v)->mld) +#define mt792x_sta_to_link_sta(v,s,id) (&(s)->deflink) +#define mt7925_mac_set_links(...) ((void)0) +#define mt7925_mac_link_sta_assoc(...) ((void)0) +#define WARN_ON_ONCE(x) (x) +#define EXPORT_SYMBOL_GPL(x) +#define container_of(ptr,type,member) ((type *)((char *)(ptr) - offsetof(type,member))) +#define timer_delete_sync(timer) (*(timer) = false) +#define timer_pending(timer) (*(timer)) +#define cancel_work(work) ((void)0) +#define cancel_work_sync(work) do { assert(!locked); worker_running = false; } while (0) +#define mt792x_mutex_acquire(d) do { assert(!locked); locked = true; } while (0) +#define mt792x_mutex_release(d) do { assert(locked); locked = false; } while (0) +#define wait_event_timeout(q,cond,t) (cond) +#define test_and_clear_bit(bit,p) __atomic_exchange_n(p, 0, __ATOMIC_SEQ_CST) +#define test_and_set_bit(bit,p) __atomic_exchange_n(p, 1, __ATOMIC_SEQ_CST) +#define clear_bit(bit,p) (*(p) = 0) +#define ieee80211_remain_on_channel_expired(hw) (++expired) +#define ieee80211_iterate_interfaces(hw,flags,cb,data) cb(data, NULL, &vif[0]) +#define ieee80211_iterate_active_interfaces ieee80211_iterate_interfaces + +struct tlv { u16 tag; }; +struct mt7925_roc_grant_tlv { u16 tag, reqtype; int max_interval; }; +#define UNI_EVENT_ROC_GRANT 1 +#define le16_to_cpu(val) (val) +#define le32_to_cpu(val) (val) +#define jiffies 0 +#define msecs_to_jiffies(val) (val) +#define mod_timer(timer, deadline) (*(timer) = true) +#define smp_store_release(p,v) (*(p) = (v)) +#define smp_load_acquire(p) (*(p)) +#define ieee80211_ready_on_channel(hw) ((void)0) +#define ieee80211_iterate_active_interfaces_atomic(...) ((void)0) +#define wake_up(q) (woke_without_timer = !device.phy.roc_timer) + +/* GRANT */ + +static int mt7925_mcu_set_roc(struct mt792x_phy *p, struct mt792x_bss_conf *b, + struct ieee80211_channel *ch, int ms, int type, u8 token) { + assert(locked); + if (fail_grant) + return -EIO; + struct mt7925_roc_grant_tlv grant = { UNI_EVENT_ROC_GRANT, type, ms }; + mt7925_mcu_roc_handle_grant(p->dev, (struct tlv *)&grant); + return 0; +} +#define mt7925_mcu_set_mlo_roc(p,b,links,d,t) mt7925_mcu_set_roc(p,b,NULL,d,0,t) +static int mt7925_mcu_abort_roc(struct mt792x_phy *p, struct mt792x_bss_conf *b, u8 t) { + assert(locked && t == p->roc_token_id); + ++aborted; + return 0; +} + +/* DRIVER */ + +int main(int argc, char **argv) { + assert(argc == 2); + const char *s = argv[1]; + bool busy = !strcmp(s, "busy") || !strcmp(s, "busy-reject"); + struct ieee80211_prep_tx_info assoc = { + .subtype = !strcmp(s, "reassoc") ? IEEE80211_STYPE_REASSOC_REQ : IEEE80211_STYPE_ASSOC_REQ, + .success = strcmp(s, "rejected") && strcmp(s, "busy-reject"), + }; + struct ieee80211_sta sta = {0}; + device.phy.dev = &device; + device.phy.mt76 = &radio; + for (int i = 0; i < 2; ++i) { + ifdata[i].phy = &device.phy; + ifdata[i].bss_conf.mt76.ctx = &ctx; + vif[i].drv_priv = &ifdata[i]; + vif[i].type = NL80211_IFTYPE_STATION; + } + vif[0].mld = !strcmp(s, "mlo"); + fail_grant = !strcmp(s, "failed"); + if (busy) + assert(!mt7925_remain_on_channel(NULL, &vif[1], NULL, 50, OFFCHANNEL)); + mt7925_mgd_prepare_tx(NULL, &vif[0], &assoc); + if (!strcmp(s, "grant")) { + assert(!woke_without_timer); + return 0; + } + if (!strcmp(s, "open")) + mt7925_mac_sta_event(NULL, &vif[0], &sta, MT76_STA_EVENT_AUTHORIZE); + if (vif[0].mld) { + /* Link activation replaces the management ROC before completion. */ + mt7925_abort_roc(&device.phy, &ifdata[0].bss_conf); + mt792x_mutex_acquire(&device); + assert(!mt7925_set_mlo_roc(&device.phy, &ifdata[0].bss_conf, 3)); + mt792x_mutex_release(&device); + } + mt7925_mgd_complete_tx(NULL, &vif[0], &assoc); + + if (!strcmp(s, "open") || !strcmp(s, "mlo") || !strcmp(s, "rejected")) { + assert(!radio.state && !device.phy.roc_timer && aborted == (vif[0].mld ? 2 : 1)); + return 0; + } + if (fail_grant) { + assert(!radio.state && !aborted); + fail_grant = false; + assert(!mt7925_remain_on_channel(NULL, &vif[1], NULL, 50, OFFCHANNEL)); + } + assert(radio.state && !aborted); + if (!strcmp(s, "other-vif")) { + mt7925_mac_sta_event(NULL, &vif[1], &sta, MT76_STA_EVENT_AUTHORIZE); + assert(radio.state && !aborted); + } + if (!strcmp(s, "tdls")) { + sta.tdls = true; + mt7925_mac_sta_event(NULL, &vif[0], &sta, MT76_STA_EVENT_AUTHORIZE); + assert(radio.state && !aborted); + sta.tdls = false; + } + if (!strcmp(s, "offchannel")) { + mt7925_mac_sta_event(NULL, &vif[0], &sta, MT76_STA_EVENT_DISASSOC); + assert(!mt7925_remain_on_channel(NULL, &vif[1], NULL, 50, OFFCHANNEL)); + device.phy.roc_timer = false; + mt7925_roc_work(&device.phy.roc_work); + assert(!radio.state && expired == 1); + return 0; + } + if (!strcmp(s, "removed")) { + /* The station-removal path already holds the device mutex. */ + mt792x_mutex_acquire(&device); + mt7925_roc_abort_sync(&device); + mt792x_mutex_release(&device); + assert(!radio.state && !device.phy.roc_timer); + assert(!mt7925_remain_on_channel(NULL, &vif[0], NULL, 50, OFFCHANNEL)); + } + if (!strcmp(s, "expired")) { + device.phy.roc_timer = false; + mt7925_roc_work(&device.phy.roc_work); + assert(!radio.state && !expired); + assert(!mt7925_remain_on_channel(NULL, &vif[0], NULL, 50, OFFCHANNEL)); + } + if (!strcmp(s, "queued")) { + /* An expired timer worker may already be running, waiting for the mutex. */ + worker_running = true; + device.phy.roc_timer = false; + mt7925_mac_sta_event(NULL, &vif[0], &sta, MT76_STA_EVENT_AUTHORIZE); + assert(!mt7925_remain_on_channel(NULL, &vif[1], NULL, 50, OFFCHANNEL)); + if (worker_running) + mt7925_roc_work(&device.phy.roc_work); + assert(radio.state && device.phy.roc_timer && !expired); + return 0; + } + + int previous = aborted; + mt7925_mac_sta_event(NULL, &vif[0], &sta, !strcmp(s, "disassoc") ? + MT76_STA_EVENT_DISASSOC : MT76_STA_EVENT_AUTHORIZE); + if (busy || !strcmp(s, "expired") || !strcmp(s, "failed") || !strcmp(s, "removed")) { + assert(radio.state && device.phy.roc_timer && aborted == previous); + mt7925_cancel_remain_on_channel(NULL, &vif[busy || !strcmp(s, "failed") ? 1 : 0]); + assert(!radio.state && !device.phy.roc_timer); + } else { + assert(!radio.state && !device.phy.roc_timer && aborted == previous + 1); + } +} diff --git a/tests/cb1/test_alsa_hdmi_dts.py b/tests/cb1/test_alsa_hdmi_dts.py new file mode 100644 index 0000000000..db64073062 --- /dev/null +++ b/tests/cb1/test_alsa_hdmi_dts.py @@ -0,0 +1,221 @@ +# SPDX-License-Identifier: MIT +"""Exercise ALSA enumeration and passthrough admission with HDMI ELD fixtures.""" +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +from test_native_video_source import TREE, body + + +class AlsaHdmiDts(unittest.TestCase): + def test_passthrough_uses_complete_hdmi_eld_for_dts_only(self): + engine = TREE / 'xbmc/cores/AudioEngine' + alsa = (engine / 'Sinks/AESinkALSA.cpp').read_text() + header = (engine / 'Sinks/AESinkALSA.h').read_text() + sink = (engine / 'Engines/ActiveAE/ActiveAESink.cpp').read_text() + program = r''' +#include "cores/AudioEngine/Utils/AEAudioFormat.h" +#include "cores/AudioEngine/Utils/AEDeviceInfo.h" +#include "cores/AudioEngine/Utils/AEELDParser.h" + +#include +#include +#include +#include + +const uint8_t* eldData; +int eldSize; +bool eldReadable; + +// Replace hardware calls while running Kodi's enumeration and format checks. +using snd_pcm_t = int; +using snd_config_t = int; +using snd_pcm_info_t = int; +using snd_pcm_hw_params_t = int; +using snd_pcm_format_t = int; +using snd_ctl_t = int; +using snd_hctl_t = int; +using snd_ctl_elem_id_t = int; +using snd_ctl_elem_info_t = int; +using snd_ctl_elem_value_t = int; +using snd_hctl_elem_t = int; +using snd_pcm_chmap_t = int; +struct snd_pcm_chmap_query_t { snd_pcm_chmap_t map; }; + +#define ALSA_ALLOC(ptr) *(ptr) = static_cast(__builtin_alloca(sizeof(int))) +#define snd_pcm_info_alloca(ptr) ALSA_ALLOC(ptr) +#define snd_pcm_hw_params_alloca(ptr) ALSA_ALLOC(ptr) +#define snd_ctl_elem_id_alloca(ptr) ALSA_ALLOC(ptr) +#define snd_ctl_elem_info_alloca(ptr) ALSA_ALLOC(ptr) +#define snd_ctl_elem_value_alloca(ptr) ALSA_ALLOC(ptr) +constexpr int SND_PCM_FORMAT_UNKNOWN = -1, SND_CTL_ELEM_IFACE_PCM = 1; +constexpr int SND_CTL_ELEM_TYPE_BYTES = 1, LOGINFO = 0, LOGDEBUG = 0; +constexpr int ALSA_MAX_CHANNELS = 2; +const AEChannel LegacyALSAChannelMap[] = {AE_CH_FL, AE_CH_FR}; +unsigned int ALSASampleRateList[] = {48000, 192000, 0}; +size_t snd_pcm_info_sizeof() { return sizeof(int); } +size_t snd_pcm_hw_params_sizeof() { return sizeof(int); } +size_t snd_ctl_elem_id_sizeof() { return sizeof(int); } +size_t snd_ctl_elem_info_sizeof() { return sizeof(int); } +size_t snd_ctl_elem_value_sizeof() { return sizeof(int); } +int snd_pcm_info(snd_pcm_t*, snd_pcm_info_t*) { return 0; } +int snd_pcm_close(snd_pcm_t*) { return 0; } +int snd_pcm_info_get_card(snd_pcm_info_t*) { return 0; } +int snd_pcm_info_get_device(snd_pcm_info_t*) { return 3; } +const char* snd_pcm_info_get_name(snd_pcm_info_t*) { return "Test PCM"; } +int snd_card_get_name(int, char** name) { *name = strdup("Test Card"); return 0; } +int snd_ctl_open_lconf(snd_ctl_t** out, const char*, int, snd_config_t*) { *out = nullptr; return 0; } +int snd_hctl_open_ctl(snd_hctl_t** out, snd_ctl_t*) { *out = nullptr; return 0; } +int snd_hctl_load(snd_hctl_t*) { return 0; } +int snd_hctl_close(snd_hctl_t*) { return 0; } +int snd_ctl_close(snd_ctl_t*) { return 0; } +int snd_pcm_hw_params_any(snd_pcm_t*, snd_pcm_hw_params_t*) { return 0; } +int snd_pcm_hw_params_test_rate(snd_pcm_t*, snd_pcm_hw_params_t*, unsigned int, int) { return 0; } +int snd_pcm_hw_params_test_channels(snd_pcm_t*, snd_pcm_hw_params_t*, int) { return 0; } +int snd_pcm_hw_params_test_format(snd_pcm_t*, snd_pcm_hw_params_t*, snd_pcm_format_t) { return 0; } +snd_pcm_chmap_query_t** snd_pcm_query_chmaps(snd_pcm_t*) { return nullptr; } +void snd_pcm_free_chmaps(snd_pcm_chmap_query_t**) {} +void snd_ctl_elem_id_set_interface(snd_ctl_elem_id_t*, int) {} +void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t*, const char*) {} +void snd_ctl_elem_id_set_device(snd_ctl_elem_id_t*, int device) { assert(device == 3); } +snd_hctl_elem_t* snd_hctl_find_elem(snd_hctl_t*, snd_ctl_elem_id_t*) { + static snd_hctl_elem_t control; + return eldReadable ? &control : nullptr; +} +int snd_hctl_elem_info(snd_hctl_elem_t*, snd_ctl_elem_info_t*) { return 0; } +int snd_ctl_elem_info_is_readable(snd_ctl_elem_info_t*) { return 1; } +int snd_ctl_elem_info_get_type(snd_ctl_elem_info_t*) { return SND_CTL_ELEM_TYPE_BYTES; } +int snd_hctl_elem_read(snd_hctl_elem_t*, snd_ctl_elem_value_t*) { return 0; } +int snd_ctl_elem_info_get_count(snd_ctl_elem_info_t*) { return eldSize; } +const void* snd_ctl_elem_value_get_bytes(const snd_ctl_elem_value_t*) { return eldData; } + +struct CLog { + template static void Log(int, const char*, Args&&...) {} +}; +struct CAESinkALSA { + static bool OpenPCMDevice(const std::string&, const std::string&, int, snd_pcm_t** out, snd_config_t*) { + *out = nullptr; + return true; + } + static snd_pcm_format_t AEFormatToALSAFormat(AEDataFormat fmt) { + return fmt == AE_FMT_S16NE ? 0 : SND_PCM_FORMAT_UNKNOWN; + } + static CAEChannelInfo ALSAchmapToAEChannelMap(snd_pcm_chmap_t*) { return {}; } + static AEDeviceType AEDeviceTypeFromName(const std::string& name) @DEVICE_TYPE@ + static void EnumerateDevice(AEDeviceInfoList&, const std::string&, const std::string&, snd_config_t*); + @ELD_DECLARATION@ +}; +@ENUMERATE@ + +struct AESinkDevice { std::string driver, name; }; +struct CAESinkFactory { + static AESinkDevice ParseDevice(const std::string& device) { return {"ALSA", device}; } +}; +struct Sink { std::string m_sinkName; AEDeviceInfoList m_deviceInfoList; }; +struct CActiveAESink { + std::vector m_sinkInfoList; + bool SupportsFormat(const std::string& device, AEAudioFormat& format) @SUPPORTS_FORMAT@ +}; + +using enum CAEStreamInfo::DataType; + +void Check(const uint8_t* data, int size, bool core, bool hd, + const std::string& device = "hdmi:CARD=PCH,DEV=0", bool hasControl = true) +{ + eldData = data; + eldSize = size; + eldReadable = hasControl; + CActiveAESink sink{{{"ALSA", {}}}}; + auto& devices = sink.m_sinkInfoList.front().m_deviceInfoList; + CAESinkALSA::EnumerateDevice(devices, device, device, nullptr); + assert(devices.size() == 1); + + AEAudioFormat format; + format.m_sampleRate = format.m_streamInfo.m_sampleRate = 48000; + format.m_dataFormat = AE_FMT_S16NE; + assert(sink.SupportsFormat(device, format)); + format.m_dataFormat = AE_FMT_RAW; + for (auto type : {STREAM_TYPE_DTS_512, STREAM_TYPE_DTS_1024, STREAM_TYPE_DTS_2048, + STREAM_TYPE_DTSHD_CORE, STREAM_TYPE_DTSHD, STREAM_TYPE_DTSHD_MA}) + { + format.m_streamInfo.m_type = type; + const bool isHd = type == STREAM_TYPE_DTSHD || type == STREAM_TYPE_DTSHD_MA; + assert(sink.SupportsFormat(device, format) == (isHd ? hd : core)); + } + for (auto type : {STREAM_TYPE_AC3, STREAM_TYPE_EAC3, STREAM_TYPE_TRUEHD}) + { + format.m_streamInfo.m_type = type; + assert(sink.SupportsFormat(device, format) == + (device.starts_with("hdmi") || (device.starts_with("iec958") && type == STREAM_TYPE_AC3))); + } +} + +int main() +{ + // Baseline ELD reconstructed from the S95C's captured CTA SAD bytes (issue #191). + alignas(8) uint8_t eld[44] = { + 0x10, 0, 10, 0, 0x66, 0x50, 0, 0x0f, 0, 0, 0, 0, 0, 0, 0, 0, + 0x4c, 0x2d, 0x46, 0x73, 'Q', 'C', 'Q', '9', '5', 'S', + 0x0d, 0x57, 0x07, 0x09, 0x07, 0x07, 0x15, 0x07, 0x50, + 0x57, 0x07, 0x01, 0x67, 0x54, 0x07}; + Check(eld, sizeof(eld), false, false); + eld[4] = 0x86; // reserved CTA revision with a plausible SAD list + Check(eld, sizeof(eld), true, true); + eld[4] = 0x66; + Check(eld, sizeof(eld), true, false, "iec958:CARD=PCH,DEV=0"); + Check(eld, sizeof(eld), false, false, "@"); + Check(nullptr, 0, true, true); + Check(nullptr, 0, true, true, "hdmi:CARD=PCH,DEV=0", false); + const uint8_t shortHeader[] = {0x10}; + Check(shortHeader, sizeof(shortHeader), true, true); + const std::vector shortSad(eld, eld + 40); + Check(shortSad.data(), shortSad.size(), true, true); + Check(eld, 41, true, true); // incomplete declared baseline + eld[0] = 0xf8; // Partial or canned ELD + Check(eld, sizeof(eld), true, true); + eld[0] = 0x10; + eld[5] = 0x54; // DisplayPort ELD + Check(eld, sizeof(eld), true, true); + eld[5] = 0; // no SAD evidence yet + Check(eld, sizeof(eld), true, true); + eld[5] = 0x50; + eld[26] = 0; // reserved coding type + Check(eld, sizeof(eld), true, true); + eld[26] = 0x3d; // DTS core SAD + Check(eld, sizeof(eld), true, false); + eld[32] = 0x5f; // DTS-HD SAD + Check(eld, sizeof(eld), true, true); + eld[26] = 0x0d; + Check(eld, sizeof(eld), false, true); +} +''' + enumerate_start = alsa.index('void CAESinkALSA::EnumerateDevice(') + enumerate_end = alsa.index('void CAESinkALSA::sndLibErrorHandler(', enumerate_start) + get_eld_start = header.index('static bool GetELD(') + get_eld_end = header.index(';', get_eld_start) + 1 + for marker, text in { + '@DEVICE_TYPE@': body(alsa, 'AEDeviceType CAESinkALSA::AEDeviceTypeFromName('), + '@ELD_DECLARATION@': header[get_eld_start:get_eld_end], + '@ENUMERATE@': alsa[enumerate_start:enumerate_end], + '@SUPPORTS_FORMAT@': body(sink, 'bool CActiveAESink::SupportsFormat('), + }.items(): + program = program.replace(marker, text) + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + source = root / 'check.cpp' + source.write_text(program) + includes = ['-I' + str(TREE / 'xbmc')] + if prefix := os.environ.get('FFMPEG_TEST_PREFIX'): + includes += ['-I' + str(Path(prefix) / 'include')] + build = subprocess.run( + ['c++', '-std=c++20', '-DHAVE_X11', '-DTARGET_POSIX', + '-fsanitize=address,undefined', '-fno-sanitize-recover=all', *includes, + str(source), str(engine / 'Utils/AEELDParser.cpp'), + str(engine / 'Utils/AEChannelInfo.cpp'), '-o', str(root / 'check')], + capture_output=True, text=True, + ) + self.assertEqual(build.returncode, 0, build.stderr) + run = subprocess.run([str(root / 'check')], capture_output=True, text=True) + self.assertEqual(run.returncode, 0, run.stdout + run.stderr) diff --git a/tests/cb1/test_bitmap_subtitles.py b/tests/cb1/test_bitmap_subtitles.py index 2e57dc4378..5732c17c86 100644 --- a/tests/cb1/test_bitmap_subtitles.py +++ b/tests/cb1/test_bitmap_subtitles.py @@ -29,9 +29,10 @@ def test_pq_palette_destination_changes_rebuild_retained_native_cache(self): namespace KODI::UTILS {enum class Eotf {TRADITIONAL_SDR,PQ};} struct CWinSystemBase { virtual ~CWinSystemBase()=default; - bool composite=true,limited=false,cb1=false; + bool composite=true,limited=false,cb1=false,nativeSDRBT2020=false; KODI::UTILS::Eotf eotf=KODI::UTILS::Eotf::PQ; bool IsHdrComposite() const {return composite;} + bool UsesNativeSDRBT2020() const {return nativeSDRBT2020;} bool UseLimitedColor() const {return limited;} auto GetEotf() const {return eotf;} }; @@ -57,9 +58,7 @@ class COverlay OVERLAY_CLASS; unsigned loadedState; Texture(const CDVDOverlayImage& image) { m_isHDROverlay=image.m_isHDROverlay; - auto& window=CServiceBroker::window; - loadedState=(ShouldConvertPQPaletteToSRGB(true)?1u:0u)| - ((window.composite && window.limited && !window.cb1)?2u:0u); + loadedState=BitmapPaletteOutputState(); SET_CACHED_STATE } void Render(SRenderState&) override {} @@ -100,6 +99,12 @@ class COverlay OVERLAY_CLASS; renderer.Reset(); auto limited=std::dynamic_pointer_cast(renderer.Convert(entry)); assert(limited->loadedState==2 && limited!=sdr); + CServiceBroker::window.nativeSDRBT2020=true; + CServiceBroker::window.eotf=KODI::UTILS::Eotf::TRADITIONAL_SDR; + auto wide=std::dynamic_pointer_cast(renderer.Convert(entry)); + assert(wide->loadedState==1 && wide!=limited && "native SDR needs sRGB palettes before composition"); + CServiceBroker::window.nativeSDRBT2020=false; + CServiceBroker::window.eotf=KODI::UTILS::Eotf::PQ; CServiceBroker::window.cb1=true; auto cb1=std::dynamic_pointer_cast(renderer.Convert(entry)); assert(cb1->loadedState==0 && cb1!=limited && "CB1 composition must not reuse pre-encoded limited PQ"); diff --git a/tests/cb1/test_bluray_display_capabilities.py b/tests/cb1/test_bluray_display_capabilities.py index 5ee094c8c6..04329a0368 100644 --- a/tests/cb1/test_bluray_display_capabilities.py +++ b/tests/cb1/test_bluray_display_capabilities.py @@ -47,7 +47,9 @@ def test_complete_gbm_mode_list_is_published_without_partial_catalogue(self): static CDisplaySettings& GetInstance(){static CDisplaySettings s;return s;} void ClearCustomResolutions(){if(observer)observer();} void AddResolutionInfo(const RESOLUTION_INFO&){if(observer)observer();} - RESOLUTION_INFO& GetResolutionInfo(int){static RESOLUTION_INFO r;return r;} + RESOLUTION_INFO desktop; + RESOLUTION_INFO& GetResolutionInfo(int){return desktop;} + void SetDesktopResolutionInfo(const RESOLUTION_INFO& resolution){desktop=resolution;} void ApplyCalibrations(){}void UpdateCalibrations(){} }; struct Window {Window& GetGfxContext(){return *this;}void ResetOverscan(RESOLUTION_INFO&){} }; diff --git a/tests/cb1/test_decode_startup_diagnostics.py b/tests/cb1/test_decode_startup_diagnostics.py index 55a404c409..1094630d35 100644 --- a/tests/cb1/test_decode_startup_diagnostics.py +++ b/tests/cb1/test_decode_startup_diagnostics.py @@ -57,7 +57,7 @@ def test_native_events_keep_exact_pairing_and_do_not_log_every_frame(self): constexpr int CODEC_BLURAY_NAVIGATION=4; int dvbridge_fel_take_mel(Fel*,int64_t,AVFrame**,const void*,size_t){return 3;} bool dvbridge_fel_device(Fel*,void*){return true;} -bool dvbridge_fel_drain(Fel*){return true;} +bool dvbridge_fel_drain(Fel*,const char**){return true;} int dvbridge_fel_take(Fel* f,int64_t pts,AVFrame** frame){ if(pts<=f->discardUntil)return 2; if(!f->ready)return 0;assert(pts>=1);++f->takes;*frame=new AVFrame;return 1; diff --git a/tests/cb1/test_diagnostics_runtime.py b/tests/cb1/test_diagnostics_runtime.py index bd8386e715..5cc68d24f6 100644 --- a/tests/cb1/test_diagnostics_runtime.py +++ b/tests/cb1/test_diagnostics_runtime.py @@ -684,6 +684,7 @@ def test_same_size_refresh_updates_only_accepted_current_mode(self): #include #include #include +#include #include "utils/DVBridgeDiagnosticState.h" #include "windowing/gbm/ModeChangeHold.h" #include "utils/DVBridgeLldv.h" @@ -741,6 +742,8 @@ def test_same_size_refresh_updates_only_accepted_current_mode(self): }; struct CWinSystemGbm { std::shared_ptr m_DRM=std::make_shared(); + struct DVOutputTiming {int index,width,height; double refresh;}; + std::vector GetDVOutputTimings() const {return {{0,3840,2160,m_DRM->rate}};} bool SetFullScreen(bool,RESOLUTION_INFO& res,bool) { if(!m_DRM->accept) return false; if(m_DRM->receipt) m_DRM->rate=res.rate; @@ -764,6 +767,7 @@ def test_same_size_refresh_updates_only_accepted_current_mode(self): std::shared_ptr m_dvContext; bool m_dvAvailableNativeDV=false,m_dvAvailableHDR10=false; DVBRIDGE::LldvConnectorStatus m_dvLldvStatus{}; + std::vector m_dvOutputTimings; DVBRIDGE::LldvConnectorStatus GetLldvConnectorStatus(bool = false) const {return m_dvLldvStatus;} bool EndDVBridge() {return true;} bool RetireDVContext() {return true;} bool PrepareNvidiaModeRestore(const RESOLUTION_INFO&) {return true;} diff --git a/tests/cb1/test_dv_uhd_mode.py b/tests/cb1/test_dv_uhd_mode.py index 0c49ec7931..1e84a07513 100644 --- a/tests/cb1/test_dv_uhd_mode.py +++ b/tests/cb1/test_dv_uhd_mode.py @@ -8,6 +8,57 @@ class DVUHDModeTests(unittest.TestCase): + def test_resolution_catalogue_removal_takes_the_reader_lock(self): + display = (TREE/'xbmc/settings/DisplaySettings.cpp').read_text() + read = body(display, 'RESOLUTION_INFO CDisplaySettings::GetResolutionInfoCopy(') + clear = body(display, 'void CDisplaySettings::ClearCustomResolutions()') + program = r'''#include +#include +#include +#include + +enum RESOLUTION {RES_INVALID = -1, RES_DESKTOP = 0, RES_CUSTOM = 1}; +using RESOLUTION_INFO = std::string; +const RESOLUTION_INFO EmptyResolution; + +struct CDisplaySettings { + struct Catalogue : std::vector { + using std::vector::vector; + bool* locked; + iterator erase(iterator first, iterator last) { + assert(*locked && "Catalogue removal must exclude readers"); + return std::vector::erase(first, last); + } + }; + struct Mutex { + bool locked=false; + void lock() {assert(!locked); locked=true;} + void unlock() {assert(locked); locked=false;} + }; + mutable Mutex m_critical; + Catalogue m_resolutions{"desktop", "custom"}; + CDisplaySettings() {m_resolutions.locked=&m_critical.locked;} + RESOLUTION_INFO GetResolutionInfoCopy(RESOLUTION resolution) const READ + void ClearCustomResolutions() CLEAR +}; + +int main() { + CDisplaySettings settings; + const auto copy = settings.GetResolutionInfoCopy(RES_CUSTOM); + settings.ClearCustomResolutions(); + assert(copy=="custom"); + assert(settings.GetResolutionInfoCopy(RES_CUSTOM).empty()); + assert(settings.GetResolutionInfoCopy(RES_DESKTOP)=="desktop"); +} +'''.replace(' READ', ' ' + read).replace(' CLEAR', ' ' + clear) + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + source = root/'test.cpp' + binary = root/'test' + source.write_text(program) + subprocess.run(['c++', '-std=c++20', str(source), '-o', str(binary)], check=True) + subprocess.run([str(binary)], check=True) + def test_real_selector_preserves_whitelist_override_and_adjustment_off(self): resolution = (TREE/'xbmc/windowing/Resolution.cpp').read_text() resolution = re.sub(r'^#include[^\n]*', '', resolution, flags=re.M) @@ -15,13 +66,21 @@ def test_real_selector_preserves_whitelist_override_and_adjustment_off(self): manager = body(manager_source, 'RESOLUTION CRenderManager::GetResolution()') choice = body(manager_source, 'RESOLUTION CRenderManager::ChoosePlaybackResolution(') gbm = (TREE/'xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp').read_text() + gbm_window = (TREE/'xbmc/windowing/gbm/WinSystemGbm.cpp').read_text() eligible = body(gbm, 'bool NativeDVEligible(') wants = body(gbm, 'bool DVBRIDGE::WantsNativeOutput(const CDVDStreamInfo& stream)') + timing = body(gbm_window, 'double DVOutputTimingRate(') + snapshot = body(gbm_window, 'CWinSystemGbm::GetDVOutputTimings()') + support = body(gbm, 'bool CWinSystemGbmGLESContext::SupportsDVOutputTiming(') + select_fallback = body(gbm, 'CWinSystemGbmGLESContext::ChooseHDR10FallbackResolution(') + fallback = body(gbm, 'CWinSystemGbmGLESContext::PlayerLedStartupHDR10Resolution(') program = r''' +#define HAVE_DVBRIDGE #include "windowing/Resolution.h" #include "cores/VideoPlayer/DVDCodecs/Video/DVPlaybackPolicy.h" #include #include +#include #include #include #include @@ -29,6 +88,7 @@ def test_real_selector_preserves_whitelist_override_and_adjustment_off(self): #include #include #include +#include constexpr uint32_t D3DPRESENTFLAG_INTERLACED=1, D3DPRESENTFLAG_MODE3DSBS=2, D3DPRESENTFLAG_MODE3DTB=4, D3DPRESENTFLAG_MODEMASK=7; constexpr int LOGDEBUG=0, LOGINFO=1, STEREOSCOPIC_PLAYBACK_MODE_PREFERRED=1, @@ -67,6 +127,7 @@ def test_real_selector_preserves_whitelist_override_and_adjustment_off(self): std::vector modes=std::vector(RES_DESKTOP); static CDisplaySettings& GetInstance(){static CDisplaySettings d;return d;} const RESOLUTION_INFO& GetResolutionInfo(RESOLUTION r)const{return modes.at(r);} + RESOLUTION_INFO GetResolutionInfoCopy(RESOLUTION r)const{return modes.at(r);} RESOLUTION GetCurrentResolution()const{return RES_DESKTOP;} RESOLUTION GetResFromString(const std::string& s)const{return static_cast(std::stoi(s));} std::string GetStringFromRes(RESOLUTION r)const{return std::to_string(r);} @@ -82,11 +143,39 @@ def test_real_selector_preserves_whitelist_override_and_adjustment_off(self): RenderStereoMode GetNextStereoMode()const{return RenderStereoMode::OFF;} bool IsFullScreenRoot()const{return true;} }; +struct Connector { + std::vector modes; + bool connected=true; + bool IsConnected() {return connected;} + int GetModesCount() const {return modes.size();} + const drmModeModeInfo* GetModeForIndex(int i) const {return &modes.at(i);} +}; +struct DRM { + Connector connector; + Connector* GetConnector() {return &connector;} +} drm; struct Window { + struct DVOutputTiming {int index,width,height;double refresh;}; CGraphicContext gfx;CGraphicContext& GetGfxContext(){return gfx;} + const CGraphicContext& GetGfxContext() const {return gfx;} + DRM* m_DRM=&drm; + mutable std::mutex m_dvCapabilityMutex; + std::vector m_dvOutputTimings; + std::vector GetDVOutputTimings() const; bool available=true;bool CanRetainDVSource()const{return available;} + bool SupportsDVOutputTiming(const RESOLUTION_INFO& mode) const; + struct Caps { + bool hdr10=true, depthLimited=false; + bool HDR10DepthLimited() const {return depthLimited;} + } caps; + Caps GetDVOutputCapabilities(const void*, bool) const {return caps;} + RESOLUTION ChooseHDR10FallbackResolution(RESOLUTION chosen) const; + std::optional PlayerLedStartupHDR10Resolution(RESOLUTION resolution, int preference) const; + int PlayerLedResolutionReason(RESOLUTION, int) const {return 41212;} + std::optional PlayerLedResolution(double, bool) const {return {};} }; -using CWinSystemGbmGLESContext=Window; +namespace KODI::WINDOWING::GBM {using CWinSystemGbmGLESContext=Window;} +using namespace KODI::WINDOWING::GBM; struct Stereo {bool IsStereoModeSettled()const{return true;}}; struct GUI {Stereo stereo;Stereo& GetStereoscopicsManager(){return stereo;}}; struct CServiceBroker { @@ -101,18 +190,32 @@ class CDVDStreamInfo { int codecOptions=0;bool interlaced=false;std::string stereo_mode; }; namespace DVBRIDGE { + constexpr int LLDV_DRIVER_REJECTED_LABEL = 41247; enum class OutputMode {Standard,Disabled}; std::atomic playbackMode{OutputMode::Standard}; + struct Preferences { bool hdr10TransportFallback{}; } preferences; + Preferences FrameOutputSettings() {return preferences;} } bool NativeDVEligible(bool source,bool software,bool interlaced,bool stereo) ELIGIBLE_CODE bool DVBRIDGE::WantsNativeOutput(const CDVDStreamInfo& stream) WANTS_CODE RESOLUTION_CODE -struct Picture {int iWidth=3840,iHeight=2160;std::string stereoMode;}; +double DVOutputTimingRate(const drmModeModeInfo* mode) TIMING_CODE +std::vector Window::GetDVOutputTimings() const SNAPSHOT_CODE +bool Window::SupportsDVOutputTiming(const RESOLUTION_INFO& mode) const SUPPORT_CODE +RESOLUTION Window::ChooseHDR10FallbackResolution(RESOLUTION chosen) const SELECT_FALLBACK_CODE +std::optional Window::PlayerLedStartupHDR10Resolution(RESOLUTION resolution, int preference) const FALLBACK_CODE +enum class StreamHdrType {HDR_TYPE_NONE, HDR_TYPE_DOLBYVISION, HDR_TYPE_HDR10}; +struct VideoPicture { + int iWidth=3840,iHeight=2160; + std::string stereoMode; + StreamHdrType hdrType=StreamHdrType::HDR_TYPE_DOLBYVISION; + struct {int profile=0;} doviSourceInfo; +}; struct CRenderManager { std::mutex m_statelock;int m_renderState=1;bool m_nativeDVRate=false;float m_fps=24000.f/1001; - Picture m_picture; + VideoPicture m_picture; static RESOLUTION ChoosePlaybackResolution(double fps,int width,int height,bool stereo,bool nativeDV, - bool atStartup=false) CHOICE_CODE + bool atStartup=false, const VideoPicture* picture=nullptr) CHOICE_CODE RESOLUTION GetResolution() MANAGER_CODE }; int main() { @@ -227,13 +330,94 @@ class CDVDStreamInfo { component.settings.adjust=ADJUST_REFRESHRATE_OFF; manager.m_picture.iWidth=3832;manager.m_picture.iHeight=1600; assert(manager.GetResolution()==RES_DESKTOP); + + // An 8K desktop makes Kodi's empty whitelist select 8K at the film cadence. + const auto desktop8k=add(7680,4320,60); + const auto film8k=add(7680,4320,film); + auto advertise=[&](RESOLUTION res, int clock, int flags=0) { + auto& info=modes[res]; + info.strId=std::to_string(drm.connector.modes.size()); + drmModeModeInfo mode{}; + mode.hdisplay=info.iScreenWidth;mode.vdisplay=info.iScreenHeight; + mode.htotal=4400;mode.vtotal=2250;mode.clock=clock;mode.flags=flags; + drm.connector.modes.push_back(mode); + }; + advertise(desktop8k,594000); + advertise(uhd60,594000); + advertise(film8k,237363); + advertise(interlaced,237363,DRM_MODE_FLAG_INTERLACE); + advertise(sbs,237363,DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF); + advertise(fhd,237363); + advertise(uhd,237600); // The ID points to 24.000, despite Kodi advertising 23.976. + auto* window=CServiceBroker::GetWinSystem(); + auto publish=[&] { + window->m_DRM=&drm; + window->m_dvOutputTimings=window->GetDVOutputTimings(); + window->m_DRM=nullptr; // Mode selection uses the snapshot even during DRM teardown. + }; + publish(); + modes[RES_DESKTOP]=modes[desktop8k]; + component.settings.whitelist.clear(); + component.settings.adjust=1; + manager.m_picture.iWidth=3840;manager.m_picture.iHeight=2160; + assert(manager.GetResolution()==film8k && "ordinary playback must keep the 8K desktop floor"); + const auto selected=CRenderManager::ChoosePlaybackResolution(60.0,3840,2160,false,true,true); + assert(selected==desktop8k || selected==RES_DESKTOP); + assert(window->PlayerLedStartupHDR10Resolution(selected,0)==uhd60 && + "Startup must admit UHD60 HDR10 before the fallback flag is set"); + auto unconventional=drm.connector.modes[1]; + unconventional.flags=DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF; + assert(DVOutputTimingRate(&unconventional)==0.0); + unconventional.flags=0; + unconventional.vscan=2; + assert(DVOutputTimingRate(&unconventional)==0.0); + list({desktop8k}); + assert(!window->PlayerLedStartupHDR10Resolution(selected,0)); + component.settings.whitelist.clear(); + window->caps.depthLimited=true; + assert(!window->PlayerLedStartupHDR10Resolution(selected,0)); + window->caps.depthLimited=false; + component.advanced.m_videoAdjustRefreshOverrides.push_back({false,59,61,59,61}); + assert(!window->PlayerLedStartupHDR10Resolution(selected,0)); + component.advanced.m_videoAdjustRefreshOverrides.clear(); + + DVBRIDGE::preferences.hdr10TransportFallback=true; + assert(choose(3840,2160)==film8k); + assert(manager.GetResolution()==fhd && "automatic recovery must skip an unusable 8K mode"); + drm.connector.modes.back().clock=237363; + publish(); + assert(manager.GetResolution()==uhd && "prefer the largest usable mode at the same cadence"); + assert(CRenderManager::ChoosePlaybackResolution(film,3840,2160,false,true)==uhd); + manager.m_picture.hdrType=StreamHdrType::HDR_TYPE_HDR10; + assert(manager.GetResolution()==film8k && "ordinary HDR10 processing must keep the 8K mode"); + manager.m_picture.hdrType=StreamHdrType::HDR_TYPE_DOLBYVISION; + list({film8k,uhd}); + assert(manager.GetResolution()==uhd); + list({film8k}); + assert(manager.GetResolution()==film8k && "explicit whitelist allows the 8K mode"); + component.settings.whitelist.clear(); + component.advanced.m_videoAdjustRefreshOverrides.push_back({false,23,24,23.97f,23.98f}); + assert(manager.GetResolution()==film8k && "explicit refresh override allows the 8K mode"); + component.advanced.m_videoAdjustRefreshOverrides.clear(); + component.settings.adjust=ADJUST_REFRESHRATE_OFF; + assert(manager.GetResolution()==RES_DESKTOP); + component.settings.adjust=1; + drm.connector.modes.back().flags=DRM_MODE_FLAG_DBLSCAN; + drm.connector.modes[5].clock=237600; + publish(); + assert(manager.GetResolution()==film8k && "keep Kodi's choice if the cadence has no usable mode"); + drm.connector.modes.back().flags=0; + drm.connector.connected=false; + publish(); + assert(manager.GetResolution()==film8k && "a disconnected display has no eligible candidate"); } '''.replace('RESOLUTION_CODE', resolution).replace('CHOICE_CODE',choice).replace('MANAGER_CODE', manager).replace( + 'TIMING_CODE', timing).replace('SNAPSHOT_CODE', snapshot).replace('SUPPORT_CODE', support).replace('SELECT_FALLBACK_CODE', select_fallback).replace('FALLBACK_CODE', fallback).replace( 'ELIGIBLE_CODE', eligible).replace('WANTS_CODE', wants) with tempfile.TemporaryDirectory() as temporary: root=Path(temporary) (root/'test.cpp').write_text(program) - built=subprocess.run(['c++','-std=c++20','-I'+str(TREE/'xbmc'), + built=subprocess.run(['c++','-std=c++20','-I/usr/include/libdrm','-I'+str(TREE/'xbmc'), str(root/'test.cpp'),'-o',str(root/'test')],capture_output=True,text=True) self.assertEqual(built.returncode,0,built.stderr) ran=subprocess.run([str(root/'test')],capture_output=True,text=True) diff --git a/tests/cb1/test_fel_terminal.py b/tests/cb1/test_fel_terminal.py index afb9038d8c..39e2f355ab 100644 --- a/tests/cb1/test_fel_terminal.py +++ b/tests/cb1/test_fel_terminal.py @@ -53,6 +53,7 @@ def test_actual_fel_decoder_reports_terminal_failure_and_keeps_vanilla_result(se program=r''' #include #include +#include #include #include #define HAVE_DVBRIDGE 1 @@ -82,16 +83,23 @@ def test_actual_fel_decoder_reports_terminal_failure_and_keeps_vanilla_result(se std::shared_ptrdoviEnhancement;int doviEnhancementBinding=0; void Reset(){}void CopyRef(const VideoPicture&v){*this=v;}}; struct Context{Buffer* hw_frames_ctx=nullptr;}; -struct Fel{bool failed=false,exhausted=false;int result=0;}; +struct Fel{bool failed=false,exhausted=false;int result=0;bool missingEnhancement=false;}; bool dvbridge_fel_failed(Fel*f){return f->failed;} bool dvbridge_fel_exhausted(Fel*f){return f->exhausted;} int dvbridge_fel_take(Fel*f,int64_t,AVFrame**out){if(f->result==1)*out=new AVFrame;return f->result;} constexpr int CODEC_BLURAY_NAVIGATION=4; int dvbridge_fel_take_mel(Fel*,int64_t,AVFrame**,const void*,size_t){return 3;} bool dvbridge_fel_device(Fel*,void*){return true;} -bool dvbridge_fel_drain(Fel*){return true;} +bool dvbridge_fel_drain(Fel*f,const char** reason=nullptr){ + if(reason)*reason=f->missingEnhancement?"no enhancement video received before drain":nullptr; + return !f->missingEnhancement; +} enum{LOGWARNING,LOGERROR}; -struct CLog{templatestatic void Log(T...){}}; +int missingEnhancementLogs=0; +struct CLog{ + templatestatic void Log(T...){} + static void Log(decltype(LOGERROR),const char* format,const char*){if(std::string(format).find("Kodi Default")!=std::string::npos)++missingEnhancementLogs;} +}; struct CDVDVideoCodec{enum VCReturn{VC_NONE,VC_BUFFER,VC_PICTURE,VC_ERROR,VC_EOF,VC_FATAL};}; struct CDVDVideoCodecFFmpeg:CDVDVideoCodec{ struct {int codecOptions{};bool preferHybridHDR10Plus{};}m_hints; @@ -123,6 +131,19 @@ def test_actual_fel_decoder_reports_terminal_failure_and_keeps_vanilla_result(se assert(incomplete.GetPicture(&out)==CDVDVideoCodec::VC_FATAL); CDVDVideoCodecFFmpeg cleanEnd;cleanEnd.baseResult=CDVDVideoCodec::VC_EOF; assert(cleanEnd.GetPicture(&out)==CDVDVideoCodec::VC_EOF); + CDVDVideoCodecFFmpeg missing;missing.m_dvFel->missingEnhancement=true;missing.baseResult=CDVDVideoCodec::VC_EOF; + assert(missing.GetPicture(&out)==CDVDVideoCodec::VC_FATAL && missingEnhancementLogs==1); + CDVDVideoCodecFFmpeg optional;optional.m_hints.preferHybridHDR10Plus=true; + optional.m_dvFel->missingEnhancement=true;optional.baseResult=CDVDVideoCodec::VC_EOF; + assert(optional.GetPicture(&out)==CDVDVideoCodec::VC_EOF && missingEnhancementLogs==1); + CDVDVideoCodecFFmpeg leading;leading.m_dvFel->result=2; + leading.baseResult=CDVDVideoCodec::VC_PICTURE; + for (int i=0;i<74;++i) { + assert(leading.GetPicture(&out)==CDVDVideoCodec::VC_BUFFER); + assert(leading.m_dvPending.empty()); + } + leading.m_dvFel->result=1; + assert(leading.GetPicture(&out)==CDVDVideoCodec::VC_PICTURE && out.doviEnhancement); CDVDVideoCodecFFmpeg readyThenFailed;readyThenFailed.m_dvFailed=true; readyThenFailed.m_dvFel->failed=true;readyThenFailed.m_dvFel->result=1; readyThenFailed.m_dvPending.push_back(std::make_shared()); diff --git a/tests/cb1/test_gbm_colour_owner.py b/tests/cb1/test_gbm_colour_owner.py index 29d1442237..f81c7180a2 100644 --- a/tests/cb1/test_gbm_colour_owner.py +++ b/tests/cb1/test_gbm_colour_owner.py @@ -29,7 +29,8 @@ def native_owner_program(root): "MigrateLimitedRangeSetting", "DeferConnectorPreferences", "ApplyConnectorProperties", "ApplyBroadcastRange", "ApplyMaxBpc", "ApplyColorFormat", "IsRequestRejected", "RequeueConnectorProperties", "RetryConnectorProperties", "UpdateDriverLimitedRange", - "UseLimitedColor", "ApplyColorspace", "SetColorimetry"] + "UseLimitedColor", "ApplyColorspace", "SetColorimetry", "NativeSDRBT2020Colorspace", + "BeginFrameGuiComposite", "StageNativeSDRSignal"] bodies = "\n".join(method(source, "CWinSystemGbm::" + name) for name in names) # The two QueueConnectorProperty overloads are adjacent in the actual owner. start = source.index("bool CWinSystemGbm::QueueConnectorProperty(") diff --git a/tests/cb1/test_gbm_colour_transition.py b/tests/cb1/test_gbm_colour_transition.py index a9c3f27335..8c15df1f7b 100644 --- a/tests/cb1/test_gbm_colour_transition.py +++ b/tests/cb1/test_gbm_colour_transition.py @@ -246,7 +246,28 @@ def test_source_depth_change_requires_configuration_before_render(self): self.assertIn("tmp.colorBits = buf.m_srcBits;", check) self.assertIn("tmp.color_transfer = buf.m_srcColTransfer;", check) shader_request = "!m_cmsOn" if backend == "GL" else "true" - self.assertIn(f"SetColorimetry(&tmp, {shader_request})", check) + end = check.index(f"SetColorimetry(&tmp, {shader_request});") + stage = check[check.index("VideoPicture tmp{};"):check.index(';', end) + 1] + compile_run(self, r''' +#include +constexpr int AVCOL_SPC_UNSPECIFIED=0, AVCOL_PRI_BT2020=9; +struct VideoPicture {int color_space{},color_transfer{},color_primaries{},iWidth{},iHeight{},colorBits{};}; +struct Window { + VideoPicture picture; + bool native=false; + void SetColorimetry(const VideoPicture* value,bool requested){picture=*value;native=requested;} +}; +struct CServiceBroker {static inline Window window;static Window* GetWinSystem(){return &window;}}; +int main(){ + const struct {int m_srcColSpace=9,m_srcColTransfer=1,m_srcPrimaries=AVCOL_PRI_BT2020,m_srcBits=10;} buf; + const int m_sourceWidth=3840,m_sourceHeight=2160; + const bool toneMap=false,m_cmsOn=false; + STAGE + const auto& output=CServiceBroker::window; + assert(output.native && output.picture.color_primaries==AVCOL_PRI_BT2020); + assert(output.picture.colorBits==10 && output.picture.color_transfer==1); +} +'''.replace('STAGE', stage)) configure = method(renderer, f"CLinuxRenderer{backend}::" + ("Configure" if backend == "GL" else "ConfigureVideoOutput")) output = "!m_ColorManager->IsEnabled()" if backend == "GL" else "true" diff --git a/tests/cb1/test_gbm_front_buffer.py b/tests/cb1/test_gbm_front_buffer.py new file mode 100644 index 0000000000..c0bd2f97c7 --- /dev/null +++ b/tests/cb1/test_gbm_front_buffer.py @@ -0,0 +1,103 @@ +"""Probe the same GBM buffer used to route a newly swapped output surface.""" +import unittest + +from test_native_video_source import TREE, body +from test_process_info_metadata import run + + +class GbmFrontBufferTests(unittest.TestCase): + def test_float_probe_reuses_the_front_buffer_without_a_second_lock(self): + gbm = TREE / 'xbmc/windowing/gbm' + method = body((gbm / 'WinSystemGbmEGLContext.cpp').read_text(), + 'bool CWinSystemGbmEGLContext::SetVideoOutput(') + start = method.index(' if (!m_eglContext.TrySwapBuffers()') + end = method.index(' // No new drawable exists', start) + surface = (gbm / 'GBMUtils.cpp').read_text() + access = body(surface, 'CGBMSurface::GetLockedFrontBuffer()') + program = r''' +#include +#include +#include +#include + +struct gbm_bo {}; +unsigned gbm_bo_get_format(gbm_bo*) { return 1; } +constexpr int DRM_FORMAT_MOD_LINEAR=0, LOGINFO=1; +namespace KODI::WINDOWING::GBM { enum { QUIRK_NEEDSPRIMARY }; } +struct CLog { template static void LogF(T...) {} }; + +struct Surface +{ + struct Buffer { gbm_bo* value; gbm_bo* Get() const { return value; } }; + std::queue> m_buffers; + std::unique_ptr m_scanoutBuffer; + gbm_bo buffer; + int locks=0; + bool frameReady=false; + Surface& GetDevice(){return *this;} + Surface& GetSurface(){return *this;} + Buffer& LockFrontBuffer() + { + ++locks; + m_buffers.push(std::make_unique(Buffer{frameReady ? &buffer : nullptr})); + frameReady=false; + return *m_buffers.back(); + } + gbm_bo* GetLockedFrontBuffer() const ACCESS +}; +struct EGL { Surface& surface; bool TrySwapBuffers(){surface.frameReady=true;return true;} }; +struct Plane { void SetFormat(unsigned){} void SetModifier(int){} }; +struct DRM +{ + virtual ~DRM()=default; + Plane plane; + bool HasQuirk(int){return false;} + void SetActive(bool){} + Plane* GetGuiPlane(){return nullptr;} + Plane* GetVideoPlane(){return &plane;} +}; +struct CDRMAtomic:DRM +{ + bool accepts=true; + gbm_bo* tested=nullptr; + bool TestFramebuffer(gbm_bo* bo){tested=bo;return bo && accepts;} +}; +struct CWinSystemGbm {bool SetVideoOutput(void*){return true;}}; +struct Window:CWinSystemGbm +{ + Surface surface; + EGL m_eglContext{surface}; + Surface* m_GBM=&surface; + std::shared_ptr drm=std::make_shared(); + std::shared_ptr m_DRM=drm; + bool m_dvOutputSurface=false; + bool HasFloatOutput() const{return true;} + bool Configure(bool swapped) + { + void* videoPicture=nullptr; + const int bitDepth=10; + auto reject=[](){return false;}; + if(swapped){ + PROBE + return true; + } +}; +int main() +{ + Window window; + assert(window.Configure(true)); + assert(window.surface.locks==1 && window.drm->tested==&window.surface.buffer); + assert(window.Configure(false)); + assert(window.surface.locks==1 && window.drm->tested==&window.surface.buffer); + window.drm->accepts=false; + assert(!window.Configure(false)); + assert(window.surface.locks==1 && window.drm->tested==&window.surface.buffer); + Window unavailable; + assert(!unavailable.Configure(false)); + assert(unavailable.surface.locks==0); + unavailable.surface.m_scanoutBuffer=std::make_unique(Surface::Buffer{&unavailable.surface.buffer}); + assert(unavailable.Configure(false)); + assert(unavailable.surface.locks==0 && unavailable.drm->tested==&unavailable.surface.buffer); +} +'''.replace('ACCESS', access).replace('PROBE', method[start:end]) + run(self, {'test.cpp': program}) diff --git a/tests/cb1/test_hybrid_source_preference.py b/tests/cb1/test_hybrid_source_preference.py index 16794aa4a6..8992ee7afa 100644 --- a/tests/cb1/test_hybrid_source_preference.py +++ b/tests/cb1/test_hybrid_source_preference.py @@ -213,6 +213,8 @@ def test_secondary_failure_waits_for_real_bl_verdict_and_survives_seek(self): #include enum class StreamHdrType { HDR_TYPE_DOLBYVISION, HDR_TYPE_HDR10PLUS }; enum VCReturn {VC_PICTURE,VC_BUFFER,VC_NONE,VC_FATAL,VC_EOF}; +enum { LOGERROR }; +struct CLog { template static void Log(Args...) {} }; enum { DVD_CODEC_CTRL_POLL=1, DVD_CODEC_CTRL_DRAIN=2, DVEnhancementPendingPictures=16 }; struct AVHWFramesContext { void* device_ref{}; }; struct HWBuffer { void* data{}; }; @@ -220,7 +222,7 @@ def test_secondary_failure_waits_for_real_bl_verdict_and_survives_seek(self): struct Fel { bool deviceOK=false, failed=false; }; bool dvbridge_fel_device(Fel* f, void*) { return f->deviceOK; } bool dvbridge_fel_failed(Fel* f) { return f->failed; } -bool dvbridge_fel_drain(Fel*) { return true; } +bool dvbridge_fel_drain(Fel*,const char**) { return true; } struct VideoPicture { StreamHdrType hdrType=StreamHdrType::HDR_TYPE_DOLBYVISION; int pts=0; diff --git a/tests/cb1/test_intel_hdmi_pin_out.py b/tests/cb1/test_intel_hdmi_pin_out.py index 7feaa858c1..62ea2418b0 100644 --- a/tests/cb1/test_intel_hdmi_pin_out.py +++ b/tests/cb1/test_intel_hdmi_pin_out.py @@ -1,4 +1,4 @@ -"""Exercise the pinned Intel HDMI route fixup with HDA register state.""" +"""Exercise the active HDMI audio configuration against an HDA pin register.""" import os from pathlib import Path import subprocess @@ -11,30 +11,68 @@ @unittest.skipUnless(os.environ.get('CB1_KERNEL_SOURCE'), 'requires the replayed pinned kernel') class IntelHDMIPinOut(unittest.TestCase): def test_active_route(self): - path = Path(os.environ['CB1_KERNEL_SOURCE']) / 'sound/hda/codecs/hdmi/intelhdmi.c' - fixup = function(path.read_text(), 'i915_pin_cvt_fixup') + path = Path(os.environ['CB1_KERNEL_SOURCE']) / 'sound/hda/codecs/hdmi/hdmi.c' + source = path.read_text() + refresh = function(source, 'snd_hda_hdmi_setup_audio_infoframe') + update = function(source, 'update_eld') + self.assertLess(update.index('hdmi_pcm_setup_pin('), update.index('if (eld_changed)')) + self.assertIn('snd_hda_hdmi_setup_audio_infoframe(', function(source, 'hdmi_pcm_setup_pin')) + prepare = function(source, 'snd_hda_hdmi_generic_pcm_prepare') + self.assertLess(prepare.index('scoped_guard(mutex, &per_pin->lock)'), + prepare.index('adlp_restore_pin_out(')) + self.assertLess(prepare.index('snd_hda_hdmi_setup_audio_infoframe('), + prepare.index('adlp_restore_pin_out(')) + reconcile = function(source, 'adlp_restore_pin_out') driver = r''' #include #include #include +#include #define PIN_OUT 0x40 #define AC_VERB_GET_PIN_WIDGET_CONTROL 0xf07 #define AC_VERB_SET_PIN_WIDGET_CONTROL 0x707 +#define AC_PAR_DEVLIST_LEN 0x15 +#define AC_WCAP_OUT_AMP 1 +#define AC_VERB_SET_AMP_GAIN_MUTE 0x300 +#define AMP_OUT_UNMUTE 0 typedef unsigned short hda_nid_t; -struct hdmi_spec { unsigned long pcm_in_use; }; +struct hda_codec; +struct hdac { unsigned vendor_id; }; +struct hdmi_eld { + bool eld_valid, monitor_present; + int eld_size; + unsigned char eld_buffer[2]; + struct { int spk_alloc, conn_type, sad_count; } info; +}; +struct hdac_chmap { struct { void (*set_channel_count)(struct hdac*, int, int); } ops; }; +struct hdmi_spec { + unsigned long pcm_in_use; + bool static_pcm_mapping; + struct hdac_chmap chmap; + struct { void (*pin_setup_infoframe)(struct hda_codec*, int, int, int, int, int); } ops; +}; struct hdmi_spec_per_pin { hda_nid_t cvt_nid, pin_nid; - int dev_id, pcm_idx, mux_idx; - struct { bool eld_valid; } sink_eld; + int dev_id, pcm_idx, channels; + bool non_pcm, chmap_set, setup; + unsigned char chmap[8]; + struct hdmi_eld sink_eld; }; -struct hda_codec { struct { unsigned vendor_id; } core; struct hdmi_spec *spec; }; -/* Unrelated routing helpers in the native callback. */ -#define haswell_verify_D0(...) ((void)0) -#define intel_verify_pin_cvt_connect(...) ((void)0) -#define intel_not_share_assigned_cvt(...) ((void)0) -#define intel_not_share_assigned_cvt_nid(c, p, d, n) ((void)(n)) -static int selected, select_status, regs[2], reads, writes; +struct hda_codec { struct hdac core; struct hdmi_spec *spec; }; +/* Channel mapping is unchanged and does not touch PIN_WIDGET_CONTROL. */ +#define get_wcaps(c,n) 0 +#define snd_hdac_channel_allocation(c,s,ch,m,np,map) (0) +#define snd_hdac_get_active_channels(ca) (2) +#define snd_hdac_setup_channel_mapping(...) ((void)0) +static void set_channels(struct hdac *c, int cvt, int ch) { (void)c; (void)cvt; (void)ch; } +static void infoframe(struct hda_codec *c, int p, int d, int ca, int ch, int t) { + (void)c; (void)p; (void)d; (void)ca; (void)ch; (void)t; +} +static int selected, select_status, regs[2], reads, writes, entries; static bool latch; +static inline int snd_hdac_read_parm_uncached(struct hdac *c, int pin, int param) { + (void)c; assert(pin == 7 && param == AC_PAR_DEVLIST_LEN); return entries; +} static inline int test_bit(int bit, unsigned long *map) { return (*map >> bit) & 1; } static int snd_hda_set_dev_select(struct hda_codec *c, hda_nid_t pin, int id) { (void)c; assert(pin == 7 && (id == 0 || id == 1)); @@ -42,57 +80,116 @@ def test_active_route(self): return select_status; } static inline int snd_hda_get_dev_select(struct hda_codec *c, hda_nid_t pin) { - (void)c; assert(pin == 7); return selected; + (void)c; assert(pin == 7); return entries == 0 ? -1 : selected; } static inline unsigned snd_hda_codec_read(struct hda_codec *c, hda_nid_t pin, int flags, int verb, int value) { (void)c; assert(pin == 7 && !flags && verb == AC_VERB_GET_PIN_WIDGET_CONTROL && !value); - reads++; return (unsigned)regs[selected]; + reads++; return (unsigned)regs[entries == 0 ? 0 : selected]; } static inline int snd_hda_codec_write(struct hda_codec *c, hda_nid_t pin, int flags, int verb, int value) { (void)c; assert(pin == 7 && !flags && verb == AC_VERB_SET_PIN_WIDGET_CONTROL); - writes++; regs[selected] = value; return 0; + writes++; regs[entries == 0 ? 0 : selected] = value; return 0; +} +''' + eld_calls = r''' +struct snd_jack {}; +#define snd_parse_eld(...) 0 +#define snd_show_eld(...) ((void)0) +#define schedule_delayed_work(...) ((void)0) +#define hdmi_attach_hda_pcm(...) ((void)0) +#define hdmi_detach_hda_pcm(...) ((void)0) +#define hdmi_pcm_reset_pin(...) ((void)0) +#define pin_cvt_fixup(...) ((void)0) +#define snd_jack_report(...) ((void)0) +#define snd_ctl_notify(...) ((void)0) +#define pin_idx_to_pcm_jack(...) NULL +static struct hda_codec *active_codec; +static void hdmi_pcm_setup_pin(struct hdmi_spec *spec, struct hdmi_spec_per_pin *pin) { + (void)spec; + snd_hda_hdmi_setup_audio_infoframe(active_codec, pin, false); } ''' cases = r''' int main(void) { struct scenario { const char *name; int reg, dev, pcm, active; bool eld; - unsigned id; int status; bool latch; int reads, writes; + unsigned id; int status; bool latch; int reads, writes, entries, conn_type; } tests[] = { - {"PCM output disabled", 0, 0, 2, 4, true, 0x8086281c, 0, true, 1, 1}, - {"HBR output disabled", 3, 1, 2, 4, true, 0x8086281c, 0, true, 1, 1}, - {"HBR already enabled", 0x43, 1, 2, 4, true, 0x8086281c, 0, true, 1, 0}, - {"no valid ELD", 3, 0, 2, 4, false, 0x8086281c, 0, true, 0, 0}, - {"unassigned PCM", 3, 0, -1, 4, true, 0x8086281c, 0, true, 0, 0}, - {"another PCM open", 3, 0, 2, 2, true, 0x8086281c, 0, true, 0, 0}, - {"different codec", 3, 0, 2, 4, true, 0x8086281d, 0, true, 0, 0}, - {"failed device select", 0, 1, 2, 4, true, 0x8086281c, -1, false, 0, 0}, - {"device select ignored", 0, 1, 2, 4, true, 0x8086281c, 0, false, 0, 0}, - {"pin read failed", -1, 0, 2, 4, true, 0x8086281c, 0, true, 1, 0}, + {"single-entry HDMI after modeset", 0, 0, 2, 4, true, 0x8086281c, 0, false, 1, 1, 0, 0}, + {"HBR on the same HDMI route", 3, 0, 2, 4, true, 0x8086281c, 0, false, 1, 1, 0, 0}, + {"invalid hardware length and unconfirmed owner", 0, 0, 2, 4, true, 0x8086281c, 0, false, 0, 0, -1, 0}, + {"nonzero owner on single-entry HDMI", 3, 1, 2, 4, true, 0x8086281c, 0, false, 0, 0, 0, 0}, + {"DP rejects missing selector", 0, 0, 2, 4, true, 0x8086281c, 0, false, 0, 0, 0, 1}, + {"PCM output disabled", 0, 0, 2, 4, true, 0x8086281c, 0, true, 1, 1, 1, 1}, + {"HBR output disabled", 3, 1, 2, 4, true, 0x8086281c, 0, true, 1, 1, 1, 1}, + {"HBR already enabled", 0x43, 1, 2, 4, true, 0x8086281c, 0, true, 1, 0, 1, 1}, + {"no valid ELD", 3, 0, 2, 4, false, 0x8086281c, 0, true, 0, 0, 1, 1}, + {"unassigned PCM", 3, 0, -1, 4, true, 0x8086281c, 0, true, 0, 0, 1, 1}, + {"another PCM open", 3, 0, 2, 2, true, 0x8086281c, 0, true, 0, 0, 1, 1}, + {"different codec", 3, 0, 2, 4, true, 0x8086281d, 0, true, 0, 0, 1, 1}, + {"failed device select", 0, 1, 2, 4, true, 0x8086281c, -1, false, 0, 0, 1, 1}, + {"device select ignored", 0, 1, 2, 4, true, 0x8086281c, 0, false, 0, 0, 1, 1}, + {"pin read failed", -1, 0, 2, 4, true, 0x8086281c, 0, true, 1, 0, 1, 1}, }; for (unsigned i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { struct scenario s = tests[i]; - struct hdmi_spec spec = { .pcm_in_use = s.active }; + struct hdmi_spec spec = { .pcm_in_use = s.active, .chmap.ops.set_channel_count = set_channels, + .ops.pin_setup_infoframe = infoframe }; struct hda_codec codec = { .core.vendor_id = s.id, .spec = &spec }; struct hdmi_spec_per_pin pin = { .pin_nid = 7, .dev_id = s.dev, .pcm_idx = s.pcm, - .sink_eld.eld_valid = s.eld }; - selected = 1 - s.dev; regs[selected] = 2; regs[s.dev] = s.reg; + .channels = 2, .setup = false, .sink_eld = { .eld_valid = s.eld, + .info.conn_type = s.conn_type } }; + entries = s.entries; selected = 1 - s.dev; regs[selected] = 2; regs[s.dev] = s.reg; reads = writes = 0; select_status = s.status; latch = s.latch; - i915_pin_cvt_fixup(&codec, NULL, 2); - i915_pin_cvt_fixup(&codec, &pin, 0); + /* A synthetic silent stream can have channels without a prepared route. */ + adlp_restore_pin_out(&codec, &pin); + assert(!reads && !writes); + pin.setup = true; + adlp_restore_pin_out(&codec, &pin); if (reads != s.reads || writes != s.writes || regs[1 - s.dev] != 2 || regs[s.dev] != (s.writes ? s.reg | PIN_OUT : s.reg)) { fprintf(stderr, "%s: reads=%d writes=%d reg=%d\n", s.name, reads, writes, regs[s.dev]); return 1; } + if (s.writes) { + /* Repeating the same ELD refresh must only write if a modeset reset the pin. */ + adlp_restore_pin_out(&codec, &pin); + assert(writes == 1); + regs[s.dev] = s.reg; + adlp_restore_pin_out(&codec, &pin); + assert(writes == 2 && regs[s.dev] == (s.reg | PIN_OUT)); + } } + /* ELD refresh first configures the PCM, then replaces the cached ELD. + * An HDMI-to-DP change cannot reuse HDMI's single-entry exception. */ + struct hdmi_spec spec = { .pcm_in_use = 1, .chmap.ops.set_channel_count = set_channels, + .ops.pin_setup_infoframe = infoframe }; + struct hda_codec codec = { .core.vendor_id = 0x8086281c, .spec = &spec }; + struct hdmi_spec_per_pin pin = { .pin_nid = 7, .dev_id = 0, .pcm_idx = 0, .channels = 2, + .setup = true, .sink_eld = { .eld_valid = true, .eld_size = 1, + .info = { .conn_type = 0, .sad_count = 1 } } }; + struct hdmi_eld next = pin.sink_eld; + active_codec = &codec; + entries = select_status = reads = writes = regs[0] = 0; + latch = false; + next.info.conn_type = 1; + next.eld_buffer[0] = 1; + update_eld(&codec, &pin, &next, 0); + assert(pin.sink_eld.info.conn_type == 1 && !writes && !reads); + next.info.conn_type = 0; + next.eld_buffer[0] = 2; + update_eld(&codec, &pin, &next, 0); + assert(pin.sink_eld.info.conn_type == 0 && writes == 1 && regs[0] == PIN_OUT); + regs[0] = 3; + update_eld(&codec, &pin, &next, 0); + assert(writes == 2 && regs[0] == (3 | PIN_OUT)); } ''' with tempfile.TemporaryDirectory() as tmp: source, binary = Path(tmp) / 'pin.c', Path(tmp) / 'pin' - source.write_text('\n'.join((driver, fixup, cases))) + source.write_text('\n'.join((driver, reconcile, refresh, eld_calls, update, cases))) subprocess.run(['cc', '-std=c11', '-Wall', '-Wextra', '-Werror', str(source), '-o', str(binary)], check=True) result = subprocess.run([str(binary)], text=True, capture_output=True) diff --git a/tests/cb1/test_lldv_format.py b/tests/cb1/test_lldv_format.py index 07e75dd286..fdf17e3468 100644 --- a/tests/cb1/test_lldv_format.py +++ b/tests/cb1/test_lldv_format.py @@ -458,6 +458,7 @@ def test_resolution_prefers_an_unrefused_exact_kodi_mode(self): source = (kodi / 'xbmc/windowing/gbm/WinSystemGbmGLESContext.cpp').read_text() choose = body(source, 'CWinSystemGbmGLESContext::PlayerLedResolution(') reason = body(source, 'CWinSystemGbmGLESContext::PlayerLedResolutionReason(') + fallback = body(source, 'CWinSystemGbmGLESContext::PlayerLedStartupHDR10Resolution(') program = r''' #include "utils/DVBridgeLldv.h" #include @@ -482,6 +483,10 @@ def test_resolution_prefers_an_unrefused_exact_kodi_mode(self): static CDisplaySettings& GetInstance(){static CDisplaySettings settings;return settings;} size_t ResolutionInfoSize() const{return modes.size();} const Mode& GetResolutionInfo(RESOLUTION index) const{return modes.at(index);} + Mode GetResolutionInfoCopy(RESOLUTION index) const + { + return index >= 0 && static_cast(index) < modes.size() ? modes[index] : Mode{}; + } }; namespace DVBRIDGE { @@ -498,18 +503,33 @@ def test_resolution_prefers_an_unrefused_exact_kodi_mode(self): { DVBRIDGE::LldvConnectorStatus m_dvLldvStatus; mutable std::mutex m_dvCapabilityMutex; - struct Caps{bool playerLed=true;}; + struct Caps + { + bool playerLed=true, hdr10=true, limited=false; + bool HDR10DepthLimited() const{return limited;} + }; + bool hdr10=true, currentHDR10=true, limited=false; + Caps GetDVOutputCapabilities(void*,bool allowModeSwitch) const + { + return {true,allowModeSwitch ? hdr10 : currentHDR10,limited}; + } + RESOLUTION ChooseHDR10FallbackResolution(RESOLUTION resolution) const {return resolution;} + bool SupportsDVOutputTiming(const Mode& mode) const + { + return !mode.strId.empty() && mode.strId!="7"; + } Caps GetDVOutputCapabilities(void*,const DVBRIDGE::Preferences&,bool) const{return {};} bool LldvSupportsPlaybackTiming(double) const{return true;} std::optional Choose(double fps,bool atStartup=false) const CHOOSE_BODY int PlayerLedResolutionReason(RESOLUTION resolution,int preference) const REASON_BODY + std::optional PlayerLedStartupHDR10Resolution(RESOLUTION resolution,int preference) const FALLBACK_BODY }; int main() { using namespace DVBRIDGE; constexpr double film=24000.0/1001; - CDisplaySettings::GetInstance().modes={{"0",60},{"",film},{"4",film},{"5",film},{"6",24}}; + CDisplaySettings::GetInstance().modes={{"0",60000.0/1001},{"",film},{"4",film},{"5",film},{"6",24},{"7",120}}; Window window; auto& status=window.m_dvLldvStatus; status.display.status=LldvEdidStatus::Ready; @@ -529,6 +549,25 @@ def test_resolution_prefers_an_unrefused_exact_kodi_mode(self): assert(window.PlayerLedResolutionReason(2,0)==LLDV_DRIVER_REJECTED_LABEL); assert(window.PlayerLedResolutionReason(4,0)==0); assert(window.PlayerLedResolutionReason(1,0)!=LLDV_DRIVER_REJECTED_LABEL); + // 59.94 Hz is a known HDMI timing with HDR10 transport, but no LLDV carrier. + assert(window.PlayerLedStartupHDR10Resolution(0,0)); + status.display.status=LldvEdidStatus::Missing; + assert(!window.PlayerLedStartupHDR10Resolution(0,0)); + status.display.status=LldvEdidStatus::Ready; + assert(!window.PlayerLedStartupHDR10Resolution(0,static_cast(LldvFormat::Rgb12))); + assert(window.PlayerLedStartupHDR10Resolution(2,0)); + assert(!window.PlayerLedStartupHDR10Resolution(1,0)); // unknown DRM mode + assert(!window.PlayerLedStartupHDR10Resolution(4,0)); // usable LLDV + assert(!window.PlayerLedStartupHDR10Resolution(5,0)); // 120 Hz unavailable for HDR10 conversion + assert(window.PlayerLedStartupHDR10Resolution(RES_INVALID,0)==RES_INVALID); + window.currentHDR10=false; + assert(!window.PlayerLedStartupHDR10Resolution(RES_INVALID,0)); + assert(window.PlayerLedStartupHDR10Resolution(0,0)); + window.limited=true; + assert(!window.PlayerLedStartupHDR10Resolution(0,0)); + window.limited=false; + window.hdr10=false; + assert(!window.PlayerLedStartupHDR10Resolution(0,0)); status.modeRejections.emplace_back(5,0); assert(window.Choose(film,true)==3); status.modeRejections.front().second=ten; @@ -541,7 +580,7 @@ def test_resolution_prefers_an_unrefused_exact_kodi_mode(self): preferences.hdr10TransportFallback=true; assert(!window.Choose(film,true)); } -'''.replace('CHOOSE_BODY', choose).replace('REASON_BODY', reason) +'''.replace('CHOOSE_BODY', choose).replace('REASON_BODY', reason).replace('FALLBACK_BODY', fallback) run(self, {'test.cpp': program}) def test_menu_keeps_live_forced_format_when_auto_is_unavailable(self): diff --git a/tests/cb1/test_master_screenshot.py b/tests/cb1/test_master_screenshot.py index 9ab1de5ed3..29c3dfe9ea 100644 --- a/tests/cb1/test_master_screenshot.py +++ b/tests/cb1/test_master_screenshot.py @@ -18,6 +18,7 @@ def test_native_readback_preserves_framebuffer_and_other_modes(self): #include #include constexpr int LOGWARNING=1; +struct CLog { static void Log(int,const char*){} }; namespace DVBRIDGE { class DiagnosticFailures DIAGNOSTICS; inline bool enabled=false;inline uint64_t now=0;inline unsigned logs=0;inline std::string lastStage; @@ -62,16 +63,31 @@ class DiagnosticFailures DIAGNOSTICS; struct Texture{struct{int w=3840,h=2160;}params;} texture;Texture* m_scanout=&texture; unsigned m_scanoutFramebuffer=42,m_pendingInfo=2;int pqCalls=0; struct {const void* Data(){return this;}size_t Size(){return 10;}}m_pendingMetadata; - unsigned GetPQFramebuffer(){++pqCalls;return 77;} + bool m_pendingOverlayVisible=false, m_overlayVisible=false, m_guiComposed=false, m_nativeOverlayEnabled=false; + struct {float rect[4]{};} m_nativeOverlay; + unsigned GetPQFramebuffer(bool forGUI){++pqCalls;if(forGUI)m_guiComposed=true;return 77;} struct {struct {int primaries=PL_COLOR_PRIM_BT_709;} container;} sdrOutput; auto HDR10Output() const {return &sdrOutput;} - bool ReadScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out) @@BODY@@ + bool ReadScreenshot(KODI::RENDERING::CAPTURE::ReadbackBuffer& out, bool videoOnly=false) @@BODY@@ }; int main(){ CDVBridgeGLES bridge;KODI::RENDERING::CAPTURE::ReadbackBuffer out; assert(bridge.ReadScreenshot(out));assert(bound==99 && depth==8 && flip); assert(out.format==AV_PIX_FMT_RGBA64LE && out.stride==-16 && bridge.pqCalls==0); - auto* accepted=out.pixels.get();bridge.m_direct=false; + auto* accepted=out.pixels.get(); + bridge.m_pendingOverlayVisible=bridge.m_overlayVisible=true; // Scheduled for later, clean current frame. + assert(bridge.ReadScreenshot(out,true)); + bridge.m_nativeOverlayEnabled=true; // An empty rect only primes the Master compositor. + assert(bridge.ReadScreenshot(out,true)); + bridge.m_nativeOverlay.rect[2]=bridge.m_nativeOverlay.rect[3]=1; + accepted=out.pixels.get(); + assert(!bridge.ReadScreenshot(out,true) && out.pixels.get()==accepted); + assert(bridge.ReadScreenshot(out,false)); + bridge.m_pendingOverlayVisible=bridge.m_overlayVisible=bridge.m_nativeOverlayEnabled=false; + bridge.m_guiComposed=true; + assert(!bridge.ReadScreenshot(out,true)); + bridge.m_guiComposed=false; + assert(bridge.ReadScreenshot(out,true)); accepted=out.pixels.get(); bridge.m_direct=false; assert(!bridge.ReadScreenshot(out) && out.pixels.get()==accepted && bound==99); bridge.m_direct=true;readOK=false; assert(!bridge.ReadScreenshot(out) && bound==99 && out.pixels.get()==accepted); @@ -80,6 +96,8 @@ class DiagnosticFailures DIAGNOSTICS; bridge.m_effectiveMode=1;bridge.m_direct=false; assert(bridge.ReadScreenshot(out));assert(bound==99 && depth==16 && !flip && bridge.pqCalls==1); assert(out.format==AV_PIX_FMT_RGBA && out.stride==8); + bridge.m_guiComposed=false; + assert(bridge.ReadScreenshot(out,true) && !bridge.m_guiComposed); bridge.m_effectiveMode=DVBRIDGE_MODE_SDR;bridge.m_direct=true;mapOK=false; const int priorPQ=bridge.pqCalls; assert(bridge.ReadScreenshot(out));assert(bound==99 && depth==10 && flip); diff --git a/tests/cb1/test_mode_hold.py b/tests/cb1/test_mode_hold.py index 42c14b9c73..5ba8b0a659 100644 --- a/tests/cb1/test_mode_hold.py +++ b/tests/cb1/test_mode_hold.py @@ -13,7 +13,13 @@ def test_disc_stream_changes_delegate_resolution_to_the_render_thread(self): resolve = opening.index('const bool nativeDV =') trigger = opening.index('m_renderManager.TriggerUpdateResolution', resolve) mode = opening[resolve:trigger] - synchronous = body(mode, 'if (!pMenus)') + synchronous = body(mode, 'if (!pMenus && !dvStartupModeSet)') + startup = body(opening, 'if (window && !m_HasVideo && !pMenus && !hint.interlaced') + callback = body(startup, 'auto setStartupMode = [&]') + self.assertIn('ChoosePlaybackResolution(', callback) + self.assertIn('PlayerLedStartupHDR10Resolution(', callback) + self.assertIn('SetVideoResolution(resolution, false)', callback) + self.assertIn('SendMsg(TMSG_CALLBACK', startup) self.assertEqual(mode.count('SetVideoResolution('), 1) self.assertIn('SetVideoResolution(', synchronous) self.assertIn('nativeDV', opening[trigger:opening.index(';', trigger)]) @@ -216,7 +222,7 @@ def test_renderer_carries_startup_intent_with_its_native_resolution_request(self struct Manager { bool m_bTriggerUpdateResolution=true,m_nativeDVRate=true;float m_fps=24;Picture m_picture; Renderer renderer,*m_pRenderer=&renderer;Port port,*m_playerPort=&port; - int ChoosePlaybackResolution(double fps,int width,int height,bool stereo,bool)const{return CResolutionUtils::ChooseBestResolution(fps,width,height,stereo);} + int ChoosePlaybackResolution(double fps,int width,int height,bool stereo,bool,bool,const Picture*)const{return CResolutionUtils::ChooseBestResolution(fps,width,height,stereo);} void UpdateLatencyTweak(){} void update() METHOD }; diff --git a/tests/cb1/test_mt7925_roc.py b/tests/cb1/test_mt7925_roc.py new file mode 100644 index 0000000000..9ae64462fa --- /dev/null +++ b/tests/cb1/test_mt7925_roc.py @@ -0,0 +1,33 @@ +"""Exercise Linux's MT7925 ROC callbacks with a simulated channel grant and timer.""" +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +from test_hdr10_transport import function + + +@unittest.skipUnless(os.environ.get("CB1_KERNEL_SOURCE"), "requires the replayed kernel") +class Mt7925Roc(unittest.TestCase): + def test_join_ownership(self): + directory = Path(os.environ["CB1_KERNEL_SOURCE"]) / "drivers/net/wireless/mediatek/mt76/mt7925" + driver = (directory / "main.c").read_text() + channel = driver[driver.index("static void mt7925_roc_iter("): + driver.index("static int mt7925_set_link_key(")] + callbacks = [function(driver, name) for name in + ("mt7925_mac_sta_event", "mt7925_mgd_prepare_tx", "mt7925_mgd_complete_tx")] + mcu = (directory / "mcu.c").read_text() + source = Path(__file__).with_name("mt7925_roc.c").read_text() + source = source.replace("/* DRIVER */", "\n".join([channel, *callbacks])) + source = source.replace("/* GRANT */", function(mcu, "mt7925_mcu_roc_handle_grant")) + with tempfile.TemporaryDirectory() as tmp: + binary = Path(tmp) / "roc" + subprocess.run(["cc", "-std=gnu11", "-Werror", "-x", "c", "-", "-o", str(binary)], + input=source, text=True, check=True) + for scenario in ("open", "wpa", "disassoc", "rejected", "tdls", "expired", + "busy", "failed", "mlo", "queued", "other-vif", "grant", "offchannel", + "reassoc", "removed", "busy-reject"): + with self.subTest(scenario=scenario): + result = subprocess.run([str(binary), scenario], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stderr) diff --git a/tests/cb1/test_native_spatial_contract.py b/tests/cb1/test_native_spatial_contract.py index 4a8106ba92..7d6a0d2999 100644 --- a/tests/cb1/test_native_spatial_contract.py +++ b/tests/cb1/test_native_spatial_contract.py @@ -136,7 +136,10 @@ def test_screenshot_readback_uses_current_surface_size(self): struct{unsigned stream=0,picture=0,revision=0;}m_pendingIdentity; int m_effectiveMode=1;bool m_prepared=true,m_direct=true;unsigned m_scanoutFramebuffer=0,m_outputBits=8; struct Texture{struct{int w=1920,h=1080;}params;} texture;Texture* m_scanout=&texture; - unsigned GetPQFramebuffer(){return 2;} + bool videoOnly=false,m_nativeOverlayEnabled=false,m_guiComposed=false; + struct {float rect[4]{};} m_nativeOverlay; + struct CLog { static void Log(int,const char*){} }; + unsigned GetPQFramebuffer(bool){return 2;} bool run(){ PREFIX return read && pixels.width==texture.params.w && pixels.height==texture.params.h;} }; int main(){Test t;assert(t.run());t.m_effectiveMode=5;assert(t.run()); @@ -162,16 +165,18 @@ def test_direct_hdr_admission_uses_actual_target(self): def test_dv_mode_admission_accepts_native_targets_not_stale_uhd_only(self): text = (TREE / "xbmc/windowing/gbm/WinSystemGbm.cpp").read_text() - function = body(text, "bool CWinSystemGbm::SupportsDVOutputMode(") - start = function.index(" const auto usable =") - predicate = function[start:function.index(" if (usable(", start)] + predicate = body(text, "double DVOutputTimingRate(") self.run_program(r''' #include #include -constexpr int DRM_MODE_FLAG_INTERLACE=1,DRM_MODE_FLAG_DBLSCAN=2; -struct drmModeModeInfo {int hdisplay,vdisplay,clock=148500,htotal=2200,vtotal=1125,flags=0;}; +#include +constexpr int DRM_MODE_FLAG_INTERLACE=1,DRM_MODE_FLAG_DBLSCAN=2,DRM_MODE_FLAG_3D_MASK=0xf<<14; +struct drmModeModeInfo { + int hdisplay,vdisplay,clock=148500,htotal=2200,vtotal=1125,flags=0,vscan=0; +}; struct CResolutionUtils {static bool IsCB1RefreshRate(double value){return value>=10 && value<=60;}}; -int main(){PREDICATE +double usable(const drmModeModeInfo* mode) PREDICATE +int main(){ assert(!usable(nullptr)); for(int width: {1280,1920,2560,3840}){drmModeModeInfo mode{width,width*9/16};assert(usable(&mode));} drmModeModeInfo invalid{4096,2160};assert(!usable(&invalid)); @@ -179,7 +184,7 @@ def test_dv_mode_admission_accepts_native_targets_not_stale_uhd_only(self): invalid={1920,1080};invalid.flags=DRM_MODE_FLAG_INTERLACE;assert(!usable(&invalid)); invalid.flags=0;invalid.clock*=2;assert(!usable(&invalid)); } -'''.replace("PREDICATE", predicate).replace("#include ", "#include \n#include ")) +'''.replace("PREDICATE", predicate)) def test_overlay_wrap_and_bounds_follow_current_scanout(self): text = (TREE / "xbmc/cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp").read_text() diff --git a/tests/cb1/test_native_video_screenshot.py b/tests/cb1/test_native_video_screenshot.py new file mode 100644 index 0000000000..8db9fde287 --- /dev/null +++ b/tests/cb1/test_native_video_screenshot.py @@ -0,0 +1,205 @@ +"""Exercise the native video screenshot tap with a packed carrier and a logical readback.""" +from pathlib import Path +import os +import subprocess +import tempfile +import unittest + +from test_native_video_source import TREE, body + + +class NativeVideoScreenshot(unittest.TestCase): + def test_unscaled_logical_capture(self): + xbmc = TREE / 'xbmc' + blit = (xbmc / 'rendering/capture/CaptureBlit.cpp').read_text() + renderer = (xbmc / 'cores/VideoPlayer/VideoRenderers/RenderManager.cpp').read_text() + loop = body(renderer, 'void CRenderManager::ServiceVideoCaptures()') + loop = loop[loop.rindex('for (const auto& request : requests)'):-1] + bridge = (xbmc / 'cores/VideoPlayer/VideoRenderers/DVBridgeGLES.cpp').read_text() + window = (xbmc / 'windowing/gbm/WinSystemGbmGLESContext.cpp').read_text() + prepare = body(window, 'bool CWinSystemGbmGLESContext::RenderDVBridge(') + refresh = prepare[prepare.index(' if (masterCapture)'):prepare.index(' const bool guiAvailable')] + reader = body(window, 'bool CWinSystemGbmGLESContext::ReadDVBridgeScreenshot(') + dispatch = reader[reader.rindex(' }') + 3:-1] + colors = body((xbmc / 'rendering/capture/CaptureMetadata.cpp').read_text(), + 'ImageColorMetadata GetOutputColorMetadata(') + parts = [r''' +#include "rendering/capture/CaptureReadback.h" +#include "rendering/capture/CapturePixels.h" +#include "dvbridge_metadata_bounds.h" +#include "cores/VideoPlayer/DVDCodecs/Video/DVMetadataBuffer.h" +extern "C" { +#include +#include +} +#include +#include +#include +#include +#include +using namespace KODI::RENDERING::CAPTURE; +struct CRect { float x1,y1,x2,y2; float Width() const{return x2-x1;} float Height() const{return y2-y1;} }; +struct CGraphicContext { int GetWidth() const{return 5;} int GetHeight() const{return 4;} }; +namespace KODI::UTILS { enum class Colorimetry { BT709, BT2020_RGB, BT2020_YCC, BT2020_CYCC }; enum class Eotf { SDR, PQ, HLG }; } +struct ImageColorMetadata { AVColorPrimaries primaries{}; AVColorTransferCharacteristic transfer{}; AVColorRange range{}; }; +struct Window { CGraphicContext gfx; + KODI::UTILS::Eotf eotf=KODI::UTILS::Eotf::PQ; + auto GetEotf() const {return eotf;} + auto GetColorimetry() const {return eotf==KODI::UTILS::Eotf::PQ ? KODI::UTILS::Colorimetry::BT2020_RGB : KODI::UTILS::Colorimetry::BT709;} + bool UseLimitedColor() const {return true;} + CGraphicContext& GetGfxContext(){return gfx;} }; +struct CServiceBroker { static Window* GetWinSystem(){static Window w; return &w;} }; +namespace MathUtils { int round_int(float v){return std::lround(v);} } +enum class CaptureCadence { ONESHOT, CONTINUOUS }; +enum class CaptureFormat { NATIVE, BGRA8 }; enum class CaptureContent { VIDEO, COMPOSITE, BOTH }; +struct CaptureSpec { unsigned width=0,height=0; CaptureFormat format=CaptureFormat::NATIVE; CaptureCadence cadence=CaptureCadence::ONESHOT; CaptureContent content=CaptureContent::VIDEO; }; +struct CaptureResult { + std::shared_ptr pixels; unsigned width=0,height=0; int stride=0; + AVPixelFormat format=AV_PIX_FMT_NONE; ImageColorMetadata color; int displayMetadata=0, lightMetadata=0; + bool hasDisplayMetadata=false, hasLightMetadata=false; CaptureContent content=CaptureContent::VIDEO; +}; + +enum dvbridge_mode { DVBRIDGE_MODE_MASTER_REFERENCE, HDR10, SDR, PLAYER_LED, ENHANCED }; +static dvbridge_mode mode=DVBRIDGE_MODE_MASTER_REFERENCE; +static bool logical=true, masterIPT=false, valid=true, bottom=true; +static CDVMetadataBuffer metadata; +struct CDVBridgeGLES { + unsigned invalidations=0; + void InvalidateScreenshot() { ++invalidations; } + bool UsesMasterSourceCarrier() const {return UsesMasterSourceCarrier(mode,masterIPT,metadata);} + bool ReadScreenshot(ReadbackBuffer& b, bool videoOnly); + static bool UsesMasterSourceCarrier(dvbridge_mode mode,bool masterIPT,const CDVMetadataBuffer& metadata) CARRIER +}; +static unsigned bufferWidth=5; static int pitch=48; +static unsigned decodeReads=0, ordinaryReads=0; +namespace KODI::WINDOWING::GBM { +bool HasDVBridgeScreenshot(Window&){return logical;} +bool IsDVBridgeScreenshotSDR(Window&){return mode==SDR;} +bool ReadDVBridgeScreenshot(Window&, ReadbackBuffer& out, bool videoOnly=false){ + CDVBridgeGLES bridge;auto* m_dvBridge=&bridge; + bool m_hdrConversion=mode==HDR10 || mode==SDR; + DISPATCH +} +} +bool CDVBridgeGLES::ReadScreenshot(ReadbackBuffer& b, bool videoOnly){ + assert(videoOnly); + ++decodeReads; + if(!valid)return false; + b.width=bufferWidth; b.height=4; b.stride=bottom?-pitch:pitch; b.format=AV_PIX_FMT_RGBA64LE; + b.pixels=std::make_unique(192); + for(int y=0;y<4;++y) for(int x=0;x<5;++x) b.pixels[(bottom?3-y:y)*48+x*8]=10*y+x; + return true; +} +ImageColorMetadata GetOutputColorMetadata(Window& winSystem) COLORS +class CCaptureBlit { +public: + bool Capture(const CRect&,const CaptureSpec&,CaptureResult&); + bool Blit(const CRect&,unsigned,unsigned,CaptureFormat){++ordinaryReads;return true;} + bool Read(CaptureResult& out){out.format=AV_PIX_FMT_RGBA;return true;} +}; +struct Request {CaptureSpec spec;}; +static bool fresh(const CaptureSpec& spec) { + Request item{spec}; + struct { + Request* r; + std::vector TakeActive(CaptureContent c) const { + return r->spec.content==c || r->spec.content==CaptureContent::BOTH ? + std::vector{r} : std::vector{}; + } + } registry{&item}; + auto* capture=®istry; + CDVBridgeGLES renderer; auto* m_dvBridge=&renderer; + struct {struct {dvbridge_mode mode;} policy;} m_dvSelection{{mode}}; + struct { bool masterIPT; } preferences{masterIPT}; + bool capturing=!capture->TakeActive(CaptureContent::COMPOSITE).empty(); + const bool m_sdrConversion=mode==SDR,m_hdrConversion=mode==HDR10 || m_sdrConversion; + const bool masterCapture=mode==DVBRIDGE_MODE_MASTER_REFERENCE && capturing; + REFRESH + if(m_hdrConversion && spec.content==CaptureContent::VIDEO && spec.width==0 && spec.height==0 && + spec.format==CaptureFormat::NATIVE && spec.cadence==CaptureCadence::ONESHOT) assert(capturing==!m_sdrConversion); + return renderer.invalidations!=0; +} +struct Service { + bool success=false, failed=false; CaptureResult last; + void Complete(Request*,CaptureResult r){success=true;last=std::move(r);} + void Fail(Request*){failed=true;} +}; +'''.replace('CARRIER',body(bridge,'bool CDVBridgeGLES::UsesMasterSourceCarrier(')).replace('REFRESH',refresh).replace('COLORS',colors).replace('DISPATCH',dispatch)] + fill = blit.index('void FillResult(') + parts += [blit[blit.index('bool ClampToOutput('):fill], + blit[fill:blit.index('} // namespace', fill)], + 'bool CCaptureBlit::Capture(const CRect& visible, const CaptureSpec& spec,' + ' CaptureResult& result)' + body(blit, 'bool CCaptureBlit::Capture(')] + parts += [r''' +static Service run(CaptureSpec spec, CRect visible) { + CCaptureBlit blit; auto* m_captureBlit=&blit; Service service;auto* captureService=&service; + Request item{spec}; std::vector requests{&item}; CaptureResult m_picture; + m_picture.hasDisplayMetadata=m_picture.hasLightMetadata=true; +''', loop, r''' + return service; +} +int main() { + CRect crop{0.6f,0.6f,3.4f,2.7f}; + for(bool flip : {false,true}) { + bottom=flip; + auto r=run({},crop); + assert(r.success && r.last.format==AV_PIX_FMT_RGBA64LE && !ordinaryReads); + assert(r.last.width==2 && r.last.height==2 && r.last.stride==(bottom?-48:48)); + auto row=CaptureSrcRow0(r.last.pixels->Lock(),r.last.stride,r.last.height); + assert(row[0]==11 && row[8]==12 && row[r.last.stride]==21 && row[r.last.stride+8]==22); + } + auto full=run({},{-2,-2,7,7}); assert(full.success && full.last.width==5 && full.last.height==4); + assert(!run({},{2,1,2,3}).success && !ordinaryReads); + valid=false; assert(run({},crop).failed && !ordinaryReads); + CaptureSpec both; both.content=CaptureContent::BOTH; + auto partial=run(both,crop); + assert(!partial.success && !partial.failed); // The composite tap can still serve this request. + valid=true; bufferWidth=4; assert(!run({},crop).success && !ordinaryReads); bufferWidth=5; + pitch=8; assert(!run({},crop).success && !ordinaryReads); pitch=48; + assert(run({2,3,CaptureFormat::NATIVE},crop).last.format==AV_PIX_FMT_RGBA); + assert(run({0,0,CaptureFormat::BGRA8},crop).last.format==AV_PIX_FMT_RGBA); + assert(run({0,0,CaptureFormat::NATIVE,CaptureCadence::CONTINUOUS},crop).last.format==AV_PIX_FMT_RGBA); + assert(fresh({}) && !fresh({2,3,CaptureFormat::NATIVE}) && + !fresh({0,0,CaptureFormat::BGRA8}) && !fresh({0,0,CaptureFormat::NATIVE,CaptureCadence::CONTINUOUS})); + for (auto other : {PLAYER_LED,ENHANCED}) { + mode=other; auto single=run({},crop); + assert(single.failed && !single.success && !fresh({})); + auto pair=run(both,crop); assert(!pair.failed && !pair.success); + } + for(auto conversion : {HDR10,SDR}) { + mode=conversion; assert(fresh({})); auto single=run({},crop); + assert(single.success && single.last.format==AV_PIX_FMT_RGBA64LE); + assert(single.last.color.primaries==(mode==SDR ? AVCOL_PRI_BT709 : AVCOL_PRI_BT2020)); + assert(single.last.color.transfer==(mode==SDR ? AVCOL_TRC_IEC61966_2_1 : AVCOL_TRC_SMPTE2084)); + assert(single.last.color.range==AVCOL_RANGE_JPEG && !single.last.hasDisplayMetadata && !single.last.hasLightMetadata); + } + mode=DVBRIDGE_MODE_MASTER_REFERENCE; masterIPT=true; + size_t size=0; auto* source=av_dovi_metadata_alloc(&size); assert(source); + auto* color=av_dovi_get_color(source); + color->signal_color_space=0; // YCC was converted to a different IPT carrier. + assert(metadata.Assign(reinterpret_cast(source),size)); + assert(!fresh({}) && run({},crop).failed); + partial=run(both,crop); assert(!partial.success && !partial.failed); + color->signal_color_space=2; // An authored P5 IPT carrier stays in its source encoding. + assert(metadata.Assign(reinterpret_cast(source),size)); + assert(fresh({}) && run({},crop).last.format==AV_PIX_FMT_RGBA64LE); + av_free(source); + assert(ordinaryReads==3); + logical=false; auto pass=run({},crop); + assert(pass.success && pass.last.format==AV_PIX_FMT_RGBA && pass.last.color.transfer==AVCOL_TRC_SMPTE2084 && pass.last.color.range==AVCOL_RANGE_MPEG); + CServiceBroker::GetWinSystem()->eotf=KODI::UTILS::Eotf::SDR; + pass=run({},crop); + assert(pass.success && pass.last.format==AV_PIX_FMT_RGBA && pass.last.color.transfer==AVCOL_TRC_SMPTE170M && pass.last.color.range==AVCOL_RANGE_MPEG); + assert(pass.last.hasDisplayMetadata && pass.last.hasLightMetadata && ordinaryReads==5); +} +'''] + prefix = Path(os.environ['FFMPEG_TEST_PREFIX']) + with tempfile.TemporaryDirectory() as tmp: + program = Path(tmp) / 'capture.cpp' + program.write_text('\n'.join(parts)) + binary = Path(tmp) / 'capture' + subprocess.run(['c++', '-std=c++20', '-DHAVE_DVBRIDGE', '-I'+str(xbmc), + '-I'+str(prefix/'include'), '-I'+str(Path(__file__).resolve().parents[2]/'CB1/src'), str(program), '-L'+str(prefix/'lib'), + '-lavutil', '-o', str(binary)], check=True) + subprocess.run([str(binary)], check=True, + env=dict(os.environ, LD_LIBRARY_PATH=str(prefix/'lib'))) diff --git a/tests/cb1/test_output_supersession.py b/tests/cb1/test_output_supersession.py index cdc04f5900..1dc31cebda 100644 --- a/tests/cb1/test_output_supersession.py +++ b/tests/cb1/test_output_supersession.py @@ -212,6 +212,7 @@ def test_pending_target_rekeys_and_rolls_back_through_existing_owners(self): void CompleteOutputSurface(bool accepted){if(pending&&!accepted)front=prior;pending=false;} gbm_bo*LockTransactionalBuffer(){return &front;}void CompleteTransactionalBuffer(bool){}void EndTransactionalMode(){} Lease LockFrontBuffer(){return {&front};} + gbm_bo* GetLockedFrontBuffer(){return &front;} }; struct CWinSystemGbm { int m_nWidth=3840,m_nHeight=2160,m_renderableType=EGL_OPENGL_ES3_BIT;std::shared_ptrm_DRM=std::make_shared();std::shared_ptrm_GBM=std::make_shared(); diff --git a/tests/cb1/test_sdr_gui_transfer.py b/tests/cb1/test_sdr_gui_transfer.py index c0e11c3ea4..48285d5400 100644 --- a/tests/cb1/test_sdr_gui_transfer.py +++ b/tests/cb1/test_sdr_gui_transfer.py @@ -12,7 +12,7 @@ def test_sdr_gamma_never_enables_pq_or_hlg_gui_conversion(self): #include #include #include -constexpr int AVCOL_TRC_GAMMA22=4,AVCOL_TRC_SMPTE2084=16,AVCOL_TRC_ARIB_STD_B67=18; +constexpr int AVCOL_TRC_GAMMA22=4,AVCOL_TRC_BT2020_10=14,AVCOL_TRC_SMPTE2084=16,AVCOL_TRC_ARIB_STD_B67=18; constexpr int LOGERROR=1,LOGDEBUG=2; struct CLog{templatestatic void Log(Args...){}}; unsigned deleted=0; @@ -27,9 +27,11 @@ def test_sdr_gamma_never_enables_pq_or_hlg_gui_conversion(self): }; int main(){ CGuiCompositeShaderGLES shader; - for(float gamma:{2.2f,2.4f,2.6f}){ - assert(shader.CreateLUTs(AVCOL_TRC_GAMMA22,gamma)); - assert(shader.m_ootfGamma==-gamma && !shader.m_lutTFTexId && shader.pqCalls==0); + for(int transfer:{AVCOL_TRC_GAMMA22,AVCOL_TRC_BT2020_10}){ + for(float gamma:{2.2f,2.4f,2.6f}){ + assert(shader.CreateLUTs(transfer,gamma)); + assert(shader.m_ootfGamma==-gamma && !shader.m_lutTFTexId && shader.pqCalls==0); + } } assert(!shader.CreateLUTs(AVCOL_TRC_GAMMA22,NAN)); assert(shader.CreateLUTs(AVCOL_TRC_SMPTE2084));assert(shader.m_ootfGamma==0 && shader.pqCalls==1); diff --git a/tests/cb1/test_sdr_live_settings.py b/tests/cb1/test_sdr_live_settings.py index 7dfd124514..f97f54a0a7 100644 --- a/tests/cb1/test_sdr_live_settings.py +++ b/tests/cb1/test_sdr_live_settings.py @@ -61,7 +61,7 @@ def test_same_mode_live_pause_failure_and_rollback_use_the_matching_gui_gamma(se #include #include #include "dvbridge_policy.h" -constexpr int AVCOL_TRC_GAMMA22=4,AVCOL_TRC_SMPTE2084=16,AVCOL_TRC_ARIB_STD_B67=18,LOGERROR=1,LOGDEBUG=2,DVBRIDGE_DV_IDLE=0,DVBRIDGE_DV_FAILED=3; +constexpr int AVCOL_TRC_GAMMA22=4,AVCOL_TRC_BT2020_10=14,AVCOL_TRC_SMPTE2084=16,AVCOL_TRC_ARIB_STD_B67=18,LOGERROR=1,LOGDEBUG=2,DVBRIDGE_DV_IDLE=0,DVBRIDGE_DV_FAILED=3; struct CLog{templatestatic void Log(A...){}}; bool failLUT=false;unsigned textures=0; void glDeleteTextures(int,const unsigned*){} @@ -70,6 +70,8 @@ def test_same_mode_live_pause_failure_and_rollback_use_the_matching_gui_gamma(se explicit CGuiCompositeShaderGLES(const std::string&){}bool CompileAndLink(){return true;} unsigned CreateLUTTexture(const std::vector&){++textures;return failLUT?0:1;} std::vectorGenerateDegammaLUT(){return {0,1};}std::vectorGeneratePQLUT(float){return {0,1};} + bool wide=false,premultiplied=false; + void SetSDRBT2020(bool enabled,bool coverage){wide=enabled;premultiplied=coverage;} bool CreateLUTs(int colorTransfer,float sdrGamma) SHADER }; namespace DVBRIDGE {enum class OutputRoute{Vanilla,NativeDV,HDR10,SDR, PlayerLed};} @@ -103,6 +105,11 @@ def test_same_mode_live_pause_failure_and_rollback_use_the_matching_gui_gamma(se Window(){m_dvSelection.policy.mode=DVBRIDGE_MODE_SDR;m_dvSelection.policy.sdr.preset=DVBRIDGE_SDR_REFERENCE;assert(SetGuiCompositing(AVCOL_TRC_GAMMA22));} }; int main(int argc,char**argv){assert(argc==2);std::string test=argv[1];Window w;const auto initial=textures;w.m_guiCacheValid=true; + if(test=="native"){w.m_sdrConversion=w.m_hdrConversion=false; + assert(w.SetGuiCompositing(AVCOL_TRC_BT2020_10)); + assert(w.m_compositeShader->wide && w.m_compositeShader->premultiplied && w.m_compositeShader->m_ootfGamma==-2.4f); + assert(w.SetGuiCompositing(AVCOL_TRC_GAMMA22)); + assert(!w.m_compositeShader->wide && !w.m_compositeShader->premultiplied && w.m_compositeShader->m_ootfGamma==-2.4f);} if(test=="live"){w.m_dvSelection.policy.sdr.preset=DVBRIDGE_SDR_BRIGHT;assert(w.Prepare());assert(w.m_compositeShader->m_ootfGamma==-2.2f&&!w.m_guiCacheValid);} if(test=="paused"){w.m_dvSelection.policy.sdr={DVBRIDGE_SDR_CUSTOM,120,2.6,.01,DVBRIDGE_GAMUT_UNSET};assert(w.Begin());assert(w.m_compositeShader->m_ootfGamma==-2.6f&&!w.m_guiCacheValid);} if(test=="unchanged"){for(unsigned i=0;i<100;++i){assert(w.Prepare()&&w.Begin());}assert(textures==initial&&w.m_guiCacheValid);} @@ -116,7 +123,7 @@ def test_same_mode_live_pause_failure_and_rollback_use_the_matching_gui_gamma(se 'CONFIGGUI',body(source,'bool CWinSystemGbmGLESContext::ConfigureGuiCompositing(')).replace( 'PREPARE',prepare).replace('BEGIN',begin).replace('SNAPSHOT',snapshot).replace( 'ROLLBACK',body(source,'bool CWinSystemGbmGLESContext::PollRejectedDVSurface()')) - compile_run(self,program,('live','paused','unchanged','lut-failure','invalid-target','rollback','rollback-failure'), + compile_run(self,program,('native','live','paused','unchanged','lut-failure','invalid-target','rollback','rollback-failure'), ('-DHAVE_DVBRIDGE','-Wall','-Wextra','-Werror')) def test_requested_hdr10plus_sdr_policy_comes_from_the_immutable_source(self):