mediatype.h

Go to the documentation of this file.
00001 /*
00002  * mediatype.h
00003  *
00004  * Media Format Type descriptions
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  *
00008  * Copyright (C) 2007 Post Increment and Hannes Friederich
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is OPAL
00021  *
00022  * The Initial Developer of the Original Code is Hannes Friederich and Post Increment
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 24162 $
00027  * $Author: rjongbloed $
00028  * $Date: 2010-03-29 02:46:26 -0500 (Mon, 29 Mar 2010) $
00029  */
00030 
00031 #ifndef OPAL_OPAL_MEDIATYPE_H
00032 #define OPAL_OPAL_MEDIATYPE_H
00033 
00034 #include <ptbuildopts.h>
00035 #include <ptlib/pfactory.h>
00036 #include <opal/buildopts.h>
00037 
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041 
00042 
00043 class OpalMediaTypeDefinition;
00044 class OpalSecurityMode;
00045 class OpalConnection;
00046 
00048 //
00049 //  define the factory used for keeping track of OpalMediaTypeDefintions
00050 //
00051 typedef PFactory<OpalMediaTypeDefinition> OpalMediaTypeFactory;
00052 typedef OpalMediaTypeFactory::KeyList_T OpalMediaTypeList;
00053 
00054 
00057 class OpalMediaType : public std::string     // do not make this PCaselessString as that type does not work as index for std::map etc
00058 {
00059   public:
00060     OpalMediaType()
00061     { }
00062 
00063     virtual ~OpalMediaType()
00064     { }
00065 
00066     OpalMediaType(const std::string & str)
00067       : std::string(str) { }
00068 
00069     OpalMediaType(const char * str)
00070       : std::string(str) { }
00071 
00072     OpalMediaType(const PString & str)
00073       : std::string((const char *)str) { }
00074 
00075     static const OpalMediaType & Audio();
00076     static const OpalMediaType & Video();
00077     static const OpalMediaType & Fax();
00078     static const OpalMediaType & UserInput();
00079 
00080     OpalMediaTypeDefinition * GetDefinition() const;
00081     static OpalMediaTypeDefinition * GetDefinition(const OpalMediaType & key);
00082     static OpalMediaTypeDefinition * GetDefinition(unsigned sessionId);
00083 
00084     static OpalMediaTypeFactory::KeyList_T GetList() { return OpalMediaTypeFactory::GetKeyList(); }
00085 
00086 #if OPAL_SIP
00087     static OpalMediaType GetMediaTypeFromSDP(const std::string & key, const std::string & transport);
00088 #endif  // OPAL_SIP
00089 
00090     enum AutoStartMode {
00091       // Do not change order of enum as useful for bitmasking rx/tx
00092       OfferInactive,
00093       Receive,
00094       Transmit,
00095       ReceiveTransmit,
00096       DontOffer,
00097 
00098       TransmitReceive = ReceiveTransmit
00099     };
00100 
00101     __inline friend AutoStartMode operator++(AutoStartMode & mode)                 { return (mode = (AutoStartMode)(mode+1)); }
00102     __inline friend AutoStartMode operator--(AutoStartMode & mode)                 { return (mode = (AutoStartMode)(mode-1)); }
00103     __inline friend AutoStartMode operator|=(AutoStartMode & m1, AutoStartMode m2) { return (m1 = (AutoStartMode)((m1 & ~DontOffer) | m2)); }
00104     __inline friend AutoStartMode operator-=(AutoStartMode & m1, AutoStartMode m2) { return (m1 = (AutoStartMode)((int)m1 & ~((int)m2|DontOffer))); }
00105 
00106     AutoStartMode GetAutoStart() const;
00107 };
00108 
00109 
00110 __inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
00111 {
00112   return strm << mediaType.c_str();
00113 }
00114 
00115 
00117 //
00118 //  this class defines the functions needed to work with the media type, i.e. 
00119 //
00120 class OpalRTPConnection;
00121 class RTP_UDP;
00122 
00123 #if OPAL_SIP
00124 class SDPMediaDescription;
00125 class OpalTransportAddress;
00126 #endif
00127 
00128 class OpalMediaSession;
00129 
00132 class OpalMediaTypeDefinition
00133 {
00134   public:
00136     OpalMediaTypeDefinition(
00137       const char * mediaType,          
00138       const char * sdpType,            
00139       unsigned requiredSessionId = 0,  
00140       OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer   
00141     );
00142 
00143     // Needed to avoid gcc warning about classes with virtual functions and 
00144     //  without a virtual destructor
00145     virtual ~OpalMediaTypeDefinition() { }
00146 
00149     OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
00150 
00153     void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
00154     void SetAutoStart(OpalMediaType::AutoStartMode v, bool on) { if (on) m_autoStart |= v; else m_autoStart -= v; }
00155 
00159     virtual bool UsesRTP() const { return true; }
00160 
00163     virtual OpalMediaSession * CreateMediaSession(
00164       OpalConnection & connection,  
00165       unsigned         sessionID    
00166     ) const;
00167 
00174     virtual PString GetRTPEncoding() const = 0;
00175 
00181     virtual RTP_UDP * CreateRTPSession(
00182       OpalRTPConnection & conn,
00183       unsigned sessionID, 
00184       bool remoteIsNAT
00185     );
00186 
00189     unsigned GetDefaultSessionId() const { return m_defaultSessionId; }
00190 
00191   protected:
00192     std::string m_mediaType;
00193     unsigned    m_defaultSessionId;
00194     OpalMediaType::AutoStartMode m_autoStart;
00195 
00196 #if OPAL_SIP
00197   public:
00198     //
00199     //  return the SDP type for this media type
00200     //
00201     virtual std::string GetSDPType() const 
00202     { return m_sdpType; }
00203 
00204     //
00205     //  create an SDP media description entry for this media type
00206     //
00207     virtual SDPMediaDescription * CreateSDPMediaDescription(
00208       const OpalTransportAddress & localAddress
00209     ) = 0;
00210 
00211   protected:
00212     std::string m_sdpType;
00213 #endif
00214 };
00215 
00216 
00218 //
00219 //  define a macro for declaring a new OpalMediaTypeDefinition factory
00220 //
00221 
00222 #define OPAL_INSTANTIATE_MEDIATYPE2(title, name, cls) \
00223 namespace OpalMediaTypeSpace { \
00224   static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##title##_##cls(name, true); \
00225 }; \
00226 
00227 #define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
00228   OPAL_INSTANTIATE_MEDIATYPE2(type, #type, cls) \
00229 
00230 
00231 #ifdef SOLARIS
00232 template <char * Type, char * sdp>
00233 #else
00234 template <char * Type, const char * sdp>
00235 #endif
00236 class SimpleMediaType : public OpalMediaTypeDefinition
00237 {
00238   public:
00239     SimpleMediaType()
00240       : OpalMediaTypeDefinition(Type, sdp, 0)
00241     { }
00242 
00243     virtual ~SimpleMediaType()                     { }
00244 
00245     virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & ,unsigned , bool ) { return NULL; }
00246 
00247     PString GetRTPEncoding() const { return PString::Empty(); } 
00248 
00249 #if OPAL_SIP
00250   public:
00251     virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & ) { return NULL; }
00252 #endif
00253 };
00254 
00255 
00256 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
00257 namespace OpalMediaTypeSpace { \
00258   char type##_type_string[] = #type; \
00259   char type##_sdp_string[] = #sdp; \
00260   typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
00261 }; \
00262 OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
00263 
00264 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "") 
00265 
00267 //
00268 //  common ancestor for audio and video OpalMediaTypeDefinitions
00269 //
00270 
00271 class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
00272   public:
00273     OpalRTPAVPMediaType(
00274       const char * mediaType, 
00275       const char * sdpType, 
00276       unsigned     requiredSessionId = 0,
00277       OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
00278     );
00279 
00280     virtual PString GetRTPEncoding() const;
00281 
00282     OpalMediaSession * CreateMediaSession(OpalConnection & /*conn*/, unsigned /* sessionID*/) const;
00283 };
00284 
00285 
00286 class OpalAudioMediaType : public OpalRTPAVPMediaType {
00287   public:
00288     OpalAudioMediaType();
00289 
00290 #if OPAL_SIP
00291     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00292 #endif
00293 };
00294 
00295 
00296 #if OPAL_VIDEO
00297 
00298 class OpalVideoMediaType : public OpalRTPAVPMediaType {
00299   public:
00300     OpalVideoMediaType();
00301 
00302 #if OPAL_SIP
00303     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00304 #endif
00305 };
00306 
00307 #endif // OPAL_VIDEO
00308 
00309 
00310 #if OPAL_T38_CAPABILITY
00311 
00312 class OpalFaxMediaType : public OpalMediaTypeDefinition 
00313 {
00314   public:
00315     OpalFaxMediaType();
00316 
00317     PString GetRTPEncoding(void) const;
00318     RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
00319                                unsigned sessionID, bool remoteIsNAT);
00320 
00321     OpalMediaSession * CreateMediaSession(OpalConnection & conn, unsigned /* sessionID*/) const;
00322 
00323 #if OPAL_SIP
00324     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00325 #endif
00326 };
00327 
00328 PFACTORY_LOAD(T38PseudoRTP_Handler);
00329 
00330 #endif // OPAL_T38_CAPABILITY
00331 
00332 
00333 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
00334 
00335 
00336 #endif // OPAL_OPAL_MEDIATYPE_H

Generated on Mon Feb 21 20:19:21 2011 for OPAL by  doxygen 1.4.7