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: 22444 $
00027  * $Author: rjongbloed $
00028  * $Date: 2009-04-20 23:49:06 +0000 (Mon, 20 Apr 2009) $
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 
00083     static OpalMediaTypeFactory::KeyList_T GetList() { return OpalMediaTypeFactory::GetKeyList(); }
00084 
00085 #if OPAL_SIP
00086     static OpalMediaType GetMediaTypeFromSDP(const std::string & key, const std::string & transport);
00087 #endif  // OPAL_SIP
00088 
00089     enum AutoStartMode {
00090       DontOffer = -1, // Do not change order of enum as useful for bitmasking rx/tx
00091       OfferInactive,
00092       Receive,
00093       Transmit,
00094       ReceiveTransmit,
00095       TransmitReceive = ReceiveTransmit
00096     };
00097     AutoStartMode GetAutoStart() const;
00098 };
00099 
00100 
00101 __inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
00102 {
00103   return strm << mediaType.c_str();
00104 }
00105 
00106 
00108 //
00109 //  this class defines the functions needed to work with the media type, i.e. 
00110 //
00111 class OpalRTPConnection;
00112 class RTP_UDP;
00113 
00114 #if OPAL_SIP
00115 class SDPMediaDescription;
00116 class OpalTransportAddress;
00117 #endif
00118 
00119 class OpalMediaSession;
00120 
00123 class OpalMediaTypeDefinition
00124 {
00125   public:
00127     OpalMediaTypeDefinition(
00128       const char * mediaType,          
00129       const char * sdpType,            
00130       unsigned     preferredSessionId, 
00131       OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer   
00132     );
00133 
00134     // Needed to avoid gcc warning about classes with virtual functions and 
00135     //  without a virtual destructor
00136     virtual ~OpalMediaTypeDefinition() { }
00137 
00140     OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
00141 
00144     void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
00145 
00149     virtual bool UsesRTP() const { return true; }
00150 
00153     virtual OpalMediaSession * CreateMediaSession(
00154       OpalConnection & connection,  
00155       unsigned         sessionID    
00156     ) const;
00157 
00164     virtual PString GetRTPEncoding() const = 0;
00165 
00171     virtual RTP_UDP * CreateRTPSession(
00172       OpalRTPConnection & conn,
00173       unsigned sessionID, 
00174       bool remoteIsNAT);
00175 
00178     unsigned GetDefaultSessionId() const { return GetDefaultSessionId(m_mediaType); }
00179 
00182     static unsigned GetDefaultSessionId(
00183       const OpalMediaType & mediaType   
00184     );
00185 
00188     static OpalMediaType GetMediaTypeForSessionId(
00189       unsigned sessionId      
00190     );
00191 
00192   protected:
00193     static PMutex & GetMapMutex();
00194 
00195     typedef std::map<OpalMediaType, unsigned> MediaTypeToSessionIDMap_T;
00196     static MediaTypeToSessionIDMap_T & GetMediaTypeToSessionIDMap();
00197 
00198     typedef std::map<unsigned, OpalMediaType> SessionIDToMediaTypeMap_T;
00199     static SessionIDToMediaTypeMap_T & GetSessionIDToMediaTypeMap();
00200 
00201     std::string m_mediaType;
00202     OpalMediaType::AutoStartMode m_autoStart;
00203 
00204 #if OPAL_SIP
00205   public:
00206     //
00207     //  return the SDP type for this media type
00208     //
00209     virtual std::string GetSDPType() const 
00210     { return m_sdpType; }
00211 
00212     //
00213     //  create an SDP media description entry for this media type
00214     //
00215     virtual SDPMediaDescription * CreateSDPMediaDescription(
00216       const OpalTransportAddress & localAddress
00217     ) = 0;
00218 
00219   protected:
00220     std::string m_sdpType;
00221 #endif
00222 };
00223 
00224 
00226 //
00227 //  define a macro for declaring a new OpalMediaTypeDefinition factory
00228 //
00229 
00230 #define OPAL_INSTANTIATE_MEDIATYPE2(title, name, cls) \
00231 namespace OpalMediaTypeSpace { \
00232   static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##title##_##cls(name, true); \
00233 }; \
00234 
00235 #define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
00236   OPAL_INSTANTIATE_MEDIATYPE2(type, #type, cls) \
00237 
00238 
00239 #ifdef SOLARIS
00240 template <char * Type, char * sdp>
00241 #else
00242 template <char * Type, const char * sdp>
00243 #endif
00244 class SimpleMediaType : public OpalMediaTypeDefinition
00245 {
00246   public:
00247     SimpleMediaType()
00248       : OpalMediaTypeDefinition(Type, sdp, 0)
00249     { }
00250 
00251     virtual ~SimpleMediaType()                     { }
00252 
00253     virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & ,unsigned , bool ) { return NULL; }
00254 
00255     PString GetRTPEncoding() const { return PString::Empty(); } 
00256 
00257 #if OPAL_SIP
00258   public:
00259     virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & ) { return NULL; }
00260 #endif
00261 };
00262 
00263 
00264 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
00265 namespace OpalMediaTypeSpace { \
00266   char type##_type_string[] = #type; \
00267   char type##_sdp_string[] = #sdp; \
00268   typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
00269 }; \
00270 OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
00271 
00272 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "") 
00273 
00275 //
00276 //  common ancestor for audio and video OpalMediaTypeDefinitions
00277 //
00278 
00279 class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
00280   public:
00281     OpalRTPAVPMediaType(
00282       const char * mediaType, 
00283       const char * sdpType, 
00284       unsigned     preferredSessionId,
00285       OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
00286     );
00287 
00288     virtual PString GetRTPEncoding() const;
00289 
00290     OpalMediaSession * CreateMediaSession(OpalConnection & /*conn*/, unsigned /* sessionID*/) const;
00291 };
00292 
00293 
00294 class OpalAudioMediaType : public OpalRTPAVPMediaType {
00295   public:
00296     OpalAudioMediaType();
00297 
00298 #if OPAL_SIP
00299     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00300 #endif
00301 };
00302 
00303 
00304 #if OPAL_VIDEO
00305 
00306 class OpalVideoMediaType : public OpalRTPAVPMediaType {
00307   public:
00308     OpalVideoMediaType();
00309 
00310 #if OPAL_SIP
00311     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00312 #endif
00313 };
00314 
00315 #endif // OPAL_VIDEO
00316 
00317 
00318 #if OPAL_T38_CAPABILITY
00319 
00320 class OpalFaxMediaType : public OpalMediaTypeDefinition 
00321 {
00322   public:
00323     OpalFaxMediaType();
00324 
00325     PString GetRTPEncoding(void) const;
00326     RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
00327                                unsigned sessionID, bool remoteIsNAT);
00328 
00329     OpalMediaSession * CreateMediaSession(OpalConnection & conn, unsigned /* sessionID*/) const;
00330 
00331 #if OPAL_SIP
00332     SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00333 #endif
00334 };
00335 
00336 #endif // OPAL_T38_CAPABILITY
00337 
00338 
00339 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
00340 
00341 
00342 #endif // OPAL_OPAL_MEDIATYPE_H

Generated on Mon Aug 3 20:50:24 2009 for OPAL by  doxygen 1.5.1