blob: e11a2ade9ad92712e4784c0f4420d2d1247d04c6 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
11// Interfaces matching the draft-ietf-rtcweb-jsep-01.
12
Henrik Kjellander15583c12016-02-10 10:53:12 +010013#ifndef WEBRTC_API_JSEP_H_
14#define WEBRTC_API_JSEP_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
16#include <string>
17#include <vector>
18
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000019#include "webrtc/base/basictypes.h"
20#include "webrtc/base/refcount.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22namespace cricket {
tommi6f59a4f2016-03-11 14:05:09 -080023class Candidate;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070024class SessionDescription;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025} // namespace cricket
26
27namespace webrtc {
28
29struct 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.
40class 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.org28e20752013-07-10 00:45:36 +000057// |error| can be NULL if doesn't care about the failure reason.
58IceCandidateInterface* 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.
66class 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.
78class 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 Zhang7fb69db2016-03-14 11:59:18 -070098 // 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.org28e20752013-07-10 00:45:36 +0000103 // 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.org28e20752013-07-10 00:45:36 +0000114// |error| can be NULL if doesn't care about the failure reason.
115SessionDescriptionInterface* CreateSessionDescription(const std::string& type,
116 const std::string& sdp,
117 SdpParseError* error);
118
119// Jsep CreateOffer and CreateAnswer callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000120class CreateSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 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.orgd4e598d2014-07-29 17:36:52 +0000132class SetSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 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 Kjellander15583c12016-02-10 10:53:12 +0100143#endif // WEBRTC_API_JSEP_H_