OPAL
Version 3.10.10
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
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: 26521 $
27
* $Author: rjongbloed $
28
* $Date: 2011-10-04 23:57:06 -0500 (Tue, 04 Oct 2011) $
29
*/
30
31
#ifndef OPAL_OPAL_MEDIATYPE_H
32
#define OPAL_OPAL_MEDIATYPE_H
33
34
#include <ptbuildopts.h>
35
#include <ptlib/pfactory.h>
36
#include <
opal/buildopts.h
>
37
38
#ifdef P_USE_PRAGMA
39
#pragma interface
40
#endif
41
42
43
class
OpalMediaTypeDefinition
;
44
class
OpalSecurityMode
;
45
class
OpalConnection
;
46
48
//
49
// define the factory used for keeping track of OpalMediaTypeDefintions
50
//
51
typedef
PFactory<OpalMediaTypeDefinition>
OpalMediaTypeFactory
;
52
typedef
OpalMediaTypeFactory::KeyList_T
OpalMediaTypeList
;
53
54
57
class
OpalMediaType
:
public
std::string
// do not make this PCaselessString as that type does not work as index for std::map etc
58
{
59
public
:
60
OpalMediaType
()
61
{ }
62
63
virtual
~OpalMediaType
()
64
{ }
65
66
OpalMediaType
(
const
std::string & str)
67
: std::string(str) { }
68
69
OpalMediaType
(
const
char
* str)
70
: std::string(str) { }
71
72
OpalMediaType
(
const
PString & str)
73
: std::string((const char *)str) { }
74
75
static
const
OpalMediaType
&
Audio
();
76
static
const
OpalMediaType
&
Video
();
77
static
const
OpalMediaType
&
Fax
();
78
static
const
OpalMediaType
&
UserInput
();
79
80
OpalMediaTypeDefinition
*
GetDefinition
()
const
;
81
static
OpalMediaTypeDefinition
*
GetDefinition
(
const
OpalMediaType
& key);
82
static
OpalMediaTypeDefinition
*
GetDefinition
(
unsigned
sessionId);
83
84
static
OpalMediaTypeFactory::KeyList_T
GetList
() {
return
OpalMediaTypeFactory::GetKeyList(); }
85
86
#if OPAL_SIP
87
static
OpalMediaType
GetMediaTypeFromSDP
(
const
std::string & key,
const
std::string & transport);
88
#endif // OPAL_SIP
89
90
enum
AutoStartMode
{
91
// Do not change order of enum as useful for bitmasking rx/tx
92
OfferInactive
,
93
Receive
,
94
Transmit
,
95
ReceiveTransmit
,
96
DontOffer
,
97
98
TransmitReceive
=
ReceiveTransmit
99
};
100
101
__inline
friend
AutoStartMode
operator++
(
AutoStartMode
& mode) {
return
(mode = (
AutoStartMode
)(mode+1)); }
102
__inline
friend
AutoStartMode
operator--
(
AutoStartMode
& mode) {
return
(mode = (
AutoStartMode
)(mode-1)); }
103
__inline
friend
AutoStartMode
operator|=
(
AutoStartMode
& m1,
AutoStartMode
m2) {
return
(m1 = (
AutoStartMode
)((m1 & ~
DontOffer
) | m2)); }
104
__inline
friend
AutoStartMode
operator-=
(
AutoStartMode
& m1,
AutoStartMode
m2) {
return
(m1 = (
AutoStartMode
)((
int
)m1 & ~((
int
)m2|
DontOffer
))); }
105
106
AutoStartMode
GetAutoStart
()
const
;
107
};
108
109
110
__inline ostream &
operator <<
(ostream & strm,
const
OpalMediaType
& mediaType)
111
{
112
return
strm << mediaType.c_str();
113
}
114
115
117
//
118
// this class defines the functions needed to work with the media type, i.e.
119
//
120
class
OpalRTPConnection
;
121
class
RTP_UDP
;
122
123
#if OPAL_SIP
124
class
SDPMediaDescription
;
125
class
OpalTransportAddress
;
126
#endif
127
128
class
OpalMediaSession
;
129
132
class
OpalMediaTypeDefinition
133
{
134
public
:
136
OpalMediaTypeDefinition
(
137
const
char
* mediaType,
138
const
char
* sdpType,
139
unsigned
requiredSessionId = 0,
140
OpalMediaType::AutoStartMode
autoStart =
OpalMediaType::DontOffer
141
);
142
143
// Needed to avoid gcc warning about classes with virtual functions and
144
// without a virtual destructor
145
virtual
~OpalMediaTypeDefinition
();
146
149
OpalMediaType::AutoStartMode
GetAutoStart
()
const
{
return
m_autoStart
; }
150
153
void
SetAutoStart
(
OpalMediaType::AutoStartMode
v) {
m_autoStart
= v; }
154
void
SetAutoStart
(
OpalMediaType::AutoStartMode
v,
bool
on) {
if
(on)
m_autoStart
|= v;
else
m_autoStart
-= v; }
155
159
virtual
bool
UsesRTP
()
const
{
return
true
; }
160
163
virtual
OpalMediaSession
*
CreateMediaSession
(
164
OpalConnection
& connection,
165
unsigned
sessionID
166
)
const
;
167
174
virtual
PString
GetRTPEncoding
()
const
= 0;
175
181
virtual
RTP_UDP
*
CreateRTPSession
(
182
OpalRTPConnection
& conn,
183
unsigned
sessionID,
184
bool
remoteIsNAT
185
);
186
189
unsigned
GetDefaultSessionId
()
const
{
return
m_defaultSessionId
; }
190
191
protected
:
192
std::string
m_mediaType
;
193
unsigned
m_defaultSessionId
;
194
OpalMediaType::AutoStartMode
m_autoStart
;
195
196
#if OPAL_SIP
197
public
:
198
//
199
// return the SDP type for this media type
200
//
201
virtual
std::string
GetSDPType
()
const
202
{
return
m_sdpType
; }
203
204
//
205
// create an SDP media description entry for this media type
206
//
207
virtual
SDPMediaDescription
*
CreateSDPMediaDescription
(
208
const
OpalTransportAddress
& localAddress
209
) = 0;
210
211
protected
:
212
std::string
m_sdpType
;
213
#endif
214
};
215
216
218
//
219
// define a macro for declaring a new OpalMediaTypeDefinition factory
220
//
221
222
#define OPAL_INSTANTIATE_MEDIATYPE2(title, name, cls) \
223
namespace OpalMediaTypeSpace { \
224
static PFactory<OpalMediaTypeDefinition>::Worker<cls> static_##title##_##cls(name, true); \
225
}; \
226
227
#define OPAL_INSTANTIATE_MEDIATYPE(type, cls) \
228
OPAL_INSTANTIATE_MEDIATYPE2(type, #type, cls) \
229
230
231
#ifdef SOLARIS
232
template
<
char
* Type,
char
* sdp>
233
#else
234
template
<
char
* Type, const
char
* sdp>
235
#endif
236
class
SimpleMediaType
:
public
OpalMediaTypeDefinition
237
{
238
public
:
239
SimpleMediaType
()
240
:
OpalMediaTypeDefinition
(Type, sdp, 0)
241
{ }
242
243
virtual
~SimpleMediaType
() { }
244
245
virtual
RTP_UDP
*
CreateRTPSession
(
OpalRTPConnection
& ,
unsigned
,
bool
) {
return
NULL; }
246
247
PString
GetRTPEncoding
()
const
{
return
PString::Empty(); }
248
249
#if OPAL_SIP
250
public
:
251
virtual
SDPMediaDescription
*
CreateSDPMediaDescription
(
const
OpalTransportAddress
& ) {
return
NULL; }
252
#endif
253
};
254
255
256
#define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, sdp) \
257
namespace OpalMediaTypeSpace { \
258
char type##_type_string[] = #type; \
259
char type##_sdp_string[] = #sdp; \
260
typedef SimpleMediaType<type##_type_string, type##_sdp_string> type##_MediaType; \
261
}; \
262
OPAL_INSTANTIATE_MEDIATYPE(type, type##_MediaType) \
263
264
#define OPAL_INSTANTIATE_SIMPLE_MEDIATYPE_NO_SDP(type) OPAL_INSTANTIATE_SIMPLE_MEDIATYPE(type, "")
265
267
//
268
// common ancestor for audio and video OpalMediaTypeDefinitions
269
//
270
271
class
OpalRTPAVPMediaType
:
public
OpalMediaTypeDefinition
{
272
public
:
273
OpalRTPAVPMediaType
(
274
const
char
* mediaType,
275
const
char
* sdpType,
276
unsigned
requiredSessionId = 0,
277
OpalMediaType::AutoStartMode
autoStart =
OpalMediaType::DontOffer
278
);
279
280
virtual
PString
GetRTPEncoding
()
const
;
281
282
OpalMediaSession
*
CreateMediaSession
(
OpalConnection
&
/*conn*/
,
unsigned
/* sessionID*/
)
const
;
283
};
284
285
286
class
OpalAudioMediaType
:
public
OpalRTPAVPMediaType
{
287
public
:
288
OpalAudioMediaType
();
289
290
#if OPAL_SIP
291
SDPMediaDescription
*
CreateSDPMediaDescription
(
const
OpalTransportAddress
& localAddress);
292
#endif
293
};
294
295
296
#if OPAL_VIDEO
297
298
class
OpalVideoMediaType
:
public
OpalRTPAVPMediaType
{
299
public
:
300
OpalVideoMediaType
();
301
302
#if OPAL_SIP
303
SDPMediaDescription
*
CreateSDPMediaDescription
(
const
OpalTransportAddress
& localAddress);
304
#endif
305
};
306
307
#endif // OPAL_VIDEO
308
309
310
#if OPAL_T38_CAPABILITY
311
312
class
OpalFaxMediaType :
public
OpalMediaTypeDefinition
313
{
314
public
:
315
OpalFaxMediaType();
316
317
PString
GetRTPEncoding
(
void
)
const
;
318
RTP_UDP
*
CreateRTPSession
(
OpalRTPConnection
& conn,
319
unsigned
sessionID,
bool
remoteIsNAT);
320
321
OpalMediaSession
*
CreateMediaSession
(
OpalConnection
& conn,
unsigned
/* sessionID*/
)
const
;
322
323
#if OPAL_SIP
324
SDPMediaDescription
*
CreateSDPMediaDescription
(
const
OpalTransportAddress
& localAddress);
325
#endif
326
};
327
328
PFACTORY_LOAD
(T38PseudoRTP_Handler);
329
330
#endif // OPAL_T38_CAPABILITY
331
332
333
__inline
OpalMediaType::AutoStartMode
OpalMediaType::GetAutoStart
()
const
{
return
GetDefinition
()->
GetAutoStart
(); }
334
335
336
#endif // OPAL_OPAL_MEDIATYPE_H
include
opal
mediatype.h
Generated on Fri Sep 13 2013 11:29:26 for OPAL by
1.8.4