This URL has Read-Only access.

Statistics
| Branch: | Tag: | Revision:

root / src / gst / engine / audioSource.h @ 96b128e9

History | View | Annotate | Download (8 kB)

1
// audioSource.h
2
// Copyright (C) 2008-2009 Société des arts technologiques (SAT)
3
// http://www.sat.qc.ca
4
// All rights reserved.
5
//
6
// This file is part of [propulse]ART.
7
//
8
// [propulse]ART is free software: you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation, either version 3 of the License, or
11
// (at your option) any later version.
12
//
13
// [propulse]ART is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
// GNU General Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// along with [propulse]ART.  If not, see <http://www.gnu.org/licenses/>.
20
//
21

    
22
/** \file audioSource.h
23
 *      A family of classes representing different types/sources of audio input.
24
 */
25

    
26
#ifndef _AUDIO_SOURCE_H_
27
#define _AUDIO_SOURCE_H_
28

    
29
#include "gstLinkable.h"
30
#include "interleave.h"
31
#include "busMsgHandler.h"
32

    
33
// forward declarations
34
class AudioSourceConfig;
35

    
36
/** 
37
 *  Abstract base class from which our audio sources are derived.
38
 *  Uses template method to define the initialization process that subclasses will have to
39
 *  implement (in part) and/or override. Any direct, concrete descendant of this class will not
40
 *  need to have its audio frames interleaved.
41
 */
42

    
43
class AudioSource : public GstLinkableSource
44
{
45
    public:
46
        ~AudioSource();
47
        virtual void init();
48

    
49
    protected:
50
        explicit AudioSource(const AudioSourceConfig &config);
51
        
52
        /// Implemented by subclasses to perform other specific initialization 
53
        virtual void sub_init() = 0;
54

    
55
        /// Audio parameter object 
56
        const AudioSourceConfig &config_;
57
        
58
        /// GstElements representing each source and audioconvert 
59
        GstElement *source_;
60

    
61
    private:
62
        
63
        GstElement *srcElement() { return source_; }
64
        
65
        /// No Copy Constructor
66
        AudioSource(const AudioSource&);     
67
        /// No Assignment Operator
68
        AudioSource& operator=(const AudioSource&);     
69
};
70

    
71
/** 
72
 * Abstract child of AudioSource whose audio frames must be interleaved before pushing audio further down pipeline.
73
 */
74

    
75
class InterleavedAudioSource
76
    : public AudioSource
77
{
78
    protected:
79
        /// Object initializer 
80
        void sub_init();
81

    
82
        explicit InterleavedAudioSource(const AudioSourceConfig &config);
83
        
84
        ~InterleavedAudioSource();
85

    
86
        /// Object which performs the interleaving of this source's channels 
87
        Interleave interleave_;
88
        std::vector<GstElement*> sources_, aconvs_;
89

    
90
    private:
91
        
92
        GstElement *srcElement() { return interleave_.srcElement(); }
93
};
94

    
95
/** 
96
 *  Concrete InterleavedAudioSource which gives us an array of sine-wave generating sources.
97
 *
98
 *  AudioTestSource generates sine-tones, each of which alternate between two hard-coded frequencies. Their
99
 *  combined output is then interleaved.
100
 */
101

    
102
class AudioTestSource : public InterleavedAudioSource
103
{
104
    public:
105
        explicit AudioTestSource(const AudioSourceConfig &config);
106
        
107
    private:
108
        void sub_init();
109

    
110
        ~AudioTestSource();
111

    
112
        static gboolean timedCallback(GstClock *clock, 
113
                                      GstClockTime time, 
114
                                      GstClockID id,
115
                                      gpointer user_data);
116
        void toggle_frequency();
117

    
118
        GstClockID clockId_;
119
        int offset_;
120

    
121
        static const double FREQUENCY[2][8];
122
        /// No Copy Constructor
123
        AudioTestSource(const AudioTestSource&);     
124
        /// No Assignment Operator
125
        AudioTestSource& operator=(const AudioTestSource&);     
126
};
127

    
128
/** 
129
 *  \class AudioFileSource
130
 *  Concrete AudioSource which provides playback of files. 
131
 *
132
 *  AudioFileSource plays back a file (determined by its AudioSourceConfig object). Depending
133
 *  on its AudioSourceConfig object, it may loop the file. It implements the BusMsgHandler interface
134
 *  so that it knows when an End-of-Signal event occurs, in which case it may
135
 *  play the file again if it has been set to continue to play the file (either infinitely or for a finite
136
 *  number of plays).
137
 */
