Chromium Code Reviews| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call | 62 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call |
| 63 // this method when it's done with a mixer. | 63 // this method when it's done with a mixer. |
| 64 void RemoveMixer(int source_render_view_id, | 64 void RemoveMixer(int source_render_view_id, |
| 65 const media::AudioParameters& params); | 65 const media::AudioParameters& params); |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 friend class AudioRendererMixerManagerTest; | 68 friend class AudioRendererMixerManagerTest; |
| 69 | 69 |
| 70 // Define a key so that only those AudioRendererMixerInputs from the same | 70 // Define a key so that only those AudioRendererMixerInputs from the same |
| 71 // RenderView and with the same AudioParameters can be mixed together. | 71 // RenderView and with the same AudioParameters can be mixed together. |
| 72 typedef std::pair<int, media::AudioParameters> MixerKey; | 72 typedef std::pair<int, media::AudioParameters> MixerKey; |
|
xhwang
2014/09/23 21:14:04
nit: comment that the "int" is for render view ID.
DaleCurtis
2014/09/23 21:17:45
Done.
| |
| 73 | 73 |
| 74 // Custom compare operator for the AudioRendererMixerMap. Allows reuse of | |
| 75 // mixers where irrelevant keys mismatch (i.e., effects, bits per sample). | |
|
xhwang
2014/09/23 21:14:04
s/where/where only/
DaleCurtis
2014/09/23 21:17:45
Done.
| |
| 76 struct MixerKeyCompare { | |
| 77 bool operator()(const MixerKey& a, const MixerKey& b) const { | |
| 78 if (a.first != b.first) | |
| 79 return a.first < b.first; | |
| 80 if (a.second.sample_rate() != b.second.sample_rate()) | |
| 81 return a.second.sample_rate() < b.second.sample_rate(); | |
| 82 if (a.second.channels() != b.second.channels()) | |
| 83 return a.second.channels() < b.second.channels(); | |
| 84 | |
| 85 // Ignore effects(), bits_per_sample(), format(), and frames_per_buffer(), | |
| 86 // these parameters do not affect mixer reuse. All AudioRendererMixer | |
| 87 // units disable FIFO, so frames_per_buffer() can be safely ignored. | |
| 88 return a.second.channel_layout() < b.second.channel_layout(); | |
| 89 } | |
| 90 }; | |
| 91 | |
| 74 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows | 92 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows |
| 75 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which | 93 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which |
| 76 // is implicit) of the number of outstanding AudioRendererMixers. | 94 // is implicit) of the number of outstanding AudioRendererMixers. |
| 77 struct AudioRendererMixerReference { | 95 struct AudioRendererMixerReference { |
| 78 media::AudioRendererMixer* mixer; | 96 media::AudioRendererMixer* mixer; |
| 79 int ref_count; | 97 int ref_count; |
| 80 }; | 98 }; |
| 81 typedef std::map<MixerKey, AudioRendererMixerReference> AudioRendererMixerMap; | 99 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> |
| 100 AudioRendererMixerMap; | |
| 82 | 101 |
| 83 // Overrides the AudioRendererSink implementation for unit testing. | 102 // Overrides the AudioRendererSink implementation for unit testing. |
| 84 void SetAudioRendererSinkForTesting(media::AudioRendererSink* sink); | 103 void SetAudioRendererSinkForTesting(media::AudioRendererSink* sink); |
| 85 | 104 |
| 86 // Active mixers. | 105 // Active mixers. |
| 87 AudioRendererMixerMap mixers_; | 106 AudioRendererMixerMap mixers_; |
| 88 base::Lock mixers_lock_; | 107 base::Lock mixers_lock_; |
| 89 | 108 |
| 90 // Audio hardware configuration. Used to construct output AudioParameters for | 109 // Audio hardware configuration. Used to construct output AudioParameters for |
| 91 // each AudioRendererMixer instance. | 110 // each AudioRendererMixer instance. |
| 92 media::AudioHardwareConfig* const hardware_config_; | 111 media::AudioHardwareConfig* const hardware_config_; |
| 93 | 112 |
| 94 media::AudioRendererSink* sink_for_testing_; | 113 media::AudioRendererSink* sink_for_testing_; |
| 95 | 114 |
| 96 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 115 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
| 97 }; | 116 }; |
| 98 | 117 |
| 99 } // namespace content | 118 } // namespace content |
| 100 | 119 |
| 101 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 120 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
| OLD | NEW |