diff --git a/engine/core/DynamicNativeSessionPublisher.h b/engine/core/DynamicNativeSessionPublisher.h index f01866602..91cddac21 100644 --- a/engine/core/DynamicNativeSessionPublisher.h +++ b/engine/core/DynamicNativeSessionPublisher.h @@ -2,6 +2,7 @@ #pragma once #include "DynamicPreparedMixerBlock.h" #include "../device/MultiDeviceInputPlan.h" +#include "../device/QualifiedPrimaryRestartRecoveryPlan.h" #include "DynamicConsoleRoutingView.h" #include "NativeMusicTempoMonitor.h" #include "NativeBeatFrameContext.h" @@ -55,6 +56,12 @@ class DynamicNativeSessionPublisher final { none, staleDevice, staleRevision, outputArmed, invalidGraph, retirementFull, invalidCandidate }; + // Explicit CONTROL transition: a persisted primary-only .smix may + // replace a qualified A+B graph. Ordinary WIRE/FX edits MUST inherit + // the prior qualified map; absence of an argument never drops it. + enum class QualifiedMapChange : std::uint8_t { + inherit, replaceWithPrimaryOnly + }; struct CommitResult final { Fault fault=Fault::none; DynamicGraphError graphError{}; @@ -77,7 +84,8 @@ class DynamicNativeSessionPublisher final { bool allOutputsDisarmed, FxPlan fx={nullptr,nullptr,nullptr,0,0,nullptr},bool verifiedInternalWireOnly=false, bool verifiedInternalFxOnly=false, - const armix::device::MultiDeviceInputPlan* qualifiedInputMap=nullptr) { + const armix::device::MultiDeviceInputPlan* qualifiedInputMap=nullptr, + QualifiedMapChange mapChange=QualifiedMapChange::inherit) { CommitResult report;report.revision=publisher_.lastRevision(); if(!fx.valid() || (fx.owner && (fx.deviceEpoch!=proposedDeviceEpoch || @@ -103,21 +111,52 @@ class DynamicNativeSessionPublisher final { !verifiedInternalFxOnly) { report.fault=Fault::outputArmed;return report; } + // CONTROL: the next BUS/WIRE/FX-only revision retains the exact + // already-qualified device map. Omitting the optional argument must + // never turn a dual-device graph into unqualified ordinal-only PCM. + // Replacing a device map is ALWAYS a hardware transaction requiring + // MAIN/MONITOR/output disarm, not a hidden in-place WIRE edit. + const auto* prior=publisher_.controlPrepared( + proposedDeviceEpoch,expectedRevision); + // Old A+B input maps are still CONTROL-owned after a primary epoch + // change, but cannot render in that new epoch. Only explicit A-only + // session replacement may retire that previous qualified lease. + const auto ownedEpoch=publisher_.controlOwnedEpoch(expectedRevision); + const auto* retained=ownedEpoch? + publisher_.controlPrepared(ownedEpoch,expectedRevision):nullptr; + if(qualifiedInputMap&&!allOutputsDisarmed) { + report.fault=Fault::outputArmed;return report; + } + const bool replacing=mapChange==QualifiedMapChange::replaceWithPrimaryOnly; + if(replacing && (!allOutputsDisarmed || qualifiedInputMap || + verifiedInternalWireOnly || verifiedInternalFxOnly || + !retained || !retained->inputMap)) { + report.fault=Fault::invalidCandidate;return report; + } + // A cross-epoch commit missing the explicit retirement marker must + // NOT discard B's map and reinterpret its virtual pins as A inputs. + if(!replacing && retained && retained->inputMap && !prior && + !qualifiedInputMap) { + report.fault=Fault::invalidCandidate;return report; + } + const auto* acceptedInputMap=replacing?nullptr: + qualifiedInputMap?qualifiedInputMap: + (prior&&prior->inputMap?prior->inputMap.get():nullptr); // CONTROL: validate every physical source against ONE actual // device-qualified map before starting a potentially costly graph // compile. Reject mixed old/new source namespaces as a transaction. - if(qualifiedInputMap) { - if(qualifiedInputMap->primaryEpoch()!=proposedDeviceEpoch || - qualifiedInputMap->deviceCount()<1 || - qualifiedInputMap->virtualInputCount()!=request.physicalInputs) { + if(acceptedInputMap) { + if(acceptedInputMap->primaryEpoch()!=proposedDeviceEpoch || + acceptedInputMap->deviceCount()<1 || + acceptedInputMap->virtualInputCount()!=request.physicalInputs) { report.fault=Fault::invalidCandidate;return report; } std::size_t matched=0; for(const auto& source:request.sources) { if(source.kind!=DynamicSourceKind::physical)continue; bool verified=false; - for(int i=0;isourceCount();++i) { - const auto& mapped=qualifiedInputMap->source(i); + for(int i=0;isourceCount();++i) { + const auto& mapped=acceptedInputMap->source(i); if(source.id==mapped.channel && source.inputL==mapped.inputL && source.inputR==mapped.inputR && @@ -130,7 +169,7 @@ class DynamicNativeSessionPublisher final { } ++matched; } - if(matched!=static_cast(qualifiedInputMap->sourceCount())) { + if(matched!=static_cast(acceptedInputMap->sourceCount())) { report.fault=Fault::invalidCandidate;return report; } } @@ -153,9 +192,9 @@ class DynamicNativeSessionPublisher final { report.fault=Fault::invalidGraph;return report; } prepared->physicalInputs=request.physicalInputs; - if(qualifiedInputMap) + if(acceptedInputMap) prepared->inputMap= - std::make_unique(*qualifiedInputMap); + std::make_unique(*acceptedInputMap); prepared->fx=std::move(fx); // one accepted control-plane publication prepared->monitor=std::any_of(roster.channels().begin(), roster.channels().end(),[](const ChannelStripDefinition& row) { @@ -475,6 +514,35 @@ class DynamicNativeSessionPublisher final { const auto* p=publisher_.controlPrepared(epoch,revision); return p?p->graph.latencySamples():0; } + // CONTROL-only durability guard: v1 .smix binds only the primary A + // hardware mask. Qualified A+B virtual input ordinals cannot safely + // replace physical device-qualified saved source intent. + bool hasQualifiedInputMap(std::uint64_t epoch, + std::uint64_t revision) const noexcept { + const auto* p=publisher_.controlPrepared(epoch,revision); + return p && static_cast(p->inputMap); + } + // CONTROL-only primary restart: stage A-only physical sources from + // the PREVIOUS accepted A+B lease. Never reinterpret B virtual slots as + // callback indices and never destroy the original graph on failure. + bool preparePrimaryRestartFallback(std::uint64_t priorEpoch, + std::uint64_t priorRevision,int verifiedPrimaryInputs, + const DynamicGraphRequest& accepted, + DynamicGraphRequest& destination) const { + const auto* p=publisher_.controlPrepared(priorEpoch,priorRevision); + return p && p->inputMap && + armix::device::QualifiedPrimaryRestartRecoveryPlan::stage( + *p->inputMap,accepted,verifiedPrimaryInputs,destination); + } + // CONTROL-only explicit source disconnection; never mutate the + // callback-visible prior map. WIRE/FX revisions keep inheriting it. + bool qualifiedMapWithoutSource(std::uint64_t epoch, + std::uint64_t revision,ChannelId source, + armix::device::MultiDeviceInputPlan& candidate) const { + const auto* p=publisher_.controlPrepared(epoch,revision); + return p && p->inputMap && + p->inputMap->withoutSource(source,candidate); + } void unpublish() noexcept {publisher_.unpublish();} void pollRetirement() noexcept {publisher_.pollRetirement();} std::uint64_t acceptedRevision() const noexcept { diff --git a/engine/core/RealtimeRoutePublisher.h b/engine/core/RealtimeRoutePublisher.h index 1e72f59c3..2ce842ce2 100644 --- a/engine/core/RealtimeRoutePublisher.h +++ b/engine/core/RealtimeRoutePublisher.h @@ -160,6 +160,15 @@ class RealtimeRoutePublisher final { owned_->graphRevision==expectedRevision ?owned_->prepared.get():nullptr; } + // CONTROL only. Cross-epoch recovery may need to inspect the LAST + // accepted qualified lease for explicit transaction retirement. Do not + // expose the old epoch as a valid RT producer: ReadLease::get() remains + // exact-epoch guarded, and no stale graph may render after device START. + std::uint64_t controlOwnedEpoch(std::uint64_t revision) const noexcept { + return owned_ && owned_->prepared && revision_==revision && + owned_->graphRevision==revision + ? owned_->deviceEpoch:0; + } [[nodiscard]] ReadLease acquire(bool skip=false) noexcept {return ReadLease(*this,skip);} std::uint64_t lastRevision() const noexcept {return revision_;} // CONTROL std::size_t pendingRetirements() const noexcept {return retiredCount_;} // CONTROL diff --git a/engine/device/LiveSecondaryCaptureDevice.h b/engine/device/LiveSecondaryCaptureDevice.h index 47972b05f..916171a0f 100644 --- a/engine/device/LiveSecondaryCaptureDevice.h +++ b/engine/device/LiveSecondaryCaptureDevice.h @@ -198,6 +198,9 @@ class LiveSecondaryCaptureDevice final bool ready() const noexcept{return opened_.load(std::memory_order_acquire)&& stream_.ready();} bool faulted() const noexcept{return stream_.faulted();} + // Borrowed ONLY from the one native primary callback; lifetime owned by + // this LiveSecondaryCaptureDevice and serialized CONTROL stop/close. + SecondaryCaptureClockStream& clockStream() noexcept{return stream_;} Readback readback() const // CONTROL only: called after driver lifecycle { Readback b; diff --git a/engine/device/MultiDeviceInputPlan.h b/engine/device/MultiDeviceInputPlan.h index 83ce02a20..1ea632b9c 100644 --- a/engine/device/MultiDeviceInputPlan.h +++ b/engine/device/MultiDeviceInputPlan.h @@ -287,6 +287,25 @@ class MultiDeviceInputPlan final { const PreparedChannelSource& source(int index) const noexcept { return assignments_[index]; } + // IO-2D: explicit SOURCE NONE / Delete Track staging. Keep *every* + // verified device generation, lease and virtual slot unchanged; remove + // only one ChannelId's PCM assignment in a DETACHED CONTROL candidate. + // The entire graph+map publishes as one immutable snapshot on success. + bool withoutSource(armix::mixer::ChannelId removed, + MultiDeviceInputPlan& destination) const { + if(!primaryEpoch_ || !removed.value)return false; + MultiDeviceInputPlan staged=*this; + int write=0; + bool found=false; + for(int i=0;i + +// CONTROL-side exact A/B admission; no driver query or realtime work. +// Caller MUST derive both device identities and masks from independently +// attested native hardware readback, never from display labels or .smix. +namespace armix::device { +class QualifiedCaptureAdmission final { +public: + enum class Fault { + none, stalePrimary, wrongTopology, wrongPrimaryPins, + secondaryNotReady, wrongCaptureLease, unsafeFrames + }; + static Fault verify(const MultiDeviceInputPlan& plan, + const SecondaryCaptureClockStream& clock, + std::uint64_t primaryEpoch, + int verifiedPrimaryInputCount, + int maximumRenderFrames) noexcept { + if(!primaryEpoch||plan.primaryEpoch()!=primaryEpoch|| + plan.deviceCount()!=2|| + plan.device(0).generation!=primaryEpoch) + return Fault::stalePrimary; + if(!plan.device(0).primary||plan.device(1).primary|| + !plan.device(0).deviceLease||!plan.device(1).deviceLease|| + plan.device(0).deviceLease==plan.device(1).deviceLease|| + plan.device(1).activePins<1|| + plan.device(1).activePins>16) + return Fault::wrongTopology; + if(verifiedPrimaryInputCount<1|| + plan.device(0).activePins!=verifiedPrimaryInputCount) + return Fault::wrongPrimaryPins; + if(maximumRenderFrames<1|| + maximumRenderFrames>MultiDeviceInputPlan::maxCallbackFrames) + return Fault::unsafeFrames; + if(!clock.ready())return Fault::secondaryNotReady; + const auto& format=clock.format(); // CONTROL only; not in RT + // The ASIO callback period is a HARDWARE value. The native graph + // legitimately renders in smaller bounded chunks when the period + // exceeds the retained VST scratch quantum. Reader::prepare() and + // withBlocks() are constrained by maximumRenderFrames, not by the + // whole hardware callback size. Never reject a valid 512->256 split. + if(format.captureGeneration!=plan.device(1).generation|| + format.deviceLease!=plan.device(1).deviceLease|| + format.primaryEpoch!=primaryEpoch|| + format.channels!=plan.device(1).activePins|| + format.primaryPeriod<1|| + format.primaryPeriod>MultiDeviceInputPlan::maxCallbackFrames) + return Fault::wrongCaptureLease; + return Fault::none; + } +}; +} // namespace armix::device diff --git a/engine/device/QualifiedCaptureHostMode.h b/engine/device/QualifiedCaptureHostMode.h new file mode 100644 index 000000000..a19f415a3 --- /dev/null +++ b/engine/device/QualifiedCaptureHostMode.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +// IO-2D: native callback selection is a pure rule, not another renderer. +// The existing qualified reader and publisher still check exact leases. +namespace armix::device { +enum class QualifiedCaptureHostMode { + directPrimary, qualifiedDual, rejectPartial +}; +constexpr QualifiedCaptureHostMode qualifiedCaptureHostMode( + bool hasReader,bool hasClock) noexcept { + if(!hasReader&&!hasClock)return QualifiedCaptureHostMode::directPrimary; + if(hasReader&&hasClock)return QualifiedCaptureHostMode::qualifiedDual; + return QualifiedCaptureHostMode::rejectPartial; +} +} // namespace armix::device diff --git a/engine/device/QualifiedPrimaryRestartRecoveryPlan.h b/engine/device/QualifiedPrimaryRestartRecoveryPlan.h new file mode 100644 index 000000000..c7dec428f --- /dev/null +++ b/engine/device/QualifiedPrimaryRestartRecoveryPlan.h @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once + +#include "MultiDeviceInputPlan.h" +#include "../core/DynamicPreparedMixerBlock.h" +#include +#include + +// IO-2D CONTROL-only, non-destructive restart fallback. Keep the entire +// ChannelId/WIRE/VST3 graph, but remove B's old physical source assignments +// from a DETACHED request after the primary ASIO clock changes. Never render +// or authorize an ordinal from the previous secondary device lease. +namespace armix::device { +class QualifiedPrimaryRestartRecoveryPlan final { +public: + static bool stage(const MultiDeviceInputPlan& prior, + const armix::mixer::DynamicGraphRequest& accepted, + int verifiedPrimaryInputs, + armix::mixer::DynamicGraphRequest& destination) { + using namespace armix::mixer; + if(prior.primaryEpoch()==0 || prior.deviceCount()!=2 || + !prior.device(0).primary || prior.device(0).firstVirtual!=0 || + prior.device(0).activePins<=0 || + verifiedPrimaryInputs!=prior.device(0).activePins || + prior.virtualInputCount()!=accepted.physicalInputs || + prior.virtualInputCount()<=verifiedPrimaryInputs) + return false; + int sourceCount=0; + for(const auto& source:accepted.sources) { + if(source.kind!=DynamicSourceKind::physical)continue; + ++sourceCount; + bool matched=false; + for(int i=0;i=prior.virtualInputCount() || + (source.stereo && + (source.inputR<0 || + source.inputR>=prior.virtualInputCount()))) + return false; + const auto device=prior.slot(source.inputL).device; + if((device==0 && source.inputL>=verifiedPrimaryInputs) || + (device!=0 && source.inputL +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// IO-2C: one primary callback consuming ONE independent capture clock (B). +// This only assembles qualified borrowed PCM for the existing native graph; +// it NEVER renders FX, owns hardware, creates a callback, or publishes a +// second source of truth. The operator-verified map is published separately +// in the SAME native PCM/FX snapshot by DynamicNativeSessionPublisher. +// +// prepare/stop: CONTROL ONLY, after output disarm and callback ownership gate. +// withBlocks: PRIMARY callback ONLY. Buffer/pointer lifetime spans the entire +// caller's render invocation. Future N-device support must extend this bounded +// writer/reader ownership explicitly; sharing one SPSC between producers is +// prohibited. +namespace armix::device { + +class QualifiedSecondaryCaptureReader final { +public: + using CaptureBlock=MultiDeviceInputPlan::CaptureBlock; + static constexpr int maxSecondaryChannels=16; + static constexpr int maxCallbackFrames=8192; + // One seq-cst atomic for writer admission AND bounded callback leases. + static constexpr std::uint32_t writerFlag=1U,readerUnit=2U; + struct Status { + bool ready=false; + std::uint64_t primaryBlocks=0,secondaryAccepted=0,secondarySilent=0, + rejected=0,overlaps=0; + }; + + QualifiedSecondaryCaptureReader()=default; + QualifiedSecondaryCaptureReader(const QualifiedSecondaryCaptureReader&)=delete; + QualifiedSecondaryCaptureReader& operator=(const QualifiedSecondaryCaptureReader&)=delete; + + // CONTROL: allocate once with exact size, never on the primary callback. + // The native host must detach/disarm before modifying this adapter. + bool prepare(const MultiDeviceInputPlan& qualified,int maximumFrames) { + stop(); + if(qualified.primaryEpoch()==0||qualified.deviceCount()!=2|| + maximumFrames<=0||maximumFrames>maxCallbackFrames|| + !qualified.device(0).primary||qualified.device(1).primary || + qualified.device(0).generation!=qualified.primaryEpoch()|| + qualified.device(0).deviceLease==0||qualified.device(1).deviceLease==0|| + qualified.device(0).deviceLease==qualified.device(1).deviceLease|| + qualified.device(0).activePins<1|| + qualified.device(1).activePins<1|| + qualified.device(1).activePins>maxSecondaryChannels)return false; + const int n=qualified.device(1).activePins; + const auto total=static_cast(n)* + static_cast(maximumFrames); + std::unique_ptr newScratch{new(std::nothrow) float[total]{}}; + if(!newScratch)return false; + scratch_=std::move(newScratch); + epoch_=qualified.primaryEpoch(); + primaryGeneration_=qualified.device(0).generation; + primaryLease_=qualified.device(0).deviceLease; + secondaryGeneration_=qualified.device(1).generation; + secondaryLease_=qualified.device(1).deviceLease; + primaryChannels_=qualified.device(0).activePins; + secondaryChannels_=n; + maximumFrames_=maximumFrames; + for(int c=0;c(c)*static_cast(maximumFrames); + write_[c]=channel;read_[c]=channel; + } + primaryBlocks_.store(0,std::memory_order_relaxed); + secondaryAccepted_.store(0,std::memory_order_relaxed); + secondarySilent_.store(0,std::memory_order_relaxed); + rejected_.store(0,std::memory_order_relaxed); + overlaps_.store(0,std::memory_order_relaxed); + ready_.store(true,std::memory_order_release); + // stop() keeps the writer bit held until every scratch pointer and + // physical lease is initialized, then readers may enter atomically. + activity_.fetch_and(~writerFlag,std::memory_order_seq_cst); + return true; + } + + // CONTROL ONLY, never called inside either audio callback. + // Prevent reprepare/free while a borrowed scratch view is rendering. + void stop() noexcept { + // Atomically close admission before examining reader count. + // A reader that won the CAS must finish; new arrivals reject. + activity_.fetch_or(writerFlag,std::memory_order_seq_cst); + ready_.store(false,std::memory_order_release); + while((activity_.load(std::memory_order_seq_cst)&~writerFlag)!=0) + std::this_thread::yield(); // CONTROL only, never audio callback + scratch_.reset(); + write_={};read_={}; + epoch_=primaryGeneration_=primaryLease_=0; + secondaryGeneration_=secondaryLease_=0; + primaryChannels_=secondaryChannels_=maximumFrames_=0; + } + + // PRIMARY callback only. Render owns the view synchronously and returns + // before scratch can be reused; a broken overlapping driver fails silent. + // The caller MUST silence physical outputs on a false return. + template + bool withBlocks(std::uint64_t primaryEpoch, + const float* const* primary,int primaryChannels, + int frames,SecondaryCaptureClockStream& secondary, + Render&& render) noexcept { + static_assert(std::is_nothrow_invocable_r_v>, + "Render must synchronously consume blocks without throwing"); + // Single non-blocking compare-exchange; no audio-thread spin. + // Counter and stop/admission flag share one linearizable state. + auto activity=activity_.load(std::memory_order_seq_cst); + if((activity&writerFlag)!=0 || + activity>std::numeric_limits::max()-readerUnit || + !activity_.compare_exchange_strong(activity,activity+readerUnit, + std::memory_order_seq_cst,std::memory_order_seq_cst)) { + rejected_.fetch_add(1,std::memory_order_relaxed); + return false; + } + const bool admitted=ready_.load(std::memory_order_acquire) && + scratch_ && primaryEpoch==epoch_ && + primaryChannels==primaryChannels_ && + frames>0&&frames<=maximumFrames_ && + (primaryChannels==0||primary!=nullptr); + if(!admitted) { + rejected_.fetch_add(1,std::memory_order_relaxed); + activity_.fetch_sub(readerUnit,std::memory_order_seq_cst); + return false; + } + armix::rt::RealtimeRenderPermit exclusive{consumer_}; + if(!exclusive){ + overlaps_.fetch_add(1,std::memory_order_relaxed); + activity_.fetch_sub(readerUnit,std::memory_order_seq_cst); + return false; + } + primaryBlocks_.fetch_add(1,std::memory_order_relaxed); + // Separate SPSC: B's real device callback pushes at capture rate; + // this primary callback is the sole FIFO consumer after ASRC. + const bool bReady=secondary.pull(write_.data(),secondaryChannels_, + frames,secondaryGeneration_,primaryEpoch,secondaryLease_); + if(bReady)secondaryAccepted_.fetch_add(1,std::memory_order_relaxed); + else secondarySilent_.fetch_add(1,std::memory_order_relaxed); + const std::array blocks{{ + {primary,primaryChannels,frames,primaryGeneration_,true,primaryLease_}, + {read_.data(),secondaryChannels_,frames,secondaryGeneration_, + bReady,secondaryLease_} + }}; + // The receiver must use the SAME snapshot-owned input map/graph as + // this primary callback; it cannot hold this view after return. + const bool ok=std::forward(render)( + std::span(blocks.data(),blocks.size())); + activity_.fetch_sub(readerUnit,std::memory_order_seq_cst); + return ok; + } + + Status status() const noexcept { + return {ready_.load(std::memory_order_acquire) && + !(activity_.load(std::memory_order_seq_cst)&writerFlag), + primaryBlocks_.load(std::memory_order_relaxed), + secondaryAccepted_.load(std::memory_order_relaxed), + secondarySilent_.load(std::memory_order_relaxed), + rejected_.load(std::memory_order_relaxed), + overlaps_.load(std::memory_order_relaxed)}; + } + +private: + // No reader can remain after stop's CONTROL quiescence barrier. + // Same gate as RealtimeRoutePublisher: writer=bit0, each reader=+2. + std::unique_ptr scratch_; + std::array write_{}; + std::array read_{}; + std::uint64_t epoch_=0,primaryGeneration_=0,primaryLease_=0, + secondaryGeneration_=0,secondaryLease_=0; + int primaryChannels_=0,secondaryChannels_=0,maximumFrames_=0; + std::atomic ready_{false}; + std::atomic activity_{writerFlag}; + std::atomic_flag consumer_=ATOMIC_FLAG_INIT; + std::atomic primaryBlocks_{0},secondaryAccepted_{0}, + secondarySilent_{0},rejected_{0},overlaps_{0}; +}; +} // namespace armix::device diff --git a/engine/device/SecondaryCaptureClockStream.h b/engine/device/SecondaryCaptureClockStream.h index 60acddff3..5b6528b70 100644 --- a/engine/device/SecondaryCaptureClockStream.h +++ b/engine/device/SecondaryCaptureClockStream.h @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace armix::device @@ -21,6 +22,8 @@ class SecondaryCaptureClockStream final public: static constexpr int capacityFrames=32768; static constexpr int maxCallbackFrames=8192; + // Independent atomic admission gates avoid A/B clock callback contention. + static constexpr std::uint32_t writerFlag=1U,readerUnit=2U; struct Format { double captureHz=0.,primaryHz=0.; @@ -36,12 +39,11 @@ class SecondaryCaptureClockStream final bool prepare(const Format& format,double desiredTargetMs=24.) { - if(ready_.load(std::memory_order_acquire)|| - producers_.load(std::memory_order_acquire)!=0|| - consumers_.load(std::memory_order_acquire)!=0) - return false; + if(ready_.load(std::memory_order_acquire))return false; + // Faulted callbacks may still be in flight even with ready=false. + // CONTROL closes BOTH entry gates and drains old leases before ASRC. + stop(); // leaves both writer bits held until activate() // CONTROL owns the entire format and bridge reprepare interval. - ready_.store(false,std::memory_order_release); fault_.store(false,std::memory_order_release); // A previous successfully prepared (but not activated) stream must // never survive an invalid replacement request. activate() may not @@ -75,6 +77,9 @@ class SecondaryCaptureClockStream final if(!prepared_||fault_.load(std::memory_order_acquire)) return false; ready_.store(true,std::memory_order_release); + // Complete physical format + FIR initialization before opening RT. + producerActivity_.fetch_and(~writerFlag,std::memory_order_seq_cst); + consumerActivity_.fetch_and(~writerFlag,std::memory_order_seq_cst); return true; } @@ -90,10 +95,14 @@ class SecondaryCaptureClockStream final // Never call this or yield on either audio callback. void stop() noexcept { + // Set BOTH writer bits BEFORE observing in-flight borrow counts. + // Each CAS-admitted producer/consumer must retire before resetStopped. + producerActivity_.fetch_or(writerFlag,std::memory_order_seq_cst); + consumerActivity_.fetch_or(writerFlag,std::memory_order_seq_cst); ready_.store(false,std::memory_order_release); - while(producers_.load(std::memory_order_acquire)!=0|| - consumers_.load(std::memory_order_acquire)!=0) - std::this_thread::yield(); + while((producerActivity_.load(std::memory_order_seq_cst)&~writerFlag)!=0|| + (consumerActivity_.load(std::memory_order_seq_cst)&~writerFlag)!=0) + std::this_thread::yield(); // CONTROL only, never RT prepared_=false; fault_.store(false,std::memory_order_release); bridge_.resetStopped(); // no live producer or consumer @@ -102,16 +111,23 @@ class SecondaryCaptureClockStream final bool push(const float* const* capture,int channels,int frames) noexcept { - producers_.fetch_add(1,std::memory_order_acq_rel); + // One nonblocking CAS; no spin/lock/device call on B callback. + auto state=producerActivity_.load(std::memory_order_seq_cst); + if((state&writerFlag)!=0 || + state>std::numeric_limits::max()-readerUnit || + !producerActivity_.compare_exchange_strong( + state,state+readerUnit, + std::memory_order_seq_cst,std::memory_order_seq_cst)) + return false; const bool enabled=ready_.load(std::memory_order_acquire)&& !fault_.load(std::memory_order_acquire); - if(!enabled){producers_.fetch_sub(1,std::memory_order_release);return false;} + if(!enabled){producerActivity_.fetch_sub(readerUnit,std::memory_order_seq_cst);return false;} if(!capture||channels!=format_.channels||frames<1|| frames>maxCallbackFrames) { invalidBlocks_.fetch_add(1,std::memory_order_relaxed); fault(); - producers_.fetch_sub(1,std::memory_order_release); + producerActivity_.fetch_sub(readerUnit,std::memory_order_seq_cst); return false; } for(int c=0;cstd::numeric_limits::max()-readerUnit || + !consumerActivity_.compare_exchange_strong( + state,state+readerUnit, + std::memory_order_seq_cst,std::memory_order_seq_cst)) + return false; const bool valid=output&&channels>0&&channels<=16&&frames>0&& frames<=maxCallbackFrames; if(!valid) { - consumers_.fetch_sub(1,std::memory_order_release); + consumerActivity_.fetch_sub(readerUnit,std::memory_order_seq_cst); return false; } for(int c=0;c ready_{false},fault_{false}; - std::atomic producers_{0},consumers_{0}; + std::atomic producerActivity_{writerFlag}, + consumerActivity_{writerFlag}; std::atomic captureBlocks_{0},primaryBlocks_{0}, invalidBlocks_{0},staleReads_{0}; }; diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 42951518e..50346f7b1 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -18,6 +18,7 @@ #include "DiagnosticTone.h" #include "../engine/device/JuceIndependentClockDevice.h" #include "../engine/device/LiveSecondaryOutputDevice.h" +#include "../engine/device/LiveSecondaryCaptureDevice.h" #include "../engine/core/LiveOutputRouteGate.h" #include "../engine/core/NativeOutputTransition.h" #include "../engine/core/NativeRenderAuthority.h" @@ -41,6 +42,9 @@ #include #include #include +#include +#include +#include // One live stereo input path and up to 8 actual VST3 processors. // The audio callback never scans files, creates plugins, mutates the chain, @@ -292,12 +296,16 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback void stop() { dryRoutingLab_.disable(); + qualifiedSecondaryInstalled_.store(false,std::memory_order_release); + qualifiedCaptureNeedsRemap_.store(false,std::memory_order_release); directFence_.suspend(); asioPinnedRegistration_ = {}; asioRegistrationScope_ = "NONE"; secondaryOutput_.stop(); // stop independent OBS consumer before audio graph teardown independent_.close(); detach(); + qualifiedSecondaryReader_.stop(); // CONTROL: all callback borrows retired + secondaryCapture_.close(); // producer driver B stops after primary detach handoff_.resetAfterStop (graphOwned_.get()); // Last owner releases vendor resources exactly once after detach. // Reused instances remain valid until their final control-owned slot. @@ -432,12 +440,24 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback else if(wantsMainContinuation())resumeMainAfterAsioReset_.store(true,std::memory_order_release); setOutputMuted(true); secondaryOutput_.disarm(); + // A no-op AUDIO SETUP must not destroy the live A+B graph's reader: + // finishManualAudioSetup() can retain this exact same PCM lease. + // If JUCE actually restarts A, its lifecycle callback fences B and + // marks that physical binding as requiring an explicit remap. directFence_.suspend(); // Do NOT disable the accepted ChannelId graph. Audio Setup is a // device-binding operation, not an implicit CLEAR MIXER command. // The JUCE selector may change the driver before its window closes. } bool finishManualAudioSetup(bool reuseAsioBinding=true) { + if(qualifiedCaptureNeedsRemap_.load(std::memory_order_acquire)) { + // A restarted PRIMARY must not leave the authored mixer + // stranded. Keep B invalidated, but permit the verified A-only + // retained graph recovery below; the new B binding stays OFF. + setOutputMuted(true); + qualifiedSecondaryReader_.stop(); // CONTROL quiescence + secondaryCapture_.close(); + } if(!approveDirectRoute())return false; using Decision=armix::device::DeviceSessionDecision; switch(armix::device::decideDeviceSession( @@ -566,10 +586,26 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback MixerBindingInspection inspected; constexpr auto mode=Policy::Mode::verifiedAsioRestart; if(inspectNativeMixerSessionBinding(document,inspected,mode).isNotEmpty() || - inspected.live.rate!=document.binding.rate || - Policy::apply(document,inspected.live,inspected.outputs,inspected.callbackInputs,mode).isNotEmpty() || - !dryRoutingLab_.rebindRetainedAsioSession(std::move(document),inspected.pins, - inspected.live.frames))return false; + inspected.live.rate!=document.binding.rate)return false; + // The B reconnection reminder may survive an already recovered + // primary-only graph. A second ASIO A restart must NOT demand an + // A+B map that was intentionally retired after the first recovery. + const bool lostB=qualifiedCaptureNeedsRemap_.load( + std::memory_order_acquire) && + dryRoutingLab_.qualifiedInputMapActive(); + // Rebuild from the last genuine A+B snapshot without saving a + // corrupt virtual-input .smix. The exact prior A port count is + // checked against current verified hardware before any mutation. + if(lostB && !dryRoutingLab_.preparePrimaryOnlyAsioRestartDocument( + document,inspected.callbackInputs))return false; + if(Policy::apply(document,inspected.live,inspected.outputs, + inspected.callbackInputs,mode).isNotEmpty() || + !dryRoutingLab_.rebindRetainedAsioSession(std::move(document), + inspected.pins,inspected.live.frames,lostB))return false; + if(lostB) { + retireQualifiedCaptureForNewGraph(); // only AFTER A graph published + qualifiedCaptureNeedsRemap_.store(true,std::memory_order_release); + } acceptedMixerBinding_=std::move(inspected.live); return true; } @@ -703,6 +739,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // native NORMAL mixer ready, not stranded without a session. if(dryRoutingLab_.active()) { setOutputMuted(true); + retireQualifiedCaptureForNewGraph(); dryRoutingLab_.disable(); } directFence_.suspend(); // independent path bypasses only this DIRECT fence @@ -790,6 +827,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // selecting a one-sided device. No phantom hardware output or CH1 mix. if(dryRoutingLab_.active()) { setOutputMuted(true); + retireQualifiedCaptureForNewGraph(); dryRoutingLab_.disable(); } // Muting the old/new combined backend callback during an intermediate @@ -1326,6 +1364,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback secondaryOutput_.disarm(); // never carry LIVE STREAM into a new unpatched graph if(hasRetainedUnboundMixer()) return "Mixer session preserved, but device changed: full ChannelId graph and plugin-state rebind required (output stays muted)"; + if(qualifiedSecondaryInstalled_.load(std::memory_order_acquire) || + qualifiedCaptureNeedsRemap_.load(std::memory_order_acquire)) + retireQualifiedCaptureForNewGraph(); // only a genuinely new session auto* device=deviceManager_.getCurrentAudioDevice(); if(!device || !directFence_.permitted() || independent_.active()) return "No verified DIRECT full-duplex device"; @@ -1349,11 +1390,27 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return error; } + // CONTROL ONLY; no audio callback may block or free driver state. + // Stop the qualified view before closing B's capture producer. In-flight + // primary reads finish under the reader's own RT lease. The subsequent + // new primary-only graph then uses raw A pointers again, without a + // stale A+B map or a second render owner. + void retireQualifiedCaptureForNewGraph() noexcept { + qualifiedSecondaryInstalled_.store(false,std::memory_order_release); + qualifiedSecondaryReader_.stop(); + secondaryCapture_.close(); + qualifiedCaptureNeedsRemap_.store(false,std::memory_order_release); + } + // Historical STOP command retained as a safe CLEAR PATCH alias. // Returning to legacy CH1 is explicitly forbidden in NORMAL production. juce::String clearProductionRouting() { setOutputMuted(true); secondaryOutput_.disarm(); + // IO-2D: an A+B qualified input lease cannot be passed to the fresh + // primary-only graph. Retire both resources while CONTROL has muted + // every output, before unpublishing the old graph. + retireQualifiedCaptureForNewGraph(); dryRoutingLab_.disable(); return startUnpatchedProductionSession(); } @@ -1363,6 +1420,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const juce::var& command, const LiveDryRoutingLab::FxSelections& fx, const LiveDryRoutingLab::FxRestores* restored=nullptr) { + // A successful legacy M4 apply would supersede A+B virtual input + // layout. Require an explicit CLEAR PATCH rather than dropping its + // reader on a speculative edit that might fail validation. + if(qualifiedSecondaryInstalled_.load(std::memory_order_acquire)) + return "CLEAR PATCH and explicitly remove secondary capture before applying M4 routing"; if (dryRoutingLab_.nativeBusTopologyLive()) return "REMOVE native GROUP/FX RETURN buses before applying an M4 route"; if (!allOutputsDisarmed()) return "MUTE hardware output and DISARM STREAM before APPLY routing"; @@ -1398,6 +1460,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } void disableDryRoutingLab() noexcept { setOutputMuted(true); // never expose CH1 unexpectedly on STOP + retireQualifiedCaptureForNewGraph(); dryRoutingLab_.disable(); } // One structural graph transaction for SOURCE, OUT, M/ST and FX inserts: @@ -1817,14 +1880,33 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // Graph publication is a temporary PHYSICAL silence, not a user MUTE. // Retain MAIN intent across the accepted ChannelId/FX rebind. if(monitoring)setOutputMuted(true); + // IO-2D: explicit .smix replacement is a paired PCM+device-map + // transaction. No capture driver closes until a new A-only graph + // is accepted; on failed candidate, restore the old B admission. + // A short muted control handoff prevents old qualified PCM from + // receiving raw A-only callback pointers during the swap. + const bool hadQualifiedMap=dryRoutingLab_.qualifiedInputMapActive(); + const bool oldQualifiedAdmission=qualifiedSecondaryInstalled_.load( + std::memory_order_acquire); + if(hadQualifiedMap) + qualifiedSecondaryInstalled_.store(false,std::memory_order_release); const auto applied=dryRoutingLab_.restoreNativeMixerSession( std::move(document),std::move(bank),inspected.pins, - allOutputsDisarmed(),replaceActive); + allOutputsDisarmed(),replaceActive,hadQualifiedMap); if(applied.isNotEmpty()) { + if(hadQualifiedMap) { + if(dryRoutingLab_.qualifiedInputMapActive()) + qualifiedSecondaryInstalled_.store(oldQualifiedAdmission, + std::memory_order_release); + else + retireQualifiedCaptureForNewGraph(); // publication did complete + } if(monitoring&&ep==dryRoutingLab_.epoch()&&liveOutputArmFault(false).isEmpty()) - setOutputMuted(false); // same user intent; safe original graph + setOutputMuted(false); // only restore verified original intent return applied; } + if(hadQualifiedMap) + retireQualifiedCaptureForNewGraph(); // A-only PCM accepted, B retired acceptedWasapiBinding_=std::move(profile); acceptedMixerBinding_=std::move(inspected.live); setMasterGainLinear(gain); @@ -2366,6 +2448,160 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback true,beforePublish); }); } + // IO-2D native product host boundary. This entrypoint is deliberately + // NOT exposed as a web/JS activation yet: a serialized user-approved + // native command must provide exact verified binding intent and wait for + // independently matching installed PCM readback before displaying LIVE. + struct QualifiedPhysicalSourceChoice final { + armix::mixer::ChannelId channel{}; + bool onSecondary=false; + int leftPhysical=-1,rightPhysical=-1; + bool stereo=false; + }; + LiveDryRoutingLab::NativeBusResult installSecondaryAsioCapture( + const juce::String& secondaryDriver, + const juce::BigInteger& selectedSecondaryPins, + double requestedCaptureHz,int requestedCaptureFrames, + std::uint64_t expectedEpoch,std::uint64_t expectedPcmRevision, + std::uint64_t expectedRosterRevision, + std::span selectedSources) { + namespace d=armix::device; + LiveDryRoutingLab::NativeBusResult reply{}; + reply.error="SECONDARY_CAPTURE_NOT_ADMITTED"; + if(!allOutputsDisarmed()||independent_.active()||!attached_|| + !directFence_.permitted()||qualifiedSecondaryInstalled_.load( + std::memory_order_acquire)|| + (qualifiedCaptureNeedsRemap_.load(std::memory_order_acquire)&& + dryRoutingLab_.qualifiedInputMapActive())|| + secondaryCapture_.ready()|| + routeReconfiguring_.load(std::memory_order_acquire)|| + diagnosticRoute_.load(std::memory_order_acquire)!= + armix::diagnostics::Route::normal|| + handoff_.busy()||fxMovePhase_.load(std::memory_order_acquire)!=0|| + deviceManager_.getCurrentAudioDeviceType()!="ASIO"|| + !asioPinnedRegistration_.valid()|| + expectedEpoch!=dryRoutingLab_.epoch()|| + !dryRoutingLab_.channelIdPhysicalPcmActive()|| + selectedSources.empty())return reply; + auto* primary=deviceManager_.getCurrentAudioDevice(); + if(!primary||!primary->isOpen()||primary->getTypeName()!="ASIO") + return reply; + d::JuceActivePortSnapshot pins; + d::JuceActivePortSnapshot::Fault portFault{}; + if(!d::JuceActivePortSnapshot::capture(primary,expectedEpoch, + pins,portFault)||!dryRoutingLab_.matchesSessionDevice(pins)|| + pins.inputs.enabledCount<1) { + reply.error="PRIMARY_CAPTURE_MASK_NOT_VERIFIED";return reply; + } + if(secondaryLeaseSequence_>std::numeric_limits::max()-3) { + reply.error="SECONDARY_LEASE_EXHAUSTED";return reply; + } + // New native-issued leases every attempt; never reuse a stale B + // generation after a driver fault, disconnect or source remap. + const auto primaryLease=++secondaryLeaseSequence_; + const auto secondaryLease=++secondaryLeaseSequence_; + const auto captureGeneration=secondaryLease; + auto error=secondaryCapture_.open(secondaryDriver,primary->getName(), + selectedSecondaryPins,requestedCaptureHz,requestedCaptureFrames, + primary->getCurrentSampleRate(),primary->getCurrentBufferSizeSamples(), + captureGeneration,expectedEpoch,secondaryLease); + if(error.isNotEmpty()) { + reply.error="SECONDARY_ASIO_OPEN_REJECTED";return reply; + } + const auto rollback=[&]() noexcept { + qualifiedSecondaryReader_.stop(); + secondaryCapture_.close(); + }; + try { + const auto b=secondaryCapture_.readback(); + if(!b.ready||b.faulted|| + b.primaryEpoch!=expectedEpoch|| + b.captureGeneration!=captureGeneration|| + b.deviceLease!=secondaryLease|| + b.callbackInputs!=selectedSecondaryPins.countNumberOfSetBits()|| + b.activeInputPins!=selectedSecondaryPins) { + rollback();reply.error="SECONDARY_ASIO_READBACK_MISMATCH";return reply; + } + const auto classB=d::AsioRegistryIdentityProbe::resolve( + std::wstring(secondaryDriver.toWideCharPointer())).registration; + if(!classB.ok()|| + asioPinnedRegistration_.sameDriverClass(classB.identity)) { + rollback();reply.error="SECONDARY_ASIO_CLASS_NOT_INDEPENDENT";return reply; + } + // Ephemeral in-session keys refer to two independently attested + // native driver classes and distinct leases; NOT persistent USB + // endpoint GUIDs. Offline .smix remap remains explicitly pending. + const std::string aKey="ASIO_PRIMARY:"+ + juce::String(asioPinnedRegistration_.canonicalClsid.c_str()).toStdString()+ + ":"+std::to_string(expectedEpoch); + const std::string bKey="ASIO_CAPTURE:"+ + juce::String(classB.identity.canonicalClsid.c_str()).toStdString()+ + ":"+std::to_string(secondaryLease); + std::array primaryPins{}; + for(int i=0;i secondaryPins{}; + int bCount=0; + for(int index=b.activeInputPins.findNextSetBit(0);index>=0; + index=b.activeInputPins.findNextSetBit(index+1)) { + if(bCount>=16) { + rollback();reply.error="SECONDARY_PIN_COUNT_EXCEEDED";return reply; + } + secondaryPins[bCount++]=index; + } + std::array devices{{ + {aKey,expectedEpoch,true, + std::span(primaryPins.data(), + static_cast(pins.inputs.enabledCount)), + primaryLease}, + {bKey,captureGeneration,false, + std::span(secondaryPins.data(), + static_cast(bCount)),secondaryLease} + }}; + std::vector bindings; + bindings.reserve(selectedSources.size()); + for(const auto& row:selectedSources) { + const std::string_view key=row.onSecondary?bKey:aKey; + d::QualifiedChannelSource next; + next.channel=row.channel; + next.left={key,row.leftPhysical}; + next.stereo=row.stereo; + if(row.stereo)next.right={key,row.rightPhysical}; + bindings.push_back(next); + } + d::MultiDeviceInputPlan plan; + d::MultiDeviceInputFault planFault{}; + if(!dryRoutingLab_.prepareQualifiedCapturePlan( + expectedEpoch,devices,bindings,plan,planFault)) { + rollback();reply.error="SECONDARY_SOURCE_MAP_REJECTED";return reply; + } + const auto verified=dryRoutingLab_.installQualifiedSecondaryInput( + expectedEpoch,expectedPcmRevision,expectedRosterRevision,plan, + qualifiedSecondaryReader_,secondaryCapture_.clockStream(),true); + if(!verified.accepted) { + rollback();return verified; + } + // One release-store AFTER the same snapshot/FX publication. + // Before this flag, a qualified map rejects raw A-only inputs, + // so a transient callback is SILENT, never wrong-device PCM. + qualifiedCaptureNeedsRemap_.store(false,std::memory_order_release); + qualifiedSecondaryInstalled_.store(true,std::memory_order_release); + return verified; + } catch(...) { + rollback(); + reply.error="SECONDARY_CAPTURE_CONTROL_PREPARE_FAILED"; + return reply; + } + } + // Disconnecting B intentionally retains the already-qualified map and + // ChannelId/FX snapshot: primary A keeps playing; B slots fail SILENT. + // A future explicit new binding requires output disarm and exact remap. + void disconnectSecondaryAsioCapture() { + secondaryCapture_.close(); // CONTROL, never audio callback + } + armix::device::LiveSecondaryCaptureDevice::Readback + secondaryCaptureReadback() const {return secondaryCapture_.readback();} + template LiveDryRoutingLab::NativeBusResult editNativeInputTopology( std::uint64_t epoch,const char* unavailable,const char* exception, @@ -2926,6 +3162,13 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback juce::String startupFallbackReason_; // control-thread-only startup diagnostics armix::device::JuceIndependentClockDevice independent_; armix::device::LiveSecondaryOutputDevice secondaryOutput_; + // IO-2D: separate ASIO input B is capture-only. Both PCM streams enter + // the ONE existing ChannelId/FX callback only after CONTROL admission. + armix::device::LiveSecondaryCaptureDevice secondaryCapture_; + armix::device::QualifiedSecondaryCaptureReader qualifiedSecondaryReader_; + std::atomic qualifiedSecondaryInstalled_{false}; + std::atomic qualifiedCaptureNeedsRemap_{false}; // device lifecycle invalidated B + std::uint64_t secondaryLeaseSequence_=0; // CONTROL only, never callback std::optional savedDirectSetup_; juce::AudioPluginFormatManager formats_; // Strong ownership stays on CONTROL. The admitted native ChannelId @@ -3060,6 +3303,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } setOutputMuted(true); // transient hardware gate, NOT an operator MUTE secondaryOutput_.invalidateSource(); // source clock may have changed + if(qualifiedSecondaryInstalled_.exchange(false,std::memory_order_acq_rel)) + qualifiedCaptureNeedsRemap_.store(true,std::memory_order_release); + secondaryCapture_.invalidatePrimaryClock(); // RT-safe fault only dryRoutingLab_.prepareDevice(d); // exact active mask, before callback if (!independent_.active()) { @@ -3121,6 +3367,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback monitor_.store(false,std::memory_order_release); secondaryOutput_.invalidateSource(); // explicit reconnect required after device stop masterLoudness_.prepare (0.0); // clear validity across device epoch + if(qualifiedSecondaryInstalled_.exchange(false,std::memory_order_acq_rel)) + qualifiedCaptureNeedsRemap_.store(true,std::memory_order_release); + secondaryCapture_.invalidatePrimaryClock(); // no driver teardown in JUCE callback dryRoutingLab_.deviceStopped(); playerDeck_.deviceRate(0.0); // invalidates old PCM generation deviceStopCount_.fetch_add (1, std::memory_order_relaxed); @@ -3371,6 +3620,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback playerScratch_[1].data()}; deckCount=1; } + // One acquire: CONTROL changes the admitted A+B resource pair + // atomically; a callback never observes half a pair. + const bool qualifiedInput=qualifiedSecondaryInstalled_.load( + std::memory_order_acquire); const bool routed=dryRoutingLab_.process(inputs,inputChannels,outputs, outputChannels,samples, masterGain_.load(std::memory_order_relaxed), @@ -3381,7 +3634,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback !routeReconfiguring_.load(std::memory_order_acquire) && !topologyPublicationMute_.load(std::memory_order_acquire), std::span( - deckBlocks.data(),deckCount),mainOnlyMuted); + deckBlocks.data(),deckCount),mainOnlyMuted, + qualifiedInput?&qualifiedSecondaryReader_:nullptr, + qualifiedInput?&secondaryCapture_.clockStream():nullptr); // Constant-time, callback-local physical PCM tap. Nothing is // reconfigured or acquired from another graph generation. const auto nativeMain=armix::mixer::NativeOutputPairTap::select( diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 418465e7b..45d866c45 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -20,6 +20,10 @@ #include "../engine/core/ProductionRenderAudit.h" #include "../engine/core/LiveOutputRouteGate.h" #include "../engine/device/LiveInputPortRegistry.h" +#include "../engine/device/QualifiedSecondaryCaptureReader.h" +#include "../engine/device/QualifiedCaptureHostMode.h" +#include "../engine/device/QualifiedCaptureAdmission.h" +#include "../engine/device/QualifiedInputGraphBridge.h" #include #include #include @@ -1954,10 +1958,14 @@ class LiveDryRoutingLab final { }; fx.deviceEpoch=expectedEpoch; fx.graphRevision=expectedPcmRevision+1; + armix::device::MultiDeviceInputPlan reducedMap; + const bool removingQualified=nativePublisher_.qualifiedMapWithoutSource( + expectedEpoch,expectedPcmRevision,id,reducedMap); if(beforePublish)beforePublish(); const auto published=nativePublisher_.commit( roster,request,expectedPcmRevision, - expectedEpoch,epoch(),true,std::move(fx)); + expectedEpoch,epoch(),true,std::move(fx), + false,false,removingQualified?&reducedMap:nullptr); if(!published.ok()){ reply.error="NATIVE_TRACK_PCM_COMMIT_REJECTED";return reply; } @@ -1978,6 +1986,120 @@ class LiveDryRoutingLab final { } } + // CONTROL staging only: check the current accepted ChannelId roster. + // Source bindings and exact hardware masks must originate from genuine + // native device preflight; offline friendly names cannot authorize PCM. + bool prepareQualifiedCapturePlan( + std::uint64_t expectedEpoch, + std::span devices, + std::span bindings, + armix::device::MultiDeviceInputPlan& destination, + armix::device::MultiDeviceInputFault& fault) const { + if(!channelIdPhysicalPcmActive()||!ready()|| + expectedEpoch!=epoch()||nativeAccepted_.deviceEpoch!=expectedEpoch|| + !nativeAccepted_.fxOwners)return false; + return armix::device::MultiDeviceInputPlan::prepare( + expectedEpoch,devices,bindings, + nativeAccepted_.graph.roster.channels(),destination,fault); + } + + // IO-2D CONTROL: stage B's already-open, independently attested ASIO + // capture inside THIS accepted native graph/FX lease. The caller keeps + // the output disarmed and owns the verified stream/device lifecycle; + // no GUI-local LIVE, second manager, processor, or output auto-arm. + // The matching reader/clock are then passed to process() by the same + // native host on the PRIMARY callback. No hardware is opened here. + NativeBusResult installQualifiedSecondaryInput( + std::uint64_t expectedEpoch,std::uint64_t expectedPcmRevision, + std::uint64_t expectedRosterRevision, + const armix::device::MultiDeviceInputPlan& plan, + armix::device::QualifiedSecondaryCaptureReader& reader, + armix::device::SecondaryCaptureClockStream& clock, + bool outputsDisarmed, + const std::function& beforePublish={}) { + using namespace armix::mixer; + NativeBusResult reply{}; + reply.pcmRevision=nativeAccepted_.pcmRevision; + reply.rosterRevision=nativeAccepted_.graph.roster.revision(); + if(!outputsDisarmed) { + reply.error="OUTPUT_MUST_BE_DISARMED";return reply; + } + if(!channelIdPhysicalPcmActive()||!ready()|| + expectedEpoch!=epoch()||nativeAccepted_.deviceEpoch!=expectedEpoch|| + expectedPcmRevision!=nativeAccepted_.pcmRevision|| + expectedRosterRevision!=nativeAccepted_.graph.roster.revision()|| + !nativeAccepted_.fxOwners) { + reply.error="STALE_NATIVE_CAPTURE_GRAPH";return reply; + } + if(reader.status().ready) { + reply.error="CAPTURE_READER_ALREADY_ATTACHED";return reply; + } + const auto fault=armix::device::QualifiedCaptureAdmission::verify( + plan,clock,expectedEpoch, + callbackInputCount_.load(std::memory_order_acquire), + nativeAccepted_.graph.request.maxFrames); + if(fault!=armix::device::QualifiedCaptureAdmission::Fault::none) { + reply.error="SECONDARY_CAPTURE_LEASE_OR_MASK_REJECTED";return reply; + } + try { + DynamicGraphRequest staged; + armix::device::QualifiedInputGraphBridge::Fault stageFault{}; + if(!armix::device::QualifiedInputGraphBridge::stage( + plan,nativeAccepted_.graph.request,staged,stageFault)) { + reply.error="QUALIFIED_INPUT_GRAPH_REJECTED";return reply; + } + DynamicChannelFxLeaseBank bank; + if(DynamicChannelFxLeaseBank::reuseRevision( + expectedEpoch,expectedPcmRevision+1, + *nativeAccepted_.fxOwners,bank)!= + DynamicChannelFxLeaseBank::Fault::none) { + reply.error="QUALIFIED_INPUT_FX_LEASE_REJECTED";return reply; + } + auto owner=std::make_shared(std::move(bank)); + owner->bindGlobalRackOverride(&globalFxBypassed_); + DynamicNativeSessionPublisher::FxPlan fx; + fx.owner=std::static_pointer_cast(owner); + fx.context=owner.get(); + fx.render=+[](void* ctx,ChannelId id,float* left,float* right,int n) noexcept { + (*static_cast(ctx))(id,left,right,n); + }; + fx.latency=+[](void* ctx,ChannelId id) noexcept { + return static_cast(ctx)->latencySamples(id); + }; + fx.deviceEpoch=expectedEpoch; + fx.graphRevision=expectedPcmRevision+1; + if(!reader.prepare(plan,staged.maxFrames)) { + reply.error="QUALIFIED_READER_PREPARE_REJECTED";return reply; + } + try { + if(beforePublish)beforePublish(); + const auto published=nativePublisher_.commit( + nativeAccepted_.graph.roster,staged,expectedPcmRevision, + expectedEpoch,epoch(),true,std::move(fx), + false,false,&plan); + if(!published.ok()) { + reader.stop(); // detached failure; old PCM remains valid + reply.error="QUALIFIED_INPUT_PCM_COMMIT_REJECTED";return reply; + } + nativeAccepted_.graph.request=std::move(staged); + nativeAccepted_.fxOwners=std::move(owner); + nativeAccepted_.pcmRevision=published.revision; + reapplyExternalOutputsSameEpoch(); + nativeStructureLive_=true; + nativeMeterEpoch_.store(0,std::memory_order_release); + reply.accepted=true;reply.error=""; + reply.pcmRevision=published.revision; + reply.rosterRevision=nativeAccepted_.graph.roster.revision(); + return reply; + }catch(...) { + reader.stop(); + reply.error="QUALIFIED_CAPTURE_PUBLICATION_FAILED";return reply; + } + }catch(...) { + reply.error="QUALIFIED_CAPTURE_PREPARE_FAILED";return reply; + } + } + // Wire a verified physical capture pin to a dynamically CREATED input. // M4-owned CH1–10 keep the original device/VST continuity contract. // Prepared topology + lease revision is published once; never patch an @@ -2003,6 +2125,11 @@ class LiveDryRoutingLab final { reply.error="NATIVE_INPUT_ID_UNAVAILABLE";return reply; } const bool disconnect=!stereo&&physicalLeft==-1&&physicalRight==-1; + if(!disconnect && nativePublisher_.hasQualifiedInputMap( + expectedEpoch,expectedPcmRevision)){ + reply.error="QUALIFIED_CAPTURE_SOURCE_REMAP_REQUIRED"; + return reply; // never relabel device-qualified B pins via A ordinals + } int l=-1,r=-1; if(!disconnect){ for(int i=0;i(ctx)->latencySamples(id); }; fx.deviceEpoch=expectedEpoch;fx.graphRevision=expectedPcmRevision+1; + armix::device::MultiDeviceInputPlan reducedMap; + const bool removingQualified=disconnect && + nativePublisher_.qualifiedMapWithoutSource( + expectedEpoch,expectedPcmRevision,channel,reducedMap); if(beforePublish)beforePublish(); // late PCM publication gate const auto published=nativePublisher_.commit( nativeAccepted_.graph.roster,request,expectedPcmRevision, - expectedEpoch,epoch(),true,std::move(fx)); + expectedEpoch,epoch(),true,std::move(fx), + false,false,removingQualified?&reducedMap:nullptr); if(!published.ok()) { reply.error="NATIVE_INPUT_PCM_COMMIT_REJECTED";return reply; } @@ -2381,6 +2513,15 @@ class LiveDryRoutingLab final { (retained && channelIdPhysicalPcmActive()) || !nativeAccepted_.matches(nativePublisher_,documentEpoch,nativeAccepted_.pcmRevision)) return "No authoritative native ChannelId graph"; + // IO-2D persistence P1: v1 .smix can store primary A physical + // HardwareBinding only. Saving a qualified A+B graph would persist + // virtual callback ordinals with no B device identity, making the + // new file unrestorable and destroying recoverable autosave state. + // Reject BEFORE writing document/blobs or enqueueing any save worker. + // IO-5 must add durable device-qualified source binding first. + if(nativePublisher_.hasQualifiedInputMap( + documentEpoch,nativeAccepted_.pcmRevision)) + return "SECONDARY_CAPTURE_NEEDS_SMIX_BINDING_SCHEMA: old checkpoint preserved; disconnect/remap B or wait for qualified persistence"; if(nativeAccepted_.fxOwners->externalChannel().value) return "External CH1 FX owner cannot yet be serialized independently"; // MAIN and STREAM are muted by the caller. Wait briefly for the @@ -2559,8 +2700,32 @@ class LiveDryRoutingLab final { return true; } + // CONTROL readback of the same PCM/FX snapshot. Session replacement + // must explicitly drop this qualified map before restoring A-only .smix. + bool qualifiedInputMapActive() const noexcept { + return nativePublisher_.hasQualifiedInputMap( + nativeAccepted_.deviceEpoch,nativeAccepted_.pcmRevision); + } + // Off-RT retained document only; the B ChannelIds, WIRE, faders and FX + // remain in the roster. Removed B hardware SOURCE rows become silent + // until a newly attested ASIO B lease is explicitly accepted. + bool preparePrimaryOnlyAsioRestartDocument( + armix::session::MixerSessionDocument& document, + int primaryCallbackInputs) const { + armix::mixer::DynamicGraphRequest staged; + if(!nativePublisher_.preparePrimaryRestartFallback( + nativeAccepted_.deviceEpoch,nativeAccepted_.pcmRevision, + primaryCallbackInputs,document.request,staged))return false; + document.request=std::move(staged); + return true; + } + // IO-2F: primary-ASIO restart must carry the same explicit qualified + // map-retirement token as a verified user-requested A-only .smix restore. + // Only the owner that staged an A+B -> A-only recovery may supply true; + // an ordinary ASIO restart must not drop a still-installed B source map. bool rebindRetainedAsioSession(armix::session::MixerSessionDocument document, - const armix::device::JuceActivePortSnapshot& pins,int deviceFrames) { + const armix::device::JuceActivePortSnapshot& pins,int deviceFrames, + bool retireLostSecondaryMap=false) { const auto next=nativeGraphRevisionForRestore(); const auto previous=document.request.maxFrames; // Existing processors can still use their prepared quantum. Larger @@ -2572,7 +2737,11 @@ class LiveDryRoutingLab final { if(armix::mixer::DynamicChannelFxLeaseBank::rebindSameFormat( pins.epoch,next,*nativeAccepted_.fxOwners,*bank)!= armix::mixer::DynamicChannelFxLeaseBank::Fault::none)return false; - return restoreNativeMixerSession(std::move(document),std::move(bank),pins,true).isEmpty(); + if(retireLostSecondaryMap && !qualifiedInputMapActive())return false; + // The new A callback and its real pin mask were already verified. + // Never publish an implicit cross-epoch B ordinal reinterpretation. + return restoreNativeMixerSession(std::move(document),std::move(bank), + pins,true,false,retireLostSecondaryMap).isEmpty(); } // Match CONTROL's live device readback to the masks registered for the @@ -2599,7 +2768,8 @@ class LiveDryRoutingLab final { armix::session::MixerSessionDocument document, std::shared_ptr bank, const armix::device::JuceActivePortSnapshot& pins, - bool outputsDisarmed,bool replaceActive=false) { + bool outputsDisarmed,bool replaceActive=false, + bool replaceQualifiedWithPrimaryOnly=false) { using namespace armix::mixer; if(!outputsDisarmed || (!replaceActive && channelIdPhysicalPcmActive()) || !bank) return "Restore requires a muted device"; @@ -2627,7 +2797,10 @@ class LiveDryRoutingLab final { }; const auto published=nativePublisher_.commit( document.roster,document.request,previous,generation,epoch(), - true,std::move(fx)); + true,std::move(fx),false,false,nullptr, + replaceQualifiedWithPrimaryOnly? + DynamicNativeSessionPublisher::QualifiedMapChange::replaceWithPrimaryOnly: + DynamicNativeSessionPublisher::QualifiedMapChange::inherit); if(!published.ok()) return "Native ChannelId PCM rejected persisted topology: "+ juce::String(static_cast(published.fault)); @@ -3067,7 +3240,9 @@ class LiveDryRoutingLab final { std::array* actualMonitorPair=nullptr, bool allowMutedMetering=false, std::span playerPcm={}, - bool mainOnlyMuted=false) noexcept { + bool mainOnlyMuted=false, + armix::device::QualifiedSecondaryCaptureReader* secondaryReader=nullptr, + armix::device::SecondaryCaptureClockStream* secondaryClock=nullptr) noexcept { if(actualOutputPair)*actualOutputPair={{-1,-1}}; if(actualMonitorPair)*actualMonitorPair={{-1,-1}}; if(!active())return false; @@ -3249,17 +3424,46 @@ class LiveDryRoutingLab final { source.right?source.right+offset:nullptr}; } const auto noExtraFx=[](armix::mixer::ChannelId,float*,float*,int) noexcept {}; - processed=nativePublisher_.render( - generation,shifted.data(),inputCount, - meterOnly?mutedMain_[0].data():mainL+offset, - meterOnly?mutedMain_[1].data():mainR+offset,n,false,noExtraFx, - monitorL?(meterOnly?mutedMonitor_[0].data():monitorL+offset):nullptr, - monitorR?(meterOnly?mutedMonitor_[1].data():monitorR+offset):nullptr, - tapsL,tapsR, - std::span( - slice.data(),playerPcm.size()), - meterOnly?nullptr:outputSlices.data(), - meterOnly?0:outputCount); + // IO-2D: preserve exact physical A callback count above, + // while the accepted ChannelId graph may have A+B virtual + // capture ordinals. Only the original renderer owns FX. + // Qualified adapter is default-OFF until CONTROL installs + // a verified B clock/reader lease and matching PCM snapshot. + const auto renderNative=[&]( + std::span blocks) noexcept { + const bool qualified=!blocks.empty(); + return nativePublisher_.render( + generation,qualified?nullptr:shifted.data(), + qualified?0:inputCount, + meterOnly?mutedMain_[0].data():mainL+offset, + meterOnly?mutedMain_[1].data():mainR+offset,n,false,noExtraFx, + monitorL?(meterOnly?mutedMonitor_[0].data():monitorL+offset):nullptr, + monitorR?(meterOnly?mutedMonitor_[1].data():monitorR+offset):nullptr, + tapsL,tapsR, + std::span( + slice.data(),playerPcm.size()), + meterOnly?nullptr:outputSlices.data(), + meterOnly?0:outputCount,blocks); + }; + // Partial resource attachment must NEVER silently call raw + // A-only input ordinals against an installed A+B map. When + // qualified resources are absent, the publisher rejects + // direct raw pointers if its current PCM lease requires A+B. + switch(armix::device::qualifiedCaptureHostMode( + secondaryReader!=nullptr,secondaryClock!=nullptr)) { + case armix::device::QualifiedCaptureHostMode::directPrimary: + processed=renderNative({}); + break; + case armix::device::QualifiedCaptureHostMode::qualifiedDual: + processed=secondaryReader->withBlocks( + generation,shifted.data(),inputCount,n,*secondaryClock, + [&](std::span + blocks) noexcept { return renderNative(blocks); }); + break; + case armix::device::QualifiedCaptureHostMode::rejectPartial: + processed=false; + break; + } if(processed) { for(std::size_t ch=0;ch #include #include @@ -78,6 +79,7 @@ int main() check(!impossible.valid); armix::io2_test::run(); armix::io2_graph_test::run(); // same registered IO0 native CTest now compiles IO-2 + armix::io2_clocked_test::run(); // real producer ASRC -> native PCM/FX, B loss isolated std::puts("IO0_POLICY_PASS: identity, zero-output capture, exact masks, 9 clock profiles"); return 0; } diff --git a/tests/io2/QualifiedSecondaryCaptureReaderCases.h b/tests/io2/QualifiedSecondaryCaptureReaderCases.h new file mode 100644 index 000000000..9fbddf541 --- /dev/null +++ b/tests/io2/QualifiedSecondaryCaptureReaderCases.h @@ -0,0 +1,440 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "../../engine/device/QualifiedSecondaryCaptureReader.h" +#include "../../engine/device/QualifiedCaptureHostMode.h" +#include "../../engine/device/QualifiedCaptureAdmission.h" +#include "../../engine/device/QualifiedInputGraphBridge.h" +#include "../../engine/device/QualifiedPrimaryRestartRecoveryPlan.h" +#include "../../engine/core/DynamicNativeSessionPublisher.h" +#include +#include +#include +#include +#include +#include +#include + +namespace armix::io2_clocked_test { +namespace d=armix::device; +namespace m=armix::mixer; +inline void check(bool ok,const char* why) { + if(!ok){std::fprintf(stderr,"IO2_CLOCKED_FAIL %s\n",why);std::abort();} +} +inline bool near(float a,float b,float tolerance=0.03f) { + return std::abs(a-b) create{}; + for(int i=0;i<3;++i){ + create[i].kind=m::ChannelEdit::Kind::add; + create[i].position=static_cast(i); + create[i].role=i==2?m::ChannelRole::main:m::ChannelRole::input; + create[i].format=i==0?m::ProcessingFormat::mono:m::ProcessingFormat::stereo; + } + const auto added=roster.edit(0,create); + check(added.ok()&&added.createdIds.size()==3,"qualified ChannelId roster"); + const auto a=added.createdIds[0],b=added.createdIds[1], + main=added.createdIds[2]; + std::array wiring{}; + for(int i=0;i<2;++i){ + wiring[i].kind=m::ChannelEdit::Kind::setPrimaryOutput; + wiring[i].id=i==0?a:b;wiring[i].target=main; + } + check(roster.edit(roster.revision(),wiring).ok(),"both inputs WIRE MAIN"); + const std::array aPins{0}; + const std::array bPins{0,7}; + const std::array devices{{ + {"verified-A",epoch,true,aPins,1001}, + {"verified-B",captureGeneration,false,bPins,2002} + }}; + const std::array bindings{{ + {a,{"verified-A",0},{},false}, + {b,{"verified-B",0},{"verified-B",7},true} + }}; + d::MultiDeviceInputPlan plan; + d::MultiDeviceInputFault err; + check(d::MultiDeviceInputPlan::prepare(epoch,devices,bindings, + roster.channels(),plan,err),"two physical namespaces qualified"); + // SOURCE NONE and Delete Track must remove only the named ChannelId + // binding while preserving A/B device slots, generation and lease. + d::MultiDeviceInputPlan reduced; + check(plan.withoutSource(b,reduced) && reduced.sourceCount()==1 && + plan.sourceCount()==2 && reduced.virtualInputCount()==plan.virtualInputCount() && + reduced.device(1).deviceLease==plan.device(1).deviceLease && + reduced.source(0).channel==a, + "detached qualified source removal never drops B's device lease"); + check(!plan.withoutSource(main,reduced), + "deleting an unbound MAIN cannot mutate the qualified input map"); + m::DynamicGraphRequest old;old.physicalInputs=1;old.maxFrames=frames; + old.sources={{a,0,-1,false}}; + m::DynamicGraphRequest request; + d::QualifiedInputGraphBridge::Fault bridgeError{}; + check(d::QualifiedInputGraphBridge::stage(plan,old,request,bridgeError), + "control maps both verified sources into same graph"); + m::DynamicGraphRequest primaryFallback; + check(d::QualifiedPrimaryRestartRecoveryPlan::stage( + plan,request,1,primaryFallback) && + primaryFallback.physicalInputs==1 && + primaryFallback.sources.size()==1 && + primaryFallback.sources.front().id==a && + primaryFallback.sources.front().inputL==0 && + request.physicalInputs==3 && request.sources.size()==2, + "ASIO restart leaves B ChannelId/FX/WIRE roster and silences only B source"); + check(!d::QualifiedPrimaryRestartRecoveryPlan::stage( + plan,request,2,primaryFallback), + "different A input mask is never accepted by stale B virtual slot map"); + auto swapped=request; + swapped.sources.back().inputL=0; + check(!d::QualifiedPrimaryRestartRecoveryPlan::stage( + plan,swapped,1,primaryFallback), + "wrong-device B ordinal cannot relabel existing A source during restart"); + m::DynamicNativeSessionPublisher recoveredPcm; + check(recoveredPcm.commit(roster,primaryFallback,0,epoch+1,epoch+1,true).ok() && + !recoveredPcm.hasQualifiedInputMap(epoch+1,1), + "a new primary epoch publishes only verified A PCM but keeps original roster"); + check(recoveredPcm.commit(roster,primaryFallback,1,epoch+2,epoch+2,true).ok() && + !recoveredPcm.hasQualifiedInputMap(epoch+2,2), + "second A restart rebinds the recovered A-only graph without stale B map"); + // IO-2F caller-path regression: the REAL retained owner has an A+B + // input map on the previous epoch. Merely staging the safe A-only + // document is insufficient; ASIO restart must explicitly pass the map + // retirement token all the way through restoreNativeMixerSession(). + // The preceding A-only fixture never had B installed and missed P1. + m::DynamicNativeSessionPublisher restarted; + using Change=m::DynamicNativeSessionPublisher::QualifiedMapChange; + using Fault=m::DynamicNativeSessionPublisher::Fault; + check(restarted.commit(roster,request,0,epoch,epoch,true, + {},false,false,&plan).ok() && + restarted.hasQualifiedInputMap(epoch,1), + "actual A+B PCM installed before driver restart"); + check(restarted.commit(roster,primaryFallback,1,epoch+1,epoch+1,true).fault== + Fault::invalidCandidate && + restarted.acceptedRevision()==1 && + restarted.hasQualifiedInputMap(epoch,1), + "P1 regression reproduction: restart without explicit retirement fails closed"); + check(restarted.commit(roster,primaryFallback,1,epoch+1,epoch+2,true, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).fault== + Fault::staleDevice && + restarted.hasQualifiedInputMap(epoch,1), + "mismatched live A epoch must preserve old B lease on rejected recovery"); + check(restarted.commit(roster,primaryFallback,1,epoch+1,epoch+1,false, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).fault== + Fault::outputArmed && + restarted.hasQualifiedInputMap(epoch,1), + "ARM cannot pass the explicit map retirement boundary"); + check(restarted.commit(roster,primaryFallback,1,epoch+1,epoch+1,true, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).ok() && + restarted.acceptedRevision()==2 && + !restarted.hasQualifiedInputMap(epoch+1,2) && + !restarted.hasQualifiedInputMap(epoch,1), + "verified A-only restart atomically retires old B map"); + const auto* retainedRouting=restarted.acceptedRouting(epoch+1,2); + check(retainedRouting && retainedRouting->find(a) && + retainedRouting->find(b) && retainedRouting->find(main), + "A, silent B, MAIN ChannelId roster survives ASIO restart"); + check(restarted.commit(roster,primaryFallback,2,epoch+2,epoch+2,true, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).fault== + Fault::invalidCandidate, + "second restart must not retire nonexistent B mapping again"); + check(restarted.commit(roster,primaryFallback,2,epoch+2,epoch+2,true).ok() && + !restarted.hasQualifiedInputMap(epoch+2,3) && + restarted.acceptedRouting(epoch+2,3)->find(b), + "second ASIO restart keeps original B track silent but session usable"); + m::DynamicNativeSessionPublisher native; + check(native.commit(roster,request,0,epoch,epoch,true, + {},false,false,&plan).ok(),"one PCM and device map publication"); + check(native.hasQualifiedInputMap(epoch,1), + "v1 .smix cannot safely save virtual A+B input ordinals"); + check(!native.hasQualifiedInputMap(epoch+1,1)&& + !native.hasQualifiedInputMap(epoch,0), + "stale graph generation cannot authorize persistence"); + // A plain SOURCE NONE/Delete Track request is rejected if the old map + // remains unchanged. An explicit DETACHED subset is accepted atomically + // and stays qualified for the remaining A source. + auto subsetRequest=request; + std::erase_if(subsetRequest.sources,[b](const auto& row){return row.id==b;}); + m::DynamicNativeSessionPublisher subsetPcm; + check(subsetPcm.commit(roster,request,0,epoch,epoch,true, + {},false,false,&plan).ok(),"subset fixture starts with A+B map"); + check(subsetPcm.commit(roster,subsetRequest,1,epoch,epoch,true).fault== + m::DynamicNativeSessionPublisher::Fault::invalidCandidate && + subsetPcm.acceptedRevision()==1, + "implicit SOURCE NONE must not silently desynchronize old B map"); + check(subsetPcm.commit(roster,subsetRequest,1,epoch,epoch,true, + {},false,false,&reduced).ok() && + subsetPcm.hasQualifiedInputMap(epoch,2), + "explicit source subset publishes and retains exact device leases"); + + + d::SecondaryCaptureClockStream clock; + const d::SecondaryCaptureClockStream::Format format{ + 44100.,48000.,frames,frames,2,captureGeneration,epoch,2002}; + check(clock.prepare(format)&&clock.activate(),"independent 44.1k B into 48k A ASRC ready"); + using Admission=d::QualifiedCaptureAdmission; + check(Admission::verify(plan,clock,epoch,1,frames)==Admission::Fault::none, + "exact two-device qualified CONTROL admission"); + check(Admission::verify(plan,clock,epoch,1,frames/2)==Admission::Fault::none, + "hardware ASIO period may exceed retained renderer chunk quantum"); + check(Admission::verify(plan,clock,epoch,1,8193)==Admission::Fault::unsafeFrames, + "reader scratch cannot exceed absolute callback hard frame limit"); + check(Admission::verify(plan,clock,epoch+1,1,frames)== + Admission::Fault::stalePrimary, + "stale A output epoch cannot publish qualified PCM"); + check(Admission::verify(plan,clock,epoch,2,frames)== + Admission::Fault::wrongPrimaryPins, + "virtual A+B input count must not replace real A callback count"); + check(Admission::verify(plan,clock,epoch,1,0)== + Admission::Fault::unsafeFrames, + "no zero or unsafe native callback scratch capacity"); + auto wrongDevice=devices; + wrongDevice[1].deviceLease=3003; + d::MultiDeviceInputPlan wrongLeasePlan; + check(d::MultiDeviceInputPlan::prepare(epoch,wrongDevice,bindings, + roster.channels(),wrongLeasePlan,err), + "negative independent B lease candidate prepared"); + check(Admission::verify(wrongLeasePlan,clock,epoch,1,frames)== + Admission::Fault::wrongCaptureLease, + "driver B ASRC lease cannot silently follow device-map rebind"); + + std::array bLeft{},bRight{}; + bLeft.fill(.4f);bRight.fill(.6f); + const float* bInput[]{bLeft.data(),bRight.data()}; + check(clock.push(bInput,2,4096),"producer FIFO primed before A render"); + d::QualifiedSecondaryCaptureReader reader; + check(reader.prepare(plan,frames),"reader allocates only on CONTROL"); + std::array aRaw{},left{},right{}; + aRaw.fill(.2f);const float* aInput[]{aRaw.data()}; + int aFx=0,bFx=0,mainFx=0; + const auto fx=[&](m::ChannelId id,float*,float*,int) noexcept { + if(id==a)++aFx; + if(id==b)++bFx; + if(id==main)++mainFx; + }; + const auto render=[&](bool nested=false) { + return reader.withBlocks(epoch,aInput,1,frames,clock, + [&](std::span blocks) noexcept { + if(nested) + check(!reader.withBlocks(epoch,aInput,1,frames,clock, + [](std::span) noexcept { + return true; + }),"overlap must fail silent without scratching B"); + return native.render(epoch,nullptr,0,left.data(),right.data(), + frames,false,fx,nullptr,nullptr,{},{},{},nullptr,0,blocks); + }); + }; + check(render(true),"A+B native render consumes B ASRC exactly once"); + check(aFx==1&&bFx==1&&mainFx==1,"one ChannelId FX pass per block"); + constexpr float monoCenter=.7071067811865475f; + check(near(left[frames-1],.2f*monoCenter+.4f)&& + near(right[frames-1],.2f*monoCenter+.6f), + "B's real clock bridge PCM reaches MAIN with A"); + check(reader.status().secondaryAccepted==1&&reader.status().overlaps==1, + "one successful capture consumption, overlap rejected"); + // Structural WIRE/FX edits cannot silently drop the verified B map. + // An identical authenticated topology is allowed even with MAIN armed + // when the native caller proved this is internal WIRE-only. + const auto wired=native.commit(roster,request,1,epoch,epoch,false, + {},true,false); + check(wired.ok()&&wired.revision==2, + "WIRE-only graph revision inherits qualified input lease"); + check(native.hasQualifiedInputMap(epoch,2), + "WIRE-only revision must not restore unsafe v1 .smix saving"); + check(render(),"B still audible after internal graph recompile"); + check(near(left[frames-1],.2f*monoCenter+.4f), + "committed BUS/WIRE revision retains capture B"); + auto wrongPatch=request; + wrongPatch.sources.back().inputL=0; // erroneously aliases A, no longer B map + const auto wrongCommit=native.commit(roster,wrongPatch,2,epoch,epoch,false, + {},true,false); + check(wrongCommit.fault==m::DynamicNativeSessionPublisher::Fault::invalidCandidate + &&native.acceptedRevision()==2, + "cannot silently remap B by reusing native WIRE-only authorization"); + const auto whileArmed=native.commit(roster,request,2,epoch,epoch,false, + {},true,false,&plan); + check(whileArmed.fault==m::DynamicNativeSessionPublisher::Fault::outputArmed, + "explicit device map replacement must disarm MAIN first"); + + // B lost/failed is SILENCE in B channels, never relabeled A Input1. + clock.fault(); + check(render(),"faulted B cannot block verified primary A"); + check(near(left[frames-1],.2f*monoCenter,0.005f)&& + near(right[frames-1],.2f*monoCenter,0.005f), + "B dropout leaves A audible and correctly isolated"); + check(reader.status().secondarySilent==1, + "native B fault recorded without false ready"); + check(!reader.withBlocks(epoch+1,aInput,1,frames,clock, + [](std::span) noexcept { + return true; + }),"primary epoch invalidates entire callback"); + check(reader.status().rejected==1,"stale primary epoch counted"); + + // Same generation but changed physical device lease is not sufficient + // to republish audio or borrow another ASIO driver's PCM. + reader.stop(); + auto changed=devices; + changed[1].deviceLease=9999; + d::MultiDeviceInputPlan wrong; + check(d::MultiDeviceInputPlan::prepare(epoch,changed,bindings, + roster.channels(),wrong,err),"detached revised B lease prepared"); + check(reader.prepare(wrong,frames),"controlled new reader prepared"); + check(render(),"new B lease absent in ASRC must not break A"); + check(near(left[frames-1],.2f*monoCenter,0.005f), + "stale ASRC cannot be relabeled into newly leased device"); + // IO-2G P1: CONTROL must close callback admission BEFORE reading + // count/freeing scratch. In-flight render keeps the same exact borrowed + // B pointer pinned; a concurrent late primary callback fails immediately. + check(reader.prepare(plan,frames),"race fixture uses verified A+B map"); + std::atomic entered{false},release{false},stopped{false}; + std::thread admitted([&] { + const bool ok=reader.withBlocks(epoch,aInput,1,frames,clock, + [&](std::span) noexcept { + entered.store(true,std::memory_order_release); + while(!release.load(std::memory_order_acquire)) + std::this_thread::yield(); // test-only; never production RT + return true; + }); + check(ok,"previously admitted callback completed with scratch intact"); + }); + const auto deadline=std::chrono::steady_clock::now()+ + std::chrono::seconds(5); + while(!entered.load(std::memory_order_acquire) && + std::chrono::steady_clock::now()) noexcept { + return true; + }),"late primary callback rejects without borrowing freed scratch"); + release.store(true,std::memory_order_release); + admitted.join();control.join(); + check(stopped.load(std::memory_order_acquire) && !reader.status().ready, + "CONTROL retirement finishes only after old callback exits"); + + // ASan/TSan-friendly concurrent entry vs STOP/reprepare stress. + // The capture clock is stable; only reader scratch is being retired. + check(reader.prepare(plan,frames),"reader can safely reprepare after STOP"); + std::atomic running{true}; + std::thread primary([&] { + while(running.load(std::memory_order_acquire)) + (void)reader.withBlocks(epoch,aInput,1,frames,clock, + [](std::span) + noexcept {return true;}); + }); + for(int i=0;i<1200;++i) { + reader.stop(); + check(reader.prepare(plan,frames),"CONTROL reprepare gate stress"); + } + running.store(false,std::memory_order_release); + primary.join(); + reader.stop(); + clock.stop(); + + // IO-2H P1: B capture closes/resets its ASRC while the primary render + // callback is still consuming B. Exactly the unsafe sequence on an + // intentional disconnect. No global A reader shutdown is allowed: + // qualified A+B stays installed; B must become SILENT and A stays live. + check(clock.prepare(format)&&clock.activate(), + "fresh B clock is prepared for independent disconnect race"); + check(reader.prepare(plan,frames),"same native A+B reader stays installed"); + std::atomic keepRendering{true}; + std::atomic validPrimary{0},aOnly{0}; + std::thread aCallback([&] { + while(keepRendering.load(std::memory_order_acquire)) { + if(reader.withBlocks(epoch,aInput,1,frames,clock, + [&](std::span blocks) + noexcept { + const bool ok=native.render(epoch,nullptr,0, + left.data(),right.data(),frames,false,fx, + nullptr,nullptr,{},{},{},nullptr,0,blocks); + if(ok) { + validPrimary.fetch_add(1,std::memory_order_relaxed); + if(near(left[frames-1],.2f*monoCenter,0.005f)) + aOnly.fetch_add(1,std::memory_order_relaxed); + } + return ok; + })){} // test only: single primary callback + } + }); + for(int i=0;i<160;++i) { + clock.stop(); // CONTROL must wait for both admitted clock callbacks + if(i!=159) + check(clock.prepare(format)&&clock.activate(), + "B ASRC reprepare with competing A pulls never races reset"); + } + keepRendering.store(false,std::memory_order_release); + aCallback.join(); + check(validPrimary.load(std::memory_order_relaxed)>0 && + aOnly.load(std::memory_order_relaxed)>0, + "primary ChannelId MAIN and A-only PCM survive competing B disconnect"); + // After B has fully disconnected, the same qualified reader must still + // invoke the ONE A graph and silence only the missing B source. + check(reader.withBlocks(epoch,aInput,1,frames,clock, + [&](std::span blocks) + noexcept { + return native.render(epoch,nullptr,0,left.data(),right.data(), + frames,false,fx,nullptr,nullptr,{},{},{},nullptr,0,blocks); + }) && near(left[frames-1],.2f*monoCenter,0.005f) && + near(right[frames-1],.2f*monoCenter,0.005f), + "B absent never mutes or aliases direct primary A PCM"); + reader.stop(); + clock.stop(); + // IO-2D persistence recovery: a saved primary-only .smix can replace + // A+B only by an explicit, muted native session transaction. WIRE/FX + // omission of a map still inherits B and must never silently alias pins. + using MapChange=m::DynamicNativeSessionPublisher::QualifiedMapChange; + check(native.hasQualifiedInputMap(epoch,2), + "prior A+B PCM map installed before restore"); + const auto unsafeRestore=native.commit( + roster,old,2,epoch,epoch,false,{},false,false,nullptr, + MapChange::replaceWithPrimaryOnly); + check(unsafeRestore.fault== + m::DynamicNativeSessionPublisher::Fault::outputArmed && + native.hasQualifiedInputMap(epoch,2), + "unmuted primary-only .smix replacement cannot remove B map"); + const auto restored=native.commit( + roster,old,2,epoch,epoch,true,{},false,false,nullptr, + MapChange::replaceWithPrimaryOnly); + check(restored.ok()&&restored.revision==3 && + !native.hasQualifiedInputMap(epoch,3), + "muted explicit A-only .smix publishes one new PCM without B map"); + check(native.render(epoch,aInput,1,left.data(),right.data(), + frames,false,fx,nullptr,nullptr,{},{},{},nullptr,0), + "restored A-only PCM accepts raw primary callback again"); + check(near(left[frames-1],.2f*monoCenter,0.005f)&& + near(right[frames-1],.2f*monoCenter,0.005f), + "restored primary-only .smix never aliases or sums B PCM"); + const auto doubleRemove=native.commit( + roster,old,3,epoch,epoch,true,{},false,false,nullptr, + MapChange::replaceWithPrimaryOnly); + check(doubleRemove.fault== + m::DynamicNativeSessionPublisher::Fault::invalidCandidate, + "a nonqualified A-only session cannot spoof a B map retirement"); + std::puts("IO2_CLOCKED_NATIVE_PASS: 44.1k B -> ASRC -> 48k A qualified ChannelId PCM MAIN; loss isolated; exact A-only restore"); +} +} // namespace armix::io2_clocked_test diff --git a/tests/live_channel_fx_graph_test.cpp b/tests/live_channel_fx_graph_test.cpp index 7437310bb..09ace49a2 100644 --- a/tests/live_channel_fx_graph_test.cpp +++ b/tests/live_channel_fx_graph_test.cpp @@ -1831,6 +1831,80 @@ static void verifyNativePuzzleV8FixtureAndWire() { .getProperty("rawPeak",0.))==.25); } +// IO-2E: old qualified A+B lease belongs to epoch 91, while the actual +// verified primary callback has restarted into epoch 92. It may be retired +// only by an explicit, disarmed primary-only session replacement. No silent +// fallthrough from B virtual ordinals to A callback pins is ever permitted. +static void verifyQualifiedMapCrossEpochReplacement() { + namespace io=armix::device; + DynamicChannelRoster roster; + std::vector additions; + for(int i=0;i<3;++i) { + ChannelEdit add;add.kind=ChannelEdit::Kind::add;add.position=i; + add.role=i==2?ChannelRole::main:ChannelRole::input; + add.format=i==1?ProcessingFormat::stereo:ProcessingFormat::mono; + if(i==2)add.format=ProcessingFormat::stereo; + add.text=i==0?"A VOICE":i==1?"B STEREO":"MAIN"; + additions.push_back(add); + } + const auto created=roster.edit(0,additions); + assert(created.ok()&&created.createdIds.size()==3); + const auto sourceA=created.createdIds[0], + sourceB=created.createdIds[1]; + const std::array aPins{0,2},bPins{0,7}; + const std::array devices{{ + {"ASIO/verified-A",91,true,aPins,1001}, + {"ASIO/verified-B",91,false,bPins,2002} + }}; + const std::array mappings{{ + {sourceA,{"ASIO/verified-A",2},{},false}, + {sourceB,{"ASIO/verified-B",0},{"ASIO/verified-B",7},true} + }}; + io::MultiDeviceInputPlan plan; + io::MultiDeviceInputFault err; + assert(io::MultiDeviceInputPlan::prepare(91,devices,mappings, + roster.channels(),plan,err)); + assert(plan.virtualInputCount()==4); + DynamicGraphRequest qualified; + qualified.physicalInputs=4;qualified.maxFrames=64; + qualified.sources={{sourceA,1,-1,false},{sourceB,2,3,true}}; + DynamicNativeSessionPublisher owner; + assert(owner.commit(roster,qualified,0,91,91,true, + {},false,false,&plan).ok()); + assert(owner.acceptedRevision()==1); + assert(owner.hasQualifiedInputMap(91,1)); + + // A compatible persisted A-only .smix has real A callback ordinals, + // not inherited old A+B virtual ordinals. + DynamicGraphRequest primaryOnly; + primaryOnly.physicalInputs=2;primaryOnly.maxFrames=64; + primaryOnly.sources={{sourceA,1,-1,false}}; + using Change=DynamicNativeSessionPublisher::QualifiedMapChange; + using Fault=DynamicNativeSessionPublisher::Fault; + // Without an explicit map-replacement transaction, old B still owns a + // qualified map at epoch 91. Reject rather than guess about ASIO pins. + assert(owner.commit(roster,primaryOnly,1,92,92,true).fault== + Fault::invalidCandidate); + assert(owner.commit(roster,primaryOnly,1,92,93,true, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).fault== + Fault::staleDevice); + assert(owner.commit(roster,primaryOnly,1,92,92,false, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).fault== + Fault::outputArmed); + assert(owner.acceptedRevision()==1); + assert(owner.hasQualifiedInputMap(91,1)); + assert(owner.commit(roster,primaryOnly,1,92,92,true, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).ok()); + assert(owner.acceptedRevision()==2); + assert(!owner.hasQualifiedInputMap(92,2)); + assert(!owner.hasQualifiedInputMap(91,1)); + // A second unsolicited map retirement is never admissible. + assert(owner.commit(roster,primaryOnly,2,92,92,true, + {},false,false,nullptr,Change::replaceWithPrimaryOnly).fault== + Fault::invalidCandidate); + assert(owner.acceptedRevision()==2); +} + // E2: native JUCE VST3 stays audible through a serial GROUP edit; a missing // successor FX owner rejects atomically rather than deleting hosted processing. static void verifyChannelIdGroupPreservesHostedFx() { @@ -2603,6 +2677,7 @@ int main(int argc,char** argv) { verifyNativeConsoleWireRejectsUnsupportedM4AndPreservesEpoch(); verifyFirstSoundOnePinNativeSourceDraft(); verifyNativePuzzleV8FixtureAndWire(); + verifyQualifiedMapCrossEpochReplacement(); verifyChannelIdGroupPreservesHostedFx(); verifyLatencyAlignedBypass(); verifyNativeFxRackTransactions(); diff --git a/tests/mixer_routing_plan_test.cpp b/tests/mixer_routing_plan_test.cpp index 888108e35..1852d034e 100644 --- a/tests/mixer_routing_plan_test.cpp +++ b/tests/mixer_routing_plan_test.cpp @@ -4,6 +4,7 @@ #include "../engine/core/DynamicPreparedMixerBlock.h" #include "../engine/core/LegacyLiveGraphMigration.h" #include "../engine/core/DynamicNativeSessionPublisher.h" +#include "io2/QualifiedSecondaryCaptureReaderCases.h" #include #if defined(NDEBUG) #undef NDEBUG // Never skip P1A assertions in Release native CTest. @@ -1173,6 +1174,8 @@ static void verifyNativePrePostAndSendEnablePcm() { } int main() { + // Before paid Windows MSVC: prove the real IO1 ASRC feeds one native PCM graph. + armix::io2_clocked_test::run(); verifyNativePrePostAndSendEnablePcm(); verifyNativeInputGainBeforeFx(); verifyDynamicInPlacePhysicalIOBuffers(); diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index b5007085f..6238434d7 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -145,6 +145,97 @@ class FixtureDevice final : public juce::AudioIODevice { double rate=48000.; }; +// IO-2F: execute the actual LiveDryRoutingLab restore/rebind handoff with +// a JUCE callback fixture. No physical B driver is opened: the clock bridge +// and device lease are deterministic off-RT test objects. +static void qualifiedAsioRestartHandoffRetiresB() { + namespace d=armix::device; + FixtureDevice device; + device.frames=256; + juce::AudioPluginFormatManager formats; + LiveDryRoutingLab mixer; + mixer.prepareDevice(&device); + const auto oldEpoch=mixer.epoch(); + auto base=makeSession(); + d::JuceActivePortSnapshot pins; + d::JuceActivePortSnapshot::Fault fault{}; + assert(d::JuceActivePortSnapshot::capture(&device,oldEpoch,pins,fault)); + std::shared_ptr bank; + assert(NativeMixerSessionFxRestore::prepare(base,{},formats, + device.rate,device.frames,pins.epoch, + mixer.nativeGraphRevisionForRestore(),bank).isEmpty() && bank); + assert(mixer.restoreNativeMixerSession(base,std::move(bank), + pins,true).isEmpty()); + assert(mixer.channelIdPhysicalPcmActive()); + const std::array aPins{0,1},bPins{0,7}; + constexpr std::uint64_t bGeneration=94,bLease=2002; + const std::array endpoints{{ + {"fixture-A",oldEpoch,true,aPins,1001}, + {"fixture-B",bGeneration,false,bPins,bLease} + }}; + const std::array choices{{ + {{1},{"fixture-A",0},{},false}, + {{2},{"fixture-B",0},{"fixture-B",7},true} + }}; + d::MultiDeviceInputPlan map; + d::MultiDeviceInputFault mapFault{}; + assert(mixer.prepareQualifiedCapturePlan(oldEpoch,endpoints,choices, + map,mapFault)); + d::SecondaryCaptureClockStream clock; + const d::SecondaryCaptureClockStream::Format format{ + 44100.,device.rate,256,256,2,bGeneration,oldEpoch,bLease}; + assert(clock.prepare(format)&&clock.activate()); + d::QualifiedSecondaryCaptureReader reader; + const auto before=mixer.nativeGraphRevisionForRestore()-1; + const auto install=mixer.installQualifiedSecondaryInput( + oldEpoch,before,base.roster.revision(),map,reader,clock,true); + assert(install.accepted && mixer.qualifiedInputMapActive()); + assert(mixer.nativeGraphRevisionForRestore()==before+2); + // A normal .smix v1 cannot persist these B virtual ordinals. + MixerSessionDocument unsafe; + std::vector blobs; + assert(mixer.captureNativeMixerSession(unsafe,blobs).isNotEmpty()); + mixer.deviceStopped(); + mixer.prepareDevice(&device); + auto restartEpoch=mixer.epoch(); + MixerSessionDocument recovered; + assert(mixer.describeRetainedAsioSession(recovered)); + assert(mixer.preparePrimaryOnlyAsioRestartDocument(recovered,2)); + assert(recovered.request.physicalInputs==2 && + recovered.request.sources.size()==1 && + recovered.request.sources.front().id.value==1 && + recovered.roster.find({2})!=nullptr); + d::JuceActivePortSnapshot newPins; + assert(d::JuceActivePortSnapshot::capture(&device, + restartEpoch,newPins,fault)); + // Regression reproducer: old no-marker caller rejected, preserving A+B. + assert(!mixer.rebindRetainedAsioSession(recovered,newPins,256,false)); + assert(mixer.qualifiedInputMapActive()); + // Fixed caller supplies lostB=true only after staging verified A-only PCM. + assert(mixer.rebindRetainedAsioSession( + std::move(recovered),newPins,256,true)); + assert(!mixer.qualifiedInputMapActive()); + assert(mixer.channelIdPhysicalPcmActive()); + MixerSessionDocument durable; + assert(mixer.captureNativeMixerSession(durable,blobs).isEmpty()); + assert(durable.roster.find({2})!=nullptr && + durable.request.physicalInputs==2 && + durable.request.sources.size()==1); + // Second primary restart must use the ordinary 3-argument compatibility + // path; the old B map no longer exists and must not be retired twice. + mixer.deviceStopped(); + mixer.prepareDevice(&device); + MixerSessionDocument again; + assert(mixer.describeRetainedAsioSession(again)); + assert(d::JuceActivePortSnapshot::capture(&device, + mixer.epoch(),newPins,fault)); + assert(mixer.rebindRetainedAsioSession( + std::move(again),newPins,256)); + assert(mixer.channelIdPhysicalPcmActive() && + !mixer.qualifiedInputMapActive()); + reader.stop();clock.stop(); +} + static void outputOnlyNativeStartup() { // Real output-only callback: never invent a capture pin, but a silent // ChannelId session, its FX/WIRE bus and physical zero output are valid. @@ -1470,6 +1561,7 @@ int main(){ outputOnlyNativeStartup(); warmVst3Discovery(); nativeDeviceRecovery(); + qualifiedAsioRestartHandoffRetiresB(); auto d=makeSession(); checkRecoveryPlan(d); verifyExternalOutputPortableIntent();