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