Chromium Code Reviews| 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 | |
|
mcasas
2016/04/29 18:29:00
Either spin this class into a file on
its own, or
Henrik Grunell
2016/05/02 12:12:22
Agree, put in its own file.
rchtara
2016/05/23 16:38:17
Done.
rchtara
2016/05/23 16:38:17
Done.
| |
| 28 : public media::interfaces::AudioOutputStream { | |
| 29 public: | |
| 30 AudioOutputStreamImpl(media::interfaces::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::interfaces::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::interfaces::AudioOutput) { | |
| 58 public: | |
| 59 explicit AudioOutputImpl(scoped_refptr<AudioRendererHost> audio_renderer_host, | |
| 60 media::interfaces::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::interfaces::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::interfaces::AudioOutputRequest request); | |
| 79 | |
| 80 // Called by AudioRendererHost::DoCompleteCreation to create the streams. | |
| 81 media::interfaces::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::AudioOutputStreamParametersPtr 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 |