blob: 8f47a102e779df5579535b6d9fcee0b822ea5943 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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:369 */
10
deadbeefb10f32f2017-02-08 09:38:2111// 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:3613
Steve Anton10542f22019-01-11 17:11:0014#ifndef API_JSEP_ICE_CANDIDATE_H_
15#define API_JSEP_ICE_CANDIDATE_H_
henrike@webrtc.org28e20752013-07-10 00:45:3616
Yves Gerey988cc082018-10-23 10:03:0117#include <stddef.h>
Jonas Olssona4d87372019-07-05 17:08:3318
Steve Anton8e967df2019-07-31 01:07:4019#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3620#include <string>
oprypin803dc292017-02-01 09:55:5921#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:3622
Patrik Höglunde2d6a062017-10-05 12:53:3323#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "api/jsep.h"
Mirko Bonadei66e76792019-04-02 09:33:5925#include "rtc_base/system/rtc_export.h"
henrike@webrtc.org28e20752013-07-10 00:45:3626
27namespace webrtc {
28
deadbeefb10f32f2017-02-08 09:38:2129// Implementation of IceCandidateInterface.
Mirko Bonadei66e76792019-04-02 09:33:5930class RTC_EXPORT JsepIceCandidate : public IceCandidateInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3631 public:
32 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
Yves Gerey665174f2018-06-19 13:03:0533 JsepIceCandidate(const std::string& sdp_mid,
34 int sdp_mline_index,
henrike@webrtc.org28e20752013-07-10 00:45:3635 const cricket::Candidate& candidate);
Harald Alvestrandfc6b8712021-01-05 10:51:0836 JsepIceCandidate(const JsepIceCandidate&) = delete;
37 JsepIceCandidate& operator=(const JsepIceCandidate&) = delete;
Mirko Bonadei2ffed6d2018-07-20 09:09:3238 ~JsepIceCandidate() override;
Artem Titov0e61fdd2021-07-25 19:50:1439 // `err` may be null.
henrike@webrtc.org28e20752013-07-10 00:45:3640 bool Initialize(const std::string& sdp, SdpParseError* err);
41 void SetCandidate(const cricket::Candidate& candidate) {
42 candidate_ = candidate;
43 }
44
Mirko Bonadei2ffed6d2018-07-20 09:09:3245 std::string sdp_mid() const override;
46 int sdp_mline_index() const override;
47 const cricket::Candidate& candidate() const override;
henrike@webrtc.org28e20752013-07-10 00:45:3648
Mirko Bonadei2ffed6d2018-07-20 09:09:3249 std::string server_url() const override;
zhihuangd7e771d2017-02-16 19:29:3950
Mirko Bonadei2ffed6d2018-07-20 09:09:3251 bool ToString(std::string* out) const override;
henrike@webrtc.org28e20752013-07-10 00:45:3652
53 private:
54 std::string sdp_mid_;
55 int sdp_mline_index_;
56 cricket::Candidate candidate_;
henrike@webrtc.org28e20752013-07-10 00:45:3657};
58
deadbeefb10f32f2017-02-08 09:38:2159// Implementation of IceCandidateCollection which stores JsepIceCandidates.
henrike@webrtc.org28e20752013-07-10 00:45:3660class JsepCandidateCollection : public IceCandidateCollection {
61 public:
Mirko Bonadei2ffed6d2018-07-20 09:09:3262 JsepCandidateCollection();
deadbeef9d3584c2016-02-17 01:54:1063 // Move constructor is defined so that a vector of JsepCandidateCollections
64 // can be resized.
Mirko Bonadei2ffed6d2018-07-20 09:09:3265 JsepCandidateCollection(JsepCandidateCollection&& o);
Byoungchan Leec065e732022-01-18 00:35:4866
67 JsepCandidateCollection(const JsepCandidateCollection&) = delete;
68 JsepCandidateCollection& operator=(const JsepCandidateCollection&) = delete;
69
Harald Alvestrandfc6b8712021-01-05 10:51:0870 // Returns a copy of the candidate collection.
71 JsepCandidateCollection Clone() const;
Mirko Bonadei2ffed6d2018-07-20 09:09:3272 size_t count() const override;
73 bool HasCandidate(const IceCandidateInterface* candidate) const override;
henrike@webrtc.org28e20752013-07-10 00:45:3674 // Adds and takes ownership of the JsepIceCandidate.
deadbeefb10f32f2017-02-08 09:38:2175 // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is
76 // more clear.
Mirko Bonadei2ffed6d2018-07-20 09:09:3277 virtual void add(JsepIceCandidate* candidate);
78 const IceCandidateInterface* at(size_t index) const override;
Honghai Zhang7fb69db2016-03-14 18:59:1879 // Removes the candidate that has a matching address and protocol.
deadbeefb10f32f2017-02-08 09:38:2180 //
Honghai Zhang7fb69db2016-03-14 18:59:1881 // Returns the number of candidates that were removed.
82 size_t remove(const cricket::Candidate& candidate);
henrike@webrtc.org28e20752013-07-10 00:45:3683
84 private:
Steve Anton8e967df2019-07-31 01:07:4085 std::vector<std::unique_ptr<JsepIceCandidate>> candidates_;
henrike@webrtc.org28e20752013-07-10 00:45:3686};
87
88} // namespace webrtc
89
Steve Anton10542f22019-01-11 17:11:0090#endif // API_JSEP_ICE_CANDIDATE_H_