mx_remote_ffi/control.rs
1// Author: Lars Op den Kamp (lars@opdenkamp-it.nl)
2// Copyright (c) 2026 Op den Kamp IT Solutions
3
4//! The control surface: what a caller can ask a device to do.
5//!
6//! Every call here returns `MXR_OK` only when a frame left the socket. There
7//! is nothing further to wait for and nothing to acknowledge: a device answers
8//! a command by reporting its new state a moment later, through the callbacks,
9//! so a caller that needs confirmation waits for the event rather than for the
10//! return.
11//!
12//! A device that speaks a protocol older than a command requires is refused
13//! with `MXR_ERR_PROTOCOL_TOO_OLD` and nothing is sent, because such a device
14//! discards the frame without answering and a send would report a success that
15//! changed nothing.
16
17use std::ffi::c_char;
18
19use mx_remote::{
20 DeviceUid, EdidProfile, MultiviewerAspectRatio, MultiviewerEdidTemplate, MultiviewerHdcpMode,
21 MultiviewerItcMode, MultiviewerOutputMode, MultiviewerPipPosition, MultiviewerPipSize,
22 MultiviewerSource, MultiviewerViewMode, RcAction, RcKey, V2ipAudioFormat, V2ipColourSpace,
23 V2ipOutputMode, V2ipRoute, V2ipRouteTarget, VideoWallWindow,
24};
25
26use crate::abi::{
27 fail, from_control, mxr_bay_uid_t, mxr_result_t, mxr_tribool_t, mxr_uid_t, opt_str, req_str,
28};
29use crate::info::mxr_amp_zone_settings_t;
30use crate::remote::{mxr_remote_t, with};
31
32/// A stream's sample rate and channel count.
33#[repr(C)]
34#[derive(Clone, Copy)]
35pub struct mxr_audio_format_t {
36 /// Sample rate in Hz.
37 pub sample_rate: u32,
38 /// Channel count.
39 pub channels: u8,
40}
41
42impl From<mxr_audio_format_t> for V2ipAudioFormat {
43 fn from(f: mxr_audio_format_t) -> Self {
44 Self {
45 sample_rate: f.sample_rate,
46 channels: f.channels,
47 }
48 }
49}
50
51// ---- routing ----
52
53/// Routes a V2IP sink's video to the stream a source port advertises.
54///
55/// # Safety
56///
57/// `remote` is null or a live handle from `mxr_remote_new()`.
58#[no_mangle]
59pub unsafe extern "C" fn mxr_select_video_source(
60 remote: *const mxr_remote_t,
61 sink: mxr_bay_uid_t,
62 source_port: u16,
63) -> mxr_result_t {
64 // SAFETY: the caller guarantees a live handle or null.
65 let handle = unsafe { remote.as_ref() };
66 with(handle, |r| {
67 from_control(r.remote.select_video_source(sink.into(), source_port))
68 })
69}
70
71/// Routes a V2IP sink's audio to the stream a source port advertises,
72/// leaving its video where it is.
73///
74/// # Safety
75///
76/// `remote` is null or a live handle from `mxr_remote_new()`.
77#[no_mangle]
78pub unsafe extern "C" fn mxr_select_audio_source(
79 remote: *const mxr_remote_t,
80 sink: mxr_bay_uid_t,
81 source_port: u16,
82) -> mxr_result_t {
83 // SAFETY: the caller guarantees a live handle or null.
84 let handle = unsafe { remote.as_ref() };
85 with(handle, |r| {
86 from_control(r.remote.select_audio_source(sink.into(), source_port))
87 })
88}
89
90/// Routes a V2IP sink's video to the source bay with this user-assigned name.
91///
92/// # Safety
93///
94/// `remote` is null or a live handle, and `name` is a NUL-terminated string.
95#[no_mangle]
96pub unsafe extern "C" fn mxr_select_video_source_by_name(
97 remote: *const mxr_remote_t,
98 sink: mxr_bay_uid_t,
99 name: *const c_char,
100) -> mxr_result_t {
101 // SAFETY: the caller guarantees a live handle or null.
102 let handle = unsafe { remote.as_ref() };
103 with(handle, |r| {
104 // SAFETY: the caller guarantees a NUL-terminated string.
105 match unsafe { req_str(name) } {
106 Ok(name) => from_control(r.remote.select_video_source_by_name(sink.into(), name)),
107 Err(code) => code,
108 }
109 })
110}
111
112/// Routes a V2IP sink's audio to the source bay with this user-assigned name.
113///
114/// `format` may be null to leave the sink's audio format alone.
115///
116/// # Safety
117///
118/// `remote` is null or a live handle, `name` is a NUL-terminated string, and
119/// `format` is null or points at an initialised [`mxr_audio_format_t`].
120#[no_mangle]
121pub unsafe extern "C" fn mxr_select_audio_source_by_name(
122 remote: *const mxr_remote_t,
123 sink: mxr_bay_uid_t,
124 name: *const c_char,
125 format: *const mxr_audio_format_t,
126) -> mxr_result_t {
127 // SAFETY: the caller guarantees a live handle or null.
128 let handle = unsafe { remote.as_ref() };
129 with(handle, |r| {
130 // SAFETY: the caller guarantees a NUL-terminated string.
131 let name = match unsafe { req_str(name) } {
132 Ok(name) => name,
133 Err(code) => return code,
134 };
135 // SAFETY: the caller guarantees an initialised struct or null.
136 let format = unsafe { format.as_ref() }.map(|f| (*f).into());
137 from_control(
138 r.remote
139 .select_audio_source_by_name(sink.into(), name, format),
140 )
141 })
142}
143
144/// Routes a V2IP sink's audio to a multicast group directly, for a source this
145/// client has not heard advertise it.
146///
147/// `audio_port` may be zero for the default, and `format` may be null to leave
148/// the sink's audio format alone.
149///
150/// # Safety
151///
152/// `remote` is null or a live handle, `audio_ip` is a NUL-terminated dotted
153/// quad, and `format` is null or points at an initialised
154/// [`mxr_audio_format_t`].
155#[no_mangle]
156pub unsafe extern "C" fn mxr_select_audio_source_addr(
157 remote: *const mxr_remote_t,
158 sink: mxr_bay_uid_t,
159 audio_ip: *const c_char,
160 audio_port: u16,
161 format: *const mxr_audio_format_t,
162) -> mxr_result_t {
163 // SAFETY: the caller guarantees a live handle or null.
164 let handle = unsafe { remote.as_ref() };
165 with(handle, |r| {
166 // SAFETY: the caller guarantees a NUL-terminated string.
167 let text = match unsafe { req_str(audio_ip) } {
168 Ok(text) => text,
169 Err(code) => return code,
170 };
171 let Ok(ip) = text.parse() else {
172 return fail(
173 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
174 &format!("audio_ip is not an IPv4 address: {text:?}"),
175 );
176 };
177 // SAFETY: the caller guarantees an initialised struct or null.
178 let format = unsafe { format.as_ref() }.map(|f| (*f).into());
179 from_control(r.remote.select_audio_source_addr(
180 sink.into(),
181 ip,
182 // Zero is not a port a stream can arrive on, so it is how the
183 // caller declines to name one.
184 (audio_port != 0).then_some(audio_port),
185 format,
186 ))
187 })
188}
189
190/// One stream of a route the caller assembles.
191#[repr(C)]
192#[derive(Clone, Copy)]
193pub struct mxr_stream_addr_t {
194 /// The multicast group, as a dotted quad. Null or empty sends the slot
195 /// zeroed, naming no group for that stream.
196 ///
197 /// It is not a way to leave one stream alone. The firmware decides
198 /// whether a sink has a manual route at all by reading the video and
199 /// ancillary slots, so an empty one of those disqualifies the whole
200 /// route rather than preserving anything - see
201 /// `mxr_select_source_addr()`.
202 pub ip: *const c_char,
203 /// The destination UDP port. Zero means the standard port for the stream
204 /// this slot names.
205 pub port: u16,
206}
207
208/// The three streams a manual route points a V2IP sink at.
209#[repr(C)]
210#[derive(Clone, Copy)]
211pub struct mxr_v2ip_route_t {
212 /// The video stream, at port 50020 unless the port says otherwise.
213 pub video: mxr_stream_addr_t,
214 /// The audio stream, at port 50022 unless the port says otherwise.
215 pub audio: mxr_stream_addr_t,
216 /// The ancillary-data stream, at port 50021 unless the port says
217 /// otherwise.
218 pub anc: mxr_stream_addr_t,
219}
220
221/// Reads one route slot, where a null or empty address means "not set".
222///
223/// # Safety
224///
225/// `slot.ip` is null or a NUL-terminated string.
226unsafe fn to_target(slot: mxr_stream_addr_t, what: &str) -> Result<V2ipRouteTarget, mxr_result_t> {
227 // SAFETY: the caller guarantees a NUL-terminated string or null.
228 let text = unsafe { opt_str(slot.ip) }?.unwrap_or_default();
229 if text.is_empty() {
230 return Ok(V2ipRouteTarget::default());
231 }
232 match text.parse() {
233 Ok(ip) => Ok(V2ipRouteTarget {
234 ip,
235 port: slot.port,
236 }),
237 Err(_) => Err(fail(
238 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
239 &format!("{what} is not an IPv4 address: {text:?}"),
240 )),
241 }
242}
243
244/// Routes a V2IP sink's video, audio and ancillary streams to multicast groups
245/// the caller names.
246///
247/// This is the only way to reach a stream no device on the mesh advertises,
248/// such as one the calling program is transmitting itself; the routes by
249/// source port and by name can only name a stream some bay has announced.
250///
251/// Set all three groups. The firmware decides whether a sink has a manual
252/// route by looking at the video and ancillary groups, so a route that leaves
253/// either unset does not register as one and the sink falls back to the audio
254/// source its mesh picks.
255///
256/// A null `format` sends 48kHz stereo rather than omitting the field. The
257/// firmware stores whatever the frame carries and hands it to the FPGA
258/// unexamined, so a frame without a format leaves a zero sample rate there,
259/// which the FPGA rejects and which takes the switch down with it.
260///
261/// # Safety
262///
263/// `remote` is null or a live handle, `route` points at an initialised
264/// [`mxr_v2ip_route_t`] whose addresses are null or NUL-terminated strings,
265/// and `format` is null or points at an initialised [`mxr_audio_format_t`].
266#[no_mangle]
267pub unsafe extern "C" fn mxr_select_source_addr(
268 remote: *const mxr_remote_t,
269 sink: mxr_bay_uid_t,
270 route: *const mxr_v2ip_route_t,
271 format: *const mxr_audio_format_t,
272) -> mxr_result_t {
273 // SAFETY: the caller guarantees a live handle or null.
274 let handle = unsafe { remote.as_ref() };
275 with(handle, |r| {
276 // SAFETY: the caller guarantees an initialised struct or null.
277 let Some(route) = (unsafe { route.as_ref() }) else {
278 return fail(
279 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
280 "the route pointer is null",
281 );
282 };
283 // SAFETY: the caller guarantees NUL-terminated strings or null.
284 let route = unsafe {
285 match (
286 to_target(route.video, "video ip"),
287 to_target(route.audio, "audio ip"),
288 to_target(route.anc, "anc ip"),
289 ) {
290 (Ok(video), Ok(audio), Ok(anc)) => V2ipRoute { video, audio, anc },
291 (Err(code), _, _) | (_, Err(code), _) | (_, _, Err(code)) => return code,
292 }
293 };
294 // SAFETY: the caller guarantees an initialised struct or null.
295 let format = unsafe { format.as_ref() }.map(|f| (*f).into());
296 from_control(r.remote.select_source_addr(sink.into(), route, format))
297 })
298}
299
300// ---- bays ----
301
302/// Renames a bay. The device stores the first 16 bytes.
303///
304/// # Safety
305///
306/// `remote` is null or a live handle, and `name` is a NUL-terminated string.
307#[no_mangle]
308pub unsafe extern "C" fn mxr_set_bay_name(
309 remote: *const mxr_remote_t,
310 bay: mxr_bay_uid_t,
311 name: *const c_char,
312) -> mxr_result_t {
313 // SAFETY: the caller guarantees a live handle or null.
314 let handle = unsafe { remote.as_ref() };
315 with(handle, |r| {
316 // SAFETY: the caller guarantees a NUL-terminated string.
317 match unsafe { req_str(name) } {
318 Ok(name) => from_control(r.remote.set_bay_name(bay.into(), name)),
319 Err(code) => code,
320 }
321 })
322}
323
324/// Hides a bay from the installation's user interface, or shows it again.
325///
326/// # Safety
327///
328/// `remote` is null or a live handle from `mxr_remote_new()`.
329#[no_mangle]
330pub unsafe extern "C" fn mxr_set_bay_hidden(
331 remote: *const mxr_remote_t,
332 bay: mxr_bay_uid_t,
333 hidden: bool,
334) -> mxr_result_t {
335 // SAFETY: the caller guarantees a live handle or null.
336 let handle = unsafe { remote.as_ref() };
337 with(handle, |r| {
338 from_control(r.remote.set_bay_hidden(bay.into(), hidden))
339 })
340}
341
342/// Switches an input bay's EDID profile.
343///
344/// # Safety
345///
346/// `remote` is null or a live handle from `mxr_remote_new()`.
347#[no_mangle]
348pub unsafe extern "C" fn mxr_select_edid_profile(
349 remote: *const mxr_remote_t,
350 bay: mxr_bay_uid_t,
351 profile: u16,
352) -> mxr_result_t {
353 // SAFETY: the caller guarantees a live handle or null.
354 let handle = unsafe { remote.as_ref() };
355 with(handle, |r| {
356 from_control(
357 r.remote
358 .select_edid_profile(bay.into(), EdidProfile::from_wire(profile)),
359 )
360 })
361}
362
363/// Sends a remote-control action to whatever is attached to a bay.
364///
365/// # Safety
366///
367/// `remote` is null or a live handle from `mxr_remote_new()`.
368#[no_mangle]
369pub unsafe extern "C" fn mxr_send_action(
370 remote: *const mxr_remote_t,
371 bay: mxr_bay_uid_t,
372 action: u16,
373) -> mxr_result_t {
374 // SAFETY: the caller guarantees a live handle or null.
375 let handle = unsafe { remote.as_ref() };
376 with(handle, |r| {
377 from_control(
378 r.remote
379 .send_action(bay.into(), RcAction::from_wire(action)),
380 )
381 })
382}
383
384/// Sends a remote-control key press to whatever is attached to a bay.
385///
386/// The device forwards it over CEC, infrared or IP, whichever that bay is
387/// configured for; the caller does not choose. `key` is one of the `MXR_KEY_*`
388/// values, or a raw code above `MXR_KEY_CUSTOM_CEC` or `MXR_KEY_CUSTOM_SKY`.
389/// A value this library has no name for is sent as it was given.
390///
391/// `mxr_send_action()` names an outcome instead, and lets the device decide
392/// which keys reach it.
393///
394/// # Safety
395///
396/// `remote` is null or a live handle from `mxr_remote_new()`.
397#[no_mangle]
398pub unsafe extern "C" fn mxr_send_key(
399 remote: *const mxr_remote_t,
400 bay: mxr_bay_uid_t,
401 key: u16,
402) -> mxr_result_t {
403 // SAFETY: the caller guarantees a live handle or null.
404 let handle = unsafe { remote.as_ref() };
405 with(handle, |r| {
406 from_control(r.remote.send_key(bay.into(), RcKey::from_wire(key)))
407 })
408}
409
410/// Powers on what is attached to a bay.
411///
412/// # Safety
413///
414/// `remote` is null or a live handle from `mxr_remote_new()`.
415#[no_mangle]
416pub unsafe extern "C" fn mxr_power_on(
417 remote: *const mxr_remote_t,
418 bay: mxr_bay_uid_t,
419) -> mxr_result_t {
420 // SAFETY: the caller guarantees a live handle or null.
421 let handle = unsafe { remote.as_ref() };
422 with(handle, |r| from_control(r.remote.power_on(bay.into())))
423}
424
425/// Powers off what is attached to a bay.
426///
427/// # Safety
428///
429/// `remote` is null or a live handle from `mxr_remote_new()`.
430#[no_mangle]
431pub unsafe extern "C" fn mxr_power_off(
432 remote: *const mxr_remote_t,
433 bay: mxr_bay_uid_t,
434) -> mxr_result_t {
435 // SAFETY: the caller guarantees a live handle or null.
436 let handle = unsafe { remote.as_ref() };
437 with(handle, |r| from_control(r.remote.power_off(bay.into())))
438}
439
440// ---- volume ----
441
442/// Sets a bay's volume percentage, and its mute state when `muted` is not
443/// `MXR_UNKNOWN`.
444///
445/// A bay with no volume control of its own is set through its `linked_bay`,
446/// so an output wired to an amplifier zone reaches that zone.
447///
448/// # Safety
449///
450/// `remote` is null or a live handle from `mxr_remote_new()`.
451#[no_mangle]
452pub unsafe extern "C" fn mxr_set_volume(
453 remote: *const mxr_remote_t,
454 bay: mxr_bay_uid_t,
455 volume: u8,
456 muted: mxr_tribool_t,
457) -> mxr_result_t {
458 // SAFETY: the caller guarantees a live handle or null.
459 let handle = unsafe { remote.as_ref() };
460 with(handle, |r| {
461 from_control(r.remote.set_volume(
462 bay.into(),
463 volume,
464 match muted {
465 mxr_tribool_t::MXR_UNKNOWN => None,
466 mxr_tribool_t::MXR_FALSE => Some(false),
467 mxr_tribool_t::MXR_TRUE => Some(true),
468 },
469 ))
470 })
471}
472
473/// Asks a bay to step its volume up.
474///
475/// # Safety
476///
477/// `remote` is null or a live handle from `mxr_remote_new()`.
478#[no_mangle]
479pub unsafe extern "C" fn mxr_volume_up(
480 remote: *const mxr_remote_t,
481 bay: mxr_bay_uid_t,
482) -> mxr_result_t {
483 // SAFETY: the caller guarantees a live handle or null.
484 let handle = unsafe { remote.as_ref() };
485 with(handle, |r| from_control(r.remote.volume_up(bay.into())))
486}
487
488/// Asks a bay to step its volume down.
489///
490/// # Safety
491///
492/// `remote` is null or a live handle from `mxr_remote_new()`.
493#[no_mangle]
494pub unsafe extern "C" fn mxr_volume_down(
495 remote: *const mxr_remote_t,
496 bay: mxr_bay_uid_t,
497) -> mxr_result_t {
498 // SAFETY: the caller guarantees a live handle or null.
499 let handle = unsafe { remote.as_ref() };
500 with(handle, |r| from_control(r.remote.volume_down(bay.into())))
501}
502
503/// Mutes or unmutes a bay, leaving its volume alone.
504///
505/// # Safety
506///
507/// `remote` is null or a live handle from `mxr_remote_new()`.
508#[no_mangle]
509pub unsafe extern "C" fn mxr_set_muted(
510 remote: *const mxr_remote_t,
511 bay: mxr_bay_uid_t,
512 muted: bool,
513) -> mxr_result_t {
514 // SAFETY: the caller guarantees a live handle or null.
515 let handle = unsafe { remote.as_ref() };
516 with(handle, |r| {
517 from_control(r.remote.set_muted(bay.into(), muted))
518 })
519}
520
521/// Writes an amplifier zone's gain, delay, tone and power settings.
522///
523/// This replaces every setting at once, so a caller changing one reads the
524/// current set with `mxr_bay_amp_settings()`
525/// first.
526///
527/// # Safety
528///
529/// `remote` is null or a live handle, and `settings` points at an initialised
530/// [`mxr_amp_zone_settings_t`].
531#[no_mangle]
532pub unsafe extern "C" fn mxr_set_amp_zone_settings(
533 remote: *const mxr_remote_t,
534 bay: mxr_bay_uid_t,
535 settings: *const mxr_amp_zone_settings_t,
536) -> mxr_result_t {
537 // SAFETY: the caller guarantees a live handle or null.
538 let handle = unsafe { remote.as_ref() };
539 with(handle, |r| {
540 // SAFETY: the caller guarantees an initialised struct or null.
541 let Some(settings) = (unsafe { settings.as_ref() }) else {
542 return fail(
543 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
544 "the amp zone settings pointer is null",
545 );
546 };
547 from_control(
548 r.remote
549 .set_amp_zone_settings(bay.into(), (*settings).into()),
550 )
551 })
552}
553
554// ---- audio endpoints ----
555
556/// Mutes or unmutes one of a device's audio endpoints.
557///
558/// A loadable module serves this, not the device firmware, and a model may
559/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
560/// sent and not that anything acted on it.
561///
562/// # Safety
563///
564/// `remote` is null or a live handle from `mxr_remote_new()`.
565#[no_mangle]
566pub unsafe extern "C" fn mxr_set_audio_endpoint_muted(
567 remote: *const mxr_remote_t,
568 device: mxr_uid_t,
569 endpoint: u16,
570 muted: bool,
571) -> mxr_result_t {
572 // SAFETY: the caller guarantees a live handle or null.
573 let handle = unsafe { remote.as_ref() };
574 with(handle, |r| {
575 from_control(
576 r.remote
577 .set_audio_endpoint_muted(device.into(), endpoint, muted),
578 )
579 })
580}
581
582/// Activates or clears an audio endpoint's trigger.
583///
584/// A loadable module serves this, not the device firmware, and a model may
585/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
586/// sent and not that anything acted on it.
587///
588/// # Safety
589///
590/// `remote` is null or a live handle from `mxr_remote_new()`.
591#[no_mangle]
592pub unsafe extern "C" fn mxr_set_audio_endpoint_trigger(
593 remote: *const mxr_remote_t,
594 device: mxr_uid_t,
595 endpoint: u16,
596 active: bool,
597) -> mxr_result_t {
598 // SAFETY: the caller guarantees a live handle or null.
599 let handle = unsafe { remote.as_ref() };
600 with(handle, |r| {
601 from_control(
602 r.remote
603 .set_audio_endpoint_trigger(device.into(), endpoint, active),
604 )
605 })
606}
607
608/// Sets an audio endpoint's volume.
609///
610/// A loadable module serves this, not the device firmware, and a model may
611/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
612/// sent and not that anything acted on it.
613///
614/// # Safety
615///
616/// `remote` is null or a live handle from `mxr_remote_new()`.
617#[no_mangle]
618pub unsafe extern "C" fn mxr_set_audio_endpoint_volume(
619 remote: *const mxr_remote_t,
620 device: mxr_uid_t,
621 endpoint: u16,
622 volume: u32,
623) -> mxr_result_t {
624 // SAFETY: the caller guarantees a live handle or null.
625 let handle = unsafe { remote.as_ref() };
626 with(handle, |r| {
627 from_control(
628 r.remote
629 .set_audio_endpoint_volume(device.into(), endpoint, volume),
630 )
631 })
632}
633
634/// Points one device's audio endpoint at another device's.
635///
636/// `sink` is the end doing the listening and `source` the end being
637/// listened to.
638///
639/// A loadable module serves this, not the device firmware, and a model may
640/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
641/// sent and not that anything acted on it.
642///
643/// # Safety
644///
645/// `remote` is null or a live handle from `mxr_remote_new()`.
646#[no_mangle]
647pub unsafe extern "C" fn mxr_select_audio_endpoint_input(
648 remote: *const mxr_remote_t,
649 sink: mxr_uid_t,
650 sink_endpoint: u16,
651 source: mxr_uid_t,
652 source_endpoint: u16,
653) -> mxr_result_t {
654 // SAFETY: the caller guarantees a live handle or null.
655 let handle = unsafe { remote.as_ref() };
656 with(handle, |r| {
657 from_control(r.remote.select_audio_endpoint_input(
658 sink.into(),
659 sink_endpoint,
660 source.into(),
661 source_endpoint,
662 ))
663 })
664}
665
666// ---- devices ----
667
668/// Asks a device for an EDID: the one the display on its output publishes, or
669/// the one the device presents to the source on its input.
670///
671/// The device answers a moment later. The bytes reach `on_edid_received` and
672/// stay readable through `mxr_device_edid()`.
673///
674/// Only V2IP hardware handles this opcode. A matrix or an amplifier accepts
675/// the frame and answers nothing, at any protocol version, so the silence that
676/// follows is permanent rather than a reply still to come. `MXR_OK` here means
677/// the frame was sent, and nothing more; a caller polling for an EDID should
678/// ask a device that can answer rather than wait on one that cannot.
679///
680/// # Safety
681///
682/// `remote` is null or a live handle from `mxr_remote_new()`.
683#[no_mangle]
684pub unsafe extern "C" fn mxr_request_edid(
685 remote: *const mxr_remote_t,
686 device: mxr_uid_t,
687 output: bool,
688) -> mxr_result_t {
689 // SAFETY: the caller guarantees a live handle or null.
690 let handle = unsafe { remote.as_ref() };
691 with(handle, |r| {
692 from_control(r.remote.request_edid(device.into(), output))
693 })
694}
695
696/// Asks for a detailed signal report from every bay of one device, or - with
697/// the zero uid - from every bay on the network.
698///
699/// Devices report on their own when a signal changes, so this is what a client
700/// that has just started needs: without it, a bay that has been showing the
701/// same picture for an hour says nothing until it changes.
702///
703/// # Safety
704///
705/// `remote` is null or a live handle from `mxr_remote_new()`.
706#[no_mangle]
707pub unsafe extern "C" fn mxr_request_signal_status(
708 remote: *const mxr_remote_t,
709 device: mxr_uid_t,
710) -> mxr_result_t {
711 // SAFETY: the caller guarantees a live handle or null.
712 let handle = unsafe { remote.as_ref() };
713 with(handle, |r| {
714 let uid = DeviceUid::from(device);
715 let target = (uid != DeviceUid::ZERO).then_some(uid);
716 from_control(r.remote.request_signal_status(target))
717 })
718}
719
720/// Subscribes to, or unsubscribes from, a device's V2IP statistics.
721///
722/// # Safety
723///
724/// `remote` is null or a live handle from `mxr_remote_new()`.
725#[no_mangle]
726pub unsafe extern "C" fn mxr_subscribe_v2ip_stats(
727 remote: *const mxr_remote_t,
728 device: mxr_uid_t,
729 subscribe: bool,
730) -> mxr_result_t {
731 // SAFETY: the caller guarantees a live handle or null.
732 let handle = unsafe { remote.as_ref() };
733 with(handle, |r| {
734 from_control(r.remote.subscribe_v2ip_stats(device.into(), subscribe))
735 })
736}
737
738/// Reboots a device.
739///
740/// # Safety
741///
742/// `remote` is null or a live handle from `mxr_remote_new()`.
743#[no_mangle]
744pub unsafe extern "C" fn mxr_reboot(
745 remote: *const mxr_remote_t,
746 device: mxr_uid_t,
747) -> mxr_result_t {
748 // SAFETY: the caller guarantees a live handle or null.
749 let handle = unsafe { remote.as_ref() };
750 with(handle, |r| from_control(r.remote.reboot(device.into())))
751}
752
753/// Sends the monitoring pulse that tells devices this client is watching.
754///
755/// # Safety
756///
757/// `remote` is null or a live handle from `mxr_remote_new()`.
758#[no_mangle]
759pub unsafe extern "C" fn mxr_send_monitoring_pulse(remote: *const mxr_remote_t) -> mxr_result_t {
760 // SAFETY: the caller guarantees a live handle or null.
761 let handle = unsafe { remote.as_ref() };
762 with(handle, |r| from_control(r.remote.send_monitoring_pulse()))
763}
764
765// ---- V2IP scaling ----
766
767/// The colour space a V2IP sink scales its output to.
768pub const MXR_V2IP_COLOUR_RGB: u8 = 0;
769/// YCbCr 4:4:4. See `MXR_V2IP_COLOUR_RGB`.
770pub const MXR_V2IP_COLOUR_YCBCR444: u8 = 1;
771/// YCbCr 4:2:2. See `MXR_V2IP_COLOUR_RGB`.
772pub const MXR_V2IP_COLOUR_YCBCR422: u8 = 2;
773/// YCbCr 4:2:0. See `MXR_V2IP_COLOUR_RGB`.
774pub const MXR_V2IP_COLOUR_YCBCR420: u8 = 3;
775
776/// Lowest refresh rate a V2IP output stage accepts, in Hz.
777pub const MXR_V2IP_SCALING_REFRESH_MIN: u16 = 24;
778
779/// Highest refresh rate a V2IP output stage accepts, in Hz.
780pub const MXR_V2IP_SCALING_REFRESH_MAX: u16 = 120;
781
782/// The output format to scale a V2IP sink to.
783///
784/// Given as a depth and a colour space rather than as a packed signal-type
785/// word, so a caller cannot send the "no depth" index a sink reports while it
786/// has none configured - a value a sink decodes cleanly and then drops.
787///
788/// `svd` must name a known video descriptor and may not be zero, `depth` must
789/// be 8, 10 or 12, `colour` one of the `MXR_V2IP_COLOUR_*` values, and
790/// `refresh` between `MXR_V2IP_SCALING_REFRESH_MIN` and
791/// `MXR_V2IP_SCALING_REFRESH_MAX`. Each is checked before anything is sent.
792#[repr(C)]
793#[derive(Clone, Copy)]
794pub struct mxr_v2ip_output_mode_t {
795 /// The CTA-861 short video descriptor to output.
796 pub svd: u8,
797 /// Bit depth: 8, 10 or 12.
798 pub depth: u8,
799 /// One of the `MXR_V2IP_COLOUR_*` values.
800 pub colour: u8,
801 /// Refresh rate in Hz.
802 pub refresh: u16,
803}
804
805impl From<mxr_v2ip_output_mode_t> for V2ipOutputMode {
806 fn from(m: mxr_v2ip_output_mode_t) -> Self {
807 Self {
808 svd: m.svd,
809 depth: m.depth,
810 colour: V2ipColourSpace::from_wire(m.colour),
811 refresh: m.refresh,
812 }
813 }
814}
815
816/// Reads a mode argument, refusing a null pointer.
817unsafe fn output_mode(mode: *const mxr_v2ip_output_mode_t) -> Result<V2ipOutputMode, mxr_result_t> {
818 // SAFETY: the caller guarantees an initialised struct or null.
819 match unsafe { mode.as_ref() } {
820 Some(m) => Ok((*m).into()),
821 None => Err(fail(
822 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
823 "the mode pointer is null",
824 )),
825 }
826}
827
828/// Turns a V2IP sink's automatic scaling on or off.
829///
830/// Automatic scaling and a configured output mode are separate reasons for a
831/// sink to scale, and this moves only the first: a sink with a mode configured
832/// goes on scaling to it with automatic scaling off. Turning both off is this
833/// call plus `mxr_clear_v2ip_output_mode()`.
834///
835/// Nothing acknowledges the frame, so `MXR_OK` means it was sent. Read the sink
836/// back with `mxr_v2ip_details()`, and trust the scaling fields only where the
837/// device reports `MXR_FEATURE_CONFIG_INITIALISED`.
838///
839/// # Safety
840///
841/// `remote` is null or a live handle from `mxr_remote_new()`.
842#[no_mangle]
843pub unsafe extern "C" fn mxr_set_v2ip_auto_scaling(
844 remote: *const mxr_remote_t,
845 device: mxr_uid_t,
846 enabled: bool,
847) -> mxr_result_t {
848 // SAFETY: the caller guarantees a live handle or null.
849 let handle = unsafe { remote.as_ref() };
850 with(handle, |r| {
851 from_control(r.remote.set_v2ip_auto_scaling(device.into(), enabled))
852 })
853}
854
855/// Sets the output format a V2IP sink scales to.
856///
857/// The mode is checked here and `MXR_ERR_INVALID_ARGUMENT` returned without
858/// sending anything, because a sink refuses a bad one in silence. Passing is
859/// not a guarantee: the sink also weighs the format against the attached
860/// display's EDID and against what its own output stage can produce.
861///
862/// **Turn automatic scaling off first if it is on.** A sink silently refuses a
863/// mode the display does not list while it is scaling automatically. Set the
864/// mode, then turn automatic scaling back on if it was on.
865///
866/// # Safety
867///
868/// `remote` is null or a live handle, and `mode` points at an initialised
869/// [`mxr_v2ip_output_mode_t`].
870#[no_mangle]
871pub unsafe extern "C" fn mxr_set_v2ip_output_mode(
872 remote: *const mxr_remote_t,
873 device: mxr_uid_t,
874 mode: *const mxr_v2ip_output_mode_t,
875) -> mxr_result_t {
876 // SAFETY: the caller guarantees a live handle or null.
877 let handle = unsafe { remote.as_ref() };
878 with(handle, |r| {
879 // SAFETY: the caller guarantees an initialised struct or null.
880 match unsafe { output_mode(mode) } {
881 Ok(m) => from_control(r.remote.set_v2ip_output_mode(device.into(), m)),
882 Err(code) => code,
883 }
884 })
885}
886
887/// Clears the output format a V2IP sink is configured to scale to.
888///
889/// The sink stops scaling for that reason and keeps its automatic scaling
890/// setting. This is the only way to express "no mode configured", and it is
891/// what restoring a sink that had none requires: a sink reports no mode by
892/// leaving `MXR_SCALING_FLAG_MODE_VALID` clear, which a write cannot say.
893///
894/// # Safety
895///
896/// `remote` is null or a live handle from `mxr_remote_new()`.
897#[no_mangle]
898pub unsafe extern "C" fn mxr_clear_v2ip_output_mode(
899 remote: *const mxr_remote_t,
900 device: mxr_uid_t,
901) -> mxr_result_t {
902 // SAFETY: the caller guarantees a live handle or null.
903 let handle = unsafe { remote.as_ref() };
904 with(handle, |r| {
905 from_control(r.remote.clear_v2ip_output_mode(device.into()))
906 })
907}
908
909// ---- video wall ----
910
911/// Where a video-wall sink's window sits, and the picture it was measured
912/// against.
913///
914/// `pos_x` must be a multiple of `MXR_VIDEO_WALL_POS_ALIGN`, `width` a
915/// multiple of `MXR_VIDEO_WALL_WIDTH_ALIGN`, both sides at least
916/// `MXR_VIDEO_WALL_MIN_SIZE`, and the window must fit inside the raster it
917/// names. `pos_y` and `height` have no alignment rule. A zero `width` or
918/// `height` clears the wall and is checked against none of this.
919#[repr(C)]
920#[derive(Clone, Copy)]
921pub struct mxr_video_wall_window_t {
922 /// Window origin, horizontal.
923 pub pos_x: u16,
924 /// Window origin, vertical.
925 pub pos_y: u16,
926 /// Window width, or zero to clear the wall.
927 pub width: u16,
928 /// Window height, or zero to clear the wall.
929 pub height: u16,
930 /// Active picture width the window was measured against.
931 pub raster_w: u16,
932 /// Active picture height the window was measured against.
933 pub raster_h: u16,
934}
935
936/// A window's horizontal origin must be a multiple of this.
937pub const MXR_VIDEO_WALL_POS_ALIGN: u16 = 64;
938
939/// A window's width must be a multiple of this.
940pub const MXR_VIDEO_WALL_WIDTH_ALIGN: u16 = 4;
941
942/// Neither side of a window may be smaller than this.
943pub const MXR_VIDEO_WALL_MIN_SIZE: u16 = 64;
944
945impl From<mxr_video_wall_window_t> for VideoWallWindow {
946 fn from(w: mxr_video_wall_window_t) -> Self {
947 Self {
948 pos_x: w.pos_x,
949 pos_y: w.pos_y,
950 width: w.width,
951 height: w.height,
952 raster_w: w.raster_w,
953 raster_h: w.raster_h,
954 }
955 }
956}
957
958/// Reads a window argument, refusing a null pointer.
959unsafe fn wall_window(
960 window: *const mxr_video_wall_window_t,
961) -> Result<VideoWallWindow, mxr_result_t> {
962 // SAFETY: the caller guarantees an initialised struct or null.
963 match unsafe { window.as_ref() } {
964 Some(w) => Ok((*w).into()),
965 None => Err(fail(
966 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
967 "the window pointer is null",
968 )),
969 }
970}
971
972/// Shows a window on a sink's video wall without storing it.
973///
974/// The window lasts until the sink is told otherwise or restarts;
975/// `mxr_revert_video_wall()` puts back whatever it has stored. A zero width or
976/// height shows the whole frame again.
977///
978/// The geometry is checked here and `MXR_ERR_INVALID_ARGUMENT` returned
979/// without sending anything, because the sink is not guaranteed to check it
980/// itself.
981///
982/// A loadable module serves this, not the device firmware, and a model may
983/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
984/// sent and not that anything acted on it.
985///
986/// # Safety
987///
988/// `remote` is null or a live handle, and `window` points at an initialised
989/// [`mxr_video_wall_window_t`].
990#[no_mangle]
991pub unsafe extern "C" fn mxr_preview_video_wall(
992 remote: *const mxr_remote_t,
993 sink: mxr_uid_t,
994 window: *const mxr_video_wall_window_t,
995) -> mxr_result_t {
996 // SAFETY: the caller guarantees a live handle or null.
997 let handle = unsafe { remote.as_ref() };
998 with(handle, |r| {
999 // SAFETY: the caller guarantees an initialised struct or null.
1000 match unsafe { wall_window(window) } {
1001 Ok(w) => from_control(r.remote.preview_video_wall(sink.into(), w)),
1002 Err(code) => code,
1003 }
1004 })
1005}
1006
1007/// Stores a window as a sink's video wall.
1008///
1009/// The geometry is checked here and `MXR_ERR_INVALID_ARGUMENT` returned
1010/// without sending anything. That matters more than a refused frame would: a
1011/// sink running a video-wall module older than 2026083100 writes the window to
1012/// its configuration before asking its video processor to apply it, and the
1013/// processor's refusal does not undo the write, so an out-of-spec window
1014/// survives a reboot and is re-offered on every stream restart until something
1015/// else replaces it. A power cycle does not clear it.
1016///
1017/// A zero width or height stores "show the whole frame".
1018///
1019/// A loadable module serves this, not the device firmware, and a model may
1020/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1021/// sent and not that anything acted on it.
1022///
1023/// # Safety
1024///
1025/// `remote` is null or a live handle, and `window` points at an initialised
1026/// [`mxr_video_wall_window_t`].
1027#[no_mangle]
1028pub unsafe extern "C" fn mxr_store_video_wall(
1029 remote: *const mxr_remote_t,
1030 sink: mxr_uid_t,
1031 window: *const mxr_video_wall_window_t,
1032) -> mxr_result_t {
1033 // SAFETY: the caller guarantees a live handle or null.
1034 let handle = unsafe { remote.as_ref() };
1035 with(handle, |r| {
1036 // SAFETY: the caller guarantees an initialised struct or null.
1037 match unsafe { wall_window(window) } {
1038 Ok(w) => from_control(r.remote.store_video_wall(sink.into(), w)),
1039 Err(code) => code,
1040 }
1041 })
1042}
1043
1044/// Restores the window a sink has stored, discarding a preview.
1045///
1046/// Carries no window: the sink already holds the one this puts back.
1047///
1048/// A loadable module serves this, not the device firmware, and a model may
1049/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1050/// sent and not that anything acted on it.
1051///
1052/// # Safety
1053///
1054/// `remote` is null or a live handle from `mxr_remote_new()`.
1055#[no_mangle]
1056pub unsafe extern "C" fn mxr_revert_video_wall(
1057 remote: *const mxr_remote_t,
1058 sink: mxr_uid_t,
1059) -> mxr_result_t {
1060 // SAFETY: the caller guarantees a live handle or null.
1061 let handle = unsafe { remote.as_ref() };
1062 with(handle, |r| {
1063 from_control(r.remote.revert_video_wall(sink.into()))
1064 })
1065}
1066
1067// ---- multiviewer ----
1068
1069/// Switches a multiviewer's window layout.
1070///
1071/// A loadable module serves this, not the device firmware, and a model may
1072/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1073/// sent and not that anything acted on it.
1074///
1075/// # Safety
1076///
1077/// `remote` is null or a live handle from `mxr_remote_new()`.
1078#[no_mangle]
1079pub unsafe extern "C" fn mxr_set_multiviewer_view_mode(
1080 remote: *const mxr_remote_t,
1081 device: mxr_uid_t,
1082 mode: u8,
1083) -> mxr_result_t {
1084 // SAFETY: the caller guarantees a live handle or null.
1085 let handle = unsafe { remote.as_ref() };
1086 with(handle, |r| {
1087 from_control(
1088 r.remote
1089 .set_multiviewer_view_mode(device.into(), MultiviewerViewMode::from_wire(mode)),
1090 )
1091 })
1092}
1093
1094/// Puts a source in one of a multiviewer's windows.
1095///
1096/// A loadable module serves this, not the device firmware, and a model may
1097/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1098/// sent and not that anything acted on it.
1099///
1100/// # Safety
1101///
1102/// `remote` is null or a live handle from `mxr_remote_new()`.
1103#[no_mangle]
1104pub unsafe extern "C" fn mxr_set_multiviewer_video_source(
1105 remote: *const mxr_remote_t,
1106 device: mxr_uid_t,
1107 screen: u8,
1108 source: u8,
1109) -> mxr_result_t {
1110 // SAFETY: the caller guarantees a live handle or null.
1111 let handle = unsafe { remote.as_ref() };
1112 with(handle, |r| {
1113 from_control(r.remote.set_multiviewer_video_source(
1114 device.into(),
1115 screen,
1116 MultiviewerSource::from_wire(source),
1117 ))
1118 })
1119}
1120
1121/// Chooses which window a multiviewer takes its audio from.
1122///
1123/// A loadable module serves this, not the device firmware, and a model may
1124/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1125/// sent and not that anything acted on it.
1126///
1127/// # Safety
1128///
1129/// `remote` is null or a live handle from `mxr_remote_new()`.
1130#[no_mangle]
1131pub unsafe extern "C" fn mxr_set_multiviewer_audio_source(
1132 remote: *const mxr_remote_t,
1133 device: mxr_uid_t,
1134 source: u8,
1135) -> mxr_result_t {
1136 // SAFETY: the caller guarantees a live handle or null.
1137 let handle = unsafe { remote.as_ref() };
1138 with(handle, |r| {
1139 from_control(
1140 r.remote
1141 .set_multiviewer_audio_source(device.into(), MultiviewerSource::from_wire(source)),
1142 )
1143 })
1144}
1145
1146/// Sets a multiviewer's output volume and mute state.
1147///
1148/// A loadable module serves this, not the device firmware, and a model may
1149/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1150/// sent and not that anything acted on it.
1151///
1152/// # Safety
1153///
1154/// `remote` is null or a live handle from `mxr_remote_new()`.
1155#[no_mangle]
1156pub unsafe extern "C" fn mxr_set_multiviewer_audio_volume(
1157 remote: *const mxr_remote_t,
1158 device: mxr_uid_t,
1159 volume: u8,
1160 muted: bool,
1161) -> mxr_result_t {
1162 // SAFETY: the caller guarantees a live handle or null.
1163 let handle = unsafe { remote.as_ref() };
1164 with(handle, |r| {
1165 from_control(
1166 r.remote
1167 .set_multiviewer_audio_volume(device.into(), volume, muted),
1168 )
1169 })
1170}
1171
1172/// Switches the EDID a multiviewer presents to its sources.
1173///
1174/// A loadable module serves this, not the device firmware, and a model may
1175/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1176/// sent and not that anything acted on it.
1177///
1178/// # Safety
1179///
1180/// `remote` is null or a live handle from `mxr_remote_new()`.
1181#[no_mangle]
1182pub unsafe extern "C" fn mxr_set_multiviewer_edid_template(
1183 remote: *const mxr_remote_t,
1184 device: mxr_uid_t,
1185 template: u8,
1186) -> mxr_result_t {
1187 // SAFETY: the caller guarantees a live handle or null.
1188 let handle = unsafe { remote.as_ref() };
1189 with(handle, |r| {
1190 from_control(r.remote.set_multiviewer_edid_template(
1191 device.into(),
1192 MultiviewerEdidTemplate::from_wire(template),
1193 ))
1194 })
1195}
1196
1197/// Chooses which window a multiviewer forwards remote control to.
1198///
1199/// A loadable module serves this, not the device firmware, and a model may
1200/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1201/// sent and not that anything acted on it.
1202///
1203/// # Safety
1204///
1205/// `remote` is null or a live handle from `mxr_remote_new()`.
1206#[no_mangle]
1207pub unsafe extern "C" fn mxr_set_multiviewer_remote_control(
1208 remote: *const mxr_remote_t,
1209 device: mxr_uid_t,
1210 source: u8,
1211) -> mxr_result_t {
1212 // SAFETY: the caller guarantees a live handle or null.
1213 let handle = unsafe { remote.as_ref() };
1214 with(handle, |r| {
1215 from_control(
1216 r.remote.set_multiviewer_remote_control(
1217 device.into(),
1218 MultiviewerSource::from_wire(source),
1219 ),
1220 )
1221 })
1222}
1223
1224/// Sets the size of a multiviewer's picture-in-picture window.
1225///
1226/// A loadable module serves this, not the device firmware, and a model may
1227/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1228/// sent and not that anything acted on it.
1229///
1230/// # Safety
1231///
1232/// `remote` is null or a live handle from `mxr_remote_new()`.
1233#[no_mangle]
1234pub unsafe extern "C" fn mxr_set_multiviewer_pip_size(
1235 remote: *const mxr_remote_t,
1236 device: mxr_uid_t,
1237 size: u8,
1238) -> mxr_result_t {
1239 // SAFETY: the caller guarantees a live handle or null.
1240 let handle = unsafe { remote.as_ref() };
1241 with(handle, |r| {
1242 from_control(
1243 r.remote
1244 .set_multiviewer_pip_size(device.into(), MultiviewerPipSize::from_wire(size)),
1245 )
1246 })
1247}
1248
1249/// Sets which corner a multiviewer's picture-in-picture window sits in.
1250///
1251/// A loadable module serves this, not the device firmware, and a model may
1252/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1253/// sent and not that anything acted on it.
1254///
1255/// # Safety
1256///
1257/// `remote` is null or a live handle from `mxr_remote_new()`.
1258#[no_mangle]
1259pub unsafe extern "C" fn mxr_set_multiviewer_pip_position(
1260 remote: *const mxr_remote_t,
1261 device: mxr_uid_t,
1262 position: u8,
1263) -> mxr_result_t {
1264 // SAFETY: the caller guarantees a live handle or null.
1265 let handle = unsafe { remote.as_ref() };
1266 with(handle, |r| {
1267 from_control(r.remote.set_multiviewer_pip_position(
1268 device.into(),
1269 MultiviewerPipPosition::from_wire(position),
1270 ))
1271 })
1272}
1273
1274/// Sets how a multiviewer fits a source into its window.
1275///
1276/// A loadable module serves this, not the device firmware, and a model may
1277/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1278/// sent and not that anything acted on it.
1279///
1280/// # Safety
1281///
1282/// `remote` is null or a live handle from `mxr_remote_new()`.
1283#[no_mangle]
1284pub unsafe extern "C" fn mxr_set_multiviewer_aspect_ratio(
1285 remote: *const mxr_remote_t,
1286 device: mxr_uid_t,
1287 aspect: u8,
1288) -> mxr_result_t {
1289 // SAFETY: the caller guarantees a live handle or null.
1290 let handle = unsafe { remote.as_ref() };
1291 with(handle, |r| {
1292 from_control(
1293 r.remote.set_multiviewer_aspect_ratio(
1294 device.into(),
1295 MultiviewerAspectRatio::from_wire(aspect),
1296 ),
1297 )
1298 })
1299}
1300
1301/// Turns a multiviewer's automatic source switching on or off.
1302///
1303/// A loadable module serves this, not the device firmware, and a model may
1304/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1305/// sent and not that anything acted on it.
1306///
1307/// # Safety
1308///
1309/// `remote` is null or a live handle from `mxr_remote_new()`.
1310#[no_mangle]
1311pub unsafe extern "C" fn mxr_set_multiviewer_auto_switch(
1312 remote: *const mxr_remote_t,
1313 device: mxr_uid_t,
1314 enable: bool,
1315) -> mxr_result_t {
1316 // SAFETY: the caller guarantees a live handle or null.
1317 let handle = unsafe { remote.as_ref() };
1318 with(handle, |r| {
1319 from_control(r.remote.set_multiviewer_auto_switch(device.into(), enable))
1320 })
1321}
1322
1323/// Switches a multiviewer's output resolution.
1324///
1325/// A loadable module serves this, not the device firmware, and a model may
1326/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1327/// sent and not that anything acted on it.
1328///
1329/// # Safety
1330///
1331/// `remote` is null or a live handle from `mxr_remote_new()`.
1332#[no_mangle]
1333pub unsafe extern "C" fn mxr_set_multiviewer_output_mode(
1334 remote: *const mxr_remote_t,
1335 device: mxr_uid_t,
1336 mode: u8,
1337) -> mxr_result_t {
1338 // SAFETY: the caller guarantees a live handle or null.
1339 let handle = unsafe { remote.as_ref() };
1340 with(handle, |r| {
1341 from_control(
1342 r.remote
1343 .set_multiviewer_output_mode(device.into(), MultiviewerOutputMode::from_wire(mode)),
1344 )
1345 })
1346}
1347
1348/// Sets a multiviewer's IT content flag.
1349///
1350/// A loadable module serves this, not the device firmware, and a model may
1351/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1352/// sent and not that anything acted on it.
1353///
1354/// # Safety
1355///
1356/// `remote` is null or a live handle from `mxr_remote_new()`.
1357#[no_mangle]
1358pub unsafe extern "C" fn mxr_set_multiviewer_output_itc(
1359 remote: *const mxr_remote_t,
1360 device: mxr_uid_t,
1361 mode: u8,
1362) -> mxr_result_t {
1363 // SAFETY: the caller guarantees a live handle or null.
1364 let handle = unsafe { remote.as_ref() };
1365 with(handle, |r| {
1366 from_control(
1367 r.remote
1368 .set_multiviewer_output_itc(device.into(), MultiviewerItcMode::from_wire(mode)),
1369 )
1370 })
1371}
1372
1373/// Switches a multiviewer's HDCP mode.
1374///
1375/// A loadable module serves this, not the device firmware, and a model may
1376/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1377/// sent and not that anything acted on it.
1378///
1379/// # Safety
1380///
1381/// `remote` is null or a live handle from `mxr_remote_new()`.
1382#[no_mangle]
1383pub unsafe extern "C" fn mxr_set_multiviewer_hdcp_mode(
1384 remote: *const mxr_remote_t,
1385 device: mxr_uid_t,
1386 mode: u8,
1387) -> mxr_result_t {
1388 // SAFETY: the caller guarantees a live handle or null.
1389 let handle = unsafe { remote.as_ref() };
1390 with(handle, |r| {
1391 from_control(
1392 r.remote
1393 .set_multiviewer_hdcp_mode(device.into(), MultiviewerHdcpMode::from_wire(mode)),
1394 )
1395 })
1396}
1397
1398/// Maps one of a multiviewer's inputs to a source device.
1399///
1400/// A loadable module serves this, not the device firmware, and a model may
1401/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1402/// sent and not that anything acted on it.
1403///
1404/// # Safety
1405///
1406/// `remote` is null or a live handle from `mxr_remote_new()`.
1407#[no_mangle]
1408pub unsafe extern "C" fn mxr_set_multiviewer_input_source(
1409 remote: *const mxr_remote_t,
1410 device: mxr_uid_t,
1411 input: u8,
1412 source: mxr_uid_t,
1413) -> mxr_result_t {
1414 // SAFETY: the caller guarantees a live handle or null.
1415 let handle = unsafe { remote.as_ref() };
1416 with(handle, |r| {
1417 from_control(
1418 r.remote
1419 .set_multiviewer_input_source(device.into(), input, source.into()),
1420 )
1421 })
1422}
1423
1424/// Asks a multiviewer to map its inputs to the sources it can see.
1425///
1426/// A loadable module serves this, not the device firmware, and a model may
1427/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1428/// sent and not that anything acted on it.
1429///
1430/// # Safety
1431///
1432/// `remote` is null or a live handle from `mxr_remote_new()`.
1433#[no_mangle]
1434pub unsafe extern "C" fn mxr_multiviewer_auto_route(
1435 remote: *const mxr_remote_t,
1436 device: mxr_uid_t,
1437) -> mxr_result_t {
1438 // SAFETY: the caller guarantees a live handle or null.
1439 let handle = unsafe { remote.as_ref() };
1440 with(handle, |r| {
1441 from_control(r.remote.multiviewer_auto_route(device.into()))
1442 })
1443}