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