xref: /aosp_15_r20/external/webrtc/test/pc/e2e/sdp/sdp_changer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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 #ifndef TEST_PC_E2E_SDP_SDP_CHANGER_H_
12 #define TEST_PC_E2E_SDP_SDP_CHANGER_H_
13 
14 #include <map>
15 #include <string>
16 #include <vector>
17 
18 #include "absl/strings/string_view.h"
19 #include "absl/types/optional.h"
20 #include "api/array_view.h"
21 #include "api/jsep.h"
22 #include "api/rtp_parameters.h"
23 #include "api/test/pclf/media_configuration.h"
24 #include "media/base/rid_description.h"
25 #include "pc/session_description.h"
26 #include "pc/simulcast_description.h"
27 
28 namespace webrtc {
29 namespace webrtc_pc_e2e {
30 
31 // Creates list of capabilities, which can be set on RtpTransceiverInterface via
32 // RtpTransceiverInterface::SetCodecPreferences(...) to negotiate use of codecs
33 // from list of `supported_codecs` which will match `video_codecs`. If flags
34 // `ulpfec` or `flexfec` set to true corresponding FEC codec will be added.
35 // FEC and RTX codecs will be added after required codecs.
36 //
37 // All codecs will be added only if they exists in the list of
38 // `supported_codecs`. If multiple codecs from this list will match
39 // `video_codecs`, then all of them will be added to the output
40 // vector and they will be added in the same order, as they were in
41 // `supported_codecs`.
42 std::vector<RtpCodecCapability> FilterVideoCodecCapabilities(
43     rtc::ArrayView<const VideoCodecConfig> video_codecs,
44     bool use_rtx,
45     bool use_ulpfec,
46     bool use_flexfec,
47     rtc::ArrayView<const RtpCodecCapability> supported_codecs);
48 
49 struct LocalAndRemoteSdp {
LocalAndRemoteSdpLocalAndRemoteSdp50   LocalAndRemoteSdp(std::unique_ptr<SessionDescriptionInterface> local_sdp,
51                     std::unique_ptr<SessionDescriptionInterface> remote_sdp)
52       : local_sdp(std::move(local_sdp)), remote_sdp(std::move(remote_sdp)) {}
53 
54   // Sdp, that should be as local description on the peer, that created it.
55   std::unique_ptr<SessionDescriptionInterface> local_sdp;
56   // Sdp, that should be set as remote description on the peer opposite to the
57   // one, who created it.
58   std::unique_ptr<SessionDescriptionInterface> remote_sdp;
59 };
60 
61 struct PatchingParams {
PatchingParamsPatchingParams62   PatchingParams(
63       bool use_conference_mode,
64       std::map<std::string, int> stream_label_to_simulcast_streams_count)
65       : use_conference_mode(use_conference_mode),
66         stream_label_to_simulcast_streams_count(
67             stream_label_to_simulcast_streams_count) {}
68 
69   bool use_conference_mode;
70   std::map<std::string, int> stream_label_to_simulcast_streams_count;
71 };
72 
73 class SignalingInterceptor {
74  public:
SignalingInterceptor(PatchingParams params)75   explicit SignalingInterceptor(PatchingParams params) : params_(params) {}
76 
77   LocalAndRemoteSdp PatchOffer(
78       std::unique_ptr<SessionDescriptionInterface> offer,
79       const VideoCodecConfig& first_codec);
80   LocalAndRemoteSdp PatchAnswer(
81       std::unique_ptr<SessionDescriptionInterface> answer,
82       const VideoCodecConfig& first_codec);
83 
84   std::vector<std::unique_ptr<IceCandidateInterface>> PatchOffererIceCandidates(
85       rtc::ArrayView<const IceCandidateInterface* const> candidates);
86   std::vector<std::unique_ptr<IceCandidateInterface>>
87   PatchAnswererIceCandidates(
88       rtc::ArrayView<const IceCandidateInterface* const> candidates);
89 
90  private:
91   // Contains information about simulcast section, that is required to perform
92   // modified offer/answer and ice candidates exchange.
93   struct SimulcastSectionInfo {
94     SimulcastSectionInfo(const std::string& mid,
95                          cricket::MediaProtocolType media_protocol_type,
96                          const std::vector<cricket::RidDescription>& rids_desc);
97 
98     const std::string mid;
99     const cricket::MediaProtocolType media_protocol_type;
100     std::vector<std::string> rids;
101     cricket::SimulcastDescription simulcast_description;
102     webrtc::RtpExtension mid_extension;
103     webrtc::RtpExtension rid_extension;
104     webrtc::RtpExtension rrid_extension;
105     cricket::TransportDescription transport_description;
106   };
107 
108   struct SignalingContext {
109     SignalingContext() = default;
110     // SignalingContext is not copyable and movable.
111     SignalingContext(SignalingContext&) = delete;
112     SignalingContext& operator=(SignalingContext&) = delete;
113     SignalingContext(SignalingContext&&) = delete;
114     SignalingContext& operator=(SignalingContext&&) = delete;
115 
116     void AddSimulcastInfo(const SimulcastSectionInfo& info);
HasSimulcastSignalingContext117     bool HasSimulcast() const { return !simulcast_infos.empty(); }
118 
119     std::vector<SimulcastSectionInfo> simulcast_infos;
120     std::map<std::string, SimulcastSectionInfo*> simulcast_infos_by_mid;
121     std::map<std::string, SimulcastSectionInfo*> simulcast_infos_by_rid;
122 
123     std::vector<std::string> mids_order;
124   };
125 
126   LocalAndRemoteSdp PatchVp8Offer(
127       std::unique_ptr<SessionDescriptionInterface> offer);
128   LocalAndRemoteSdp PatchVp9Offer(
129       std::unique_ptr<SessionDescriptionInterface> offer);
130   LocalAndRemoteSdp PatchVp8Answer(
131       std::unique_ptr<SessionDescriptionInterface> answer);
132   LocalAndRemoteSdp PatchVp9Answer(
133       std::unique_ptr<SessionDescriptionInterface> answer);
134 
135   void FillSimulcastContext(SessionDescriptionInterface* offer);
136   std::unique_ptr<cricket::SessionDescription> RestoreMediaSectionsOrder(
137       std::unique_ptr<cricket::SessionDescription> source);
138 
139   PatchingParams params_;
140   SignalingContext context_;
141 };
142 
143 }  // namespace webrtc_pc_e2e
144 }  // namespace webrtc
145 
146 #endif  // TEST_PC_E2E_SDP_SDP_CHANGER_H_
147