blob: 277f1bab4fff10d384f7d13a74fae3a8d48a78be [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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "api/jsepicecandidate.h"
henrike@webrtc.org28e20752013-07-10 00:45:3612
13#include <vector>
14
tzikcdb87f12018-08-15 08:28:3515#include "absl/memory/memory.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "pc/webrtcsdp.h"
17#include "rtc_base/stringencode.h"
henrike@webrtc.org28e20752013-07-10 00:45:3618
19namespace webrtc {
20
21IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
22 int sdp_mline_index,
henrike@webrtc.org28e20752013-07-10 00:45:3623 const std::string& sdp,
24 SdpParseError* error) {
25 JsepIceCandidate* jsep_ice = new JsepIceCandidate(sdp_mid, sdp_mline_index);
26 if (!jsep_ice->Initialize(sdp, error)) {
27 delete jsep_ice;
28 return NULL;
29 }
30 return jsep_ice;
31}
32
Steve Anton27ab0e52018-07-23 22:11:5333std::unique_ptr<IceCandidateInterface> CreateIceCandidate(
34 const std::string& sdp_mid,
35 int sdp_mline_index,
36 const cricket::Candidate& candidate) {
37 return absl::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index,
38 candidate);
39}
40
henrike@webrtc.org28e20752013-07-10 00:45:3641JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
42 int sdp_mline_index)
Yves Gerey665174f2018-06-19 13:03:0543 : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {}
henrike@webrtc.org28e20752013-07-10 00:45:3644
45JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
46 int sdp_mline_index,
47 const cricket::Candidate& candidate)
48 : sdp_mid_(sdp_mid),
49 sdp_mline_index_(sdp_mline_index),
Yves Gerey665174f2018-06-19 13:03:0550 candidate_(candidate) {}
henrike@webrtc.org28e20752013-07-10 00:45:3651
Yves Gerey665174f2018-06-19 13:03:0552JsepIceCandidate::~JsepIceCandidate() {}
henrike@webrtc.org28e20752013-07-10 00:45:3653
54bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) {
55 return SdpDeserializeCandidate(sdp, this, err);
56}
57
58bool JsepIceCandidate::ToString(std::string* out) const {
59 if (!out)
60 return false;
61 *out = SdpSerializeCandidate(*this);
62 return !out->empty();
63}
64
henrike@webrtc.org28e20752013-07-10 00:45:3665} // namespace webrtc