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

Side by Side Diff: media/base/audio_renderer_mixer.h

Issue 1942803002: Caching AudioOutputDevice instances in mixer manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments addressed, map->vector in AudioRendererCacheImpl 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 MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ 5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ 6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "media/base/audio_converter.h" 17 #include "media/base/audio_converter.h"
18 #include "media/base/audio_renderer_sink.h" 18 #include "media/base/audio_renderer_sink.h"
19 #include "media/base/loopback_audio_converter.h" 19 #include "media/base/loopback_audio_converter.h"
20 20
21 namespace media { 21 namespace media {
22 22
23 // Mixes a set of AudioConverter::InputCallbacks into a single output stream 23 // Mixes a set of AudioConverter::InputCallbacks into a single output stream
24 // which is funneled into a single shared AudioRendererSink; saving a bundle 24 // which is funneled into a single shared AudioRendererSink; saving a bundle
25 // on renderer side resources. 25 // on renderer side resources.
26 class MEDIA_EXPORT AudioRendererMixer 26 class MEDIA_EXPORT AudioRendererMixer
27 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { 27 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) {
28 public: 28 public:
29 AudioRendererMixer(const AudioParameters& output_params, 29 AudioRendererMixer(const AudioParameters& output_params,
30 const scoped_refptr<AudioRendererSink>& sink); 30 scoped_refptr<AudioRendererSink> sink);
31 ~AudioRendererMixer() override; 31 ~AudioRendererMixer() override;
32 32
33 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. 33 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput.
34 void AddMixerInput(const AudioParameters& input_params, 34 void AddMixerInput(const AudioParameters& input_params,
35 AudioConverter::InputCallback* input); 35 AudioConverter::InputCallback* input);
36 void RemoveMixerInput(const AudioParameters& input_params, 36 void RemoveMixerInput(const AudioParameters& input_params,
37 AudioConverter::InputCallback* input); 37 AudioConverter::InputCallback* input);
38 38
39 // Since errors may occur even when no inputs are playing, an error callback 39 // Since errors may occur even when no inputs are playing, an error callback
40 // must be registered separately from adding a mixer input. The same callback 40 // must be registered separately from adding a mixer input. The same callback
41 // must be given to both the functions. 41 // must be given to both the functions.
42 void AddErrorCallback(const base::Closure& error_cb); 42 void AddErrorCallback(const base::Closure& error_cb);
43 void RemoveErrorCallback(const base::Closure& error_cb); 43 void RemoveErrorCallback(const base::Closure& error_cb);
44 44
45 void set_pause_delay_for_testing(base::TimeDelta delay) { 45 void set_pause_delay_for_testing(base::TimeDelta delay) {
46 pause_delay_ = delay; 46 pause_delay_ = delay;
47 } 47 }
48 48
49 OutputDeviceInfo GetOutputDeviceInfo(); 49 OutputDeviceInfo GetOutputDeviceInfo();
50 50
51 // Used by AudioRendererMixerManager to remove mixer sink from the sink cache.
DaleCurtis 2016/05/23 18:29:08 This isn't necessary, just have the ARMM store the
o1ka 2016/05/23 19:21:35 Well, I don feel like it's any better to store it
DaleCurtis 2016/05/23 20:20:26 I do in this case. Can you explain why you think i
o1ka 2016/05/24 15:00:41 Ok, the one without an interface is nicer. (added
52 const AudioRendererSink* sink_ptr() { return audio_sink_.get(); };
53
51 private: 54 private:
52 // Maps input sample rate to the dedicated converter. 55 // Maps input sample rate to the dedicated converter.
53 using AudioConvertersMap = 56 using AudioConvertersMap =
54 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; 57 std::map<int, std::unique_ptr<LoopbackAudioConverter>>;
55 58
56 // AudioRendererSink::RenderCallback implementation. 59 // AudioRendererSink::RenderCallback implementation.
57 int Render(AudioBus* audio_bus, 60 int Render(AudioBus* audio_bus,
58 uint32_t frames_delayed, 61 uint32_t frames_delayed,
59 uint32_t frames_skipped) override; 62 uint32_t frames_skipped) override;
60 void OnRenderError() override; 63 void OnRenderError() override;
61 64
62 bool is_master_sample_rate(int sample_rate) { 65 bool is_master_sample_rate(int sample_rate) {
63 return sample_rate == output_params_.sample_rate(); 66 return sample_rate == output_params_.sample_rate();
64 } 67 }
65 68
69 // Output parameters for this mixer.
70 const AudioParameters output_params_;
71
66 // Output sink for this mixer. 72 // Output sink for this mixer.
67 scoped_refptr<AudioRendererSink> audio_sink_; 73 const scoped_refptr<AudioRendererSink> audio_sink_;
68
69 // Output parameters for this mixer.
70 AudioParameters output_params_;
71 74
72 // ---------------[ All variables below protected by |lock_| ]--------------- 75 // ---------------[ All variables below protected by |lock_| ]---------------
73 base::Lock lock_; 76 base::Lock lock_;
74 77
75 // List of error callbacks used by this mixer. 78 // List of error callbacks used by this mixer.
76 typedef std::list<base::Closure> ErrorCallbackList; 79 typedef std::list<base::Closure> ErrorCallbackList;
77 ErrorCallbackList error_callbacks_; 80 ErrorCallbackList error_callbacks_;
78 81
79 // Each of these converters mixes inputs with a given sample rate and 82 // Each of these converters mixes inputs with a given sample rate and
80 // resamples them to the output sample rate. Inputs not reqiuring resampling 83 // resamples them to the output sample rate. Inputs not reqiuring resampling
81 // go directly to |master_converter_|. 84 // go directly to |master_converter_|.
82 AudioConvertersMap converters_; 85 AudioConvertersMap converters_;
83 86
84 // Master converter which mixes all the outputs from |converters_| as well as 87 // Master converter which mixes all the outputs from |converters_| as well as
85 // mixer inputs that are in the output sample rate. 88 // mixer inputs that are in the output sample rate.
86 AudioConverter master_converter_; 89 AudioConverter master_converter_;
87 90
88 // Handles physical stream pause when no inputs are playing. For latency 91 // Handles physical stream pause when no inputs are playing. For latency
89 // reasons we don't want to immediately pause the physical stream. 92 // reasons we don't want to immediately pause the physical stream.
90 base::TimeDelta pause_delay_; 93 base::TimeDelta pause_delay_;
91 base::TimeTicks last_play_time_; 94 base::TimeTicks last_play_time_;
92 bool playing_; 95 bool playing_;
93 96
94 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); 97 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer);
95 }; 98 };
96 99
97 } // namespace media 100 } // namespace media
98 101
99 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ 102 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698