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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "api/jsep_ice_candidate.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 14 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 15 | #include "pc/webrtc_sdp.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 16 | |
Harald Alvestrand | fc6b871 | 2021-01-05 10:51:08 | [diff] [blame] | 17 | // This file contains JsepIceCandidate-related functions that are not |
| 18 | // included in api/jsep_ice_candidate.cc. Some of these link to SDP |
| 19 | // parsing/serializing functions, which some users may not want. |
| 20 | // TODO(bugs.webrtc.org/12330): Merge the two .cc files somehow. |
| 21 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
| 24 | IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, |
| 25 | int sdp_mline_index, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 26 | const std::string& sdp, |
| 27 | SdpParseError* error) { |
| 28 | JsepIceCandidate* jsep_ice = new JsepIceCandidate(sdp_mid, sdp_mline_index); |
| 29 | if (!jsep_ice->Initialize(sdp, error)) { |
| 30 | delete jsep_ice; |
| 31 | return NULL; |
| 32 | } |
| 33 | return jsep_ice; |
| 34 | } |
| 35 | |
Steve Anton | 27ab0e5 | 2018-07-23 22:11:53 | [diff] [blame] | 36 | std::unique_ptr<IceCandidateInterface> CreateIceCandidate( |
| 37 | const std::string& sdp_mid, |
| 38 | int sdp_mline_index, |
| 39 | const cricket::Candidate& candidate) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 40 | return std::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index, |
| 41 | candidate); |
Steve Anton | 27ab0e5 | 2018-07-23 22:11:53 | [diff] [blame] | 42 | } |
| 43 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 44 | JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, |
| 45 | int sdp_mline_index) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 46 | : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 47 | |
| 48 | JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, |
| 49 | int sdp_mline_index, |
| 50 | const cricket::Candidate& candidate) |
| 51 | : sdp_mid_(sdp_mid), |
| 52 | sdp_mline_index_(sdp_mline_index), |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 53 | candidate_(candidate) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 54 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 55 | JsepIceCandidate::~JsepIceCandidate() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 56 | |
Harald Alvestrand | fc6b871 | 2021-01-05 10:51:08 | [diff] [blame] | 57 | JsepCandidateCollection JsepCandidateCollection::Clone() const { |
| 58 | JsepCandidateCollection new_collection; |
| 59 | for (const auto& candidate : candidates_) { |
| 60 | new_collection.candidates_.push_back(std::make_unique<JsepIceCandidate>( |
| 61 | candidate->sdp_mid(), candidate->sdp_mline_index(), |
| 62 | candidate->candidate())); |
| 63 | } |
| 64 | return new_collection; |
| 65 | } |
| 66 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 67 | bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) { |
| 68 | return SdpDeserializeCandidate(sdp, this, err); |
| 69 | } |
| 70 | |
| 71 | bool JsepIceCandidate::ToString(std::string* out) const { |
| 72 | if (!out) |
| 73 | return false; |
| 74 | *out = SdpSerializeCandidate(*this); |
| 75 | return !out->empty(); |
| 76 | } |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 78 | } // namespace webrtc |