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 <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/output_device_info.h" | 17 #include "media/base/output_device_info.h" |
| 18 #include "url/origin.h" | 18 #include "url/origin.h" |
| 19 | 19 |
| 20 namespace media { | 20 namespace media { |
| 21 class AudioHardwareConfig; | |
| 22 class AudioRendererMixer; | 21 class AudioRendererMixer; |
| 23 class AudioRendererMixerInput; | 22 class AudioRendererMixerInput; |
| 24 class AudioRendererSink; | |
| 25 } | 23 } |
| 26 | 24 |
| 27 namespace content { | 25 namespace content { |
| 26 class AudioRendererSinkCache; | |
| 28 | 27 |
| 29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based | 28 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based |
| 30 // on their AudioParameters configuration. Inputs with the same AudioParameters | 29 // on their AudioParameters configuration. Inputs with the same AudioParameters |
| 31 // configuration will share a mixer while a new AudioRendererMixer will be | 30 // configuration will share a mixer while a new AudioRendererMixer will be |
| 32 // lazily created if one with the exact AudioParameters does not exist. | 31 // lazily created if one with the exact AudioParameters does not exist. |
| 33 // | 32 // |
| 34 // There should only be one instance of AudioRendererMixerManager per render | 33 // There should only be one instance of AudioRendererMixerManager per render |
| 35 // thread. | 34 // thread. |
| 36 // | 35 // |
| 37 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match | 36 // 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 | 37 // 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 | 38 // with floats. However, bits per channel is currently used to interleave the |
| 40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption | 39 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption |
| 41 // via the shared memory. See http://crbug.com/114700. | 40 // via the shared memory. See http://crbug.com/114700. |
| 42 class CONTENT_EXPORT AudioRendererMixerManager { | 41 class CONTENT_EXPORT AudioRendererMixerManager { |
| 43 public: | 42 public: |
| 44 AudioRendererMixerManager(); | 43 static std::unique_ptr<AudioRendererMixerManager> Create(); |
| 44 | |
| 45 ~AudioRendererMixerManager(); | 45 ~AudioRendererMixerManager(); |
| 46 | 46 |
| 47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to | 47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to |
| 48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. | 48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. |
| 49 // |source_render_frame_id| refers to the RenderFrame containing the entity | 49 // |source_render_frame_id| refers to the RenderFrame containing the entity |
| 50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives | 50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives |
| 51 // the returned input. |device_id|, |session_id| and |security_origin| | 51 // 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| | 52 // 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 | 53 // is nonzero, output device associated with the opened input device |
| 54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. | 54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 67 media::OutputDeviceStatus* device_status); | 67 media::OutputDeviceStatus* device_status); |
| 68 | 68 |
| 69 // Remove a mixer instance given a mixer if the only other reference is held | 69 // Remove a mixer instance given a mixer if the only other reference is held |
| 70 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call | 70 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call |
| 71 // this method when it's done with a mixer. | 71 // this method when it's done with a mixer. |
| 72 void RemoveMixer(int source_render_frame_id, | 72 void RemoveMixer(int source_render_frame_id, |
| 73 const media::AudioParameters& params, | 73 const media::AudioParameters& params, |
| 74 const std::string& device_id, | 74 const std::string& device_id, |
| 75 const url::Origin& security_origin); | 75 const url::Origin& security_origin); |
| 76 | 76 |
| 77 // Returns output device information. This call goes to the sink cache. | |
| 78 media::OutputDeviceInfo GetOutputDeviceInfo( | |
| 79 int source_render_frame_id, | |
| 80 int session_id, | |
| 81 const std::string& device_id, | |
| 82 const url::Origin& security_origin); | |
| 83 | |
| 84 protected: | |
| 85 AudioRendererMixerManager(std::unique_ptr<AudioRendererSinkCache> sink_cache); | |
| 86 | |
| 77 private: | 87 private: |
| 78 friend class AudioRendererMixerManagerTest; | 88 friend class AudioRendererMixerManagerTest; |
| 79 | 89 |
| 80 // Define a key so that only those AudioRendererMixerInputs from the same | 90 // Define a key so that only those AudioRendererMixerInputs from the same |
| 81 // RenderView, AudioParameters and output device can be mixed together. | 91 // RenderView, AudioParameters and output device can be mixed together. |
| 82 struct MixerKey { | 92 struct MixerKey { |
| 83 MixerKey(int source_render_frame_id, | 93 MixerKey(int source_render_frame_id, |
| 84 const media::AudioParameters& params, | 94 const media::AudioParameters& params, |
| 85 const std::string& device_id, | 95 const std::string& device_id, |
| 86 const url::Origin& security_origin); | 96 const url::Origin& security_origin); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 media::AudioRendererMixer* mixer; | 138 media::AudioRendererMixer* mixer; |
| 129 int ref_count; | 139 int ref_count; |
| 130 }; | 140 }; |
| 131 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> | 141 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> |
| 132 AudioRendererMixerMap; | 142 AudioRendererMixerMap; |
| 133 | 143 |
| 134 // Active mixers. | 144 // Active mixers. |
| 135 AudioRendererMixerMap mixers_; | 145 AudioRendererMixerMap mixers_; |
| 136 base::Lock mixers_lock_; | 146 base::Lock mixers_lock_; |
| 137 | 147 |
| 148 // Mixer sink cache. Should outlive |mixers_| => must be declared after them. | |
| 149 std::unique_ptr<AudioRendererSinkCache> sink_cache_; | |
|
miu
2016/05/12 21:53:06
Please make this const, since it is not mutated an
o1ka
2016/05/17 17:17:23
Done.
| |
| 150 | |
| 138 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 151 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
| 139 }; | 152 }; |
| 140 | 153 |
| 141 } // namespace content | 154 } // namespace content |
| 142 | 155 |
| 143 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 156 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
| OLD | NEW |