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/sync_socket.h" |
| 10 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 11 #include "media/mojo/interfaces/audio_output.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 14 |
| 15 namespace base { |
| 16 class SharedMemory; |
| 17 } |
| 18 |
| 19 namespace content { |
| 20 class AudioOutputStreamImpl; |
| 21 class RenderFrameHostImpl; |
| 22 |
| 23 // This class implements AudioOutput Mojo interface. It is connected to |
| 24 // the AudioOutputClient to perform operations on audio output streams. |
| 25 // AudioOutputClient is going to perform operations remotely and Mojo is |
| 26 // transfer them to AudioOutputImpl. |
| 27 // This class must always be accessed from the creation thread. |
| 28 class CONTENT_EXPORT AudioOutputImpl |
| 29 : NON_EXPORTED_BASE(public media::mojom::AudioOutput) { |
| 30 public: |
| 31 explicit AudioOutputImpl(RenderFrameHostImpl* frame, |
| 32 media::mojom::AudioOutputRequest request); |
| 33 |
| 34 ~AudioOutputImpl() override; |
| 35 |
| 36 // Creates a Mojo service. |
| 37 static void CreateService(RenderFrameHostImpl* frame, |
| 38 media::mojom::AudioOutputRequest request); |
| 39 |
| 40 // Initializes Mojo service on the IO thread. The service is bound to the |
| 41 // IO thread so future Mojo calls performed by the AudioOutputClient to the |
| 42 // AudioOutput interface will be run on that thread. |
| 43 // There are a lot of dependencies used in audio output that require to be |
| 44 // called on the IO thread, this is why we initialize Mojo service on this |
| 45 // thread. |
| 46 static void CreateServiceOnIOThread(RenderFrameHostImpl* frame, |
| 47 media::mojom::AudioOutputRequest request); |
| 48 void Reset(); |
| 49 |
| 50 // Called by AudioRendererHost::DoCompleteCreation to create the streams. |
| 51 virtual void CreateStreamFactory( |
| 52 int stream_id, |
| 53 base::SharedMemory* shared_memory, |
| 54 base::SyncSocket::TransitDescriptor socket_descriptor); |
| 55 |
| 56 virtual bool CloseStream(int stream_id); |
| 57 |
| 58 // Sends an error message to the renderer, then close the stream. |
| 59 virtual void ReportErrorAndCloseStream(int stream_id); |
| 60 |
| 61 private: |
| 62 friend class AudioOutputImplTest; |
| 63 friend class MockAudioOutputImpl; |
| 64 FRIEND_TEST_ALL_PREFIXES(AudioOutputImplTest, CreateStream); |
| 65 FRIEND_TEST_ALL_PREFIXES(AudioOutputImplTest, StreamFactory); |
| 66 FRIEND_TEST_ALL_PREFIXES(AudioOutputImplTest, RemoveStream); |
| 67 |
| 68 // AudioOutput interface implementation. |
| 69 void CreateStream(int stream_id, |
| 70 const media::AudioParameters& params, |
| 71 const CreateStreamCallback& callback) override; |
| 72 |
| 73 void InitAudioRendererHost(); |
| 74 |
| 75 RenderFrameHostImpl* frame_; |
| 76 std::unique_ptr<mojo::Binding<AudioOutput>> binding_; |
| 77 scoped_refptr<AudioRendererHost> audio_renderer_host_; |
| 78 // Maps from |stream_id| to AudioOutputStreamImpl. |
| 79 std::map<int, std::unique_ptr<AudioOutputStreamImpl>> stream_impls_; |
| 80 // Maps from |stream_id| to CreateStreamCallback. |
| 81 std::map<int, media::mojom::AudioOutput::CreateStreamCallback> |
| 82 create_stream_callbacks_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(AudioOutputImpl); |
| 85 }; |
| 86 |
| 87 } // namespace content |
| 88 |
| 89 #endif // CONTENT_BROWSER_MEDIA_AUDIO_OUTPUT_IMPL_H_ |
OLD | NEW |