@@ -17,6 +17,10 @@ impl<T> RdpsndError for T where T: std::error::Error + Send + Sync + 'static {}
17
17
pub enum RdpsndServerMessage {
18
18
/// Wave data, with timestamp
19
19
Wave ( Vec < u8 > , u32 ) ,
20
+ SetVolume {
21
+ left : u16 ,
22
+ right : u16 ,
23
+ } ,
20
24
Close ,
21
25
/// Failure received from the OS event loop.
22
26
///
@@ -70,11 +74,20 @@ impl RdpsndServer {
70
74
let client_format = self
71
75
. client_format
72
76
. 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 " ) ) ?;
74
78
75
79
Ok ( client_format. version )
76
80
}
77
81
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
+
78
91
pub fn training_pdu ( & mut self ) -> PduResult < RdpsndSvcMessages > {
79
92
let pdu = pdu:: TrainingPdu {
80
93
timestamp : 4231 , // a random number
@@ -116,6 +129,19 @@ impl RdpsndServer {
116
129
Ok ( msg)
117
130
}
118
131
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
+
119
145
pub fn close ( & mut self ) -> PduResult < RdpsndSvcMessages > {
120
146
Ok ( RdpsndSvcMessages :: new ( vec ! [ pdu:: ServerAudioOutputPdu :: Close . into( ) ] ) )
121
147
}
0 commit comments