Skip to main content

grafton_ndi/discovery/
advertiser.rs

1//! Registration of senders and receivers with a Discovery Server.
2
3use super::{Retained, ServerApi, ServerObject};
4use crate::{
5    receiver::{ReceiverCore, ReceiverMode},
6    sender::SenderResource,
7    sys, Error, Ndi, Receiver, Rejected, Result, RuntimeFeature, Sender,
8};
9use std::{
10    collections::BTreeMap,
11    ffi::CString,
12    fmt, ptr,
13    sync::{
14        atomic::{AtomicU64, Ordering},
15        Arc,
16    },
17};
18
19/// The Discovery Server an advertiser registers with.
20///
21/// Without explicit servers the SDK uses the Discovery Server from the NDI
22/// configuration. Creation fails when it names no server or one the SDK
23/// cannot use.
24#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
25pub struct AdvertiserOptions {
26    servers: Option<Vec<String>>,
27    #[cfg(feature = "advanced")]
28    config: Option<crate::advanced::AdvancedConfig>,
29}
30impl AdvertiserOptions {
31    /// Inherit Discovery Server endpoints from the NDI configuration.
32    #[must_use]
33    pub fn clear_servers(mut self) -> Self {
34        self.servers = None;
35        self
36    }
37
38    /// Remove the per-instance Advanced configuration override.
39    #[cfg(feature = "advanced")]
40    #[must_use]
41    pub fn clear_config(mut self) -> Self {
42        self.config = None;
43        self
44    }
45
46    /// Requested server endpoints, or `None` to inherit the NDI configuration.
47    #[must_use]
48    pub fn configured_servers(&self) -> Option<&[String]> {
49        self.servers.as_deref()
50    }
51
52    /// The stored Advanced configuration handle, if any.
53    #[cfg(feature = "advanced")]
54    #[must_use]
55    pub fn configured_config(&self) -> Option<&crate::advanced::AdvancedConfig> {
56        self.config.as_ref()
57    }
58
59    /// The default options: the Discovery Server of the NDI configuration.
60    pub fn new() -> Self {
61        Self::default()
62    }
63    /// Use a non-empty list of endpoints in place of the SDK configuration.
64    /// Use [`Self::clear_servers`] to inherit the configuration.
65    ///
66    /// Each endpoint is a host name or IP address, optionally followed by a
67    /// colon and a port (5959 when omitted). Several elements register with
68    /// redundant servers. Creation refuses empty elements and elements
69    /// containing a comma or NUL.
70    #[must_use]
71    pub fn servers(mut self, servers: impl IntoIterator<Item = impl Into<String>>) -> Self {
72        self.servers = Some(servers.into_iter().map(Into::into).collect());
73        self
74    }
75    /// Create the advertiser with this per-instance Advanced SDK
76    /// configuration, which it keeps for as long as it lives.
77    ///
78    /// [`SendAdvertiser::new`] and [`RecvAdvertiser::new`] then need an
79    /// Advanced runtime, and a build with the Advanced SDK.
80    #[cfg(feature = "advanced")]
81    #[must_use]
82    pub fn config(mut self, config: crate::advanced::AdvancedConfig) -> Self {
83        self.config = Some(config);
84        self
85    }
86}
87/// How a sender is advertised. Monitoring is disabled unless explicitly enabled.
88#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
89pub struct SendAdvertisement {
90    monitoring: bool,
91}
92impl SendAdvertisement {
93    /// Whether remote monitoring was requested.
94    #[must_use]
95    pub fn configured_allow_monitoring(&self) -> bool {
96        self.monitoring
97    }
98
99    /// The default advertisement: no remote monitoring.
100    pub fn new() -> Self {
101        Self::default()
102    }
103    /// Permit remote monitoring of this sender.
104    #[must_use]
105    pub fn allow_monitoring(mut self, enabled: bool) -> Self {
106        self.monitoring = enabled;
107        self
108    }
109}
110/// How a receiver is advertised. Monitoring and remote source control are
111/// disabled unless explicitly enabled.
112#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
113pub struct RecvAdvertisement {
114    monitoring: bool,
115    controlling: bool,
116    input_group: Option<String>,
117}
118impl RecvAdvertisement {
119    /// Remove the explicitly requested receiver input group.
120    #[must_use]
121    pub fn clear_input_group(mut self) -> Self {
122        self.input_group = None;
123        self
124    }
125
126    /// Whether remote monitoring was requested.
127    #[must_use]
128    pub fn configured_allow_monitoring(&self) -> bool {
129        self.monitoring
130    }
131
132    /// Whether remote source control was requested.
133    #[must_use]
134    pub fn configured_allow_controlling(&self) -> bool {
135        self.controlling
136    }
137
138    /// Requested input group, if any.
139    #[must_use]
140    pub fn configured_input_group(&self) -> Option<&str> {
141        self.input_group.as_deref()
142    }
143
144    /// The default advertisement: no remote monitoring or source control, and
145    /// no input group.
146    pub fn new() -> Self {
147        Self::default()
148    }
149    /// Permit remote monitoring.
150    #[must_use]
151    pub fn allow_monitoring(mut self, enabled: bool) -> Self {
152        self.monitoring = enabled;
153        self
154    }
155    /// Permit Discovery Server clients to change this receiver's source.
156    ///
157    /// Remote changes are observed through [`Receiver::wait_for_source_name_change`].
158    /// They do not update [`Receiver::connection_target`], the latest local
159    /// request; [`Receiver::reconnect`] requests that local target again and
160    /// replaces any remote routing.
161    ///
162    /// Registering with this enabled requires
163    /// [remote receiver control](RuntimeFeature::RemoteReceiverControl),
164    /// which is unavailable on Standard Windows runtimes.
165    #[must_use]
166    pub fn allow_controlling(mut self, enabled: bool) -> Self {
167        self.controlling = enabled;
168        self
169    }
170    /// Name the receiver's input group. Receivers that share a group name, such
171    /// as the video and audio receivers of one input, are presented together.
172    #[must_use]
173    pub fn input_group(mut self, group: impl Into<String>) -> Self {
174        self.input_group = Some(group.into());
175        self
176    }
177}
178
179/// Registration operations added to the shared Discovery Server lifecycle.
180trait AdvertiserApi: ServerApi {
181    type Member: Send;
182    type Advertisement;
183    const MEMBER: &'static str;
184    fn same_member(a: &Self::Member, b: &Self::Member) -> bool;
185    /// # Safety
186    /// The advertiser and member are live; the member retains its native handle
187    /// and all advertisement strings until removal or advertiser destruction.
188    unsafe fn add(
189        &self,
190        instance: Self::Instance,
191        member: &Self::Member,
192        options: &Self::Advertisement,
193    ) -> sys::table::Called<bool>;
194    /// # Safety
195    /// The advertiser and member are live and belong to this runtime.
196    unsafe fn remove(
197        &self,
198        instance: Self::Instance,
199        member: &Self::Member,
200    ) -> sys::table::Called<bool>;
201}
202
203impl AdvertiserApi for sys::SenderAdvertising {
204    type Member = Arc<SenderResource>;
205    type Advertisement = SendAdvertisement;
206    const MEMBER: &'static str = "sender";
207    fn same_member(a: &Self::Member, b: &Self::Member) -> bool {
208        Arc::ptr_eq(a, b)
209    }
210    unsafe fn add(
211        &self,
212        instance: Self::Instance,
213        member: &Self::Member,
214        options: &Self::Advertisement,
215    ) -> sys::table::Called<bool> {
216        // SAFETY: forwarded to the caller's live-owner obligation.
217        unsafe {
218            self.named().NDIlib_send_advertiser_add_sender(
219                instance.0,
220                member.handle().instance(),
221                options.monitoring,
222            )
223        }
224    }
225    unsafe fn remove(
226        &self,
227        instance: Self::Instance,
228        member: &Self::Member,
229    ) -> sys::table::Called<bool> {
230        // SAFETY: forwarded to the caller's live-owner obligation.
231        unsafe {
232            self.named()
233                .NDIlib_send_advertiser_del_sender(instance.0, member.handle().instance())
234        }
235    }
236}
237
238/// A registered receiver and the input-group name the SDK was given for it.
239struct ReceiverMember {
240    resource: Arc<ReceiverCore>,
241    _input_group: Option<CString>,
242}
243
244impl AdvertiserApi for sys::ReceiverAdvertising {
245    type Member = ReceiverMember;
246    type Advertisement = RecvAdvertisement;
247    const MEMBER: &'static str = "receiver";
248    fn same_member(a: &Self::Member, b: &Self::Member) -> bool {
249        Arc::ptr_eq(&a.resource, &b.resource)
250    }
251    unsafe fn add(
252        &self,
253        instance: Self::Instance,
254        member: &Self::Member,
255        options: &Self::Advertisement,
256    ) -> sys::table::Called<bool> {
257        let membership = member.resource.advertiser_membership();
258        // SAFETY: membership borrows immutable receiver creation properties and
259        // its stable observer registry. Native registry mutexes cover mutation;
260        // the retained owner and input-group name cover native lifetimes.
261        unsafe {
262            self.named().NDIlib_recv_advertiser_add_receiver(
263                instance.0,
264                membership.instance(),
265                options.controlling,
266                options.monitoring,
267                member
268                    ._input_group
269                    .as_ref()
270                    .map_or(ptr::null(), |s| s.as_ptr()),
271            )
272        }
273    }
274    unsafe fn remove(
275        &self,
276        instance: Self::Instance,
277        member: &Self::Member,
278    ) -> sys::table::Called<bool> {
279        let membership = member.resource.advertiser_membership();
280        // SAFETY: removal borrows the retained receiver and reaches only its
281        // stable observer registry, protected by the native registry mutex.
282        // It can run from an allocator policy while a connection call waits.
283        unsafe {
284            self.named()
285                .NDIlib_recv_advertiser_del_receiver(instance.0, membership.instance())
286        }
287    }
288}
289
290/// Source of registration identifiers. They are unique across advertisers, so
291/// a registration can only ever name an entry of the advertiser that issued it.
292static NEXT_REGISTRATION: AtomicU64 = AtomicU64::new(1);
293
294/// The objects the SDK can read until their advertiser is destroyed.
295struct Members<A: AdvertiserApi>(BTreeMap<u64, A::Member>);
296
297impl<A: AdvertiserApi> Default for Members<A> {
298    fn default() -> Self {
299        Self(BTreeMap::new())
300    }
301}
302
303/// A native advertiser and the objects registered with it.
304///
305/// The advertiser is the single owner of its registrations: each one keeps its
306/// sender or receiver alive until it is removed or the advertiser is dropped.
307struct Advertiser<A: AdvertiserApi> {
308    server: ServerObject<A, Members<A>>,
309}
310
311const_assert!({
312    const fn assert_send<T: Send>() {}
313    assert_send::<Advertiser<sys::SenderAdvertising>>();
314    assert_send::<Advertiser<sys::ReceiverAdvertising>>();
315});
316
317impl<A: AdvertiserApi> Advertiser<A>
318where
319    A: ServerApi<Options = AdvertiserOptions>,
320{
321    fn new(ndi: &Ndi, options: &AdvertiserOptions) -> Result<Self> {
322        Ok(Self {
323            server: ServerObject::new(ndi, options)?,
324        })
325    }
326}
327
328impl<A: AdvertiserApi> Advertiser<A> {
329    fn register(&mut self, member: A::Member, options: &A::Advertisement) -> Result<u64> {
330        if self
331            .server
332            .retained()
333            .0
334            .values()
335            .any(|existing| A::same_member(existing, &member))
336        {
337            return Err(Error::InvalidInput(crate::InputDefect::AlreadyRegistered {
338                member: A::MEMBER,
339            }));
340        }
341        // SAFETY: the member owns its native object and advertisement strings;
342        // successful registration retains that value until the SDK releases it.
343        unsafe {
344            self.server
345                .api
346                .add(self.server.instance(), &member, options)
347        }
348        .performed()?;
349        Ok(self.retain(member))
350    }
351
352    /// Keep a newly registered `member` alive and return its identifier.
353    fn retain(&mut self, member: A::Member) -> u64 {
354        let id = NEXT_REGISTRATION.fetch_add(1, Ordering::Relaxed);
355        self.server.retained_mut().0.insert(id, member);
356        id
357    }
358
359    /// End the registration `id`, which the token `registration` names, as
360    /// its native removal operation.
361    ///
362    /// # Errors
363    ///
364    /// Hands `registration` back, changing nothing: with
365    /// [`Error::InvalidInput`] when another advertiser issued it, since the
366    /// token is the only way to end that registration, and with
367    /// [`Error::NativeOperationFailed`] when the SDK removes nothing because
368    /// it does not know the registered object.
369    fn release<R>(&mut self, id: u64, registration: R) -> std::result::Result<(), Rejected<R>> {
370        let Some(member) = self.server.retained().0.get(&id) else {
371            return Err(Rejected::new(
372                Error::InvalidInput(crate::InputDefect::ForeignRegistration),
373                registration,
374            ));
375        };
376        // SAFETY: the advertiser is live for this borrow.
377        if let Err(error) =
378            unsafe { self.server.api.remove(self.server.instance(), member) }.performed()
379        {
380            return Err(Rejected::new(error, registration));
381        }
382        // The SDK has forgotten the object, so it may be released.
383        self.server.retained_mut().0.remove(&id);
384        Ok(())
385    }
386}
387
388// SAFETY: the default map is empty. Registered members stay owned through
389// removal or native destruction, including when a pre-destroy removal fails.
390unsafe impl<A: AdvertiserApi> Retained<A> for Members<A> {
391    unsafe fn before_destroy(&mut self, api: &A, instance: A::Instance) {
392        for member in self.0.values() {
393            // SAFETY: the owner calls this hook before native destruction,
394            // retaining every registered object and its advertisement strings.
395            unsafe { api.remove(instance, member) };
396        }
397    }
398}
399
400/// Advertises senders to a Discovery Server so they can be monitored.
401///
402/// This is separate from the discovery every sender already performs: a
403/// registration here makes a sender visible to [`SendListener`]s, not to
404/// finders or receivers.
405///
406/// # Connection
407///
408/// An advertiser connects in the background and keeps trying for as long as
409/// it lives. It is created, and accepts registrations, whether or not its
410/// server can be reached, and delivers them once the server answers, which
411/// can take several seconds after the server appears. It has no way to report
412/// whether it is connected. To find out, use a [`SendListener`] on the same
413/// server: [`is_connected`](super::SendListener::is_connected) reports the
414/// connection, and a [snapshot](super::SendListener::current_senders) shows whether
415/// the registration arrived.
416///
417/// # Ownership
418///
419/// The advertiser owns its registrations. Registering a sender keeps the native
420/// sender alive until the registration is [removed](Self::unregister) or the
421/// advertiser is dropped, even if every [`Sender`] handle is dropped first.
422/// Dropping the advertiser removes every registration, destroys the native
423/// advertiser, and then releases the senders it was keeping alive.
424///
425/// # Threading
426///
427/// An advertiser is [`Send`] but not [`Sync`]: it may be moved to another
428/// thread, and is used by one thread at a time. Every method takes it
429/// exclusively, so `Sync` would give a shared reference nothing to do today.
430/// It is withheld, as from the listeners, because the SDK does not say
431/// whether calls on one advertiser may overlap, so that a shared query such
432/// as the listeners' connection state can be added without that guarantee.
433///
434/// [`SendListener`]: super::SendListener
435pub struct SendAdvertiser {
436    inner: Advertiser<sys::SenderAdvertising>,
437}
438/// Advertises receivers to a Discovery Server so they can be monitored and,
439/// when permitted, told which source to connect to.
440///
441/// # Connection
442///
443/// An advertiser connects in the background and keeps trying for as long as
444/// it lives. It is created, and accepts registrations, whether or not its
445/// server can be reached, and delivers them once the server answers, which
446/// can take several seconds after the server appears. It has no way to report
447/// whether it is connected. To find out, use a [`RecvListener`] on the same
448/// server: [`is_connected`](super::RecvListener::is_connected) reports the
449/// connection, and a [snapshot](super::RecvListener::current_receivers) shows whether
450/// the registration arrived.
451///
452/// # Ownership
453///
454/// The advertiser owns its registrations. Registering a receiver keeps the
455/// native receiver alive until the registration is [removed](Self::unregister)
456/// or the advertiser is dropped, even if every [`Receiver`] handle is dropped
457/// first. Dropping the advertiser removes every registration, destroys the
458/// native advertiser, and then releases the receivers it was keeping alive.
459///
460/// # Threading
461///
462/// An advertiser is [`Send`] but not [`Sync`]: it may be moved to another
463/// thread, and is used by one thread at a time. Every method takes it
464/// exclusively, so `Sync` would give a shared reference nothing to do today.
465/// It is withheld, as from the listeners, because the SDK does not say
466/// whether calls on one advertiser may overlap, so that a shared query such
467/// as the listeners' connection state can be added without that guarantee.
468///
469/// [`RecvListener`]: super::RecvListener
470pub struct RecvAdvertiser {
471    inner: Advertiser<sys::ReceiverAdvertising>,
472}
473
474const_assert!({
475    const fn assert_send<T: Send>() {}
476    assert_send::<SendAdvertiser>();
477    assert_send::<RecvAdvertiser>();
478});
479
480/// Names one sender registration for [`SendAdvertiser::unregister`].
481///
482/// The registration belongs to the advertiser that issued it, and only that
483/// advertiser can end it. Dropping this value changes nothing: the sender
484/// stays advertised, and alive, until the registration is removed or the
485/// advertiser is dropped.
486#[derive(Debug, PartialEq, Eq, Hash)]
487pub struct SendRegistration(u64);
488/// Names one receiver registration for [`RecvAdvertiser::unregister`].
489///
490/// The registration belongs to the advertiser that issued it, and only that
491/// advertiser can end it. Dropping this value changes nothing: the receiver
492/// stays advertised, and alive, until the registration is removed or the
493/// advertiser is dropped.
494#[derive(Debug, PartialEq, Eq, Hash)]
495pub struct RecvRegistration(u64);
496
497impl fmt::Debug for SendAdvertiser {
498    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
499        f.debug_struct("SendAdvertiser")
500            .field("server", &self.inner.server._url)
501            .field("registrations", &self.inner.server.retained().0.len())
502            .finish_non_exhaustive()
503    }
504}
505impl fmt::Debug for RecvAdvertiser {
506    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
507        f.debug_struct("RecvAdvertiser")
508            .field("server", &self.inner.server._url)
509            .field("registrations", &self.inner.server.retained().0.len())
510            .finish_non_exhaustive()
511    }
512}
513
514impl SendAdvertiser {
515    /// Create an advertiser for the Discovery Server `options` name, without
516    /// registering any sender.
517    ///
518    /// Success does not mean the server was reached; see
519    /// [Connection](Self#connection).
520    ///
521    /// # Errors
522    ///
523    /// Returns [`Error::UnsupportedCapability`] when the selected runtime
524    /// cannot provide [sender advertising], which needs NDI 6.4.0 or later, or
525    /// the options carry an Advanced configuration that the runtime or this
526    /// build cannot take; [`Error::InvalidInput`] when the server list is empty,
527    /// a server element is empty or contains a comma or NUL, or the SDK
528    /// creates no advertiser. Without an explicit server the SDK uses its configuration;
529    /// creation fails when it names no server or one the SDK cannot use. An
530    /// explicit address the SDK cannot parse is also refused.
531    ///
532    /// [sender advertising]: crate::capabilities::RuntimeFeature::SenderAdvertising
533    #[doc(alias = "NDIlib_send_advertiser_create")]
534    #[doc(alias = "NDIlib_send_advertiser_create_ex")]
535    pub fn new(ndi: &Ndi, options: &AdvertiserOptions) -> Result<Self> {
536        Ok(Self {
537            inner: Advertiser::new(ndi, options)?,
538        })
539    }
540    /// Advertise `sender`, keeping the native sender alive for as long as the
541    /// registration exists.
542    ///
543    /// The sender is not borrowed: it stays fully usable, and may even be
544    /// dropped, while it is registered.
545    ///
546    /// Only an ordinary sender, in the [`RawSend`](crate::RawSend) mode, can
547    /// be registered. The Advanced `CompressedSender` and `QueuedSender` lend
548    /// their sender in another [`SenderMode`](crate::SenderMode), which this
549    /// method does not take: they free the frames or completion state the SDK
550    /// uses as soon as their native sender is destroyed, and a registration
551    /// would keep it alive past that.
552    ///
553    /// Registering a sender within a few tens of milliseconds of removing it
554    /// from another advertiser on the same server can crash a listener on
555    /// that server, through an SDK defect of NDI 6.3.2 and 6.4.0.2. Wait a
556    /// second, or drop the other advertiser first. See the
557    /// [module documentation](super#sdk-defects-that-remain-in-64).
558    ///
559    /// # Errors
560    ///
561    /// Returns [`Error::InvalidInput`] when this advertiser already
562    /// advertises the sender, and [`Error::NativeOperationFailed`] when the SDK
563    /// refuses the registration.
564    #[doc(alias = "NDIlib_send_advertiser_add_sender")]
565    pub fn register(
566        &mut self,
567        sender: &Sender,
568        options: &SendAdvertisement,
569    ) -> Result<SendRegistration> {
570        self.inner
571            .register(sender.native_owner(), options)
572            .map(SendRegistration)
573    }
574    /// Stop advertising a sender and release this advertiser's hold on it.
575    ///
576    /// # Errors
577    ///
578    /// A failure changes nothing and hands the registration back inside
579    /// [`Rejected`]. Only the advertiser that issued a registration can end
580    /// it: another one fails with [`Error::InvalidInput`], and the
581    /// registration can still be given to the advertiser it belongs to. The
582    /// call fails with [`Error::NativeOperationFailed`] when the SDK removes
583    /// nothing because it does not know the sender; the registration then
584    /// stays in effect, and keeps the sender alive, until it is removed or
585    /// the advertiser is dropped.
586    #[doc(alias = "NDIlib_send_advertiser_del_sender")]
587    pub fn unregister(
588        &mut self,
589        registration: SendRegistration,
590    ) -> std::result::Result<(), Rejected<SendRegistration>> {
591        self.inner.release(registration.0, registration)
592    }
593}
594impl RecvAdvertiser {
595    /// Create an advertiser for the Discovery Server `options` name, without
596    /// registering any receiver.
597    ///
598    /// Success does not mean the server was reached; see
599    /// [Connection](Self#connection).
600    ///
601    /// # Errors
602    ///
603    /// Returns [`Error::UnsupportedCapability`] when the selected runtime
604    /// cannot provide [receiver advertising], which needs NDI 6.4.0 or later,
605    /// or the options carry an Advanced configuration that the runtime or this
606    /// build cannot take; [`Error::InvalidInput`] when the server list is empty,
607    /// a server element is empty or contains a comma or NUL, or the SDK
608    /// creates no advertiser. Without an explicit server the SDK uses its configuration;
609    /// creation fails when it names no server or one the SDK cannot use. An
610    /// explicit address the SDK cannot parse is also refused.
611    ///
612    /// [receiver advertising]: crate::capabilities::RuntimeFeature::ReceiverAdvertising
613    #[doc(alias = "NDIlib_recv_advertiser_create")]
614    #[doc(alias = "NDIlib_recv_advertiser_create_ex")]
615    pub fn new(ndi: &Ndi, options: &AdvertiserOptions) -> Result<Self> {
616        Ok(Self {
617            inner: Advertiser::new(ndi, options)?,
618        })
619    }
620    /// Advertise `receiver`, in any mode, keeping the native receiver alive for
621    /// as long as the registration exists.
622    ///
623    /// The receiver is not borrowed: it stays fully usable, and may even be
624    /// dropped, while it is registered.
625    ///
626    /// Two SDK defects of NDI 6.3.2 and 6.4.0.2 concern a registered receiver.
627    /// Registering it within a few tens of milliseconds of removing it from
628    /// another advertiser on the same server can crash a listener on that
629    /// server; wait a second, or drop the other advertiser first. And a
630    /// listener anywhere that unsubscribes from it while it connects can block
631    /// that connect for good. See the
632    /// [module documentation](super#sdk-defects-that-remain-in-64).
633    ///
634    /// # Errors
635    ///
636    /// Returns [`Error::InvalidCString`] when the input-group name contains a
637    /// NUL byte, [`Error::InvalidInput`] when this advertiser already
638    /// advertises the receiver, and [`Error::NativeOperationFailed`] when the
639    /// SDK refuses the registration. Returns [`Error::UnsupportedCapability`]
640    /// when the options request remote control and the selected runtime
641    /// lacks [remote receiver control](RuntimeFeature::RemoteReceiverControl).
642    #[doc(alias = "NDIlib_recv_advertiser_add_receiver")]
643    pub fn register<M: ReceiverMode>(
644        &mut self,
645        receiver: &Receiver<M>,
646        options: &RecvAdvertisement,
647    ) -> Result<RecvRegistration> {
648        if options.controlling {
649            receiver
650                .core
651                .ndi()
652                .require_feature(RuntimeFeature::RemoteReceiverControl)?;
653        }
654        let input_group = options
655            .input_group
656            .as_deref()
657            .map(CString::new)
658            .transpose()?;
659        self.inner
660            .register(
661                ReceiverMember {
662                    resource: Arc::clone(&receiver.core),
663                    _input_group: input_group,
664                },
665                options,
666            )
667            .map(RecvRegistration)
668    }
669    /// Stop advertising a receiver and release this advertiser's hold on it.
670    ///
671    /// # Errors
672    ///
673    /// A failure changes nothing and hands the registration back inside
674    /// [`Rejected`]. Only the advertiser that issued a registration can end
675    /// it: another one fails with [`Error::InvalidInput`], and the
676    /// registration can still be given to the advertiser it belongs to. The
677    /// call fails with [`Error::NativeOperationFailed`] when the SDK removes
678    /// nothing because it does not know the receiver; the registration then
679    /// stays in effect, and keeps the receiver alive, until it is removed or
680    /// the advertiser is dropped.
681    #[doc(alias = "NDIlib_recv_advertiser_del_receiver")]
682    pub fn unregister(
683        &mut self,
684        registration: RecvRegistration,
685    ) -> std::result::Result<(), Rejected<RecvRegistration>> {
686        self.inner.release(registration.0, registration)
687    }
688}