Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(814)

Unified Diff: content/renderer/media/audio_output_client.h

Issue 1930393002: Switch stream creation and closing in Chrome audio rendering from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unique_ptr for Binding Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_output_client.h
diff --git a/content/renderer/media/audio_output_client.h b/content/renderer/media/audio_output_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..3d056714e420dfbd60b67e569e6f43db8a7f5dc3
--- /dev/null
+++ b/content/renderer/media/audio_output_client.h
@@ -0,0 +1,117 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_
+#define CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_
+
+#include <map>
+
+#include "base/files/file.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/shared_memory_handle.h"
+#include "base/message_loop/message_loop.h"
+#include "base/sync_socket.h"
+#include "base/threading/thread_checker.h"
+#include "content/common/content_export.h"
+#include "media/mojo/interfaces/audio_output.mojom.h"
+#include "mojo/edk/embedder/embedder.h"
+#include "mojo/public/c/system/buffer.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/public/cpp/system/handle.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace media {
+class AudioParameters;
+}
+
+namespace content {
+
+class AudioMessageFilter;
+class ServiceRegistry;
+
+class CONTENT_EXPORT AudioOutputClient
+ : public base::RefCounted<AudioOutputClient> {
+ public:
+ using AudioOutputStreamPtrMap =
+ std::map<int, media::mojom::AudioOutputStreamPtr>;
+
+ // Creates a Mojo Audio Output Client. It's going to be created by
+ // RenderThreadImpl::Init() and be bound to RenderThread. This means that all
+ // future Mojo service calls and all Mojo callbacks are going to be
+ // performed on the RenderThread.
+ explicit AudioOutputClient(
+ ServiceRegistry* service_registry,
+ const scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner =
+ base::MessageLoop::current()->task_runner());
+
+ // Creates stream by calling the AudioOutput.CreateStream Mojo interface
+ // function using the Mojo service. This function could be called on any
+ // thread and is going to call itself in the RenderThread if it's not
+ // already running there.
+ void CreateStream(int stream_id,
+ const media::AudioParameters& params,
+ const media::mojom::AudioOutput::CreateStreamCallback&
+ create_stream_callback);
+
+ // Callback for AudioOutput.CreateStream which contains information about
+ // the new created stream. Called on RenderThread. This function is going to
+ // notify the |audio_message_filter_| of the stream creation by calling
+ // StreamCreated. StreamCreated could only be ran on |io_task_runner_| and
+ // this is why CreateStreamOnIOThread is going to be used to do that.
+ void CreateStreamCallback(int stream_id,
+ media::mojom::AudioOutputStreamPtr stream,
+ mojo::ScopedSharedBufferHandle shared_buffer,
+ mojo::ScopedHandle socket_descriptor);
+
+ // Closes stream by calling the AudioOutputStream.Close Mojo interface
+ // function using the Mojo service. This function could be called on any
+ // thread and is going to call itself in the RenderThread if it's not
+ // already running there.
+ void CloseStream(int stream_id);
+
+ private:
+ friend class base::RefCounted<AudioOutputClient>;
+ friend class AudioOutputClientTest;
+ FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, CreateStream);
+ FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest,
+ CloseAuthorizedNotCreatedStream);
+ FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, CloseCreatedStream);
+
+ ~AudioOutputClient();
+
+ static void Reset(media::mojom::AudioOutputPtr* service);
+
+ // Notifies the |audio_message_filter_| of the stream creation. Can only be
+ // called on |io_task_runner_|.
+ void CreateStreamOnIOThread(
+ AudioOutputClient::AudioOutputStreamPtrMap::iterator stream,
+ base::SharedMemoryHandle handle,
+ base::SyncSocket::TransitDescriptor socket_descriptor,
+ uint32_t length);
+
+ // Called when there is an error with AudioOutputStream Mojo interface in
+ // the renderer. This function is going to call ReportErrorOnIOThread in the
+ // RenderThread.
+ void OnStreamError(int stream_id);
+
+ // Notifies the |audio_message_filter_| of a stream error. Can only be called
+ // on |io_task_runner_|.
+ void ReportErrorOnIOThread(int stream_id);
+
+ const scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner_;
+ media::mojom::AudioOutputPtr* service_;
+ AudioOutputStreamPtrMap streams_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputClient);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_
« no previous file with comments | « content/renderer/media/audio_message_filter_unittest.cc ('k') | content/renderer/media/audio_output_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698