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_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/files/file.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/shared_memory_handle.h" |
| 14 #include "base/sync_socket.h" |
| 15 #include "base/threading/thread_checker.h" |
| 16 #include "content/common/content_export.h" |
| 17 #include "media/mojo/interfaces/audio_output.mojom.h" |
| 18 #include "mojo/edk/embedder/embedder.h" |
| 19 #include "mojo/public/c/system/buffer.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" |
| 21 #include "mojo/public/cpp/bindings/binding.h" |
| 22 #include "mojo/public/cpp/bindings/interface_request.h" |
| 23 #include "mojo/public/cpp/system/handle.h" |
| 24 |
| 25 namespace base { |
| 26 class SingleThreadTaskRunner; |
| 27 } |
| 28 |
| 29 namespace media { |
| 30 class AudioParameters; |
| 31 } |
| 32 |
| 33 namespace content { |
| 34 |
| 35 class AudioMessageFilter; |
| 36 class ServiceRegistry; |
| 37 |
| 38 class CONTENT_EXPORT AudioOutputClient { |
| 39 public: |
| 40 typedef std::map<int, |
| 41 std::unique_ptr<media::mojom::AudioOutputStreamPtr>> |
| 42 ScopedAudioOutputStreamPtrMap; |
| 43 |
| 44 // Create a Mojo Audio Output Client. It's going to be created by |
| 45 // RenderThreadImpl::init and be bound to RenderThread. This means that all |
| 46 // future Mojo service calls and all Mojo callbacks are going to be |
| 47 // performed on the RenderThread. |
| 48 explicit AudioOutputClient( |
| 49 ServiceRegistry* service_registry, |
| 50 scoped_refptr<AudioMessageFilter> audio_message_filter); |
| 51 |
| 52 ~AudioOutputClient(); |
| 53 |
| 54 // Create stream by calling the AudioOutput.CreateStream Mojo interface |
| 55 // function using the Mojo service. This function could be called on any |
| 56 // thread and is going to call CreateStreamOnMainThread in the RenderThread. |
| 57 void CreateStream(int stream_id, |
| 58 int render_frame_id, |
| 59 const media::AudioParameters& params); |
| 60 |
| 61 // Create stream by calling the AudioOutput.CreateStream Mojo interface |
| 62 // function using the Mojo service. This function could be called on just |
| 63 // the RenderThread. |
| 64 void CreateStreamOnMainThread(int stream_id, |
| 65 int render_frame_id, |
| 66 const media::AudioParameters& params); |
| 67 |
| 68 // Callback for AudioOutput.CreateStream which contains information about |
| 69 // the new created stream. Called on RenderThread. This function is going to |
| 70 // notify the |audio_message_filter_| of the stream creation by calling |
| 71 // StreamCreated. StreamCreated could only be ran on |io_task_runner_| and |
| 72 // this is why CreateStreamOnIOThread is going to be used to do that. |
| 73 void CreateStreamCallback(int stream_id, |
| 74 media::mojom::AudioOutputStreamPtr stream, |
| 75 mojo::ScopedSharedBufferHandle shared_buffer, |
| 76 mojo::ScopedHandle socket_descriptor); |
| 77 |
| 78 // Notify the |audio_message_filter_| of the stream creation. Can only be |
| 79 // called on |io_task_runner_|. |
| 80 void CreateStreamOnIOThread( |
| 81 media::mojom::AudioOutputStreamPtr* const stream, |
| 82 base::SharedMemoryHandle handle, |
| 83 base::SyncSocket::TransitDescriptor socket_descriptor, |
| 84 uint32_t length); |
| 85 |
| 86 // Close stream by calling the AudioOutputStream.Close Mojo interface |
| 87 // function using the Mojo service. This function could be called on any |
| 88 // thread and is going to call CloseStreamOnMainThread in the RenderThread. |
| 89 void CloseStream(int stream_id); |
| 90 |
| 91 // Close stream by calling the AudioOutputStream.Close Mojo interface |
| 92 // function using the Mojo service. This function could be called on just the |
| 93 // RenderThread. |
| 94 void CloseStreamOnMainThread(int stream_id); |
| 95 |
| 96 // Called when there is an error with AudioOutputStream Mojo interface in |
| 97 // the renderer. This function is going to call ReportErrorOnIOThread in the |
| 98 // RenderThread. |
| 99 void OnStreamError(int stream_id); |
| 100 |
| 101 // Notify the |audio_message_filter_| of a stream error. Can only be called |
| 102 // on |io_task_runner_|. |
| 103 void ReportErrorOnIOThread(int stream_id); |
| 104 |
| 105 private: |
| 106 // Mojo connection error handler. |
| 107 void OnConnectionError(); |
| 108 |
| 109 scoped_refptr<AudioMessageFilter> audio_message_filter_; |
| 110 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 111 // The Mojo service. |
| 112 media::mojom::AudioOutputPtr service_; |
| 113 ScopedAudioOutputStreamPtrMap streams_; |
| 114 DISALLOW_COPY_AND_ASSIGN(AudioOutputClient); |
| 115 }; |
| 116 |
| 117 } // namespace content |
| 118 |
| 119 #endif // CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |
OLD | NEW |