@@ -76,6 +76,14 @@ struct Cli {
7676 /// Codec type
7777 #[ clap( long, help = "Codec type" , default_value = "g722" ) ]
7878 codec : String ,
79+
80+ /// VAD
81+ #[ clap( long, help = "VAD" , default_value = "true" ) ]
82+ vad : Option < bool > ,
83+
84+ /// Denoising
85+ #[ clap( long, help = "Denoising" , default_value = "true" ) ]
86+ denoise : Option < bool > ,
7987}
8088
8189async fn serve_client ( codec : CodecType , cli : Cli , id : u32 , state : Arc < AppState > ) -> Result < ( ) > {
@@ -88,7 +96,7 @@ async fn serve_client(codec: CodecType, cli: Cli, id: u32, state: Arc<AppState>)
8896
8997 let peer_connection = Arc :: new ( api. new_peer_connection ( config) . await ?) ;
9098 // Create an audio track
91- let track = WebrtcTrack :: create_audio_track ( CodecType :: G722 , None ) ;
99+ let track = WebrtcTrack :: create_audio_track ( codec , None ) ;
92100 // Add the track to the peer connection
93101 let _rtp_sender = peer_connection
94102 . add_track ( Arc :: clone ( & track) as Arc < TrackLocalStaticSample > )
@@ -101,7 +109,6 @@ async fn serve_client(codec: CodecType, cli: Cli, id: u32, state: Arc<AppState>)
101109 let ice_candidates_tx_clone = Arc :: clone ( & ice_candidates_tx) ;
102110 peer_connection. on_ice_candidate ( Box :: new (
103111 move |candidate : Option < webrtc:: ice_transport:: ice_candidate:: RTCIceCandidate > | {
104- info ! ( "ICE candidate received: {:?}" , candidate) ;
105112 let ice_candidates_tx_clone = ice_candidates_tx_clone. clone ( ) ;
106113 Box :: pin ( async move {
107114 if candidate. is_none ( ) {
@@ -182,7 +189,16 @@ async fn serve_client(codec: CodecType, cli: Cli, id: u32, state: Arc<AppState>)
182189 // Create the invite command with proper options
183190 let option = CallOption {
184191 offer : Some ( strip_ipv6_candidates ( & offer. sdp ) ) ,
185- vad : Some ( VADOption :: default ( ) ) ,
192+ vad : if cli. vad . unwrap_or ( false ) {
193+ Some ( VADOption :: default ( ) )
194+ } else {
195+ None
196+ } ,
197+ denoise : if cli. denoise . unwrap_or ( false ) {
198+ Some ( true )
199+ } else {
200+ None
201+ } ,
186202 ..Default :: default ( )
187203 } ;
188204
@@ -196,12 +212,20 @@ async fn serve_client(codec: CodecType, cli: Cli, id: u32, state: Arc<AppState>)
196212 // Wait for transcription event
197213 let recv_event_loop = async move {
198214 while let Some ( Ok ( msg) ) = ws_receiver. next ( ) . await {
199- let event: SessionEvent = serde_json:: from_str ( & msg. to_string ( ) ) ?;
215+ let event: SessionEvent =
216+ serde_json:: from_str ( & msg. to_string ( ) ) . expect ( "Failed to parse event" ) ;
200217 match event {
201218 SessionEvent :: Answer { sdp, .. } => {
202219 info ! ( id, "Received answer: {}" , sdp) ;
203220 let offer = RTCSessionDescription :: answer ( sdp) ?;
204- peer_connection. set_remote_description ( offer) . await ?;
221+ match peer_connection. set_remote_description ( offer) . await {
222+ Ok ( _) => {
223+ info ! ( id, "Set remote description ok" ) ;
224+ }
225+ Err ( e) => {
226+ error ! ( id, "Set remote description failed: {}" , e) ;
227+ }
228+ }
205229 ws_sender
206230 . send ( tungstenite:: Message :: Text (
207231 serde_json:: to_string_pretty ( & Command :: Play {
@@ -281,8 +305,8 @@ async fn serve_client(codec: CodecType, cli: Cli, id: u32, state: Arc<AppState>)
281305 state. alive . fetch_add ( 1 , Ordering :: Relaxed ) ;
282306
283307 select ! {
284- _ = recv_event_loop => {
285- info!( id, "Transcription received" ) ;
308+ r = recv_event_loop => {
309+ info!( id, "recv_event_loop completed {:?}" , r ) ;
286310 }
287311 _ = send_audio_loop => {
288312 }
@@ -324,6 +348,7 @@ async fn main() -> Result<()> {
324348 let codec = match cli. codec . as_str ( ) {
325349 "g722" => CodecType :: G722 ,
326350 "opus" => CodecType :: Opus ,
351+ "pcmu" => CodecType :: PCMU ,
327352 _ => return Err ( anyhow:: anyhow!( "Invalid codec type" ) ) ,
328353 } ;
329354 for id in 0 ..cli. clients {
@@ -344,7 +369,13 @@ async fn main() -> Result<()> {
344369 } ) ) ;
345370 }
346371
347- info ! ( "Waiting for {} clients to connect..." , cli. clients) ;
372+ println ! (
373+ "perfcli started, clients: {}, codec: {:?}, vad: {}, denoise: {}" ,
374+ cli. clients,
375+ codec,
376+ cli. vad. unwrap_or( false ) ,
377+ cli. denoise. unwrap_or( false )
378+ ) ;
348379 let dump_state_loop = async move {
349380 let mut last_rx_bytes = 0u64 ;
350381 let mut last_tx_bytes = 0u64 ;
@@ -356,7 +387,7 @@ async fn main() -> Result<()> {
356387 let rx_rate = current_rx. saturating_sub ( last_rx_bytes) ;
357388 let tx_rate = current_tx. saturating_sub ( last_tx_bytes) ;
358389
359- info ! (
390+ println ! (
360391 "alive: {}, rx_bytes: {:.2} KB/s, tx_bytes: {:.2} KB/s" ,
361392 state. alive. load( Ordering :: Relaxed ) ,
362393 rx_rate as f64 / 1024.0 ,
0 commit comments