| 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 <string> | 9 #include <string> |
| 10 #include <utility> | 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_manager_base.h" |
| 15 #include "media/audio/audio_parameters.h" | 16 #include "media/audio/audio_parameters.h" |
| 16 #include "media/base/output_device_info.h" | 17 #include "media/base/output_device_info.h" |
| 17 #include "url/origin.h" | 18 #include "url/origin.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 class AudioHardwareConfig; | 21 class AudioHardwareConfig; |
| 21 class AudioRendererMixer; | 22 class AudioRendererMixer; |
| 22 class AudioRendererMixerInput; | 23 class AudioRendererMixerInput; |
| 23 class AudioRendererSink; | 24 class AudioRendererSink; |
| 24 } | 25 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 // via the shared memory. See http://crbug.com/114700. | 41 // via the shared memory. See http://crbug.com/114700. |
| 41 class CONTENT_EXPORT AudioRendererMixerManager { | 42 class CONTENT_EXPORT AudioRendererMixerManager { |
| 42 public: | 43 public: |
| 43 AudioRendererMixerManager(); | 44 AudioRendererMixerManager(); |
| 44 ~AudioRendererMixerManager(); | 45 ~AudioRendererMixerManager(); |
| 45 | 46 |
| 46 // Creates an AudioRendererMixerInput with the proper callbacks necessary to | 47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to |
| 47 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. | 48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. |
| 48 // |source_render_frame_id| refers to the RenderFrame containing the entity | 49 // |source_render_frame_id| refers to the RenderFrame containing the entity |
| 49 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives | 50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives |
| 50 // the returned input. |device_id| and |security_origin| identify the output | 51 // the returned input. |device_id|, |session_id| and |security_origin| |
| 51 // device to use | 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 |
| 54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. |
| 52 media::AudioRendererMixerInput* CreateInput( | 55 media::AudioRendererMixerInput* CreateInput( |
| 53 int source_render_frame_id, | 56 int source_render_frame_id, |
| 57 int session_id, |
| 54 const std::string& device_id, | 58 const std::string& device_id, |
| 55 const url::Origin& security_origin); | 59 const url::Origin& security_origin); |
| 56 | 60 |
| 57 // Returns a mixer instance based on AudioParameters; an existing one if one | 61 // Returns a mixer instance based on AudioParameters; an existing one if one |
| 58 // with the provided AudioParameters exists or a new one if not. | 62 // with the provided AudioParameters exists or a new one if not. |
| 59 media::AudioRendererMixer* GetMixer(int source_render_frame_id, | 63 media::AudioRendererMixer* GetMixer(int source_render_frame_id, |
| 60 const media::AudioParameters& params, | 64 const media::AudioParameters& params, |
| 61 const std::string& device_id, | 65 const std::string& device_id, |
| 62 const url::Origin& security_origin, | 66 const url::Origin& security_origin, |
| 63 media::OutputDeviceStatus* device_status); | 67 media::OutputDeviceStatus* device_status); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return a.source_render_frame_id < b.source_render_frame_id; | 99 return a.source_render_frame_id < b.source_render_frame_id; |
| 96 if (a.params.channels() != b.params.channels()) | 100 if (a.params.channels() != b.params.channels()) |
| 97 return a.params.channels() < b.params.channels(); | 101 return a.params.channels() < b.params.channels(); |
| 98 | 102 |
| 99 // Ignore effects(), bits_per_sample(), format(), and frames_per_buffer(), | 103 // Ignore effects(), bits_per_sample(), format(), and frames_per_buffer(), |
| 100 // these parameters do not affect mixer reuse. All AudioRendererMixer | 104 // these parameters do not affect mixer reuse. All AudioRendererMixer |
| 101 // units disable FIFO, so frames_per_buffer() can be safely ignored. | 105 // units disable FIFO, so frames_per_buffer() can be safely ignored. |
| 102 if (a.params.channel_layout() != b.params.channel_layout()) | 106 if (a.params.channel_layout() != b.params.channel_layout()) |
| 103 return a.params.channel_layout() < b.params.channel_layout(); | 107 return a.params.channel_layout() < b.params.channel_layout(); |
| 104 | 108 |
| 109 if (media::AudioManagerBase::IsDefaultDeviceId(a.device_id) && |
| 110 media::AudioManagerBase::IsDefaultDeviceId(b.device_id)) { |
| 111 // Both device IDs represent the same default device => do not compare |
| 112 // them; the default device is always authorized => ignoring security |
| 113 // origin. |
| 114 return false; |
| 115 } |
| 116 |
| 105 if (a.device_id != b.device_id) | 117 if (a.device_id != b.device_id) |
| 106 return a.device_id < b.device_id; | 118 return a.device_id < b.device_id; |
| 107 | 119 |
| 108 return a.security_origin < b.security_origin; | 120 return a.security_origin < b.security_origin; |
| 109 } | 121 } |
| 110 }; | 122 }; |
| 111 | 123 |
| 112 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows | 124 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows |
| 113 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which | 125 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which |
| 114 // is implicit) of the number of outstanding AudioRendererMixers. | 126 // is implicit) of the number of outstanding AudioRendererMixers. |
| 115 struct AudioRendererMixerReference { | 127 struct AudioRendererMixerReference { |
| 116 media::AudioRendererMixer* mixer; | 128 media::AudioRendererMixer* mixer; |
| 117 int ref_count; | 129 int ref_count; |
| 118 }; | 130 }; |
| 119 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> | 131 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> |
| 120 AudioRendererMixerMap; | 132 AudioRendererMixerMap; |
| 121 | 133 |
| 122 // Active mixers. | 134 // Active mixers. |
| 123 AudioRendererMixerMap mixers_; | 135 AudioRendererMixerMap mixers_; |
| 124 base::Lock mixers_lock_; | 136 base::Lock mixers_lock_; |
| 125 | 137 |
| 126 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); | 138 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); |
| 127 }; | 139 }; |
| 128 | 140 |
| 129 } // namespace content | 141 } // namespace content |
| 130 | 142 |
| 131 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ | 143 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ |
| OLD | NEW |