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 <bitset> |
8 #include <map> | 9 #include <map> |
9 #include <memory> | 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "media/audio/audio_device_description.h" | 16 #include "media/audio/audio_device_description.h" |
| 17 #include "media/base/audio_latency.h" |
16 #include "media/base/audio_parameters.h" | 18 #include "media/base/audio_parameters.h" |
17 #include "media/base/audio_renderer_mixer_pool.h" | 19 #include "media/base/audio_renderer_mixer_pool.h" |
18 #include "media/base/output_device_info.h" | 20 #include "media/base/output_device_info.h" |
19 #include "url/origin.h" | 21 #include "url/origin.h" |
20 | 22 |
21 namespace media { | 23 namespace media { |
22 class AudioRendererMixer; | 24 class AudioRendererMixer; |
23 class AudioRendererMixerInput; | 25 class AudioRendererMixerInput; |
24 class AudioRendererSink; | 26 class AudioRendererSink; |
25 } | 27 } |
(...skipping 28 matching lines...) Expand all Loading... |
54 // |source_render_frame_id| refers to the RenderFrame containing the entity | 56 // |source_render_frame_id| refers to the RenderFrame containing the entity |
55 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives | 57 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives |
56 // the returned input. |device_id|, |session_id| and |security_origin| | 58 // the returned input. |device_id|, |session_id| and |security_origin| |
57 // identify the output device to use. If |device_id| is empty and |session_id| | 59 // identify the output device to use. If |device_id| is empty and |session_id| |
58 // is nonzero, output device associated with the opened input device | 60 // is nonzero, output device associated with the opened input device |
59 // designated by |session_id| is used. Otherwise, |session_id| is ignored. | 61 // designated by |session_id| is used. Otherwise, |session_id| is ignored. |
60 media::AudioRendererMixerInput* CreateInput( | 62 media::AudioRendererMixerInput* CreateInput( |
61 int source_render_frame_id, | 63 int source_render_frame_id, |
62 int session_id, | 64 int session_id, |
63 const std::string& device_id, | 65 const std::string& device_id, |
64 const url::Origin& security_origin); | 66 const url::Origin& security_origin, |
| 67 media::AudioLatency::LatencyType latency); |
65 | 68 |
66 // AudioRendererMixerPool implementation. | 69 // AudioRendererMixerPool implementation. |
67 | 70 |
68 media::AudioRendererMixer* GetMixer( | 71 media::AudioRendererMixer* GetMixer( |
69 int source_render_frame_id, | 72 int source_render_frame_id, |
70 const media::AudioParameters& params, | 73 const media::AudioParameters& input_params, |
| 74 media::AudioLatency::LatencyType latency, |
71 const std::string& device_id, | 75 const std::string& device_id, |
72 const url::Origin& security_origin, | 76 const url::Origin& security_origin, |
73 media::OutputDeviceStatus* device_status) final; | 77 media::OutputDeviceStatus* device_status) final; |
74 | 78 |
75 void ReturnMixer(int source_render_frame_id, | 79 void ReturnMixer(media::AudioRendererMixer* mixer) final; |
76 const media::AudioParameters& params, | |
77 const std::string& device_id, | |
78 const url::Origin& security_origin) final; | |
79 | 80 |
80 media::OutputDeviceInfo GetOutputDeviceInfo( | 81 media::OutputDeviceInfo GetOutputDeviceInfo( |
81 int source_render_frame_id, | 82 int source_render_frame_id, |
82 int session_id, | 83 int session_id, |
83 const std::string& device_id, | 84 const std::string& device_id, |
84 const url::Origin& security_origin) final; | 85 const url::Origin& security_origin) final; |
85 | 86 |
86 protected: | 87 protected: |
87 explicit AudioRendererMixerManager( | 88 explicit AudioRendererMixerManager( |
88 std::unique_ptr<AudioRendererSinkCache> sink_cache); | 89 std::unique_ptr<AudioRendererSinkCache> sink_cache); |
89 | 90 |
90 private: | 91 private: |
91 friend class AudioRendererMixerManagerTest; | 92 friend class AudioRendererMixerManagerTest; |
92 | 93 |
93 // Define a key so that only those AudioRendererMixerInputs from the same | 94 // Define a key so that only those AudioRendererMixerInputs from the same |
94 // RenderView, AudioParameters and output device can be mixed together. | 95 // RenderView, AudioParameters and output device can be mixed together. |
95 struct MixerKey { | 96 struct MixerKey { |
96 MixerKey(int source_render_frame_id, | 97 MixerKey(int source_render_frame_id, |
97 const media::AudioParameters& params, | 98 const media::AudioParameters& params, |
| 99 media::AudioLatency::LatencyType latency, |
98 const std::string& device_id, | 100 const std::string& device_id, |
99 const url::Origin& security_origin); | 101 const url::Origin& security_origin); |
100 MixerKey(const MixerKey& other); | 102 MixerKey(const MixerKey& other); |
101 int source_render_frame_id; | 103 int source_render_frame_id; |
102 media::AudioParameters params; | 104 media::AudioParameters params; |
| 105 media::AudioLatency::LatencyType latency; |
103 std::string device_id; | 106 std::string device_id; |
104 url::Origin security_origin; | 107 url::Origin security_origin; |
105 }; | 108 }; |
106 | 109 |
107 // Custom compare operator for the AudioRendererMixerMap. Allows reuse of | 110 // Custom compare operator for the AudioRendererMixerMap. Allows reuse of |
108 // mixers where only irrelevant keys mismatch; e.g., effects, bits per sample. | 111 // mixers where only irrelevant keys mismatch; e.g., effects, bits per sample. |
109 struct MixerKeyCompare { | 112 struct MixerKeyCompare { |
110 bool operator()(const MixerKey& a, const MixerKey& b) const { | 113 bool operator()(const MixerKey& a, const MixerKey& b) const { |
111 if (a.source_render_frame_id != b.source_render_frame_id) | 114 if (a.source_render_frame_id != b.source_render_frame_id) |
112 return a.source_render_frame_id < b.source_render_frame_id; | 115 return a.source_render_frame_id < b.source_render_frame_id; |
113 if (a.params.channels() != b.params.channels()) | 116 if (a.params.channels() != b.params.channels()) |
114 return a.params.channels() < b.params.channels(); | 117 return a.params.channels() < b.params.channels(); |
115 | 118 |
| 119 if (a.latency != b.latency) |
| 120 return a.latency < b.latency; |
| 121 |
| 122 // TODO(olka) add buffer duration comparison for LATENCY_EXACT_MS when |
| 123 // adding support for it. |
| 124 DCHECK_NE(media::AudioLatency::LATENCY_EXACT_MS, a.latency); |
| 125 |
116 // Ignore effects(), bits_per_sample(), format(), and frames_per_buffer(), | 126 // Ignore effects(), bits_per_sample(), format(), and frames_per_buffer(), |
117 // these parameters do not affect mixer reuse. All AudioRendererMixer | 127 // these parameters do not affect mixer reuse. All AudioRendererMixer |
118 // units disable FIFO, so frames_per_buffer() can be safely ignored. | 128 // units disable FIFO, so frames_per_buffer() can be safely ignored. |
119 if (a.params.channel_layout() != b.params.channel_layout()) | 129 if (a.params.channel_layout() != b.params.channel_layout()) |
120 return a.params.channel_layout() < b.params.channel_layout(); | 130 return a.params.channel_layout() < b.params.channel_layout(); |
121 | 131 |
122 if (media::AudioDeviceDescription::IsDefaultDevice(a.device_id) && | 132 if (media::AudioDeviceDescription::IsDefaultDevice(a.device_id) && |
123 media::AudioDeviceDescription::IsDefaultDevice(b.device_id)) { | 133 media::AudioDeviceDescription::IsDefaultDevice(b.device_id)) { |
124 // Both device IDs represent the same default device => do not compare | 134 // Both device IDs represent the same default device => do not compare |
125 // them; the default device is always authorized => ignoring security | 135 // them; the default device is always authorized => ignoring security |
(...skipping 21 matching lines...) Expand all Loading... |
147 using AudioRendererMixerMap = | 157 using AudioRendererMixerMap = |
148 std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare>; | 158 std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare>; |
149 | 159 |
150 // Active mixers. | 160 // Active mixers. |
151 AudioRendererMixerMap mixers_; | 161 AudioRendererMixerMap mixers_; |
152 base::Lock mixers_lock_; | 162 base::Lock mixers_lock_; |
153 | 163 |
154 // Mixer sink cache. | 164 // Mixer sink cache. |
155 const std::unique_ptr<AudioRendererSinkCache> sink_cache_; | 165 const std::unique_ptr<AudioRendererSinkCache> sink_cache_; |
156 | 166 |
| 167 // Map of the output latencies encountered throughout mixer manager lifetime. |
| 168 std::bitset<media::AudioLatency::LATENCY_COUNT> latency_map_; |
| 169 |
157 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 170 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
158 }; | 171 }; |
159 | 172 |
160 } // namespace content | 173 } // namespace content |
161 | 174 |
162 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 175 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
OLD | NEW |