use std::net::Ipv4Addr;
use crate::event::Event;
use crate::state::State;
use crate::types::V2ipSinkSdp;
use crate::wire::{
cstr, V2ipSdpClockMode, V2ipSdpClockState, V2ipSdpEncoding, V2ipSdpFlag, V2ipSdpMediaClock,
V2ipSdpRefClock, UID_LEN,
};
use super::handlers::{u16_at, u32_at};
use super::Rx;
const SDP_HEADER_SIZE: usize = UID_LEN + 4;
const SDP_STATUS: u8 = 0;
const SDP_STATUS_SIZE: usize = 80;
pub(super) fn sink_sdp(state: &mut State, rx: &Rx<'_>, ev: &mut Vec<Event>) {
let p = rx.frame.payload();
if p.len() < SDP_HEADER_SIZE || p[UID_LEN] != SDP_STATUS {
return;
}
let mut s = p[SDP_HEADER_SIZE..].to_vec();
s.resize(s.len().max(SDP_STATUS_SIZE), 0);
let status = V2ipSinkSdp {
flags: V2ipSdpFlag::from_bits(s[0]),
screen: s[1],
encoding: V2ipSdpEncoding::from_wire(s[2]),
channels: s[3],
payload_type: s[4],
media_clock: V2ipSdpMediaClock::from_wire(s[5]),
ref_clock: V2ipSdpRefClock::from_wire(s[6]),
clock_mode: V2ipSdpClockMode::from_wire(s[7]),
clock_state: V2ipSdpClockState::from_wire(s[8]),
port: u16_at(&s, 10),
rate_hz: u32_at(&s, 12),
media_clock_offset: u32_at(&s, 16),
group: Ipv4Addr::new(s[20], s[21], s[22], s[23]),
name: cstr(&s[24..71]),
layout: cstr(&s[72..79]),
};
if let Some(device) = state.device_mut(rx.sender()) {
device.set_v2ip_sink_sdp(status, ev);
}
}