138

    
139
class AudioFileSource : public AudioSource, public BusMsgHandler
140
{
141
    public:
142
        explicit AudioFileSource(const AudioSourceConfig &config);
143

    
144
    private:
145
        ~AudioFileSource();
146
         
147
        bool handleBusMsg(_GstMessage *msg);
148
        
149
        static void cb_new_src_pad(GstElement * srcElement, 
150
                                   GstPad * srcPad, 
151
                                   gboolean last,
152
                                   void *data);
153
        void loop(int nTimes);
154
        void sub_init();
155

    
156
        void restartPlayback();
157
        GstElement* decoder_;
158
        GstElement* aconv_;
159
        int loopCount_;
160
        static const int LOOP_INFINITE;
161
        
162
        /// No Copy Constructor
163
        AudioFileSource(const AudioFileSource&);     
164
        /// No Assignment Operator
165
        AudioFileSource& operator=(const AudioFileSource&);     
166
};
167

    
168
/** 
169
 *  Concrete AudioSource which captures audio from ALSA
170
 *  Has caps filter to allow number of channels to be variable.
171
 */
172

    
173
class AudioAlsaSource : public AudioSource
174
{
175
    public:
176
        explicit AudioAlsaSource(const AudioSourceConfig &config);
177

    
178
    private:
179
        ~AudioAlsaSource();
180

    
181
        void sub_init();
182
        GstElement *srcElement() { return capsFilter_; }
183

    
184
        GstElement *capsFilter_;
185
        GstElement *aconv_;
186
        /// No Copy Constructor
187
        AudioAlsaSource(const AudioAlsaSource&);     
188
        /// No Assignment Operator
189
        AudioAlsaSource& operator=(const AudioAlsaSource&);     
190
};
191

    
192
/** 
193
 *  Concrete AudioSource which captures audio from PulseAudio
194
 *  Has caps filter to allow number of channels to be variable.
195
 */
196

    
197
class AudioPulseSource : public AudioSource
198
{
199
    public:
200
        explicit AudioPulseSource(const AudioSourceConfig &config);
201
    private:
202
        ~AudioPulseSource();
203
    
204
        void sub_init();
205
        GstElement *srcElement() { return capsFilter_; }
206
    
207
        GstElement *capsFilter_;
208
        GstElement *aconv_;
209
        /// No Copy Constructor
210
        AudioPulseSource(const AudioPulseSource&);     
211
        /// No Assignment Operator
212
        AudioPulseSource& operator=(const AudioPulseSource&);     
213
};
214

    
215
/** 
216
 *  Concrete AudioSource which captures audio from JACK, 
217
 *  and interleaves incoming jack buffers into one multichannel stream.
218
 */
219

    
220
class AudioJackSource : public AudioSource
221
{
222
    public:
223
        AudioJackSource(const AudioSourceConfig &config, unsigned long long bufferTime);
224
    
225
    private:
226
        ~AudioJackSource();
227

    
228
        GstElement *srcElement() { return capsFilter_; }
229
        void sub_init();
230

    
231
        GstElement *capsFilter_;
232
        GstElement *aconv_;
233
        unsigned long long bufferTime_;
234
        /// No Copy Constructor
235
        AudioJackSource(const AudioJackSource&);     
236
        /// No Assignment Operator
237
        AudioJackSource& operator=(const AudioJackSource&);     
238
};
239

    
240

    
241
/** 
242
 *  Concrete AudioSource which captures audio from dv device.
243
 *
244
 *  This object is tightly coupled with VideoDvSource, as both (if present) will share one source_ GstElement, 
245
 *  and one dvdemux GstElement. It will look for both of these in the pipeline before trying to instantiate them. 
246
 *  If these GstElement are already present, AudioDvSource will simply store their addresses and link to them, if not
247
 *  it will create them. DVAudio can only be stereo or 4 channels according to gstreamer.
248
 */
249

    
250
class AudioDvSource : public AudioSource
251
{
252
    public:
253
        explicit AudioDvSource(const AudioSourceConfig &config);
254
    
255
    private:
256
        ~AudioDvSource();
257
        void sub_init();
258

    
259
        GstElement *queue_;
260
        GstElement *aconv_;
261
        GstElement *srcElement() { return aconv_; }
262
        /// No Copy Constructor
263
        AudioDvSource(const AudioDvSource&);     
264
        /// No Assignment Operator
265
        AudioDvSource& operator=(const AudioDvSource&);     
266
};
267

    
268
#endif //_AUDIO_SOURCE_H_
269

    
270