webrtc_sdp.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2011 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. // This file contain functions for parsing and serializing SDP messages.
  11. // Related RFC/draft including:
  12. // * RFC 4566 - SDP
  13. // * RFC 5245 - ICE
  14. // * RFC 3388 - Grouping of Media Lines in SDP
  15. // * RFC 4568 - SDP Security Descriptions for Media Streams
  16. // * draft-lennox-mmusic-sdp-source-selection-02 -
  17. // Mechanisms for Media Source Selection in SDP
  18. #ifndef PC_WEBRTC_SDP_H_
  19. #define PC_WEBRTC_SDP_H_
  20. #include <string>
  21. #include "media/base/codec.h"
  22. #include "rtc_base/system/rtc_export.h"
  23. namespace cricket {
  24. class Candidate;
  25. } // namespace cricket
  26. namespace rtc {
  27. class StringBuilder;
  28. } // namespace rtc
  29. namespace webrtc {
  30. class IceCandidateInterface;
  31. class JsepIceCandidate;
  32. class JsepSessionDescription;
  33. struct SdpParseError;
  34. // Serializes the passed in JsepSessionDescription.
  35. // Serialize SessionDescription including candidates if
  36. // JsepSessionDescription has candidates.
  37. // jdesc - The JsepSessionDescription object to be serialized.
  38. // unified_plan_sdp - If set to true, include "a=msid" lines where appropriate.
  39. // return - SDP string serialized from the arguments.
  40. std::string SdpSerialize(const JsepSessionDescription& jdesc);
  41. // Serializes the passed in IceCandidateInterface to a SDP string.
  42. // candidate - The candidate to be serialized.
  43. std::string SdpSerializeCandidate(const IceCandidateInterface& candidate);
  44. // Serializes a cricket Candidate.
  45. // candidate - The candidate to be serialized.
  46. RTC_EXPORT std::string SdpSerializeCandidate(
  47. const cricket::Candidate& candidate);
  48. // Deserializes the passed in SDP string to a JsepSessionDescription.
  49. // message - SDP string to be Deserialized.
  50. // jdesc - The JsepSessionDescription deserialized from the SDP string.
  51. // error - The detail error information when parsing fails.
  52. // return - true on success, false on failure.
  53. bool SdpDeserialize(const std::string& message,
  54. JsepSessionDescription* jdesc,
  55. SdpParseError* error);
  56. // Deserializes the passed in SDP string to one JsepIceCandidate.
  57. // The first line must be a=candidate line and only the first line will be
  58. // parsed.
  59. // message - The SDP string to be Deserialized.
  60. // candidates - The JsepIceCandidate from the SDP string.
  61. // error - The detail error information when parsing fails.
  62. // return - true on success, false on failure.
  63. RTC_EXPORT bool SdpDeserializeCandidate(const std::string& message,
  64. JsepIceCandidate* candidate,
  65. SdpParseError* error);
  66. // Deserializes the passed in SDP string to a cricket Candidate.
  67. // The first line must be a=candidate line and only the first line will be
  68. // parsed.
  69. // transport_name - The transport name (MID) of the candidate.
  70. // message - The SDP string to be deserialized.
  71. // candidate - The cricket Candidate from the SDP string.
  72. // error - The detail error information when parsing fails.
  73. // return - true on success, false on failure.
  74. RTC_EXPORT bool SdpDeserializeCandidate(const std::string& transport_name,
  75. const std::string& message,
  76. cricket::Candidate* candidate,
  77. SdpParseError* error);
  78. // Parses |message| according to the grammar defined in RFC 5245, Section 15.1
  79. // and, if successful, stores the result in |candidate| and returns true.
  80. // If unsuccessful, returns false and stores error information in |error| if
  81. // |error| is not null.
  82. // If |is_raw| is false, |message| is expected to be prefixed with "a=".
  83. // If |is_raw| is true, no prefix is expected in |messaage|.
  84. RTC_EXPORT bool ParseCandidate(const std::string& message,
  85. cricket::Candidate* candidate,
  86. SdpParseError* error,
  87. bool is_raw);
  88. // Generates an FMTP line based on |parameters|. Please note that some
  89. // parameters are not considered to be part of the FMTP line, see the function
  90. // IsFmtpParam(). Returns true if the set of FMTP parameters is nonempty, false
  91. // otherwise.
  92. bool WriteFmtpParameters(const cricket::CodecParameterMap& parameters,
  93. rtc::StringBuilder* os);
  94. } // namespace webrtc
  95. #endif // PC_WEBRTC_SDP_H_