OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
6 #define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 6 #define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "media/audio/audio_device_description.h" | 15 #include "media/audio/audio_device_description.h" |
16 #include "media/base/audio_parameters.h" | 16 #include "media/base/audio_parameters.h" |
| 17 #include "media/base/audio_renderer_mixer_pool.h" |
17 #include "media/base/output_device_info.h" | 18 #include "media/base/output_device_info.h" |
18 #include "url/origin.h" | 19 #include "url/origin.h" |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 class AudioHardwareConfig; | |
22 class AudioRendererMixer; | 22 class AudioRendererMixer; |
23 class AudioRendererMixerInput; | 23 class AudioRendererMixerInput; |
24 class AudioRendererSink; | |
25 } | 24 } |
26 | 25 |
27 namespace content { | 26 namespace content { |
| 27 class AudioRendererSinkCache; |
28 | 28 |
29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based | 29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based |
30 // on their AudioParameters configuration. Inputs with the same AudioParameters | 30 // on their AudioParameters configuration. Inputs with the same AudioParameters |
31 // configuration will share a mixer while a new AudioRendererMixer will be | 31 // configuration will share a mixer while a new AudioRendererMixer will be |
32 // lazily created if one with the exact AudioParameters does not exist. | 32 // lazily created if one with the exact AudioParameters does not exist. |
33 // | 33 // |
34 // There should only be one instance of AudioRendererMixerManager per render | 34 // There should only be one instance of AudioRendererMixerManager per render |
35 // thread. | 35 // thread. |
36 // | 36 // |
37 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match | 37 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match |
38 // when we should be able to ignore bits per channel since we're only dealing | 38 // when we should be able to ignore bits per channel since we're only dealing |
39 // with floats. However, bits per channel is currently used to interleave the | 39 // with floats. However, bits per channel is currently used to interleave the |
40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption | 40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption |
41 // via the shared memory. See http://crbug.com/114700. | 41 // via the shared memory. See http://crbug.com/114700. |
42 class CONTENT_EXPORT AudioRendererMixerManager { | 42 class CONTENT_EXPORT AudioRendererMixerManager |
| 43 : public media::AudioRendererMixerPool { |
43 public: | 44 public: |
44 AudioRendererMixerManager(); | 45 ~AudioRendererMixerManager() final; |
45 ~AudioRendererMixerManager(); | 46 |
| 47 static std::unique_ptr<AudioRendererMixerManager> Create(); |
46 | 48 |
47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to | 49 // Creates an AudioRendererMixerInput with the proper callbacks necessary to |
48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. | 50 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. |
49 // |source_render_frame_id| refers to the RenderFrame containing the entity | 51 // |source_render_frame_id| refers to the RenderFrame containing the entity |
50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives | 52 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives |
51 // the returned input. |device_id|, |session_id| and |security_origin| | 53 // the returned input. |device_id|, |session_id| and |security_origin| |
52 // identify the output device to use. If |device_id| is empty and |session_id| | 54 // identify the output device to use. If |device_id| is empty and |session_id| |
53 // is nonzero, output device associated with the opened input device | 55 // is nonzero, output device associated with the opened input device |
54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. | 56 // designated by |session_id| is used. Otherwise, |session_id| is ignored. |
55 media::AudioRendererMixerInput* CreateInput( | 57 media::AudioRendererMixerInput* CreateInput( |
56 int source_render_frame_id, | 58 int source_render_frame_id, |
57 int session_id, | 59 int session_id, |
58 const std::string& device_id, | 60 const std::string& device_id, |
59 const url::Origin& security_origin); | 61 const url::Origin& security_origin); |
60 | 62 |
61 // Returns a mixer instance based on AudioParameters; an existing one if one | 63 // Returns a mixer instance based on AudioParameters; an existing one if one |
62 // with the provided AudioParameters exists or a new one if not. | 64 // with the provided AudioParameters exists or a new one if not. |
63 media::AudioRendererMixer* GetMixer(int source_render_frame_id, | 65 media::AudioRendererMixer* GetMixer( |
64 const media::AudioParameters& params, | 66 int source_render_frame_id, |
65 const std::string& device_id, | 67 const media::AudioParameters& params, |
66 const url::Origin& security_origin, | 68 const std::string& device_id, |
67 media::OutputDeviceStatus* device_status); | 69 const url::Origin& security_origin, |
| 70 media::OutputDeviceStatus* device_status) final; |
68 | 71 |
69 // Remove a mixer instance given a mixer if the only other reference is held | 72 // Remove a mixer instance given a mixer if the only other reference is held |
70 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call | 73 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call |
71 // this method when it's done with a mixer. | 74 // this method when it's done with a mixer. |
72 void RemoveMixer(int source_render_frame_id, | 75 void ReturnMixer(int source_render_frame_id, |
73 const media::AudioParameters& params, | 76 const media::AudioParameters& params, |
74 const std::string& device_id, | 77 const std::string& device_id, |
75 const url::Origin& security_origin); | 78 const url::Origin& security_origin) final; |
| 79 |
| 80 // Returns output device information. This call goes to the sink cache. |
| 81 media::OutputDeviceInfo GetOutputDeviceInfo( |
| 82 int source_render_frame_id, |
| 83 int session_id, |
| 84 const std::string& device_id, |
| 85 const url::Origin& security_origin) final; |
| 86 |
| 87 protected: |
| 88 explicit AudioRendererMixerManager( |
| 89 std::unique_ptr<AudioRendererSinkCache> sink_cache); |
76 | 90 |
77 private: | 91 private: |
78 friend class AudioRendererMixerManagerTest; | 92 friend class AudioRendererMixerManagerTest; |
79 | 93 |
80 // Define a key so that only those AudioRendererMixerInputs from the same | 94 // Define a key so that only those AudioRendererMixerInputs from the same |
81 // RenderView, AudioParameters and output device can be mixed together. | 95 // RenderView, AudioParameters and output device can be mixed together. |
82 struct MixerKey { | 96 struct MixerKey { |
83 MixerKey(int source_render_frame_id, | 97 MixerKey(int source_render_frame_id, |
84 const media::AudioParameters& params, | 98 const media::AudioParameters& params, |
85 const std::string& device_id, | 99 const std::string& device_id, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 135 } |
122 }; | 136 }; |
123 | 137 |
124 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows | 138 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows |
125 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which | 139 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which |
126 // is implicit) of the number of outstanding AudioRendererMixers. | 140 // is implicit) of the number of outstanding AudioRendererMixers. |
127 struct AudioRendererMixerReference { | 141 struct AudioRendererMixerReference { |
128 media::AudioRendererMixer* mixer; | 142 media::AudioRendererMixer* mixer; |
129 int ref_count; | 143 int ref_count; |
130 }; | 144 }; |
131 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> | 145 using AudioRendererMixerMap = |
132 AudioRendererMixerMap; | 146 std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare>; |
133 | 147 |
134 // Active mixers. | 148 // Active mixers. |
135 AudioRendererMixerMap mixers_; | 149 AudioRendererMixerMap mixers_; |
136 base::Lock mixers_lock_; | 150 base::Lock mixers_lock_; |
137 | 151 |
| 152 // Mixer sink cache. |
| 153 const std::unique_ptr<AudioRendererSinkCache> sink_cache_; |
| 154 |
138 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 155 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
139 }; | 156 }; |
140 | 157 |
141 } // namespace content | 158 } // namespace content |
142 | 159 |
143 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 160 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
OLD | NEW |