blob: 4e4542182ab28c33a5c3c9465c3ed06cc990bee0 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "api/jsep_ice_candidate.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014
Steve Anton10542f22019-01-11 09:11:00 -080015#include "pc/webrtc_sdp.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
17namespace webrtc {
18
19IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
20 int sdp_mline_index,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021 const std::string& sdp,
22 SdpParseError* error) {
23 JsepIceCandidate* jsep_ice = new JsepIceCandidate(sdp_mid, sdp_mline_index);
24 if (!jsep_ice->Initialize(sdp, error)) {
25 delete jsep_ice;
26 return NULL;
27 }
28 return jsep_ice;
29}
30
Steve Anton27ab0e52018-07-23 15:11:53 -070031std::unique_ptr<IceCandidateInterface> CreateIceCandidate(
32 const std::string& sdp_mid,
33 int sdp_mline_index,
34 const cricket::Candidate& candidate) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +020035 return std::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index,
36 candidate);
Steve Anton27ab0e52018-07-23 15:11:53 -070037}
38
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
40 int sdp_mline_index)
Yves Gerey665174f2018-06-19 15:03:05 +020041 : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
43JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
44 int sdp_mline_index,
45 const cricket::Candidate& candidate)
46 : sdp_mid_(sdp_mid),
47 sdp_mline_index_(sdp_mline_index),
Yves Gerey665174f2018-06-19 15:03:05 +020048 candidate_(candidate) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
Yves Gerey665174f2018-06-19 15:03:05 +020050JsepIceCandidate::~JsepIceCandidate() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) {
53 return SdpDeserializeCandidate(sdp, this, err);
54}
55
56bool JsepIceCandidate::ToString(std::string* out) const {
57 if (!out)
58 return false;
59 *out = SdpSerializeCandidate(*this);
60 return !out->empty();
61}
62
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063} // namespace webrtc