sipXtapi home page


SdpCodec.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2017 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2008 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2007 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 #ifndef _SdpCodec_h_
14 #define _SdpCodec_h_
15 
16 // SYSTEM INCLUDES
17 //#include <...>
18 
19 // APPLICATION INCLUDES
20 #include <utl/UtlInt.h>
21 #include <utl/UtlString.h>
22 
23 
24 // DEFINES
25 
26 // Mime major types
27 #define MIME_TYPE_AUDIO "audio"
28 #define MIME_TYPE_VIDEO "video"
29 #define MIME_TYPE_APPLICATION "application"
30 
31 // Mime Sub types
32 #define MIME_SUBTYPE_PCMU "PCMU"
33 #define MIME_SUBTYPE_PCMA "PCMA"
34 #define MIME_SUBTYPE_G729A "G729"
35 #define MIME_SUBTYPE_G729AB "G729"
36 #define MIME_SUBTYPE_G729ACISCO7960 "G729a"
37 #define MIME_SUBTYPE_G723 "G723"
38 #define MIME_SUBTYPE_G726_16 "G726-16"
39 #define MIME_SUBTYPE_G726_24 "G726-24"
40 #define MIME_SUBTYPE_G726_32 "G726-32"
41 #define MIME_SUBTYPE_G726_40 "G726-40"
42 #define MIME_SUBTYPE_G722 "G722"
43 #define MIME_SUBTYPE_G7221 "G7221"
44 #define MIME_SUBTYPE_DTMF_TONES "telephone-event"
45 #define MIME_SUBTYPE_IPCMU "EG711U"
46 #define MIME_SUBTYPE_IPCMA "EG711A"
47 #define MIME_SUBTYPE_IPCMWB "IPCMWB"
48 #define MIME_SUBTYPE_ILBC "iLBC"
49 #define MIME_SUBTYPE_ISAC "ISAC"
50 #define MIME_SUBTYPE_GSM "GSM"
51 #define MIME_SUBTYPE_GSM_WAVE "GSM_WAVE"
52 #define MIME_SUBTYPE_OPUS "opus"
53 #define MIME_SUBTYPE_SPEEX "speex"
54 #define MIME_SUBTYPE_AMR "amr"
55 #define MIME_SUBTYPE_AMRWB "amr-wb"
56 #define MIME_SUBTYPE_AAC_LC "aac_lc"
57 #define MIME_SUBTYPE_MPEG4_GENERIC "mpeg4-generic"
58 #define MIME_SUBTYPE_VP71 "VP71"
59 #define MIME_SUBTYPE_IYUV "IYUV"
60 #define MIME_SUBTYPE_I420 "I420"
61 #define MIME_SUBTYPE_RGB24 "RGB24"
62 #define MIME_SUBTYPE_H263 "H263"
63 #define MIME_SUBTYPE_H263_1998 "H263-1998"
64 #define MIME_SUBTYPE_H264 "H264"
65 
66 // Canonical internal case represation
67 #define SDP_MIME_TO_CASE toLower
68 #define SDP_MIME_SUBTYPE_TO_CASE toUpper
69 
70 // Bandwidth requirements for SDP Codecs
71 #define SDP_CODEC_BANDWIDTH_VARIABLE 0
72 #define SDP_CODEC_BANDWIDTH_LOW 1
73 #define SDP_CODEC_BANDWIDTH_NORMAL 2
74 #define SDP_CODEC_BANDWIDTH_HIGH 3
75 #define SDP_CODEC_BANDWIDTH_VERY_HIGH 4
76 
77 // Video formats - must be bitmap values
78 #define SDP_VIDEO_FORMAT_SQCIF 0x0001
79 #define SDP_VIDEO_FORMAT_QCIF 0x0002
80 #define SDP_VIDEO_FORMAT_CIF 0x0004
81 #define SDP_VIDEO_FORMAT_QVGA 0x0008
82 #define SDP_VIDEO_FORMAT_VGA 0x0010
83 #define SDP_VIDEO_FORMAT_NTSC 0x0020
84 #define SDP_VIDEO_FORMAT_4CIF 0x0040
85 #define SDP_VIDEO_FORMAT_EDTV 0x0080
86 #define SDP_VIDEO_FORMAT_QHD 0x0100
87 #define SDP_VIDEO_FORMAT_HD720 0x0200
88 #define SDP_VIDEO_FORMAT_16CIF 0x0400
89 #define SDP_VIDEO_FORMAT_HD1088 0x0800
90 
91 // MACROS
92 // EXTERNAL FUNCTIONS
93 // EXTERNAL VARIABLES
94 // CONSTANTS
95 // STRUCTS
96 // TYPEDEFS
97 // FORWARD DECLARATIONS
98 
100 
123 class SdpCodec : public UtlInt
124 {
125 /* //////////////////////////// PUBLIC //////////////////////////////////// */
126 public:
127 
129 
134  {
146 
160 
201 
203 
209 
211 
215  SDP_CODEC_VP71_QVGA, // (ENUM 150)
232  SDP_CODEC_H264, // (enum 166)
252  };
253 
254 
257  {
261  };
262 
263 
264 /* ============================ CREATORS ================================== */
266 
267 
269  SdpCodec(enum SdpCodecTypes sdpCodecType = SDP_CODEC_UNKNOWN,
270  int payloadFormat = -1,
271  const char* mimeType = MIME_TYPE_AUDIO,
272  const char* mimeSubtype = "",
273  int sampleRate = 8000,
274  int preferredPacketLength = 20000,
275  int numChannels = 1,
276  const char* formatSpecificData = "",
277  const SdpCodecCPUCost CPUCost = SDP_CODEC_CPU_LOW,
278  const int BWCost = SDP_CODEC_BANDWIDTH_NORMAL,
279  const int videoFormat = SDP_VIDEO_FORMAT_QCIF,
280  const int videoFmtp = 0);
281 
282  SdpCodec(int payloadFormat,
283  const char* mimeType,
284  const char* mimeSubType,
285  int sampleRate,
286  int preferredPacketLength,
287  int numChannels,
288  const char* formatSpecificData);
289 
291  SdpCodec(const SdpCodec& rSdpCodec);
292 
294  virtual
295  ~SdpCodec();
296 
298 
299 /* ============================ MANIPULATORS ============================== */
301 
302 
304  SdpCodec& operator=(const SdpCodec& rhs);
305 
306  UtlCopyableContainable* clone() const { return new SdpCodec(*this); }
307 
309  void setCodecPayloadFormat(int formatId);
310 
312  void setVideoFmtp(const int videoFmtp);
313 
315  void setVideoFmtpString(int videoFmtp);
316 
318  void clearVideoFmtpString();
319 
321  void setPacketSize(const int packetSize);
322 
324 
325 /* ============================ ACCESSORS ================================= */
327 
328 
330  enum SdpCodecTypes getCodecType() const;
336  int getCodecPayloadFormat() const;
342  virtual void getSdpFmtpField(UtlString& formatSpecificData) const;
349  virtual void setSdpFmtpField(const UtlString& formatSpecificData);
356  virtual UtlBoolean getFmtpParameter(const UtlString& parameterName, UtlString& parameterValue, char nameValueSeperator = '=') const;
358 
360  static UtlBoolean getFmtpParameter(const UtlString& fmtpField, const UtlString& parameterName, UtlString& parameterValue, char nameValueSeperator = '=');
366  static UtlBoolean getFmtpParameter(const UtlString& fmtpField, const UtlString& parameterName, int& parameterValue,
368  char nameValueSeperator = '=');
374  static OsStatus getVideoSizes(const UtlString& fmtpField, int maxSizes, int& numSizes, int videoSizes[]);
381  void getMediaType(UtlString& mimeMajorType) const;
387  void getEncodingName(UtlString& mimeSubtype) const;
395  int getSampleRate() const;
397 
399  int getVideoFormat() const;
400 
402  int getNumChannels() const;
403 
405  int getPacketLength() const;
412  void toString(UtlString& sdpCodecContents) const;
414 
416  SdpCodecCPUCost getCPUCost() const;
421  int getBWCost() const;
428  int getVideoFmtp() const;
430 
432  void getVideoFmtpString(UtlString& fmtpString) const;
433 
435 
436 /* ============================ INQUIRY =================================== */
438 
439 
441  UtlBoolean isSameDefinition(const SdpCodec& codec) const;
446  UtlBoolean isFmtpParameterSame(const SdpCodec& codec, const UtlString& fmtpParameterName, const UtlString& fmtpParameterDefaultValue, const char nameValueSeperater = '=') const;
448  /*
449  * @param codec - codec to compare fmpt parameter with this codec's
450  * @param fmtpParameterName - name of the parameter in the fmtp to compare
451  * @param fmtpParameterDefaultValue - default value of the parameter to assume if it is not set
452  */
453 
455  UtlBoolean isFmtpParameterSame(const UtlString& fmtp, const UtlString& fmtpParameterName, const UtlString& fmtpParameterDefaultValue, const char nameValueSeperater = '=') const;
456  /*
457  * @param fmpt = SDP fmpt field value string containing zero or more parameters and values
458  * @param fmtpParameterName - name of the parameter in the fmtp to compare
459  * @param fmtpParameterDefaultValue - default value of the parameter to assume if it is not set
460  */
461 
462  static UtlBoolean isFmtpParameterSame(const UtlString& fmtp1, const UtlString& fmtp2, const UtlString& fmtpParameterName, const UtlString& fmtpParameterDefaultValue, const char nameValueSeperater = '=');
463 
464  // Check fmtp parameters for specific mime type to see if they are equivalent
465  UtlBoolean compareFmtp(const SdpCodec& codec, int& compares) const;
472  // Check fmtp parameters for specific mime type to see if they are equivalent
473  UtlBoolean compareFmtp(const UtlString& fmtp, int& compares) const;
482  // Check fmtp parameters for specific mime type to see if they are equivalent
483  static UtlBoolean compareFmtp(const UtlString& mimeType, const UtlString& mimeSubtype, const UtlString& fmpt1, const UtlString& fmtp2, int& compares);
495 
496 /* //////////////////////////// PROTECTED ///////////////////////////////// */
497 protected:
498 
499 /* //////////////////////////// PRIVATE /////////////////////////////////// */
500 private:
501 
502 // enum SdpCodecTypes mCodecType; ///< Internal id
504  UtlString mMimeType;
505  UtlString mMimeSubtype;
511  int mBWCost;
514  UtlString mVideoFmtpString;
515 
516 };
517 
518 /* ============================ INLINE METHODS ============================ */
519 
520 #endif // _SdpCodec_h_
Internet Low Bit Rate Codec, 20ms (RFC3951)
Definition: SdpCodec.h:162
SdpCodecTypes
Unique identifier used for each supported codec.
Definition: SdpCodec.h:133
Speex WB 42,200bps.
Definition: SdpCodec.h:155
Speex NB, 24,600bps.
Definition: SdpCodec.h:151
Speex WB 5,750bps.
Definition: SdpCodec.h:153
void getMediaType(UtlString &mimeMajorType) const
Assumes the "a=fmtp:<payloadType>" of the fmtp field has be stripped off "a=fmtp:<payloadType> <fmtpd...
Definition: SdpCodec.cpp:868
PCM 16 bit/sample 32000 samples/sec mono.
Definition: SdpCodec.h:187
Definition: SdpCodec.h:259
Speex NB, 8,000bps.
Definition: SdpCodec.h:148
virtual void setSdpFmtpField(const UtlString &formatSpecificData)
Set the format specific parameters for the SDP.
Definition: SdpCodec.cpp:863
virtual ~SdpCodec()
Destructor.
Definition: SdpCodec.cpp:574
#define SDP_CODEC_BANDWIDTH_NORMAL
Definition: SdpCodec.h:73
Definition: SdpCodec.h:205
int getPacketLength() const
Get the preferred packet size in micro seconds.
Definition: SdpCodec.cpp:888
int getVideoFormat() const
Return the video format.
Definition: SdpCodec.cpp:883
PCM 16 bit/sample 44100 samples/sec.
Definition: SdpCodec.h:141
int getSampleRate() const
Get the number of samples per second.
Definition: SdpCodec.cpp:878
Definition: SdpCodec.h:231
PCM 16 bit/sample 22050 samples/sec mono. (enum 125)
Definition: SdpCodec.h:183
#define SDP_VIDEO_FORMAT_QCIF
Definition: SdpCodec.h:79
Definition: SdpCodec.h:232
PCM 16 bit/sample 22050 samples/sec stereo.
Definition: SdpCodec.h:182
H.263 video codec.
Definition: SdpCodec.h:144
PCM 16 bit/sample 11025 samples/sec stereo.
Definition: SdpCodec.h:178
int mNumChannels
Definition: SdpCodec.h:508
void setVideoFmtpString(int videoFmtp)
Set the video format string.
Definition: SdpCodec.cpp:614
G.729A.
Definition: SdpCodec.h:164
Definition: SdpCodec.h:258
Definition: SdpCodec.h:239
Definition: SdpCodec.h:224
Definition: SdpCodec.h:227
Container for SDP/RTP codec specification.
Definition: SdpCodec.h:123
enum SdpCodecTypes getCodecType() const
Get the internal/sipX codec type id.
Definition: SdpCodec.cpp:649
Definition: SdpCodec.h:245
AMR-WB Octet Aligned mode.
Definition: SdpCodec.h:175
void setPacketSize(const int packetSize)
Set the packet size.
Definition: SdpCodec.cpp:642
Siren/G.722.1 Annex C (32k sps) 24Kb.
Definition: SdpCodec.h:168
int getVideoFmtp() const
Get the video format bitmap.
Definition: SdpCodec.cpp:898
Definition: SdpCodec.h:238
Definition: SdpCodec.h:194
Definition: SdpCodec.h:220
UtlCopyableContainable * clone() const
Definition: SdpCodec.h:306
int mVideoFormat
Definition: SdpCodec.h:512
PCM 16 bit/sample 16000 samples/sec mono.
Definition: SdpCodec.h:181
Definition: SdpCodec.h:229
#define MIME_TYPE_AUDIO
Definition: SdpCodec.h:27
PCM 16 bit/sample 16000 samples/sec stereo.
Definition: SdpCodec.h:180
Definition: SdpCodec.h:225
AMR-WB Bandwidth Efficient mode.
Definition: SdpCodec.h:174
virtual void getSdpFmtpField(UtlString &formatSpecificData) const
Get the format specific parameters for the SDP.
Definition: SdpCodec.cpp:659
Definition: SdpCodec.h:248
Definition: SdpCodec.h:230
int mCodecPayloadFormat
Definition: SdpCodec.h:503
PCM 16 bit/sample 8000 samples/sec mono.
Definition: SdpCodec.h:177
Definition: SdpCodec.h:214
virtual UtlBoolean getFmtpParameter(const UtlString &parameterName, UtlString &parameterValue, char nameValueSeperator= '=') const
Get the named parameter in the format field (fmtp parameter)
Definition: SdpCodec.cpp:664
UtlString mMimeSubtype
a=rtpmap mime subtype value
Definition: SdpCodec.h:505
Definition: SdpCodec.h:191
Payload types for codecs below < will be assigned dynamically.
Definition: SdpCodec.h:145
Definition: SdpCodec.h:213
Definition: SdpCodec.h:228
Definition: SdpCodec.h:234
Definition: SdpCodec.h:218
void toString(UtlString &sdpCodecContents) const
Get a string dump of this codecs definition.
Definition: SdpCodec.cpp:908
Definition: SdpCodec.h:196
AMR Octet Aligned mode.
Definition: SdpCodec.h:173
G.723.1.
Definition: SdpCodec.h:171
G.729A.
Definition: SdpCodec.h:190
Definition: SdpCodec.h:233
Siren/G.722.1 Annex C (32k sps) 32Kb.
Definition: SdpCodec.h:169
Definition: SdpCodec.h:192
Definition: SdpCodec.h:195
PCM 16 bit/sample 48000 samples/sec mono.
Definition: SdpCodec.h:189
Definition: SdpCodec.h:236
UtlBoolean compareFmtp(const SdpCodec &codec, int &compares) const
Definition: SdpCodec.cpp:959
AVT/DTMF Tones, RFC 2833.
Definition: SdpCodec.h:163
int mSampleRate
samples per second
Definition: SdpCodec.h:506
Siren.
Definition: SdpCodec.h:165
G.729, with or without Annexes A or B.
Definition: SdpCodec.h:143
int getNumChannels() const
Get the number of channels.
Definition: SdpCodec.cpp:893
Siren/G.722.1 (16k sps) 32Kb.
Definition: SdpCodec.h:167
Speex UWB 11,600bps.
Definition: SdpCodec.h:156
Definition: SdpCodec.h:217
Definition: SdpCodec.h:223
void setVideoFmtp(const int videoFmtp)
Set the video format bitmap.
Definition: SdpCodec.cpp:609
Video codecs.
Definition: SdpCodec.h:212
G.722.
Definition: SdpCodec.h:140
Speex NB, 5,950bps.
Definition: SdpCodec.h:149
void getEncodingName(UtlString &mimeSubtype) const
MimeSubtype used as encoding name.
Definition: SdpCodec.cpp:873
void getVideoFmtpString(UtlString &fmtpString) const
Get the video format string.
Definition: SdpCodec.cpp:903
int mVideoFmtp
Definition: SdpCodec.h:513
int getBWCost() const
Get the bandwidth cost for this codec.
Definition: SdpCodec.cpp:926
int getCodecPayloadFormat() const
Get the SDP/RTP payload id to be used for this codec.
Definition: SdpCodec.cpp:654
Speex UWB 7,550bps.
Definition: SdpCodec.h:157
Default OPUS VoIP codec upto 48000 samples/sec.
Definition: SdpCodec.h:200
PCM 16 bit/sample 11025 samples/sec mono.
Definition: SdpCodec.h:179
SdpCodec & operator=(const SdpCodec &rhs)
Assignment operator.
Definition: SdpCodec.cpp:582
PCM 16 bit/sample 8000 samples/sec stereo.
Definition: SdpCodec.h:176
Definition: SdpCodec.h:260
Definition: SdpCodec.h:246
Speex WB 9,800bps (enum 100)
Definition: SdpCodec.h:152
Internet Low Bit Rate Codec, 30ms (RFC3951)
Definition: SdpCodec.h:161
UtlString mFormatSpecificData
a=fmtp parameter
Definition: SdpCodec.h:509
Definition: SdpCodec.h:221
PCM 16 bit/sample 24000 samples/sec mono.
Definition: SdpCodec.h:185
Definition: SdpCodec.h:216
Definition: SdpCodec.h:240
Definition: SdpCodec.h:193
PCM 16 bit/sample 24000 samples/sec stereo.
Definition: SdpCodec.h:184
PCM 16 bit/sample 48000 samples/sec stereo.
Definition: SdpCodec.h:188
Siren/G.722.1 (16k sps) 24Kb.
Definition: SdpCodec.h:166
Definition: SdpCodec.h:222
PCM 16 bit/sample 44100 samples/sec.
Definition: SdpCodec.h:142
void setCodecPayloadFormat(int formatId)
Set the SDP/RTP payload id to be used for this codec.
Definition: SdpCodec.cpp:604
UtlBoolean isFmtpParameterSame(const SdpCodec &codec, const UtlString &fmtpParameterName, const UtlString &fmtpParameterDefaultValue, const char nameValueSeperater= '=') const
Returns TRUE if the named fmtp parameters are the same in this and the given codec.
Definition: SdpCodec.cpp:1193
Definition: SdpCodec.h:215
SdpCodecCPUCost
Identifies the relative CPU cost for a SDP Codec.
Definition: SdpCodec.h:256
Definition: SdpCodec.h:207
Speex WB 20,600bps.
Definition: SdpCodec.h:154
UtlString mMimeType
audio, video, etc.
Definition: SdpCodec.h:504
AMR Bandwidth Efficient mode.
Definition: SdpCodec.h:172
Definition: SdpCodec.h:243
Definition: SdpCodec.h:241
void clearVideoFmtpString()
Clears the format string.
Definition: SdpCodec.cpp:637
Speex UWB 44,000bps.
Definition: SdpCodec.h:159
GIPS specific codecs.
Definition: SdpCodec.h:204
Definition: SdpCodec.h:226
Definition: SdpCodec.h:237
Speex NB, 15,000bps.
Definition: SdpCodec.h:150
SdpCodec(enum SdpCodecTypes sdpCodecType=SDP_CODEC_UNKNOWN, int payloadFormat=-1, const char *mimeType=MIME_TYPE_AUDIO, const char *mimeSubtype="", int sampleRate=8000, int preferredPacketLength=20000, int numChannels=1, const char *formatSpecificData="", const SdpCodecCPUCost CPUCost=SDP_CODEC_CPU_LOW, const int BWCost=SDP_CODEC_BANDWIDTH_NORMAL, const int videoFormat=SDP_VIDEO_FORMAT_QCIF, const int videoFmtp=0)
Default constructor.
Definition: SdpCodec.cpp:46
Definition: SdpCodec.h:244
PCM 16 bit/sample 32000 samples/sec stereo.
Definition: SdpCodec.h:186
Definition: SdpCodec.h:135
UtlBoolean isSameDefinition(const SdpCodec &codec) const
Returns TRUE if this codec is the same definition as the given codec.
Definition: SdpCodec.cpp:933
Definition: SdpCodec.h:247
int mBWCost
Definition: SdpCodec.h:511
G.711 mu-law.
Definition: SdpCodec.h:136
Definition: SdpCodec.h:235
Speex UWB 22,400bps.
Definition: SdpCodec.h:158
Definition: SdpCodec.h:242
GSM codec.
Definition: SdpCodec.h:137
Definition: SdpCodec.h:219
G.711 a-law.
Definition: SdpCodec.h:139
Definition: SdpCodec.h:206
G.723.
Definition: SdpCodec.h:138
UtlString mVideoFmtpString
video format string
Definition: SdpCodec.h:514
int mPacketLength
micro seconds
Definition: SdpCodec.h:507
SdpCodecCPUCost getCPUCost() const
Get the CPU cost for this codec.
Definition: SdpCodec.cpp:920
Siren/G.722.1 Annex C (32k sps) 48Kb.
Definition: SdpCodec.h:170
static OsStatus getVideoSizes(const UtlString &fmtpField, int maxSizes, int &numSizes, int videoSizes[])
Assumes the "a=fmtp:<payloadType>" of the fmtp field has be stripped off "a=fmtp:<payloadType> <fmtpd...
Definition: SdpCodec.cpp:714
SdpCodecCPUCost mCPUCost
relative cost of a SDP codec
Definition: SdpCodec.h:510