blob: 651aa7c658b86c428c3482f650375d18dcfe7841 [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
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019#include <string>
oprypin803dc292017-02-01 01:55:59 -080020#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
Patrik Höglunde2d6a062017-10-05 14:53:33 +020022#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "rtc_base/constructor_magic.h"
Mirko Bonadei66e76792019-04-02 11:33:59 +020025#include "rtc_base/system/rtc_export.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026
27namespace webrtc {
28
deadbeefb10f32f2017-02-08 01:38:21 -080029// Implementation of IceCandidateInterface.
Mirko Bonadei66e76792019-04-02 11:33:59 +020030class RTC_EXPORT JsepIceCandidate : public IceCandidateInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031 public:
32 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
Yves Gerey665174f2018-06-19 15:03:05 +020033 JsepIceCandidate(const std::string& sdp_mid,
34 int sdp_mline_index,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035 const cricket::Candidate& candidate);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020036 ~JsepIceCandidate() override;
deadbeef8d60a942017-02-27 14:47:33 -080037 // |err| may be null.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038 bool Initialize(const std::string& sdp, SdpParseError* err);
39 void SetCandidate(const cricket::Candidate& candidate) {
40 candidate_ = candidate;
41 }
42
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020043 std::string sdp_mid() const override;
44 int sdp_mline_index() const override;
45 const cricket::Candidate& candidate() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020047 std::string server_url() const override;
zhihuangd7e771d2017-02-16 11:29:39 -080048
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020049 bool ToString(std::string* out) const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
51 private:
52 std::string sdp_mid_;
53 int sdp_mline_index_;
54 cricket::Candidate candidate_;
55
henrikg3c089d72015-09-16 05:37:44 -070056 RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057};
58
deadbeefb10f32f2017-02-08 01:38:21 -080059// Implementation of IceCandidateCollection which stores JsepIceCandidates.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060class JsepCandidateCollection : public IceCandidateCollection {
61 public:
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020062 JsepCandidateCollection();
deadbeef9d3584c2016-02-16 17:54:10 -080063 // Move constructor is defined so that a vector of JsepCandidateCollections
64 // can be resized.
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020065 JsepCandidateCollection(JsepCandidateCollection&& o);
66 ~JsepCandidateCollection() override;
67 size_t count() const override;
68 bool HasCandidate(const IceCandidateInterface* candidate) const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 // Adds and takes ownership of the JsepIceCandidate.
deadbeefb10f32f2017-02-08 01:38:21 -080070 // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is
71 // more clear.
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020072 virtual void add(JsepIceCandidate* candidate);
73 const IceCandidateInterface* at(size_t index) const override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070074 // Removes the candidate that has a matching address and protocol.
deadbeefb10f32f2017-02-08 01:38:21 -080075 //
Honghai Zhang7fb69db2016-03-14 11:59:18 -070076 // Returns the number of candidates that were removed.
77 size_t remove(const cricket::Candidate& candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
79 private:
80 std::vector<JsepIceCandidate*> candidates_;
deadbeef9d3584c2016-02-16 17:54:10 -080081
82 RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083};
84
85} // namespace webrtc
86
Steve Anton10542f22019-01-11 09:11:00 -080087#endif // API_JSEP_ICE_CANDIDATE_H_