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