sipxtacklib  Version 3.3
SdpBody.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005-2013 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 // Author: Daniel Petrie (dpetrie AT SIPez DOT com)
13 
14 #ifndef _SdpBody_h_
15 #define _SdpBody_h_
16 
17 // SYSTEM INCLUDES
18 // APPLICATION INCLUDES
19 #include <utl/UtlDefs.h>
20 #include <utl/UtlSListIterator.h>
21 #include <os/OsSocket.h>
22 #include <os/OsNatConnectionSocket.h>
23 #include <tapi/sipXtapiEvents.h>
24 #include <sdp/SdpMediaLine.h>
25 #include <net/HttpBody.h>
26 #include <net/NameValuePair.h>
27 #include <sdp/SdpCodec.h>
28 
29 // DEFINES
30 #define SDP_AUDIO_MEDIA_TYPE "audio"
31 #define SDP_VIDEO_MEDIA_TYPE "video"
32 #define SDP_APPLICATION_MEDIA_TYPE "application"
33 
34 // Crypto suites
35 #define AES_CM_128_HMAC_SHA1_80 1
36 #define AES_CM_128_HMAC_SHA1_32 2
37 #define F8_128_HMAC_SHA1_80 3
38 // Protection level
39 #define SRTP_ENCRYPTION 0x0001
40 #define SRTP_AUTHENTICATION 0x0002
41 #define SRTP_SEND 0x0004
42 #define SRTP_RECEIVE 0x0008
43 #define SRTP_OFF 0
44 #define SRTP_ON (SRTP_ENCRYPTION|SRTP_AUTHENTICATION|SRTP_SEND|SRTP_RECEIVE)
45 #define SRTP_SECURITY_MASK (SRTP_ENCRYPTION|SRTP_AUTHENTICATION)
46 // Key length
47 #define SRTP_KEY_LENGTH 30
48 
49 // MACROS
50 // EXTERNAL FUNCTIONS
51 // EXTERNAL VARIABLES
52 // CONSTANTS
53 #define SDP_CONTENT_TYPE "application/sdp"
54 // STRUCTS
55 // TYPEDEFS
56 typedef struct SdpSrtpParameters
57 {
60  unsigned char masterKey[SRTP_KEY_LENGTH+1];
62 
63 
64 // FORWARD DECLARATIONS
65 class SdpCodecList;
66 class SdpMediaLine;
67 
69 
89 class SdpBody : public HttpBody
90 {
91 /* //////////////////////////// PUBLIC //////////////////////////////////// */
92  public:
93 
94  typedef enum
95  {
100  SendRecv
102 
107  SdpBody(const char* bytes = NULL,
109  int byteCount = -1
110  );
111 
113  SdpBody(const SdpBody& rSdpBody);
114 
116  virtual
117  ~SdpBody();
118 
120 
127  virtual int getLength() const;
129 
131  virtual void getBytes(const char** bytes,
132  int* length
133  ) const;
134 
136  virtual void getBytes(UtlString* bytes,
137  int* length
138  ) const;
139 
141 
150  void setStandardHeaderFields(const char* sessionName,
151  const char* emailAddress,
152  const char* phoneNumber,
153  const char* originatorAddress
154  );
155 
156 
157  void setSessionNameField(const char* sessionName);
158 
159  void setOriginator(const char* userId,
161  int sessionId,
162  int sessionVersion,
164  const char* address
165  );
166 
167  void setEmailAddressField(const char* emailAddress);
168 
169  void setPhoneNumberField(const char* phoneNumber);
170 
171  // Append a 't' field after any existing times, converting from epoch->ntp time.
172  void addEpochTime(unsigned long epochStartTime,
173  unsigned long epochEndTime = 0
174  );
175 
176  // Append a 't' field after any existing times.
177  void addNtpTime(unsigned long ntpStartTime,
178  unsigned long ntpEndTime = 0
179  );
180 
181  // Get the stream direction or activity state (i.e. sendrecv, sendonly, recvonly, inactive)
182  UtlBoolean getMediaStreamDirection(int mediaIndex,
183  SessionDirection& direction) const;
184 
185  // set all media attributes to either a=setup:actpass, a=setup:active, or a=setup:passive
186  void setRtpTcpRole(RtpTcpRoles role);
187  UtlString getRtpTcpRole() const;
188 
190 
199  void addCodecsOffer(int iNumAddresses,
201  const UtlString mediaAddresses[],
202  int rtpAudioPorts[],
203  int rtcpAudioPorts[],
204  int rtpVideoPorts[],
205  int rtcpVideoPorts[],
206  RTP_TRANSPORT transportTypes[],
207  int numRtpCodecs,
208  SdpCodec* rtpCodecs[],
209  SdpSrtpParameters& srtpParams,
210  int videoBandwidth,
211  int videoFramerate,
212  RTP_TRANSPORT transportOffering
213  );
214 
220  // Build a MediaLine (for local capabilities for using in addMediaLinesAnswer)
221  static void buildMediaLine(SdpMediaLine::SdpMediaType mediaType,
222  int totalBandwidth,
223  int iNumAddresses,
224  UtlString hostAddresses[],
225  int rtpPorts[],
226  int rtcpPorts[],
227  int numRtpCodecs,
228  SdpCodec* rtpCodecs[],
229  SdpMediaLine& mediaLine);
230 
232  void addCodecsAnswer(int iNumAddresses,
233  UtlString mediaAddresses[],
234  int rtpAudioPorts[],
235  int rtcpAudioPorts[],
236  int rtpVideoPorts[],
237  int rtcpVideoPorts[],
238  RTP_TRANSPORT transportTypes[],
239  int numRtpCodecs,
240  SdpCodec* rtpCodecs[],
241  SdpSrtpParameters& srtpParams,
242  int videoBandwidth,
243  int videoFramerate,
244  const SdpBody* sdpRequest
245  );
251  // Create an answer SDP in this for the given media streams and SDP offer
252  void addMediaLinesAnswer(int numMediaLines, const SdpMediaLine* mediaLines[], const SdpBody& offer);
253 
255  void addMediaData(const char* mediaType,
256  int portNumber,
257  int portPairCount,
258  const char* mediaTransportType,
259  int numPayloadTypes,
260  int payloadType[]
265  );
266 
267  void addCodecParameters(int numRtpCodecs,
268  SdpCodec* rtpCodecs[],
269  const char* szMimeType = "audio"
270  );
271 
273  void addConnectionAddress(const char* ipAddress
275  );
281  void addConnectionAddress(const char* networkType,
282  const char* addressType,
283  const char* ipAddress
284  );
285 
287  void setConnectionAddress(const char* ipAddress
289  );
294  void setConnectionAddress(const char* networkType,
295  const char* addressType,
296  const char* ipAddress
297  );
298 
299  void addRtpmap(int payloadType,
300  const char* mimeSubtype,
301  int sampleRate,
302  int numChannels
303  );
304 
305  void addSrtpCryptoField(SdpSrtpParameters& params);
306 
307  void addFormatParameters(int payloadType,
308  const char* formatParameters
309  );
310 
312  void addPtime(int pTime);
313 
317  void addCandidateAttribute(int candidateId,
318  const char* transportId,
319  const char* transportType,
320  uint64_t qValue,
321  const char* candidateIp,
322  int candidatePort) ;
323 
325 
334  int getMediaSetCount() const;
336 
338  int findMediaType(const char* mediaType,
339  int startMediaIndex = 0
340  ) const;
348  UtlBoolean getMediaData(int mediaIndex,
350  UtlString* mediaType,
351  int* mediaPort,
352  int* mediaPortPairs,
353  UtlString* mediaTransportType,
354  int maxPayloadTypes,
355  int* numPayloadTypes,
356  int payloadTypes[]) const;
357 
360  const bool isTransportAvailable(const OsSocket::IpProtocolSocketType protocol,
361  const SIPX_MEDIA_TYPE mediaType) const;
362 
364  UtlBoolean getMediaNetworkType(int mediaIndex,
365  UtlString* networkType) const;
366 
368  UtlBoolean getMediaAddress(int mediaIndex,
369  UtlString* address) const;
370 
372  UtlBoolean getMediaType(int mediaIndex,
373  UtlString* mediaType
374  ) const;
375 
377  UtlBoolean getMediaPort(int mediaIndex,
378  int* port) const;
379 
380  // Get the rtcp port number of the indicated media stream.
381  UtlBoolean getMediaRtcpPort(int mediaIndex,
382  int* port) const ;
383 
385  UtlBoolean getMediaPortCount(int mediaIndex,
386  int* numPorts) const;
393  UtlBoolean getMediaProtocol(int mediaIndex,
395  UtlString* transportProtocol
396  ) const;
397 
399  UtlBoolean getMediaPayloadType(int mediaIndex,
400  int maxTypes,
401  int* numTypes,
402  int payloadTypes[]
403  ) const;
404 
406  UtlBoolean getPtime(int mediaIndex, int& ptime) const;
407 
409  UtlBoolean getMediaSubfield(int mediaIndex,
410  int subfieldIndex,
411  UtlString* subField
412  ) const;
413 
415  UtlBoolean getPayloadRtpMap(int mediaIndex,
416  int payloadType,
417  UtlString& mimeSubtype,
418  int& sampleRate,
419  int& numChannels
420  ) const;
421 
422  // Get the fmtp parameter
423  UtlBoolean getPayloadFormat(int mediaIndex,
424  int payloadType,
425  UtlString& fmtp) const;
430  // Get the crypto field for SRTP
431  UtlBoolean getSrtpCryptoField(int mediaIndex,
432  int index,
433  SdpSrtpParameters& params) const;
434 
435  // Get the a=control;trackId= value
436  UtlBoolean getControlTrackId(int mediaLineIndex, UtlString& trackId) const;
437 
438  // Get the framerate field if there
439  UtlBoolean getFramerateField(int mediaIndex,
440  int& videoFramerate) const;
441 
442  UtlBoolean getBandwidthField(int& bandwidth) const;
443 
450 #if 0
451  void getBestAudioCodecs(int numRtpCodecs,
453  SdpCodec rtpCodecs[],
454  UtlString* rtpAddress,
455  int* rtpPort,
456  int* sendCodecIndex,
457  int* receiveCodecIndex) const;
459 #endif
460 
461 
463  void getBestAudioCodecs(SdpCodecList& localRtpCodecs,
464  int& numCodecsInCommon,
465  SdpCodec**& commonCodecsForEncoder,
466  //SdpCodec**& commonCodecsForDecoder,
467  UtlString& rtpAddress,
468  int& rtpPort,
469  int& rtcpPort,
470  int& videoRtpPort,
471  int& videoRtcpPort,
472  SdpSrtpParameters& localSrtpParams,
473  SdpSrtpParameters& matchingSrtpParams,
474  int localBandwidth,
475  int& matchingBandwidth,
476  int localVideoFramerate,
477  int& matchingVideoFramerate) const;
478 
480  // TODO: This interface is total broken and needs to be eliminated
481  // It munges the codecs and payload types accross all of the m lines
482  void getCodecsInCommon(int audioMediaSetIndex,
483  int videoMediaSetIndex,
484  int audioPayloadIdCount,
485  int videoPayloadIdCount,
486  int audioPayloadTypes[],
487  int videoPayloadTypes[],
488  int videoRtpPort,
489  SdpCodecList& localRtpCodecs,
490  int& numCodecsInCommon,
491  SdpCodec* commonCodecsForEncoder[],
492  SdpCodec* commonCodecsForDecoder[]) const;
493 
495  int getCodecsInCommon(const SdpMediaLine& localMediaLine,
496  int remoteMediaLineIndex,
497  SdpMediaLine& remoteMediaLine,
498  SdpCodecList& localDecodeCodecs) const;
513  // Reads the indexed m line from this SDP into the given SdpMediaLine container.
514  UtlBoolean getMediaLine(int remoteMediaLineIndex, SdpMediaLine& mediaLine, const SdpCodecList* codecFactory) const;
515 
516  // Add a SdpMediaLine object to this SdpBody
517  void addMediaLine(const SdpMediaLine& mediaLine, SdpBody& sdpBody);
518 
519  // Find common encryption suites
520  void getEncryptionInCommon(SdpSrtpParameters& audioParams,
521  SdpSrtpParameters& remoteParams,
522  SdpSrtpParameters& commonAudioParms) const;
523 
524  // Find common bandwidth
525  void getBandwidthInCommon(int localBandwidth,
526  int remoteBandwidth,
527  int& commonBandwidth) const;
528 
529  // Find a common video framerate
530  void getVideoFramerateInCommon(int localVideoFramerate,
531  int remoteVideoFramerate,
532  int& commonVideoFramerate) const;
533 
537  UtlBoolean getCandidateAttribute(int mediaIndex,
538  int candidateIndex,
539  int& rCandidateId,
540  UtlString& rTransportId,
541  UtlString& rTransportType,
542  uint64_t& rQvalue,
543  UtlString& rCandidateIp,
544  int& rCandidatePort) const ;
545 
546 
547  UtlBoolean getCandidateAttributes(const char* szMimeType,
548  int nMaxAddresses,
549  int candidateIds[],
550  UtlString transportIds[],
551  UtlString transportTypes[],
552  uint64_t qvalues[],
553  UtlString candidateIps[],
554  int candidatePorts[],
555  int& nActualAddresses) const ;
556 
557  UtlBoolean getCandidateAttributes(int mediaIndex,
558  int nMaxAddresses,
559  int candidateIds[],
560  UtlString transportIds[],
561  UtlString transportTypes[],
562  uint64_t qvalues[],
563  UtlString candidateIps[],
564  int candidatePorts[],
565  int& nActualAddresses) const ;
566 
571  UtlBoolean findValueInField(const char* pField, const char* pvalue) const;
572 
573 
575 
576 /* //////////////////////////// PROTECTED ///////////////////////////////// */
577  protected:
578  friend class SdpBodyTest;
579 
589  int getFieldCount() const;
591 
593  UtlBoolean getValue(int fieldIndex,
594  UtlString* name,
595  UtlString* value) const;
603  void setValue(const char* name,
605  const char* value
606  );
607 
609 
611  void parseBody(const char* bytes = NULL,
612  int byteCount = -1
613  );
614 
615 
616 /* //////////////////////////// PRIVATE /////////////////////////////////// */
617  private:
618 
620  size_t findFirstOf( const char* headers );
633  bool isOptionalField(const char* name) const;
635 
637  void addValue(const char* name,
638  const char* value = NULL,
639  int fieldIndex = -1
640  );
641 
642  UtlSList* sdpFields;
643 
645  static NameValuePair* positionFieldInstance(int fieldInstanceIndex,
646  UtlSListIterator* iter,
648  const char* fieldName
649  );
655  static NameValuePair* findFieldNameBefore(UtlSListIterator* iter,
656  const char* targetFieldName,
657  const char* beforeFieldName);
658 
660  SdpBody& operator=(const SdpBody& rhs);
661 
662 };
663 
664 /* ============================ INLINE METHODS ============================ */
665 
666 #endif // _SdpBody_h_
Definition: SdpBody.h:98
unsigned char masterKey[SRTP_KEY_LENGTH+1]
Definition: SdpBody.h:60
Definition: SdpBody.h:99
Definition: SdpBody.h:97
sipXtapi event declarations
struct SdpSrtpParameters SdpSrtpParameters
SessionDirection
Definition: SdpBody.h:94
Definition: SdpBody.h:56
Definition: NameValuePair.h:35
SIPX_MEDIA_TYPE
Enumeration of possible media event types.
Definition: sipXtapiEvents.h:660
int cipherType
Definition: SdpBody.h:58
int securityLevel
Definition: SdpBody.h:59
#define SRTP_KEY_LENGTH
Definition: SdpBody.h:47
class to contain an HTTP body
Definition: HttpBody.h:55
Container for MIME type application/sdp.
Definition: SdpBody.h:89
Definition: SdpBody.h:96

sipXtackLib home page