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/// **Read any route you still need before writing.** The sink rebuilds and
840/// rebroadcasts its subscription in response, and the addresses in
841/// `mxr_v2ip_details()` can read as zero for up to a minute afterwards.
842///
843/// # Safety
844///
845/// `remote` is null or a live handle from `mxr_remote_new()`.
846#[no_mangle]
847pub unsafe extern "C" fn mxr_set_v2ip_auto_scaling(
848 remote: *const mxr_remote_t,
849 device: mxr_uid_t,
850 enabled: bool,
851) -> mxr_result_t {
852 // SAFETY: the caller guarantees a live handle or null.
853 let handle = unsafe { remote.as_ref() };
854 with(handle, |r| {
855 from_control(r.remote.set_v2ip_auto_scaling(device.into(), enabled))
856 })
857}
858
859/// Sets the output format a V2IP sink scales to.
860///
861/// The mode is checked here and `MXR_ERR_INVALID_ARGUMENT` returned without
862/// sending anything, because a sink refuses a bad one in silence. Passing is
863/// not a guarantee: the sink also weighs the format against the attached
864/// display's EDID and against what its own output stage can produce.
865///
866/// **Turn automatic scaling off first if it is on.** A sink silently refuses a
867/// mode the display does not list while it is scaling automatically. Set the
868/// mode, then turn automatic scaling back on if it was on.
869///
870/// **Pass an `svd` and a `refresh` that agree.** A sink stores both halves and,
871/// with its match-source setting on as it ships, reports back the SVD matching
872/// the refresh it holds: a 60Hz SVD written with a refresh of 50 reads back as
873/// that SVD's 50Hz sibling, once, and stays there. A sink with match-source off
874/// reports the SVD it was given. Either way a pair that agrees reads back
875/// unchanged and the format driven is the same, and the substitution appears on
876/// the sink's next report rather than in the next `mxr_v2ip_details()`.
877///
878/// A mode read from the sink's own web interface is not interchangeable with
879/// this pair. That interface reports the SVD's 60Hz sibling and carries the
880/// refresh in a field of its own, so writing back what it shows as the mode, on
881/// its own, changes the setting rather than restoring it.
882///
883/// **Read any route you still need before writing.** The sink rebuilds and
884/// rebroadcasts its subscription in response, and the addresses in
885/// `mxr_v2ip_details()` can read as zero for up to a minute afterwards.
886///
887/// # Safety
888///
889/// `remote` is null or a live handle, and `mode` points at an initialised
890/// [`mxr_v2ip_output_mode_t`].
891#[no_mangle]
892pub unsafe extern "C" fn mxr_set_v2ip_output_mode(
893 remote: *const mxr_remote_t,
894 device: mxr_uid_t,
895 mode: *const mxr_v2ip_output_mode_t,
896) -> mxr_result_t {
897 // SAFETY: the caller guarantees a live handle or null.
898 let handle = unsafe { remote.as_ref() };
899 with(handle, |r| {
900 // SAFETY: the caller guarantees an initialised struct or null.
901 match unsafe { output_mode(mode) } {
902 Ok(m) => from_control(r.remote.set_v2ip_output_mode(device.into(), m)),
903 Err(code) => code,
904 }
905 })
906}
907
908/// Clears the output format a V2IP sink is configured to scale to.
909///
910/// The sink stops scaling for that reason and keeps its automatic scaling
911/// setting. This is the only way to express "no mode configured", and it is
912/// what restoring a sink that had none requires: a sink reports no mode by
913/// leaving `MXR_SCALING_FLAG_MODE_VALID` clear, which a write cannot say.
914///
915/// **Read any route you still need before writing.** The sink rebuilds and
916/// rebroadcasts its subscription in response, and the addresses in
917/// `mxr_v2ip_details()` can read as zero for up to a minute afterwards.
918///
919/// # Safety
920///
921/// `remote` is null or a live handle from `mxr_remote_new()`.
922#[no_mangle]
923pub unsafe extern "C" fn mxr_clear_v2ip_output_mode(
924 remote: *const mxr_remote_t,
925 device: mxr_uid_t,
926) -> mxr_result_t {
927 // SAFETY: the caller guarantees a live handle or null.
928 let handle = unsafe { remote.as_ref() };
929 with(handle, |r| {
930 from_control(r.remote.clear_v2ip_output_mode(device.into()))
931 })
932}
933
934// ---- video wall ----
935
936/// Where a video-wall sink's window sits, and the picture it was measured
937/// against.
938///
939/// `pos_x` must be a multiple of `MXR_VIDEO_WALL_POS_ALIGN`, `width` a
940/// multiple of `MXR_VIDEO_WALL_WIDTH_ALIGN`, both sides at least
941/// `MXR_VIDEO_WALL_MIN_SIZE`, and the window must fit inside the raster it
942/// names. `pos_y` and `height` have no alignment rule. A zero `width` or
943/// `height` clears the wall and is checked against none of this.
944#[repr(C)]
945#[derive(Clone, Copy)]
946pub struct mxr_video_wall_window_t {
947 /// Window origin, horizontal.
948 pub pos_x: u16,
949 /// Window origin, vertical.
950 pub pos_y: u16,
951 /// Window width, or zero to clear the wall.
952 pub width: u16,
953 /// Window height, or zero to clear the wall.
954 pub height: u16,
955 /// Active picture width the window was measured against.
956 pub raster_w: u16,
957 /// Active picture height the window was measured against.
958 pub raster_h: u16,
959}
960
961/// A window's horizontal origin must be a multiple of this.
962pub const MXR_VIDEO_WALL_POS_ALIGN: u16 = 64;
963
964/// A window's width must be a multiple of this.
965pub const MXR_VIDEO_WALL_WIDTH_ALIGN: u16 = 4;
966
967/// Neither side of a window may be smaller than this.
968pub const MXR_VIDEO_WALL_MIN_SIZE: u16 = 64;
969
970impl From<mxr_video_wall_window_t> for VideoWallWindow {
971 fn from(w: mxr_video_wall_window_t) -> Self {
972 Self {
973 pos_x: w.pos_x,
974 pos_y: w.pos_y,
975 width: w.width,
976 height: w.height,
977 raster_w: w.raster_w,
978 raster_h: w.raster_h,
979 }
980 }
981}
982
983/// Reads a window argument, refusing a null pointer.
984unsafe fn wall_window(
985 window: *const mxr_video_wall_window_t,
986) -> Result<VideoWallWindow, mxr_result_t> {
987 // SAFETY: the caller guarantees an initialised struct or null.
988 match unsafe { window.as_ref() } {
989 Some(w) => Ok((*w).into()),
990 None => Err(fail(
991 mxr_result_t::MXR_ERR_INVALID_ARGUMENT,
992 "the window pointer is null",
993 )),
994 }
995}
996
997/// Shows a window on a sink's video wall without storing it.
998///
999/// The window lasts until the sink is told otherwise or restarts;
1000/// `mxr_revert_video_wall()` puts back whatever it has stored. A zero width or
1001/// height shows the whole frame again.
1002///
1003/// The geometry is checked here and `MXR_ERR_INVALID_ARGUMENT` returned
1004/// without sending anything, because the sink is not guaranteed to check it
1005/// itself.
1006///
1007/// A loadable module serves this, not the device firmware, and a model may
1008/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1009/// sent and not that anything acted on it.
1010///
1011/// # Safety
1012///
1013/// `remote` is null or a live handle, and `window` points at an initialised
1014/// [`mxr_video_wall_window_t`].
1015#[no_mangle]
1016pub unsafe extern "C" fn mxr_preview_video_wall(
1017 remote: *const mxr_remote_t,
1018 sink: mxr_uid_t,
1019 window: *const mxr_video_wall_window_t,
1020) -> mxr_result_t {
1021 // SAFETY: the caller guarantees a live handle or null.
1022 let handle = unsafe { remote.as_ref() };
1023 with(handle, |r| {
1024 // SAFETY: the caller guarantees an initialised struct or null.
1025 match unsafe { wall_window(window) } {
1026 Ok(w) => from_control(r.remote.preview_video_wall(sink.into(), w)),
1027 Err(code) => code,
1028 }
1029 })
1030}
1031
1032/// Stores a window as a sink's video wall.
1033///
1034/// The geometry is checked here and `MXR_ERR_INVALID_ARGUMENT` returned
1035/// without sending anything. That matters more than a refused frame would: a
1036/// sink running a video-wall module older than 2026083100 writes the window to
1037/// its configuration before asking its video processor to apply it, and the
1038/// processor's refusal does not undo the write, so an out-of-spec window
1039/// survives a reboot and is re-offered on every stream restart until something
1040/// else replaces it. A power cycle does not clear it.
1041///
1042/// A zero width or height stores "show the whole frame".
1043///
1044/// A loadable module serves this, not the device firmware, and a model may
1045/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1046/// sent and not that anything acted on it.
1047///
1048/// # Safety
1049///
1050/// `remote` is null or a live handle, and `window` points at an initialised
1051/// [`mxr_video_wall_window_t`].
1052#[no_mangle]
1053pub unsafe extern "C" fn mxr_store_video_wall(
1054 remote: *const mxr_remote_t,
1055 sink: mxr_uid_t,
1056 window: *const mxr_video_wall_window_t,
1057) -> mxr_result_t {
1058 // SAFETY: the caller guarantees a live handle or null.
1059 let handle = unsafe { remote.as_ref() };
1060 with(handle, |r| {
1061 // SAFETY: the caller guarantees an initialised struct or null.
1062 match unsafe { wall_window(window) } {
1063 Ok(w) => from_control(r.remote.store_video_wall(sink.into(), w)),
1064 Err(code) => code,
1065 }
1066 })
1067}
1068
1069/// Restores the window a sink has stored, discarding a preview.
1070///
1071/// Carries no window: the sink already holds the one this puts back.
1072///
1073/// A loadable module serves this, not the device firmware, and a model may
1074/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1075/// sent and not that anything acted on it.
1076///
1077/// # Safety
1078///
1079/// `remote` is null or a live handle from `mxr_remote_new()`.
1080#[no_mangle]
1081pub unsafe extern "C" fn mxr_revert_video_wall(
1082 remote: *const mxr_remote_t,
1083 sink: mxr_uid_t,
1084) -> mxr_result_t {
1085 // SAFETY: the caller guarantees a live handle or null.
1086 let handle = unsafe { remote.as_ref() };
1087 with(handle, |r| {
1088 from_control(r.remote.revert_video_wall(sink.into()))
1089 })
1090}
1091
1092// ---- multiviewer ----
1093
1094/// Switches a multiviewer's window layout.
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_view_mode(
1105 remote: *const mxr_remote_t,
1106 device: mxr_uid_t,
1107 mode: u8,
1108) -> mxr_result_t {
1109 // SAFETY: the caller guarantees a live handle or null.
1110 let handle = unsafe { remote.as_ref() };
1111 with(handle, |r| {
1112 from_control(
1113 r.remote
1114 .set_multiviewer_view_mode(device.into(), MultiviewerViewMode::from_wire(mode)),
1115 )
1116 })
1117}
1118
1119/// Puts a source in one of a multiviewer's windows.
1120///
1121/// A loadable module serves this, not the device firmware, and a model may
1122/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1123/// sent and not that anything acted on it.
1124///
1125/// # Safety
1126///
1127/// `remote` is null or a live handle from `mxr_remote_new()`.
1128#[no_mangle]
1129pub unsafe extern "C" fn mxr_set_multiviewer_video_source(
1130 remote: *const mxr_remote_t,
1131 device: mxr_uid_t,
1132 screen: u8,
1133 source: u8,
1134) -> mxr_result_t {
1135 // SAFETY: the caller guarantees a live handle or null.
1136 let handle = unsafe { remote.as_ref() };
1137 with(handle, |r| {
1138 from_control(r.remote.set_multiviewer_video_source(
1139 device.into(),
1140 screen,
1141 MultiviewerSource::from_wire(source),
1142 ))
1143 })
1144}
1145
1146/// Chooses which window a multiviewer takes its audio from.
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_source(
1157 remote: *const mxr_remote_t,
1158 device: mxr_uid_t,
1159 source: u8,
1160) -> mxr_result_t {
1161 // SAFETY: the caller guarantees a live handle or null.
1162 let handle = unsafe { remote.as_ref() };
1163 with(handle, |r| {
1164 from_control(
1165 r.remote
1166 .set_multiviewer_audio_source(device.into(), MultiviewerSource::from_wire(source)),
1167 )
1168 })
1169}
1170
1171/// Sets a multiviewer's output volume and mute state.
1172///
1173/// A loadable module serves this, not the device firmware, and a model may
1174/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1175/// sent and not that anything acted on it.
1176///
1177/// # Safety
1178///
1179/// `remote` is null or a live handle from `mxr_remote_new()`.
1180#[no_mangle]
1181pub unsafe extern "C" fn mxr_set_multiviewer_audio_volume(
1182 remote: *const mxr_remote_t,
1183 device: mxr_uid_t,
1184 volume: u8,
1185 muted: bool,
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(
1191 r.remote
1192 .set_multiviewer_audio_volume(device.into(), volume, muted),
1193 )
1194 })
1195}
1196
1197/// Switches the EDID a multiviewer presents to its sources.
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_edid_template(
1208 remote: *const mxr_remote_t,
1209 device: mxr_uid_t,
1210 template: 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(r.remote.set_multiviewer_edid_template(
1216 device.into(),
1217 MultiviewerEdidTemplate::from_wire(template),
1218 ))
1219 })
1220}
1221
1222/// Chooses which window a multiviewer forwards remote control to.
1223///
1224/// A loadable module serves this, not the device firmware, and a model may
1225/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1226/// sent and not that anything acted on it.
1227///
1228/// # Safety
1229///
1230/// `remote` is null or a live handle from `mxr_remote_new()`.
1231#[no_mangle]
1232pub unsafe extern "C" fn mxr_set_multiviewer_remote_control(
1233 remote: *const mxr_remote_t,
1234 device: mxr_uid_t,
1235 source: u8,
1236) -> mxr_result_t {
1237 // SAFETY: the caller guarantees a live handle or null.
1238 let handle = unsafe { remote.as_ref() };
1239 with(handle, |r| {
1240 from_control(
1241 r.remote.set_multiviewer_remote_control(
1242 device.into(),
1243 MultiviewerSource::from_wire(source),
1244 ),
1245 )
1246 })
1247}
1248
1249/// Sets the size of a multiviewer's picture-in-picture window.
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_size(
1260 remote: *const mxr_remote_t,
1261 device: mxr_uid_t,
1262 size: 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(
1268 r.remote
1269 .set_multiviewer_pip_size(device.into(), MultiviewerPipSize::from_wire(size)),
1270 )
1271 })
1272}
1273
1274/// Sets which corner a multiviewer's picture-in-picture window sits in.
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_pip_position(
1285 remote: *const mxr_remote_t,
1286 device: mxr_uid_t,
1287 position: 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(r.remote.set_multiviewer_pip_position(
1293 device.into(),
1294 MultiviewerPipPosition::from_wire(position),
1295 ))
1296 })
1297}
1298
1299/// Sets how a multiviewer fits a source into its window.
1300///
1301/// A loadable module serves this, not the device firmware, and a model may
1302/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1303/// sent and not that anything acted on it.
1304///
1305/// # Safety
1306///
1307/// `remote` is null or a live handle from `mxr_remote_new()`.
1308#[no_mangle]
1309pub unsafe extern "C" fn mxr_set_multiviewer_aspect_ratio(
1310 remote: *const mxr_remote_t,
1311 device: mxr_uid_t,
1312 aspect: u8,
1313) -> mxr_result_t {
1314 // SAFETY: the caller guarantees a live handle or null.
1315 let handle = unsafe { remote.as_ref() };
1316 with(handle, |r| {
1317 from_control(
1318 r.remote.set_multiviewer_aspect_ratio(
1319 device.into(),
1320 MultiviewerAspectRatio::from_wire(aspect),
1321 ),
1322 )
1323 })
1324}
1325
1326/// Turns a multiviewer's automatic source switching on or off.
1327///
1328/// A loadable module serves this, not the device firmware, and a model may
1329/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1330/// sent and not that anything acted on it.
1331///
1332/// # Safety
1333///
1334/// `remote` is null or a live handle from `mxr_remote_new()`.
1335#[no_mangle]
1336pub unsafe extern "C" fn mxr_set_multiviewer_auto_switch(
1337 remote: *const mxr_remote_t,
1338 device: mxr_uid_t,
1339 enable: bool,
1340) -> mxr_result_t {
1341 // SAFETY: the caller guarantees a live handle or null.
1342 let handle = unsafe { remote.as_ref() };
1343 with(handle, |r| {
1344 from_control(r.remote.set_multiviewer_auto_switch(device.into(), enable))
1345 })
1346}
1347
1348/// Switches a multiviewer's output resolution.
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_mode(
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_mode(device.into(), MultiviewerOutputMode::from_wire(mode)),
1369 )
1370 })
1371}
1372
1373/// Sets a multiviewer's IT content flag.
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_output_itc(
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_output_itc(device.into(), MultiviewerItcMode::from_wire(mode)),
1394 )
1395 })
1396}
1397
1398/// Switches a multiviewer's HDCP mode.
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_hdcp_mode(
1409 remote: *const mxr_remote_t,
1410 device: mxr_uid_t,
1411 mode: u8,
1412) -> mxr_result_t {
1413 // SAFETY: the caller guarantees a live handle or null.
1414 let handle = unsafe { remote.as_ref() };
1415 with(handle, |r| {
1416 from_control(
1417 r.remote
1418 .set_multiviewer_hdcp_mode(device.into(), MultiviewerHdcpMode::from_wire(mode)),
1419 )
1420 })
1421}
1422
1423/// Maps one of a multiviewer's inputs to a source device.
1424///
1425/// A loadable module serves this, not the device firmware, and a model may
1426/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1427/// sent and not that anything acted on it.
1428///
1429/// # Safety
1430///
1431/// `remote` is null or a live handle from `mxr_remote_new()`.
1432#[no_mangle]
1433pub unsafe extern "C" fn mxr_set_multiviewer_input_source(
1434 remote: *const mxr_remote_t,
1435 device: mxr_uid_t,
1436 input: u8,
1437 source: mxr_uid_t,
1438) -> mxr_result_t {
1439 // SAFETY: the caller guarantees a live handle or null.
1440 let handle = unsafe { remote.as_ref() };
1441 with(handle, |r| {
1442 from_control(
1443 r.remote
1444 .set_multiviewer_input_source(device.into(), input, source.into()),
1445 )
1446 })
1447}
1448
1449/// Asks a multiviewer to map its inputs to the sources it can see.
1450///
1451/// A loadable module serves this, not the device firmware, and a model may
1452/// not have it. Nothing answers either way, so `MXR_OK` means the frame was
1453/// sent and not that anything acted on it.
1454///
1455/// # Safety
1456///
1457/// `remote` is null or a live handle from `mxr_remote_new()`.
1458#[no_mangle]
1459pub unsafe extern "C" fn mxr_multiviewer_auto_route(
1460 remote: *const mxr_remote_t,
1461 device: mxr_uid_t,
1462) -> mxr_result_t {
1463 // SAFETY: the caller guarantees a live handle or null.
1464 let handle = unsafe { remote.as_ref() };
1465 with(handle, |r| {
1466 from_control(r.remote.multiviewer_auto_route(device.into()))
1467 })
1468}