@@ -17,7 +17,6 @@ extern crate lazy_static;
17
17
18
18
use failure:: Error ;
19
19
use gst:: prelude:: * ;
20
- use gst:: { BinExt , ElementExt } ;
21
20
use rand:: Rng ;
22
21
use std:: sync:: { mpsc, Arc , Mutex } ;
23
22
use std:: thread;
@@ -49,7 +48,6 @@ lazy_static! {
49
48
50
49
#[ derive( PartialEq , PartialOrd , Eq , Debug ) ]
51
50
enum AppState {
52
- // AppStateUnknown = 0,
53
51
AppStateErr = 1 ,
54
52
ServerConnected ,
55
53
ServerRegistering = 2000 ,
@@ -116,7 +114,11 @@ struct PadLinkError {
116
114
right : gst:: PadLinkReturn ,
117
115
}
118
116
119
- fn check_plugins ( ) -> bool {
117
+ #[ derive( Debug , Fail ) ]
118
+ #[ fail( display = "Missing elements {:?}" , _0) ]
119
+ struct MissingElements ( Vec < & ' static str > ) ;
120
+
121
+ fn check_plugins ( ) -> Result < ( ) , Error > {
120
122
let needed = vec ! [
121
123
"opus" ,
122
124
"vpx" ,
@@ -129,15 +131,18 @@ fn check_plugins() -> bool {
129
131
"audiotestsrc" ,
130
132
] ;
131
133
let registry = gst:: Registry :: get ( ) ;
132
- let mut ret = true ;
134
+ let mut missing : Vec < & ' static str > = Vec :: new ( ) ;
133
135
for plugin_name in needed {
134
136
let plugin = registry. find_plugin ( & plugin_name. to_string ( ) ) ;
135
137
if plugin. is_none ( ) {
136
- println ! ( "Required gstreamer plugin '{}' not found" , plugin_name) ;
137
- ret = false ;
138
+ missing. push ( plugin_name)
138
139
}
139
140
}
140
- ret
141
+ if missing. len ( ) > 0 {
142
+ Err ( MissingElements ( missing) ) ?
143
+ } else {
144
+ Ok ( ( ) )
145
+ }
141
146
}
142
147
143
148
fn send_sdp_offer ( app_control : & AppControl , offer : gst_webrtc:: WebRTCSessionDescription ) {
@@ -425,7 +430,6 @@ impl AppControl {
425
430
. unwrap ( ) ;
426
431
let app_control_clone = self . clone ( ) ;
427
432
webrtc. connect ( "on-negotiation-needed" , false , move |values| {
428
- // handle
429
433
on_negotiation_needed ( & app_control_clone, values) . unwrap ( ) ;
430
434
None
431
435
} ) ?;
@@ -557,7 +561,6 @@ impl AppControl {
557
561
}
558
562
559
563
fn close_and_quit ( & self , err : Error ) {
560
- // self.update_state(AppState::ServerClosed);
561
564
let app_control = self . 0 . lock ( ) . unwrap ( ) ;
562
565
println ! ( "{}\n quitting" , err) ;
563
566
app_control
@@ -646,16 +649,13 @@ fn receive_loop(
646
649
let _ = send_msg_tx. send ( OwnedMessage :: Close ( None ) ) ;
647
650
return ;
648
651
}
649
- OwnedMessage :: Ping ( data) => {
650
- match send_msg_tx. send ( OwnedMessage :: Pong ( data) ) {
651
- // Send a pong in response
652
- Ok ( ( ) ) => ( ) ,
653
- Err ( e) => {
654
- println ! ( "Receive Loop error: {:?}" , e) ;
655
- return ;
656
- }
652
+ OwnedMessage :: Ping ( data) => match send_msg_tx. send ( OwnedMessage :: Pong ( data) ) {
653
+ Ok ( ( ) ) => ( ) ,
654
+ Err ( e) => {
655
+ println ! ( "Receive Loop error: {:?}" , e) ;
656
+ return ;
657
657
}
658
- }
658
+ } ,
659
659
OwnedMessage :: Text ( msg) => {
660
660
let mbuilder = gst:: Message :: new_application ( gst:: Structure :: new (
661
661
"ws-message" ,
@@ -674,8 +674,12 @@ fn receive_loop(
674
674
675
675
fn main ( ) {
676
676
gst:: init ( ) . unwrap ( ) ;
677
- if !check_plugins ( ) {
678
- return ;
677
+ match check_plugins ( ) {
678
+ Err ( err) => {
679
+ println ! ( "{:?}" , err) ;
680
+ return ;
681
+ }
682
+ _ => { }
679
683
}
680
684
681
685
let ( server, peer_id) = parse_args ( ) ;
0 commit comments