rtsp_server: RTSPServer::attach() is fallible

If we don't handle the case of RTSPServer::attach() failing, we end up
with a panic. Unfortunately, we don't get any details from the
underlying call so we've to live with a generic error. :(
This commit is contained in:
Zeeshan Ali 2021-02-04 20:53:13 +01:00
parent 280433ebc1
commit 7a014e4024
4 changed files with 18 additions and 7 deletions

View file

@ -130,7 +130,7 @@ fn main_loop() -> Result<(), Error> {
// interested in them. In this example, we only do have one, so we can
// leave the context parameter empty, it will automatically select
// the default one.
let id = server.attach(None);
let id = server.attach(None)?;
println!(
"Stream ready at rtsps://127.0.0.1:{}/test",

View file

@ -58,7 +58,7 @@ fn main_loop() -> Result<(), Error> {
// interested in them. In this example, we only do have one, so we can
// leave the context parameter empty, it will automatically select
// the default one.
let id = server.attach(None);
let id = server.attach(None)?;
println!(
"Stream ready at rtsp://127.0.0.1:{}/test",

View file

@ -66,7 +66,7 @@ fn main_loop() -> Result<(), Error> {
// interested in them. In this example, we only do have one, so we can
// leave the context parameter empty, it will automatically select
// the default one.
let id = server.attach(None);
let id = server.attach(None)?;
println!(
"Stream ready at rtsp://127.0.0.1:{}/test",

View file

@ -6,16 +6,27 @@ use glib::source::SourceId;
use glib::translate::*;
pub trait RTSPServerExtManual: 'static {
fn attach(&self, context: Option<&glib::MainContext>) -> SourceId;
fn attach(
&self,
context: Option<&glib::MainContext>,
) -> Result<SourceId, glib::error::BoolError>;
}
impl<O: IsA<RTSPServer>> RTSPServerExtManual for O {
fn attach(&self, context: Option<&glib::MainContext>) -> SourceId {
fn attach(
&self,
context: Option<&glib::MainContext>,
) -> Result<SourceId, glib::error::BoolError> {
unsafe {
from_glib(ffi::gst_rtsp_server_attach(
match ffi::gst_rtsp_server_attach(
self.as_ref().to_glib_none().0,
context.to_glib_none().0,
))
) {
0 => Err(glib::bool_error!(
"Failed to attach main context to RTSP server"
)),
id => Ok(from_glib(id)),
}
}
}
}