| 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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "media/base/audio_converter.h" | 12 #include "media/base/audio_converter.h" |
| 13 #include "media/base/audio_renderer_sink.h" | 13 #include "media/base/audio_renderer_sink.h" |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 // Mixes a set of AudioConverter::InputCallbacks into a single output stream | 17 // Mixes a set of AudioConverter::InputCallbacks into a single output stream |
| 18 // which is funneled into a single shared AudioRendererSink; saving a bundle | 18 // which is funneled into a single shared AudioRendererSink; saving a bundle |
| 19 // on renderer side resources. | 19 // on renderer side resources. |
| 20 class MEDIA_EXPORT AudioRendererMixer | 20 class MEDIA_EXPORT AudioRendererMixer |
| 21 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { | 21 : NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback) { |
| 22 public: | 22 public: |
| 23 AudioRendererMixer(const AudioParameters& input_params, | 23 AudioRendererMixer(const AudioParameters& input_params, |
| 24 const AudioParameters& output_params, | 24 const AudioParameters& output_params, |
| 25 const scoped_refptr<AudioRendererSink>& sink); | 25 const scoped_refptr<AudioRendererSink>& sink); |
| 26 virtual ~AudioRendererMixer(); | 26 virtual ~AudioRendererMixer(); |
| 27 | 27 |
| 28 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. | 28 // Add or remove a mixer input from mixing; called by AudioRendererMixerInput. |
| 29 void AddMixerInput(AudioConverter::InputCallback* input, | 29 void AddMixerInput(AudioConverter::InputCallback* input); |
| 30 const base::Closure& error_cb); | |
| 31 void RemoveMixerInput(AudioConverter::InputCallback* input); | 30 void RemoveMixerInput(AudioConverter::InputCallback* input); |
| 32 | 31 |
| 32 // Since errors may occur even when no inputs are playing, an error callback |
| 33 // must be registered separately from adding a mixer. |
| 34 void RegisterErrorCallback(AudioConverter::InputCallback* input, |
| 35 const base::Closure& error_cb); |
| 36 void UnregisterErrorCallback(AudioConverter::InputCallback* input); |
| 37 |
| 33 void set_pause_delay_for_testing(base::TimeDelta delay) { | 38 void set_pause_delay_for_testing(base::TimeDelta delay) { |
| 34 pause_delay_ = delay; | 39 pause_delay_ = delay; |
| 35 } | 40 } |
| 36 | 41 |
| 37 private: | 42 private: |
| 38 // AudioRendererSink::RenderCallback implementation. | 43 // AudioRendererSink::RenderCallback implementation. |
| 39 virtual int Render(AudioBus* audio_bus, | 44 virtual int Render(AudioBus* audio_bus, |
| 40 int audio_delay_milliseconds) OVERRIDE; | 45 int audio_delay_milliseconds) OVERRIDE; |
| 41 virtual void OnRenderError() OVERRIDE; | 46 virtual void OnRenderError() OVERRIDE; |
| 42 | 47 |
| 43 // Output sink for this mixer. | 48 // Output sink for this mixer. |
| 44 scoped_refptr<AudioRendererSink> audio_sink_; | 49 scoped_refptr<AudioRendererSink> audio_sink_; |
| 45 | 50 |
| 46 // Set of mixer inputs to be mixed by this mixer. Access is thread-safe | 51 // ---------------[ All variables below protected by |lock_| ]--------------- |
| 47 // through |mixer_inputs_lock_|. | 52 base::Lock lock_; |
| 53 |
| 54 // Set of error callbacks used by this mixer. |
| 48 typedef std::map<AudioConverter::InputCallback*, base::Closure> | 55 typedef std::map<AudioConverter::InputCallback*, base::Closure> |
| 49 AudioRendererMixerInputSet; | 56 AudioRendererMixerErrorCallbackMap; |
| 50 AudioRendererMixerInputSet mixer_inputs_; | 57 AudioRendererMixerErrorCallbackMap error_callbacks_; |
| 51 base::Lock mixer_inputs_lock_; | |
| 52 | 58 |
| 53 // Handles mixing and resampling between input and output parameters. | 59 // Handles mixing and resampling between input and output parameters. |
| 54 AudioConverter audio_converter_; | 60 AudioConverter audio_converter_; |
| 55 | 61 |
| 56 // Handles physical stream pause when no inputs are playing. For latency | 62 // Handles physical stream pause when no inputs are playing. For latency |
| 57 // reasons we don't want to immediately pause the physical stream. | 63 // reasons we don't want to immediately pause the physical stream. |
| 58 base::TimeDelta pause_delay_; | 64 base::TimeDelta pause_delay_; |
| 59 base::TimeTicks last_play_time_; | 65 base::TimeTicks last_play_time_; |
| 60 bool playing_; | 66 bool playing_; |
| 61 | 67 |
| 62 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); | 68 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixer); |
| 63 }; | 69 }; |
| 64 | 70 |
| 65 } // namespace media | 71 } // namespace media |
| 66 | 72 |
| 67 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ | 73 #endif // MEDIA_BASE_AUDIO_RENDERER_MIXER_H_ |
| OLD | NEW |