Loading system/gd/rust/topshim/facade/src/media_service.rs +8 −2 Original line number Diff line number Diff line //! Media service facade use bt_topshim::btif::BluetoothInterface; use bt_topshim::profiles::a2dp::{A2dp, A2dpCallbacksDispatcher, A2dpSink}; use bt_topshim::profiles::a2dp::{ A2dp, A2dpCallbacksDispatcher, A2dpSink, A2dpSinkCallbacksDispatcher, }; use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacksDispatcher}; use bt_topshim_facade_protobuf::facade::{ A2dpSourceConnectRequest, A2dpSourceConnectResponse, StartA2dpRequest, StartA2dpResponse, Loading @@ -17,6 +19,10 @@ fn get_a2dp_dispatcher() -> A2dpCallbacksDispatcher { A2dpCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) } } fn get_a2dp_sink_dispatcher() -> A2dpSinkCallbacksDispatcher { A2dpSinkCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) } } fn get_avrcp_dispatcher() -> AvrcpCallbacksDispatcher { AvrcpCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) } } Loading Loading @@ -60,7 +66,7 @@ impl MediaService for MediaServiceImpl { sink.success(StartA2dpResponse::default()).await.unwrap(); }) } else if req.start_a2dp_sink { self.btif_a2dp_sink.lock().unwrap().initialize(); self.btif_a2dp_sink.lock().unwrap().initialize(get_a2dp_sink_dispatcher()); ctx.spawn(async move { sink.success(StartA2dpResponse::default()).await.unwrap(); }) Loading system/gd/rust/topshim/src/profiles/a2dp.rs +15 −1 Original line number Diff line number Diff line Loading @@ -335,6 +335,17 @@ impl A2dp { } } #[derive(Debug)] pub enum A2dpSinkCallbacks { ConnectionState(RawAddress, BtavConnectionState), } pub struct A2dpSinkCallbacksDispatcher { pub dispatch: Box<dyn Fn(A2dpSinkCallbacks) + Send>, } type A2dpSinkCb = Arc<Mutex<A2dpSinkCallbacksDispatcher>>; pub struct A2dpSink { internal: cxx::UniquePtr<ffi::A2dpSinkIntf>, _is_init: bool, Loading @@ -353,7 +364,10 @@ impl A2dpSink { A2dpSink { internal: a2dp_sink, _is_init: false } } pub fn initialize(&mut self) -> bool { pub fn initialize(&mut self, callbacks: A2dpSinkCallbacksDispatcher) -> bool { if get_dispatchers().lock().unwrap().set::<A2dpSinkCb>(Arc::new(Mutex::new(callbacks))) { panic!("Tried to set dispatcher for A2dp Sink Callbacks while it already exists"); } self.internal.pin_mut().init(); true } Loading Loading
system/gd/rust/topshim/facade/src/media_service.rs +8 −2 Original line number Diff line number Diff line //! Media service facade use bt_topshim::btif::BluetoothInterface; use bt_topshim::profiles::a2dp::{A2dp, A2dpCallbacksDispatcher, A2dpSink}; use bt_topshim::profiles::a2dp::{ A2dp, A2dpCallbacksDispatcher, A2dpSink, A2dpSinkCallbacksDispatcher, }; use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacksDispatcher}; use bt_topshim_facade_protobuf::facade::{ A2dpSourceConnectRequest, A2dpSourceConnectResponse, StartA2dpRequest, StartA2dpResponse, Loading @@ -17,6 +19,10 @@ fn get_a2dp_dispatcher() -> A2dpCallbacksDispatcher { A2dpCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) } } fn get_a2dp_sink_dispatcher() -> A2dpSinkCallbacksDispatcher { A2dpSinkCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) } } fn get_avrcp_dispatcher() -> AvrcpCallbacksDispatcher { AvrcpCallbacksDispatcher { dispatch: Box::new(move |_cb| {}) } } Loading Loading @@ -60,7 +66,7 @@ impl MediaService for MediaServiceImpl { sink.success(StartA2dpResponse::default()).await.unwrap(); }) } else if req.start_a2dp_sink { self.btif_a2dp_sink.lock().unwrap().initialize(); self.btif_a2dp_sink.lock().unwrap().initialize(get_a2dp_sink_dispatcher()); ctx.spawn(async move { sink.success(StartA2dpResponse::default()).await.unwrap(); }) Loading
system/gd/rust/topshim/src/profiles/a2dp.rs +15 −1 Original line number Diff line number Diff line Loading @@ -335,6 +335,17 @@ impl A2dp { } } #[derive(Debug)] pub enum A2dpSinkCallbacks { ConnectionState(RawAddress, BtavConnectionState), } pub struct A2dpSinkCallbacksDispatcher { pub dispatch: Box<dyn Fn(A2dpSinkCallbacks) + Send>, } type A2dpSinkCb = Arc<Mutex<A2dpSinkCallbacksDispatcher>>; pub struct A2dpSink { internal: cxx::UniquePtr<ffi::A2dpSinkIntf>, _is_init: bool, Loading @@ -353,7 +364,10 @@ impl A2dpSink { A2dpSink { internal: a2dp_sink, _is_init: false } } pub fn initialize(&mut self) -> bool { pub fn initialize(&mut self, callbacks: A2dpSinkCallbacksDispatcher) -> bool { if get_dispatchers().lock().unwrap().set::<A2dpSinkCb>(Arc::new(Mutex::new(callbacks))) { panic!("Tried to set dispatcher for A2dp Sink Callbacks while it already exists"); } self.internal.pin_mut().init(); true } Loading