OPAL  Version 3.18.8
mediatype.h
Go to the documentation of this file.
1 /*
2  * mediatype.h
3  *
4  * Media Format Type descriptions
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (C) 2007 Post Increment and Hannes Friederich
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is OPAL
21  *
22  * The Initial Developer of the Original Code is Hannes Friederich and Post Increment
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_OPAL_MEDIATYPE_H
28 #define OPAL_OPAL_MEDIATYPE_H
29 
30 #include <opal_config.h>
31 
32 #include <ptlib/pfactory.h>
33 #include <ptlib/bitwise_enum.h>
34 
35 
36 #ifdef P_USE_PRAGMA
37 #pragma interface
38 #endif
39 
40 
42 class OpalConnection;
43 
45 //
46 // define the factory used for keeping track of OpalMediaTypeDefintions
47 //
49 typedef PFactory<OpalMediaTypeDefinition, OpalMediaType> OpalMediaTypesFactory;
50 class OpalMediaTypeList : public OpalMediaTypesFactory::KeyList_T, public PObject
51 {
52  public:
54 
55  OpalMediaTypeList(const OpalMediaTypesFactory::KeyList_T & list)
56  : OpalMediaTypesFactory::KeyList_T(list) { }
57 
58  virtual void PrintOn(ostream & strm) const;
59 
60  void PrioritiseAudioVideo();
61 };
62 
63 
66 class OpalMediaType : public std::string // do not make this PCaselessString as that type does not work as index for std::map etc
67 {
68  public:
70  { }
71 
72  virtual ~OpalMediaType()
73  { }
74 
75  OpalMediaType(const std::string & str)
76  : std::string(str) { }
77 
78  OpalMediaType(const char * str)
79  : std::string(str) { }
80 
81  OpalMediaType(const PString & str)
82  : std::string((const char *)str) { }
83 
84  static const OpalMediaType & Audio();
85 #if OPAL_VIDEO
86  static const OpalMediaType & Video();
87 #endif
88 #if OPAL_T38_CAPABILITY
89  static const OpalMediaType & Fax();
90 #endif
91  static const OpalMediaType & UserInput();
92 
96 
100  static OpalMediaTypeList GetList();
101 
102  P_DECLARE_BITWISE_ENUM_EX(AutoStartMode, 3,
103  (OfferInactive, Receive, Transmit, DontOffer),
104  ReceiveTransmit = Receive|Transmit,
105  TransmitReceive = Receive|Transmit);
106 
107  AutoStartMode GetAutoStart() const;
108 
109  class AutoStartMap : public std::map<OpalMediaType, OpalMediaType::AutoStartMode>
110  {
111  public:
112  AutoStartMap();
113 
114  bool Add(const PString & stringOption);
115  bool Add(const PCaselessString & mediaTypeName, const PCaselessString & modeName);
116 
117  OpalMediaType::AutoStartMode GetAutoStart(const OpalMediaType & mediaType) const;
118 
119  void SetGlobalAutoStart();
120 
121  protected:
122  PDECLARE_MUTEX(m_mutex);
123  };
124 };
125 
126 
127 __inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
128 {
129  return strm << mediaType.c_str();
130 }
131 
132 ostream & operator<<(ostream & strm, OpalMediaType::AutoStartMode mode);
133 
134 
136 //
137 // this class defines the functions needed to work with the media type, i.e.
138 //
139 
140 class SDPMediaDescription;
142 class OpalMediaSession;
143 
144 
148 {
149  public:
152  const char * mediaType,
153  const char * mediaSession,
154  unsigned defaultSessionId = 0,
155  OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
156  );
157 
158  // Needed to avoid gcc warning about classes with virtual functions and
159  // without a virtual destructor
160  virtual ~OpalMediaTypeDefinition();
161 
162  // Get the media type instance
163  const OpalMediaType & GetMediaType() const { return m_mediaType; }
164 
167  OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
168 
171  void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
172  void SetAutoStart(OpalMediaType::AutoStartMode v, bool on);
173 
176  unsigned GetDefaultSessionId() const { return m_defaultSessionId; }
177 
180  const PCaselessString & GetMediaSessionType() const { return m_mediaSessionType; }
181 
182 #if OPAL_SDP
183  virtual PString GetSDPMediaType() const;
184  virtual PString GetSDPTransportType() const;
185 
187  virtual bool MatchesSDP(
188  const PCaselessString & sdpMediaType,
189  const PCaselessString & sdpTransport,
190  const PStringArray & sdpLines,
191  PINDEX index
192  );
193 
195  virtual SDPMediaDescription * CreateSDPMediaDescription(
196  const OpalTransportAddress & localAddress
197  ) const;
198 #endif // OPAL_SDP
199 
200  protected:
202  PCaselessString m_mediaSessionType;
204  OpalMediaType::AutoStartMode m_autoStart;
205 
206  private:
207  P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned), NULL);
208 };
209 
210 
212 //
213 // define a macro for declaring a new OpalMediaTypeDefinition factory
214 //
215 
216 #define OPAL_INSTANTIATE_MEDIATYPE2(cls, name) \
217  PFACTORY_CREATE(OpalMediaTypesFactory, cls, name, true)
218 
219 #define OPAL_INSTANTIATE_MEDIATYPE(cls) \
220  OPAL_INSTANTIATE_MEDIATYPE2(cls, cls::Name())
221 
222 #define OPAL_MEDIATYPE(clsBase) \
223  OPAL_INSTANTIATE_MEDIATYPE2(clsBase##Definition, clsBase##Definition::Name()); \
224  const OpalMediaType & clsBase##Type() { static OpalMediaType t(clsBase##Definition::Name()); return t; }
225 
226 
227 template <const char * Type, unsigned SessionId = 0>
229 {
230  public:
231  static const char * Name() { return Type; }
232 
234  : OpalMediaTypeDefinition(Name(), PString::Empty(), SessionId)
235  { }
236 };
237 
238 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(cls, name, ...) \
239  namespace OpalMediaTypeSpace { extern const char cls[] = name; }; \
240  typedef SimpleMediaType<OpalMediaTypeSpace::cls, ##__VA_ARGS__> cls; \
241  OPAL_INSTANTIATE_MEDIATYPE(cls) \
242 
243 
245 //
246 // common ancestor for audio and video OpalMediaTypeDefinitions
247 //
248 
250 {
251  public:
253  const char * mediaType,
254  unsigned defaultSessionId = 0,
255  OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
256  );
257 
258 #if OPAL_SDP
259  virtual bool MatchesSDP(const PCaselessString &, const PCaselessString &, const PStringArray &, PINDEX);
260 #endif
261 };
262 
263 
265 {
266  public:
267  static const char * Name();
268 
270 
271 #if OPAL_SDP
272  SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &) const;
273 #endif
274 };
275 
276 
277 #if OPAL_VIDEO
278 
280 {
281  public:
282  static const char * Name();
283 
285 
286 #if OPAL_SDP
287  SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &) const;
288 #endif
289 
290  protected:
291  OpalVideoMediaDefinition(const char * mediaType, unsigned defaultSessionId);
292 };
293 
295 {
296  public:
297  static const char * Name();
298 
299  OpalPresentationVideoMediaDefinition(const char * mediaType = Name());
300 };
301 #endif // OPAL_VIDEO
302 
303 
304 #if OPAL_T38_CAPABILITY
305 
306 class OpalFaxMediaDefinition : public OpalMediaTypeDefinition
307 {
308  public:
309  static const char * Name();
310  static const PCaselessString & UDPTL();
311 
312  OpalFaxMediaDefinition();
313 
314 #if OPAL_SDP
315  virtual PString GetSDPMediaType() const;
316  virtual PString GetSDPTransportType() const;
317 
318  SDPMediaDescription * CreateSDPMediaDescription(
319  const OpalTransportAddress & localAddress
320  ) const;
321 #endif // OPAL_SDP
322 };
323 
324 #endif // OPAL_T38_CAPABILITY
325 
326 
327 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
328 
329 
330 #endif // OPAL_OPAL_MEDIATYPE_H
OpalMediaType(const std::string &str)
Definition: mediatype.h:75
unsigned GetDefaultSessionId() const
Definition: mediatype.h:176
OpalMediaType()
Definition: mediatype.h:69
Definition: mediasession.h:647
OpalMediaType(const char *str)
Definition: mediatype.h:78
OpalPresentationVideoMediaDefinition(const char *mediaType=Name())
OpalMediaTypeDefinition * operator->() const
Definition: mediatype.h:93
OpalRTPAVPMediaDefinition(const char *mediaType, unsigned defaultSessionId=0, OpalMediaType::AutoStartMode autoStart=OpalMediaType::DontOffer)
bool Add(const PString &stringOption)
static const OpalMediaType & Video()
Definition: mediatype.h:66
void SetAutoStart(OpalMediaType::AutoStartMode v)
Definition: mediatype.h:171
static const char * Name()
static const OpalMediaType & UserInput()
SimpleMediaType()
Definition: mediatype.h:233
const OpalMediaType & GetMediaType() const
Definition: mediatype.h:163
PCaselessString m_mediaSessionType
Definition: mediatype.h:202
static OpalMediaTypeList GetList()
AutoStartMode GetAutoStart() const
Definition: mediatype.h:327
OpalMediaTypeDefinition(const char *mediaType, const char *mediaSession, unsigned defaultSessionId=0, OpalMediaType::AutoStartMode autoStart=OpalMediaType::DontOffer)
Create a new media type definition.
Definition: mediatype.h:264
Definition: mediatype.h:50
OpalMediaType::AutoStartMode GetAutoStart(const OpalMediaType &mediaType) const
Definition: mediatype.h:279
void PrioritiseAudioVideo()
OpalMediaTypeList(const OpalMediaTypesFactory::KeyList_T &list)
Definition: mediatype.h:55
OpalMediaTypeList()
Definition: mediatype.h:53
static const OpalMediaType & Audio()
OpalMediaTypeDefinition * GetDefinition() const
Definition: mediatype.h:249
const PCaselessString & GetMediaSessionType() const
Definition: mediatype.h:180
ostream & operator<<(ostream &strm, OpalSilenceDetector::Mode mode)
PFactory< OpalMediaTypeDefinition, OpalMediaType > OpalMediaTypesFactory
Definition: mediatype.h:48
Definition: mediatype.h:109
Definition: mediatype.h:228
P_DECLARE_BITWISE_ENUM_EX(AutoStartMode, 3,(OfferInactive, Receive, Transmit, DontOffer), ReceiveTransmit=Receive|Transmit, TransmitReceive=Receive|Transmit)
OpalMediaType(const PString &str)
Definition: mediatype.h:81
Definition: connection.h:415
static const char * Name()
Definition: mediatype.h:231
virtual ~OpalMediaTypeDefinition()
OpalMediaType::AutoStartMode m_autoStart
Definition: mediatype.h:204
OpalMediaType::AutoStartMode GetAutoStart() const
Definition: mediatype.h:167
Definition: transports.h:151
unsigned m_defaultSessionId
Definition: mediatype.h:203
Definition: mediatype.h:147
Definition: mediatype.h:294
virtual ~OpalMediaType()
Definition: mediatype.h:72
static const char * Name()
virtual void PrintOn(ostream &strm) const
OpalMediaType m_mediaType
Definition: mediatype.h:201