blob: dae6121eade1ec308b1cae9b46c10781f4727795 [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
Mirko Bonadei92ea95e2017-09-15 04:47:3114#ifndef API_JSEPICECANDIDATE_H_
15#define API_JSEPICECANDIDATE_H_
henrike@webrtc.org28e20752013-07-10 00:45:3616
17#include <string>
oprypin803dc292017-02-01 09:55:5918#include <utility>
19#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:3620
Patrik Höglunde2d6a062017-10-05 12:53:3321#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "api/jsep.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3123#include "rtc_base/constructormagic.h"
henrike@webrtc.org28e20752013-07-10 00:45:3624
25namespace webrtc {
26
deadbeefb10f32f2017-02-08 09:38:2127// Implementation of IceCandidateInterface.
henrike@webrtc.org28e20752013-07-10 00:45:3628class JsepIceCandidate : public IceCandidateInterface {
29 public:
30 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
31 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
32 const cricket::Candidate& candidate);
33 ~JsepIceCandidate();
deadbeef8d60a942017-02-27 22:47:3334 // |err| may be null.
henrike@webrtc.org28e20752013-07-10 00:45:3635 bool Initialize(const std::string& sdp, SdpParseError* err);
36 void SetCandidate(const cricket::Candidate& candidate) {
37 candidate_ = candidate;
38 }
39
40 virtual std::string sdp_mid() const { return sdp_mid_; }
41 virtual int sdp_mline_index() const { return sdp_mline_index_; }
42 virtual const cricket::Candidate& candidate() const {
43 return candidate_;
44 }
45
zhihuangd7e771d2017-02-16 19:29:3946 virtual std::string server_url() const { return candidate_.url(); }
47
henrike@webrtc.org28e20752013-07-10 00:45:3648 virtual bool ToString(std::string* out) const;
49
50 private:
51 std::string sdp_mid_;
52 int sdp_mline_index_;
53 cricket::Candidate candidate_;
54
henrikg3c089d72015-09-16 12:37:4455 RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate);
henrike@webrtc.org28e20752013-07-10 00:45:3656};
57
deadbeefb10f32f2017-02-08 09:38:2158// Implementation of IceCandidateCollection which stores JsepIceCandidates.
henrike@webrtc.org28e20752013-07-10 00:45:3659class JsepCandidateCollection : public IceCandidateCollection {
60 public:
deadbeef9d3584c2016-02-17 01:54:1061 JsepCandidateCollection() {}
62 // Move constructor is defined so that a vector of JsepCandidateCollections
63 // can be resized.
64 JsepCandidateCollection(JsepCandidateCollection&& o)
65 : candidates_(std::move(o.candidates_)) {}
henrike@webrtc.org28e20752013-07-10 00:45:3666 ~JsepCandidateCollection();
67 virtual size_t count() const {
68 return candidates_.size();
69 }
70 virtual bool HasCandidate(const IceCandidateInterface* candidate) const;
71 // Adds and takes ownership of the JsepIceCandidate.
deadbeefb10f32f2017-02-08 09:38:2172 // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is
73 // more clear.
henrike@webrtc.org28e20752013-07-10 00:45:3674 virtual void add(JsepIceCandidate* candidate) {
75 candidates_.push_back(candidate);
76 }
77 virtual const IceCandidateInterface* at(size_t index) const {
78 return candidates_[index];
79 }
Honghai Zhang7fb69db2016-03-14 18:59:1880 // Removes the candidate that has a matching address and protocol.
deadbeefb10f32f2017-02-08 09:38:2181 //
Honghai Zhang7fb69db2016-03-14 18:59:1882 // Returns the number of candidates that were removed.
83 size_t remove(const cricket::Candidate& candidate);
henrike@webrtc.org28e20752013-07-10 00:45:3684
85 private:
86 std::vector<JsepIceCandidate*> candidates_;
deadbeef9d3584c2016-02-17 01:54:1087
88 RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection);
henrike@webrtc.org28e20752013-07-10 00:45:3689};
90
91} // namespace webrtc
92
Mirko Bonadei92ea95e2017-09-15 04:47:3193#endif // API_JSEPICECANDIDATE_H_