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