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

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: dalecurtis@'s comments addressed, build issue fixed Created 4 years, 7 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;
25 } 24 }
26 25
27 namespace content { 26 namespace content {
27 class AudioRendererSinkCache;
28 28
29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based 29 // Manages sharing of an AudioRendererMixer among AudioRendererMixerInputs based
30 // on their AudioParameters configuration. Inputs with the same AudioParameters 30 // on their AudioParameters configuration. Inputs with the same AudioParameters
31 // configuration will share a mixer while a new AudioRendererMixer will be 31 // configuration will share a mixer while a new AudioRendererMixer will be
32 // lazily created if one with the exact AudioParameters does not exist. 32 // lazily created if one with the exact AudioParameters does not exist.
33 // 33 //
34 // There should only be one instance of AudioRendererMixerManager per render 34 // There should only be one instance of AudioRendererMixerManager per render
35 // thread. 35 // thread.
36 // 36 //
37 // TODO(dalecurtis): Right now we require AudioParameters to be an exact match 37 // 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 38 // 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 39 // with floats. However, bits per channel is currently used to interleave the
40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption 40 // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption
41 // via the shared memory. See http://crbug.com/114700. 41 // via the shared memory. See http://crbug.com/114700.
42 class CONTENT_EXPORT AudioRendererMixerManager { 42 class CONTENT_EXPORT AudioRendererMixerManager
43 : public media::AudioRendererMixerPool {
43 public: 44 public:
44 AudioRendererMixerManager(); 45 static std::unique_ptr<AudioRendererMixerManager> Create();
45 ~AudioRendererMixerManager(); 46
47 ~AudioRendererMixerManager() final;
46 48
47 // Creates an AudioRendererMixerInput with the proper callbacks necessary to 49 // Creates an AudioRendererMixerInput with the proper callbacks necessary to
48 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager. 50 // retrieve an AudioRendererMixer instance from AudioRendererMixerManager.
49 // |source_render_frame_id| refers to the RenderFrame containing the entity 51 // |source_render_frame_id| refers to the RenderFrame containing the entity
50 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives 52 // rendering the audio. Caller must ensure AudioRendererMixerManager outlives
51 // the returned input. |device_id|, |session_id| and |security_origin| 53 // 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| 54 // 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 55 // is nonzero, output device associated with the opened input device
54 // designated by |session_id| is used. Otherwise, |session_id| is ignored. 56 // designated by |session_id| is used. Otherwise, |session_id| is ignored.
55 media::AudioRendererMixerInput* CreateInput( 57 media::AudioRendererMixerInput* CreateInput(
56 int source_render_frame_id, 58 int source_render_frame_id,
57 int session_id, 59 int session_id,
58 const std::string& device_id, 60 const std::string& device_id,
59 const url::Origin& security_origin); 61 const url::Origin& security_origin);
60 62
61 // Returns a mixer instance based on AudioParameters; an existing one if one 63 // Returns a mixer instance based on AudioParameters; an existing one if one
62 // with the provided AudioParameters exists or a new one if not. 64 // with the provided AudioParameters exists or a new one if not.
63 media::AudioRendererMixer* GetMixer(int source_render_frame_id, 65 media::AudioRendererMixer* GetMixer(
64 const media::AudioParameters& params, 66 int source_render_frame_id,
65 const std::string& device_id, 67 const media::AudioParameters& params,
66 const url::Origin& security_origin, 68 const std::string& device_id,
67 media::OutputDeviceStatus* device_status); 69 const url::Origin& security_origin,
70 media::OutputDeviceStatus* device_status) final;
68 71
69 // Remove a mixer instance given a mixer if the only other reference is held 72 // Remove a mixer instance given a mixer if the only other reference is held
70 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call 73 // by AudioRendererMixerManager. Every AudioRendererMixer owner must call
71 // this method when it's done with a mixer. 74 // this method when it's done with a mixer.
72 void RemoveMixer(int source_render_frame_id, 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 // Returns output device information. This call goes to the sink cache.
81 media::OutputDeviceInfo GetOutputDeviceInfo(
82 int source_render_frame_id,
83 int session_id,
84 const std::string& device_id,
85 const url::Origin& security_origin) final;
86
87 protected:
88 AudioRendererMixerManager(std::unique_ptr<AudioRendererSinkCache> sink_cache);
miu 2016/05/19 22:27:15 Need 'explicit' keyword for 1-arg ctors.
o1ka 2016/05/23 16:16:54 Done.
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
130 }; 143 };
131 typedef std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare> 144 using AudioRendererMixerMap =
132 AudioRendererMixerMap; 145 std::map<MixerKey, AudioRendererMixerReference, MixerKeyCompare>;
133 146
134 // Active mixers. 147 // Active mixers.
135 AudioRendererMixerMap mixers_; 148 AudioRendererMixerMap mixers_;
136 base::Lock mixers_lock_; 149 base::Lock mixers_lock_;
137 150
151 // Mixer sink cache.
152 const std::unique_ptr<AudioRendererSinkCache> sink_cache_;
153
138 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager); 154 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManager);
139 }; 155 };
140 156
141 } // namespace content 157 } // namespace content
142 158
143 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_ 159 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_MIXER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698