blob: c49a16b4515ecd3b1feff8108177fac070324545 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28// Interfaces matching the draft-ietf-rtcweb-jsep-01.
29
Henrik Kjellander15583c12016-02-10 10:53:12 +010030#ifndef WEBRTC_API_JSEP_H_
31#define WEBRTC_API_JSEP_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33#include <string>
34#include <vector>
35
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000036#include "webrtc/base/basictypes.h"
37#include "webrtc/base/refcount.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
39namespace cricket {
40class SessionDescription;
41class Candidate;
42} // namespace cricket
43
44namespace webrtc {
45
46struct SdpParseError {
47 public:
48 // The sdp line that causes the error.
49 std::string line;
50 // Explains the error.
51 std::string description;
52};
53
54// Class representation of an ICE candidate.
55// An instance of this interface is supposed to be owned by one class at
56// a time and is therefore not expected to be thread safe.
57class IceCandidateInterface {
58 public:
59 virtual ~IceCandidateInterface() {}
60 /// If present, this contains the identierfier of the "media stream
61 // identification" as defined in [RFC 3388] for m-line this candidate is
62 // assocated with.
63 virtual std::string sdp_mid() const = 0;
64 // This indeicates the index (starting at zero) of m-line in the SDP this
65 // candidate is assocated with.
66 virtual int sdp_mline_index() const = 0;
67 virtual const cricket::Candidate& candidate() const = 0;
68 // Creates a SDP-ized form of this candidate.
69 virtual bool ToString(std::string* out) const = 0;
70};
71
72// Creates a IceCandidateInterface based on SDP string.
73// Returns NULL if the sdp string can't be parsed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074// |error| can be NULL if doesn't care about the failure reason.
75IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
76 int sdp_mline_index,
77 const std::string& sdp,
78 SdpParseError* error);
79
80// This class represents a collection of candidates for a specific m-line.
81// This class is used in SessionDescriptionInterface to represent all known
82// candidates for a certain m-line.
83class IceCandidateCollection {
84 public:
85 virtual ~IceCandidateCollection() {}
86 virtual size_t count() const = 0;
87 // Returns true if an equivalent |candidate| exist in the collection.
88 virtual bool HasCandidate(const IceCandidateInterface* candidate) const = 0;
89 virtual const IceCandidateInterface* at(size_t index) const = 0;
90};
91
92// Class representation of a Session description.
93// An instance of this interface is supposed to be owned by one class at
94// a time and is therefore not expected to be thread safe.
95class 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() {}
103 virtual cricket::SessionDescription* description() = 0;
104 virtual const cricket::SessionDescription* description() const = 0;
105 // Get the session id and session version, which are defined based on
106 // RFC 4566 for the SDP o= line.
107 virtual std::string session_id() const = 0;
108 virtual std::string session_version() const = 0;
109 virtual std::string type() const = 0;
110 // Adds the specified candidate to the description.
111 // Ownership is not transferred.
112 // Returns false if the session description does not have a media section that
113 // corresponds to the |candidate| label.
114 virtual bool AddCandidate(const IceCandidateInterface* candidate) = 0;
115 // Returns the number of m- lines in the session description.
116 virtual size_t number_of_mediasections() const = 0;
117 // Returns a collection of all candidates that belong to a certain m-line
118 virtual const IceCandidateCollection* candidates(
119 size_t mediasection_index) const = 0;
120 // Serializes the description to SDP.
121 virtual bool ToString(std::string* out) const = 0;
122};
123
124// Creates a SessionDescriptionInterface based on SDP string and the type.
125// Returns NULL if the sdp string can't be parsed or the type is unsupported.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126// |error| can be NULL if doesn't care about the failure reason.
127SessionDescriptionInterface* CreateSessionDescription(const std::string& type,
128 const std::string& sdp,
129 SdpParseError* error);
130
131// Jsep CreateOffer and CreateAnswer callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000132class CreateSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 public:
134 // The implementation of the CreateSessionDescriptionObserver takes
135 // the ownership of the |desc|.
136 virtual void OnSuccess(SessionDescriptionInterface* desc) = 0;
137 virtual void OnFailure(const std::string& error) = 0;
138
139 protected:
140 ~CreateSessionDescriptionObserver() {}
141};
142
143// Jsep SetLocalDescription and SetRemoteDescription callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000144class SetSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 public:
146 virtual void OnSuccess() = 0;
147 virtual void OnFailure(const std::string& error) = 0;
148
149 protected:
150 ~SetSessionDescriptionObserver() {}
151};
152
153} // namespace webrtc
154
Henrik Kjellander15583c12016-02-10 10:53:12 +0100155#endif // WEBRTC_API_JSEP_H_