Skip to content

Commit a6c3651

Browse files
authored
feat(server): add volume support (#641)
Add server messages and API to support setting client volume. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 0f9877a commit a6c3651

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

crates/ironrdp-rdpsnd/src/server.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ impl<T> RdpsndError for T where T: std::error::Error + Send + Sync + 'static {}
1717
pub enum RdpsndServerMessage {
1818
/// Wave data, with timestamp
1919
Wave(Vec<u8>, u32),
20+
SetVolume {
21+
left: u16,
22+
right: u16,
23+
},
2024
Close,
2125
/// Failure received from the OS event loop.
2226
///
@@ -70,11 +74,20 @@ impl RdpsndServer {
7074
let client_format = self
7175
.client_format
7276
.as_ref()
73-
.ok_or_else(|| pdu_other_err!("invalid state - no version"))?;
77+
.ok_or_else(|| pdu_other_err!("invalid state, client format not yet received"))?;
7478

7579
Ok(client_format.version)
7680
}
7781

82+
pub fn flags(&self) -> PduResult<pdu::AudioFormatFlags> {
83+
let client_format = self
84+
.client_format
85+
.as_ref()
86+
.ok_or_else(|| pdu_other_err!("invalid state, client format not yet received"))?;
87+
88+
Ok(client_format.flags)
89+
}
90+
7891
pub fn training_pdu(&mut self) -> PduResult<RdpsndSvcMessages> {
7992
let pdu = pdu::TrainingPdu {
8093
timestamp: 4231, // a random number
@@ -116,6 +129,19 @@ impl RdpsndServer {
116129
Ok(msg)
117130
}
118131

132+
pub fn set_volume(&mut self, volume_left: u16, volume_right: u16) -> PduResult<RdpsndSvcMessages> {
133+
if !self.flags()?.contains(pdu::AudioFormatFlags::VOLUME) {
134+
return Err(pdu_other_err!("client doesn't support volume"));
135+
}
136+
let pdu = pdu::VolumePdu {
137+
volume_left,
138+
volume_right,
139+
};
140+
Ok(RdpsndSvcMessages::new(vec![
141+
pdu::ServerAudioOutputPdu::Volume(pdu).into()
142+
]))
143+
}
144+
119145
pub fn close(&mut self) -> PduResult<RdpsndSvcMessages> {
120146
Ok(RdpsndSvcMessages::new(vec![pdu::ServerAudioOutputPdu::Close.into()]))
121147
}

crates/ironrdp-server/src/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ impl RdpServer {
496496
wave_limit -= 1;
497497
rdpsnd.wave(data, ts)
498498
}
499+
RdpsndServerMessage::SetVolume { left, right } => rdpsnd.set_volume(left, right),
499500
RdpsndServerMessage::Close => rdpsnd.close(),
500501
RdpsndServerMessage::Error(error) => {
501502
error!(?error, "Handling rdpsnd event");

0 commit comments

Comments
 (0)