Gnash 0.8.10dev
AudioInputGst.h
Go to the documentation of this file.
00001 // AudioInput.h: Audio input processing using Gstreamer.
00002 // 
00003 //   Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_AUDIOINPUTGST_H
00020 #define GNASH_AUDIOINPUTGST_H
00021 
00022 #include "gst/gst.h"
00023 #include "AudioInput.h"
00024 #include <string>
00025 #include <boost/cstdint.hpp> // for C99 int types
00026 #include <vector>
00027 #include <cassert>
00028 
00029 namespace gnash {
00030 namespace media {
00031 namespace gst {
00032 
00038 class GnashAudio {
00039     public:
00045         GstElement* getElementPtr() {return _element;}
00046         
00051         void setElementPtr(GstElement* element) {_element = element;}
00052         
00057         gchar* getDevLocation() {return _devLocation;}
00058         
00064         void setDevLocation(gchar *l) {_devLocation = l;}
00065         
00072         gchar* getGstreamerSrc() {return _gstreamerSrc;}
00073         
00079         void setGstreamerSrc(gchar *s) {_gstreamerSrc = s;}
00080         
00086         gchar* getProductName() {return _productName;}
00087         
00093         void setProductName(gchar *n) {_productName = n;}
00094 
00096         GnashAudio();
00097         
00098     private:
00102         GstElement* _element;
00103         
00106         gchar* _devLocation;
00107         
00111         gchar* _gstreamerSrc;
00112         
00116         gchar* _productName;
00117 };
00118  
00124 class GnashAudioPrivate {
00125     public:
00129         GstElement *audioSource;
00130         
00134         GstElement *audioEnc;
00135         
00137         GnashAudioPrivate();
00138         
00143         void setAudioDevice(GnashAudio* d) {_audioDevice = d;}
00144         
00148         GnashAudio* getAudioDevice() {return _audioDevice;}
00149         
00153         void setDeviceName(gchar* n) {_deviceName = n;}
00154         
00158         gchar* getDeviceName() {return _deviceName;}
00159     
00160     //FIXME: I can't figure out why this isn't working right. Since I made 
00161     // AudioInputGst inherit from GnashAudioPrivate it should be able to access
00162     // protected variables, but I can't get it to work!    
00163     //protected:
00168         GnashAudio* _audioDevice;
00169         
00173         gchar* _deviceName;
00174         
00178         GstElement* _pipeline;
00179         
00187         GstElement* _audioMainBin;
00188         
00196         GstElement* _audioSourceBin;
00197         
00205         GstElement* _audioPlaybackBin;
00206         
00215         GstElement* _audioSaveBin;
00216         
00221         GstElement* _mux;
00222         
00226         gboolean _pipelineIsPlaying;
00227 };
00228  
00233 //
00237 //
00241 class AudioInputGst : public AudioInput, public GnashAudioPrivate
00242 {
00243         
00244 public:
00245 
00247 
00248         AudioInputGst();
00249 
00250         virtual ~AudioInputGst();
00251 
00252     //setters and getters
00253     virtual void setActivityLevel(double a) {
00254         _activityLevel = a;
00255     }
00256 
00257     virtual double activityLevel() const {
00258         return _activityLevel;
00259     }
00260     
00262     //
00266     virtual void setGain(double g) {
00267         assert (g >= 0 && g <= 100);
00268         _gain = g;
00269         audioChangeSourceBin(getGlobalAudio());
00270     }
00271 
00273     //
00277     virtual double gain() const {
00278         return _gain;
00279     }
00280     
00281     virtual void setIndex(int i) {
00282         _index = i;
00283     }
00284 
00285     virtual int index() const {
00286         return _index; 
00287     }
00288     
00289     virtual bool muted() {
00290         return _muted;
00291     }
00292     
00293     virtual void setName(std::string name) {
00294         _name = name;
00295     }
00296 
00297     virtual const std::string& name() const { return _name; }
00298     
00300     //
00302     virtual void setRate(int r) {
00303 
00304         // Yes, this isn't pretty, but it is only designed for the 
00305         // testsuite to continue passing.
00306         if (r >= 44) {
00307             _rate = 44000;
00308             audioChangeSourceBin(getGlobalAudio());
00309             return;
00310         }
00311         static const int rates[] = { 5, 8, 11, 16, 22, 44 };
00312         const int* rate = rates;
00313         while (*rate < r) ++rate;
00314         _rate = *rate * 1000;
00315         audioChangeSourceBin(getGlobalAudio());
00316     }
00317 
00319     //
00321     virtual int rate() const {
00322         return _rate / 1000;
00323     }
00324     
00325     virtual void setSilenceLevel(double s) {
00326         _silenceLevel = s;
00327     }
00328     
00329     virtual double silenceLevel() const {
00330         return _silenceLevel;
00331     }
00332     
00333     virtual void setSilenceTimeout(int s) {
00334         _silenceTimeout = s;
00335     }
00336     
00337     virtual int silenceTimeout() const {
00338         return _silenceTimeout;
00339     }
00340     
00341     virtual void setUseEchoSuppression(bool e) {
00342         _useEchoSuppression = e;
00343     }
00344 
00345     virtual bool useEchoSuppression() const {
00346         return _useEchoSuppression;
00347     }
00348 
00349 private:
00350 
00351     double _activityLevel;
00352     double _gain;
00353     int _index;
00354     bool _muted;
00355     std::string _name;
00356     int _rate;
00357     double _silenceLevel;
00358     int _silenceTimeout;
00359     bool _useEchoSuppression;
00360 
00362 
00368     void findAudioDevs();
00369     
00375     int makeAudioDevSelection();
00376     
00383     void getSelectedCaps(int devselect);
00384     
00391     bool checkSupportedFormats(GstCaps *caps);
00392     
00399     GnashAudioPrivate* transferToPrivate(int devselect);
00400     
00407     gboolean audioCreateMainBin (GnashAudioPrivate *audio);
00408     
00415     gboolean audioCreateSourceBin (GnashAudioPrivate *audio);
00416     
00425     gboolean audioCreatePlaybackBin (GnashAudioPrivate *audio);
00426     
00435     gboolean makeAudioSourcePlaybackLink (GnashAudioPrivate *audio);
00436     
00442     gboolean breakAudioSourcePlaybackLink (GnashAudioPrivate *audio);
00443     
00452     gboolean makeAudioSourceSaveLink (GnashAudioPrivate *audio);
00453     
00459     gboolean breakAudioSourceSaveLink (GnashAudioPrivate *audio);
00460     
00469     gboolean audioCreateSaveBin (GnashAudioPrivate *audio);
00470     
00477     bool audioPlay(GnashAudioPrivate *audio);
00478     
00484     bool audioStop(GnashAudioPrivate *audio);
00485     
00494     gboolean audioChangeSourceBin (GnashAudioPrivate *audio);
00495     
00499     int getNumdevs() const { return _audioVect.size(); }
00500     
00503     std::vector<GnashAudio*>* getAudioVect() {return &_audioVect;}
00504     
00507     GnashAudioPrivate* getGlobalAudio() {return _globalAudio;}
00508     
00510     double gstgain() { return (gain() - 50) * 1.2; }
00511 
00512 private:
00513     
00519     std::vector<GnashAudio*> _audioVect;
00520     
00525     GnashAudioPrivate* _globalAudio;
00526 
00527 };
00528 
00529 } // gst namespace
00530 } // gnash.media namespace 
00531 } // gnash namespace
00532 
00533 #endif