blob: 65a7446af6c7b05d31c44d4aab6f41d94128b470 [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>
17
Henrik Kjellander15583c12016-02-10 10:53:12 +010018#include "webrtc/api/jsep.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000019#include "webrtc/base/constructormagic.h"
kjellandera96e2d72016-02-04 23:52:28 -080020#include "webrtc/p2p/base/candidate.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22namespace webrtc {
23
24class JsepIceCandidate : public IceCandidateInterface {
25 public:
26 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index);
27 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
28 const cricket::Candidate& candidate);
29 ~JsepIceCandidate();
30 // |error| can be NULL if don't care about the failure reason.
31 bool Initialize(const std::string& sdp, SdpParseError* err);
32 void SetCandidate(const cricket::Candidate& candidate) {
33 candidate_ = candidate;
34 }
35
36 virtual std::string sdp_mid() const { return sdp_mid_; }
37 virtual int sdp_mline_index() const { return sdp_mline_index_; }
38 virtual const cricket::Candidate& candidate() const {
39 return candidate_;
40 }
41
42 virtual bool ToString(std::string* out) const;
43
44 private:
45 std::string sdp_mid_;
46 int sdp_mline_index_;
47 cricket::Candidate candidate_;
48
henrikg3c089d72015-09-16 05:37:44 -070049 RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050};
51
52// Implementation of IceCandidateCollection.
53// This implementation stores JsepIceCandidates.
54class JsepCandidateCollection : public IceCandidateCollection {
55 public:
56 ~JsepCandidateCollection();
57 virtual size_t count() const {
58 return candidates_.size();
59 }
60 virtual bool HasCandidate(const IceCandidateInterface* candidate) const;
61 // Adds and takes ownership of the JsepIceCandidate.
62 virtual void add(JsepIceCandidate* candidate) {
63 candidates_.push_back(candidate);
64 }
65 virtual const IceCandidateInterface* at(size_t index) const {
66 return candidates_[index];
67 }
68
69 private:
70 std::vector<JsepIceCandidate*> candidates_;
71};
72
73} // namespace webrtc
74
Henrik Kjellander15583c12016-02-10 10:53:12 +010075#endif // WEBRTC_API_JSEPICECANDIDATE_H_