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