Home | History | Annotate | Download | only in base
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
      6 #define MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/callback.h"
     11 #include "media/base/audio_converter.h"
     12 #include "media/base/audio_renderer_sink.h"
     13 
     14 namespace media {
     15 
     16 class AudioRendererMixer;
     17 
     18 class MEDIA_EXPORT AudioRendererMixerInput
     19     : NON_EXPORTED_BASE(public AudioRendererSink),
     20       public AudioConverter::InputCallback {
     21  public:
     22   typedef base::Callback<AudioRendererMixer*(
     23       const AudioParameters& params)> GetMixerCB;
     24   typedef base::Callback<void(const AudioParameters& params)> RemoveMixerCB;
     25 
     26   AudioRendererMixerInput(
     27       const GetMixerCB& get_mixer_cb, const RemoveMixerCB& remove_mixer_cb);
     28 
     29   // AudioRendererSink implementation.
     30   virtual void Start() OVERRIDE;
     31   virtual void Stop() OVERRIDE;
     32   virtual void Play() OVERRIDE;
     33   virtual void Pause() OVERRIDE;
     34   virtual bool SetVolume(double volume) OVERRIDE;
     35   virtual void Initialize(const AudioParameters& params,
     36                           AudioRendererSink::RenderCallback* renderer) OVERRIDE;
     37 
     38   // Called by AudioRendererMixer when an error occurs.
     39   void OnRenderError();
     40 
     41  protected:
     42   virtual ~AudioRendererMixerInput();
     43 
     44  private:
     45   friend class AudioRendererMixerInputTest;
     46 
     47   bool playing_;
     48   bool initialized_;
     49   double volume_;
     50 
     51   // AudioConverter::InputCallback implementation.
     52   virtual double ProvideInput(AudioBus* audio_bus,
     53                               base::TimeDelta buffer_delay) OVERRIDE;
     54 
     55   // Callbacks provided during construction which allow AudioRendererMixerInput
     56   // to retrieve a mixer during Initialize() and notify when it's done with it.
     57   GetMixerCB get_mixer_cb_;
     58   RemoveMixerCB remove_mixer_cb_;
     59 
     60   // AudioParameters received during Initialize().
     61   AudioParameters params_;
     62 
     63   // AudioRendererMixer provided through |get_mixer_cb_| during Initialize(),
     64   // guaranteed to live (at least) until |remove_mixer_cb_| is called.
     65   AudioRendererMixer* mixer_;
     66 
     67   // Source of audio data which is provided to the mixer.
     68   AudioRendererSink::RenderCallback* callback_;
     69 
     70   // Error callback for handing to AudioRendererMixer.
     71   base::Closure error_cb_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerInput);
     74 };
     75 
     76 }  // namespace media
     77 
     78 #endif  // MEDIA_BASE_AUDIO_RENDERER_MIXER_INPUT_H_
     79