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 // This class implements AudioOutputStream Mojo interface. It will be used |
| 23 // by the AudioOutputClient to perform operations on audio output streams. |
| 24 // AudioOutputClient will perform operations remotely on the |
| 25 // AudioOutputStreamPtr and Mojo will transfer them to AudioOutputStreamImpl. |
| 26 // Owned by AudioOutputImpl. |
| 27 class CONTENT_EXPORT AudioOutputStreamImpl |
| 28 : public media::mojom::AudioOutputStream { |
| 29 public: |
| 30 AudioOutputStreamImpl(media::mojom::AudioOutputStreamRequest request, |
| 31 int stream_id, |
| 32 AudioRendererHost* audio_renderer_host); |
| 33 |
| 34 ~AudioOutputStreamImpl() override; |
| 35 |
| 36 private: |
| 37 // AudioOutputStream interface implementation. |
| 38 void Close() override; |
| 39 |
| 40 mojo::StrongBinding<media::mojom::AudioOutputStream> binding_; |
| 41 int stream_id_; |
| 42 // AudioRendererHost is ref counted and AudioOutputImpl holds a reference to |
| 43 // it. And because all AudioOutputStreamImpl instances will be owned by |
| 44 // AudioOutputImpl too, it's safe to access AudioRendererHost from |
| 45 // AudioOutputStreamImpl. |
| 46 // The only issue that could happen is during AudioOutputStreamImpl |
| 47 // destructor. AudioRendererHost cannot access from there. |
| 48 AudioRendererHost* audio_renderer_host_; |
| 49 }; |
| 50 |
| 51 // This class implements AudioOutput Mojo interface. It will be used |
| 52 // by the AudioOutputClient to perform operations on audio output streams. |
| 53 // AudioOutputClient is going to perform operations remotely and Mojo will |
| 54 // transfer them to AudioOutputImpl. |
| 55 // This class must always be accessed from the creation thread. |
| 56 class CONTENT_EXPORT AudioOutputImpl |
| 57 : NON_EXPORTED_BASE(public media::mojom::AudioOutput) { |
| 58 public: |
| 59 explicit AudioOutputImpl(scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 60 media::mojom::AudioOutputRequest request); |
| 61 |
| 62 ~AudioOutputImpl() override; |
| 63 |
| 64 // Create a Mojo service. |
| 65 static void CreateService( |
| 66 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 67 media::mojom::AudioOutputRequest request); |
| 68 // Initialize Mojo service on the IO thread. The service is bound to the |
| 69 // IO thread so future Mojo calls performed by the AudioOutputClient to the |
| 70 // AudioOutput interface will be run on that thread. |
| 71 // There are a lot of dependencies used in audio output that require to be |
| 72 // called on the IO thread, this is why we initialize Mojo service on this |
| 73 // thread. There is a plan to enable these dependencies to run on another |
| 74 // thread and move the Mojo service to this thread as IO thread is very |
| 75 // performance sensitive and we want to move stuff off it. |
| 76 static void CreateServiceOnIOThread( |
| 77 scoped_refptr<AudioRendererHost> audio_renderer_host, |
| 78 media::mojom::AudioOutputRequest request); |
| 79 |
| 80 // Called by AudioRendererHost::DoCompleteCreation to create the streams. |
| 81 media::mojom::AudioOutputStreamPtr StreamFactory( |
| 82 int stream_id, |
| 83 AudioRendererHost* audio_renderer_host); |
| 84 |
| 85 private: |
| 86 // AudioOutput interface implementation. |
| 87 void CreateStream(int stream_id, |
| 88 int render_frame_id, |
| 89 media::interfaces::AudioParametersPtr params, |
| 90 const CreateStreamCallback& callback) override; |
| 91 |
| 92 scoped_refptr<AudioRendererHost> audio_renderer_host_; |
| 93 mojo::StrongBinding<AudioOutput> binding_; |
| 94 std::map<int, std::unique_ptr<AudioOutputStreamImpl>> stream_impls_; |
| 95 DISALLOW_COPY_AND_ASSIGN(AudioOutputImpl); |
| 96 }; |
| 97 |
| 98 } // namespace content |
| 99 |
| 100 #endif // CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
OLD | NEW |