From 647d600c234a3a50a8c23cf472fe3cefa655d8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Ka=C5=BAmierczak?= Date: Mon, 21 Oct 2024 11:35:02 +0200 Subject: [PATCH] refactor --- compositor_pipeline/src/pipeline.rs | 2 +- compositor_pipeline/src/pipeline/output/whip.rs | 13 +++++-------- integration_tests/examples/whip_client.rs | 3 +-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/compositor_pipeline/src/pipeline.rs b/compositor_pipeline/src/pipeline.rs index 56c26082f..1a4058b4d 100644 --- a/compositor_pipeline/src/pipeline.rs +++ b/compositor_pipeline/src/pipeline.rs @@ -196,7 +196,7 @@ impl Pipeline { download_dir: download_dir.into(), event_emitter, tokio_rt: Arc::new( - Runtime::new().map_err(|err| InitPipelineError::CreateTokioRuntime(err))?, + Runtime::new().map_err(InitPipelineError::CreateTokioRuntime)?, ), #[cfg(feature = "vk-video")] vulkan_ctx: preinitialized_ctx.and_then(|ctx| ctx.vulkan_ctx), diff --git a/compositor_pipeline/src/pipeline/output/whip.rs b/compositor_pipeline/src/pipeline/output/whip.rs index 4de291c53..163655573 100644 --- a/compositor_pipeline/src/pipeline/output/whip.rs +++ b/compositor_pipeline/src/pipeline/output/whip.rs @@ -137,18 +137,18 @@ fn start_whip_sender_thread( match chunk.kind { DataKind::Audio => { - if let Err(_) = audio_track.write(&chunk.data).await { + if audio_track.write(&chunk.data).await.is_err() { error!("Error occurred while writing to audio track for session"); } } DataKind::Video => { - if let Err(_) = video_track.write(&chunk.data).await { + if video_track.write(&chunk.data).await.is_err() { error!("Error occurred while writing to video track for session"); } } } } - let _ = client.delete(whip_session_url).send().await; // not unwrapping, because server may have gone down, so it should be handled better way + let _ = client.delete(whip_session_url).send().await; }); } @@ -204,7 +204,6 @@ async fn init_pc() -> ( ..Default::default() }; let peer_connection = Arc::new(api.new_peer_connection(config).await.unwrap()); - // Create Track that we send video back to browser on let video_track = Arc::new(TrackLocalStaticRTP::new( RTCRtpCodecCapability { mime_type: MIME_TYPE_H264.to_owned(), @@ -236,11 +235,10 @@ async fn connect( peer_connection: Arc, endpoint_url: String, bearer_token: String, - should_close: Arc, // TODO handle should_close if necessary + should_close: Arc, tokio_rt: Arc, client: reqwest::Client, ) -> anyhow::Result { - // TODO replace anyhow with proper errors peer_connection.on_ice_connection_state_change(Box::new( move |connection_state: RTCIceConnectionState| { debug!("Connection State has changed {connection_state}"); @@ -289,7 +287,7 @@ async fn connect( .unwrap(); let answer = response.bytes().await.unwrap(); - let _ = peer_connection.set_local_description(offer).await.unwrap(); + peer_connection.set_local_description(offer).await.unwrap(); peer_connection .set_remote_description( @@ -302,7 +300,6 @@ async fn connect( let client = Arc::new(client); let location1: Url = location_url.clone(); - println!("{location1}"); peer_connection.on_ice_candidate(Box::new(move |candidate| { if let Some(candidate) = candidate { diff --git a/integration_tests/examples/whip_client.rs b/integration_tests/examples/whip_client.rs index b47366703..a922278a9 100644 --- a/integration_tests/examples/whip_client.rs +++ b/integration_tests/examples/whip_client.rs @@ -33,8 +33,7 @@ fn client_code() -> Result<()> { &json!({ "type": "whip", "endpoint_url": "https://g.webrtc.live-video.net:4443/v2/offer", - // "endpoint_url": "http://localhost:9000/whip", - "bearer_token": "", // your Bearer token + "bearer_token": "", // your Bearer token "video": { "resolution": { "width": VIDEO_RESOLUTION.width,