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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/jsepicecandidate.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <vector> |
| 14 | |
tzik | cdb87f1 | 2018-08-15 17:28:35 +0900 | [diff] [blame] | 15 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "pc/webrtcsdp.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 21 | int sdp_mline_index, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | const std::string& sdp, |
| 23 | SdpParseError* error) { |
| 24 | JsepIceCandidate* jsep_ice = new JsepIceCandidate(sdp_mid, sdp_mline_index); |
| 25 | if (!jsep_ice->Initialize(sdp, error)) { |
| 26 | delete jsep_ice; |
| 27 | return NULL; |
| 28 | } |
| 29 | return jsep_ice; |
| 30 | } |
| 31 | |
Steve Anton | 27ab0e5 | 2018-07-23 15:11:53 -0700 | [diff] [blame] | 32 | std::unique_ptr<IceCandidateInterface> CreateIceCandidate( |
| 33 | const std::string& sdp_mid, |
| 34 | int sdp_mline_index, |
| 35 | const cricket::Candidate& candidate) { |
| 36 | return absl::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index, |
| 37 | candidate); |
| 38 | } |
| 39 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, |
| 41 | int sdp_mline_index) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 42 | : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
| 44 | JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, |
| 45 | int sdp_mline_index, |
| 46 | const cricket::Candidate& candidate) |
| 47 | : sdp_mid_(sdp_mid), |
| 48 | sdp_mline_index_(sdp_mline_index), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 49 | candidate_(candidate) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 51 | JsepIceCandidate::~JsepIceCandidate() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | |
| 53 | bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) { |
| 54 | return SdpDeserializeCandidate(sdp, this, err); |
| 55 | } |
| 56 | |
| 57 | bool JsepIceCandidate::ToString(std::string* out) const { |
| 58 | if (!out) |
| 59 | return false; |
| 60 | *out = SdpSerializeCandidate(*this); |
| 61 | return !out->empty(); |
| 62 | } |
| 63 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | } // namespace webrtc |