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 // TODO(deadbeef): Move this out of api/; it's an implementation detail and 12 // shouldn't be used externally. 13 14 #ifndef API_JSEP_SESSION_DESCRIPTION_H_ 15 #define API_JSEP_SESSION_DESCRIPTION_H_ 16 17 #include <memory> 18 #include <string> 19 #include <vector> 20 21 #include "absl/strings/string_view.h" 22 #include "api/candidate.h" 23 #include "api/jsep.h" 24 #include "api/jsep_ice_candidate.h" 25 26 namespace cricket { 27 class SessionDescription; 28 } 29 30 namespace webrtc { 31 32 // Implementation of SessionDescriptionInterface. 33 class JsepSessionDescription : public SessionDescriptionInterface { 34 public: 35 explicit JsepSessionDescription(SdpType type); 36 // TODO(steveanton): Remove this once callers have switched to SdpType. 37 explicit JsepSessionDescription(const std::string& type); 38 JsepSessionDescription( 39 SdpType type, 40 std::unique_ptr<cricket::SessionDescription> description, 41 absl::string_view session_id, 42 absl::string_view session_version); 43 virtual ~JsepSessionDescription(); 44 45 JsepSessionDescription(const JsepSessionDescription&) = delete; 46 JsepSessionDescription& operator=(const JsepSessionDescription&) = delete; 47 48 // Takes ownership of `description`. 49 bool Initialize(std::unique_ptr<cricket::SessionDescription> description, 50 const std::string& session_id, 51 const std::string& session_version); 52 53 virtual std::unique_ptr<SessionDescriptionInterface> Clone() const; 54 description()55 virtual cricket::SessionDescription* description() { 56 return description_.get(); 57 } description()58 virtual const cricket::SessionDescription* description() const { 59 return description_.get(); 60 } session_id()61 virtual std::string session_id() const { return session_id_; } session_version()62 virtual std::string session_version() const { return session_version_; } GetType()63 virtual SdpType GetType() const { return type_; } type()64 virtual std::string type() const { return SdpTypeToString(type_); } 65 // Allows changing the type. Used for testing. 66 virtual bool AddCandidate(const IceCandidateInterface* candidate); 67 virtual size_t RemoveCandidates( 68 const std::vector<cricket::Candidate>& candidates); 69 virtual size_t number_of_mediasections() const; 70 virtual const IceCandidateCollection* candidates( 71 size_t mediasection_index) const; 72 virtual bool ToString(std::string* out) const; 73 74 static const int kDefaultVideoCodecId; 75 static const char kDefaultVideoCodecName[]; 76 77 private: 78 std::unique_ptr<cricket::SessionDescription> description_; 79 std::string session_id_; 80 std::string session_version_; 81 SdpType type_; 82 std::vector<JsepCandidateCollection> candidate_collection_; 83 84 bool GetMediasectionIndex(const IceCandidateInterface* candidate, 85 size_t* index); 86 int GetMediasectionIndex(const cricket::Candidate& candidate); 87 }; 88 89 } // namespace webrtc 90 91 #endif // API_JSEP_SESSION_DESCRIPTION_H_ 92