@@ -11,10 +11,10 @@ use std::time::Duration;
1111use anyhow:: Context as _;
1212use calloop:: timer:: { TimeoutAction , Timer } ;
1313use calloop:: RegistrationToken ;
14- use pipewire:: context:: Context ;
15- use pipewire:: core:: { Core , PW_ID_CORE } ;
16- use pipewire:: main_loop:: MainLoop ;
17- use pipewire:: properties:: Properties ;
14+ use pipewire:: context:: ContextRc ;
15+ use pipewire:: core:: { CoreRc , PW_ID_CORE } ;
16+ use pipewire:: main_loop:: MainLoopRc ;
17+ use pipewire:: properties:: PropertiesBox ;
1818use pipewire:: spa:: buffer:: DataType ;
1919use pipewire:: spa:: param:: format:: { FormatProperties , MediaSubtype , MediaType } ;
2020use pipewire:: spa:: param:: format_utils:: parse_format;
@@ -28,7 +28,7 @@ use pipewire::spa::utils::{
2828 Choice , ChoiceEnum , ChoiceFlags , Direction , Fraction , Rectangle , SpaTypes ,
2929} ;
3030use pipewire:: spa:: { self } ;
31- use pipewire:: stream:: { Stream , StreamFlags , StreamListener , StreamState } ;
31+ use pipewire:: stream:: { Stream , StreamFlags , StreamListener , StreamRc , StreamState } ;
3232use pipewire:: sys:: { pw_buffer, pw_stream_queue_buffer} ;
3333use smithay:: backend:: allocator:: dmabuf:: { AsDmabuf , Dmabuf } ;
3434use smithay:: backend:: allocator:: format:: FormatSet ;
@@ -55,8 +55,8 @@ use crate::utils::get_monotonic_time;
5555const CAST_DELAY_ALLOWANCE : Duration = Duration :: from_micros ( 100 ) ;
5656
5757pub struct PipeWire {
58- _context : Context ,
59- pub core : Core ,
58+ _context : ContextRc ,
59+ pub core : CoreRc ,
6060 pub token : RegistrationToken ,
6161 event_loop : LoopHandle < ' static , State > ,
6262 to_niri : calloop:: channel:: Sender < PwToNiri > ,
@@ -72,7 +72,7 @@ pub struct Cast {
7272 event_loop : LoopHandle < ' static , State > ,
7373 pub session_id : usize ,
7474 pub stream_id : usize ,
75- pub stream : Stream ,
75+ pub stream : StreamRc ,
7676 _listener : StreamListener < ( ) > ,
7777 pub target : CastTarget ,
7878 pub dynamic_target : bool ,
@@ -158,9 +158,9 @@ impl PipeWire {
158158 event_loop : LoopHandle < ' static , State > ,
159159 to_niri : calloop:: channel:: Sender < PwToNiri > ,
160160 ) -> anyhow:: Result < Self > {
161- let main_loop = MainLoop :: new ( None ) . context ( "error creating MainLoop" ) ?;
162- let context = Context :: new ( & main_loop) . context ( "error creating Context" ) ?;
163- let core = context. connect ( None ) . context ( "error creating Core" ) ?;
161+ let main_loop = MainLoopRc :: new ( None ) . context ( "error creating MainLoop" ) ?;
162+ let context = ContextRc :: new ( & main_loop, None ) . context ( "error creating Context" ) ?;
163+ let core = context. connect_rc ( None ) . context ( "error creating Core" ) ?;
164164
165165 let to_niri_ = to_niri. clone ( ) ;
166166 let listener = core
@@ -178,7 +178,7 @@ impl PipeWire {
178178 . register ( ) ;
179179 mem:: forget ( listener) ;
180180
181- struct AsFdWrapper ( MainLoop ) ;
181+ struct AsFdWrapper ( MainLoopRc ) ;
182182 impl AsFd for AsFdWrapper {
183183 fn as_fd ( & self ) -> BorrowedFd < ' _ > {
184184 self . 0 . loop_ ( ) . fd ( )
@@ -233,8 +233,12 @@ impl PipeWire {
233233 } ;
234234 let redraw_ = redraw. clone ( ) ;
235235
236- let stream = Stream :: new ( & self . core , "niri-screen-cast-src" , Properties :: new ( ) )
237- . context ( "error creating Stream" ) ?;
236+ let stream = StreamRc :: new (
237+ self . core . clone ( ) ,
238+ "niri-screen-cast-src" ,
239+ PropertiesBox :: new ( ) ,
240+ )
241+ . context ( "error creating Stream" ) ?;
238242
239243 let pending_size = Size :: from ( ( size. w as u32 , size. h as u32 ) ) ;
240244
0 commit comments