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 | |
| 11 | // Interfaces matching the draft-ietf-rtcweb-jsep-01. |
| 12 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 13 | #ifndef WEBRTC_API_JSEP_H_ |
| 14 | #define WEBRTC_API_JSEP_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 19 | #include "webrtc/base/basictypes.h" |
| 20 | #include "webrtc/base/refcount.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | |
| 22 | namespace cricket { |
tommi | 6f59a4f | 2016-03-11 14:05:09 -0800 | [diff] [blame] | 23 | class Candidate; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 24 | class SessionDescription; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | } // namespace cricket |
| 26 | |
| 27 | namespace webrtc { |
| 28 | |
| 29 | struct SdpParseError { |
| 30 | public: |
| 31 | // The sdp line that causes the error. |
| 32 | std::string line; |
| 33 | // Explains the error. |
| 34 | std::string description; |
| 35 | }; |
| 36 | |
| 37 | // Class representation of an ICE candidate. |
| 38 | // An instance of this interface is supposed to be owned by one class at |
| 39 | // a time and is therefore not expected to be thread safe. |
| 40 | class IceCandidateInterface { |
| 41 | public: |
| 42 | virtual ~IceCandidateInterface() {} |
| 43 | /// If present, this contains the identierfier of the "media stream |
| 44 | // identification" as defined in [RFC 3388] for m-line this candidate is |
| 45 | // assocated with. |
| 46 | virtual std::string sdp_mid() const = 0; |
| 47 | // This indeicates the index (starting at zero) of m-line in the SDP this |
| 48 | // candidate is assocated with. |
| 49 | virtual int sdp_mline_index() const = 0; |
| 50 | virtual const cricket::Candidate& candidate() const = 0; |
| 51 | // Creates a SDP-ized form of this candidate. |
| 52 | virtual bool ToString(std::string* out) const = 0; |
| 53 | }; |
| 54 | |
| 55 | // Creates a IceCandidateInterface based on SDP string. |
| 56 | // Returns NULL if the sdp string can't be parsed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | // |error| can be NULL if doesn't care about the failure reason. |
| 58 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 59 | int sdp_mline_index, |
| 60 | const std::string& sdp, |
| 61 | SdpParseError* error); |
| 62 | |
| 63 | // This class represents a collection of candidates for a specific m-line. |
| 64 | // This class is used in SessionDescriptionInterface to represent all known |
| 65 | // candidates for a certain m-line. |
| 66 | class IceCandidateCollection { |
| 67 | public: |
| 68 | virtual ~IceCandidateCollection() {} |
| 69 | virtual size_t count() const = 0; |
| 70 | // Returns true if an equivalent |candidate| exist in the collection. |
| 71 | virtual bool HasCandidate(const IceCandidateInterface* candidate) const = 0; |
| 72 | virtual const IceCandidateInterface* at(size_t index) const = 0; |
| 73 | }; |
| 74 | |
| 75 | // Class representation of a Session description. |
| 76 | // An instance of this interface is supposed to be owned by one class at |
| 77 | // a time and is therefore not expected to be thread safe. |
| 78 | class SessionDescriptionInterface { |
| 79 | public: |
| 80 | // Supported types: |
| 81 | static const char kOffer[]; |
| 82 | static const char kPrAnswer[]; |
| 83 | static const char kAnswer[]; |
| 84 | |
| 85 | virtual ~SessionDescriptionInterface() {} |
| 86 | virtual cricket::SessionDescription* description() = 0; |
| 87 | virtual const cricket::SessionDescription* description() const = 0; |
| 88 | // Get the session id and session version, which are defined based on |
| 89 | // RFC 4566 for the SDP o= line. |
| 90 | virtual std::string session_id() const = 0; |
| 91 | virtual std::string session_version() const = 0; |
| 92 | virtual std::string type() const = 0; |
| 93 | // Adds the specified candidate to the description. |
| 94 | // Ownership is not transferred. |
| 95 | // Returns false if the session description does not have a media section that |
| 96 | // corresponds to the |candidate| label. |
| 97 | virtual bool AddCandidate(const IceCandidateInterface* candidate) = 0; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 98 | // Removes the candidates from the description. |
| 99 | // Returns the number of candidates removed. |
| 100 | virtual size_t RemoveCandidates( |
| 101 | const std::vector<cricket::Candidate>& candidates) { return 0; } |
| 102 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | // Returns the number of m- lines in the session description. |
| 104 | virtual size_t number_of_mediasections() const = 0; |
| 105 | // Returns a collection of all candidates that belong to a certain m-line |
| 106 | virtual const IceCandidateCollection* candidates( |
| 107 | size_t mediasection_index) const = 0; |
| 108 | // Serializes the description to SDP. |
| 109 | virtual bool ToString(std::string* out) const = 0; |
| 110 | }; |
| 111 | |
| 112 | // Creates a SessionDescriptionInterface based on SDP string and the type. |
| 113 | // Returns NULL if the sdp string can't be parsed or the type is unsupported. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | // |error| can be NULL if doesn't care about the failure reason. |
| 115 | SessionDescriptionInterface* CreateSessionDescription(const std::string& type, |
| 116 | const std::string& sdp, |
| 117 | SdpParseError* error); |
| 118 | |
| 119 | // Jsep CreateOffer and CreateAnswer callback interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 120 | class CreateSessionDescriptionObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | public: |
| 122 | // The implementation of the CreateSessionDescriptionObserver takes |
| 123 | // the ownership of the |desc|. |
| 124 | virtual void OnSuccess(SessionDescriptionInterface* desc) = 0; |
| 125 | virtual void OnFailure(const std::string& error) = 0; |
| 126 | |
| 127 | protected: |
| 128 | ~CreateSessionDescriptionObserver() {} |
| 129 | }; |
| 130 | |
| 131 | // Jsep SetLocalDescription and SetRemoteDescription callback interface. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 132 | class SetSessionDescriptionObserver : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 133 | public: |
| 134 | virtual void OnSuccess() = 0; |
| 135 | virtual void OnFailure(const std::string& error) = 0; |
| 136 | |
| 137 | protected: |
| 138 | ~SetSessionDescriptionObserver() {} |
| 139 | }; |
| 140 | |
| 141 | } // namespace webrtc |
| 142 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 143 | #endif // WEBRTC_API_JSEP_H_ |