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 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<media::AudioRendererSink> sink); |
|
DaleCurtis
2016/05/17 19:13:48
Remove media:: this is already in media. Ditto bel
o1ka
2016/05/18 13:15:12
Done.
| |
| 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 const AudioRendererSink* sink_ptr() { return audio_sink_.get(); }; | |
|
DaleCurtis
2016/05/17 19:13:48
Needed? for_testing?
o1ka
2016/05/18 13:15:12
Needed, I put it into the comment.
Maybe you have
| |
| 52 | |
| 51 private: | 53 private: |
| 52 // Maps input sample rate to the dedicated converter. | 54 // Maps input sample rate to the dedicated converter. |
| 53 using AudioConvertersMap = | 55 using AudioConvertersMap = |
| 54 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; | 56 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; |
| 55 | 57 |
| 56 // AudioRendererSink::RenderCallback implementation. | 58 // AudioRendererSink::RenderCallback implementation. |
| 57 int Render(AudioBus* audio_bus, | 59 int Render(AudioBus* audio_bus, |
| 58 uint32_t frames_delayed, | 60 uint32_t frames_delayed, |
| 59 uint32_t frames_skipped) override; | 61 uint32_t frames_skipped) override; |
| 60 void OnRenderError() override; | 62 void OnRenderError() override; |
| 61 | 63 |
| 62 bool is_master_sample_rate(int sample_rate) { | 64 bool is_master_sample_rate(int sample_rate) { |
| 63 return sample_rate == output_params_.sample_rate(); | 65 return sample_rate == output_params_.sample_rate(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 // Output sink for this mixer. | 68 // Output sink for this mixer. |
| 67 scoped_refptr<AudioRendererSink> audio_sink_; | 69 const scoped_refptr<media::AudioRendererSink> audio_sink_; |
| 68 | 70 |
| 69 // Output parameters for this mixer. | 71 // Output parameters for this mixer. |
| 70 AudioParameters output_params_; | 72 const AudioParameters output_params_; |
| 71 | 73 |
| 72 // ---------------[ All variables below protected by |lock_| ]--------------- | 74 // ---------------[ All variables below protected by |lock_| ]--------------- |
| 73 base::Lock lock_; | 75 base::Lock lock_; |
| 74 | 76 |
| 75 // List of error callbacks used by this mixer. | 77 // List of error callbacks used by this mixer. |
| 76 typedef std::list<base::Closure> ErrorCallbackList; | 78 typedef std::list<base::Closure> ErrorCallbackList; |
| 77 ErrorCallbackList error_callbacks_; | 79 ErrorCallbackList error_callbacks_; |
| 78 | 80 |
| 79 // Each of these converters mixes inputs with a given sample rate and | 81 // Each of these converters mixes inputs with a given sample rate and |
| 80 // resamples them to the output sample rate. Inputs not reqiuring resampling | 82 // resamples them to the output sample rate. Inputs not reqiuring resampling |
| 81 // go directly to |master_converter_|. | 83 // go directly to |master_converter_|. |
| 82 AudioConvertersMap converters_; | 84 AudioConvertersMap converters_; |
| 83 | 85 |
| 84 // Master converter which mixes all the outputs from |converters_| as well as | 86 // Master converter which mixes all the outputs from |converters_| as well as |
| 85 // mixer inputs that are in the output sample rate. | 87 // mixer inputs that are in the output sample rate. |
| 86 AudioConverter master_converter_; | 88 AudioConverter master_converter_; |
| 87 | 89 |
| 88 // Handles physical stream pause when no inputs are playing. For latency | 90 // Handles physical stream pause when no inputs are playing. For latency |
| 89 // reasons we don't want to immediately pause the physical stream. | 91 // reasons we don't want to immediately pause the physical stream. |
| 90 base::TimeDelta pause_delay_; | 92 base::TimeDelta pause_delay_; |
| 91 base::TimeTicks last_play_time_; | 93 base::TimeTicks last_play_time_; |
| 92 bool playing_; | 94 bool playing_; |
| 93 | 95 |
| 94 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 96 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 } // namespace media | 99 } // namespace media |
| 98 | 100 |
| 99 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 101 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |