Index: content/browser/media/audio_output_impl.h |
diff --git a/content/browser/media/audio_output_impl.h b/content/browser/media/audio_output_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6517fd8c0bfd0617c76d819c37b5ee153c2c490a |
--- /dev/null |
+++ b/content/browser/media/audio_output_impl.h |
@@ -0,0 +1,93 @@ |
+// 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_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
+#define CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
+ |
+#include "base/callback.h" |
+#include "base/compiler_specific.h" |
+#include "base/memory/ref_counted.h" |
+#include "content/browser/renderer_host/media/audio_renderer_host.h" |
+#include "content/common/content_export.h" |
+#include "media/mojo/interfaces/audio_output.mojom.h" |
+#include "mojo/public/cpp/bindings/interface_request.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+ |
+namespace base { |
+class FilePath; |
+} |
+ |
+namespace content { |
+ |
+class CONTENT_EXPORT AudioOutputStreamImpl : public media::interfaces::AudioOutputStream { |
+ // All the instance of this class are going to be owned by AudioOutputImpl. |
+ public: |
+ AudioOutputStreamImpl( |
+ media::interfaces::AudioOutputStreamRequest request, |
+ int stream_id, |
+ AudioRendererHost* audio_renderer_host); |
+ |
+ ~AudioOutputStreamImpl() override; |
+ |
+ private: |
+ // AudioOutputStream interface implementation. |
+ void Close() override; |
+ |
+ mojo::StrongBinding<media::interfaces::AudioOutputStream> binding_; |
+ int stream_id_; |
+ // AudioRendererHost is ref counted and AudioOutputImpl holds a reference to |
+ // it. And because all AudioOutputStreamImpl instances will be owned by |
+ // AudioOutputImpl too, it's safe to access AudioRendererHost from |
+ // AudioOutputStreamImpl. |
+ // The only issue that could happen is during AudioOutputStreamImpl |
+ // destructor. AudioRendererHost cannot access from there. |
+ AudioRendererHost* audio_renderer_host_; |
+}; |
+ |
+// This class must always be accessed from the creation thread. |
+class CONTENT_EXPORT AudioOutputImpl |
+ : NON_EXPORTED_BASE(public media::interfaces::AudioOutput) { |
+ public: |
+ explicit AudioOutputImpl(scoped_refptr<AudioRendererHost> audio_renderer_host, |
+ media::interfaces::AudioOutputRequest request); |
+ |
+ ~AudioOutputImpl() override; |
+ |
+ // Create a Mojo service. |
+ static void CreateService( |
+ scoped_refptr<AudioRendererHost> audio_renderer_host, |
+ AudioOutputImpl** audio_output_impl, |
+ media::interfaces::AudioOutputRequest request); |
+ // Initialize Mojo on the BrowserThread::IO. Mojo is going to be bound to |
+ // BrowserThread::IO so future Mojo calls will be run on |
+ // that thread. |
+ static void CreateServiceOnIOThread( |
+ scoped_refptr<AudioRendererHost> audio_renderer_host, |
+ AudioOutputImpl** audio_output_impl, |
+ media::interfaces::AudioOutputRequest request); |
+ |
+ // Called by AudioRendererHost::DoCompleteCreation to create the streams. |
+ media::interfaces::AudioOutputStreamPtr* StreamFactory( |
+ int stream_id, |
+ AudioRendererHost* audio_renderer_host); |
+ |
+ private: |
+ // AudioOutput interface implementation. |
+ void CreateStream(int stream_id, |
+ int render_frame_id, |
+ media::interfaces::AudioOutputStreamParametersPtr params, |
+ const CreateStreamCallback& callback) override; |
+ |
+ // Mojo connection error callback. |
+ void OnDisconnect(AudioOutputImpl* impl); |
+ |
+ scoped_refptr<AudioRendererHost> audio_renderer_host_; |
+ mojo::Binding<AudioOutput> binding_; |
+ std::map<int, std::unique_ptr<AudioOutputStreamImpl>> stream_impls_; |
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputImpl); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |