blob: 0673ce128e053098bbc87c7ee264ce88d6a01ccf [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 {
23class SessionDescription;
24class Candidate;
25} // 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;
98 // Returns the number of m- lines in the session description.
99 virtual size_t number_of_mediasections() const = 0;
100 // Returns a collection of all candidates that belong to a certain m-line
101 virtual const IceCandidateCollection* candidates(
102 size_t mediasection_index) const = 0;
103 // Serializes the description to SDP.
104 virtual bool ToString(std::string* out) const = 0;
105};
106
107// Creates a SessionDescriptionInterface based on SDP string and the type.
108// Returns NULL if the sdp string can't be parsed or the type is unsupported.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109// |error| can be NULL if doesn't care about the failure reason.
110SessionDescriptionInterface* CreateSessionDescription(const std::string& type,
111 const std::string& sdp,
112 SdpParseError* error);
113
114// Jsep CreateOffer and CreateAnswer callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000115class CreateSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 public:
117 // The implementation of the CreateSessionDescriptionObserver takes
118 // the ownership of the |desc|.
119 virtual void OnSuccess(SessionDescriptionInterface* desc) = 0;
120 virtual void OnFailure(const std::string& error) = 0;
121
122 protected:
123 ~CreateSessionDescriptionObserver() {}
124};
125
126// Jsep SetLocalDescription and SetRemoteDescription callback interface.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000127class SetSessionDescriptionObserver : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128 public:
129 virtual void OnSuccess() = 0;
130 virtual void OnFailure(const std::string& error) = 0;
131
132 protected:
133 ~SetSessionDescriptionObserver() {}
134};
135
136} // namespace webrtc
137
Henrik Kjellander15583c12016-02-10 10:53:12 +0100138#endif // WEBRTC_API_JSEP_H_