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<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 |
(...skipping 15 matching lines...) Expand all Loading... |
56 // AudioRendererSink::RenderCallback implementation. | 56 // AudioRendererSink::RenderCallback implementation. |
57 int Render(AudioBus* audio_bus, | 57 int Render(AudioBus* audio_bus, |
58 uint32_t frames_delayed, | 58 uint32_t frames_delayed, |
59 uint32_t frames_skipped) override; | 59 uint32_t frames_skipped) override; |
60 void OnRenderError() override; | 60 void OnRenderError() override; |
61 | 61 |
62 bool is_master_sample_rate(int sample_rate) { | 62 bool is_master_sample_rate(int sample_rate) { |
63 return sample_rate == output_params_.sample_rate(); | 63 return sample_rate == output_params_.sample_rate(); |
64 } | 64 } |
65 | 65 |
| 66 // Output parameters for this mixer. |
| 67 const AudioParameters output_params_; |
| 68 |
66 // Output sink for this mixer. | 69 // Output sink for this mixer. |
67 scoped_refptr<AudioRendererSink> audio_sink_; | 70 const scoped_refptr<AudioRendererSink> audio_sink_; |
68 | |
69 // Output parameters for this mixer. | |
70 AudioParameters output_params_; | |
71 | 71 |
72 // ---------------[ All variables below protected by |lock_| ]--------------- | 72 // ---------------[ All variables below protected by |lock_| ]--------------- |
73 base::Lock lock_; | 73 base::Lock lock_; |
74 | 74 |
75 // List of error callbacks used by this mixer. | 75 // List of error callbacks used by this mixer. |
76 typedef std::list<base::Closure> ErrorCallbackList; | 76 typedef std::list<base::Closure> ErrorCallbackList; |
77 ErrorCallbackList error_callbacks_; | 77 ErrorCallbackList error_callbacks_; |
78 | 78 |
79 // Each of these converters mixes inputs with a given sample rate and | 79 // Each of these converters mixes inputs with a given sample rate and |
80 // resamples them to the output sample rate. Inputs not reqiuring resampling | 80 // resamples them to the output sample rate. Inputs not reqiuring resampling |
81 // go directly to |master_converter_|. | 81 // go directly to |master_converter_|. |
82 AudioConvertersMap converters_; | 82 AudioConvertersMap converters_; |
83 | 83 |
84 // Master converter which mixes all the outputs from |converters_| as well as | 84 // Master converter which mixes all the outputs from |converters_| as well as |
85 // mixer inputs that are in the output sample rate. | 85 // mixer inputs that are in the output sample rate. |
86 AudioConverter master_converter_; | 86 AudioConverter master_converter_; |
87 | 87 |
88 // Handles physical stream pause when no inputs are playing. For latency | 88 // Handles physical stream pause when no inputs are playing. For latency |
89 // reasons we don't want to immediately pause the physical stream. | 89 // reasons we don't want to immediately pause the physical stream. |
90 base::TimeDelta pause_delay_; | 90 base::TimeDelta pause_delay_; |
91 base::TimeTicks last_play_time_; | 91 base::TimeTicks last_play_time_; |
92 bool playing_; | 92 bool playing_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 94 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
95 }; | 95 }; |
96 | 96 |
97 } // namespace media | 97 } // namespace media |
98 | 98 |
99 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 99 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
OLD | NEW |