Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: content/renderer/media/audio_renderer_mixer_manager.h

Issue 1942803002: Caching AudioOutputDevice instances in mixer manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make WebAudioSourceProvider to always return real sink info reguardless the client - to avoid behavior change. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/audio_renderer_mixer_pool.h"
17 #include "media/base/output_device_info.h" 18 #include "media/base/output_device_info.h"
18 #include "url/origin.h" 19 #include "url/origin.h"
19 20
20 namespace media { 21 namespace media {
21 class AudioHardwareConfig;
22 class AudioRendererMixer; 22 class AudioRendererMixer;
23 class AudioRendererMixerInput; 23 class AudioRendererMixerInput;
24 class AudioRendererSink; 24 class AudioRendererSink;
25 } 25 }
26 26
27 namespace content { 27 namespace content {
28 class AudioRendererSinkCache;
28 29
29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based 30 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based
30 // on their AudioParameters configuration. Inputs with the same AudioParameters 31 // on their AudioParameters configuration. Inputs with the same AudioParameters
31 // configuration will share a mixer while a new AudioRendererMixer will be 32 // configuration will share a mixer while a new AudioRendererMixer will be
32 // lazily created if one with the exact AudioParameters does not exist. 33 // lazily created if one with the exact AudioParameters does not exist. When an
34 // AudioRendererMixer is returned by AudioRendererMixerInput, it will be deleted
35 // if its only other reference is held by AudioRendererMixerManager.
33 // 36 //
34 // There should only be one instance of AudioRendererMixerManager per render 37 // There should only be one instance of AudioRendererMixerManager per render
35 // thread. 38 // thread.
36 // 39 //
37 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match 40 // 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 41 // 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 42 // with floats. However, bits per channel is currently used to interleave the
40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption 43 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption
41 // via the shared memory. See http://crbug.com/114700. 44 // via the shared memory. See http://crbug.com/114700.
42 class CONTENT_EXPORT AudioRendererMixerManager { 45 class CONTENT_EXPORT AudioRendererMixerManager
46 : public media::AudioRendererMixerPool {
43 public: 47 public:
44 AudioRendererMixerManager(); 48 ~AudioRendererMixerManager() final;
45 ~AudioRendererMixerManager(); 49
50 static std::unique_ptr<AudioRendererMixerManager> Create();
46 51
47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to 52 // Creates an AudioRendererMixerInput with the proper callbacks necessary to
48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. 53 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager.
49 // |source_render_frame_id| refers to the RenderFrame containing the entity 54 // |source_render_frame_id| refers to the RenderFrame containing the entity
50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives 55 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives
51 // the returned input. |device_id|, |session_id| and |security_origin| 56 // 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| 57 // 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 58 // is nonzero, output device associated with the opened input device
54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. 59 // designated by |session_id| is used. Otherwise, |session_id| is ignored.
55 media::AudioRendererMixerInput* CreateInput( 60 media::AudioRendererMixerInput* CreateInput(
56 int source_render_frame_id, 61 int source_render_frame_id,
57 int session_id, 62 int session_id,
58 const std::string& device_id, 63 const std::string& device_id,
59 const url::Origin& security_origin); 64 const url::Origin& security_origin);
60 65
61 // Returns a mixer instance based on AudioParameters; an existing one if one 66 // AudioRendererMixerPool implementation.
62 // with the provided AudioParameters exists or a new one if not.
63 media::AudioRendererMixer* GetMixer(int source_render_frame_id,
64 const media::AudioParameters& params,
65 const std::string& device_id,
66 const url::Origin& security_origin,
67 media::OutputDeviceStatus* device_status);
68 67
69 // Remove a mixer instance given a mixer if the only other reference is held 68 media::AudioRendererMixer* GetMixer(
70 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call 69 int source_render_frame_id,
71 // this method when it's done with a mixer. 70 const media::AudioParameters& params,
72 void RemoveMixer(int source_render_frame_id, 71 const std::string& device_id,
72 const url::Origin& security_origin,
73 media::OutputDeviceStatus* device_status) final;
74
75 void ReturnMixer(int source_render_frame_id,
73 const media::AudioParameters& params, 76 const media::AudioParameters& params,
74 const std::string& device_id, 77 const std::string& device_id,
75 const url::Origin& security_origin); 78 const url::Origin& security_origin) final;
79
80 media::OutputDeviceInfo GetOutputDeviceInfo(
81 int source_render_frame_id,
82 int session_id,
83 const std::string& device_id,
84 const url::Origin& security_origin) final;
85
86 protected:
87 explicit AudioRendererMixerManager(
88 std::unique_ptr<AudioRendererSinkCache> sink_cache);
76 89
77 private: 90 private:
78 friend class AudioRendererMixerManagerTest; 91 friend class AudioRendererMixerManagerTest;
79 92
80 // Define a key so that only those AudioRendererMixerInputs from the same 93 // Define a key so that only those AudioRendererMixerInputs from the same
81 // RenderView, AudioParameters and output device can be mixed together. 94 // RenderView, AudioParameters and output device can be mixed together.
82 struct MixerKey { 95 struct MixerKey {
83 MixerKey(int source_render_frame_id, 96 MixerKey(int source_render_frame_id,
84 const media::AudioParameters& params, 97 const media::AudioParameters& params,
85 const std::string& device_id, 98 const std::string& device_id,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return a.security_origin < b.security_origin; 133 return a.security_origin < b.security_origin;
121 } 134 }
122 }; 135 };
123 136
124 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows 137 // Map of MixerKey to <AudioRendererMixer, Count>. Count allows
125 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which 138 // AudioRendererMixerManager to keep track explicitly (v.s. RefCounted which
126 // is implicit) of the number of outstanding AudioRendererMixers. 139 // is implicit) of the number of outstanding AudioRendererMixers.
127 struct AudioRendererMixerReference { 140 struct AudioRendererMixerReference {
128 media::AudioRendererMixer* mixer; 141 media::AudioRendererMixer* mixer;
129 int ref_count; 142 int ref_count;
143 // Mixer sink pointer, to remove a sink from cache upon mixer destruction.
144 const media::AudioRendererSink* sink_ptr;
130 }; 145 };
131 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> 146
132 AudioRendererMixerMap; 147 using AudioRendererMixerMap =
148 std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare>;
133 149
134 // Active mixers. 150 // Active mixers.
135 AudioRendererMixerMap mixers_; 151 AudioRendererMixerMap mixers_;
136 base::Lock mixers_lock_; 152 base::Lock mixers_lock_;
137 153
154 // Mixer sink cache.
155 const std::unique_ptr<AudioRendererSinkCache> sink_cache_;
156
138 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); 157 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager);
139 }; 158 };
140 159
141 } // namespace content 160 } // namespace content
142 161
143 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ 162 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/audio_device_factory.cc ('k') | content/renderer/media/audio_renderer_mixer_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698