OPAL  Version 3.12.9
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: 28946 $
27  * $Author: rjongbloed $
28  * $Date: 2013-01-19 15:27:47 +1100 (Sat, 19 Jan 2013) $
29  */
30 
31 #ifndef OPAL_OPAL_MEDIATYPE_H
32 #define OPAL_OPAL_MEDIATYPE_H
33 
34 #include <opal/buildopts.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 typedef OpalMediaTypesFactory::KeyList_T OpalMediaTypeList;
55 
56 
59 class OpalMediaType : public std::string // do not make this PCaselessString as that type does not work as index for std::map etc
60 {
61  public:
63  { }
64 
65  virtual ~OpalMediaType()
66  { }
67 
68  OpalMediaType(const std::string & str)
69  : std::string(str) { }
70 
71  OpalMediaType(const char * str)
72  : std::string(str) { }
73 
74  OpalMediaType(const PString & str)
75  : std::string((const char *)str) { }
76 
77  static const OpalMediaType & Audio();
78 #if OPAL_VIDEO
79  static const OpalMediaType & Video();
80 #endif
81 #if OPAL_T38_CAPABILITY
82  static const OpalMediaType & Fax();
83 #endif
84  static const OpalMediaType & UserInput();
85 
89  static OpalMediaTypeDefinition * GetDefinition(unsigned sessionId);
90 
94  static OpalMediaTypeList GetList();
95 
96  P_DECLARE_BITWISE_ENUM_EX(AutoStartMode, 3,
97  (OfferInactive, Receive, Transmit, DontOffer),
98  ReceiveTransmit = Receive|Transmit,
99  TransmitReceive = Receive|Transmit);
100 
101  AutoStartMode GetAutoStart() const;
102 };
103 
104 
105 __inline ostream & operator << (ostream & strm, const OpalMediaType & mediaType)
106 {
107  return strm << mediaType.c_str();
108 }
109 
110 
112 //
113 // this class defines the functions needed to work with the media type, i.e.
114 //
115 
116 class SDPMediaDescription;
118 class OpalMediaSession;
119 
120 
124 {
125  public:
128  const char * mediaType,
129  const char * mediaSession,
130  unsigned requiredSessionId = 0,
131  OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
132  );
133 
134  // Needed to avoid gcc warning about classes with virtual functions and
135  // without a virtual destructor
136  virtual ~OpalMediaTypeDefinition();
137 
140  OpalMediaType::AutoStartMode GetAutoStart() const { return m_autoStart; }
141 
144  void SetAutoStart(OpalMediaType::AutoStartMode v) { m_autoStart = v; }
145  void SetAutoStart(OpalMediaType::AutoStartMode v, bool on) { if (on) m_autoStart |= v; else m_autoStart -= v; }
146 
149  unsigned GetDefaultSessionId() const { return m_defaultSessionId; }
150 
153  const PString & GetMediaSessionType() const { return m_mediaSessionType; }
154 
155 #if OPAL_SIP
156 
157  virtual bool MatchesSDP(
158  const PCaselessString & sdpMediaType,
159  const PCaselessString & sdpTransport,
160  const PStringArray & sdpLines,
161  PINDEX index
162  );
163 
166  const OpalTransportAddress & localAddress
167  ) const;
168 #endif // OPAL_SIP
169 
170  protected:
174  OpalMediaType::AutoStartMode m_autoStart;
175 
176  private:
177  P_REMOVE_VIRTUAL(OpalMediaSession *, CreateMediaSession(OpalConnection &, unsigned), NULL);
178 };
179 
180 
182 //
183 // define a macro for declaring a new OpalMediaTypeDefinition factory
184 //
185 
186 #define OPAL_INSTANTIATE_MEDIATYPE2(cls, name) \
187  PFACTORY_CREATE(OpalMediaTypesFactory, cls, name, true)
188 
189 #define OPAL_INSTANTIATE_MEDIATYPE(cls) \
190  OPAL_INSTANTIATE_MEDIATYPE2(cls, cls::Name())
191 
192 
193 template <const char * Type, unsigned SessionId = 0>
195 {
196  public:
197  static const char * Name() { return Type; }
198 
200  : OpalMediaTypeDefinition(Name(), PString::Empty(), SessionId)
201  { }
202 };
203 
204 #define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(cls, name, ...) \
205  namespace OpalMediaTypeSpace { extern const char cls[] = name; }; \
206  typedef SimpleMediaType<OpalMediaTypeSpace::cls, ##__VA_ARGS__> cls; \
207  OPAL_INSTANTIATE_MEDIATYPE(cls) \
208 
209 
211 //
212 // common ancestor for audio and video OpalMediaTypeDefinitions
213 //
214 
216  public:
218  const char * mediaType,
219  unsigned requiredSessionId = 0,
220  OpalMediaType::AutoStartMode autoStart = OpalMediaType::DontOffer
221  );
222 
223 #if OPAL_SIP
224  virtual bool MatchesSDP(const PCaselessString &, const PCaselessString &, const PStringArray &, PINDEX);
225 #endif
226 };
227 
228 
230  public:
231  static const char * Name();
232 
234 
235 #if OPAL_SIP
237 #endif
238 };
239 
240 
241 #if OPAL_VIDEO
242 
244  public:
245  static const char * Name();
246 
248 
249 #if OPAL_SIP
251 #endif
252 };
253 
254 #endif // OPAL_VIDEO
255 
256 
257 #if OPAL_T38_CAPABILITY
258 
259 class OpalFaxMediaType : public OpalMediaTypeDefinition
260 {
261  public:
262  static const char * Name();
263  static const PCaselessString & UDPTL();
264 
265  OpalFaxMediaType();
266 
267 #if OPAL_SIP
268  static const PCaselessString & GetSDPMediaType();
269  static const PString & GetSDPTransportType();
270 
271  virtual bool MatchesSDP(
272  const PCaselessString & sdpMediaType,
273  const PCaselessString & sdpTransport,
274  const PStringArray & sdpLines,
275  PINDEX index
276  );
277 
279  const OpalTransportAddress & localAddress
280  ) const;
281 #endif // OPAL_SIP
282 };
283 
284 #endif // OPAL_T38_CAPABILITY
285 
286 
287 __inline OpalMediaType::AutoStartMode OpalMediaType::GetAutoStart() const { return GetDefinition()->GetAutoStart(); }
288 
289 
290 #endif // OPAL_OPAL_MEDIATYPE_H