00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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 namespace PWLibStupidLinkerHacks {
00043 extern int mediaTypeLoader;
00044 };
00045
00046 class OpalMediaTypeDefinition;
00047 class OpalSecurityMode;
00048 class OpalConnection;
00049
00051
00052
00053
00054 typedef PFactory<OpalMediaTypeDefinition> OpalMediaTypeFactory;
00055 typedef OpalMediaTypeFactory::KeyList_T OpalMediaTypeList;
00056
00057
00060 class OpalMediaType : public std::string
00061 {
00062 public:
00063 OpalMediaType()
00064 { }
00065
00066 virtual ~OpalMediaType()
00067 { }
00068
00069 OpalMediaType(const std::string & str)
00070 : std::string(str) { }
00071
00072 OpalMediaType(const char * str)
00073 : std::string(str) { }
00074
00075 OpalMediaType(const PString & str)
00076 : std::string((const char *)str) { }
00077
00078 static const OpalMediaType & Audio();
00079 static const OpalMediaType & Video();
00080 static const OpalMediaType & Fax();
00081 static const OpalMediaType & UserInput();
00082
00083 void PrintOn(ostream & strm) const { strm << c_str(); }
00084
00085 OpalMediaTypeDefinition * GetDefinition() const;
00086 static OpalMediaTypeDefinition * GetDefinition(const OpalMediaType & key);
00087
00088 static OpalMediaTypeFactory::KeyList_T GetList() { return OpalMediaTypeFactory::GetKeyList(); }
00089
00090 #if OPAL_SIP
00091 static OpalMediaType GetMediaTypeFromSDP(const std::string & key, const std::string & transport);
00092 #endif // OPAL_SIP
00093
00094 enum AutoStartMode {
00095 DontOffer = -1,
00096 OfferInactive,
00097 Receive,
00098 Transmit,
00099 ReceiveTransmit,
00100 TransmitReceive = ReceiveTransmit
00101 };
00102 AutoStartMode GetAutoStart() const;
00103 };
00104
00105 ostream & operator << (ostream & strm, const OpalMediaType & mediaType);
00106
00107
00109
00110
00111
00112 class OpalRTPConnection;
00113 class RTP_UDP;
00114
00115 #if OPAL_SIP
00116 class SDPMediaDescription;
00117 class OpalTransportAddress;
00118 #endif
00119
00120 class OpalMediaSession;
00121
00124 class OpalMediaTypeDefinition
00125 {
00126 public:
00128 OpalMediaTypeDefinition(
00129 const char * mediaType,
00130 const char * sdpType,
00131 unsigned preferredSessionId,
00132 OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
00133 );
00134
00135
00136
00137 virtual ~OpalMediaTypeDefinition() { }
00138
00141 OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
00142
00145 void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
00146
00150 virtual bool UsesRTP() const { return true; }
00151
00154 virtual OpalMediaSession * CreateMediaSession(
00155 OpalConnection & connection,
00156 unsigned sessionID
00157 ) const;
00158
00165 virtual PString GetRTPEncoding() const = 0;
00166
00172 virtual RTP_UDP * CreateRTPSession(
00173 OpalRTPConnection & conn,
00174 unsigned sessionID,
00175 bool remoteIsNAT);
00176
00179 unsigned GetDefaultSessionId() const { return GetDefaultSessionId(m_mediaType); }
00180
00183 static unsigned GetDefaultSessionId(
00184 const OpalMediaType & mediaType
00185 );
00186
00189 static OpalMediaType GetMediaTypeForSessionId(
00190 unsigned sessionId
00191 );
00192
00193 protected:
00194 static PMutex & GetMapMutex();
00195
00196 typedef std::map<OpalMediaType, unsigned> MediaTypeToSessionIDMap_T;
00197 static MediaTypeToSessionIDMap_T & GetMediaTypeToSessionIDMap();
00198
00199 typedef std::map<unsigned, OpalMediaType> SessionIDToMediaTypeMap_T;
00200 static SessionIDToMediaTypeMap_T & GetSessionIDToMediaTypeMap();
00201
00202 std::string m_mediaType;
00203 OpalMediaType::AutoStartMode m_autoStart;
00204
00205 #if OPAL_SIP
00206 public:
00207
00208
00209
00210 virtual std::string GetSDPType() const
00211 { return m_sdpType; }
00212
00213
00214
00215
00216 virtual SDPMediaDescription * CreateSDPMediaDescription(
00217 const OpalTransportAddress & localAddress
00218 ) = 0;
00219
00220 protected:
00221 std::string m_sdpType;
00222 #endif
00223 };
00224
00225
00227
00228
00229
00230
00231 #define OPAL_INSTANTIATE_MEDIATYPE2(title, name, cls) \
00232 namespace OpalMediaTypeSpace { \
00233 static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##title##_##cls(name, true); \
00234 }; \
00235
00236 #define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
00237 OPAL_INSTANTIATE_MEDIATYPE2(type, #type, cls) \
00238
00239
00240 #ifdef SOLARIS
00241 template <char * Type, char * sdp>
00242 #else
00243 template <char * Type, const char * sdp>
00244 #endif
00245 class SimpleMediaType : public OpalMediaTypeDefinition
00246 {
00247 public:
00248 SimpleMediaType()
00249 : OpalMediaTypeDefinition(Type, sdp, 0)
00250 { }
00251
00252 virtual ~SimpleMediaType() { }
00253
00254 virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & ,unsigned , bool ) { return NULL; }
00255
00256 PString GetRTPEncoding() const { return PString::Empty(); }
00257
00258 #if OPAL_SIP
00259 public:
00260 virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & ) { return NULL; }
00261 #endif
00262 };
00263
00264
00265 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
00266 namespace OpalMediaTypeSpace { \
00267 char type##_type_string[] = #type; \
00268 char type##_sdp_string[] = #sdp; \
00269 typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
00270 }; \
00271 OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
00272
00273 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "")
00274
00276
00277
00278
00279
00280 class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
00281 public:
00282 OpalRTPAVPMediaType(
00283 const char * mediaType,
00284 const char * sdpType,
00285 unsigned preferredSessionId,
00286 OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
00287 );
00288
00289 virtual PString GetRTPEncoding() const;
00290
00291 OpalMediaSession * CreateMediaSession(OpalConnection & , unsigned ) const;
00292 };
00293
00294
00295 class OpalAudioMediaType : public OpalRTPAVPMediaType {
00296 public:
00297 OpalAudioMediaType();
00298
00299 #if OPAL_SIP
00300 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00301 #endif
00302 };
00303
00304
00305 #if OPAL_VIDEO
00306
00307 class OpalVideoMediaType : public OpalRTPAVPMediaType {
00308 public:
00309 OpalVideoMediaType();
00310
00311 #if OPAL_SIP
00312 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00313 #endif
00314 };
00315
00316 #endif // OPAL_VIDEO
00317
00318
00319 #if OPAL_T38_CAPABILITY
00320
00321 class OpalFaxMediaType : public OpalMediaTypeDefinition
00322 {
00323 public:
00324 OpalFaxMediaType();
00325
00326 PString GetRTPEncoding(void) const;
00327 RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
00328 unsigned sessionID, bool remoteIsNAT);
00329
00330 OpalMediaSession * CreateMediaSession(OpalConnection & conn, unsigned ) const;
00331
00332 #if OPAL_SIP
00333 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00334 #endif
00335 };
00336
00337 #endif // OPAL_T38_CAPABILITY
00338
00339
00340 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
00341
00342
00343 #endif // OPAL_OPAL_MEDIATYPE_H