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_SINK_H_
      6 #define MEDIA_BASE_AUDIO_RENDERER_SINK_H_
      7 
      8 #include <vector>
      9 #include "base/basictypes.h"
     10 #include "base/logging.h"
     11 #include "base/memory/ref_counted.h"
     12 #include "media/audio/audio_parameters.h"
     13 #include "media/base/audio_bus.h"
     14 #include "media/base/media_export.h"
     15 
     16 namespace media {
     17 
     18 // AudioRendererSink is an interface representing the end-point for
     19 // rendered audio.  An implementation is expected to
     20 // periodically call Render() on a callback object.
     21 
     22 class AudioRendererSink
     23     : public base::RefCountedThreadSafe<media::AudioRendererSink> {
     24  public:
     25   class RenderCallback {
     26    public:
     27     // Attempts to completely fill all channels of |dest|, returns actual
     28     // number of frames filled.
     29     virtual int Render(AudioBus* dest, int audio_delay_milliseconds) = 0;
     30 
     31     // Synchronized audio I/O - see InitializeIO() below.
     32     virtual void RenderIO(AudioBus* source,
     33                           AudioBus* dest,
     34                           int audio_delay_milliseconds) {}
     35 
     36     // Signals an error has occurred.
     37     virtual void OnRenderError() = 0;
     38 
     39    protected:
     40     virtual ~RenderCallback() {}
     41   };
     42 
     43   // Sets important information about the audio stream format.
     44   // It must be called before any of the other methods.
     45   virtual void Initialize(const AudioParameters& params,
     46                           RenderCallback* callback) = 0;
     47 
     48   // Starts audio playback.
     49   virtual void Start() = 0;
     50 
     51   // Stops audio playback.
     52   virtual void Stop() = 0;
     53 
     54   // Pauses playback.
     55   virtual void Pause() = 0;
     56 
     57   // Resumes playback after calling Pause().
     58   virtual void Play() = 0;
     59 
     60   // Sets the playback volume, with range [0.0, 1.0] inclusive.
     61   // Returns |true| on success.
     62   virtual bool SetVolume(double volume) = 0;
     63 
     64  protected:
     65   friend class base::RefCountedThreadSafe<AudioRendererSink>;
     66   virtual ~AudioRendererSink() {}
     67 };
     68 
     69 }  // namespace media
     70 
     71 #endif  // MEDIA_BASE_AUDIO_RENDERER_SINK_H_
     72