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..121de052c9af0418693fbb3efbad86e87ca1417c |
--- /dev/null |
+++ b/content/renderer/media/audio_output_client.h |
@@ -0,0 +1,115 @@ |
+// 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/scoped_ptr.h" |
+#include "base/memory/shared_memory_handle.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/public/cpp/bindings/binding.h" |
+#include "mojo/public/cpp/bindings/interface_request.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} |
+ |
+namespace media { |
+class AudioParameters; |
+} |
+ |
+namespace content { |
+ |
+class AudioMessageFilter; |
+class ServiceRegistry; |
+ |
+class CONTENT_EXPORT AudioOutputClient { |
+ public: |
+ typedef std::map<int, scoped_ptr<mojom::AudioOutputStreamPtr>> |
+ ScopedAudioOutputStreamPtrMap; |
+ |
+ // Create 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, |
+ scoped_refptr<AudioMessageFilter> audio_message_filter); |
+ |
+ ~AudioOutputClient(); |
+ |
+ // Create 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 CreateStreamOnMainThread in the RenderThread. |
+ void CreateStream(int stream_id, |
+ int render_frame_id, |
+ const media::AudioParameters& params); |
+ |
+ // Create stream by calling the AudioOutput.CreateStream Mojo interface |
+ // function using the Mojo service. This function could be called on just |
+ // the RenderThread. |
+ void CreateStreamOnMainThread(int stream_id, |
+ int render_frame_id, |
+ const media::AudioParameters& params); |
+ |
+ // 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, |
+ mojom::AudioOutputStreamPtr stream, |
+ mojo::ScopedSharedBufferHandle shared_buffer, |
+ mojo::ScopedHandle socket_descriptor); |
+ |
+ // Notify the |audio_message_filter_| of the stream creation. Can only be |
+ // called on |io_task_runner_|. |
+ void CreateStreamOnIOThread( |
+ mojom::AudioOutputStreamPtr* const stream, |
+ base::SharedMemoryHandle handle, |
+ base::SyncSocket::TransitDescriptor socket_descriptor, |
+ uint32_t length); |
+ |
+ // Close 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 CloseStreamOnMainThread in the RenderThread. |
+ void CloseStream(int stream_id); |
+ |
+ // Close stream by calling the AudioOutputStream.Close Mojo interface |
+ // function using the Mojo service. This function could be called on just the |
+ // RenderThread. |
+ void CloseStreamOnMainThread(int stream_id); |
+ |
+ // 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); |
+ |
+ // Notify the |audio_message_filter_| of a stream error. Can only be called |
+ // on |io_task_runner_|. |
+ void ReportErrorOnIOThread(int stream_id); |
+ |
+ private: |
+ // Mojo connection error handler. |
+ void OnConnectionError(); |
+ |
+ scoped_refptr<AudioMessageFilter> audio_message_filter_; |
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
+ // The Mojo service. |
+ mojom::AudioOutputPtr service_; |
+ ScopedAudioOutputStreamPtrMap streams_; |
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputClient); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |