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 <opal/buildopts.h>
00035
00036 #include <ptlib/pfactory.h>
00037 #include <ptlib/bitwise_enum.h>
00038
00039
00040 #ifdef P_USE_PRAGMA
00041 #pragma interface
00042 #endif
00043
00044
00045 class OpalMediaTypeDefinition;
00046 class OpalConnection;
00047
00049
00050
00051
00052 class OpalMediaType;
00053 typedef PFactory<OpalMediaTypeDefinition, OpalMediaType> OpalMediaTypesFactory;
00054 typedef OpalMediaTypesFactory::KeyList_T OpalMediaTypeList;
00055
00056
00059 class OpalMediaType : public std::string
00060 {
00061 public:
00062 OpalMediaType()
00063 { }
00064
00065 virtual ~OpalMediaType()
00066 { }
00067
00068 OpalMediaType(const std::string & str)
00069 : std::string(str) { }
00070
00071 OpalMediaType(const char * str)
00072 : std::string(str) { }
00073
00074 OpalMediaType(const PString & str)
00075 : std::string((const char *)str) { }
00076
00077 static const OpalMediaType & Audio();
00078 #if OPAL_VIDEO
00079 static const OpalMediaType & Video();
00080 #endif
00081 #if OPAL_T38_CAPABILITY
00082 static const OpalMediaType & Fax();
00083 #endif
00084 static const OpalMediaType & UserInput();
00085
00086 OpalMediaTypeDefinition * operator->() const { return GetDefinition(); }
00087 OpalMediaTypeDefinition * GetDefinition() const;
00088 static OpalMediaTypeDefinition * GetDefinition(const OpalMediaType & key);
00089 static OpalMediaTypeDefinition * GetDefinition(unsigned sessionId);
00090
00094 static OpalMediaTypeList GetList();
00095
00096 P_DECLARE_BITWISE_ENUM_EX(AutoStartMode, 3,
00097 (OfferInactive, Receive, Transmit, DontOffer),
00098 ReceiveTransmit = Receive|Transmit,
00099 TransmitReceive = Receive|Transmit);
00100
00101 AutoStartMode GetAutoStart() const;
00102 };
00103
00104
00105 __inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
00106 {
00107 return strm << mediaType.c_str();
00108 }
00109
00110
00112
00113
00114
00115
00116 class SDPMediaDescription;
00117 class OpalTransportAddress;
00118 class OpalMediaSession;
00119
00120
00123 class OpalMediaTypeDefinition
00124 {
00125 public:
00127 OpalMediaTypeDefinition(
00128 const char * mediaType,
00129 const char * mediaSession,
00130 unsigned requiredSessionId = 0,
00131 OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
00132 );
00133
00134
00135
00136 virtual ~OpalMediaTypeDefinition();
00137
00140 OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
00141
00144 void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
00145 void SetAutoStart(OpalMediaType::AutoStartMode v, bool on) { if (on) m_autoStart |= v; else m_autoStart -= v; }
00146
00149 unsigned GetDefaultSessionId() const { return m_defaultSessionId; }
00150
00153 const PString & GetMediaSessionType() const { return m_mediaSessionType; }
00154
00155 #if OPAL_SIP
00157 virtual bool MatchesSDP(
00158 const PCaselessString & sdpMediaType,
00159 const PCaselessString & sdpTransport,
00160 const PStringArray & sdpLines,
00161 PINDEX index
00162 );
00163
00165 virtual SDPMediaDescription * CreateSDPMediaDescription(
00166 const OpalTransportAddress & localAddress
00167 ) const;
00168 #endif // OPAL_SIP
00169
00170 protected:
00171 OpalMediaType m_mediaType;
00172 PString m_mediaSessionType;
00173 unsigned m_defaultSessionId;
00174 OpalMediaType::AutoStartMode m_autoStart;
00175
00176 private:
00177 P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned), NULL);
00178 };
00179
00180
00182
00183
00184
00185
00186 #define OPAL_INSTANTIATE_MEDIATYPE2(cls, name) \
00187 PFACTORY_CREATE(OpalMediaTypesFactory, cls, name, true)
00188
00189 #define OPAL_INSTANTIATE_MEDIATYPE(cls) \
00190 OPAL_INSTANTIATE_MEDIATYPE2(cls, cls::Name())
00191
00192
00193 template <const char * Type, unsigned SessionId = 0>
00194 class SimpleMediaType : public OpalMediaTypeDefinition
00195 {
00196 public:
00197 static const char * Name() { return Type; }
00198
00199 SimpleMediaType()
00200 : OpalMediaTypeDefinition(Name(), PString::Empty(), SessionId)
00201 { }
00202 };
00203
00204 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(cls, name, ...) \
00205 namespace OpalMediaTypeSpace { extern const char cls[] = name; }; \
00206 typedef SimpleMediaType<OpalMediaTypeSpace::cls, ##__VA_ARGS__> cls; \
00207 OPAL_INSTANTIATE_MEDIATYPE(cls) \
00208
00209
00211
00212
00213
00214
00215 class OpalRTPAVPMediaType : public OpalMediaTypeDefinition {
00216 public:
00217 OpalRTPAVPMediaType(
00218 const char * mediaType,
00219 unsigned requiredSessionId = 0,
00220 OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
00221 );
00222
00223 #if OPAL_SIP
00224 virtual bool MatchesSDP(const PCaselessString &, const PCaselessString &, const PStringArray &, PINDEX);
00225 #endif
00226 };
00227
00228
00229 class OpalAudioMediaType : public OpalRTPAVPMediaType {
00230 public:
00231 static const char * Name();
00232
00233 OpalAudioMediaType();
00234
00235 #if OPAL_SIP
00236 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &) const;
00237 #endif
00238 };
00239
00240
00241 #if OPAL_VIDEO
00242
00243 class OpalVideoMediaType : public OpalRTPAVPMediaType {
00244 public:
00245 static const char * Name();
00246
00247 OpalVideoMediaType();
00248
00249 #if OPAL_SIP
00250 SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &) const;
00251 #endif
00252 };
00253
00254 #endif // OPAL_VIDEO
00255
00256
00257 #if OPAL_T38_CAPABILITY
00258
00259 class OpalFaxMediaType : public OpalMediaTypeDefinition
00260 {
00261 public:
00262 static const char * Name();
00263 static const PCaselessString & UDPTL();
00264
00265 OpalFaxMediaType();
00266
00267 #if OPAL_SIP
00268 static const PCaselessString & GetSDPMediaType();
00269 static const PString & GetSDPTransportType();
00270
00271 virtual bool MatchesSDP(
00272 const PCaselessString & sdpMediaType,
00273 const PCaselessString & sdpTransport,
00274 const PStringArray & sdpLines,
00275 PINDEX index
00276 );
00277
00278 SDPMediaDescription * CreateSDPMediaDescription(
00279 const OpalTransportAddress & localAddress
00280 ) const;
00281 #endif // OPAL_SIP
00282 };
00283
00284 #endif // OPAL_T38_CAPABILITY
00285
00286
00287 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
00288
00289
00290 #endif // OPAL_OPAL_MEDIATYPE_H