Commit 9acaaa43 authored by Olga Sharonova's avatar Olga Sharonova Committed by Commit Bot

Allow blocking when audio::OutputDevice joins the audio thread.


BUG=858987

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ic61830a546ffe6873fef4db18a49d03031293fe7
Reviewed-on: https://chromium-review.googlesource.com/1119914Reviewed-by: default avatarMarina Ciocea <marinaciocea@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Commit-Queue: Olga Sharonova <olka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577832}
parent 1adb2564
...@@ -20,7 +20,9 @@ class AwFormDatabaseService; ...@@ -20,7 +20,9 @@ class AwFormDatabaseService;
class CookieManager; class CookieManager;
class ScopedAllowInitGLBindings; class ScopedAllowInitGLBindings;
} }
namespace audio {
class OutputDevice;
}
namespace cc { namespace cc {
class CompletionEvent; class CompletionEvent;
class SingleThreadTaskGraphRunner; class SingleThreadTaskGraphRunner;
...@@ -249,6 +251,7 @@ class BASE_EXPORT ScopedAllowBlocking { ...@@ -249,6 +251,7 @@ class BASE_EXPORT ScopedAllowBlocking {
// in unit tests to avoid the friend requirement. // in unit tests to avoid the friend requirement.
FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest, ScopedAllowBlocking); FRIEND_TEST_ALL_PREFIXES(ThreadRestrictionsTest, ScopedAllowBlocking);
friend class android_webview::ScopedAllowInitGLBindings; friend class android_webview::ScopedAllowInitGLBindings;
friend class audio::OutputDevice;
friend class content::BrowserProcessSubThread; friend class content::BrowserProcessSubThread;
friend class content::GpuProcessTransportFactory; friend class content::GpuProcessTransportFactory;
friend class cronet::CronetPrefsManager; friend class cronet::CronetPrefsManager;
......
...@@ -72,6 +72,7 @@ class MEDIA_EXPORT AudioDeviceThread : public base::PlatformThread::Delegate { ...@@ -72,6 +72,7 @@ class MEDIA_EXPORT AudioDeviceThread : public base::PlatformThread::Delegate {
// This tells the audio thread to stop and clean up the data; this is a // This tells the audio thread to stop and clean up the data; this is a
// synchronous process and the thread will stop before the method returns. // synchronous process and the thread will stop before the method returns.
// Blocking call, see base/threading/thread_restrictions.h.
~AudioDeviceThread() override; ~AudioDeviceThread() override;
private: private:
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "base/threading/thread_restrictions.h"
#include "media/audio/audio_output_device_thread_callback.h" #include "media/audio/audio_output_device_thread_callback.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
#include "services/audio/public/mojom/constants.mojom.h" #include "services/audio/public/mojom/constants.mojom.h"
...@@ -27,8 +28,8 @@ OutputDevice::OutputDevice( ...@@ -27,8 +28,8 @@ OutputDevice::OutputDevice(
media::mojom::AudioOutputStreamRequest stream_request = media::mojom::AudioOutputStreamRequest stream_request =
mojo::MakeRequest(&stream_); mojo::MakeRequest(&stream_);
stream_.set_connection_error_handler( stream_.set_connection_error_handler(base::BindOnce(
base::BindOnce(&OutputDevice::CleanUp, weak_factory_.GetWeakPtr())); &OutputDevice::OnConnectionError, weak_factory_.GetWeakPtr()));
stream_factory_->CreateOutputStream( stream_factory_->CreateOutputStream(
std::move(stream_request), nullptr, nullptr, device_id, params, std::move(stream_request), nullptr, nullptr, device_id, params,
base::UnguessableToken::Create(), base::UnguessableToken::Create(),
...@@ -68,16 +69,25 @@ void OutputDevice::StreamCreated( ...@@ -68,16 +69,25 @@ void OutputDevice::StreamCreated(
data_pipe->shared_memory; data_pipe->shared_memory;
DCHECK(shared_memory_region.IsValid()); DCHECK(shared_memory_region.IsValid());
audio_callback_.reset(new media::AudioOutputDeviceThreadCallback( DCHECK(!audio_callback_);
audio_parameters_, std::move(shared_memory_region), render_callback_)); DCHECK(!audio_thread_);
audio_thread_.reset(new media::AudioDeviceThread( audio_callback_ = std::make_unique<media::AudioOutputDeviceThreadCallback>(
audio_parameters_, std::move(shared_memory_region), render_callback_);
audio_thread_ = std::make_unique<media::AudioDeviceThread>(
audio_callback_.get(), socket_handle, "audio::OutputDevice", audio_callback_.get(), socket_handle, "audio::OutputDevice",
base::ThreadPriority::REALTIME_AUDIO)); base::ThreadPriority::REALTIME_AUDIO);
}
void OutputDevice::OnConnectionError() {
// Connection errors should be rare and handling them synchronously is
// simpler.
base::ScopedAllowBlocking allow_blocking;
CleanUp();
} }
void OutputDevice::CleanUp() { void OutputDevice::CleanUp() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
audio_thread_.reset(); audio_thread_.reset(); // Blocking call.
audio_callback_.reset(); audio_callback_.reset();
stream_.reset(); stream_.reset();
stream_factory_.reset(); stream_factory_.reset();
......
...@@ -22,10 +22,13 @@ namespace audio { ...@@ -22,10 +22,13 @@ namespace audio {
class OutputDevice { class OutputDevice {
public: public:
// media::AudioRendererSink::RenderCallback must outlive |this|.
OutputDevice(std::unique_ptr<service_manager::Connector> connector, OutputDevice(std::unique_ptr<service_manager::Connector> connector,
const media::AudioParameters& params, const media::AudioParameters& params,
media::AudioRendererSink::RenderCallback* callback, media::AudioRendererSink::RenderCallback* callback,
const std::string& device_id); const std::string& device_id);
// Blocking call; see base/threading/thread_restrictions.h.
~OutputDevice(); ~OutputDevice();
void Play(); void Play();
...@@ -34,7 +37,8 @@ class OutputDevice { ...@@ -34,7 +37,8 @@ class OutputDevice {
private: private:
void StreamCreated(media::mojom::ReadWriteAudioDataPipePtr data_pipe); void StreamCreated(media::mojom::ReadWriteAudioDataPipePtr data_pipe);
void CleanUp(); void OnConnectionError();
void CleanUp(); // Blocking call.
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
......
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