13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file.
43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#ifndef MEDIA_AUDIO_CLOCKLESS_AUDIO_SINK_H_
63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define MEDIA_AUDIO_CLOCKLESS_AUDIO_SINK_H_
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/time/time.h"
103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "media/base/audio_renderer_sink.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace base {
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SingleThreadTaskRunner;
143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace media {
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class AudioBus;
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class ClocklessAudioSinkThread;
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Implementation of an AudioRendererSink that consumes the audio as fast as
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// possible. This class does not support multiple Play()/Pause() events.
223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class MEDIA_EXPORT ClocklessAudioSink
233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    : NON_EXPORTED_BASE(public AudioRendererSink) {
243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public:
253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ClocklessAudioSink();
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // AudioRendererSink implementation.
283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void Initialize(const AudioParameters& params,
293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                          RenderCallback* callback) OVERRIDE;
303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void Start() OVERRIDE;
313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void Stop() OVERRIDE;
323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void Pause() OVERRIDE;
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void Play() OVERRIDE;
343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual bool SetVolume(double volume) OVERRIDE;
353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Returns the time taken to consume all the audio.
373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  base::TimeDelta render_time() { return playback_time_; }
383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) protected:
403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual ~ClocklessAudioSink();
413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) private:
433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_ptr<ClocklessAudioSinkThread> thread_;
443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bool initialized_;
453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bool playing_;
463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Time taken in last set of Render() calls.
483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  base::TimeDelta playback_time_;
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ClocklessAudioSink);
513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}  // namespace media
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#endif  // MEDIA_AUDIO_CLOCKLESS_AUDIO_SINK_H_
56