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 #include "rtc_base/constructor_magic.h"
26 #include "rtc_base/deprecation.h"
27 
28 namespace cricket {
29 class SessionDescription;
30 }
31 
32 namespace webrtc {
33 
34 // Implementation of SessionDescriptionInterface.
35 class JsepSessionDescription : public SessionDescriptionInterface {
36  public:
37   explicit JsepSessionDescription(SdpType type);
38   // TODO(steveanton): Remove this once callers have switched to SdpType.
39   explicit JsepSessionDescription(const std::string& type);
40   JsepSessionDescription(
41       SdpType type,
42       std::unique_ptr<cricket::SessionDescription> description,
43       absl::string_view session_id,
44       absl::string_view session_version);
45   virtual ~JsepSessionDescription();
46 
47   // Takes ownership of |description|.
48   bool Initialize(std::unique_ptr<cricket::SessionDescription> description,
49                   const std::string& session_id,
50                   const std::string& session_version);
51 
description()52   virtual cricket::SessionDescription* description() {
53     return description_.get();
54   }
description()55   virtual const cricket::SessionDescription* description() const {
56     return description_.get();
57   }
session_id()58   virtual std::string session_id() const { return session_id_; }
session_version()59   virtual std::string session_version() const { return session_version_; }
GetType()60   virtual SdpType GetType() const { return type_; }
type()61   virtual std::string type() const { return SdpTypeToString(type_); }
62   // Allows changing the type. Used for testing.
63   virtual bool AddCandidate(const IceCandidateInterface* candidate);
64   virtual size_t RemoveCandidates(
65       const std::vector<cricket::Candidate>& candidates);
66   virtual size_t number_of_mediasections() const;
67   virtual const IceCandidateCollection* candidates(
68       size_t mediasection_index) const;
69   virtual bool ToString(std::string* out) const;
70 
71   static const int kDefaultVideoCodecId;
72   static const char kDefaultVideoCodecName[];
73 
74  private:
75   std::unique_ptr<cricket::SessionDescription> description_;
76   std::string session_id_;
77   std::string session_version_;
78   SdpType type_;
79   std::vector<JsepCandidateCollection> candidate_collection_;
80 
81   bool GetMediasectionIndex(const IceCandidateInterface* candidate,
82                             size_t* index);
83   int GetMediasectionIndex(const cricket::Candidate& candidate);
84 
85   RTC_DISALLOW_COPY_AND_ASSIGN(JsepSessionDescription);
86 };
87 
88 }  // namespace webrtc
89 
90 #endif  // API_JSEP_SESSION_DESCRIPTION_H_
91