OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "media/mojo/interfaces/audio_output.mojom.h" |
| 14 #include "mojo/public/cpp/bindings/interface_request.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 |
| 17 namespace base { |
| 18 class FilePath; |
| 19 } |
| 20 |
| 21 namespace content { |
| 22 |
| 23 class CONTENT_EXPORT AudioOutputStreamImpl : public media::interfaces::AudioOutp
utStream { |
| 24 // All the instance of this class are going to be owned by AudioOutputImpl. |
| 25 public: |
| 26 AudioOutputStreamImpl( |
| 27 media::interfaces::AudioOutputStreamRequest request, |
| 28 int stream_id, |
| 29 AudioRendererHost* audio_renderer_host); |
| 30 |
| 31 ~AudioOutputStreamImpl() override; |
| 32 |
| 33 private: |
| 34 // AudioOutputStream interface implementation. |
| 35 void Close() override; |
| 36 |
| 37 mojo::StrongBinding<media::interfaces::AudioOutputStream> binding_; |
| 38 int stream_id_; |
| 39 // AudioRendererHost is ref counted and AudioOutputImpl holds a reference to |
| 40 // it. And because all AudioOutputStreamImpl instances will be owned by |
| 41 // AudioOutputImpl too, it's safe to access AudioRendererHost from |
| 42 // AudioOutputStreamImpl. |
| 43 // The only issue that could happen is during AudioOutputStreamImpl |
| 44 // destructor. AudioRendererHost cannot access from there. |
| 45 AudioRendererHost* audio_renderer_host_; |
| 46 }; |
| 47 |
| 48 // This class must always be accessed from the creation thread. |
| 49 class CONTENT_EXPORT AudioOutputImpl |
| 50 : NON_EXPORTED_BASE(public media::interfaces::AudioOutput) { |
| 51 public: |
| 52 explicit AudioOutputImpl(scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 53 media::interfaces::AudioOutputRequest request); |
| 54 |
| 55 ~AudioOutputImpl() override; |
| 56 |
| 57 // Create a Mojo service. |
| 58 static void CreateService( |
| 59 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 60 AudioOutputImpl** audio_output_impl, |
| 61 media::interfaces::AudioOutputRequest request); |
| 62 // Initialize Mojo on the BrowserThread::IO. Mojo is going to be bound to |
| 63 // BrowserThread::IO so future Mojo calls will be run on |
| 64 // that thread. |
| 65 static void CreateServiceOnIOThread( |
| 66 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 67 AudioOutputImpl** audio_output_impl, |
| 68 media::interfaces::AudioOutputRequest request); |
| 69 |
| 70 // Called by AudioRendererHost::DoCompleteCreation to create the streams. |
| 71 media::interfaces::AudioOutputStreamPtr* StreamFactory( |
| 72 int stream_id, |
| 73 AudioRendererHost* audio_renderer_host); |
| 74 |
| 75 private: |
| 76 // AudioOutput interface implementation. |
| 77 void CreateStream(int stream_id, |
| 78 int render_frame_id, |
| 79 media::interfaces::AudioOutputStreamParametersPtr params, |
| 80 const CreateStreamCallback& callback) override; |
| 81 |
| 82 // Mojo connection error callback. |
| 83 void OnDisconnect(AudioOutputImpl* impl); |
| 84 |
| 85 scoped_refptr<AudioRendererHost> audio_renderer_host_; |
| 86 mojo::Binding<AudioOutput> binding_; |
| 87 std::map<int, std::unique_ptr<AudioOutputStreamImpl>> stream_impls_; |
| 88 DISALLOW_COPY_AND_ASSIGN(AudioOutputImpl); |
| 89 }; |
| 90 |
| 91 } // namespace content |
| 92 |
| 93 #endif // CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
OLD | NEW |