Gnash
0.8.10
|
00001 // AudioInput.h: Audio input processing using Gstreamer. 00002 // 00003 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 00004 // Free Software Foundation, Inc. 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 #ifndef GNASH_AUDIOINPUTGST_H 00021 #define GNASH_AUDIOINPUTGST_H 00022 00023 #include "gst/gst.h" 00024 #include "AudioInput.h" 00025 #include <string> 00026 #include <boost/cstdint.hpp> // for C99 int types 00027 #include <vector> 00028 #include <cassert> 00029 00030 namespace gnash { 00031 namespace media { 00032 namespace gst { 00033 00039 class GnashAudio { 00040 public: 00046 GstElement* getElementPtr() {return _element;} 00047 00052 void setElementPtr(GstElement* element) {_element = element;} 00053 00058 gchar* getDevLocation() {return _devLocation;} 00059 00065 void setDevLocation(gchar *l) {_devLocation = l;} 00066 00073 gchar* getGstreamerSrc() {return _gstreamerSrc;} 00074 00080 void setGstreamerSrc(gchar *s) {_gstreamerSrc = s;} 00081 00087 gchar* getProductName() {return _productName;} 00088 00094 void setProductName(gchar *n) {_productName = n;} 00095 00097 GnashAudio(); 00098 00099 private: 00103 GstElement* _element; 00104 00107 gchar* _devLocation; 00108 00112 gchar* _gstreamerSrc; 00113 00117 gchar* _productName; 00118 }; 00119 00125 class GnashAudioPrivate { 00126 public: 00130 GstElement *audioSource; 00131 00135 GstElement *audioEnc; 00136 00138 GnashAudioPrivate(); 00139 00144 void setAudioDevice(GnashAudio* d) {_audioDevice = d;} 00145 00149 GnashAudio* getAudioDevice() {return _audioDevice;} 00150 00154 void setDeviceName(gchar* n) {_deviceName = n;} 00155 00159 gchar* getDeviceName() {return _deviceName;} 00160 00161 //FIXME: I can't figure out why this isn't working right. Since I made 00162 // AudioInputGst inherit from GnashAudioPrivate it should be able to access 00163 // protected variables, but I can't get it to work! 00164 //protected: 00169 GnashAudio* _audioDevice; 00170 00174 gchar* _deviceName; 00175 00179 GstElement* _pipeline; 00180 00188 GstElement* _audioMainBin; 00189 00197 GstElement* _audioSourceBin; 00198 00206 GstElement* _audioPlaybackBin; 00207 00216 GstElement* _audioSaveBin; 00217 00222 GstElement* _mux; 00223 00227 gboolean _pipelineIsPlaying; 00228 }; 00229 00234 // 00238 // 00242 class AudioInputGst : public AudioInput, public GnashAudioPrivate 00243 { 00244 00245 public: 00246 00248 00249 AudioInputGst(); 00250 00251 virtual ~AudioInputGst(); 00252 00253 //setters and getters 00254 virtual void setActivityLevel(double a) { 00255 _activityLevel = a; 00256 } 00257 00258 virtual double activityLevel() const { 00259 return _activityLevel; 00260 } 00261 00263 // 00267 virtual void setGain(double g) { 00268 assert (g >= 0 && g <= 100); 00269 _gain = g; 00270 audioChangeSourceBin(getGlobalAudio()); 00271 } 00272 00274 // 00278 virtual double gain() const { 00279 return _gain; 00280 } 00281 00282 virtual void setIndex(int i) { 00283 _index = i; 00284 } 00285 00286 virtual int index() const { 00287 return _index; 00288 } 00289 00290 virtual bool muted() { 00291 return _muted; 00292 } 00293 00294 virtual void setName(std::string name) { 00295 _name = name; 00296 } 00297 00298 virtual const std::string& name() const { return _name; } 00299 00301 // 00303 virtual void setRate(int r) { 00304 00305 // Yes, this isn't pretty, but it is only designed for the 00306 // testsuite to continue passing. 00307 if (r >= 44) { 00308 _rate = 44000; 00309 audioChangeSourceBin(getGlobalAudio()); 00310 return; 00311 } 00312 static const int rates[] = { 5, 8, 11, 16, 22, 44 }; 00313 const int* rate = rates; 00314 while (*rate < r) ++rate; 00315 _rate = *rate * 1000; 00316 audioChangeSourceBin(getGlobalAudio()); 00317 } 00318 00320 // 00322 virtual int rate() const { 00323 return _rate / 1000; 00324 } 00325 00326 virtual void setSilenceLevel(double s) { 00327 _silenceLevel = s; 00328 } 00329 00330 virtual double silenceLevel() const { 00331 return _silenceLevel; 00332 } 00333 00334 virtual void setSilenceTimeout(int s) { 00335 _silenceTimeout = s; 00336 } 00337 00338 virtual int silenceTimeout() const { 00339 return _silenceTimeout; 00340 } 00341 00342 virtual void setUseEchoSuppression(bool e) { 00343 _useEchoSuppression = e; 00344 } 00345 00346 virtual bool useEchoSuppression() const { 00347 return _useEchoSuppression; 00348 } 00349 00350 private: 00351 00352 double _activityLevel; 00353 double _gain; 00354 int _index; 00355 bool _muted; 00356 std::string _name; 00357 int _rate; 00358 double _silenceLevel; 00359 int _silenceTimeout; 00360 bool _useEchoSuppression; 00361 00363 00369 void findAudioDevs(); 00370 00376 int makeAudioDevSelection(); 00377 00384 void getSelectedCaps(int devselect); 00385 00392 bool checkSupportedFormats(GstCaps *caps); 00393 00400 GnashAudioPrivate* transferToPrivate(int devselect); 00401 00408 gboolean audioCreateMainBin (GnashAudioPrivate *audio); 00409 00416 gboolean audioCreateSourceBin (GnashAudioPrivate *audio); 00417 00426 gboolean audioCreatePlaybackBin (GnashAudioPrivate *audio); 00427 00436 gboolean makeAudioSourcePlaybackLink (GnashAudioPrivate *audio); 00437 00443 gboolean breakAudioSourcePlaybackLink (GnashAudioPrivate *audio); 00444 00453 gboolean makeAudioSourceSaveLink (GnashAudioPrivate *audio); 00454 00460 gboolean breakAudioSourceSaveLink (GnashAudioPrivate *audio); 00461 00470 gboolean audioCreateSaveBin (GnashAudioPrivate *audio); 00471 00478 bool audioPlay(GnashAudioPrivate *audio); 00479 00485 bool audioStop(GnashAudioPrivate *audio); 00486 00495 gboolean audioChangeSourceBin (GnashAudioPrivate *audio); 00496 00500 int getNumdevs() const { return _audioVect.size(); } 00501 00504 std::vector<GnashAudio*>* getAudioVect() {return &_audioVect;} 00505 00508 GnashAudioPrivate* getGlobalAudio() {return _globalAudio;} 00509 00511 double gstgain() { return (gain() - 50) * 1.2; } 00512 00513 private: 00514 00520 std::vector<GnashAudio*> _audioVect; 00521 00526 GnashAudioPrivate* _globalAudio; 00527 00528 }; 00529 00530 } // gst namespace 00531 } // gnash.media namespace 00532 } // gnash namespace 00533 00534 #endif