blob: a57f8618fe1853221edd33124a0fc11906c6ecc8 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#ifndef API_JSEPICECANDIDATE_H_
15#define API_JSEPICECANDIDATE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
17#include <string>
oprypin803dc292017-02-01 01:55:59 -080018#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
Patrik Höglunde2d6a062017-10-05 14:53:33 +020020#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/jsep.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/constructormagic.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023
24namespace webrtc {
25
deadbeefb10f32f2017-02-08 01:38:21 -080026// Implementation of IceCandidateInterface.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027class JsepIceCandidate : public IceCandidateInterface {
28 public:
29 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
Yves Gerey665174f2018-06-19 15:03:05 +020030 JsepIceCandidate(const std::string& sdp_mid,
31 int sdp_mline_index,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 const cricket::Candidate& candidate);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020033 ~JsepIceCandidate() override;
deadbeef8d60a942017-02-27 14:47:33 -080034 // |err| may be null.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035 bool Initialize(const std::string& sdp, SdpParseError* err);
36 void SetCandidate(const cricket::Candidate& candidate) {
37 candidate_ = candidate;
38 }
39
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020040 std::string sdp_mid() const override;
41 int sdp_mline_index() const override;
42 const cricket::Candidate& candidate() const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020044 std::string server_url() const override;
zhihuangd7e771d2017-02-16 11:29:39 -080045
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020046 bool ToString(std::string* out) const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48 private:
49 std::string sdp_mid_;
50 int sdp_mline_index_;
51 cricket::Candidate candidate_;
52
henrikg3c089d72015-09-16 05:37:44 -070053 RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054};
55
deadbeefb10f32f2017-02-08 01:38:21 -080056// Implementation of IceCandidateCollection which stores JsepIceCandidates.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057class JsepCandidateCollection : public IceCandidateCollection {
58 public:
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020059 JsepCandidateCollection();
deadbeef9d3584c2016-02-16 17:54:10 -080060 // Move constructor is defined so that a vector of JsepCandidateCollections
61 // can be resized.
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020062 JsepCandidateCollection(JsepCandidateCollection&& o);
63 ~JsepCandidateCollection() override;
64 size_t count() const override;
65 bool HasCandidate(const IceCandidateInterface* candidate) const override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 // Adds and takes ownership of the JsepIceCandidate.
deadbeefb10f32f2017-02-08 01:38:21 -080067 // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is
68 // more clear.
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020069 virtual void add(JsepIceCandidate* candidate);
70 const IceCandidateInterface* at(size_t index) const override;
Honghai Zhang7fb69db2016-03-14 11:59:18 -070071 // Removes the candidate that has a matching address and protocol.
deadbeefb10f32f2017-02-08 01:38:21 -080072 //
Honghai Zhang7fb69db2016-03-14 11:59:18 -070073 // Returns the number of candidates that were removed.
74 size_t remove(const cricket::Candidate& candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
76 private:
77 std::vector<JsepIceCandidate*> candidates_;
deadbeef9d3584c2016-02-16 17:54:10 -080078
79 RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080};
81
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // API_JSEPICECANDIDATE_H_