EMIPLIB

mipvideosession.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 MIPVIDEOSESSION_H
00030 
00031 #define MIPVIDEOSESSION_H
00032 
00033 #include "mipconfig.h"
00034 
00035 #if defined(MIPCONFIG_SUPPORT_AVCODEC) && (defined(MIPCONFIG_SUPPORT_DIRECTSHOW) || defined(MIPCONFIG_SUPPORT_VIDEO4LINUX))
00036 
00037 #include "mipcomponentchain.h"
00038 #include "miperrorbase.h"
00039 #include "miptime.h"
00040 #include <jrtplib3/rtptransmitter.h>
00041 #include <string>
00042 
00043 namespace jrtplib
00044 {
00045         class RTPSession;
00046         class RTPAddress;
00047 }
00048 
00049 class MIPRTPSynchronizer;
00050 class MIPDirectShowCapture;
00051 class MIPV4L2Input;
00052 class MIPAVCodecEncoder;
00053 class MIPRTPH263Encoder;
00054 class MIPRTPVideoEncoder;
00055 class MIPRTPComponent;
00056 class MIPAverageTimer;
00057 class MIPRTPDecoder;
00058 class MIPRTPH263Decoder;
00059 class MIPRTPVideoDecoder;
00060 class MIPRTPDummyDecoder;
00061 class MIPMediaBuffer;
00062 class MIPAVCodecDecoder;
00063 class MIPVideoMixer;
00064 class MIPQtOutput;
00065 class MIPVideoFrameStorage;
00066 class MIPTinyJPEGDecoder;
00067 class MIPAVCodecFrameConverter;
00068 class MIPComponentAlias;
00069 
00071 class EMIPLIB_IMPORTEXPORT MIPVideoSessionParams
00072 {
00073 public:
00075         enum SessionType 
00076         { 
00077                 InputOutput,    
00078                 OutputOnly      
00079         };
00080         
00082         enum EncodingType 
00083         { 
00084                 H263,           
00085                 IntH263,        
00086                 IntYUV420       
00087         };
00088 
00089         MIPVideoSessionParams()                                                         
00090         { 
00091                 m_devNum = 0;
00092                 m_devName = std::string("/dev/video0"); 
00093                 m_width = 160;
00094                 m_height = 120;
00095                 m_frameRate = 15.0;
00096                 m_portbase = 5100; 
00097                 m_acceptOwnPackets = false;
00098                 m_bandwidth = 200000;
00099                 m_qtoutput = true;
00100                 m_type = InputOutput;
00101                 m_outH263PayloadType = 34;
00102                 m_inH263PayloadType = 34;
00103                 m_outIntPayloadType = 103;
00104                 m_inIntPayloadType = 103;
00105                 m_encType = H263;
00106                 m_waitForKeyframe = true;
00107                 m_maxPayloadSize = 64000;
00108         }
00109         ~MIPVideoSessionParams()                                                        { }
00110 
00112         int getDeviceNumber() const                                                     { return m_devNum; }
00113 
00115         std::string getDeviceName() const                                               { return m_devName; }
00116 
00118         int getWidth() const                                                            { return m_width; }
00119         
00121         int getHeight() const                                                           { return m_height; }
00122 
00124         real_t getFrameRate() const                                                     { return m_frameRate; }
00125 
00127         uint16_t getPortbase() const                                                    { return m_portbase; }
00128 
00130         bool getAcceptOwnPackets() const                                                { return m_acceptOwnPackets; }
00131 
00133         int getBandwidth() const                                                        { return m_bandwidth; }
00134         
00138         bool getUseQtOutput() const                                                     { return m_qtoutput; }
00139 
00141         SessionType getSessionType() const                                              { return m_type; }
00142 
00146         uint8_t getIncomingH263PayloadType() const                                      { return m_inH263PayloadType; }
00147 
00151         uint8_t getOutgoingH263PayloadType() const                                      { return m_outH263PayloadType; }
00152 
00156         uint8_t getIncomingInternalPayloadType() const                                  { return m_inIntPayloadType; }
00157 
00161         uint8_t getOutgoingInternalPayloadType() const                                  { return m_outIntPayloadType; }
00162 
00166         EncodingType getEncodingType() const                                            { return m_encType; }
00167 
00171         bool getWaitForKeyframe() const                                                 { return m_waitForKeyframe; }
00172 
00176         int getMaximumPayloadSize() const                                               { return m_maxPayloadSize; }
00177 
00179         void setDevice(int n)                                                           { m_devNum = n; }
00180 
00182         void setDevice(const std::string &devName)                                      { m_devName = devName; }
00183 
00185         void setWidth(int w)                                                            { m_width = w; }
00186         
00188         void setHeight(int h)                                                           { m_height = h; }
00189 
00191         void setBandwidth(int b)                                                        { m_bandwidth = b; }
00192 
00194         void setFrameRate(real_t r)                                                     { m_frameRate = r; }
00195 
00197         void setPortbase(uint16_t p)                                                    { m_portbase = p; }
00198         
00200         void setAcceptOwnPackets(bool v)                                                { m_acceptOwnPackets = v; }
00201 
00205         void setUseQtOutput(bool f)                                                     { m_qtoutput = f; }
00206 
00208         void setSessionType(SessionType s)                                              { m_type = s; }
00209 
00213         void setIncomingH263PayloadType(uint8_t pt)                                     { m_inH263PayloadType = pt; }
00214 
00218         void setOutgoingH263PayloadType(uint8_t pt)                                     { m_outH263PayloadType = pt; }
00219 
00223         void setIncomingInternalPayloadType(uint8_t pt)                                 { m_inIntPayloadType = pt; }
00224 
00228         void setOutgoingInternalPayloadType(uint8_t pt)                                 { m_outIntPayloadType = pt; }
00229 
00231         void setEncodingType(EncodingType t)                                            { m_encType = t; }
00232 
00236         void setWaitForKeyframe(bool w)                                                 { m_waitForKeyframe = w; }
00237 
00241         void setMaximumPayloadSize(int s)                                               { m_maxPayloadSize = s; }
00242 private:
00243         int m_devNum;
00244         std::string m_devName;
00245         int m_width, m_height;
00246         real_t m_frameRate;
00247         uint16_t m_portbase;
00248         bool m_acceptOwnPackets;
00249         int m_bandwidth;
00250         bool m_qtoutput;
00251         SessionType m_type;
00252         uint8_t m_inH263PayloadType;
00253         uint8_t m_outH263PayloadType;
00254         uint8_t m_inIntPayloadType;
00255         uint8_t m_outIntPayloadType;
00256         EncodingType m_encType; 
00257         bool m_waitForKeyframe;
00258         int m_maxPayloadSize;
00259 };
00260 
00267 class EMIPLIB_IMPORTEXPORT MIPVideoSession : public MIPErrorBase
00268 {
00269 public:
00270         MIPVideoSession();
00271         virtual ~MIPVideoSession();
00272 
00282         bool init(const MIPVideoSessionParams *pParams = 0, MIPRTPSynchronizer *pSync = 0, jrtplib::RTPSession *pRTPSession = 0);
00283         
00285         bool destroy();
00286 
00288         bool addDestination(const jrtplib::RTPAddress &addr);
00289 
00291         bool deleteDestination(const jrtplib::RTPAddress &addr);
00292 
00294         bool clearDestinations();
00295 
00297         bool supportsMulticasting();
00298 
00300         bool joinMulticastGroup(const jrtplib::RTPAddress &addr);
00301 
00303         bool leaveMulticastGroup(const jrtplib::RTPAddress &addr);
00304 
00306         bool leaveAllMulticastGroups();
00307         
00314         bool setReceiveMode(jrtplib::RTPTransmitter::ReceiveMode m);
00315 
00317         bool addToIgnoreList(const jrtplib::RTPAddress &addr);
00318 
00320         bool deleteFromIgnoreList(const jrtplib::RTPAddress &addr);
00321 
00323         bool clearIgnoreList();
00324 
00326         bool addToAcceptList(const jrtplib::RTPAddress &addr);
00327 
00329         bool deleteFromAcceptList(const jrtplib::RTPAddress &addr);
00330 
00332         bool clearAcceptList();
00333 
00337         bool getSourceIDs(std::list<uint64_t> &sourceIDs);
00338 
00352         bool getVideoFrame(uint64_t sourceID, uint8_t **pData, int *pWidth, int *pHeight, MIPTime minimalTime = MIPTime(0));
00353 protected:
00360         virtual void onInputThreadExit(bool err, const std::string &compName, const std::string &errStr)        { }
00361 
00368         virtual void onOutputThreadExit(bool err, const std::string &compName, const std::string &errStr)       { }
00369 private:
00370         class InputChain : public MIPComponentChain
00371         {
00372         public:
00373                 InputChain(MIPVideoSession *pVideoSess) : MIPComponentChain("Input chain")              { m_pVideoSess = pVideoSess; }
00374         protected:
00375                 void onThreadExit(bool err, const std::string &compName, const std::string &errStr)     { m_pVideoSess->onInputThreadExit(err, compName, errStr); }
00376         private:
00377                 MIPVideoSession *m_pVideoSess;
00378         };
00379 
00380         class OutputChain : public MIPComponentChain
00381         {
00382         public:
00383                 OutputChain(MIPVideoSession *pVideoSess) : MIPComponentChain("Output chain")            { m_pVideoSess = pVideoSess; }
00384         protected:
00385                 void onThreadExit(bool err, const std::string &compName, const std::string &errStr)     { m_pVideoSess->onOutputThreadExit(err, compName, errStr); }
00386         private:
00387                 MIPVideoSession *m_pVideoSess;
00388         };
00389 
00390         void zeroAll();
00391         void deleteAll();
00392 
00393         bool m_init;
00394         
00395         InputChain *m_pInputChain;
00396         OutputChain *m_pOutputChain;
00397         MIPAverageTimer *m_pTimer;
00398 #ifdef MIPCONFIG_SUPPORT_DIRECTSHOW
00399         MIPDirectShowCapture *m_pInput;
00400 #else
00401         MIPV4L2Input *m_pInput;
00402 #endif // MIPCONFIG_SUPPORT_DIRECTSHOW
00403         MIPTinyJPEGDecoder *m_pTinyJpegDec;
00404         MIPAVCodecFrameConverter *m_pInputFrameConverter;
00405         MIPAVCodecFrameConverter *m_pOutputFrameConverter;
00406         MIPAVCodecEncoder *m_pAvcEnc;
00407         MIPRTPH263Encoder *m_pRTPH263Enc;
00408         MIPRTPVideoEncoder *m_pRTPIntVideoEnc;
00409         MIPRTPComponent *m_pRTPComp;
00410         
00411         jrtplib::RTPSession *m_pRTPSession;
00412         bool m_deleteRTPSession;
00413         
00414         MIPAverageTimer *m_pTimer2;
00415         MIPRTPDecoder *m_pRTPDec;
00416         MIPRTPH263Decoder *m_pRTPH263Dec;
00417         MIPRTPVideoDecoder *m_pRTPIntVideoDec;
00418         MIPRTPDummyDecoder *m_pRTPDummyDec;
00419         MIPMediaBuffer *m_pMediaBuf;
00420         MIPComponentAlias *m_pBufferAlias;
00421         MIPAVCodecDecoder *m_pAvcDec;
00422         MIPVideoMixer *m_pMixer;
00423         MIPQtOutput *m_pQtOutput;
00424         MIPVideoFrameStorage *m_pStorage;
00425         
00426         friend class InputChain;
00427         friend class OutputChain;
00428 };
00429 
00430 #endif // MIPCONFIG_SUPPORT_AVCODEC && (MIPCONFIG_SUPPORT_DIRECTSHOW || MIPCONFIG_SUPPORT_VIDEO4LINUX)
00431 
00432 #endif // MIPVIDEOSESSION_H
00433