EMIPLIB

mipaudiosession.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of EMIPLIB, the EDM Media over IP Library.
00004   
00005   Copyright (C) 2006-2011  Hasselt University - Expertise Centre for
00006                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00021   USA
00022 
00023 */
00024 
00029 #ifndef MIPAUDIOSESSION_H
00030 
00031 #define MIPAUDIOSESSION_H
00032 
00033 #include "mipconfig.h"
00034 
00035 #if (defined(MIPCONFIG_SUPPORT_WINMM) || defined(MIPCONFIG_SUPPORT_OSS) || defined(MIPCONFIG_SUPPORT_PORTAUDIO) )
00036 
00037 #include "mipcomponentchain.h"
00038 #include "miperrorbase.h"
00039 #include "miptime.h"
00040 #include <jrtplib3/rtptransmitter.h>
00041 #include <string>
00042 #include <list>
00043 
00044 namespace jrtplib
00045 {
00046         class RTPSession;
00047         class RTPAddress;
00048 }
00049 
00050 class MIPComponent;
00051 class MIPRTPComponent;
00052 class MIPRTPSynchronizer;
00053 class MIPRTPPacketDecoder;
00054 
00056 class EMIPLIB_IMPORTEXPORT MIPAudioSessionParams
00057 {
00058 public:
00060         enum CompressionType 
00061         { 
00063                 ULaw, 
00065                 ALaw,
00067                 LPC, 
00069                 GSM, 
00071                 Speex,
00073                 L16Mono
00074         };
00075 
00077         enum SpeexBandWidth 
00078         { 
00080                 NarrowBand,
00082                 WideBand,               
00084                 UltraWideBand
00085         };
00086         
00087         MIPAudioSessionParams()                                                         
00088         { 
00089 #ifdef MIPCONFIG_SUPPORT_WINMM
00090                 m_inputDevID = WAVE_MAPPER;
00091                 m_outputDevID = WAVE_MAPPER;
00092 #else
00093                 m_inputDevID = 0;
00094                 m_outputDevID = 0;
00095 #endif // MIPCONFIG_SUPPORT_WINMM
00096                 m_inputDevName = std::string("/dev/dsp"); 
00097                 m_outputDevName = std::string("/dev/dsp"); 
00098                 m_highPriority = false;
00099                 m_portbase = 5000; 
00100                 m_acceptOwnPackets = false; 
00101                 m_speexMode = WideBand;
00102                 m_speexIncomingPT = 96;
00103                 m_speexOutgoingPT = 96;
00104 #ifdef _WIN32_WCE
00105                 m_inputMultiplier = 3;
00106                 m_outputMultiplier = 2;
00107 #else
00108                 m_inputMultiplier = 1;
00109                 m_outputMultiplier = 1;
00110 #endif // _WIN32_WCE
00111                 m_compType = ULaw;
00112                 m_disableInterChainTimer = false;
00113         }
00114         ~MIPAudioSessionParams()                                                        { }
00115         
00117         unsigned int getInputDeviceID() const                                           { return m_inputDevID; }
00118 
00120         unsigned int getOutputDeviceID() const                                          { return m_outputDevID; }
00121 
00123         std::string getInputDeviceName() const                                          { return m_inputDevName; }
00124         
00126         std::string getOutputDeviceName() const                                         { return m_outputDevName; }
00127 
00129         bool getUseHighPriority() const                                                 { return m_highPriority; }
00130 
00132         uint16_t getPortbase() const                                                    { return m_portbase; }
00133 
00135         bool getAcceptOwnPackets() const                                                { return m_acceptOwnPackets; }
00136         
00138         CompressionType getCompressionType() const                                      { return m_compType; }
00139         
00141         SpeexBandWidth getSpeexEncoding() const                                         { return m_speexMode; }
00142 
00144         uint8_t getSpeexIncomingPayloadType() const                                     { return m_speexIncomingPT; }
00145 
00147         uint8_t getSpeexOutgoingPayloadType() const                                     { return m_speexOutgoingPT; }
00148         
00150         int getInputMultiplier() const                                                  { return m_inputMultiplier; }
00151 
00153         int getOutputMultiplier() const                                                 { return m_outputMultiplier; }
00154 
00159         bool getDisableInterChainTimer() const                                          { return m_disableInterChainTimer; }
00160 
00162         void setInputDevice(unsigned int ID)                                            { m_inputDevID = ID; }
00163         
00165         void setOutputDevice(unsigned int ID)                                           { m_outputDevID = ID; }
00166 
00168         void setInputDevice(const std::string &devName)                                 { m_inputDevName = devName; }
00169         
00171         void setOutputDevice(const std::string &devName)                                { m_outputDevName = devName; }
00172 
00174         void setUseHighPriority(bool f)                                                 { m_highPriority = f; }
00175 
00177         void setPortbase(uint16_t p)                                                    { m_portbase = p; }
00178         
00180         void setAcceptOwnPackets(bool v)                                                { m_acceptOwnPackets = v; }
00181 
00183         void setCompressionType(CompressionType t)                                      { m_compType = t; }
00184 
00186         void setSpeexEncoding(SpeexBandWidth b)                                         { m_speexMode = b; }
00187 
00189         void setSpeexIncomingPayloadType(uint8_t pt)                                    { m_speexIncomingPT = pt; }
00190         
00192         void setSpeexOutgoingPayloadType(uint8_t pt)                                    { m_speexOutgoingPT = pt; }
00193 
00195         void setInputMultiplier(int m)                                                  { m_inputMultiplier = m; }
00196 
00198         void setOutputMultiplier(int m)                                                 { m_outputMultiplier = m; }
00199 
00208         void setDisableInterChainTimer(bool f)                                          { m_disableInterChainTimer = f; }
00209 private:
00210         unsigned int m_inputDevID, m_outputDevID;
00211         std::string m_inputDevName, m_outputDevName;
00212         bool m_highPriority;
00213         uint16_t m_portbase;
00214         bool m_acceptOwnPackets;
00215         SpeexBandWidth m_speexMode;
00216         int m_inputMultiplier, m_outputMultiplier;
00217         CompressionType m_compType;
00218         uint8_t m_speexOutgoingPT, m_speexIncomingPT;
00219         bool m_disableInterChainTimer;
00220 };
00221 
00228 class EMIPLIB_IMPORTEXPORT MIPAudioSession : public MIPErrorBase
00229 {
00230 public:
00231         MIPAudioSession();
00232         virtual ~MIPAudioSession();
00233 
00243         bool init(const MIPAudioSessionParams *pParams = 0, MIPRTPSynchronizer *pSync = 0, jrtplib::RTPSession *pRTPSession = 0);
00244 
00246         bool destroy();
00247 
00249         bool addDestination(const jrtplib::RTPAddress &addr);
00250 
00252         bool deleteDestination(const jrtplib::RTPAddress &addr);
00253 
00255         bool clearDestinations();
00256 
00258         bool supportsMulticasting();
00259 
00261         bool joinMulticastGroup(const jrtplib::RTPAddress &addr);
00262 
00264         bool leaveMulticastGroup(const jrtplib::RTPAddress &addr);
00265 
00267         bool leaveAllMulticastGroups();
00268         
00275         bool setReceiveMode(jrtplib::RTPTransmitter::ReceiveMode m);
00276 
00278         bool addToIgnoreList(const jrtplib::RTPAddress &addr);
00279 
00281         bool deleteFromIgnoreList(const jrtplib::RTPAddress &addr);
00282 
00284         bool clearIgnoreList();
00285 
00287         bool addToAcceptList(const jrtplib::RTPAddress &addr);
00288 
00290         bool deleteFromAcceptList(const jrtplib::RTPAddress &addr);
00291 
00293         bool clearAcceptList();
00294 protected:
00301         virtual void onInputThreadExit(bool err, const std::string &compName, const std::string &errStr)        { }
00302 
00309         virtual void onOutputThreadExit(bool err, const std::string &compName, const std::string &errStr)       { }
00310 
00319         virtual void onIOThreadExit(bool err, const std::string &compName, const std::string &errStr)   { }
00320 private:
00321         class InputChain : public MIPComponentChain
00322         {
00323         public:
00324                 InputChain(MIPAudioSession *pAudioSess) : MIPComponentChain("Input chain")              { m_pAudioSess = pAudioSess; }
00325         protected:
00326                 void onThreadExit(bool err, const std::string &compName, const std::string &errStr)     { m_pAudioSess->onInputThreadExit(err, compName, errStr); }
00327         private:
00328                 MIPAudioSession *m_pAudioSess;
00329         };
00330 
00331         class OutputChain : public MIPComponentChain
00332         {
00333         public:
00334                 OutputChain(MIPAudioSession *pAudioSess) : MIPComponentChain("Output chain")            { m_pAudioSess = pAudioSess; }
00335         protected:
00336                 void onThreadExit(bool err, const std::string &compName, const std::string &errStr)     { m_pAudioSess->onOutputThreadExit(err, compName, errStr); }
00337         private:
00338                 MIPAudioSession *m_pAudioSess;
00339         };
00340 
00341         class IOChain : public MIPComponentChain
00342         {
00343         public:
00344                 IOChain(MIPAudioSession *pAudioSess) : MIPComponentChain("Input/Output chain")          { m_pAudioSess = pAudioSess; }
00345         protected:
00346                 void onThreadExit(bool err, const std::string &compName, const std::string &errStr)     { m_pAudioSess->onIOThreadExit(err, compName, errStr); }
00347         private:
00348                 MIPAudioSession *m_pAudioSess;
00349         };
00350 
00351         void zeroAll();
00352         void deleteAll();
00353         void storeComponent(MIPComponent *pComp);
00354         void storePacketDecoder(MIPRTPPacketDecoder *pDec);
00355         void addLink(MIPComponentChain *pChain, MIPComponent **pPrevComp, MIPComponent *pComp, 
00356                      bool feedback = false, uint32_t mask1 = MIPMESSAGE_TYPE_ALL, uint32_t mask2 = MIPMESSAGE_TYPE_ALL);
00357 
00358         bool m_init;
00359         
00360         InputChain *m_pInputChain;
00361         OutputChain *m_pOutputChain;
00362         IOChain *m_pIOChain;
00363         
00364         MIPRTPComponent *m_pRTPComp;
00365         jrtplib::RTPSession *m_pRTPSession;
00366         bool m_deleteRTPSession;
00367         std::list<MIPComponent *> m_components;
00368         std::list<MIPRTPPacketDecoder *> m_packetDecoders;
00369         
00370         friend class InputChain;
00371         friend class OutputChain;
00372         friend class IOChain;
00373 };
00374 
00375 #endif // MIPCONFIG_SUPPORT_WINMM || MIPCONFIG_SUPPORT_OSS || MIPCONFIG_SUPPORT_PORTAUDIO
00376 
00377 #endif // MIPAUDIOSESSION_H
00378