henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #ifndef PC_WEBRTC_SDP_H_ |
| 21 | #define PC_WEBRTC_SDP_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
| 23 | #include <string> |
| 24 | |
Johannes Kron | 72d6915 | 2020-02-10 14:05:55 +0100 | [diff] [blame] | 25 | #include "media/base/codec.h" |
Mirko Bonadei | 977b46a | 2018-10-24 16:22:04 +0200 | [diff] [blame] | 26 | #include "rtc_base/system/rtc_export.h" |
| 27 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 28 | namespace cricket { |
| 29 | class Candidate; |
| 30 | } // namespace cricket |
tommi | 6f59a4f | 2016-03-11 14:05:09 -0800 | [diff] [blame] | 31 | |
Johannes Kron | 72d6915 | 2020-02-10 14:05:55 +0100 | [diff] [blame] | 32 | namespace rtc { |
| 33 | class StringBuilder; |
| 34 | } // namespace rtc |
| 35 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 36 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | class IceCandidateInterface; |
| 38 | class JsepIceCandidate; |
| 39 | class JsepSessionDescription; |
| 40 | struct SdpParseError; |
| 41 | |
| 42 | // Serializes the passed in JsepSessionDescription. |
| 43 | // Serialize SessionDescription including candidates if |
| 44 | // JsepSessionDescription has candidates. |
| 45 | // jdesc - The JsepSessionDescription object to be serialized. |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 46 | // unified_plan_sdp - If set to true, include "a=msid" lines where appropriate. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | // return - SDP string serialized from the arguments. |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 48 | std::string SdpSerialize(const JsepSessionDescription& jdesc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | |
| 50 | // Serializes the passed in IceCandidateInterface to a SDP string. |
| 51 | // candidate - The candidate to be serialized. |
| 52 | std::string SdpSerializeCandidate(const IceCandidateInterface& candidate); |
| 53 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 54 | // Serializes a cricket Candidate. |
| 55 | // candidate - The candidate to be serialized. |
Mirko Bonadei | 977b46a | 2018-10-24 16:22:04 +0200 | [diff] [blame] | 56 | RTC_EXPORT std::string SdpSerializeCandidate( |
| 57 | const cricket::Candidate& candidate); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 58 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | // Deserializes the passed in SDP string to a JsepSessionDescription. |
| 60 | // message - SDP string to be Deserialized. |
| 61 | // jdesc - The JsepSessionDescription deserialized from the SDP string. |
| 62 | // error - The detail error information when parsing fails. |
| 63 | // return - true on success, false on failure. |
| 64 | bool SdpDeserialize(const std::string& message, |
| 65 | JsepSessionDescription* jdesc, |
| 66 | SdpParseError* error); |
| 67 | |
| 68 | // Deserializes the passed in SDP string to one JsepIceCandidate. |
| 69 | // The first line must be a=candidate line and only the first line will be |
| 70 | // parsed. |
| 71 | // message - The SDP string to be Deserialized. |
| 72 | // candidates - The JsepIceCandidate from the SDP string. |
| 73 | // error - The detail error information when parsing fails. |
| 74 | // return - true on success, false on failure. |
Mirko Bonadei | 66e7679 | 2019-04-02 11:33:59 +0200 | [diff] [blame] | 75 | RTC_EXPORT bool SdpDeserializeCandidate(const std::string& message, |
| 76 | JsepIceCandidate* candidate, |
| 77 | SdpParseError* error); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 78 | |
| 79 | // Deserializes the passed in SDP string to a cricket Candidate. |
| 80 | // The first line must be a=candidate line and only the first line will be |
| 81 | // parsed. |
| 82 | // transport_name - The transport name (MID) of the candidate. |
| 83 | // message - The SDP string to be deserialized. |
| 84 | // candidate - The cricket Candidate from the SDP string. |
| 85 | // error - The detail error information when parsing fails. |
| 86 | // return - true on success, false on failure. |
Mirko Bonadei | 977b46a | 2018-10-24 16:22:04 +0200 | [diff] [blame] | 87 | RTC_EXPORT bool SdpDeserializeCandidate(const std::string& transport_name, |
| 88 | const std::string& message, |
| 89 | cricket::Candidate* candidate, |
| 90 | SdpParseError* error); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 91 | |
Guido Urdaneta | da37473 | 2019-01-25 10:36:43 +0100 | [diff] [blame] | 92 | // Parses |message| according to the grammar defined in RFC 5245, Section 15.1 |
| 93 | // and, if successful, stores the result in |candidate| and returns true. |
| 94 | // If unsuccessful, returns false and stores error information in |error| if |
| 95 | // |error| is not null. |
| 96 | // If |is_raw| is false, |message| is expected to be prefixed with "a=". |
| 97 | // If |is_raw| is true, no prefix is expected in |messaage|. |
| 98 | RTC_EXPORT bool ParseCandidate(const std::string& message, |
| 99 | cricket::Candidate* candidate, |
| 100 | SdpParseError* error, |
| 101 | bool is_raw); |
| 102 | |
Johannes Kron | 72d6915 | 2020-02-10 14:05:55 +0100 | [diff] [blame] | 103 | // Generates an FMTP line based on |parameters|. Please note that some |
| 104 | // parameters are not considered to be part of the FMTP line, see the function |
| 105 | // IsFmtpParam(). Returns true if the set of FMTP parameters is nonempty, false |
| 106 | // otherwise. |
| 107 | bool WriteFmtpParameters(const cricket::CodecParameterMap& parameters, |
| 108 | rtc::StringBuilder* os); |
| 109 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | } // namespace webrtc |
| 111 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 112 | #endif // PC_WEBRTC_SDP_H_ |