| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // Remove a mixer instance given a mixer if the only other reference is held | 61 // Remove a mixer instance given a mixer if the only other reference is held |
| 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. The |
| 72 // first value is the RenderViewId. |
| 72 typedef std::pair<int, media::AudioParameters> MixerKey; | 73 typedef std::pair<int, media::AudioParameters> MixerKey; |
| 73 | 74 |
| 75 // Custom compare operator for the AudioRendererMixerMap. Allows reuse of |
| 76 // mixers where only irrelevant keys mismatch; e.g., effects, bits per sample. |
| 77 struct MixerKeyCompare { |
| 78 bool operator()(const MixerKey& a, const MixerKey& b) const { |
| 79 if (a.first != b.first) |
| 80 return a.first < b.first; |
| 81 if (a.second.sample_rate() != b.second.sample_rate()) |
| 82 return a.second.sample_rate() < b.second.sample_rate(); |
| 83 if (a.second.channels() != b.second.channels()) |
| 84 return a.second.channels() < b.second.channels(); |
| 85 |
| 86 // Ignore effects(), bits_per_sample(), format(), and frames_per_buffer(), |
| 87 // these parameters do not affect mixer reuse. All AudioRendererMixer |
| 88 // units disable FIFO, so frames_per_buffer() can be safely ignored. |
| 89 return a.second.channel_layout() < b.second.channel_layout(); |
| 90 } |
| 91 }; |
| 92 |
| 74 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows | 93 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows |
| 75 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which | 94 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which |
| 76 // is implicit) of the number of outstanding AudioRendererMixers. | 95 // is implicit) of the number of outstanding AudioRendererMixers. |
| 77 struct AudioRendererMixerReference { | 96 struct AudioRendererMixerReference { |
| 78 media::AudioRendererMixer* mixer; | 97 media::AudioRendererMixer* mixer; |
| 79 int ref_count; | 98 int ref_count; |
| 80 }; | 99 }; |
| 81 typedef std::map<MixerKey, AudioRendererMixerReference> AudioRendererMixerMap; | 100 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> |
| 101 AudioRendererMixerMap; |
| 82 | 102 |
| 83 // Overrides the AudioRendererSink implementation for unit testing. | 103 // Overrides the AudioRendererSink implementation for unit testing. |
| 84 void SetAudioRendererSinkForTesting(media::AudioRendererSink* sink); | 104 void SetAudioRendererSinkForTesting(media::AudioRendererSink* sink); |
| 85 | 105 |
| 86 // Active mixers. | 106 // Active mixers. |
| 87 AudioRendererMixerMap mixers_; | 107 AudioRendererMixerMap mixers_; |
| 88 base::Lock mixers_lock_; | 108 base::Lock mixers_lock_; |
| 89 | 109 |
| 90 // Audio hardware configuration. Used to construct output AudioParameters for | 110 // Audio hardware configuration. Used to construct output AudioParameters for |
| 91 // each AudioRendererMixer instance. | 111 // each AudioRendererMixer instance. |
| 92 media::AudioHardwareConfig* const hardware_config_; | 112 media::AudioHardwareConfig* const hardware_config_; |
| 93 | 113 |
| 94 media::AudioRendererSink* sink_for_testing_; | 114 media::AudioRendererSink* sink_for_testing_; |
| 95 | 115 |
| 96 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 116 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
| 97 }; | 117 }; |
| 98 | 118 |
| 99 } // namespace content | 119 } // namespace content |
| 100 | 120 |
| 101 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 121 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
| OLD | NEW |