| 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 <set> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "media/base/audio_converter.h" |
| 11 #include "media/base/audio_renderer_mixer_input.h" | 12 #include "media/base/audio_renderer_mixer_input.h" |
| 12 #include "media/base/audio_renderer_sink.h" | 13 #include "media/base/audio_renderer_sink.h" |
| 13 #include "media/base/multi_channel_resampler.h" | |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 // Mixes a set of AudioRendererMixerInputs into a single output stream which is | 17 // Mixes a set of AudioRendererMixerInputs into a single output stream which is |
| 18 // funneled into a single shared AudioRendererSink; saving a bundle on renderer | 18 // funneled into a single shared AudioRendererSink; saving a bundle on renderer |
| 19 // side resources. Resampling is done post-mixing as it is the most expensive | 19 // side resources. |
| 20 // process. If the input sample rate matches the audio hardware sample rate, no | |
| 21 // resampling is done. | |
| 22 class MEDIA_EXPORT AudioRendererMixer | 20 class MEDIA_EXPORT AudioRendererMixer |
| 23 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 21 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { |
| 24 public: | 22 public: |
| 25 AudioRendererMixer(const AudioParameters& input_params, | 23 AudioRendererMixer(const AudioParameters& input_params, |
| 26 const AudioParameters& output_params, | 24 const AudioParameters& output_params, |
| 27 const scoped_refptr<AudioRendererSink>& sink); | 25 const scoped_refptr<AudioRendererSink>& sink); |
| 28 virtual ~AudioRendererMixer(); | 26 virtual ~AudioRendererMixer(); |
| 29 | 27 |
| 30 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. | 28 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. |
| 31 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 29 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 32 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 30 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 33 | 31 |
| 34 private: | 32 private: |
| 35 // AudioRendererSink::RenderCallback implementation. | 33 // AudioRendererSink::RenderCallback implementation. |
| 36 virtual int Render(AudioBus* audio_bus, | 34 virtual int Render(AudioBus* audio_bus, |
| 37 int audio_delay_milliseconds) OVERRIDE; | 35 int audio_delay_milliseconds) OVERRIDE; |
| 38 virtual void OnRenderError() OVERRIDE; | 36 virtual void OnRenderError() OVERRIDE; |
| 39 | 37 |
| 40 // Handles mixing and volume adjustment. Fully fills |audio_bus| with mixed | |
| 41 // audio data. When resampling is necessary, ProvideInput() will be called | |
| 42 // by MultiChannelResampler when more data is necessary. | |
| 43 void ProvideInput(AudioBus* audio_bus); | |
| 44 | |
| 45 // Output sink for this mixer. | 38 // Output sink for this mixer. |
| 46 scoped_refptr<AudioRendererSink> audio_sink_; | 39 scoped_refptr<AudioRendererSink> audio_sink_; |
| 47 | 40 |
| 48 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe | 41 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe |
| 49 // through |mixer_inputs_lock_|. | 42 // through |mixer_inputs_lock_|. |
| 50 typedef std::set< scoped_refptr<AudioRendererMixerInput> > | 43 typedef std::list<scoped_refptr<AudioRendererMixerInput> > |
| 51 AudioRendererMixerInputSet; | 44 AudioRendererMixerInputSet; |
| 52 AudioRendererMixerInputSet mixer_inputs_; | 45 AudioRendererMixerInputSet mixer_inputs_; |
| 53 base::Lock mixer_inputs_lock_; | 46 base::Lock mixer_inputs_lock_; |
| 54 | 47 |
| 55 // Vector for rendering audio data from each mixer input. | 48 // Handles mixing and resampling between input and output parameters. |
| 56 scoped_ptr<AudioBus> mixer_input_audio_bus_; | 49 AudioConverter audio_converter_; |
| 57 | |
| 58 // Handles resampling post-mixing. | |
| 59 scoped_ptr<MultiChannelResampler> resampler_; | |
| 60 | |
| 61 // The audio delay in milliseconds received by the last Render() call. | |
| 62 int current_audio_delay_milliseconds_; | |
| 63 | |
| 64 // Ratio of input data to output data. Used to scale audio delay information. | |
| 65 double io_ratio_; | |
| 66 double input_ms_per_frame_; | |
| 67 | 50 |
| 68 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 51 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 69 }; | 52 }; |
| 70 | 53 |
| 71 } // namespace media | 54 } // namespace media |
| 72 | 55 |
| 73 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 56 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |