blob: af064315e0f99c486e5a590f904c576c424418d1 [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
11// Implements the IceCandidateInterface.
12
Henrik Kjellander15583c12016-02-10 10:53:12 +010013#ifndef WEBRTC_API_JSEPICECANDIDATE_H_
14#define WEBRTC_API_JSEPICECANDIDATE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
16#include <string>
oprypin803dc292017-02-01 01:55:59 -080017#include <utility>
18#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
Henrik Kjellander15583c12016-02-10 10:53:12 +010020#include "webrtc/api/jsep.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000021#include "webrtc/base/constructormagic.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/p2p/base/candidate.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023
24namespace webrtc {
25
26class JsepIceCandidate : public IceCandidateInterface {
27 public:
28 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
29 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
30 const cricket::Candidate& candidate);
31 ~JsepIceCandidate();
32 // |error| can be NULL if don't care about the failure reason.
33 bool Initialize(const std::string& sdp, SdpParseError* err);
34 void SetCandidate(const cricket::Candidate& candidate) {
35 candidate_ = candidate;
36 }
37
38 virtual std::string sdp_mid() const { return sdp_mid_; }
39 virtual int sdp_mline_index() const { return sdp_mline_index_; }
40 virtual const cricket::Candidate& candidate() const {
41 return candidate_;
42 }
43
44 virtual bool ToString(std::string* out) const;
45
46 private:
47 std::string sdp_mid_;
48 int sdp_mline_index_;
49 cricket::Candidate candidate_;
50
henrikg3c089d72015-09-16 05:37:44 -070051 RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052};
53
54// Implementation of IceCandidateCollection.
55// This implementation stores JsepIceCandidates.
56class JsepCandidateCollection : public IceCandidateCollection {
57 public:
deadbeef9d3584c2016-02-16 17:54:10 -080058 JsepCandidateCollection() {}
59 // Move constructor is defined so that a vector of JsepCandidateCollections
60 // can be resized.
61 JsepCandidateCollection(JsepCandidateCollection&& o)
62 : candidates_(std::move(o.candidates_)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063 ~JsepCandidateCollection();
64 virtual size_t count() const {
65 return candidates_.size();
66 }
67 virtual bool HasCandidate(const IceCandidateInterface* candidate) const;
68 // Adds and takes ownership of the JsepIceCandidate.
69 virtual void add(JsepIceCandidate* candidate) {
70 candidates_.push_back(candidate);
71 }
72 virtual const IceCandidateInterface* at(size_t index) const {
73 return candidates_[index];
74 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -070075 // Removes the candidate that has a matching address and protocol.
76 // 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
Henrik Kjellander15583c12016-02-10 10:53:12 +010087#endif // WEBRTC_API_JSEPICECANDIDATE_H_