threadshare/udpsink: Return Flushing if the sender gets disconnected

This can only happen if the receiver is dropped, which only happens when
the task is stopped. As such, Flushing should be returned instead of
panicking.
This commit is contained in:
Sebastian Dröge 2020-04-06 14:01:16 +03:00
parent acbd3066e8
commit 7173790da2

View file

@ -773,14 +773,18 @@ impl PadSinkHandler for UdpSinkPadHandler {
&self, &self,
_pad: &PadSinkRef, _pad: &PadSinkRef,
_udpsink: &UdpSink, _udpsink: &UdpSink,
_element: &gst::Element, element: &gst::Element,
buffer: gst::Buffer, buffer: gst::Buffer,
) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> { ) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> {
let sender = Arc::clone(&self.0.read().unwrap().sender); let sender = Arc::clone(&self.0.read().unwrap().sender);
let element = element.clone();
async move { async move {
if let Some(sender) = sender.lock().await.as_mut() { if let Some(sender) = sender.lock().await.as_mut() {
sender.send(TaskItem::Buffer(buffer)).await.unwrap(); if let Err(_) = sender.send(TaskItem::Buffer(buffer)).await {
gst_debug!(CAT, obj: &element, "Flushing");
return Err(gst::FlowError::Flushing);
}
} }
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
} }
@ -791,15 +795,19 @@ impl PadSinkHandler for UdpSinkPadHandler {
&self, &self,
_pad: &PadSinkRef, _pad: &PadSinkRef,
_udpsink: &UdpSink, _udpsink: &UdpSink,
_element: &gst::Element, element: &gst::Element,
list: gst::BufferList, list: gst::BufferList,
) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> { ) -> BoxFuture<'static, Result<gst::FlowSuccess, gst::FlowError>> {
let sender = Arc::clone(&self.0.read().unwrap().sender); let sender = Arc::clone(&self.0.read().unwrap().sender);
let element = element.clone();
async move { async move {
if let Some(sender) = sender.lock().await.as_mut() { if let Some(sender) = sender.lock().await.as_mut() {
for buffer in list.iter_owned() { for buffer in list.iter_owned() {
sender.send(TaskItem::Buffer(buffer)).await.unwrap(); if let Err(_) = sender.send(TaskItem::Buffer(buffer)).await {
gst_debug!(CAT, obj: &element, "Flushing");
return Err(gst::FlowError::Flushing);
}
} }
} }
@ -823,7 +831,9 @@ impl PadSinkHandler for UdpSinkPadHandler {
let udpsink = UdpSink::from_instance(&element); let udpsink = UdpSink::from_instance(&element);
let _ = udpsink.start(&element); let _ = udpsink.start(&element);
} else if let Some(sender) = sender.lock().await.as_mut() { } else if let Some(sender) = sender.lock().await.as_mut() {
sender.send(TaskItem::Event(event)).await.unwrap(); if let Err(_) = sender.send(TaskItem::Event(event)).await {
gst_debug!(CAT, obj: &element, "Flushing");
}
} }
true true