| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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_IPC_FACTORY_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/containers/flat_map.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h" |
| 13 |
| 14 namespace base { |
| 15 class SingleThreadTaskRunner; |
| 16 } |
| 17 |
| 18 namespace media { |
| 19 class AudioOutputIPC; |
| 20 } |
| 21 |
| 22 namespace service_manager { |
| 23 class InterfaceProvider; |
| 24 } |
| 25 |
| 26 namespace content { |
| 27 |
| 28 class AudioMessageFilter; |
| 29 |
| 30 // This is a factory for AudioOutputIPC objects. It has two modes, using either |
| 31 // AudioMessageFilter or Mojo RendererAudioOutputStreamFactory objects. This |
| 32 // class is intended to not be destructed. The functions of this class be called |
| 33 // on any thread. |
| 34 class AudioIPCFactory { |
| 35 public: |
| 36 AudioIPCFactory( |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 38 ~AudioIPCFactory(); |
| 39 |
| 40 static AudioIPCFactory* get() { return instance_; } |
| 41 |
| 42 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { |
| 43 return io_task_runner_; |
| 44 } |
| 45 |
| 46 // Enables |this| to create MojoAudioOutputIPCs for the specified frame. |
| 47 void MaybeRegisterRemoteFactory( |
| 48 int frame_id, |
| 49 service_manager::InterfaceProvider* interface_provider); |
| 50 |
| 51 // Every call to the above method must be matched by a call to this one when |
| 52 // the frame is destroyed. |
| 53 void MaybeDeregisterRemoteFactory(int frame_id); |
| 54 |
| 55 // The returned object may only be used on |io_task_runner()|. |
| 56 std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC( |
| 57 int frame_id) const; |
| 58 |
| 59 private: |
| 60 using StreamFactoryMap = |
| 61 base::flat_map<int, mojom::RendererAudioOutputStreamFactoryPtr>; |
| 62 |
| 63 mojom::RendererAudioOutputStreamFactory* GetRemoteFactory(int frame_id) const; |
| 64 |
| 65 void RegisterRemoteFactoryOnIOThread( |
| 66 int frame_id, |
| 67 mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info); |
| 68 |
| 69 // Indicates whether mojo factories are used. |
| 70 bool UsingMojoFactories() const; |
| 71 |
| 72 // Maps frame id to the corresponding factory. |
| 73 StreamFactoryMap factory_ptrs_; |
| 74 |
| 75 // If this is non-null, it will be used rather than using mojo implementation. |
| 76 const scoped_refptr<AudioMessageFilter> audio_message_filter_; |
| 77 |
| 78 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 79 |
| 80 // Global instance, set in constructor and unset in destructor. |
| 81 static AudioIPCFactory* instance_; |
| 82 }; |
| 83 |
| 84 } // namespace content |
| 85 |
| 86 #endif // CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_ |
| OLD | NEW |