system/bt
リビジョン | 14826309312a3b35ca70d38dd9ab3972f6a6bf85 (tree) |
---|---|
日時 | 2019-05-31 15:03:04 |
作者 | Cheney Ni <cheneyni@goog...> |
コミッター | android-build-merger |
Make sure the Hearing Aid source is ready before resuming or suspending calls
am: 2e4fd6f728
Change-Id: I3d483a0d35b19defe7be94b53f9c6dd5cf1f7b20
@@ -172,8 +172,9 @@ class BluetoothAudioDeathRecipient | ||
172 | 172 | // restart the session on the correct thread |
173 | 173 | message_loop_->DoInThread( |
174 | 174 | FROM_HERE, |
175 | - base::BindOnce(&RenewAudioProviderAndSession, | |
176 | - base::Unretained(bluetooth_audio_clientif_))); | |
175 | + base::BindOnce( | |
176 | + &BluetoothAudioClientInterface::RenewAudioProviderAndSession, | |
177 | + base::Unretained(bluetooth_audio_clientif_))); | |
177 | 178 | } else { |
178 | 179 | LOG(ERROR) << __func__ << ": BluetoothAudioClientInterface corrupted"; |
179 | 180 | } |
@@ -182,12 +183,6 @@ class BluetoothAudioDeathRecipient | ||
182 | 183 | private: |
183 | 184 | BluetoothAudioClientInterface* bluetooth_audio_clientif_; |
184 | 185 | bluetooth::common::MessageLoopThread* message_loop_; |
185 | - static void RenewAudioProviderAndSession( | |
186 | - BluetoothAudioClientInterface* bluetooth_audio_clientif) { | |
187 | - if (bluetooth_audio_clientif != nullptr) { | |
188 | - bluetooth_audio_clientif->RenewAudioProviderAndSession(); | |
189 | - } | |
190 | - } | |
191 | 186 | }; |
192 | 187 | |
193 | 188 | BluetoothAudioClientInterface::BluetoothAudioClientInterface(IBluetoothTransportInstance* sink, |
@@ -68,11 +68,11 @@ class HearingAidTransport | ||
68 | 68 | |
69 | 69 | void StopRequest() override { |
70 | 70 | LOG(INFO) << __func__; |
71 | - stream_cb_.on_suspend_(); | |
72 | - | |
73 | - // flush | |
74 | - uint8_t p_buf[AUDIO_STREAM_OUTPUT_BUFFER_SZ * 2]; | |
75 | - ::bluetooth::audio::hearing_aid::read(p_buf, sizeof(p_buf)); | |
71 | + if (stream_cb_.on_suspend_()) { | |
72 | + // flush | |
73 | + uint8_t p_buf[AUDIO_STREAM_OUTPUT_BUFFER_SZ * 2]; | |
74 | + ::bluetooth::audio::hearing_aid::read(p_buf, sizeof(p_buf)); | |
75 | + } | |
76 | 76 | } |
77 | 77 | |
78 | 78 | bool GetPresentationPosition(uint64_t* remote_delay_report_ns, |
@@ -38,8 +38,8 @@ int sample_rate = -1; | ||
38 | 38 | int data_interval_ms = -1; |
39 | 39 | int num_channels = 2; |
40 | 40 | bluetooth::common::RepeatingTimer audio_timer; |
41 | -HearingAidAudioReceiver* localAudioReceiver; | |
42 | -std::unique_ptr<tUIPC_STATE> uipc_hearing_aid; | |
41 | +HearingAidAudioReceiver* localAudioReceiver = nullptr; | |
42 | +std::unique_ptr<tUIPC_STATE> uipc_hearing_aid = nullptr; | |
43 | 43 | |
44 | 44 | struct AudioHalStats { |
45 | 45 | size_t media_read_total_underflow_bytes; |
@@ -85,7 +85,9 @@ void send_audio_data() { | ||
85 | 85 | |
86 | 86 | std::vector<uint8_t> data(p_buf, p_buf + bytes_read); |
87 | 87 | |
88 | - localAudioReceiver->OnAudioDataReady(data); | |
88 | + if (localAudioReceiver != nullptr) { | |
89 | + localAudioReceiver->OnAudioDataReady(data); | |
90 | + } | |
89 | 91 | } |
90 | 92 | |
91 | 93 | void hearing_aid_send_ack(tHEARING_AID_CTRL_ACK status) { |
@@ -305,7 +307,7 @@ void hearing_aid_ctrl_cb(tUIPC_CH_ID, tUIPC_EVENT event) { | ||
305 | 307 | |
306 | 308 | bool hearing_aid_on_resume_req(bool start_media_task) { |
307 | 309 | // hearing_aid_recv_ctrl_data(HEARING_AID_CTRL_CMD_START) |
308 | - if (localAudioReceiver) { | |
310 | + if (localAudioReceiver != nullptr) { | |
309 | 311 | // Call OnAudioResume and block till it returns. |
310 | 312 | std::promise<void> do_resume_promise; |
311 | 313 | std::future<void> do_resume_future = do_resume_promise.get_future(); |
@@ -342,7 +344,7 @@ bool hearing_aid_on_resume_req(bool start_media_task) { | ||
342 | 344 | bool hearing_aid_on_suspend_req() { |
343 | 345 | // hearing_aid_recv_ctrl_data(HEARING_AID_CTRL_CMD_SUSPEND): stop_media_task |
344 | 346 | stop_audio_ticks(); |
345 | - if (localAudioReceiver) { | |
347 | + if (localAudioReceiver != nullptr) { | |
346 | 348 | // Call OnAudioSuspend and block till it returns. |
347 | 349 | std::promise<void> do_suspend_promise; |
348 | 350 | std::future<void> do_suspend_future = do_suspend_promise.get_future(); |
@@ -369,8 +371,7 @@ bool hearing_aid_on_suspend_req() { | ||
369 | 371 | void HearingAidAudioSource::Start(const CodecConfiguration& codecConfiguration, |
370 | 372 | HearingAidAudioReceiver* audioReceiver, |
371 | 373 | uint16_t remote_delay_ms) { |
372 | - localAudioReceiver = audioReceiver; | |
373 | - VLOG(2) << "Hearing Aid UIPC Open"; | |
374 | + LOG(INFO) << __func__ << ": Hearing Aid Source Open"; | |
374 | 375 | |
375 | 376 | bit_rate = codecConfiguration.bit_rate; |
376 | 377 | sample_rate = codecConfiguration.sample_rate; |
@@ -382,9 +383,13 @@ void HearingAidAudioSource::Start(const CodecConfiguration& codecConfiguration, | ||
382 | 383 | bluetooth::audio::hearing_aid::start_session(); |
383 | 384 | bluetooth::audio::hearing_aid::set_remote_delay(remote_delay_ms); |
384 | 385 | } |
386 | + localAudioReceiver = audioReceiver; | |
385 | 387 | } |
386 | 388 | |
387 | 389 | void HearingAidAudioSource::Stop() { |
390 | + LOG(INFO) << __func__ << ": Hearing Aid Source Close"; | |
391 | + | |
392 | + localAudioReceiver = nullptr; | |
388 | 393 | if (bluetooth::audio::hearing_aid::is_hal_2_0_enabled()) { |
389 | 394 | bluetooth::audio::hearing_aid::end_session(); |
390 | 395 | } |
@@ -409,6 +414,7 @@ void HearingAidAudioSource::CleanUp() { | ||
409 | 414 | bluetooth::audio::hearing_aid::cleanup(); |
410 | 415 | } else { |
411 | 416 | UIPC_Close(*uipc_hearing_aid, UIPC_CH_ID_ALL); |
417 | + uipc_hearing_aid = nullptr; | |
412 | 418 | } |
413 | 419 | } |
414 | 420 |