henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "api/jsepicecandidate.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 12 | |
| 13 | #include <vector> |
| 14 | |
tzik | cdb87f1 | 2018-08-15 08:28:35 | [diff] [blame] | 15 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "pc/webrtcsdp.h" |
| 17 | #include "rtc_base/stringencode.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 22 | int sdp_mline_index, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 23 | 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 Anton | 27ab0e5 | 2018-07-23 22:11:53 | [diff] [blame] | 33 | std::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.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 41 | JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, |
| 42 | int sdp_mline_index) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 43 | : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 44 | |
| 45 | JsepIceCandidate::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 Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 50 | candidate_(candidate) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 51 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 52 | JsepIceCandidate::~JsepIceCandidate() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 53 | |
| 54 | bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) { |
| 55 | return SdpDeserializeCandidate(sdp, this, err); |
| 56 | } |
| 57 | |
| 58 | bool JsepIceCandidate::ToString(std::string* out) const { |
| 59 | if (!out) |
| 60 | return false; |
| 61 | *out = SdpSerializeCandidate(*this); |
| 62 | return !out->empty(); |
| 63 | } |
| 64 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 65 | } // namespace webrtc |