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; | 24 class AudioRendererSink; |
25 } | 25 } |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 class AudioRendererSinkCache; | |
28 | 29 |
29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based | 30 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based |
30 // on their AudioParameters configuration. Inputs with the same AudioParameters | 31 // on their AudioParameters configuration. Inputs with the same AudioParameters |
31 // configuration will share a mixer while a new AudioRendererMixer will be | 32 // configuration will share a mixer while a new AudioRendererMixer will be |
32 // lazily created if one with the exact AudioParameters does not exist. | 33 // lazily created if one with the exact AudioParameters does not exist. |
33 // | 34 // |
34 // There should only be one instance of AudioRendererMixerManager per render | 35 // There should only be one instance of AudioRendererMixerManager per render |
35 // thread. | 36 // thread. |
36 // | 37 // |
37 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match | 38 // 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 | 39 // 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 | 40 // with floats. However, bits per channel is currently used to interleave the |
40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption | 41 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption |
41 // via the shared memory. See http://crbug.com/114700. | 42 // via the shared memory. See http://crbug.com/114700. |
42 class CONTENT_EXPORT AudioRendererMixerManager { | 43 class CONTENT_EXPORT AudioRendererMixerManager |
44 : public media::AudioRendererMixerPool { | |
43 public: | 45 public: |
44 AudioRendererMixerManager(); | 46 ~AudioRendererMixerManager() final; |
45 ~AudioRendererMixerManager(); | 47 |
48 static std::unique_ptr<AudioRendererMixerManager> Create(); | |
46 | 49 |
47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to | 50 // Creates an AudioRendererMixerInput with the proper callbacks necessary to |
48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. | 51 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. |
49 // |source_render_frame_id| refers to the RenderFrame containing the entity | 52 // |source_render_frame_id| refers to the RenderFrame containing the entity |
50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives | 53 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives |
51 // the returned input. |device_id|, |session_id| and |security_origin| | 54 // 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| | 55 // 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 | 56 // is nonzero, output device associated with the opened input device |
54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. | 57 // designated by |session_id| is used. Otherwise, |session_id| is ignored. |
55 media::AudioRendererMixerInput* CreateInput( | 58 media::AudioRendererMixerInput* CreateInput( |
56 int source_render_frame_id, | 59 int source_render_frame_id, |
57 int session_id, | 60 int session_id, |
58 const std::string& device_id, | 61 const std::string& device_id, |
59 const url::Origin& security_origin); | 62 const url::Origin& security_origin); |
60 | 63 |
61 // Returns a mixer instance based on AudioParameters; an existing one if one | 64 // Returns a mixer instance based on AudioParameters; an existing one if one |
Guido Urdaneta
2016/05/25 13:33:13
Since GetMixer and ReturnMixer are now implementat
o1ka
2016/05/25 14:52:11
This comment contains implementation details not e
Guido Urdaneta
2016/05/25 15:44:09
I think the comments at the top of the class toget
o1ka
2016/05/26 09:00:27
Done.
| |
62 // with the provided AudioParameters exists or a new one if not. | 65 // with the provided AudioParameters exists or a new one if not. |
63 media::AudioRendererMixer* GetMixer(int source_render_frame_id, | 66 media::AudioRendererMixer* GetMixer( |
64 const media::AudioParameters& params, | 67 int source_render_frame_id, |
65 const std::string& device_id, | 68 const media::AudioParameters& params, |
66 const url::Origin& security_origin, | 69 const std::string& device_id, |
67 media::OutputDeviceStatus* device_status); | 70 const url::Origin& security_origin, |
71 media::OutputDeviceStatus* device_status) final; | |
68 | 72 |
69 // Remove a mixer instance given a mixer if the only other reference is held | 73 // Remove a mixer instance given a mixer if the only other reference is held |
70 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call | 74 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call |
71 // this method when it's done with a mixer. | 75 // this method when it's done with a mixer. |
72 void RemoveMixer(int source_render_frame_id, | 76 void ReturnMixer(int source_render_frame_id, |
73 const media::AudioParameters& params, | 77 const media::AudioParameters& params, |
74 const std::string& device_id, | 78 const std::string& device_id, |
75 const url::Origin& security_origin); | 79 const url::Origin& security_origin) final; |
80 | |
81 // Returns output device information. This call goes to the sink cache. | |
Guido Urdaneta
2016/05/25 13:33:13
Nit: So far, the sink cache has not been mentioned
o1ka
2016/05/25 14:52:11
changed to |sink_cache_| which is mentioned here.
| |
82 media::OutputDeviceInfo GetOutputDeviceInfo( | |
83 int source_render_frame_id, | |
84 int session_id, | |
85 const std::string& device_id, | |
86 const url::Origin& security_origin) final; | |
87 | |
88 protected: | |
89 explicit AudioRendererMixerManager( | |
90 std::unique_ptr<AudioRendererSinkCache> sink_cache); | |
76 | 91 |
77 private: | 92 private: |
78 friend class AudioRendererMixerManagerTest; | 93 friend class AudioRendererMixerManagerTest; |
79 | 94 |
80 // Define a key so that only those AudioRendererMixerInputs from the same | 95 // Define a key so that only those AudioRendererMixerInputs from the same |
81 // RenderView, AudioParameters and output device can be mixed together. | 96 // RenderView, AudioParameters and output device can be mixed together. |
82 struct MixerKey { | 97 struct MixerKey { |
83 MixerKey(int source_render_frame_id, | 98 MixerKey(int source_render_frame_id, |
84 const media::AudioParameters& params, | 99 const media::AudioParameters& params, |
85 const std::string& device_id, | 100 const std::string& device_id, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 return a.security_origin < b.security_origin; | 135 return a.security_origin < b.security_origin; |
121 } | 136 } |
122 }; | 137 }; |
123 | 138 |
124 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows | 139 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows |
125 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which | 140 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which |
126 // is implicit) of the number of outstanding AudioRendererMixers. | 141 // is implicit) of the number of outstanding AudioRendererMixers. |
127 struct AudioRendererMixerReference { | 142 struct AudioRendererMixerReference { |
128 media::AudioRendererMixer* mixer; | 143 media::AudioRendererMixer* mixer; |
129 int ref_count; | 144 int ref_count; |
145 // Mixer sink pointer, to remove a sink from cache upon mixer destruction. | |
146 const media::AudioRendererSink* sink_ptr; | |
Guido Urdaneta
2016/05/25 13:33:13
What about adding a sink() getter to ARM, so that
o1ka
2016/05/25 14:52:11
We've already been there at PS7 :) changed accordi
Guido Urdaneta
2016/05/25 15:44:09
Acknowledged.
| |
130 }; | 147 }; |
131 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> | 148 |
132 AudioRendererMixerMap; | 149 using AudioRendererMixerMap = |
150 std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare>; | |
133 | 151 |
134 // Active mixers. | 152 // Active mixers. |
135 AudioRendererMixerMap mixers_; | 153 AudioRendererMixerMap mixers_; |
136 base::Lock mixers_lock_; | 154 base::Lock mixers_lock_; |
137 | 155 |
156 // Mixer sink cache. | |
157 const std::unique_ptr<AudioRendererSinkCache> sink_cache_; | |
158 | |
138 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 159 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
139 }; | 160 }; |
140 | 161 |
141 } // namespace content | 162 } // namespace content |
142 | 163 |
143 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 164 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
OLD | NEW |