blob: 40e2783457e7a56ff6d36c79962c1b0cd79ec656 [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// TODO(deadbeef): Move this out of api/; it's an implementation detail and
12// shouldn't be used externally.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Anton10542f22019-01-11 09:11:00 -080014#ifndef API_JSEP_ICE_CANDIDATE_H_
15#define API_JSEP_ICE_CANDIDATE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
Yves Gerey988cc082018-10-23 12:03:01 +020017#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020018
Steve Anton8e967df2019-07-30 18:07:40 -070019#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <string>
oprypin803dc292017-02-01 01:55:59 -080021#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022
Patrik Höglunde2d6a062017-10-05 14:53:33 +020023#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "rtc_base/constructor_magic.h"
Mirko Bonadei66e76792019-04-02 11:33:59 +020026#include "rtc_base/system/rtc_export.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28namespace webrtc {
29
deadbeefb10f32f2017-02-08 01:38:21 -080030// Implementation of IceCandidateInterface.
Mirko Bonadei66e76792019-04-02 11:33:59 +020031class RTC_EXPORT JsepIceCandidate : public IceCandidateInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 public:
33 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
Yves Gerey665174f2018-06-19 15:03:05 +020034 JsepIceCandidate(const std::string& sdp_mid,
35 int sdp_mline_index,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036 const cricket::Candidate& candidate);
Harald Alvestrandfc6b8712021-01-05 10:51:08 +000037 JsepIceCandidate(const JsepIceCandidate&) = delete;
38 JsepIceCandidate& operator=(const JsepIceCandidate&) = delete;
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020039 ~JsepIceCandidate() override;
Artem Titov0e61fdd2021-07-25 21:50:14 +020040 // `err` may be null.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041 bool Initialize(const std::string& sdp, SdpParseError* err);
42 void SetCandidate(const cricket::Candidate& candidate) {
43 candidate_ = candidate;
44 }
45
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020046 std::string sdp_mid() const override;
47 int sdp_mline_index() const override;
48 const cricket::Candidate& candidate() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020050 std::string server_url() const override;
zhihuangd7e771d2017-02-16 11:29:39 -080051
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020052 bool ToString(std::string* out) const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
54 private:
55 std::string sdp_mid_;
56 int sdp_mline_index_;
57 cricket::Candidate candidate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058};
59
deadbeefb10f32f2017-02-08 01:38:21 -080060// Implementation of IceCandidateCollection which stores JsepIceCandidates.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061class JsepCandidateCollection : public IceCandidateCollection {
62 public:
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020063 JsepCandidateCollection();
deadbeef9d3584c2016-02-16 17:54:10 -080064 // Move constructor is defined so that a vector of JsepCandidateCollections
65 // can be resized.
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020066 JsepCandidateCollection(JsepCandidateCollection&& o);
Harald Alvestrandfc6b8712021-01-05 10:51:08 +000067 // Returns a copy of the candidate collection.
68 JsepCandidateCollection Clone() const;
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020069 size_t count() const override;
70 bool HasCandidate(const IceCandidateInterface* candidate) const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 // Adds and takes ownership of the JsepIceCandidate.
deadbeefb10f32f2017-02-08 01:38:21 -080072 // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is
73 // more clear.
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020074 virtual void add(JsepIceCandidate* candidate);
75 const IceCandidateInterface* at(size_t index) const override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070076 // Removes the candidate that has a matching address and protocol.
deadbeefb10f32f2017-02-08 01:38:21 -080077 //
Honghai Zhang7fb69db2016-03-14 11:59:18 -070078 // Returns the number of candidates that were removed.
79 size_t remove(const cricket::Candidate& candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
81 private:
Steve Anton8e967df2019-07-30 18:07:40 -070082 std::vector<std::unique_ptr<JsepIceCandidate>> candidates_;
deadbeef9d3584c2016-02-16 17:54:10 -080083
84 RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085};
86
87} // namespace webrtc
88
Steve Anton10542f22019-01-11 09:11:00 -080089#endif // API_JSEP_ICE_CANDIDATE_H_