• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2012 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10 
11 #include "api/jsep_ice_candidate.h"
12 
13 #include "pc/webrtc_sdp.h"
14 
15 // This file contains JsepIceCandidate-related functions that are not
16 // included in api/jsep_ice_candidate.cc. Some of these link to SDP
17 // parsing/serializing functions, which some users may not want.
18 // TODO(bugs.webrtc.org/12330): Merge the two .cc files somehow.
19 
20 namespace webrtc {
21 
CreateIceCandidate(const std::string & sdp_mid,int sdp_mline_index,const std::string & sdp,SdpParseError * error)22 IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid,
23                                           int sdp_mline_index,
24                                           const std::string& sdp,
25                                           SdpParseError* error) {
26   JsepIceCandidate* jsep_ice = new JsepIceCandidate(sdp_mid, sdp_mline_index);
27   if (!jsep_ice->Initialize(sdp, error)) {
28     delete jsep_ice;
29     return NULL;
30   }
31   return jsep_ice;
32 }
33 
CreateIceCandidate(const std::string & sdp_mid,int sdp_mline_index,const cricket::Candidate & candidate)34 std::unique_ptr<IceCandidateInterface> CreateIceCandidate(
35     const std::string& sdp_mid,
36     int sdp_mline_index,
37     const cricket::Candidate& candidate) {
38   return std::make_unique<JsepIceCandidate>(sdp_mid, sdp_mline_index,
39                                             candidate);
40 }
41 
JsepIceCandidate(const std::string & sdp_mid,int sdp_mline_index)42 JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
43                                    int sdp_mline_index)
44     : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {}
45 
JsepIceCandidate(const std::string & sdp_mid,int sdp_mline_index,const cricket::Candidate & candidate)46 JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid,
47                                    int sdp_mline_index,
48                                    const cricket::Candidate& candidate)
49     : sdp_mid_(sdp_mid),
50       sdp_mline_index_(sdp_mline_index),
51       candidate_(candidate) {}
52 
~JsepIceCandidate()53 JsepIceCandidate::~JsepIceCandidate() {}
54 
Clone() const55 JsepCandidateCollection JsepCandidateCollection::Clone() const {
56   JsepCandidateCollection new_collection;
57   for (const auto& candidate : candidates_) {
58     new_collection.candidates_.push_back(std::make_unique<JsepIceCandidate>(
59         candidate->sdp_mid(), candidate->sdp_mline_index(),
60         candidate->candidate()));
61   }
62   return new_collection;
63 }
64 
Initialize(const std::string & sdp,SdpParseError * err)65 bool JsepIceCandidate::Initialize(const std::string& sdp, SdpParseError* err) {
66   return SdpDeserializeCandidate(sdp, this, err);
67 }
68 
ToString(std::string * out) const69 bool JsepIceCandidate::ToString(std::string* out) const {
70   if (!out)
71     return false;
72   *out = SdpSerializeCandidate(*this);
73   return !out->empty();
74 }
75 
76 }  // namespace webrtc
77