root / src / gst / engine / audioSource.h @ d6a53ea2
History | View | Annotate | Download (7.9 kB)
| 1 |
// audioSource.h
|
|---|---|
| 2 |
// Copyright 2008 Koya Charles & Tristan Matthews
|
| 3 |
//
|
| 4 |
// This file is part of [propulse]ART.
|
| 5 |
//
|
| 6 |
// [propulse]ART is free software: you can redistribute it and/or modify
|
| 7 |
// it under the terms of the GNU General Public License as published by
|
| 8 |
// the Free Software Foundation, either version 3 of the License, or
|
| 9 |
// (at your option) any later version.
|
| 10 |
//
|
| 11 |
// [propulse]ART is distributed in the hope that it will be useful,
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
// GNU General Public License for more details.
|
| 15 |
//
|
| 16 |
// You should have received a copy of the GNU General Public License
|
| 17 |
// along with [propulse]ART. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
//
|
| 19 |
|
| 20 |
/** \file audioSource.h
|
| 21 |
* A family of classes representing different types/sources of audio input. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef _AUDIO_SOURCE_H_
|
| 25 |
#define _AUDIO_SOURCE_H_
|
| 26 |
|
| 27 |
#include "gstLinkable.h" |
| 28 |
#include "interleave.h" |
| 29 |
#include "busMsgHandler.h" |
| 30 |
|
| 31 |
// forward declarations
|
| 32 |
class AudioSourceConfig; |
| 33 |
|
| 34 |
/**
|
| 35 |
* Abstract base class from which our audio sources are derived. |
| 36 |
* Uses template method to define the initialization process that subclasses will have to |
| 37 |
* implement (in part) and/or override. Any direct, concrete descendant of this class will not |
| 38 |
* need to have its audio frames interleaved. |
| 39 |
*/ |
| 40 |
|
| 41 |
class AudioSource : public GstLinkableSource |
| 42 |
{
|
| 43 |
public:
|
| 44 |
~AudioSource(); |
| 45 |
virtual void init();
|
| 46 |
|
| 47 |
protected:
|
| 48 |
explicit AudioSource(const AudioSourceConfig &config);
|
| 49 |
|
| 50 |
/// Implemented by subclasses to perform other specific initialization
|
| 51 |
virtual void sub_init() = 0; |
| 52 |
|
| 53 |
/// Audio parameter object
|
| 54 |
const AudioSourceConfig &config_;
|
| 55 |
|
| 56 |
/// GstElements representing each source and audioconvert
|
| 57 |
GstElement *source_; |
| 58 |
|
| 59 |
private:
|
| 60 |
|
| 61 |
GstElement *srcElement() { return source_; }
|
| 62 |
|
| 63 |
/// No Copy Constructor
|
| 64 |
AudioSource(const AudioSource&);
|
| 65 |
/// No Assignment Operator
|
| 66 |
AudioSource& operator=(const AudioSource&);
|
| 67 |
}; |
| 68 |
|
| 69 |
/**
|
| 70 |
* Abstract child of AudioSource whose audio frames must be interleaved before pushing audio further down pipeline. |
| 71 |
*/ |
| 72 |
|
| 73 |
class InterleavedAudioSource |
| 74 |
: public AudioSource |
| 75 |
{
|
| 76 |
protected:
|
| 77 |
/// Object initializer
|
| 78 |
void sub_init();
|
| 79 |
|
| 80 |
explicit InterleavedAudioSource(const AudioSourceConfig &config);
|
| 81 |
|
| 82 |
~InterleavedAudioSource(); |
| 83 |
|
| 84 |
/// Object which performs the interleaving of this source's channels
|
| 85 |
Interleave interleave_; |
| 86 |
std::vector<GstElement*> sources_, aconvs_; |
| 87 |
|
| 88 |
private:
|
| 89 |
|
| 90 |
GstElement *srcElement() { return interleave_.srcElement(); }
|
| 91 |
}; |
| 92 |
|
| 93 |
/**
|
| 94 |
* Concrete InterleavedAudioSource which gives us an array of sine-wave generating sources. |
| 95 |
* |
| 96 |
* AudioTestSource generates sine-tones, each of which alternate between two hard-coded frequencies. Their |
| 97 |
* combined output is then interleaved. |
| 98 |
*/ |
| 99 |
|
| 100 |
class AudioTestSource : public InterleavedAudioSource |
| 101 |
{
|
| 102 |
public:
|
| 103 |
explicit AudioTestSource(const AudioSourceConfig &config);
|
| 104 |
|
| 105 |
private:
|
| 106 |
void sub_init();
|
| 107 |
|
| 108 |
~AudioTestSource(); |
| 109 |
|
| 110 |
static gboolean timedCallback(GstClock *clock,
|
| 111 |
GstClockTime time, |
| 112 |
GstClockID id, |
| 113 |
gpointer user_data); |
| 114 |
void toggle_frequency();
|
| 115 |
|
| 116 |
GstClockID clockId_; |
| 117 |
int offset_;
|
| 118 |
|
| 119 |
static const double FREQUENCY[2][8]; |
| 120 |
/// No Copy Constructor
|
| 121 |
AudioTestSource(const AudioTestSource&);
|
| 122 |
/// No Assignment Operator
|
| 123 |
AudioTestSource& operator=(const AudioTestSource&);
|
| 124 |
}; |
| 125 |
|
| 126 |
/**
|
| 127 |
* \class AudioFileSource |
| 128 |
* Concrete AudioSource which provides playback of files. |
| 129 |
* |
| 130 |
* AudioFileSource plays back a file (determined by its AudioSourceConfig object). Depending |
| 131 |
* on its AudioSourceConfig object, it may loop the file. It implements the BusMsgHandler interface |
| 132 |
* so that it knows when an End-of-Signal event occurs, in which case it may |
| 133 |
* play the file again if it has been set to continue to play the file (either infinitely or for a finite |
| 134 |
* number of plays). |
| 135 |
*/ |
| 136 |
|
| 137 |
class AudioFileSource : public AudioSource, public BusMsgHandler |
| 138 |
{
|
| 139 |
public:
|
| 140 |
explicit AudioFileSource(const AudioSourceConfig &config);
|
| 141 |
|
| 142 |
private:
|
| 143 |
~AudioFileSource(); |
| 144 |
|
| 145 |
bool handleBusMsg(_GstMessage *msg);
|
| 146 |
|
| 147 |
static void cb_new_src_pad(GstElement * srcElement, |
| 148 |
GstPad * srcPad, |
| 149 |
gboolean last, |
| 150 |
void *data);
|
| 151 |
void loop(int nTimes); |
| 152 |
void sub_init();
|
| 153 |
|
| 154 |
void restartPlayback();
|
| 155 |
GstElement* decoder_; |
| 156 |
GstElement* aconv_; |
| 157 |
int loopCount_;
|
| 158 |
static const int LOOP_INFINITE; |
| 159 |
|
| 160 |
/// No Copy Constructor
|
| 161 |
AudioFileSource(const AudioFileSource&);
|
| 162 |
/// No Assignment Operator
|
| 163 |
AudioFileSource& operator=(const AudioFileSource&);
|
| 164 |
}; |
| 165 |
|
| 166 |
/**
|
| 167 |
* Concrete AudioSource which captures audio from ALSA |
| 168 |
* Has caps filter to allow number of channels to be variable. |
| 169 |
*/ |
| 170 |
|
| 171 |
class AudioAlsaSource : public AudioSource |
| 172 |
{
|
| 173 |
public:
|
| 174 |
explicit AudioAlsaSource(const AudioSourceConfig &config);
|
| 175 |
|
| 176 |
private:
|
| 177 |
~AudioAlsaSource(); |
| 178 |
|
| 179 |
void sub_init();
|
| 180 |
GstElement *srcElement() { return capsFilter_; }
|
| 181 |
|
| 182 |
GstElement *capsFilter_; |
| 183 |
GstElement *aconv_; |
| 184 |
/// No Copy Constructor
|
| 185 |
AudioAlsaSource(const AudioAlsaSource&);
|
| 186 |
/// No Assignment Operator
|
| 187 |
AudioAlsaSource& operator=(const AudioAlsaSource&);
|
| 188 |
}; |
| 189 |
|
| 190 |
/**
|
| 191 |
* Concrete AudioSource which captures audio from PulseAudio |
| 192 |
* Has caps filter to allow number of channels to be variable. |
| 193 |
*/ |
| 194 |
|
| 195 |
class AudioPulseSource : public AudioSource |
| 196 |
{
|
| 197 |
public:
|
| 198 |
explicit AudioPulseSource(const AudioSourceConfig &config);
|
| 199 |
private:
|
| 200 |
~AudioPulseSource(); |
| 201 |
|
| 202 |
void sub_init();
|
| 203 |
GstElement *srcElement() { return capsFilter_; }
|
| 204 |
|
| 205 |
GstElement *capsFilter_; |
| 206 |
GstElement *aconv_; |
| 207 |
/// No Copy Constructor
|
| 208 |
AudioPulseSource(const AudioPulseSource&);
|
| 209 |
/// No Assignment Operator
|
| 210 |
AudioPulseSource& operator=(const AudioPulseSource&);
|
| 211 |
}; |
| 212 |
|
| 213 |
/**
|
| 214 |
* Concrete AudioSource which captures audio from JACK, |
| 215 |
* and interleaves incoming jack buffers into one multichannel stream. |
| 216 |
*/ |
| 217 |
|
| 218 |
class AudioJackSource : public AudioSource |
| 219 |
{
|
| 220 |
public:
|
| 221 |
explicit AudioJackSource(const AudioSourceConfig &config);
|
| 222 |
|
| 223 |
private:
|
| 224 |
~AudioJackSource(); |
| 225 |
|
| 226 |
GstElement *srcElement() { return capsFilter_; }
|
| 227 |
void sub_init();
|
| 228 |
|
| 229 |
GstElement *capsFilter_; |
| 230 |
GstElement *aconv_; |
| 231 |
/// No Copy Constructor
|
| 232 |
AudioJackSource(const AudioJackSource&);
|
| 233 |
/// No Assignment Operator
|
| 234 |
AudioJackSource& operator=(const AudioJackSource&);
|
| 235 |
}; |
| 236 |
|
| 237 |
|
| 238 |
/**
|
| 239 |
* Concrete AudioSource which captures audio from dv device. |
| 240 |
* |
| 241 |
* This object is tightly coupled with VideoDvSource, as both (if present) will share one source_ GstElement, |
| 242 |
* and one dvdemux GstElement. It will look for both of these in the pipeline before trying to instantiate them. |
| 243 |
* If these GstElement are already present, AudioDvSource will simply store their addresses and link to them, if not |
| 244 |
* it will create them. Audio can only be stereo or 4 channels according to gstreamer. |
| 245 |
*/ |
| 246 |
|
| 247 |
class AudioDvSource : public AudioSource |
| 248 |
{
|
| 249 |
public:
|
| 250 |
explicit AudioDvSource(const AudioSourceConfig &config);
|
| 251 |
|
| 252 |
private:
|
| 253 |
~AudioDvSource(); |
| 254 |
void sub_init();
|
| 255 |
|
| 256 |
GstElement *queue_; |
| 257 |
GstElement *srcElement() { return queue_; }
|
| 258 |
/// No Copy Constructor
|
| 259 |
AudioDvSource(const AudioDvSource&);
|
| 260 |
/// No Assignment Operator
|
| 261 |
AudioDvSource& operator=(const AudioDvSource&);
|
| 262 |
}; |
| 263 |
|
| 264 |
#endif //_AUDIO_SOURCE_H_ |
| 265 |
|
| 266 |
|
