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 scoped_refptr<AudioRendererSink> sink); | 30 scoped_refptr<AudioRendererSink> sink, |
| 31 const std::string& uma_histogram); | |
| 31 ~AudioRendererMixer() override; | 32 ~AudioRendererMixer() override; |
| 32 | 33 |
| 33 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. | 34 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. |
| 34 void AddMixerInput(const AudioParameters& input_params, | 35 void AddMixerInput(const AudioParameters& input_params, |
| 35 AudioConverter::InputCallback* input); | 36 AudioConverter::InputCallback* input); |
| 36 void RemoveMixerInput(const AudioParameters& input_params, | 37 void RemoveMixerInput(const AudioParameters& input_params, |
| 37 AudioConverter::InputCallback* input); | 38 AudioConverter::InputCallback* input); |
| 38 | 39 |
| 39 // Since errors may occur even when no inputs are playing, an error callback | 40 // 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 | 41 // must be registered separately from adding a mixer input. The same callback |
| 41 // must be given to both the functions. | 42 // must be given to both the functions. |
| 42 void AddErrorCallback(const base::Closure& error_cb); | 43 void AddErrorCallback(const base::Closure& error_cb); |
| 43 void RemoveErrorCallback(const base::Closure& error_cb); | 44 void RemoveErrorCallback(const base::Closure& error_cb); |
| 44 | 45 |
| 45 void set_pause_delay_for_testing(base::TimeDelta delay) { | 46 void set_pause_delay_for_testing(base::TimeDelta delay) { |
| 46 pause_delay_ = delay; | 47 pause_delay_ = delay; |
| 47 } | 48 } |
| 48 | 49 |
| 49 OutputDeviceInfo GetOutputDeviceInfo(); | 50 OutputDeviceInfo GetOutputDeviceInfo(); |
| 50 | 51 |
| 52 AudioParameters GetOutputParamsForTesting() { return output_params_; }; | |
|
tommi (sloooow) - chröme
2016/06/28 14:14:54
nit: const&
o1ka
2016/06/29 10:11:26
Done.
| |
| 53 | |
| 51 private: | 54 private: |
| 55 class UMAMaxValueTracker; | |
| 56 | |
| 52 // Maps input sample rate to the dedicated converter. | 57 // Maps input sample rate to the dedicated converter. |
| 53 using AudioConvertersMap = | 58 using AudioConvertersMap = |
| 54 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; | 59 std::map<int, std::unique_ptr<LoopbackAudioConverter>>; |
| 55 | 60 |
| 56 // AudioRendererSink::RenderCallback implementation. | 61 // AudioRendererSink::RenderCallback implementation. |
| 57 int Render(AudioBus* audio_bus, | 62 int Render(AudioBus* audio_bus, |
| 58 uint32_t frames_delayed, | 63 uint32_t frames_delayed, |
| 59 uint32_t frames_skipped) override; | 64 uint32_t frames_skipped) override; |
| 60 void OnRenderError() override; | 65 void OnRenderError() override; |
| 61 | 66 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 84 // Master converter which mixes all the outputs from |converters_| as well as | 89 // Master converter which mixes all the outputs from |converters_| as well as |
| 85 // mixer inputs that are in the output sample rate. | 90 // mixer inputs that are in the output sample rate. |
| 86 AudioConverter master_converter_; | 91 AudioConverter master_converter_; |
| 87 | 92 |
| 88 // Handles physical stream pause when no inputs are playing. For latency | 93 // Handles physical stream pause when no inputs are playing. For latency |
| 89 // reasons we don't want to immediately pause the physical stream. | 94 // reasons we don't want to immediately pause the physical stream. |
| 90 base::TimeDelta pause_delay_; | 95 base::TimeDelta pause_delay_; |
| 91 base::TimeTicks last_play_time_; | 96 base::TimeTicks last_play_time_; |
| 92 bool playing_; | 97 bool playing_; |
| 93 | 98 |
| 99 // Tracks the maximum number of simultaneous mixer inputs and logs it into | |
| 100 // UMA histogram upon the destruction. | |
| 101 std::unique_ptr<UMAMaxValueTracker> input_count_tracker_; | |
| 102 | |
| 94 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 103 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 95 }; | 104 }; |
| 96 | 105 |
| 97 } // namespace media | 106 } // namespace media |
| 98 | 107 |
| 99 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 108 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |