blob: f06863765c911b81d3c0b76708750a598706e59d [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#ifndef WEBRTC_API_JSEPICECANDIDATE_H_
15#define WEBRTC_API_JSEPICECANDIDATE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
17#include <string>
oprypin803dc292017-02-01 01:55:59 -080018#include <utility>
19#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020
Henrik Kjellander15583c12016-02-10 10:53:12 +010021#include "webrtc/api/jsep.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000022#include "webrtc/base/constructormagic.h"
kjellandera96e2d72016-02-04 23:52:28 -080023#include "webrtc/p2p/base/candidate.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
25namespace webrtc {
26
deadbeefb10f32f2017-02-08 01:38:21 -080027// Implementation of IceCandidateInterface.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028class 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();
deadbeefb10f32f2017-02-08 01:38:21 -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
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
46 virtual bool ToString(std::string* out) const;
47
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:
deadbeef9d3584c2016-02-16 17:54:10 -080059 JsepCandidateCollection() {}
60 // Move constructor is defined so that a vector of JsepCandidateCollections
61 // can be resized.
62 JsepCandidateCollection(JsepCandidateCollection&& o)
63 : candidates_(std::move(o.candidates_)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 ~JsepCandidateCollection();
65 virtual size_t count() const {
66 return candidates_.size();
67 }
68 virtual bool HasCandidate(const IceCandidateInterface* candidate) const;
69 // 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 virtual void add(JsepIceCandidate* candidate) {
73 candidates_.push_back(candidate);
74 }
75 virtual const IceCandidateInterface* at(size_t index) const {
76 return candidates_[index];
77 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -070078 // Removes the candidate that has a matching address and protocol.
deadbeefb10f32f2017-02-08 01:38:21 -080079 //
Honghai Zhang7fb69db2016-03-14 11:59:18 -070080 // Returns the number of candidates that were removed.
81 size_t remove(const cricket::Candidate& candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
83 private:
84 std::vector<JsepIceCandidate*> candidates_;
deadbeef9d3584c2016-02-16 17:54:10 -080085
86 RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087};
88
89} // namespace webrtc
90
Henrik Kjellander15583c12016-02-10 10:53:12 +010091#endif // WEBRTC_API_JSEPICECANDIDATE_H_