Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | |
| 6 #define CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "content/common/content_export.h" | |
| 12 #include "media/audio/audio_parameters.h" | |
| 13 | |
| 14 namespace media { | |
| 15 class AudioRendererMixer; | |
| 16 class AudioRendererMixerInput; | |
| 17 } | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based | |
| 22 // on their AudioParameters configuration. Inputs with the same AudioParameters | |
| 23 // configuration will share a mixer while a new AudioRendererMixer will be | |
| 24 // lazily created if one with the exact AudioParameters does not exist. | |
| 25 // | |
| 26 // There should only be one instance of AudioRendererMixerManager per render | |
| 27 // thread. | |
| 28 // | |
| 29 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match | |
| 30 // when we should be able to ignore bits per channel since we're only dealing | |
| 31 // with floats. However, bits per channel is currently used to interleave the | |
| 32 // audio data by AudioDevice::AudioThreadCallback::Process for consumption via | |
| 33 // the shared memory. See http://crbug.com/114700. | |
| 34 class CONTENT_EXPORT AudioRendererMixerManager { | |
| 35 public: | |
| 36 AudioRendererMixerManager(); | |
| 37 ~AudioRendererMixerManager(); | |
| 38 | |
| 39 // Creates an AudioRendererMixerInput with the proper callbacks necessary to | |
| 40 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. | |
| 41 // Caller must ensure AudioRendererMixerManager outlives the returned input. | |
| 42 media::AudioRendererMixerInput* CreateInput(); | |
| 43 | |
| 44 private: | |
| 45 friend class AudioRendererMixerManagerTest; | |
| 46 | |
| 47 // Returns a mixer instance based on AudioParameters; an existing one if one | |
| 48 // with the provided AudioParameters exists or a new one if not. | |
| 49 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params); | |
| 50 | |
| 51 // Remove a mixer instance given a mixer if the only other reference is held | |
| 52 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call | |
| 53 // this method when it's done with a mixer. | |
| 54 void RemoveMixer(const media::AudioParameters& params); | |
| 55 | |
| 56 // Map of AudioParameters to <AudioRendererMixer, Count>. Count allows | |
| 57 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which | |
| 58 // is implicit) of the number of outstanding AudioRendererMixers. | |
| 59 struct AudioRendererMixerReference { | |
| 60 media::AudioRendererMixer* mixer; | |
| 61 int ref_count; | |
| 62 }; | |
| 63 typedef std::map<media::AudioParameters, AudioRendererMixerReference, | |
| 64 media::AudioParameters::Compare> AudioRendererMixerMap; | |
| 65 AudioRendererMixerMap mixer_map_; | |
|
scherkus (not reviewing)
2012/07/13 23:17:38
nit: don't bother with _map / _list to variable na
DaleCurtis
2012/07/14 00:39:26
Done.
| |
| 66 base::Lock mixer_map_lock_; | |
|
scherkus (not reviewing)
2012/07/13 23:17:38
ditto here with mixers_lock_
DaleCurtis
2012/07/14 00:39:26
Done.
| |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | |
| 69 }; | |
| 70 | |
| 71 } // namespace content | |
| 72 | |
| 73 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | |
| OLD | NEW |