| 1 |
/* gstreamermm - a C++ wrapper for gstreamer |
| 2 |
* |
| 3 |
* Copyright 2008-2016 The gstreamermm Development Team |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <gstreamermm/audioringbuffer.h> |
| 21 |
#include <gst/audio/gstaudiosrc.h> |
| 22 |
#include <gstreamermm/audiobasesrc.h> |
| 23 |
|
| 24 |
_DEFS(gstreamermm,gst) |
| 25 |
|
| 26 |
namespace Gst |
| 27 |
{ |
| 28 |
|
| 29 |
/** A simple base class for audio sources. |
| 30 |
* This is the most simple base class for audio sources that only requires |
| 31 |
* subclasses to implement a set of simple virtual functions: |
| 32 |
* |
| 33 |
* - open_vfunc() - Open the device. |
| 34 |
* - prepare_vfunc() - Configure the device with the specified format. |
| 35 |
* - read_vfunc() - Read samples from the device. |
| 36 |
* - reset_vfunc() - Unblock reads and flush the device. |
| 37 |
* - get_delay_vfunc() - Get the number of samples written but not yet played |
| 38 |
* by the device. |
| 39 |
* - unprepare_vfunc() - Undo operations done by prepare. |
| 40 |
* - close_vfunc() - Close the device. |
| 41 |
* |
| 42 |
* All scheduling of samples and timestamps is done in this base class together |
| 43 |
* with Gst::AudioBaseSrc using a default implementation of a |
| 44 |
* Gst::AudioRingBuffer that uses threads. |
| 45 |
* |
| 46 |
* Last reviewed on 2016-04-23 (1.8.0) |
| 47 |
* |
| 48 |
* @ingroup GstBaseClasses |
| 49 |
*/ |
| 50 |
class AudioSrc : public Gst::AudioBaseSrc |
| 51 |
{ |
| 52 |
_CLASS_GOBJECT(AudioSrc, GstAudioSrc, GST_AUDIO_SRC, Gst::AudioBaseSrc, GstAudioBaseSrc) |
| 53 |
|
| 54 |
public: |
| 55 |
/** vfunc to open the device. |
| 56 |
*/ |
| 57 |
_WRAP_VFUNC(bool open(), "open") |
| 58 |
|
| 59 |
/** vfunc to configure device with spec. |
| 60 |
*/ |
| 61 |
virtual bool prepare_vfunc(Gst::AudioRingBufferSpec& spec); |
| 62 |
|
| 63 |
/** vfunc to undo the configuration. |
| 64 |
*/ |
| 65 |
_WRAP_VFUNC(bool unprepare(), "unprepare") |
| 66 |
|
| 67 |
/** vfunc to close the device. |
| 68 |
*/ |
| 69 |
_WRAP_VFUNC(bool close(), "close") |
| 70 |
|
| 71 |
/** vfunc to read samples to the audio device. |
| 72 |
*/ |
| 73 |
virtual guint read_vfunc(const void* data, guint length, Gst::ClockTime& timestamp); |
| 74 |
|
| 75 |
/** vfunc to get the number of samples queued in the device. |
| 76 |
*/ |
| 77 |
_WRAP_VFUNC(guint get_delay() const, "delay") |
| 78 |
|
| 79 |
/** vfunc to unblock a read to the device and reset. |
| 80 |
*/ |
| 81 |
_WRAP_VFUNC(void reset(), "reset") |
| 82 |
|
| 83 |
protected: |
| 84 |
#m4begin |
| 85 |
_PUSH(SECTION_PCC_CLASS_INIT_VFUNCS) |
| 86 |
klass->prepare = &prepare_vfunc_callback; |
| 87 |
klass->read = &read_vfunc_callback; |
| 88 |
_SECTION(SECTION_PH_VFUNCS) |
| 89 |
static gboolean prepare_vfunc_callback(GstAudioSrc* self, GstAudioRingBufferSpec* spec); |
| 90 |
static guint read_vfunc_callback(GstAudioSrc* self, gpointer data, guint length, ClockTime* timestamp); |
| 91 |
_POP() |
| 92 |
#m4end |
| 93 |
}; |
| 94 |
|
| 95 |
} // namespace Gst |