| 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 <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "media/base/audio_renderer_mixer_input.h" | 13 #include "media/base/audio_renderer_mixer_input.h" |
| 14 #include "media/base/audio_renderer_sink.h" | 14 #include "media/base/audio_renderer_sink.h" |
| 15 #include "media/base/multi_channel_resampler.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 // Mixes a set of AudioRendererMixerInputs into a single output stream which is | 19 // Mixes a set of AudioRendererMixerInputs into a single output stream which is |
| 19 // funneled into a single shared AudioRendererSink; saving a bundle on renderer | 20 // funneled into a single shared AudioRendererSink; saving a bundle on renderer |
| 20 // side resources. | 21 // side resources. Resampling is done post-mixing as it is the most expensive |
| 21 // TODO(dalecurtis): Update documentation once resampling is available. | 22 // process. If the input sample rate matches the audio hardware sample rate, no |
| 23 // resampling is done. |
| 22 class MEDIA_EXPORT AudioRendererMixer | 24 class MEDIA_EXPORT AudioRendererMixer |
| 23 : public base::RefCountedThreadSafe<AudioRendererMixer>, | 25 : public base::RefCountedThreadSafe<AudioRendererMixer>, |
| 24 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 26 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback), |
| 27 NON_EXPORTED_BASE( |
| 28 public MultiChannelResampler::MultiChannelAudioSourceProvider) { |
| 25 public: | 29 public: |
| 26 AudioRendererMixer(const AudioParameters& params, | 30 AudioRendererMixer(const AudioParameters& params, |
| 27 const scoped_refptr<AudioRendererSink>& sink); | 31 const scoped_refptr<AudioRendererSink>& sink); |
| 28 | 32 |
| 29 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. | 33 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. |
| 30 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 34 void AddMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 31 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); | 35 void RemoveMixerInput(const scoped_refptr<AudioRendererMixerInput>& input); |
| 32 | 36 |
| 33 protected: | 37 protected: |
| 34 friend class base::RefCountedThreadSafe<AudioRendererMixer>; | 38 friend class base::RefCountedThreadSafe<AudioRendererMixer>; |
| 35 virtual ~AudioRendererMixer(); | 39 virtual ~AudioRendererMixer(); |
| 36 | 40 |
| 37 private: | 41 private: |
| 38 // AudioRendererSink::RenderCallback implementation. | 42 // AudioRendererSink::RenderCallback implementation. |
| 39 virtual int Render(const std::vector<float*>& audio_data, | 43 virtual int Render(const std::vector<float*>& audio_data, |
| 40 int number_of_frames, | 44 int number_of_frames, |
| 41 int audio_delay_milliseconds) OVERRIDE; | 45 int audio_delay_milliseconds) OVERRIDE; |
| 42 virtual void OnRenderError() OVERRIDE; | 46 virtual void OnRenderError() OVERRIDE; |
| 43 | 47 |
| 44 // AudioParameters this mixer was constructed with. | 48 // MultiChannelResampler::MultiChannelAudioSourceProvider implementation and |
| 45 AudioParameters audio_parameters_; | 49 // main worker method for AudioRendererMixer. Handles mixing and volume |
| 50 // adjustment. Renders |number_of_frames| into |audio_data|. When resampling |
| 51 // is necessary, ProvideInput() will be called by MultiChannelResampler when |
| 52 // more data is necessary. |
| 53 virtual void ProvideInput(const std::vector<float*>& audio_data, |
| 54 int number_of_frames) OVERRIDE; |
| 55 |
| 56 // AudioParameters this mixer will output with. |
| 57 AudioParameters output_parameters_; |
| 46 | 58 |
| 47 // Output sink for this mixer. | 59 // Output sink for this mixer. |
| 48 scoped_refptr<AudioRendererSink> audio_sink_; | 60 scoped_refptr<AudioRendererSink> audio_sink_; |
| 49 | 61 |
| 50 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe | 62 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe |
| 51 // through |mixer_inputs_lock_|. | 63 // through |mixer_inputs_lock_|. |
| 52 typedef std::set< scoped_refptr<AudioRendererMixerInput> > | 64 typedef std::set< scoped_refptr<AudioRendererMixerInput> > |
| 53 AudioRendererMixerInputSet; | 65 AudioRendererMixerInputSet; |
| 54 AudioRendererMixerInputSet mixer_inputs_; | 66 AudioRendererMixerInputSet mixer_inputs_; |
| 55 base::Lock mixer_inputs_lock_; | 67 base::Lock mixer_inputs_lock_; |
| 56 | 68 |
| 69 // Vector for rendering audio data from each mixer input. |
| 70 std::vector<float*> mixer_input_audio_data_; |
| 71 |
| 72 // Handles resampling post-mixing. |
| 73 scoped_ptr<MultiChannelResampler> resampler_; |
| 74 |
| 75 // The audio delay in milliseconds received by the last Render() call. |
| 76 int current_audio_delay_milliseconds_; |
| 77 |
| 57 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 78 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 58 }; | 79 }; |
| 59 | 80 |
| 60 } // namespace media | 81 } // namespace media |
| 61 | 82 |
| 62 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 83 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |