blob: d19ae3c7d0a5d9c3db1872de5be403a7ff6b7bed [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
deadbeefb10f32f2017-02-08 01:38:21 -080011// 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.org28e20752013-07-10 00:45:36 +000019
Henrik Kjellander15583c12016-02-10 10:53:12 +010020#ifndef WEBRTC_API_JSEP_H_
21#define WEBRTC_API_JSEP_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022
pbos9baddf22017-01-02 06:44:41 -080023#include <stddef.h>
24
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025#include <string>
26#include <vector>
27
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000028#include "webrtc/base/refcount.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30namespace cricket {
tommi6f59a4f2016-03-11 14:05:09 -080031class Candidate;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070032class SessionDescription;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033} // namespace cricket
34
35namespace webrtc {
36
37struct 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.
deadbeefb10f32f2017-02-08 01:38:21 -080046//
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047// 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.
deadbeefb10f32f2017-02-08 01:38:21 -080049//
50// An instance can be created by CreateIceCandidate.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051class IceCandidateInterface {
52 public:
53 virtual ~IceCandidateInterface() {}
deadbeefb10f32f2017-02-08 01:38:21 -080054 // 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.org28e20752013-07-10 00:45:36 +000056 virtual std::string sdp_mid() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -080057 // 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.org28e20752013-07-10 00:45:36 +000059 virtual int sdp_mline_index() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -080060 // Only for use internally.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 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.
deadbeefb10f32f2017-02-08 01:38:21 -080068// |error| may be NULL.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
70 int sdp_mline_index,
71 const std::string& sdp,
72 SdpParseError* error);
73
deadbeefb10f32f2017-02-08 01:38:21 -080074// This class represents a collection of candidates for a specific m= section.
75// Used in SessionDescriptionInterface.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076class 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
deadbeefb10f32f2017-02-08 01:38:21 -080085// 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.org28e20752013-07-10 00:45:36 +000091class 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() {}
deadbeefb10f32f2017-02-08 01:38:21 -080099
100 // Only for use internally.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 virtual cricket::SessionDescription* description() = 0;
102 virtual const cricket::SessionDescription* description() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800103
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 // 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;
deadbeefb10f32f2017-02-08 01:38:21 -0800108
109 // kOffer/kPrAnswer/kAnswer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 virtual std::string type() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800111
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 // Adds the specified candidate to the description.
deadbeefb10f32f2017-02-08 01:38:21 -0800113 //
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 // Ownership is not transferred.
deadbeefb10f32f2017-02-08 01:38:21 -0800115 //
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.org28e20752013-07-10 00:45:36 +0000119 virtual bool AddCandidate(const IceCandidateInterface* candidate) = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800120
121 // Removes the candidates from the description, if found.
122 //
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700123 // Returns the number of candidates removed.
124 virtual size_t RemoveCandidates(
125 const std::vector<cricket::Candidate>& candidates) { return 0; }
126
deadbeefb10f32f2017-02-08 01:38:21 -0800127 // Returns the number of m= sections in the session description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128 virtual size_t number_of_mediasections() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800129
130 // Returns a collection of all candidates that belong to a certain m=
131 // section.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 virtual const IceCandidateCollection* candidates(
133 size_t mediasection_index) const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800134
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 // Serializes the description to SDP.
136 virtual bool ToString(std::string* out) const = 0;
137};
138
deadbeefb10f32f2017-02-08 01:38:21 -0800139// Creates a SessionDescriptionInterface based on the SDP string and the type.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140// Returns NULL if the sdp string can't be parsed or the type is unsupported.
deadbeefb10f32f2017-02-08 01:38:21 -0800141// |error| may be NULL.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142SessionDescriptionInterface* CreateSessionDescription(const std::string& type,
143 const std::string& sdp,
144 SdpParseError* error);
145
deadbeefb10f32f2017-02-08 01:38:21 -0800146// CreateOffer and CreateAnswer callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147class CreateSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 public:
deadbeefb10f32f2017-02-08 01:38:21 -0800149 // 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.org28e20752013-07-10 00:45:36 +0000152 virtual void OnSuccess(SessionDescriptionInterface* desc) = 0;
153 virtual void OnFailure(const std::string& error) = 0;
154
155 protected:
156 ~CreateSessionDescriptionObserver() {}
157};
158
deadbeefb10f32f2017-02-08 01:38:21 -0800159// SetLocalDescription and SetRemoteDescription callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000160class SetSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 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 Kjellander15583c12016-02-10 10:53:12 +0100171#endif // WEBRTC_API_JSEP_H_