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_MEDIATYPE_H
00032 #define __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
00050
00051
00052
00053 typedef PFactory<OpalMediaTypeDefinition> OpalMediaTypeFactory;
00054 typedef OpalMediaTypeFactory::KeyList_T OpalMediaTypeList;
00055
00057
00058
00059
00060
00061 class OpalMediaType : public std::string
00062 {
00063 public:
00064 OpalMediaType()
00065 { }
00066
00067 virtual ~OpalMediaType()
00068 { }
00069
00070 OpalMediaType(const std::string & _str)
00071 : std::string(_str) { }
00072
00073 OpalMediaType(const char * _str)
00074 : std::string(_str) { }
00075
00076 OpalMediaType(const PString & _str)
00077 : std::string((const char *)_str) { }
00078
00079 static const char * Audio();
00080 static const char * Video();
00081 static const char * Fax();
00082 static const char * UserInput();
00083
00084 void PrintOn(ostream & strm) const { strm << (std::string &)*this; }
00085
00086 OpalMediaTypeDefinition * GetDefinition() const;
00087 static OpalMediaTypeDefinition * GetDefinition(const OpalMediaType & key);
00088
00089 static OpalMediaTypeFactory::KeyList_T GetList() { return OpalMediaTypeFactory::GetKeyList(); }
00090
00091 #if OPAL_SIP
00092 public:
00093 static OpalMediaType GetMediaTypeFromSDP(const std::string & key);
00094 static PString GetSDPFromFromMediaType(const OpalMediaType & type);
00095 static OpalMediaTypeDefinition * GetDefinitionFromSDP(const std::string & key);
00096 #endif // OPAL_SIP
00097 };
00098
00099 ostream & operator << (ostream & strm, const OpalMediaType & mediaType);
00100
00101
00103
00104
00105
00106 class OpalRTPConnection;
00107 class RTP_UDP;
00108
00109 #if OPAL_RTP_AGGREGATE
00110 class PHandleAggregator;
00111 #else
00112 typedef void * PHandleAggregator;
00113 #endif
00114
00115 #if OPAL_SIP
00116 class SDPMediaDescription;
00117 class OpalTransportAddress;
00118 #endif
00119
00121
00122
00123
00124
00125 class OpalMediaTypeDefinition {
00126 public:
00127
00128
00129
00130 OpalMediaTypeDefinition(
00131 const char * mediaType,
00132 const char * sdpType,
00133 unsigned preferredSessionId
00134 );
00135
00136
00137
00138
00139
00140 virtual ~OpalMediaTypeDefinition() { }
00141
00142
00143
00144
00145
00146
00147 virtual PString GetRTPEncoding() const = 0;
00148
00149
00150
00151
00152
00153 virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
00154 #if OPAL_RTP_AGGREGATE
00155 PHandleAggregator * agg,
00156 #endif
00157 OpalSecurityMode * securityMode,
00158 unsigned sessionID,
00159 bool remoteIsNAT);
00160
00161
00162
00163
00164 unsigned GetDefaultSessionId() { return GetDefaultSessionId(mediaType); }
00165
00166 static unsigned GetDefaultSessionId(
00167 const OpalMediaType & mediaType
00168 );
00169
00170
00171
00172
00173 static OpalMediaType GetMediaTypeForSessionId(
00174 unsigned sessionId
00175 );
00176
00177 protected:
00178 static PMutex & GetMapMutex();
00179
00180 typedef std::map<OpalMediaType, unsigned> MediaTypeToSessionIDMap_T;
00181 static MediaTypeToSessionIDMap_T & GetMediaTypeToSessionIDMap();
00182
00183 typedef std::map<unsigned, OpalMediaType> SessionIDToMediaTypeMap_T;
00184 static SessionIDToMediaTypeMap_T & GetSessionIDToMediaTypeMap();
00185
00186 std::string mediaType;
00187
00188 #if OPAL_SIP
00189 public:
00190
00191
00192
00193 virtual std::string GetSDPType() const
00194 { return sdpType; }
00195
00196
00197
00198
00199 virtual SDPMediaDescription * CreateSDPMediaDescription(
00200 const OpalTransportAddress & localAddress
00201 ) = 0;
00202
00203 protected:
00204 std::string sdpType;
00205 #endif
00206 };
00207
00208
00210
00211
00212
00213
00214 #define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
00215 namespace OpalMediaTypeSpace { \
00216 static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##type##_##cls(#type, true); \
00217 }; \
00218
00219
00220 #ifdef SOLARIS
00221 template <char * Type, char * sdp>
00222 #else
00223 template <char * Type, const char * sdp>
00224 #endif
00225 class SimpleMediaType : public OpalMediaTypeDefinition
00226 {
00227 public:
00228 SimpleMediaType()
00229 : OpalMediaTypeDefinition(Type, sdp, 0)
00230 { }
00231
00232 virtual ~SimpleMediaType() { }
00233
00234 virtual RTP_UDP * CreateRTPSession(OpalRTPConnection & ,
00235 #if OPAL_RTP_AGGREGATE
00236 PHandleAggregator * ,
00237 #endif
00238 unsigned , bool ) { return NULL; }
00239
00240 PString GetRTPEncoding() const { return PString::Empty(); }
00241
00242 #if OPAL_SIP
00243 public:
00244 virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & ) { return NULL; }
00245 #endif
00246 };
00247
00248
00249 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
00250 namespace OpalMediaTypeSpace { \
00251 char type##_type_string[] = #type; \
00252 char type##_sdp_string[] = #sdp; \
00253 typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
00254 }; \
00255 OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
00256
00257 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "")
00258
00260
00261
00262
00263
00264 class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
00265 public:
00266 OpalRTPAVPMediaType(
00267 const char * mediaType,
00268 const char * sdpType,
00269 unsigned preferredSessionId
00270 );
00271
00272 virtual PString GetRTPEncoding() const;
00273 };
00274
00275
00276 class OpalAudioMediaType : public OpalRTPAVPMediaType {
00277 public:
00278 OpalAudioMediaType();
00279
00280 #if OPAL_SIP
00281 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00282 #endif
00283 };
00284
00285
00286 #if OPAL_VIDEO
00287
00288 class OpalVideoMediaType : public OpalRTPAVPMediaType {
00289 public:
00290 OpalVideoMediaType();
00291
00292 #if OPAL_SIP
00293 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00294 #endif
00295 };
00296
00297 #endif // OPAL_VIDEO
00298
00299
00300 #if OPAL_T38_CAPABILITY
00301
00302 #include <opal/mediatype.h>
00303
00304 class OpalFaxMediaType : public OpalMediaTypeDefinition
00305 {
00306 public:
00307 OpalFaxMediaType();
00308
00309 PString GetRTPEncoding(void) const;
00310 RTP_UDP * CreateRTPSession(OpalRTPConnection & conn,
00311 #if OPAL_RTP_AGGREGATE
00312 PHandleAggregator * agg,
00313 #endif
00314 unsigned sessionID, bool remoteIsNAT);
00315
00316 #if OPAL_SIP
00317 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
00318 #endif
00319 };
00320
00321 #endif // OPAL_T38_CAPABILITY
00322
00323
00324 #endif // __OPAL_MEDIATYPE_H