henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "api/jsep_ice_candidate.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 15 | #include "pc/webrtc_sdp.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 20 | int sdp_mline_index, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | 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 Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 31 | std::unique_ptr<IceCandidateInterface> CreateIceCandidate( |
| 32 | const std::string& sdp_mid, |
| 33 | int sdp_mline_index, |
| 34 | const cricket::Candidate& candidate) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 35 | return std::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index, |
| 36 | candidate); |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 37 | } |
| 38 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, |
| 40 | int sdp_mline_index) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 41 | : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
| 43 | JsepIceCandidate::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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 48 | candidate_(candidate) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 50 | JsepIceCandidate::~JsepIceCandidate() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | |
| 52 | bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) { |
| 53 | return SdpDeserializeCandidate(sdp, this, err); |
| 54 | } |
| 55 | |
| 56 | bool JsepIceCandidate::ToString(std::string* out) const { |
| 57 | if (!out) |
| 58 | return false; |
| 59 | *out = SdpSerializeCandidate(*this); |
| 60 | return !out->empty(); |
| 61 | } |
| 62 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | } // namespace webrtc |