Commit 3d91603d authored by Kehuang Li's avatar Kehuang Li Committed by Commit Bot

[Chromecast] Impl CaptureServiceReceiver::Stop in a sync way

We got crashes when accessing AudioInputCallback around the time we
Stop/Close CastAudioInputStream. The audio_io.h is ambigeous on if the
impl of Stop should be sync or async, but mostly it should be sync as
AudioOutputStream::Stop. CaptureServiceReceiver::Stop is posted to
another thread, and complete async, which explain the crashes we met.
Therefore, add an internal stop function and let the public Stop wait
for the internal stop completes.

Bug: internal: 143908196
Test: On device and unittests.
Change-Id: I9f6cfbd6457873094ce8c11ec6399b73012526dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898720Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Kehuang Li <kehuangli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712786}
parent f92ba8d5
......@@ -12,6 +12,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "chromecast/media/audio/audio_buildflags.h"
#include "chromecast/media/audio/capture_service/constants.h"
......@@ -236,9 +237,16 @@ void CaptureServiceReceiver::OnConnectTimeout(
}
void CaptureServiceReceiver::Stop() {
ENSURE_ON_IO_THREAD(Stop);
base::WaitableEvent finished;
StopOnTaskRunner(&finished);
finished.Wait();
}
void CaptureServiceReceiver::StopOnTaskRunner(base::WaitableEvent* finished) {
ENSURE_ON_IO_THREAD(StopOnTaskRunner, finished);
connecting_socket_.reset();
socket_.reset();
finished->Signal();
}
void CaptureServiceReceiver::SetTaskRunnerForTest(
......
......@@ -16,6 +16,7 @@
namespace base {
class SequencedTaskRunner;
class WaitableEvent;
} // namespace base
namespace net {
......@@ -56,6 +57,7 @@ class CaptureServiceReceiver {
int result);
void OnConnectTimeout(
::media::AudioInputStream::AudioInputCallback* input_callback);
void StopOnTaskRunner(base::WaitableEvent* finished);
const ::media::AudioParameters audio_params_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment