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 2012 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 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 11 | // This file contains declarations of interfaces that wrap SDP-related |
| 12 | // constructs; session descriptions and ICE candidates. The inner "cricket::" |
| 13 | // objects shouldn't be accessed directly; the intention is that an application |
| 14 | // using the PeerConnection API only creates these objects from strings, and |
| 15 | // them passes them into the PeerConnection. |
| 16 | // |
| 17 | // Though in the future, we're planning to provide an SDP parsing API, with a |
| 18 | // structure more friendly than cricket::SessionDescription. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #ifndef API_JSEP_H_ |
| 21 | #define API_JSEP_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
pbos | 9baddf2 | 2017-01-02 06:44:41 -0800 | [diff] [blame] | 23 | #include <stddef.h> |
| 24 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | #include <string> |
| 26 | #include <vector> |
| 27 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "rtc_base/refcount.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | |
| 30 | namespace cricket { |
tommi | 6f59a4f | 2016-03-11 14:05:09 -0800 | [diff] [blame] | 31 | class Candidate; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 32 | class SessionDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | } // namespace cricket |
| 34 | |
| 35 | namespace webrtc { |
| 36 | |
| 37 | struct SdpParseError { |
| 38 | public: |
| 39 | // The sdp line that causes the error. |
| 40 | std::string line; |
| 41 | // Explains the error. |
| 42 | std::string description; |
| 43 | }; |
| 44 | |
| 45 | // Class representation of an ICE candidate. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 46 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | // An instance of this interface is supposed to be owned by one class at |
| 48 | // a time and is therefore not expected to be thread safe. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 49 | // |
| 50 | // An instance can be created by CreateIceCandidate. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | class IceCandidateInterface { |
| 52 | public: |
| 53 | virtual ~IceCandidateInterface() {} |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 54 | // If present, this is the value of the "a=mid" attribute of the candidate's |
| 55 | // m= section in SDP, which identifies the m= section. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | virtual std::string sdp_mid() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 57 | // This indicates the index (starting at zero) of m= section this candidate |
| 58 | // is assocated with. Needed when an endpoint doesn't support MIDs. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | virtual int sdp_mline_index() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 60 | // Only for use internally. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | virtual const cricket::Candidate& candidate() const = 0; |
zhihuang | d7e771d | 2017-02-16 11:29:39 -0800 | [diff] [blame] | 62 | // The URL of the ICE server which this candidate was gathered from. |
| 63 | // TODO(zhihuang): Remove the default implementation once the subclasses |
| 64 | // implement this method. |
| 65 | virtual std::string server_url() const { return ""; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | // Creates a SDP-ized form of this candidate. |
| 67 | virtual bool ToString(std::string* out) const = 0; |
| 68 | }; |
| 69 | |
| 70 | // Creates a IceCandidateInterface based on SDP string. |
deadbeef | 8d60a94 | 2017-02-27 14:47:33 -0800 | [diff] [blame] | 71 | // Returns null if the sdp string can't be parsed. |
| 72 | // |error| may be null. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 74 | int sdp_mline_index, |
| 75 | const std::string& sdp, |
| 76 | SdpParseError* error); |
| 77 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 78 | // This class represents a collection of candidates for a specific m= section. |
| 79 | // Used in SessionDescriptionInterface. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | class IceCandidateCollection { |
| 81 | public: |
| 82 | virtual ~IceCandidateCollection() {} |
| 83 | virtual size_t count() const = 0; |
| 84 | // Returns true if an equivalent |candidate| exist in the collection. |
| 85 | virtual bool HasCandidate(const IceCandidateInterface* candidate) const = 0; |
| 86 | virtual const IceCandidateInterface* at(size_t index) const = 0; |
| 87 | }; |
| 88 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 89 | // Class representation of an SDP session description. |
| 90 | // |
| 91 | // An instance of this interface is supposed to be owned by one class at a time |
| 92 | // and is therefore not expected to be thread safe. |
| 93 | // |
| 94 | // An instance can be created by CreateSessionDescription. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | class SessionDescriptionInterface { |
| 96 | public: |
| 97 | // Supported types: |
| 98 | static const char kOffer[]; |
| 99 | static const char kPrAnswer[]; |
| 100 | static const char kAnswer[]; |
| 101 | |
| 102 | virtual ~SessionDescriptionInterface() {} |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 103 | |
| 104 | // Only for use internally. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | virtual cricket::SessionDescription* description() = 0; |
| 106 | virtual const cricket::SessionDescription* description() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 107 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | // Get the session id and session version, which are defined based on |
| 109 | // RFC 4566 for the SDP o= line. |
| 110 | virtual std::string session_id() const = 0; |
| 111 | virtual std::string session_version() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 112 | |
| 113 | // kOffer/kPrAnswer/kAnswer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | virtual std::string type() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 115 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | // Adds the specified candidate to the description. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 117 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | // Ownership is not transferred. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 119 | // |
| 120 | // Returns false if the session description does not have a media section |
| 121 | // that corresponds to |candidate.sdp_mid()| or |
| 122 | // |candidate.sdp_mline_index()|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | virtual bool AddCandidate(const IceCandidateInterface* candidate) = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 124 | |
| 125 | // Removes the candidates from the description, if found. |
| 126 | // |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 127 | // Returns the number of candidates removed. |
| 128 | virtual size_t RemoveCandidates( |
| 129 | const std::vector<cricket::Candidate>& candidates) { return 0; } |
| 130 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 131 | // Returns the number of m= sections in the session description. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | virtual size_t number_of_mediasections() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 133 | |
| 134 | // Returns a collection of all candidates that belong to a certain m= |
| 135 | // section. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | virtual const IceCandidateCollection* candidates( |
| 137 | size_t mediasection_index) const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 138 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 139 | // Serializes the description to SDP. |
| 140 | virtual bool ToString(std::string* out) const = 0; |
| 141 | }; |
| 142 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 143 | // Creates a SessionDescriptionInterface based on the SDP string and the type. |
deadbeef | 8d60a94 | 2017-02-27 14:47:33 -0800 | [diff] [blame] | 144 | // Returns null if the sdp string can't be parsed or the type is unsupported. |
| 145 | // |error| may be null. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | SessionDescriptionInterface* CreateSessionDescription(const std::string& type, |
| 147 | const std::string& sdp, |
| 148 | SdpParseError* error); |
| 149 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 150 | // CreateOffer and CreateAnswer callback interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 151 | class CreateSessionDescriptionObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | public: |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 153 | // This callback transfers the ownership of the |desc|. |
| 154 | // TODO(deadbeef): Make this take an std::unique_ptr<> to avoid confusion |
| 155 | // around ownership. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | virtual void OnSuccess(SessionDescriptionInterface* desc) = 0; |
| 157 | virtual void OnFailure(const std::string& error) = 0; |
| 158 | |
| 159 | protected: |
| 160 | ~CreateSessionDescriptionObserver() {} |
| 161 | }; |
| 162 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 163 | // SetLocalDescription and SetRemoteDescription callback interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 164 | class SetSessionDescriptionObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | public: |
| 166 | virtual void OnSuccess() = 0; |
| 167 | virtual void OnFailure(const std::string& error) = 0; |
| 168 | |
| 169 | protected: |
| 170 | ~SetSessionDescriptionObserver() {} |
| 171 | }; |
| 172 | |
| 173 | } // namespace webrtc |
| 174 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 175 | #endif // API_JSEP_H_ |