From 484d16c262ab3cc516f326b7e0e0c7fe5fb6bd1b Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 24 Oct 2023 15:39:47 +0700 Subject: [PATCH] Hnadle flushing error in appsrc as non fatal --- .../core/src/bc_protocol/connection/udpsource.rs | 6 +++--- src/rtsp/stream.rs | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/core/src/bc_protocol/connection/udpsource.rs b/crates/core/src/bc_protocol/connection/udpsource.rs index 24b260f..fd3566f 100644 --- a/crates/core/src/bc_protocol/connection/udpsource.rs +++ b/crates/core/src/bc_protocol/connection/udpsource.rs @@ -333,7 +333,7 @@ impl UdpPayloadInner { let send_cancel = cancel.clone(); let mut socket_in_rx = ReceiverStream::new(socket_in_rx); let thread_camera_addr = camera_addr; - let mut socket_out_tx = PollSender::new(socket_out_tx); + let socket_out_tx = socket_out_tx.clone(); let thread_client_id = client_id; let thread_camera_id = camera_id; const TIME_OUT: u64 = 10; @@ -355,7 +355,7 @@ impl UdpPayloadInner { let packet = packet.ok_or(Error::DroppedConnection)??; recv_timeout.as_mut().reset(Instant::now() + Duration::from_secs(TIME_OUT)); // let packet = socket_rx.next().await.ok_or(Error::DroppedConnection)??; - tokio::time::timeout(tokio::time::Duration::from_millis(250), socket_out_tx.send(packet)).await.map_err(|_| Error::DroppedConnection)??; + socket_out_tx.try_send(packet).map_err(|_| Error::DroppedConnection)?; continue; }, packet = socket_in_rx.next() => { @@ -389,7 +389,7 @@ impl UdpPayloadInner { ..Default::default() }, }); - let _ = tokio::time::timeout(Duration::from_millis(250), inner.send((msg, thread_camera_addr))).await; + let _ = tokio::time::timeout(tokio::time::Duration::from_millis(250), inner.send((msg, thread_camera_addr))).await; } } diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs index 2b77c96..3cf3a36 100644 --- a/src/rtsp/stream.rs +++ b/src/rtsp/stream.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Result}; -use gstreamer::{prelude::*, ClockTime}; +use gstreamer::{prelude::*, ClockTime, FlowError}; use gstreamer_app::AppSrc; use gstreamer_rtsp_server::prelude::*; use std::collections::HashSet; @@ -677,10 +677,14 @@ async fn send_to_appsrc> + Unpin>( gst_buf }; - appsrc - .push_buffer(buf) - .map(|_| ()) - .map_err(|e| anyhow!("Could not push buffer to appsrc: {e:?}"))?; + match appsrc.push_buffer(buf) { + Ok(_) => Ok(()), + Err(FlowError::Flushing) => { + // Buffer is full just skip + Ok(()) + } + Err(e) => Err(anyhow!("Error in streaming: {e:?}")), + }?; } Ok(()) }