Gnash  0.8.11dev
AudioInputGst.h
Go to the documentation of this file.
1 // AudioInput.h: Audio input processing using Gstreamer.
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program 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 // This program 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 this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef GNASH_AUDIOINPUTGST_H
21 #define GNASH_AUDIOINPUTGST_H
22 
23 #include "gst/gst.h"
24 #include "AudioInput.h"
25 #include <string>
26 #include <cstdint> // for C99 int types
27 #include <vector>
28 #include <cassert>
29 
30 namespace gnash {
31 namespace media {
32 namespace gst {
33 
39 class GnashAudio {
40  public:
46  GstElement* getElementPtr() {return _element;}
47 
52  void setElementPtr(GstElement* element) {_element = element;}
53 
58  gchar* getDevLocation() {return _devLocation;}
59 
65  void setDevLocation(gchar *l) {_devLocation = l;}
66 
73  gchar* getGstreamerSrc() {return _gstreamerSrc;}
74 
80  void setGstreamerSrc(gchar *s) {_gstreamerSrc = s;}
81 
87  gchar* getProductName() {return _productName;}
88 
94  void setProductName(gchar *n) {_productName = n;}
95 
97  GnashAudio();
98 
99  private:
103  GstElement* _element;
104 
107  gchar* _devLocation;
108 
112  gchar* _gstreamerSrc;
113 
117  gchar* _productName;
118 };
119 
126  public:
130  GstElement *audioSource;
131 
135  GstElement *audioEnc;
136 
139 
144  void setAudioDevice(GnashAudio* d) {_audioDevice = d;}
145 
149  GnashAudio* getAudioDevice() {return _audioDevice;}
150 
154  void setDeviceName(gchar* n) {_deviceName = n;}
155 
159  gchar* getDeviceName() {return _deviceName;}
160 
161  //FIXME: I can't figure out why this isn't working right. Since I made
162  // AudioInputGst inherit from GnashAudioPrivate it should be able to access
163  // protected variables, but I can't get it to work!
164  //protected:
170 
174  gchar* _deviceName;
175 
179  GstElement* _pipeline;
180 
188  GstElement* _audioMainBin;
189 
197  GstElement* _audioSourceBin;
198 
206  GstElement* _audioPlaybackBin;
207 
216  GstElement* _audioSaveBin;
217 
222  GstElement* _mux;
223 
228 };
229 
234 //
238 //
243 {
244 
245 public:
246 
248 
249  AudioInputGst();
250 
251  virtual ~AudioInputGst();
252 
253  //setters and getters
254  virtual void setActivityLevel(double a) {
255  _activityLevel = a;
256  }
257 
258  virtual double activityLevel() const {
259  return _activityLevel;
260  }
261 
263  //
267  virtual void setGain(double g) {
268  assert (g >= 0 && g <= 100);
269  _gain = g;
270  audioChangeSourceBin(getGlobalAudio());
271  }
272 
274  //
278  virtual double gain() const {
279  return _gain;
280  }
281 
282  virtual void setIndex(int i) {
283  _index = i;
284  }
285 
286  virtual int index() const {
287  return _index;
288  }
289 
290  virtual bool muted() {
291  return _muted;
292  }
293 
294  virtual void setName(std::string name) {
295  _name = name;
296  }
297 
298  virtual const std::string& name() const { return _name; }
299 
301  //
303  virtual void setRate(int r) {
304 
305  // Yes, this isn't pretty, but it is only designed for the
306  // testsuite to continue passing.
307  if (r >= 44) {
308  _rate = 44000;
309  audioChangeSourceBin(getGlobalAudio());
310  return;
311  }
312  static const int rates[] = { 5, 8, 11, 16, 22, 44 };
313  const int* rate = rates;
314  while (*rate < r) ++rate;
315  _rate = *rate * 1000;
316  audioChangeSourceBin(getGlobalAudio());
317  }
318 
320  //
322  virtual int rate() const {
323  return _rate / 1000;
324  }
325 
326  virtual void setSilenceLevel(double s) {
327  _silenceLevel = s;
328  }
329 
330  virtual double silenceLevel() const {
331  return _silenceLevel;
332  }
333 
334  virtual void setSilenceTimeout(int s) {
335  _silenceTimeout = s;
336  }
337 
338  virtual int silenceTimeout() const {
339  return _silenceTimeout;
340  }
341 
342  virtual void setUseEchoSuppression(bool e) {
343  _useEchoSuppression = e;
344  }
345 
346  virtual bool useEchoSuppression() const {
347  return _useEchoSuppression;
348  }
349 
350 private:
351 
352  double _activityLevel;
353  double _gain;
354  int _index;
355  bool _muted;
356  std::string _name;
357  int _rate;
358  double _silenceLevel;
359  int _silenceTimeout;
360  bool _useEchoSuppression;
361 
363 
369  void findAudioDevs();
370 
376  int makeAudioDevSelection();
377 
384  void getSelectedCaps(int devselect);
385 
392  bool checkSupportedFormats(GstCaps *caps);
393 
400  GnashAudioPrivate* transferToPrivate(int devselect);
401 
408  gboolean audioCreateMainBin (GnashAudioPrivate *audio);
409 
416  gboolean audioCreateSourceBin (GnashAudioPrivate *audio);
417 
426  gboolean audioCreatePlaybackBin (GnashAudioPrivate *audio);
427 
436  gboolean makeAudioSourcePlaybackLink (GnashAudioPrivate *audio);
437 
443  gboolean breakAudioSourcePlaybackLink (GnashAudioPrivate *audio);
444 
453  gboolean makeAudioSourceSaveLink (GnashAudioPrivate *audio);
454 
460  gboolean breakAudioSourceSaveLink (GnashAudioPrivate *audio);
461 
470  gboolean audioCreateSaveBin (GnashAudioPrivate *audio);
471 
478  bool audioPlay(GnashAudioPrivate *audio);
479 
485  bool audioStop(GnashAudioPrivate *audio);
486 
495  gboolean audioChangeSourceBin (GnashAudioPrivate *audio);
496 
500  int getNumdevs() const { return _audioVect.size(); }
501 
504  std::vector<GnashAudio*>* getAudioVect() {return &_audioVect;}
505 
508  GnashAudioPrivate* getGlobalAudio() {return _globalAudio;}
509 
511  double gstgain() { return (gain() - 50) * 1.2; }
512 
513 private:
514 
520  std::vector<GnashAudio*> _audioVect;
521 
526  GnashAudioPrivate* _globalAudio;
527 
528 };
529 
530 } // gst namespace
531 } // gnash.media namespace
532 } // gnash namespace
533 
534 #endif
GnashAudio * getAudioDevice()
This function returns the private _audioDevice element pointer from the GnashAudioPrivate class...
Definition: AudioInputGst.h:149
Definition: GnashKey.h:147
A class representing a single AudioInput device.
Definition: AudioInput.h:35
Contains information about audio input devices while enumerating information about attached hardware...
Definition: AudioInputGst.h:39
This class is initialized once a hardware input device is chosen it is more robust than GnashAudio be...
Definition: AudioInputGst.h:125
GnashAudio * _audioDevice
A pointer to the GnashAudio class of the selected hardware device This info should be stored to the G...
Definition: AudioInputGst.h:169
void setDevLocation(gchar *l)
Accessor to set the private _devLocation variable from the GnashAudio class.
Definition: AudioInputGst.h:65
virtual void setSilenceTimeout(int s)
Definition: AudioInputGst.h:334
Definition: GnashKey.h:150
GstElement * audioSource
A pointer to the Gstreamer element corresponding to the audio source (e.g. a built-in or usb micropho...
Definition: AudioInputGst.h:130
GstElement * _audioSaveBin
Definition: AudioInputGst.h:216
virtual const std::string & name() const
Definition: AudioInputGst.h:298
gchar * _deviceName
A gchar* describing the physical input device&#39;s name (e.g. HDA Intel or Built-In Microphone) ...
Definition: AudioInputGst.h:174
virtual void setSilenceLevel(double s)
Definition: AudioInputGst.h:326
virtual void setName(std::string name)
Definition: AudioInputGst.h:294
virtual void setUseEchoSuppression(bool e)
Definition: AudioInputGst.h:342
gchar * getProductName()
Accessor to get the private _productName variable from the GnashAudio class.
Definition: AudioInputGst.h:87
void setProductName(gchar *n)
Accessor to set the private _productName variable from the GnashAudio class.
Definition: AudioInputGst.h:94
virtual bool muted()
Definition: AudioInputGst.h:290
Definition: GnashKey.h:158
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
virtual int silenceTimeout() const
Definition: AudioInputGst.h:338
virtual void setIndex(int i)
Definition: AudioInputGst.h:282
virtual int index() const
Definition: AudioInputGst.h:286
GstElement * audioEnc
A pointer to the audio encoder element of the Gstreamer pipeline. The only format currently supported...
Definition: AudioInputGst.h:135
virtual double activityLevel() const
Definition: AudioInputGst.h:258
virtual int rate() const
Supported rates are (maybe hardware-dependent): 5, 8, 11, 16, 22, 44.
Definition: AudioInputGst.h:322
Definition: GnashKey.h:160
GstElement * _audioMainBin
Definition: AudioInputGst.h:188
void setAudioDevice(GnashAudio *d)
This function sets the private _audioDevice element in the GnashAudioPrivate class.
Definition: AudioInputGst.h:144
Definition: GnashKey.h:164
GstElement * _audioSourceBin
Definition: AudioInputGst.h:197
virtual void setRate(int r)
Supported rates are (maybe hardware-dependent): 5, 8, 11, 16, 22, 44.
Definition: AudioInputGst.h:303
gchar * getDevLocation()
Accessor to get the private _devLocation variable from the GnashAudio class.
Definition: AudioInputGst.h:58
void setElementPtr(GstElement *element)
Accessor to set the private _element variable from the GnashAudio class.
Definition: AudioInputGst.h:52
virtual void setGain(double g)
Set the input&#39;s gain.
Definition: AudioInputGst.h:267
gchar * getGstreamerSrc()
Accessor to return the private _gstreamerSrc variable from the GnashAudio class.
Definition: AudioInputGst.h:73
GnashAudio()
Constructor for the GnashAudio class.
Definition: AudioInputGst.cpp:44
void setDeviceName(gchar *n)
This function sets the private _deviceName element in the GnashAudioPrivate class.
Definition: AudioInputGst.h:154
GstElement * _audioPlaybackBin
Definition: AudioInputGst.h:206
virtual void setActivityLevel(double a)
Definition: AudioInputGst.h:254
GstElement * _pipeline
A pointer to the main Gstreamer pipeline that all created elements and bins will be dropped into...
Definition: AudioInputGst.h:179
virtual double silenceLevel() const
Definition: AudioInputGst.h:330
gint findAudioDevs(std::vector< data *> &audioVect)
Definition: findmicrophones.cpp:55
virtual double gain() const
Get the input&#39;s gain.
Definition: AudioInputGst.h:278
Definition: GnashKey.h:155
Definition: GnashKey.h:151
Definition: GnashKey.h:153
gboolean _pipelineIsPlaying
A boolean value which stores whether or not the _pipeline element is currently in it&#39;s &#39;playing&#39; stat...
Definition: AudioInputGst.h:227
Definition: GnashKey.h:165
GstElement * _mux
A direct link to the oggmux element in the _audioSaveBin for use with linking up to a video muxer so ...
Definition: AudioInputGst.h:222
gchar * getDeviceName()
This function returns the private _deviceName variable from the GnashAudioPrivate class...
Definition: AudioInputGst.h:159
std::string name
Definition: LocalConnection_as.cpp:149
GstElement * getElementPtr()
Accessor to retreive a the private _element variable from the GnashAudio class which contains a point...
Definition: AudioInputGst.h:46
void setGstreamerSrc(gchar *s)
Accessor to set the private _gstreamerSrc variable from the GnashAudio class.
Definition: AudioInputGst.h:80
virtual bool useEchoSuppression() const
Definition: AudioInputGst.h:346
The main AudioInputGst class, which actually doesn&#39;t store too much important information (most of th...
Definition: AudioInputGst.h:242