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 11 // This file contain functions for parsing and serializing SDP messages. 12 // Related RFC/draft including: 13 // * RFC 4566 - SDP 14 // * RFC 5245 - ICE 15 // * RFC 3388 - Grouping of Media Lines in SDP 16 // * RFC 4568 - SDP Security Descriptions for Media Streams 17 // * draft-lennox-mmusic-sdp-source-selection-02 - 18 // Mechanisms for Media Source Selection in SDP 19 20 #ifndef PC_WEBRTC_SDP_H_ 21 #define PC_WEBRTC_SDP_H_ 22 23 #include <string> 24 25 #include "absl/strings/string_view.h" 26 #include "api/candidate.h" 27 #include "api/jsep.h" 28 #include "api/jsep_ice_candidate.h" 29 #include "api/jsep_session_description.h" 30 #include "media/base/codec.h" 31 #include "rtc_base/strings/string_builder.h" 32 #include "rtc_base/system/rtc_export.h" 33 34 namespace cricket { 35 class Candidate; 36 } // namespace cricket 37 38 namespace rtc { 39 class StringBuilder; 40 } // namespace rtc 41 42 namespace webrtc { 43 class IceCandidateInterface; 44 class JsepIceCandidate; 45 class JsepSessionDescription; 46 struct SdpParseError; 47 48 // Serializes the passed in JsepSessionDescription. 49 // Serialize SessionDescription including candidates if 50 // JsepSessionDescription has candidates. 51 // jdesc - The JsepSessionDescription object to be serialized. 52 // unified_plan_sdp - If set to true, include "a=msid" lines where appropriate. 53 // return - SDP string serialized from the arguments. 54 std::string SdpSerialize(const JsepSessionDescription& jdesc); 55 56 // Serializes the passed in IceCandidateInterface to a SDP string. 57 // candidate - The candidate to be serialized. 58 std::string SdpSerializeCandidate(const IceCandidateInterface& candidate); 59 60 // Serializes a cricket Candidate. 61 // candidate - The candidate to be serialized. 62 RTC_EXPORT std::string SdpSerializeCandidate( 63 const cricket::Candidate& candidate); 64 65 // Deserializes the passed in SDP string to a JsepSessionDescription. 66 // message - SDP string to be Deserialized. 67 // jdesc - The JsepSessionDescription deserialized from the SDP string. 68 // error - The detail error information when parsing fails. 69 // return - true on success, false on failure. 70 bool SdpDeserialize(absl::string_view message, 71 JsepSessionDescription* jdesc, 72 SdpParseError* error); 73 74 // Deserializes the passed in SDP string to one JsepIceCandidate. 75 // The first line must be a=candidate line and only the first line will be 76 // parsed. 77 // message - The SDP string to be Deserialized. 78 // candidates - The JsepIceCandidate from the SDP string. 79 // error - The detail error information when parsing fails. 80 // return - true on success, false on failure. 81 RTC_EXPORT bool SdpDeserializeCandidate(absl::string_view message, 82 JsepIceCandidate* candidate, 83 SdpParseError* error); 84 85 // Deserializes the passed in SDP string to a cricket Candidate. 86 // The first line must be a=candidate line and only the first line will be 87 // parsed. 88 // transport_name - The transport name (MID) of the candidate. 89 // message - The SDP string to be deserialized. 90 // candidate - The cricket Candidate from the SDP string. 91 // error - The detail error information when parsing fails. 92 // return - true on success, false on failure. 93 RTC_EXPORT bool SdpDeserializeCandidate(absl::string_view transport_name, 94 absl::string_view message, 95 cricket::Candidate* candidate, 96 SdpParseError* error); 97 98 // Parses `message` according to the grammar defined in RFC 5245, Section 15.1 99 // and, if successful, stores the result in `candidate` and returns true. 100 // If unsuccessful, returns false and stores error information in `error` if 101 // `error` is not null. 102 // If `is_raw` is false, `message` is expected to be prefixed with "a=". 103 // If `is_raw` is true, no prefix is expected in `messaage`. 104 RTC_EXPORT bool ParseCandidate(absl::string_view message, 105 cricket::Candidate* candidate, 106 SdpParseError* error, 107 bool is_raw); 108 109 // Generates an FMTP line based on `parameters`. Please note that some 110 // parameters are not considered to be part of the FMTP line, see the function 111 // IsFmtpParam(). Returns true if the set of FMTP parameters is nonempty, false 112 // otherwise. 113 bool WriteFmtpParameters(const cricket::CodecParameterMap& parameters, 114 rtc::StringBuilder* os); 115 116 } // namespace webrtc 117 118 #endif // PC_WEBRTC_SDP_H_ 119