/* gstreamermm - a C++ wrapper for gstreamer
 *
 * Copyright 2008 The gstreamermm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
#include <gstreamermm/audioringbuffer.h>
#include <gst/audio/gstaudiosrc.h>
#include <gstreamermm/audiobasesrc.h>

_DEFS(gstreamermm,gst)

namespace Gst
{

/** A simple base class for audio sources.
 * This is the most simple base class for audio sources that only requires
 * subclasses to implement a set of simple virtual functions:
 *
 * - open_vfunc() - Open the device.
 * - prepare_vfunc()  - Configure the device with the specified format.
 * - read_vfunc() - Read samples from the device.
 * - reset_vfunc() - Unblock reads and flush the device.
 * - get_delay_vfunc() - Get the number of samples written but not yet played
 * by the device.
 * - unprepare_vfunc() - Undo operations done by prepare.
 * - close_vfunc() - Close the device.
 *
 * All scheduling of samples and timestamps is done in this base class together
 * with Gst::AudioBaseSrc using a default implementation of a
 * Gst::AudioRingBuffer that uses threads.
 *
 * Last reviewed on 2006-09-27 (0.10.12)
 *
 * @ingroup GstBaseClasses
 */
class AudioSrc : public Gst::AudioBaseSrc
{
  _CLASS_GOBJECT(AudioSrc, GstAudioSrc, GST_AUDIO_SRC, Gst::AudioBaseSrc, GstAudioBaseSrc)

public:
  /** vfunc to open the device.
   */
  _WRAP_VFUNC(bool open(), "open")

  /** vfunc to configure device with spec.
   */
  virtual bool prepare_vfunc(Gst::AudioRingBufferSpec& spec);

  /** vfunc to undo the configuration.
   */
  _WRAP_VFUNC(bool unprepare(), "unprepare")

  /** vfunc to close the device.
   */
  _WRAP_VFUNC(bool close(), "close")

  /** vfunc to read samples to the audio device.
   */
  virtual guint read_vfunc(const void* data, guint length, ClockTime* timestamp);

  /** vfunc to get the number of samples queued in the device.
   */
  _WRAP_VFUNC(guint get_delay() const, "delay")

  /** vfunc to unblock a read to the device and reset.
   */
  _WRAP_VFUNC(void reset(), "reset")

protected:
#m4begin
  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
  klass->prepare = &prepare_vfunc_callback;
  klass->read = &read_vfunc_callback;
  _SECTION(SECTION_PH_VFUNCS)
  static gboolean prepare_vfunc_callback(GstAudioSrc* self, GstAudioRingBufferSpec* spec);
  static guint read_vfunc_callback(GstAudioSrc* self, gpointer data, guint length, ClockTime* timestamp);
  _POP()
#m4end
};

} // namespace Gst
