OPAL  Version 3.14.3
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  * $Revision: 32436 $
27  * $Author: rjongbloed $
28  * $Date: 2014-08-06 15:30:22 +1000 (Wed, 06 Aug 2014) $
29  */
30 
31 #ifndef OPAL_OPAL_MEDIATYPE_H
32 #define OPAL_OPAL_MEDIATYPE_H
33 
34 #include <opal_config.h>
35 
36 #include <ptlib/pfactory.h>
37 #include <ptlib/bitwise_enum.h>
38 
39 
40 #ifdef P_USE_PRAGMA
41 #pragma interface
42 #endif
43 
44 
46 class OpalConnection;
47 
49 //
50 // define the factory used for keeping track of OpalMediaTypeDefintions
51 //
53 typedef PFactory<OpalMediaTypeDefinition, OpalMediaType> OpalMediaTypesFactory;
54 class OpalMediaTypeList : public OpalMediaTypesFactory::KeyList_T
55 {
56  public:
58 
59  OpalMediaTypeList(const OpalMediaTypesFactory::KeyList_T & list)
60  : OpalMediaTypesFactory::KeyList_T(list) { }
61 
62  void PrioritiseAudioVideo();
63 };
64 
65 
68 class OpalMediaType : public std::string // do not make this PCaselessString as that type does not work as index for std::map etc
69 {
70  public:
72  { }
73 
74  virtual ~OpalMediaType()
75  { }
76 
77  OpalMediaType(const std::string & str)
78  : std::string(str) { }
79 
80  OpalMediaType(const char * str)
81  : std::string(str) { }
82 
83  OpalMediaType(const PString & str)
84  : std::string((const char *)str) { }
85 
86  static const OpalMediaType & Audio();
87 #if OPAL_VIDEO
88  static const OpalMediaType & Video();
89 #endif
90 #if OPAL_T38_CAPABILITY
91  static const OpalMediaType & Fax();
92 #endif
93  static const OpalMediaType & UserInput();
94 
98 
102  static OpalMediaTypeList GetList();
103 
104  P_DECLARE_BITWISE_ENUM_EX(AutoStartMode, 3,
105  (OfferInactive, Receive, Transmit, DontOffer),
106  ReceiveTransmit = Receive|Transmit,
107  TransmitReceive = Receive|Transmit);
108 
109  AutoStartMode GetAutoStart() const;
110 
111  class AutoStartMap : public std::map<OpalMediaType, OpalMediaType::AutoStartMode>
112  {
113  public:
114  AutoStartMap();
115 
116  bool Add(const PString & stringOption);
117  bool Add(const PCaselessString & mediaTypeName, const PCaselessString & modeName);
118 
119  OpalMediaType::AutoStartMode GetAutoStart(const OpalMediaType & mediaType) const;
120 
121  void SetGlobalAutoStart();
122 
123  protected:
124  PMutex m_mutex;
125  };
126 };
127 
128 
129 __inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
130 {
131  return strm << mediaType.c_str();
132 }
133 
134 ostream & operator<<(ostream & strm, OpalMediaType::AutoStartMode mode);
135 
136 
138 //
139 // this class defines the functions needed to work with the media type, i.e.
140 //
141 
142 class SDPMediaDescription;
144 class OpalMediaSession;
145 
146 
150 {
151  public:
154  const char * mediaType,
155  const char * mediaSession,
156  unsigned defaultSessionId = 0,
157  OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
158  );
159 
160  // Needed to avoid gcc warning about classes with virtual functions and
161  // without a virtual destructor
162  virtual ~OpalMediaTypeDefinition();
163 
164  // Get the media type instance
165  const OpalMediaType & GetMediaType() const { return m_mediaType; }
166 
169  OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
170 
173  void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
174  void SetAutoStart(OpalMediaType::AutoStartMode v, bool on);
175 
178  unsigned GetDefaultSessionId() const { return m_defaultSessionId; }
179 
182  const PCaselessString & GetMediaSessionType() const { return m_mediaSessionType; }
183 
184 #if OPAL_SDP
185  virtual PString GetSDPMediaType() const;
186  virtual PString GetSDPTransportType() const;
187 
189  virtual bool MatchesSDP(
190  const PCaselessString & sdpMediaType,
191  const PCaselessString & sdpTransport,
192  const PStringArray & sdpLines,
193  PINDEX index
194  );
195 
197  virtual SDPMediaDescription * CreateSDPMediaDescription(
198  const OpalTransportAddress & localAddress
199  ) const;
200 #endif // OPAL_SDP
201 
202  protected:
204  PCaselessString m_mediaSessionType;
206  OpalMediaType::AutoStartMode m_autoStart;
207 
208  private:
209  P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned), NULL);
210 };
211 
212 
214 //
215 // define a macro for declaring a new OpalMediaTypeDefinition factory
216 //
217 
218 #define OPAL_INSTANTIATE_MEDIATYPE2(cls, name) \
219  PFACTORY_CREATE(OpalMediaTypesFactory, cls, name, true)
220 
221 #define OPAL_INSTANTIATE_MEDIATYPE(cls) \
222  OPAL_INSTANTIATE_MEDIATYPE2(cls, cls::Name())
223 
224 #define OPAL_MEDIATYPE(clsBase) \
225  OPAL_INSTANTIATE_MEDIATYPE2(clsBase##Definition, clsBase##Definition::Name()); \
226  const OpalMediaType & clsBase##Type() { static OpalMediaType t(clsBase##Definition::Name()); return t; }
227 
228 
229 template <const char * Type, unsigned SessionId = 0>
231 {
232  public:
233  static const char * Name() { return Type; }
234 
236  : OpalMediaTypeDefinition(Name(), PString::Empty(), SessionId)
237  { }
238 };
239 
240 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(cls, name, ...) \
241  namespace OpalMediaTypeSpace { extern const char cls[] = name; }; \
242  typedef SimpleMediaType<OpalMediaTypeSpace::cls, ##__VA_ARGS__> cls; \
243  OPAL_INSTANTIATE_MEDIATYPE(cls) \
244 
245 
247 //
248 // common ancestor for audio and video OpalMediaTypeDefinitions
249 //
250 
252 {
253  public:
255  const char * mediaType,
256  unsigned defaultSessionId = 0,
257  OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
258  );
259 
260 #if OPAL_SIP
261  virtual bool MatchesSDP(const PCaselessString &, const PCaselessString &, const PStringArray &, PINDEX);
262 #endif
263 };
264 
265 
267 {
268  public:
269  static const char * Name();
270 
272 
273 #if OPAL_SDP
274  SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &) const;
275 #endif
276 };
277 
278 
279 #if OPAL_VIDEO
280 
282 {
283  public:
284  static const char * Name();
285 
287 
288 #if OPAL_SDP
289  SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &) const;
290 #endif
291 
292  protected:
293  OpalVideoMediaDefinition(const char * mediaType, unsigned defaultSessionId);
294 };
295 
297 {
298  public:
299  static const char * Name();
300 
301  OpalPresentationVideoMediaDefinition(const char * mediaType = Name());
302 };
303 #endif // OPAL_VIDEO
304 
305 
306 #if OPAL_T38_CAPABILITY
307 
308 class OpalFaxMediaDefinition : public OpalMediaTypeDefinition
309 {
310  public:
311  static const char * Name();
312  static const PCaselessString & UDPTL();
313 
314  OpalFaxMediaDefinition();
315 
316 #if OPAL_SDP
317  virtual PString GetSDPMediaType() const;
318  virtual PString GetSDPTransportType() const;
319 
320  SDPMediaDescription * CreateSDPMediaDescription(
321  const OpalTransportAddress & localAddress
322  ) const;
323 #endif // OPAL_SIP
324 };
325 
326 #endif // OPAL_T38_CAPABILITY
327 
328 
329 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
330 
331 
332 #endif // OPAL_OPAL_MEDIATYPE_H