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 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 20 | #ifndef WEBRTC_API_JSEP_H_ |
| 21 | #define WEBRTC_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 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 28 | #include "webrtc/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; |
| 62 | // Creates a SDP-ized form of this candidate. |
| 63 | virtual bool ToString(std::string* out) const = 0; |
| 64 | }; |
| 65 | |
| 66 | // Creates a IceCandidateInterface based on SDP string. |
| 67 | // Returns NULL if the sdp string can't be parsed. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 68 | // |error| may be NULL. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 70 | int sdp_mline_index, |
| 71 | const std::string& sdp, |
| 72 | SdpParseError* error); |
| 73 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 74 | // This class represents a collection of candidates for a specific m= section. |
| 75 | // Used in SessionDescriptionInterface. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | class IceCandidateCollection { |
| 77 | public: |
| 78 | virtual ~IceCandidateCollection() {} |
| 79 | virtual size_t count() const = 0; |
| 80 | // Returns true if an equivalent |candidate| exist in the collection. |
| 81 | virtual bool HasCandidate(const IceCandidateInterface* candidate) const = 0; |
| 82 | virtual const IceCandidateInterface* at(size_t index) const = 0; |
| 83 | }; |
| 84 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 85 | // Class representation of an SDP session description. |
| 86 | // |
| 87 | // An instance of this interface is supposed to be owned by one class at a time |
| 88 | // and is therefore not expected to be thread safe. |
| 89 | // |
| 90 | // An instance can be created by CreateSessionDescription. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | class SessionDescriptionInterface { |
| 92 | public: |
| 93 | // Supported types: |
| 94 | static const char kOffer[]; |
| 95 | static const char kPrAnswer[]; |
| 96 | static const char kAnswer[]; |
| 97 | |
| 98 | virtual ~SessionDescriptionInterface() {} |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 99 | |
| 100 | // Only for use internally. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | virtual cricket::SessionDescription* description() = 0; |
| 102 | virtual const cricket::SessionDescription* description() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 103 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | // Get the session id and session version, which are defined based on |
| 105 | // RFC 4566 for the SDP o= line. |
| 106 | virtual std::string session_id() const = 0; |
| 107 | virtual std::string session_version() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 108 | |
| 109 | // kOffer/kPrAnswer/kAnswer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | virtual std::string type() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 111 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | // Adds the specified candidate to the description. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 113 | // |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | // Ownership is not transferred. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 115 | // |
| 116 | // Returns false if the session description does not have a media section |
| 117 | // that corresponds to |candidate.sdp_mid()| or |
| 118 | // |candidate.sdp_mline_index()|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | virtual bool AddCandidate(const IceCandidateInterface* candidate) = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 120 | |
| 121 | // Removes the candidates from the description, if found. |
| 122 | // |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 123 | // Returns the number of candidates removed. |
| 124 | virtual size_t RemoveCandidates( |
| 125 | const std::vector<cricket::Candidate>& candidates) { return 0; } |
| 126 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 127 | // Returns the number of m= sections in the session description. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | virtual size_t number_of_mediasections() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 129 | |
| 130 | // Returns a collection of all candidates that belong to a certain m= |
| 131 | // section. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | virtual const IceCandidateCollection* candidates( |
| 133 | size_t mediasection_index) const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 134 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | // Serializes the description to SDP. |
| 136 | virtual bool ToString(std::string* out) const = 0; |
| 137 | }; |
| 138 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 139 | // Creates a SessionDescriptionInterface based on the SDP string and the type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | // Returns NULL if the sdp string can't be parsed or the type is unsupported. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 141 | // |error| may be NULL. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | SessionDescriptionInterface* CreateSessionDescription(const std::string& type, |
| 143 | const std::string& sdp, |
| 144 | SdpParseError* error); |
| 145 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 146 | // CreateOffer and CreateAnswer callback interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 147 | class CreateSessionDescriptionObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | public: |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 149 | // This callback transfers the ownership of the |desc|. |
| 150 | // TODO(deadbeef): Make this take an std::unique_ptr<> to avoid confusion |
| 151 | // around ownership. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | virtual void OnSuccess(SessionDescriptionInterface* desc) = 0; |
| 153 | virtual void OnFailure(const std::string& error) = 0; |
| 154 | |
| 155 | protected: |
| 156 | ~CreateSessionDescriptionObserver() {} |
| 157 | }; |
| 158 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 159 | // SetLocalDescription and SetRemoteDescription callback interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 160 | class SetSessionDescriptionObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | public: |
| 162 | virtual void OnSuccess() = 0; |
| 163 | virtual void OnFailure(const std::string& error) = 0; |
| 164 | |
| 165 | protected: |
| 166 | ~SetSessionDescriptionObserver() {} |
| 167 | }; |
| 168 | |
| 169 | } // namespace webrtc |
| 170 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 171 | #endif // WEBRTC_API_JSEP_H_ |