Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | // This file contains tests that check the interaction between the |
| 12 | // PeerConnection and the underlying media engine, as well as tests that check |
| 13 | // the media-related aspects of SDP. |
| 14 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 15 | #include <algorithm> |
| 16 | #include <functional> |
| 17 | #include <iterator> |
| 18 | #include <map> |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 19 | #include <memory> |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 20 | #include <set> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 21 | #include <string> |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 22 | #include <tuple> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 23 | #include <type_traits> |
| 24 | #include <utility> |
| 25 | #include <vector> |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 26 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 27 | #include "absl/algorithm/container.h" |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 28 | #include "absl/types/optional.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 29 | #include "api/audio_options.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 30 | #include "api/jsep.h" |
| 31 | #include "api/media_types.h" |
| 32 | #include "api/peer_connection_interface.h" |
| 33 | #include "api/rtc_error.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 08:19:42 | [diff] [blame] | 34 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 35 | #include "api/rtc_event_log/rtc_event_log_factory_interface.h" |
| 36 | #include "api/rtp_parameters.h" |
| 37 | #include "api/rtp_sender_interface.h" |
| 38 | #include "api/rtp_transceiver_direction.h" |
| 39 | #include "api/rtp_transceiver_interface.h" |
| 40 | #include "api/scoped_refptr.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 08:19:42 | [diff] [blame] | 41 | #include "api/task_queue/default_task_queue_factory.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 42 | #include "api/task_queue/task_queue_factory.h" |
| 43 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 44 | #include "media/base/fake_media_engine.h" |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 45 | #include "media/base/media_channel.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 46 | #include "media/base/media_constants.h" |
| 47 | #include "media/base/media_engine.h" |
| 48 | #include "media/base/stream_params.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 49 | #include "p2p/base/fake_port_allocator.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 50 | #include "p2p/base/p2p_constants.h" |
| 51 | #include "p2p/base/port_allocator.h" |
| 52 | #include "p2p/base/transport_info.h" |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 53 | #include "pc/channel_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 54 | #include "pc/media_session.h" |
| 55 | #include "pc/peer_connection_wrapper.h" |
| 56 | #include "pc/rtp_media_utils.h" |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 57 | #include "pc/rtp_transceiver.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 58 | #include "pc/session_description.h" |
Danil Chapovalov | c63120a | 2023-11-03 10:32:24 | [diff] [blame] | 59 | #include "pc/test/enable_fake_media.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 60 | #include "pc/test/mock_peer_connection_observers.h" |
| 61 | #include "rtc_base/checks.h" |
| 62 | #include "rtc_base/rtc_certificate_generator.h" |
| 63 | #include "rtc_base/thread.h" |
| 64 | #include "test/gtest.h" |
Sameer Vijaykar | 0793ee7 | 2023-01-23 15:31:29 | [diff] [blame] | 65 | #include "test/scoped_key_value_config.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 66 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 67 | #include "pc/test/android_test_initializer.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 68 | #endif |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 69 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 70 | #include "rtc_base/virtual_socket_server.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 71 | #include "test/gmock.h" |
| 72 | |
| 73 | namespace webrtc { |
| 74 | |
| 75 | using cricket::FakeMediaEngine; |
| 76 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 77 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
| 78 | using ::testing::Bool; |
| 79 | using ::testing::Combine; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 80 | using ::testing::ElementsAre; |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 81 | using ::testing::NotNull; |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 82 | using ::testing::Values; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 83 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 84 | cricket::MediaSendChannelInterface* SendChannelInternal( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 85 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
| 86 | auto transceiver_with_internal = static_cast< |
| 87 | rtc::RefCountedObject<RtpTransceiverProxyWithInternal<RtpTransceiver>>*>( |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 88 | transceiver.get()); |
| 89 | auto transceiver_internal = |
| 90 | static_cast<RtpTransceiver*>(transceiver_with_internal->internal()); |
| 91 | return transceiver_internal->channel()->media_send_channel(); |
| 92 | } |
| 93 | |
| 94 | cricket::MediaReceiveChannelInterface* ReceiveChannelInternal( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 95 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
| 96 | auto transceiver_with_internal = static_cast< |
| 97 | rtc::RefCountedObject<RtpTransceiverProxyWithInternal<RtpTransceiver>>*>( |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 98 | transceiver.get()); |
| 99 | auto transceiver_internal = |
| 100 | static_cast<RtpTransceiver*>(transceiver_with_internal->internal()); |
| 101 | return transceiver_internal->channel()->media_receive_channel(); |
| 102 | } |
| 103 | |
| 104 | cricket::FakeVideoMediaSendChannel* VideoMediaSendChannel( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 105 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 106 | return static_cast<cricket::FakeVideoMediaSendChannel*>( |
| 107 | SendChannelInternal(transceiver)); |
| 108 | } |
| 109 | cricket::FakeVideoMediaReceiveChannel* VideoMediaReceiveChannel( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 110 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 111 | return static_cast<cricket::FakeVideoMediaReceiveChannel*>( |
| 112 | ReceiveChannelInternal(transceiver)); |
| 113 | } |
| 114 | cricket::FakeVoiceMediaSendChannel* VoiceMediaSendChannel( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 115 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 116 | return static_cast<cricket::FakeVoiceMediaSendChannel*>( |
| 117 | SendChannelInternal(transceiver)); |
| 118 | } |
| 119 | cricket::FakeVoiceMediaReceiveChannel* VoiceMediaReceiveChannel( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 120 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 121 | return static_cast<cricket::FakeVoiceMediaReceiveChannel*>( |
| 122 | ReceiveChannelInternal(transceiver)); |
| 123 | } |
| 124 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 125 | class PeerConnectionWrapperForMediaTest : public PeerConnectionWrapper { |
| 126 | public: |
| 127 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 128 | |
| 129 | FakeMediaEngine* media_engine() { return media_engine_; } |
| 130 | void set_media_engine(FakeMediaEngine* media_engine) { |
| 131 | media_engine_ = media_engine; |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | FakeMediaEngine* media_engine_; |
| 136 | }; |
| 137 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 138 | class PeerConnectionMediaBaseTest : public ::testing::Test { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 139 | protected: |
| 140 | typedef std::unique_ptr<PeerConnectionWrapperForMediaTest> WrapperPtr; |
| 141 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 142 | explicit PeerConnectionMediaBaseTest(SdpSemantics sdp_semantics) |
| 143 | : vss_(new rtc::VirtualSocketServer()), |
| 144 | main_(vss_.get()), |
| 145 | sdp_semantics_(sdp_semantics) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 146 | #ifdef WEBRTC_ANDROID |
| 147 | InitializeAndroidObjects(); |
| 148 | #endif |
| 149 | } |
| 150 | |
| 151 | WrapperPtr CreatePeerConnection() { |
| 152 | return CreatePeerConnection(RTCConfiguration()); |
| 153 | } |
| 154 | |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 155 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 156 | return CreatePeerConnection(config, std::make_unique<FakeMediaEngine>()); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | WrapperPtr CreatePeerConnection( |
| 160 | std::unique_ptr<FakeMediaEngine> media_engine) { |
| 161 | return CreatePeerConnection(RTCConfiguration(), std::move(media_engine)); |
| 162 | } |
| 163 | |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 164 | // Creates PeerConnectionFactory and PeerConnection for given configuration. |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 165 | WrapperPtr CreatePeerConnection( |
| 166 | const RTCConfiguration& config, |
| 167 | std::unique_ptr<FakeMediaEngine> media_engine) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 168 | auto* media_engine_ptr = media_engine.get(); |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 169 | |
| 170 | PeerConnectionFactoryDependencies factory_dependencies; |
| 171 | |
| 172 | factory_dependencies.network_thread = rtc::Thread::Current(); |
| 173 | factory_dependencies.worker_thread = rtc::Thread::Current(); |
| 174 | factory_dependencies.signaling_thread = rtc::Thread::Current(); |
Danil Chapovalov | 9da25bd | 2019-06-20 08:19:42 | [diff] [blame] | 175 | factory_dependencies.task_queue_factory = CreateDefaultTaskQueueFactory(); |
Danil Chapovalov | c63120a | 2023-11-03 10:32:24 | [diff] [blame] | 176 | EnableFakeMedia(factory_dependencies, std::move(media_engine)); |
Danil Chapovalov | 9da25bd | 2019-06-20 08:19:42 | [diff] [blame] | 177 | factory_dependencies.event_log_factory = |
Danil Chapovalov | 151003d | 2023-12-07 19:01:06 | [diff] [blame^] | 178 | std::make_unique<RtcEventLogFactory>(); |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 179 | |
| 180 | auto pc_factory = |
| 181 | CreateModularPeerConnectionFactory(std::move(factory_dependencies)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 182 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 183 | auto fake_port_allocator = std::make_unique<cricket::FakePortAllocator>( |
Byoungchan Lee | d58f526 | 2022-06-27 09:05:22 | [diff] [blame] | 184 | rtc::Thread::Current(), |
Sameer Vijaykar | 0793ee7 | 2023-01-23 15:31:29 | [diff] [blame] | 185 | std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get()), |
| 186 | &field_trials_); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 187 | auto observer = std::make_unique<MockPeerConnectionObserver>(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 188 | auto modified_config = config; |
| 189 | modified_config.sdp_semantics = sdp_semantics_; |
Florent Castelli | 7242440 | 2022-04-06 01:45:10 | [diff] [blame] | 190 | PeerConnectionDependencies pc_dependencies(observer.get()); |
| 191 | pc_dependencies.allocator = std::move(fake_port_allocator); |
| 192 | auto result = pc_factory->CreatePeerConnectionOrError( |
| 193 | modified_config, std::move(pc_dependencies)); |
| 194 | if (!result.ok()) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 195 | return nullptr; |
| 196 | } |
| 197 | |
Florent Castelli | 7242440 | 2022-04-06 01:45:10 | [diff] [blame] | 198 | auto pc = result.MoveValue(); |
Yves Gerey | 4e93329 | 2018-10-31 14:36:05 | [diff] [blame] | 199 | observer->SetPeerConnectionInterface(pc.get()); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 200 | auto wrapper = std::make_unique<PeerConnectionWrapperForMediaTest>( |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 201 | pc_factory, pc, std::move(observer)); |
| 202 | wrapper->set_media_engine(media_engine_ptr); |
| 203 | return wrapper; |
| 204 | } |
| 205 | |
| 206 | // Accepts the same arguments as CreatePeerConnection and adds default audio |
Piotr (Peter) Slatala | 10aeb2a | 2018-11-14 18:57:24 | [diff] [blame] | 207 | // track (but no video). |
| 208 | template <typename... Args> |
| 209 | WrapperPtr CreatePeerConnectionWithAudio(Args&&... args) { |
| 210 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 211 | if (!wrapper) { |
| 212 | return nullptr; |
| 213 | } |
| 214 | wrapper->AddAudioTrack("a"); |
| 215 | return wrapper; |
| 216 | } |
| 217 | |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 218 | // Accepts the same arguments as CreatePeerConnection and adds default video |
| 219 | // track (but no audio). |
| 220 | template <typename... Args> |
| 221 | WrapperPtr CreatePeerConnectionWithVideo(Args&&... args) { |
| 222 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 223 | if (!wrapper) { |
| 224 | return nullptr; |
| 225 | } |
| 226 | wrapper->AddVideoTrack("v"); |
| 227 | return wrapper; |
| 228 | } |
| 229 | |
Piotr (Peter) Slatala | 10aeb2a | 2018-11-14 18:57:24 | [diff] [blame] | 230 | // Accepts the same arguments as CreatePeerConnection and adds default audio |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 231 | // and video tracks. |
| 232 | template <typename... Args> |
| 233 | WrapperPtr CreatePeerConnectionWithAudioVideo(Args&&... args) { |
| 234 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 235 | if (!wrapper) { |
| 236 | return nullptr; |
| 237 | } |
| 238 | wrapper->AddAudioTrack("a"); |
| 239 | wrapper->AddVideoTrack("v"); |
| 240 | return wrapper; |
| 241 | } |
| 242 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 243 | RtpTransceiverDirection GetMediaContentDirection( |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 244 | const SessionDescriptionInterface* sdesc, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 245 | cricket::MediaType media_type) { |
| 246 | auto* content = |
| 247 | cricket::GetFirstMediaContent(sdesc->description(), media_type); |
| 248 | RTC_DCHECK(content); |
| 249 | return content->media_description()->direction(); |
| 250 | } |
| 251 | |
| 252 | bool IsUnifiedPlan() const { |
| 253 | return sdp_semantics_ == SdpSemantics::kUnifiedPlan; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 254 | } |
| 255 | |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 256 | test::ScopedKeyValueConfig field_trials_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 257 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 258 | rtc::AutoSocketServerThread main_; |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 259 | const SdpSemantics sdp_semantics_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 260 | }; |
| 261 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 262 | class PeerConnectionMediaTest |
| 263 | : public PeerConnectionMediaBaseTest, |
| 264 | public ::testing::WithParamInterface<SdpSemantics> { |
| 265 | protected: |
| 266 | PeerConnectionMediaTest() : PeerConnectionMediaBaseTest(GetParam()) {} |
| 267 | }; |
| 268 | |
| 269 | class PeerConnectionMediaTestUnifiedPlan : public PeerConnectionMediaBaseTest { |
| 270 | protected: |
| 271 | PeerConnectionMediaTestUnifiedPlan() |
| 272 | : PeerConnectionMediaBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 273 | }; |
| 274 | |
| 275 | class PeerConnectionMediaTestPlanB : public PeerConnectionMediaBaseTest { |
| 276 | protected: |
| 277 | PeerConnectionMediaTestPlanB() |
Florent Castelli | 15a38de | 2022-04-05 22:38:21 | [diff] [blame] | 278 | : PeerConnectionMediaBaseTest(SdpSemantics::kPlanB_DEPRECATED) {} |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 282 | FailToSetRemoteDescriptionIfCreateMediaChannelFails) { |
| 283 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 284 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 285 | callee->media_engine()->set_fail_create_channel(true); |
| 286 | |
| 287 | std::string error; |
| 288 | ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error)); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 289 | EXPECT_PRED_FORMAT2(AssertStartsWith, error, |
| 290 | "Failed to set remote offer sdp: Failed to create"); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 291 | } |
| 292 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 293 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 294 | FailToSetLocalDescriptionIfCreateMediaChannelFails) { |
| 295 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 296 | caller->media_engine()->set_fail_create_channel(true); |
| 297 | |
| 298 | std::string error; |
| 299 | ASSERT_FALSE(caller->SetLocalDescription(caller->CreateOffer(), &error)); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 300 | EXPECT_PRED_FORMAT2(AssertStartsWith, error, |
| 301 | "Failed to set local offer sdp: Failed to create"); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | std::vector<std::string> GetIds( |
| 305 | const std::vector<cricket::StreamParams>& streams) { |
| 306 | std::vector<std::string> ids; |
Mirko Bonadei | 649a4c2 | 2019-01-29 09:11:53 | [diff] [blame] | 307 | ids.reserve(streams.size()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 308 | for (const auto& stream : streams) { |
| 309 | ids.push_back(stream.id); |
| 310 | } |
| 311 | return ids; |
| 312 | } |
| 313 | |
| 314 | // Test that exchanging an offer and answer with each side having an audio and |
| 315 | // video stream creates the appropriate send/recv streams in the underlying |
| 316 | // media engine on both sides. |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 317 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 318 | AudioVideoOfferAnswerCreateSendRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 319 | const std::string kCallerAudioId = "caller_a"; |
| 320 | const std::string kCallerVideoId = "caller_v"; |
| 321 | const std::string kCalleeAudioId = "callee_a"; |
| 322 | const std::string kCalleeVideoId = "callee_v"; |
| 323 | |
| 324 | auto caller = CreatePeerConnection(); |
| 325 | caller->AddAudioTrack(kCallerAudioId); |
| 326 | caller->AddVideoTrack(kCallerVideoId); |
| 327 | |
| 328 | auto callee = CreatePeerConnection(); |
| 329 | callee->AddAudioTrack(kCalleeAudioId); |
| 330 | callee->AddVideoTrack(kCalleeVideoId); |
| 331 | |
| 332 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 333 | ASSERT_TRUE( |
| 334 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 335 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 336 | auto* caller_voice_send = |
| 337 | VoiceMediaSendChannel(caller->pc()->GetTransceivers()[0]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 338 | auto* caller_voice_receive = |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 339 | VoiceMediaReceiveChannel(caller->pc()->GetTransceivers()[0]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 340 | EXPECT_THAT(GetIds(caller_voice_receive->recv_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 341 | ElementsAre(kCalleeAudioId)); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 342 | EXPECT_THAT(GetIds(caller_voice_send->send_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 343 | ElementsAre(kCallerAudioId)); |
| 344 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 345 | auto* caller_video_send = |
| 346 | VideoMediaSendChannel(caller->pc()->GetTransceivers()[1]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 347 | auto* caller_video_receive = |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 348 | VideoMediaReceiveChannel(caller->pc()->GetTransceivers()[1]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 349 | EXPECT_THAT(GetIds(caller_video_receive->recv_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 350 | ElementsAre(kCalleeVideoId)); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 351 | EXPECT_THAT(GetIds(caller_video_send->send_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 352 | ElementsAre(kCallerVideoId)); |
| 353 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 354 | auto* callee_voice_send = |
| 355 | VoiceMediaSendChannel(callee->pc()->GetTransceivers()[0]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 356 | auto* callee_voice_receive = |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 357 | VoiceMediaReceiveChannel(callee->pc()->GetTransceivers()[0]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 358 | EXPECT_THAT(GetIds(callee_voice_receive->recv_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 359 | ElementsAre(kCallerAudioId)); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 360 | EXPECT_THAT(GetIds(callee_voice_send->send_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 361 | ElementsAre(kCalleeAudioId)); |
| 362 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 363 | auto* callee_video_send = |
| 364 | VideoMediaSendChannel(callee->pc()->GetTransceivers()[1]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 365 | auto* callee_video_receive = |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 366 | VideoMediaReceiveChannel(callee->pc()->GetTransceivers()[1]); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 367 | EXPECT_THAT(GetIds(callee_video_receive->recv_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 368 | ElementsAre(kCallerVideoId)); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 369 | EXPECT_THAT(GetIds(callee_video_send->send_streams()), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 370 | ElementsAre(kCalleeVideoId)); |
| 371 | } |
| 372 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 373 | // Test that stopping the caller transceivers causes the media channels on the |
| 374 | // callee to be destroyed after calling SetRemoteDescription on the generated |
| 375 | // offer. |
| 376 | // See next test for equivalent behavior with Plan B semantics. |
| 377 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 378 | StoppedRemoteTransceiversRemovesMediaChannels) { |
| 379 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 380 | auto callee = CreatePeerConnection(); |
| 381 | |
| 382 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 383 | |
| 384 | // Stop both audio and video transceivers on the caller. |
| 385 | auto transceivers = caller->pc()->GetTransceivers(); |
| 386 | ASSERT_EQ(2u, transceivers.size()); |
Harald Alvestrand | 6060df5 | 2020-08-11 07:54:02 | [diff] [blame] | 387 | transceivers[0]->StopInternal(); |
| 388 | transceivers[1]->StopInternal(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 389 | |
| 390 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 391 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 392 | ASSERT_TRUE(callee->pc()->GetTransceivers().empty()); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 393 | } |
| 394 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 395 | // Test that removing streams from a subsequent offer causes the receive streams |
| 396 | // on the callee to be removed. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 397 | // See previous test for equivalent behavior with Unified Plan semantics. |
| 398 | TEST_F(PeerConnectionMediaTestPlanB, EmptyRemoteOfferRemovesRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 399 | auto caller = CreatePeerConnection(); |
| 400 | auto caller_audio_track = caller->AddAudioTrack("a"); |
| 401 | auto caller_video_track = caller->AddVideoTrack("v"); |
| 402 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 403 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 404 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 405 | |
| 406 | // Remove both tracks from caller. |
Harald Alvestrand | 93dd763 | 2022-01-19 12:28:45 | [diff] [blame] | 407 | caller->pc()->RemoveTrackOrError(caller_audio_track); |
| 408 | caller->pc()->RemoveTrackOrError(caller_video_track); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 409 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 410 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 411 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 412 | EXPECT_TRUE(callee->pc()->GetReceivers().empty()); |
| 413 | EXPECT_EQ(2u, callee->pc()->GetSenders().size()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 414 | } |
| 415 | |
Jonas Oreland | fc1acd2 | 2018-08-24 08:58:37 | [diff] [blame] | 416 | // Test enabling of simulcast with Plan B semantics. |
| 417 | // This test creating an offer. |
| 418 | TEST_F(PeerConnectionMediaTestPlanB, SimulcastOffer) { |
| 419 | auto caller = CreatePeerConnection(); |
| 420 | auto caller_video_track = caller->AddVideoTrack("v"); |
| 421 | RTCOfferAnswerOptions options; |
| 422 | options.num_simulcast_layers = 3; |
| 423 | auto offer = caller->CreateOffer(options); |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 424 | auto* description = cricket::GetFirstMediaContent(offer->description(), |
| 425 | cricket::MEDIA_TYPE_VIDEO) |
| 426 | ->media_description(); |
Jonas Oreland | fc1acd2 | 2018-08-24 08:58:37 | [diff] [blame] | 427 | ASSERT_EQ(1u, description->streams().size()); |
| 428 | ASSERT_TRUE(description->streams()[0].get_ssrc_group("SIM")); |
| 429 | EXPECT_EQ(3u, description->streams()[0].get_ssrc_group("SIM")->ssrcs.size()); |
| 430 | |
| 431 | // Check that it actually creates simulcast aswell. |
| 432 | caller->SetLocalDescription(std::move(offer)); |
| 433 | auto senders = caller->pc()->GetSenders(); |
| 434 | ASSERT_EQ(1u, senders.size()); |
| 435 | EXPECT_EQ(cricket::MediaType::MEDIA_TYPE_VIDEO, senders[0]->media_type()); |
| 436 | EXPECT_EQ(3u, senders[0]->GetParameters().encodings.size()); |
| 437 | } |
| 438 | |
| 439 | // Test enabling of simulcast with Plan B semantics. |
| 440 | // This test creating an answer. |
| 441 | TEST_F(PeerConnectionMediaTestPlanB, SimulcastAnswer) { |
| 442 | auto caller = CreatePeerConnection(); |
| 443 | caller->AddVideoTrack("v0"); |
| 444 | auto offer = caller->CreateOffer(); |
| 445 | auto callee = CreatePeerConnection(); |
| 446 | auto callee_video_track = callee->AddVideoTrack("v1"); |
| 447 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 448 | RTCOfferAnswerOptions options; |
| 449 | options.num_simulcast_layers = 3; |
| 450 | auto answer = callee->CreateAnswer(options); |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 451 | auto* description = cricket::GetFirstMediaContent(answer->description(), |
| 452 | cricket::MEDIA_TYPE_VIDEO) |
| 453 | ->media_description(); |
Jonas Oreland | fc1acd2 | 2018-08-24 08:58:37 | [diff] [blame] | 454 | ASSERT_EQ(1u, description->streams().size()); |
| 455 | ASSERT_TRUE(description->streams()[0].get_ssrc_group("SIM")); |
| 456 | EXPECT_EQ(3u, description->streams()[0].get_ssrc_group("SIM")->ssrcs.size()); |
| 457 | |
| 458 | // Check that it actually creates simulcast aswell. |
| 459 | callee->SetLocalDescription(std::move(answer)); |
| 460 | auto senders = callee->pc()->GetSenders(); |
| 461 | ASSERT_EQ(1u, senders.size()); |
| 462 | EXPECT_EQ(cricket::MediaType::MEDIA_TYPE_VIDEO, senders[0]->media_type()); |
| 463 | EXPECT_EQ(3u, senders[0]->GetParameters().encodings.size()); |
| 464 | } |
| 465 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 466 | // Test that stopping the callee transceivers causes the media channels to be |
| 467 | // destroyed on the callee after calling SetLocalDescription on the local |
| 468 | // answer. |
| 469 | // See next test for equivalent behavior with Plan B semantics. |
| 470 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 471 | StoppedLocalTransceiversRemovesMediaChannels) { |
| 472 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 473 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 474 | |
| 475 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 476 | |
| 477 | // Stop both audio and video transceivers on the callee. |
| 478 | auto transceivers = callee->pc()->GetTransceivers(); |
| 479 | ASSERT_EQ(2u, transceivers.size()); |
Harald Alvestrand | 6060df5 | 2020-08-11 07:54:02 | [diff] [blame] | 480 | transceivers[0]->StopInternal(); |
| 481 | transceivers[1]->StopInternal(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 482 | |
| 483 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 484 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 485 | EXPECT_TRUE(callee->pc()->GetTransceivers().empty()); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 486 | } |
| 487 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 488 | // Test that removing streams from a subsequent answer causes the send streams |
| 489 | // on the callee to be removed when applied locally. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 490 | // See previous test for equivalent behavior with Unified Plan semantics. |
| 491 | TEST_F(PeerConnectionMediaTestPlanB, EmptyLocalAnswerRemovesSendStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 492 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 493 | auto callee = CreatePeerConnection(); |
| 494 | auto callee_audio_track = callee->AddAudioTrack("a"); |
| 495 | auto callee_video_track = callee->AddVideoTrack("v"); |
| 496 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 497 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 498 | |
| 499 | // Remove both tracks from callee. |
Harald Alvestrand | 93dd763 | 2022-01-19 12:28:45 | [diff] [blame] | 500 | callee->pc()->RemoveTrackOrError(callee_audio_track); |
| 501 | callee->pc()->RemoveTrackOrError(callee_video_track); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 502 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 503 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 504 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 505 | EXPECT_TRUE(callee->pc()->GetSenders().empty()); |
| 506 | EXPECT_EQ(2u, callee->pc()->GetReceivers().size()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | // Test that a new stream in a subsequent offer causes a new receive stream to |
| 510 | // be created on the callee. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 511 | TEST_P(PeerConnectionMediaTest, NewStreamInRemoteOfferAddsRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 512 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 513 | auto callee = CreatePeerConnection(); |
| 514 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 515 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 516 | |
| 517 | // Add second set of tracks to the caller. |
| 518 | caller->AddAudioTrack("a2"); |
| 519 | caller->AddVideoTrack("v2"); |
| 520 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 521 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 522 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 523 | if (IsUnifiedPlan()) { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 524 | auto a1 = VoiceMediaReceiveChannel(callee->pc()->GetTransceivers()[0]); |
| 525 | auto a2 = VoiceMediaReceiveChannel(callee->pc()->GetTransceivers()[2]); |
| 526 | auto v1 = VideoMediaReceiveChannel(callee->pc()->GetTransceivers()[1]); |
| 527 | auto v2 = VideoMediaReceiveChannel(callee->pc()->GetTransceivers()[3]); |
| 528 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 529 | ASSERT_TRUE(a1); |
| 530 | EXPECT_EQ(1u, a1->recv_streams().size()); |
| 531 | ASSERT_TRUE(a2); |
| 532 | EXPECT_EQ(1u, a2->recv_streams().size()); |
| 533 | ASSERT_TRUE(v1); |
| 534 | EXPECT_EQ(1u, v1->recv_streams().size()); |
| 535 | ASSERT_TRUE(v2); |
| 536 | EXPECT_EQ(1u, v2->recv_streams().size()); |
| 537 | } else { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 538 | EXPECT_EQ(4u, callee->pc()->GetReceivers().size()); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 539 | } |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // Test that a new stream in a subsequent answer causes a new send stream to be |
| 543 | // created on the callee when added locally. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 544 | TEST_P(PeerConnectionMediaTest, NewStreamInLocalAnswerAddsSendStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 545 | auto caller = CreatePeerConnection(); |
| 546 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 547 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 548 | RTCOfferAnswerOptions offer_options; |
| 549 | offer_options.offer_to_receive_audio = |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 550 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 551 | offer_options.offer_to_receive_video = |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 552 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 553 | RTCOfferAnswerOptions answer_options; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 554 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 555 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get(), offer_options, |
| 556 | answer_options)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 557 | |
| 558 | // Add second set of tracks to the callee. |
| 559 | callee->AddAudioTrack("a2"); |
| 560 | callee->AddVideoTrack("v2"); |
| 561 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 562 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get(), offer_options, |
| 563 | answer_options)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 564 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 565 | if (IsUnifiedPlan()) { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 566 | auto callee_voice = |
| 567 | VoiceMediaSendChannel(callee->pc()->GetTransceivers()[0]); |
| 568 | ASSERT_TRUE(callee_voice); |
| 569 | auto callee_video = |
| 570 | VideoMediaSendChannel(callee->pc()->GetTransceivers()[1]); |
| 571 | ASSERT_TRUE(callee_video); |
| 572 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 573 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 574 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 575 | } else { |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 576 | EXPECT_EQ(4u, callee->pc()->GetSenders().size()); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 577 | } |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | // A PeerConnection with no local streams and no explicit answer constraints |
| 581 | // should not reject any offered media sections. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 582 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 583 | CreateAnswerWithNoStreamsAndDefaultOptionsDoesNotReject) { |
| 584 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 585 | auto callee = CreatePeerConnection(); |
| 586 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 587 | auto answer = callee->CreateAnswer(); |
| 588 | |
| 589 | const auto* audio_content = |
| 590 | cricket::GetFirstAudioContent(answer->description()); |
| 591 | ASSERT_TRUE(audio_content); |
| 592 | EXPECT_FALSE(audio_content->rejected); |
| 593 | |
| 594 | const auto* video_content = |
| 595 | cricket::GetFirstVideoContent(answer->description()); |
| 596 | ASSERT_TRUE(video_content); |
| 597 | EXPECT_FALSE(video_content->rejected); |
| 598 | } |
| 599 | |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 600 | // Test that raw packetization is not set in the offer by default. |
| 601 | TEST_P(PeerConnectionMediaTest, RawPacketizationNotSetInOffer) { |
| 602 | std::vector<cricket::VideoCodec> fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 603 | fake_codecs.push_back(cricket::CreateVideoCodec(111, cricket::kVp8CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 604 | fake_codecs.push_back(cricket::CreateVideoRtxCodec(112, 111)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 605 | fake_codecs.push_back(cricket::CreateVideoCodec(113, cricket::kVp9CodecName)); |
| 606 | fake_codecs.push_back( |
| 607 | cricket::CreateVideoCodec(114, cricket::kH264CodecName)); |
| 608 | fake_codecs.push_back(cricket::CreateVideoCodec(115, "HEVC")); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 609 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 610 | caller_fake_engine->SetVideoCodecs(fake_codecs); |
| 611 | |
| 612 | auto caller = CreatePeerConnectionWithVideo(std::move(caller_fake_engine)); |
| 613 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 614 | auto* offer_description = |
| 615 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 616 | for (const auto& codec : offer_description->codecs()) { |
| 617 | EXPECT_EQ(codec.packetization, absl::nullopt); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // Test that raw packetization is set in the offer and answer for all |
| 622 | // video payload when raw_packetization_for_video is true. |
| 623 | TEST_P(PeerConnectionMediaTest, RawPacketizationSetInOfferAndAnswer) { |
| 624 | std::vector<cricket::VideoCodec> fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 625 | fake_codecs.push_back(cricket::CreateVideoCodec(111, cricket::kVp8CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 626 | fake_codecs.push_back(cricket::CreateVideoRtxCodec(112, 111)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 627 | fake_codecs.push_back(cricket::CreateVideoCodec(113, cricket::kVp9CodecName)); |
| 628 | fake_codecs.push_back( |
| 629 | cricket::CreateVideoCodec(114, cricket::kH264CodecName)); |
| 630 | fake_codecs.push_back(cricket::CreateVideoCodec(115, "HEVC")); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 631 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 632 | caller_fake_engine->SetVideoCodecs(fake_codecs); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 633 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 634 | callee_fake_engine->SetVideoCodecs(fake_codecs); |
| 635 | |
| 636 | RTCOfferAnswerOptions options; |
| 637 | options.raw_packetization_for_video = true; |
| 638 | |
| 639 | auto caller = CreatePeerConnectionWithVideo(std::move(caller_fake_engine)); |
| 640 | auto offer = caller->CreateOfferAndSetAsLocal(options); |
| 641 | auto* offer_description = |
| 642 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 643 | for (const auto& codec : offer_description->codecs()) { |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 644 | if (codec.IsMediaCodec()) { |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 645 | EXPECT_EQ(codec.packetization, cricket::kPacketizationParamRaw); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | auto callee = CreatePeerConnectionWithVideo(std::move(callee_fake_engine)); |
| 650 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 651 | auto answer = callee->CreateAnswerAndSetAsLocal(options); |
| 652 | auto* answer_description = |
| 653 | cricket::GetFirstVideoContentDescription(answer->description()); |
| 654 | for (const auto& codec : answer_description->codecs()) { |
Florent Castelli | 811e24a | 2023-05-31 12:35:47 | [diff] [blame] | 655 | if (codec.IsMediaCodec()) { |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 656 | EXPECT_EQ(codec.packetization, cricket::kPacketizationParamRaw); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer))); |
| 661 | } |
| 662 | |
| 663 | // Test that raw packetization is not set in the answer when |
| 664 | // raw_packetization_for_video is true if it was not set in the offer. |
| 665 | TEST_P(PeerConnectionMediaTest, |
| 666 | RawPacketizationNotSetInAnswerWhenNotSetInOffer) { |
| 667 | std::vector<cricket::VideoCodec> fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 668 | fake_codecs.push_back(cricket::CreateVideoCodec(111, cricket::kVp8CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 669 | fake_codecs.push_back(cricket::CreateVideoRtxCodec(112, 111)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 670 | fake_codecs.push_back(cricket::CreateVideoCodec(113, cricket::kVp9CodecName)); |
| 671 | fake_codecs.push_back( |
| 672 | cricket::CreateVideoCodec(114, cricket::kH264CodecName)); |
| 673 | fake_codecs.push_back(cricket::CreateVideoCodec(115, "HEVC")); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 674 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 675 | caller_fake_engine->SetVideoCodecs(fake_codecs); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 676 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 677 | callee_fake_engine->SetVideoCodecs(fake_codecs); |
| 678 | |
| 679 | RTCOfferAnswerOptions caller_options; |
| 680 | caller_options.raw_packetization_for_video = false; |
| 681 | RTCOfferAnswerOptions callee_options; |
| 682 | callee_options.raw_packetization_for_video = true; |
| 683 | |
| 684 | auto caller = CreatePeerConnectionWithVideo(std::move(caller_fake_engine)); |
| 685 | auto offer = caller->CreateOfferAndSetAsLocal(caller_options); |
| 686 | |
| 687 | auto callee = CreatePeerConnectionWithVideo(std::move(callee_fake_engine)); |
| 688 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 689 | auto answer = callee->CreateAnswerAndSetAsLocal(callee_options); |
| 690 | |
| 691 | auto* answer_description = |
| 692 | cricket::GetFirstVideoContentDescription(answer->description()); |
| 693 | for (const auto& codec : answer_description->codecs()) { |
| 694 | EXPECT_EQ(codec.packetization, absl::nullopt); |
| 695 | } |
| 696 | |
| 697 | ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer))); |
| 698 | } |
| 699 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 700 | class PeerConnectionMediaOfferDirectionTest |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 701 | : public PeerConnectionMediaBaseTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 702 | public ::testing::WithParamInterface< |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 703 | std::tuple<SdpSemantics, |
| 704 | std::tuple<bool, int, RtpTransceiverDirection>>> { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 705 | protected: |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 706 | PeerConnectionMediaOfferDirectionTest() |
| 707 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 708 | auto param = std::get<1>(GetParam()); |
| 709 | send_media_ = std::get<0>(param); |
| 710 | offer_to_receive_ = std::get<1>(param); |
| 711 | expected_direction_ = std::get<2>(param); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | bool send_media_; |
| 715 | int offer_to_receive_; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 716 | RtpTransceiverDirection expected_direction_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | // Tests that the correct direction is set on the media description according |
| 720 | // to the presence of a local media track and the offer_to_receive setting. |
| 721 | TEST_P(PeerConnectionMediaOfferDirectionTest, VerifyDirection) { |
| 722 | auto caller = CreatePeerConnection(); |
| 723 | if (send_media_) { |
| 724 | caller->AddAudioTrack("a"); |
| 725 | } |
| 726 | |
| 727 | RTCOfferAnswerOptions options; |
| 728 | options.offer_to_receive_audio = offer_to_receive_; |
| 729 | auto offer = caller->CreateOffer(options); |
| 730 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 731 | auto* content = cricket::GetFirstMediaContent(offer->description(), |
| 732 | cricket::MEDIA_TYPE_AUDIO); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 733 | if (expected_direction_ == RtpTransceiverDirection::kInactive) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 734 | EXPECT_FALSE(content); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 735 | } else { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 736 | EXPECT_EQ(expected_direction_, content->media_description()->direction()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
| 740 | // Note that in these tests, MD_INACTIVE indicates that no media section is |
| 741 | // included in the offer, not that the media direction is inactive. |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 742 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 743 | PeerConnectionMediaTest, |
| 744 | PeerConnectionMediaOfferDirectionTest, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 745 | Combine( |
Florent Castelli | 15a38de | 2022-04-05 22:38:21 | [diff] [blame] | 746 | Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan), |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 747 | Values(std::make_tuple(false, -1, RtpTransceiverDirection::kInactive), |
| 748 | std::make_tuple(false, 0, RtpTransceiverDirection::kInactive), |
| 749 | std::make_tuple(false, 1, RtpTransceiverDirection::kRecvOnly), |
| 750 | std::make_tuple(true, -1, RtpTransceiverDirection::kSendRecv), |
| 751 | std::make_tuple(true, 0, RtpTransceiverDirection::kSendOnly), |
| 752 | std::make_tuple(true, 1, RtpTransceiverDirection::kSendRecv)))); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 753 | |
| 754 | class PeerConnectionMediaAnswerDirectionTest |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 755 | : public PeerConnectionMediaBaseTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 756 | public ::testing::WithParamInterface< |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 757 | std::tuple<SdpSemantics, RtpTransceiverDirection, bool, int>> { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 758 | protected: |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 759 | PeerConnectionMediaAnswerDirectionTest() |
| 760 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 761 | offer_direction_ = std::get<1>(GetParam()); |
| 762 | send_media_ = std::get<2>(GetParam()); |
| 763 | offer_to_receive_ = std::get<3>(GetParam()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 764 | } |
| 765 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 766 | RtpTransceiverDirection offer_direction_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 767 | bool send_media_; |
| 768 | int offer_to_receive_; |
| 769 | }; |
| 770 | |
| 771 | // Tests that the direction in an answer is correct according to direction sent |
| 772 | // in the offer, the presence of a local media track on the receive side and the |
| 773 | // offer_to_receive setting. |
| 774 | TEST_P(PeerConnectionMediaAnswerDirectionTest, VerifyDirection) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 775 | if (IsUnifiedPlan() && |
| 776 | offer_to_receive_ != RTCOfferAnswerOptions::kUndefined) { |
| 777 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 778 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 779 | return; |
| 780 | } |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 781 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 782 | auto caller = CreatePeerConnection(); |
| 783 | caller->AddAudioTrack("a"); |
| 784 | |
| 785 | // Create the offer with an audio section and set its direction. |
| 786 | auto offer = caller->CreateOffer(); |
| 787 | cricket::GetFirstAudioContentDescription(offer->description()) |
| 788 | ->set_direction(offer_direction_); |
| 789 | |
| 790 | auto callee = CreatePeerConnection(); |
| 791 | if (send_media_) { |
| 792 | callee->AddAudioTrack("a"); |
| 793 | } |
| 794 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 795 | |
| 796 | // Create the answer according to the test parameters. |
| 797 | RTCOfferAnswerOptions options; |
| 798 | options.offer_to_receive_audio = offer_to_receive_; |
| 799 | auto answer = callee->CreateAnswer(options); |
| 800 | |
| 801 | // The expected direction in the answer is the intersection of each side's |
| 802 | // capability to send/recv media. |
| 803 | // For the offerer, the direction is given in the offer (offer_direction_). |
| 804 | // For the answerer, the direction has two components: |
| 805 | // 1. Send if the answerer has a local track to send. |
| 806 | // 2. Receive if the answerer has explicitly set the offer_to_receive to 1 or |
| 807 | // if it has been left as default. |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 808 | bool offer_send = RtpTransceiverDirectionHasSend(offer_direction_); |
| 809 | bool offer_recv = RtpTransceiverDirectionHasRecv(offer_direction_); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 810 | |
| 811 | // The negotiated components determine the direction set in the answer. |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 812 | bool negotiate_send = (send_media_ && offer_recv); |
| 813 | bool negotiate_recv = ((offer_to_receive_ != 0) && offer_send); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 814 | |
| 815 | auto expected_direction = |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 816 | RtpTransceiverDirectionFromSendRecv(negotiate_send, negotiate_recv); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 817 | EXPECT_EQ(expected_direction, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 818 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | // Tests that the media section is rejected if and only if the callee has no |
| 822 | // local media track and has set offer_to_receive to 0, no matter which |
| 823 | // direction the caller indicated in the offer. |
| 824 | TEST_P(PeerConnectionMediaAnswerDirectionTest, VerifyRejected) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 825 | if (IsUnifiedPlan() && |
| 826 | offer_to_receive_ != RTCOfferAnswerOptions::kUndefined) { |
| 827 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 828 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 829 | return; |
| 830 | } |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 831 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 832 | auto caller = CreatePeerConnection(); |
| 833 | caller->AddAudioTrack("a"); |
| 834 | |
| 835 | // Create the offer with an audio section and set its direction. |
| 836 | auto offer = caller->CreateOffer(); |
| 837 | cricket::GetFirstAudioContentDescription(offer->description()) |
| 838 | ->set_direction(offer_direction_); |
| 839 | |
| 840 | auto callee = CreatePeerConnection(); |
| 841 | if (send_media_) { |
| 842 | callee->AddAudioTrack("a"); |
| 843 | } |
| 844 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 845 | |
| 846 | // Create the answer according to the test parameters. |
| 847 | RTCOfferAnswerOptions options; |
| 848 | options.offer_to_receive_audio = offer_to_receive_; |
| 849 | auto answer = callee->CreateAnswer(options); |
| 850 | |
| 851 | // The media section is rejected if and only if offer_to_receive is explicitly |
| 852 | // set to 0 and there is no media to send. |
| 853 | auto* audio_content = cricket::GetFirstAudioContent(answer->description()); |
| 854 | ASSERT_TRUE(audio_content); |
| 855 | EXPECT_EQ((offer_to_receive_ == 0 && !send_media_), audio_content->rejected); |
| 856 | } |
| 857 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 858 | INSTANTIATE_TEST_SUITE_P(PeerConnectionMediaTest, |
| 859 | PeerConnectionMediaAnswerDirectionTest, |
Florent Castelli | 15a38de | 2022-04-05 22:38:21 | [diff] [blame] | 860 | Combine(Values(SdpSemantics::kPlanB_DEPRECATED, |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 861 | SdpSemantics::kUnifiedPlan), |
| 862 | Values(RtpTransceiverDirection::kInactive, |
| 863 | RtpTransceiverDirection::kSendOnly, |
| 864 | RtpTransceiverDirection::kRecvOnly, |
| 865 | RtpTransceiverDirection::kSendRecv), |
| 866 | Bool(), |
| 867 | Values(-1, 0, 1))); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 868 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 869 | TEST_P(PeerConnectionMediaTest, OfferHasDifferentDirectionForAudioVideo) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 870 | auto caller = CreatePeerConnection(); |
| 871 | caller->AddVideoTrack("v"); |
| 872 | |
| 873 | RTCOfferAnswerOptions options; |
| 874 | options.offer_to_receive_audio = 1; |
| 875 | options.offer_to_receive_video = 0; |
| 876 | auto offer = caller->CreateOffer(options); |
| 877 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 878 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 879 | GetMediaContentDirection(offer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 880 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 881 | GetMediaContentDirection(offer.get(), cricket::MEDIA_TYPE_VIDEO)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 882 | } |
| 883 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 884 | TEST_P(PeerConnectionMediaTest, AnswerHasDifferentDirectionsForAudioVideo) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 885 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 886 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 887 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 888 | return; |
| 889 | } |
| 890 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 891 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 892 | auto callee = CreatePeerConnection(); |
| 893 | callee->AddVideoTrack("v"); |
| 894 | |
| 895 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 896 | |
| 897 | RTCOfferAnswerOptions options; |
| 898 | options.offer_to_receive_audio = 1; |
| 899 | options.offer_to_receive_video = 0; |
| 900 | auto answer = callee->CreateAnswer(options); |
| 901 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 902 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 903 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 904 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 905 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_VIDEO)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | void AddComfortNoiseCodecsToSend(cricket::FakeMediaEngine* media_engine) { |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 909 | const cricket::AudioCodec kComfortNoiseCodec8k = |
| 910 | cricket::CreateAudioCodec(102, cricket::kCnCodecName, 8000, 1); |
| 911 | const cricket::AudioCodec kComfortNoiseCodec16k = |
| 912 | cricket::CreateAudioCodec(103, cricket::kCnCodecName, 16000, 1); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 913 | |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 914 | auto codecs = media_engine->voice().send_codecs(); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 915 | codecs.push_back(kComfortNoiseCodec8k); |
| 916 | codecs.push_back(kComfortNoiseCodec16k); |
| 917 | media_engine->SetAudioCodecs(codecs); |
| 918 | } |
| 919 | |
| 920 | bool HasAnyComfortNoiseCodecs(const cricket::SessionDescription* desc) { |
| 921 | const auto* audio_desc = cricket::GetFirstAudioContentDescription(desc); |
| 922 | for (const auto& codec : audio_desc->codecs()) { |
Philipp Hancke | 8498c25 | 2020-06-05 11:28:57 | [diff] [blame] | 923 | if (codec.name == cricket::kCnCodecName) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 924 | return true; |
| 925 | } |
| 926 | } |
| 927 | return false; |
| 928 | } |
| 929 | |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 930 | bool HasPayloadTypeConflict(const cricket::SessionDescription* desc) { |
| 931 | std::set<int> payload_types; |
| 932 | const auto* audio_desc = cricket::GetFirstAudioContentDescription(desc); |
| 933 | if (audio_desc) { |
| 934 | for (const auto& codec : audio_desc->codecs()) { |
| 935 | if (payload_types.count(codec.id) > 0) { |
| 936 | return true; |
| 937 | } |
| 938 | payload_types.insert(codec.id); |
| 939 | } |
| 940 | } |
| 941 | const auto* video_desc = cricket::GetFirstVideoContentDescription(desc); |
| 942 | if (video_desc) { |
| 943 | for (const auto& codec : video_desc->codecs()) { |
| 944 | if (payload_types.count(codec.id) > 0) { |
| 945 | return true; |
| 946 | } |
| 947 | payload_types.insert(codec.id); |
| 948 | } |
| 949 | } |
| 950 | return false; |
| 951 | } |
| 952 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 953 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 954 | CreateOfferWithNoVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
Philipp Hancke | 718acf6 | 2021-05-12 12:18:03 | [diff] [blame] | 955 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
| 956 | AddComfortNoiseCodecsToSend(fake_engine.get()); |
| 957 | auto caller = CreatePeerConnectionWithAudioVideo(std::move(fake_engine)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 958 | |
| 959 | RTCOfferAnswerOptions options; |
| 960 | options.voice_activity_detection = false; |
| 961 | auto offer = caller->CreateOffer(options); |
| 962 | |
| 963 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(offer->description())); |
| 964 | } |
| 965 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 966 | TEST_P(PeerConnectionMediaTest, |
Philipp Hancke | 718acf6 | 2021-05-12 12:18:03 | [diff] [blame] | 967 | CreateOfferWithVoiceActivityDetectionIncludesComfortNoiseCodecs) { |
| 968 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
| 969 | AddComfortNoiseCodecsToSend(fake_engine.get()); |
| 970 | auto caller = CreatePeerConnectionWithAudioVideo(std::move(fake_engine)); |
| 971 | |
| 972 | RTCOfferAnswerOptions options; |
| 973 | options.voice_activity_detection = true; |
| 974 | auto offer = caller->CreateOffer(options); |
| 975 | |
| 976 | EXPECT_TRUE(HasAnyComfortNoiseCodecs(offer->description())); |
| 977 | } |
| 978 | |
| 979 | TEST_P(PeerConnectionMediaTest, |
| 980 | CreateAnswerWithVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 981 | auto caller = CreatePeerConnectionWithAudioVideo(); |
Philipp Hancke | 718acf6 | 2021-05-12 12:18:03 | [diff] [blame] | 982 | |
| 983 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 984 | AddComfortNoiseCodecsToSend(callee_fake_engine.get()); |
| 985 | auto callee = |
| 986 | CreatePeerConnectionWithAudioVideo(std::move(callee_fake_engine)); |
| 987 | |
| 988 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 989 | |
| 990 | RTCOfferAnswerOptions options; |
| 991 | options.voice_activity_detection = true; |
| 992 | auto answer = callee->CreateAnswer(options); |
| 993 | |
| 994 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(answer->description())); |
| 995 | } |
| 996 | |
| 997 | TEST_P(PeerConnectionMediaTest, |
| 998 | CreateAnswerWithNoVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
| 999 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1000 | AddComfortNoiseCodecsToSend(caller_fake_engine.get()); |
| 1001 | auto caller = |
| 1002 | CreatePeerConnectionWithAudioVideo(std::move(caller_fake_engine)); |
| 1003 | |
| 1004 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1005 | AddComfortNoiseCodecsToSend(callee_fake_engine.get()); |
| 1006 | auto callee = |
| 1007 | CreatePeerConnectionWithAudioVideo(std::move(callee_fake_engine)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1008 | |
| 1009 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1010 | |
| 1011 | RTCOfferAnswerOptions options; |
| 1012 | options.voice_activity_detection = false; |
| 1013 | auto answer = callee->CreateAnswer(options); |
| 1014 | |
| 1015 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(answer->description())); |
| 1016 | } |
| 1017 | |
| 1018 | // The following test group verifies that we reject answers with invalid media |
| 1019 | // sections as per RFC 3264. |
| 1020 | |
| 1021 | class PeerConnectionMediaInvalidMediaTest |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1022 | : public PeerConnectionMediaBaseTest, |
| 1023 | public ::testing::WithParamInterface<std::tuple< |
| 1024 | SdpSemantics, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1025 | std::tuple<std::string, |
| 1026 | std::function<void(cricket::SessionDescription*)>, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1027 | std::string>>> { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1028 | protected: |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1029 | PeerConnectionMediaInvalidMediaTest() |
| 1030 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 1031 | auto param = std::get<1>(GetParam()); |
| 1032 | mutator_ = std::get<1>(param); |
| 1033 | expected_error_ = std::get<2>(param); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | std::function<void(cricket::SessionDescription*)> mutator_; |
| 1037 | std::string expected_error_; |
| 1038 | }; |
| 1039 | |
| 1040 | TEST_P(PeerConnectionMediaInvalidMediaTest, FailToSetRemoteAnswer) { |
| 1041 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1042 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1043 | |
| 1044 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1045 | |
| 1046 | auto answer = callee->CreateAnswer(); |
| 1047 | mutator_(answer->description()); |
| 1048 | |
| 1049 | std::string error; |
| 1050 | ASSERT_FALSE(caller->SetRemoteDescription(std::move(answer), &error)); |
| 1051 | EXPECT_EQ("Failed to set remote answer sdp: " + expected_error_, error); |
| 1052 | } |
| 1053 | |
| 1054 | TEST_P(PeerConnectionMediaInvalidMediaTest, FailToSetLocalAnswer) { |
| 1055 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1056 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1057 | |
| 1058 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1059 | |
| 1060 | auto answer = callee->CreateAnswer(); |
| 1061 | mutator_(answer->description()); |
| 1062 | |
| 1063 | std::string error; |
| 1064 | ASSERT_FALSE(callee->SetLocalDescription(std::move(answer), &error)); |
| 1065 | EXPECT_EQ("Failed to set local answer sdp: " + expected_error_, error); |
| 1066 | } |
| 1067 | |
Philipp Hancke | 4bf5238 | 2023-05-25 14:11:36 | [diff] [blame] | 1068 | void RemoveVideoContentAndUnbundle(cricket::SessionDescription* desc) { |
| 1069 | // Removing BUNDLE is easier than removing the content in there. |
| 1070 | desc->RemoveGroupByName("BUNDLE"); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1071 | auto content_name = cricket::GetFirstVideoContent(desc)->name; |
| 1072 | desc->RemoveContentByName(content_name); |
| 1073 | desc->RemoveTransportInfoByName(content_name); |
| 1074 | } |
| 1075 | |
Philipp Hancke | 4bf5238 | 2023-05-25 14:11:36 | [diff] [blame] | 1076 | void RenameVideoContentAndUnbundle(cricket::SessionDescription* desc) { |
| 1077 | // Removing BUNDLE is easier than renaming the content in there. |
| 1078 | desc->RemoveGroupByName("BUNDLE"); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1079 | auto* video_content = cricket::GetFirstVideoContent(desc); |
| 1080 | auto* transport_info = desc->GetTransportInfoByName(video_content->name); |
| 1081 | video_content->name = "video_renamed"; |
| 1082 | transport_info->content_name = video_content->name; |
| 1083 | } |
| 1084 | |
| 1085 | void ReverseMediaContent(cricket::SessionDescription* desc) { |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 1086 | absl::c_reverse(desc->contents()); |
| 1087 | absl::c_reverse(desc->transport_infos()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | void ChangeMediaTypeAudioToVideo(cricket::SessionDescription* desc) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1091 | std::string audio_mid = cricket::GetFirstAudioContent(desc)->name; |
| 1092 | desc->RemoveContentByName(audio_mid); |
| 1093 | auto* video_content = cricket::GetFirstVideoContent(desc); |
| 1094 | desc->AddContent(audio_mid, video_content->type, |
Harald Alvestrand | 1716d39 | 2019-06-03 18:35:45 | [diff] [blame] | 1095 | video_content->media_description()->Clone()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | constexpr char kMLinesOutOfOrder[] = |
| 1099 | "The order of m-lines in answer doesn't match order in offer. Rejecting " |
| 1100 | "answer."; |
| 1101 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 1102 | INSTANTIATE_TEST_SUITE_P( |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1103 | PeerConnectionMediaTest, |
| 1104 | PeerConnectionMediaInvalidMediaTest, |
Florent Castelli | 15a38de | 2022-04-05 22:38:21 | [diff] [blame] | 1105 | Combine(Values(SdpSemantics::kPlanB_DEPRECATED, SdpSemantics::kUnifiedPlan), |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1106 | Values(std::make_tuple("remove video", |
Philipp Hancke | 4bf5238 | 2023-05-25 14:11:36 | [diff] [blame] | 1107 | RemoveVideoContentAndUnbundle, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1108 | kMLinesOutOfOrder), |
| 1109 | std::make_tuple("rename video", |
Philipp Hancke | 4bf5238 | 2023-05-25 14:11:36 | [diff] [blame] | 1110 | RenameVideoContentAndUnbundle, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1111 | kMLinesOutOfOrder), |
| 1112 | std::make_tuple("reverse media sections", |
| 1113 | ReverseMediaContent, |
| 1114 | kMLinesOutOfOrder), |
| 1115 | std::make_tuple("change audio type to video type", |
| 1116 | ChangeMediaTypeAudioToVideo, |
| 1117 | kMLinesOutOfOrder)))); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1118 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1119 | // Tests that if the underlying video encoder fails to be initialized (signaled |
| 1120 | // by failing to set send codecs), the PeerConnection signals the error to the |
| 1121 | // client. |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 1122 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1123 | MediaEngineErrorPropagatedToClients) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1124 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1125 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1126 | |
| 1127 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1128 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 1129 | auto video_channel = |
| 1130 | VideoMediaSendChannel(caller->pc()->GetTransceivers()[1]); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1131 | video_channel->set_fail_set_send_codecs(true); |
| 1132 | |
| 1133 | std::string error; |
| 1134 | ASSERT_FALSE(caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(), |
| 1135 | &error)); |
Yura Yaroshevich | bc1f910 | 2020-06-03 21:15:22 | [diff] [blame] | 1136 | EXPECT_EQ(std::string("Failed to set remote answer sdp: Failed to set remote " |
| 1137 | "video description " |
| 1138 | "send parameters for m-section with mid='") + |
| 1139 | (IsUnifiedPlan() ? "1" : "video") + "'.", |
| 1140 | error); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | // Tests that if the underlying video encoder fails once then subsequent |
| 1144 | // attempts at setting the local/remote description will also fail, even if |
| 1145 | // SetSendCodecs no longer fails. |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 1146 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1147 | FailToApplyDescriptionIfVideoEncoderHasEverFailed) { |
| 1148 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1149 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1150 | |
| 1151 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 1152 | |
Florent Castelli | 1f31c20 | 2023-06-26 00:26:07 | [diff] [blame] | 1153 | auto video_channel = |
| 1154 | VideoMediaSendChannel(caller->pc()->GetTransceivers()[1]); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1155 | video_channel->set_fail_set_send_codecs(true); |
| 1156 | |
| 1157 | EXPECT_FALSE( |
| 1158 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 1159 | |
| 1160 | video_channel->set_fail_set_send_codecs(false); |
| 1161 | |
| 1162 | EXPECT_FALSE(caller->SetRemoteDescription(callee->CreateAnswer())); |
| 1163 | EXPECT_FALSE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1164 | } |
| 1165 | |
| 1166 | void RenameContent(cricket::SessionDescription* desc, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1167 | cricket::MediaType media_type, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1168 | const std::string& new_name) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1169 | auto* content = cricket::GetFirstMediaContent(desc, media_type); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1170 | RTC_DCHECK(content); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1171 | std::string old_name = content->name; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1172 | content->name = new_name; |
| 1173 | auto* transport = desc->GetTransportInfoByName(old_name); |
| 1174 | RTC_DCHECK(transport); |
| 1175 | transport->content_name = new_name; |
Zhi Huang | d2248f8 | 2018-04-10 21:41:03 | [diff] [blame] | 1176 | |
| 1177 | // Rename the content name in the BUNDLE group. |
| 1178 | cricket::ContentGroup new_bundle_group = |
| 1179 | *desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1180 | new_bundle_group.RemoveContentName(old_name); |
| 1181 | new_bundle_group.AddContentName(new_name); |
| 1182 | desc->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1183 | desc->AddGroup(new_bundle_group); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | // Tests that an answer responds with the same MIDs as the offer. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1187 | TEST_P(PeerConnectionMediaTest, AnswerHasSameMidsAsOffer) { |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 1188 | const std::string kAudioMid = "notdefault1"; |
| 1189 | const std::string kVideoMid = "notdefault2"; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1190 | |
| 1191 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1192 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1193 | |
| 1194 | auto offer = caller->CreateOffer(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1195 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, kAudioMid); |
| 1196 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, kVideoMid); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1197 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1198 | |
| 1199 | auto answer = callee->CreateAnswer(); |
| 1200 | EXPECT_EQ(kAudioMid, |
| 1201 | cricket::GetFirstAudioContent(answer->description())->name); |
| 1202 | EXPECT_EQ(kVideoMid, |
| 1203 | cricket::GetFirstVideoContent(answer->description())->name); |
| 1204 | } |
| 1205 | |
| 1206 | // Test that if the callee creates a re-offer, the MIDs are the same as the |
| 1207 | // original offer. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1208 | TEST_P(PeerConnectionMediaTest, ReOfferHasSameMidsAsFirstOffer) { |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 1209 | const std::string kAudioMid = "notdefault1"; |
| 1210 | const std::string kVideoMid = "notdefault2"; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1211 | |
| 1212 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1213 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1214 | |
| 1215 | auto offer = caller->CreateOffer(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1216 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, kAudioMid); |
| 1217 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, kVideoMid); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1218 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1219 | ASSERT_TRUE(callee->SetLocalDescription(callee->CreateAnswer())); |
| 1220 | |
| 1221 | auto reoffer = callee->CreateOffer(); |
| 1222 | EXPECT_EQ(kAudioMid, |
| 1223 | cricket::GetFirstAudioContent(reoffer->description())->name); |
| 1224 | EXPECT_EQ(kVideoMid, |
| 1225 | cricket::GetFirstVideoContent(reoffer->description())->name); |
| 1226 | } |
| 1227 | |
Steve Anton | 06817cd | 2018-12-18 23:55:30 | [diff] [blame] | 1228 | // Test that SetRemoteDescription returns an error if there are two m= sections |
| 1229 | // with the same MID value. |
| 1230 | TEST_P(PeerConnectionMediaTest, SetRemoteDescriptionFailsWithDuplicateMids) { |
| 1231 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1232 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1233 | |
| 1234 | auto offer = caller->CreateOffer(); |
| 1235 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, "same"); |
| 1236 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, "same"); |
| 1237 | |
| 1238 | std::string error; |
| 1239 | EXPECT_FALSE(callee->SetRemoteDescription(std::move(offer), &error)); |
| 1240 | EXPECT_EQ(error, |
| 1241 | "Failed to set remote offer sdp: Duplicate a=mid value 'same'."); |
| 1242 | } |
| 1243 | |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1244 | // Test that if a RED codec refers to another codec in its fmtp line, but that |
| 1245 | // codec's payload type was reassigned for some reason (either the remote |
| 1246 | // endpoint selected a different payload type or there was a conflict), the RED |
| 1247 | // fmtp line is modified to refer to the correct payload type. |
| 1248 | TEST_P(PeerConnectionMediaTest, RedFmtpPayloadTypeReassigned) { |
| 1249 | std::vector<cricket::AudioCodec> caller_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1250 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1251 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1252 | caller_fake_engine->SetAudioCodecs(caller_fake_codecs); |
| 1253 | auto caller = CreatePeerConnectionWithAudio(std::move(caller_fake_engine)); |
| 1254 | |
| 1255 | std::vector<cricket::AudioCodec> callee_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1256 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(120, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1257 | callee_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1258 | cricket::CreateAudioCodec(121, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1259 | callee_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1260 | "120/120"); |
| 1261 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1262 | callee_fake_engine->SetAudioCodecs(callee_fake_codecs); |
| 1263 | auto callee = CreatePeerConnectionWithAudio(std::move(callee_fake_engine)); |
| 1264 | |
| 1265 | // Offer from the caller establishes 100 as the "foo" payload type. |
| 1266 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1267 | callee->SetRemoteDescription(std::move(offer)); |
| 1268 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1269 | auto answer_description = |
| 1270 | cricket::GetFirstAudioContentDescription(answer->description()); |
| 1271 | ASSERT_EQ(1u, answer_description->codecs().size()); |
| 1272 | |
| 1273 | // Offer from the callee should respect the established payload type, and |
| 1274 | // attempt to add RED, which should refer to the correct payload type. |
| 1275 | offer = callee->CreateOfferAndSetAsLocal(); |
| 1276 | auto* offer_description = |
| 1277 | cricket::GetFirstAudioContentDescription(offer->description()); |
| 1278 | ASSERT_EQ(2u, offer_description->codecs().size()); |
| 1279 | for (const auto& codec : offer_description->codecs()) { |
| 1280 | if (codec.name == "foo") { |
| 1281 | ASSERT_EQ(100, codec.id); |
| 1282 | } else if (codec.name == cricket::kRedCodecName) { |
| 1283 | std::string fmtp; |
| 1284 | ASSERT_TRUE(codec.GetParam("", &fmtp)); |
| 1285 | EXPECT_EQ("100/100", fmtp); |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | // Test that RED without fmtp does match RED without fmtp. |
| 1291 | TEST_P(PeerConnectionMediaTest, RedFmtpPayloadTypeNoFmtpMatchNoFmtp) { |
| 1292 | std::vector<cricket::AudioCodec> caller_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1293 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1294 | caller_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1295 | cricket::CreateAudioCodec(101, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1296 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1297 | caller_fake_engine->SetAudioCodecs(caller_fake_codecs); |
| 1298 | auto caller = CreatePeerConnectionWithAudio(std::move(caller_fake_engine)); |
| 1299 | |
| 1300 | std::vector<cricket::AudioCodec> callee_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1301 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(120, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1302 | callee_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1303 | cricket::CreateAudioCodec(121, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1304 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1305 | callee_fake_engine->SetAudioCodecs(callee_fake_codecs); |
| 1306 | auto callee = CreatePeerConnectionWithAudio(std::move(callee_fake_engine)); |
| 1307 | |
| 1308 | // Offer from the caller establishes 100 as the "foo" payload type. |
| 1309 | // Red (without fmtp) is negotiated. |
| 1310 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1311 | callee->SetRemoteDescription(std::move(offer)); |
| 1312 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1313 | auto answer_description = |
| 1314 | cricket::GetFirstAudioContentDescription(answer->description()); |
| 1315 | ASSERT_EQ(2u, answer_description->codecs().size()); |
| 1316 | |
| 1317 | // Offer from the callee should respect the established payload type, and |
| 1318 | // attempt to add RED. |
| 1319 | offer = callee->CreateOfferAndSetAsLocal(); |
| 1320 | auto* offer_description = |
| 1321 | cricket::GetFirstAudioContentDescription(offer->description()); |
| 1322 | ASSERT_EQ(2u, offer_description->codecs().size()); |
| 1323 | for (const auto& codec : offer_description->codecs()) { |
| 1324 | if (codec.name == "foo") { |
| 1325 | ASSERT_EQ(100, codec.id); |
| 1326 | } else if (codec.name == cricket::kRedCodecName) { |
| 1327 | ASSERT_EQ(101, codec.id); |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | // Test that RED without fmtp does not match RED with fmtp. |
| 1333 | TEST_P(PeerConnectionMediaTest, RedFmtpPayloadTypeNoFmtpNoMatchFmtp) { |
| 1334 | std::vector<cricket::AudioCodec> caller_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1335 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1336 | caller_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1337 | cricket::CreateAudioCodec(101, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1338 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1339 | caller_fake_engine->SetAudioCodecs(caller_fake_codecs); |
| 1340 | auto caller = CreatePeerConnectionWithAudio(std::move(caller_fake_engine)); |
| 1341 | |
| 1342 | std::vector<cricket::AudioCodec> callee_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1343 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(120, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1344 | callee_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1345 | cricket::CreateAudioCodec(121, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1346 | callee_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1347 | "120/120"); |
| 1348 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1349 | callee_fake_engine->SetAudioCodecs(callee_fake_codecs); |
| 1350 | auto callee = CreatePeerConnectionWithAudio(std::move(callee_fake_engine)); |
| 1351 | |
| 1352 | // Offer from the caller establishes 100 as the "foo" payload type. |
| 1353 | // It should not negotiate RED. |
| 1354 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1355 | callee->SetRemoteDescription(std::move(offer)); |
| 1356 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1357 | auto answer_description = |
| 1358 | cricket::GetFirstAudioContentDescription(answer->description()); |
| 1359 | ASSERT_EQ(1u, answer_description->codecs().size()); |
| 1360 | |
| 1361 | // Offer from the callee should respect the established payload type, and |
| 1362 | // attempt to add RED, which should refer to the correct payload type. |
| 1363 | offer = callee->CreateOfferAndSetAsLocal(); |
| 1364 | auto* offer_description = |
| 1365 | cricket::GetFirstAudioContentDescription(offer->description()); |
| 1366 | ASSERT_EQ(2u, offer_description->codecs().size()); |
| 1367 | for (const auto& codec : offer_description->codecs()) { |
| 1368 | if (codec.name == "foo") { |
| 1369 | ASSERT_EQ(100, codec.id); |
| 1370 | } else if (codec.name == cricket::kRedCodecName) { |
| 1371 | std::string fmtp; |
| 1372 | ASSERT_TRUE( |
| 1373 | codec.GetParam(cricket::kCodecParamNotInNameValueFormat, &fmtp)); |
| 1374 | EXPECT_EQ("100/100", fmtp); |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | // Test that RED with fmtp must match base codecs. |
| 1380 | TEST_P(PeerConnectionMediaTest, RedFmtpPayloadTypeMustMatchBaseCodecs) { |
| 1381 | std::vector<cricket::AudioCodec> caller_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1382 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1383 | caller_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1384 | cricket::CreateAudioCodec(101, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1385 | caller_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1386 | "100/100"); |
| 1387 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1388 | caller_fake_engine->SetAudioCodecs(caller_fake_codecs); |
| 1389 | auto caller = CreatePeerConnectionWithAudio(std::move(caller_fake_engine)); |
| 1390 | |
| 1391 | std::vector<cricket::AudioCodec> callee_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1392 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(120, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1393 | callee_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1394 | cricket::CreateAudioCodec(121, cricket::kRedCodecName, 0, 1)); |
| 1395 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(122, "bar", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1396 | callee_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1397 | "122/122"); |
| 1398 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1399 | callee_fake_engine->SetAudioCodecs(callee_fake_codecs); |
| 1400 | auto callee = CreatePeerConnectionWithAudio(std::move(callee_fake_engine)); |
| 1401 | |
| 1402 | // Offer from the caller establishes 100 as the "foo" payload type. |
| 1403 | // It should not negotiate RED since RED is associated with foo, not bar. |
| 1404 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1405 | callee->SetRemoteDescription(std::move(offer)); |
| 1406 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1407 | auto answer_description = |
| 1408 | cricket::GetFirstAudioContentDescription(answer->description()); |
| 1409 | ASSERT_EQ(1u, answer_description->codecs().size()); |
| 1410 | } |
| 1411 | |
| 1412 | // Test behaviour when the RED fmtp attempts to specify different codecs |
| 1413 | // which is not supported. |
| 1414 | TEST_P(PeerConnectionMediaTest, RedFmtpPayloadMixed) { |
| 1415 | std::vector<cricket::AudioCodec> caller_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1416 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
| 1417 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(102, "bar", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1418 | caller_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1419 | cricket::CreateAudioCodec(101, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1420 | caller_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1421 | "100/102"); |
| 1422 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1423 | caller_fake_engine->SetAudioCodecs(caller_fake_codecs); |
| 1424 | auto caller = CreatePeerConnectionWithAudio(std::move(caller_fake_engine)); |
| 1425 | |
| 1426 | std::vector<cricket::AudioCodec> callee_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1427 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(120, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1428 | callee_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1429 | cricket::CreateAudioCodec(121, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1430 | callee_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1431 | "120/120"); |
| 1432 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1433 | callee_fake_engine->SetAudioCodecs(callee_fake_codecs); |
| 1434 | auto callee = CreatePeerConnectionWithAudio(std::move(callee_fake_engine)); |
| 1435 | |
| 1436 | // Offer from the caller establishes 100 as the "foo" payload type. |
| 1437 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1438 | callee->SetRemoteDescription(std::move(offer)); |
| 1439 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1440 | auto answer_description = |
| 1441 | cricket::GetFirstAudioContentDescription(answer->description()); |
| 1442 | // RED is not negotiated. |
| 1443 | ASSERT_EQ(1u, answer_description->codecs().size()); |
| 1444 | } |
| 1445 | |
| 1446 | // Test behaviour when the RED fmtp attempts to negotiate different levels of |
| 1447 | // redundancy. |
| 1448 | TEST_P(PeerConnectionMediaTest, RedFmtpPayloadDifferentRedundancy) { |
| 1449 | std::vector<cricket::AudioCodec> caller_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1450 | caller_fake_codecs.push_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1451 | caller_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1452 | cricket::CreateAudioCodec(101, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1453 | caller_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1454 | "100/100"); |
| 1455 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1456 | caller_fake_engine->SetAudioCodecs(caller_fake_codecs); |
| 1457 | auto caller = CreatePeerConnectionWithAudio(std::move(caller_fake_engine)); |
| 1458 | |
| 1459 | std::vector<cricket::AudioCodec> callee_fake_codecs; |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1460 | callee_fake_codecs.push_back(cricket::CreateAudioCodec(120, "foo", 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1461 | callee_fake_codecs.push_back( |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1462 | cricket::CreateAudioCodec(121, cricket::kRedCodecName, 0, 1)); |
Philipp Hancke | 7145a14 | 2021-09-28 05:46:06 | [diff] [blame] | 1463 | callee_fake_codecs.back().SetParam(cricket::kCodecParamNotInNameValueFormat, |
| 1464 | "120/120/120"); |
| 1465 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1466 | callee_fake_engine->SetAudioCodecs(callee_fake_codecs); |
| 1467 | auto callee = CreatePeerConnectionWithAudio(std::move(callee_fake_engine)); |
| 1468 | |
| 1469 | // Offer from the caller establishes 100 as the "foo" payload type. |
| 1470 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1471 | callee->SetRemoteDescription(std::move(offer)); |
| 1472 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1473 | auto answer_description = |
| 1474 | cricket::GetFirstAudioContentDescription(answer->description()); |
| 1475 | // RED is negotiated. |
| 1476 | ASSERT_EQ(2u, answer_description->codecs().size()); |
| 1477 | |
| 1478 | // Offer from the callee should respect the established payload type, and |
| 1479 | // attempt to add RED, which should refer to the correct payload type. |
| 1480 | offer = callee->CreateOfferAndSetAsLocal(); |
| 1481 | auto* offer_description = |
| 1482 | cricket::GetFirstAudioContentDescription(offer->description()); |
| 1483 | ASSERT_EQ(2u, offer_description->codecs().size()); |
| 1484 | for (const auto& codec : offer_description->codecs()) { |
| 1485 | if (codec.name == "foo") { |
| 1486 | ASSERT_EQ(100, codec.id); |
| 1487 | } else if (codec.name == cricket::kRedCodecName) { |
| 1488 | std::string fmtp; |
| 1489 | ASSERT_TRUE( |
| 1490 | codec.GetParam(cricket::kCodecParamNotInNameValueFormat, &fmtp)); |
| 1491 | EXPECT_EQ("100/100", fmtp); |
| 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1496 | template <typename C> |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1497 | bool CompareCodecs(const std::vector<RtpCodecCapability>& capabilities, |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1498 | const std::vector<C>& codecs) { |
| 1499 | bool capability_has_rtx = |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1500 | absl::c_any_of(capabilities, [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1501 | return codec.name == cricket::kRtxCodecName; |
| 1502 | }); |
| 1503 | bool codecs_has_rtx = absl::c_any_of(codecs, [](const C& codec) { |
| 1504 | return codec.name == cricket::kRtxCodecName; |
| 1505 | }); |
| 1506 | |
| 1507 | std::vector<C> codecs_no_rtx; |
| 1508 | absl::c_copy_if( |
| 1509 | codecs, std::back_inserter(codecs_no_rtx), |
| 1510 | [](const C& codec) { return codec.name != cricket::kRtxCodecName; }); |
| 1511 | |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1512 | std::vector<RtpCodecCapability> capabilities_no_rtx; |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1513 | absl::c_copy_if(capabilities, std::back_inserter(capabilities_no_rtx), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1514 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1515 | return codec.name != cricket::kRtxCodecName; |
| 1516 | }); |
| 1517 | |
| 1518 | return capability_has_rtx == codecs_has_rtx && |
| 1519 | absl::c_equal( |
| 1520 | capabilities_no_rtx, codecs_no_rtx, |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1521 | [](const RtpCodecCapability& capability, const C& codec) { |
Florent Castelli | 43a5dd8 | 2023-04-12 10:45:07 | [diff] [blame] | 1522 | return codec.MatchesRtpCodec(capability); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1523 | }); |
| 1524 | } |
| 1525 | |
| 1526 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1527 | SetCodecPreferencesAudioMissingRecvCodec) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1528 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1529 | auto send_codecs = fake_engine->voice().send_codecs(); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1530 | send_codecs.push_back(cricket::CreateAudioCodec(send_codecs.back().id + 1, |
| 1531 | "send_only_codec", 0, 1)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1532 | fake_engine->SetAudioSendCodecs(send_codecs); |
| 1533 | |
| 1534 | auto caller = CreatePeerConnectionWithAudio(std::move(fake_engine)); |
| 1535 | |
| 1536 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1537 | auto capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 1538 | cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 1539 | |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1540 | std::vector<RtpCodecCapability> codecs; |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1541 | absl::c_copy_if(capabilities.codecs, std::back_inserter(codecs), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1542 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1543 | return codec.name.find("_only_") != std::string::npos; |
| 1544 | }); |
| 1545 | |
| 1546 | auto result = transceiver->SetCodecPreferences(codecs); |
| 1547 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 1548 | } |
| 1549 | |
| 1550 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1551 | SetCodecPreferencesAudioMissingSendCodec) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1552 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1553 | auto recv_codecs = fake_engine->voice().recv_codecs(); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1554 | recv_codecs.push_back(cricket::CreateAudioCodec(recv_codecs.back().id + 1, |
| 1555 | "recv_only_codec", 0, 1)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1556 | fake_engine->SetAudioRecvCodecs(recv_codecs); |
| 1557 | auto caller = CreatePeerConnectionWithAudio(std::move(fake_engine)); |
| 1558 | |
| 1559 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1560 | auto capabilities = caller->pc_factory()->GetRtpReceiverCapabilities( |
| 1561 | cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 1562 | |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1563 | std::vector<RtpCodecCapability> codecs; |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1564 | absl::c_copy_if(capabilities.codecs, std::back_inserter(codecs), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1565 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1566 | return codec.name.find("_only_") != std::string::npos; |
| 1567 | }); |
| 1568 | |
| 1569 | auto result = transceiver->SetCodecPreferences(codecs); |
| 1570 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 1571 | } |
| 1572 | |
| 1573 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1574 | SetCodecPreferencesAudioRejectsVideoCodec) { |
| 1575 | auto caller = CreatePeerConnectionWithAudio(); |
| 1576 | |
| 1577 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1578 | auto video_codecs = |
| 1579 | caller->pc_factory() |
| 1580 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_VIDEO) |
| 1581 | .codecs; |
| 1582 | auto codecs = |
| 1583 | caller->pc_factory() |
| 1584 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_AUDIO) |
| 1585 | .codecs; |
| 1586 | codecs.insert(codecs.end(), video_codecs.begin(), video_codecs.end()); |
| 1587 | auto result = transceiver->SetCodecPreferences(codecs); |
| 1588 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 1589 | } |
| 1590 | |
| 1591 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1592 | SetCodecPreferencesAudioRejectsOnlyRtxRedFec) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1593 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1594 | auto audio_codecs = fake_engine->voice().send_codecs(); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1595 | audio_codecs.push_back(cricket::CreateAudioRtxCodec( |
| 1596 | audio_codecs.back().id + 1, audio_codecs.back().id)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1597 | audio_codecs.push_back(cricket::CreateAudioCodec( |
| 1598 | audio_codecs.back().id + 1, cricket::kRedCodecName, 0, 1)); |
| 1599 | audio_codecs.push_back(cricket::CreateAudioCodec( |
| 1600 | audio_codecs.back().id + 1, cricket::kUlpfecCodecName, 0, 1)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1601 | fake_engine->SetAudioCodecs(audio_codecs); |
| 1602 | |
| 1603 | auto caller = CreatePeerConnectionWithAudio(std::move(fake_engine)); |
| 1604 | |
| 1605 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1606 | auto codecs = |
| 1607 | caller->pc_factory() |
| 1608 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_AUDIO) |
| 1609 | .codecs; |
| 1610 | auto codecs_only_rtx_red_fec = codecs; |
| 1611 | auto it = std::remove_if(codecs_only_rtx_red_fec.begin(), |
| 1612 | codecs_only_rtx_red_fec.end(), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1613 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1614 | return !(codec.name == cricket::kRtxCodecName || |
| 1615 | codec.name == cricket::kRedCodecName || |
| 1616 | codec.name == cricket::kUlpfecCodecName); |
| 1617 | }); |
| 1618 | codecs_only_rtx_red_fec.erase(it, codecs_only_rtx_red_fec.end()); |
| 1619 | |
| 1620 | auto result = transceiver->SetCodecPreferences(codecs_only_rtx_red_fec); |
| 1621 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 1622 | } |
| 1623 | |
| 1624 | TEST_F(PeerConnectionMediaTestUnifiedPlan, SetCodecPreferencesAllAudioCodecs) { |
| 1625 | auto caller = CreatePeerConnectionWithAudio(); |
| 1626 | |
| 1627 | auto sender_audio_codecs = |
| 1628 | caller->pc_factory() |
| 1629 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_AUDIO) |
| 1630 | .codecs; |
| 1631 | |
| 1632 | auto audio_transceiver = caller->pc()->GetTransceivers().front(); |
| 1633 | |
| 1634 | // Normal case, set all capabilities as preferences |
| 1635 | EXPECT_TRUE(audio_transceiver->SetCodecPreferences(sender_audio_codecs).ok()); |
| 1636 | auto offer = caller->CreateOffer(); |
| 1637 | auto codecs = offer->description() |
| 1638 | ->contents()[0] |
| 1639 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1640 | ->codecs(); |
| 1641 | EXPECT_TRUE(CompareCodecs(sender_audio_codecs, codecs)); |
| 1642 | } |
| 1643 | |
| 1644 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1645 | SetCodecPreferencesResetAudioCodecs) { |
| 1646 | auto caller = CreatePeerConnectionWithAudio(); |
| 1647 | |
| 1648 | auto sender_audio_codecs = |
| 1649 | caller->pc_factory() |
| 1650 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_AUDIO) |
| 1651 | .codecs; |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1652 | std::vector<RtpCodecCapability> empty_codecs = {}; |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1653 | |
| 1654 | auto audio_transceiver = caller->pc()->GetTransceivers().front(); |
| 1655 | |
| 1656 | // Normal case, reset codec preferences |
| 1657 | EXPECT_TRUE(audio_transceiver->SetCodecPreferences(empty_codecs).ok()); |
| 1658 | auto offer = caller->CreateOffer(); |
| 1659 | auto codecs = offer->description() |
| 1660 | ->contents()[0] |
| 1661 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1662 | ->codecs(); |
| 1663 | EXPECT_TRUE(CompareCodecs(sender_audio_codecs, codecs)); |
| 1664 | } |
| 1665 | |
| 1666 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1667 | SetCodecPreferencesVideoRejectsAudioCodec) { |
| 1668 | auto caller = CreatePeerConnectionWithVideo(); |
| 1669 | |
| 1670 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1671 | auto audio_codecs = |
| 1672 | caller->pc_factory() |
| 1673 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_AUDIO) |
| 1674 | .codecs; |
| 1675 | auto codecs = |
| 1676 | caller->pc_factory() |
| 1677 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_VIDEO) |
| 1678 | .codecs; |
| 1679 | codecs.insert(codecs.end(), audio_codecs.begin(), audio_codecs.end()); |
| 1680 | auto result = transceiver->SetCodecPreferences(codecs); |
| 1681 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 1682 | } |
| 1683 | |
| 1684 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1685 | SetCodecPreferencesVideoRejectsOnlyRtxRedFec) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1686 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 1687 | auto video_codecs = fake_engine->video().send_codecs(); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1688 | video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1689 | video_codecs.back().id + 1, video_codecs.back().id)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1690 | video_codecs.push_back(cricket::CreateVideoCodec(video_codecs.back().id + 1, |
| 1691 | cricket::kRedCodecName)); |
| 1692 | video_codecs.push_back(cricket::CreateVideoCodec(video_codecs.back().id + 1, |
| 1693 | cricket::kUlpfecCodecName)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1694 | fake_engine->SetVideoCodecs(video_codecs); |
| 1695 | |
| 1696 | auto caller = CreatePeerConnectionWithVideo(std::move(fake_engine)); |
| 1697 | |
| 1698 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1699 | auto codecs = |
| 1700 | caller->pc_factory() |
| 1701 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_VIDEO) |
| 1702 | .codecs; |
| 1703 | auto codecs_only_rtx_red_fec = codecs; |
| 1704 | auto it = std::remove_if(codecs_only_rtx_red_fec.begin(), |
| 1705 | codecs_only_rtx_red_fec.end(), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1706 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1707 | return !(codec.name == cricket::kRtxCodecName || |
| 1708 | codec.name == cricket::kRedCodecName || |
| 1709 | codec.name == cricket::kUlpfecCodecName); |
| 1710 | }); |
| 1711 | codecs_only_rtx_red_fec.erase(it, codecs_only_rtx_red_fec.end()); |
| 1712 | |
| 1713 | auto result = transceiver->SetCodecPreferences(codecs_only_rtx_red_fec); |
| 1714 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 1715 | } |
| 1716 | |
| 1717 | TEST_F(PeerConnectionMediaTestUnifiedPlan, SetCodecPreferencesAllVideoCodecs) { |
| 1718 | auto caller = CreatePeerConnectionWithVideo(); |
| 1719 | |
| 1720 | auto sender_video_codecs = |
| 1721 | caller->pc_factory() |
| 1722 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO) |
| 1723 | .codecs; |
| 1724 | |
| 1725 | auto video_transceiver = caller->pc()->GetTransceivers().front(); |
| 1726 | |
| 1727 | // Normal case, setting preferences to normal capabilities |
| 1728 | EXPECT_TRUE(video_transceiver->SetCodecPreferences(sender_video_codecs).ok()); |
| 1729 | auto offer = caller->CreateOffer(); |
| 1730 | auto codecs = offer->description() |
| 1731 | ->contents()[0] |
| 1732 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1733 | ->codecs(); |
| 1734 | EXPECT_TRUE(CompareCodecs(sender_video_codecs, codecs)); |
| 1735 | } |
| 1736 | |
| 1737 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1738 | SetCodecPreferencesResetVideoCodecs) { |
| 1739 | auto caller = CreatePeerConnectionWithVideo(); |
| 1740 | |
| 1741 | auto sender_video_codecs = |
| 1742 | caller->pc_factory() |
| 1743 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO) |
| 1744 | .codecs; |
| 1745 | |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1746 | std::vector<RtpCodecCapability> empty_codecs = {}; |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1747 | |
| 1748 | auto video_transceiver = caller->pc()->GetTransceivers().front(); |
| 1749 | |
| 1750 | // Normal case, resetting preferences with empty list of codecs |
| 1751 | EXPECT_TRUE(video_transceiver->SetCodecPreferences(empty_codecs).ok()); |
| 1752 | auto offer = caller->CreateOffer(); |
| 1753 | auto codecs = offer->description() |
| 1754 | ->contents()[0] |
| 1755 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1756 | ->codecs(); |
| 1757 | EXPECT_TRUE(CompareCodecs(sender_video_codecs, codecs)); |
| 1758 | } |
| 1759 | |
| 1760 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1761 | SetCodecPreferencesVideoCodecDuplicatesRemoved) { |
| 1762 | auto caller = CreatePeerConnectionWithVideo(); |
| 1763 | |
| 1764 | auto sender_video_codecs = |
| 1765 | caller->pc_factory() |
| 1766 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO) |
| 1767 | .codecs; |
| 1768 | |
| 1769 | auto video_transceiver = caller->pc()->GetTransceivers().front(); |
| 1770 | |
| 1771 | // Check duplicates are removed |
| 1772 | auto single_codec = sender_video_codecs; |
| 1773 | single_codec.resize(1); |
| 1774 | auto duplicate_codec = single_codec; |
| 1775 | duplicate_codec.push_back(duplicate_codec.front()); |
| 1776 | duplicate_codec.push_back(duplicate_codec.front()); |
| 1777 | duplicate_codec.push_back(duplicate_codec.front()); |
| 1778 | |
| 1779 | EXPECT_TRUE(video_transceiver->SetCodecPreferences(duplicate_codec).ok()); |
| 1780 | auto offer = caller->CreateOffer(); |
| 1781 | auto codecs = offer->description() |
| 1782 | ->contents()[0] |
| 1783 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1784 | ->codecs(); |
| 1785 | EXPECT_TRUE(CompareCodecs(single_codec, codecs)); |
| 1786 | } |
| 1787 | |
| 1788 | TEST_F(PeerConnectionMediaTestUnifiedPlan, SetCodecPreferencesVideoWithRtx) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1789 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 1790 | auto caller_video_codecs = caller_fake_engine->video().send_codecs(); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1791 | caller_video_codecs.push_back(cricket::CreateVideoCodec( |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1792 | caller_video_codecs.back().id + 1, cricket::kVp8CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1793 | caller_video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1794 | caller_video_codecs.back().id + 1, caller_video_codecs.back().id)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1795 | caller_video_codecs.push_back(cricket::CreateVideoCodec( |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1796 | caller_video_codecs.back().id + 1, cricket::kVp9CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1797 | caller_video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1798 | caller_video_codecs.back().id + 1, caller_video_codecs.back().id)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1799 | caller_fake_engine->SetVideoCodecs(caller_video_codecs); |
| 1800 | |
| 1801 | auto caller = CreatePeerConnectionWithVideo(std::move(caller_fake_engine)); |
| 1802 | |
| 1803 | auto sender_video_codecs = |
| 1804 | caller->pc_factory() |
| 1805 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO) |
| 1806 | .codecs; |
| 1807 | |
| 1808 | auto video_transceiver = caller->pc()->GetTransceivers().front(); |
| 1809 | |
| 1810 | // Check that RTX codec is properly added |
| 1811 | auto video_codecs_vpx_rtx = sender_video_codecs; |
| 1812 | auto it = |
| 1813 | std::remove_if(video_codecs_vpx_rtx.begin(), video_codecs_vpx_rtx.end(), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1814 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1815 | return codec.name != cricket::kRtxCodecName && |
| 1816 | codec.name != cricket::kVp8CodecName && |
| 1817 | codec.name != cricket::kVp9CodecName; |
| 1818 | }); |
| 1819 | video_codecs_vpx_rtx.erase(it, video_codecs_vpx_rtx.end()); |
| 1820 | absl::c_reverse(video_codecs_vpx_rtx); |
| 1821 | EXPECT_EQ(video_codecs_vpx_rtx.size(), 3u); // VP8, VP9, RTX |
| 1822 | EXPECT_TRUE( |
| 1823 | video_transceiver->SetCodecPreferences(video_codecs_vpx_rtx).ok()); |
| 1824 | auto offer = caller->CreateOffer(); |
| 1825 | auto codecs = offer->description() |
| 1826 | ->contents()[0] |
| 1827 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1828 | ->codecs(); |
| 1829 | |
| 1830 | EXPECT_TRUE(CompareCodecs(video_codecs_vpx_rtx, codecs)); |
| 1831 | EXPECT_EQ(codecs.size(), 4u); |
| 1832 | } |
| 1833 | |
| 1834 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1835 | SetCodecPreferencesVideoCodecsNegotiation) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1836 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 1837 | auto caller_video_codecs = caller_fake_engine->video().send_codecs(); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1838 | caller_video_codecs.push_back(cricket::CreateVideoCodec( |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1839 | caller_video_codecs.back().id + 1, cricket::kVp8CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1840 | caller_video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1841 | caller_video_codecs.back().id + 1, caller_video_codecs.back().id)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1842 | caller_video_codecs.push_back(cricket::CreateVideoCodec( |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1843 | caller_video_codecs.back().id + 1, cricket::kVp9CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1844 | caller_video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1845 | caller_video_codecs.back().id + 1, caller_video_codecs.back().id)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1846 | caller_fake_engine->SetVideoCodecs(caller_video_codecs); |
| 1847 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1848 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1849 | callee_fake_engine->SetVideoCodecs(caller_video_codecs); |
| 1850 | |
| 1851 | auto caller = CreatePeerConnectionWithVideo(std::move(caller_fake_engine)); |
| 1852 | auto callee = CreatePeerConnection(std::move(callee_fake_engine)); |
| 1853 | |
| 1854 | auto video_codecs = caller->pc_factory() |
| 1855 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO) |
| 1856 | .codecs; |
| 1857 | |
| 1858 | auto send_transceiver = caller->pc()->GetTransceivers().front(); |
| 1859 | |
| 1860 | auto video_codecs_vpx = video_codecs; |
| 1861 | auto it = std::remove_if(video_codecs_vpx.begin(), video_codecs_vpx.end(), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1862 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1863 | return codec.name != cricket::kVp8CodecName && |
| 1864 | codec.name != cricket::kVp9CodecName; |
| 1865 | }); |
| 1866 | video_codecs_vpx.erase(it, video_codecs_vpx.end()); |
| 1867 | EXPECT_EQ(video_codecs_vpx.size(), 2u); // VP8, VP9 |
| 1868 | EXPECT_TRUE(send_transceiver->SetCodecPreferences(video_codecs_vpx).ok()); |
| 1869 | |
| 1870 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1871 | auto codecs = offer->description() |
| 1872 | ->contents()[0] |
| 1873 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1874 | ->codecs(); |
| 1875 | |
| 1876 | EXPECT_EQ(codecs.size(), 2u); // VP8, VP9 |
| 1877 | EXPECT_TRUE(CompareCodecs(video_codecs_vpx, codecs)); |
| 1878 | |
| 1879 | callee->SetRemoteDescription(std::move(offer)); |
| 1880 | |
| 1881 | auto recv_transceiver = callee->pc()->GetTransceivers().front(); |
| 1882 | auto video_codecs_vp8_rtx = video_codecs; |
| 1883 | it = std::remove_if(video_codecs_vp8_rtx.begin(), video_codecs_vp8_rtx.end(), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1884 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1885 | bool r = codec.name != cricket::kVp8CodecName && |
| 1886 | codec.name != cricket::kRtxCodecName; |
| 1887 | return r; |
| 1888 | }); |
| 1889 | video_codecs_vp8_rtx.erase(it, video_codecs_vp8_rtx.end()); |
| 1890 | EXPECT_EQ(video_codecs_vp8_rtx.size(), 2u); // VP8, RTX |
| 1891 | recv_transceiver->SetCodecPreferences(video_codecs_vp8_rtx); |
| 1892 | |
| 1893 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1894 | |
| 1895 | auto recv_codecs = answer->description() |
| 1896 | ->contents()[0] |
| 1897 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1898 | ->codecs(); |
| 1899 | EXPECT_EQ(recv_codecs.size(), 1u); // VP8 |
| 1900 | } |
| 1901 | |
| 1902 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1903 | SetCodecPreferencesVideoCodecsNegotiationReverseOrder) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1904 | auto caller_fake_engine = std::make_unique<FakeMediaEngine>(); |
Johannes Kron | 3e98368 | 2020-03-29 20:17:00 | [diff] [blame] | 1905 | auto caller_video_codecs = caller_fake_engine->video().send_codecs(); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1906 | caller_video_codecs.push_back(cricket::CreateVideoCodec( |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1907 | caller_video_codecs.back().id + 1, cricket::kVp8CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1908 | caller_video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1909 | caller_video_codecs.back().id + 1, caller_video_codecs.back().id)); |
Florent Castelli | 8c4b9ea | 2023-06-02 16:06:57 | [diff] [blame] | 1910 | caller_video_codecs.push_back(cricket::CreateVideoCodec( |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1911 | caller_video_codecs.back().id + 1, cricket::kVp9CodecName)); |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1912 | caller_video_codecs.push_back(cricket::CreateVideoRtxCodec( |
| 1913 | caller_video_codecs.back().id + 1, caller_video_codecs.back().id)); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1914 | caller_fake_engine->SetVideoCodecs(caller_video_codecs); |
| 1915 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 1916 | auto callee_fake_engine = std::make_unique<FakeMediaEngine>(); |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1917 | callee_fake_engine->SetVideoCodecs(caller_video_codecs); |
| 1918 | |
| 1919 | auto caller = CreatePeerConnectionWithVideo(std::move(caller_fake_engine)); |
| 1920 | auto callee = CreatePeerConnection(std::move(callee_fake_engine)); |
| 1921 | |
| 1922 | auto video_codecs = caller->pc_factory() |
| 1923 | ->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO) |
| 1924 | .codecs; |
| 1925 | |
| 1926 | auto send_transceiver = caller->pc()->GetTransceivers().front(); |
| 1927 | |
| 1928 | auto video_codecs_vpx = video_codecs; |
| 1929 | auto it = std::remove_if(video_codecs_vpx.begin(), video_codecs_vpx.end(), |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 1930 | [](const RtpCodecCapability& codec) { |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1931 | return codec.name != cricket::kVp8CodecName && |
| 1932 | codec.name != cricket::kVp9CodecName; |
| 1933 | }); |
| 1934 | video_codecs_vpx.erase(it, video_codecs_vpx.end()); |
| 1935 | EXPECT_EQ(video_codecs_vpx.size(), 2u); // VP8, VP9 |
| 1936 | EXPECT_TRUE(send_transceiver->SetCodecPreferences(video_codecs_vpx).ok()); |
| 1937 | |
| 1938 | auto video_codecs_vpx_reverse = video_codecs_vpx; |
| 1939 | absl::c_reverse(video_codecs_vpx_reverse); |
| 1940 | |
| 1941 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 1942 | auto codecs = offer->description() |
| 1943 | ->contents()[0] |
| 1944 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1945 | ->codecs(); |
| 1946 | EXPECT_EQ(codecs.size(), 2u); // VP9, VP8 |
| 1947 | EXPECT_TRUE(CompareCodecs(video_codecs_vpx, codecs)); |
| 1948 | |
| 1949 | callee->SetRemoteDescription(std::move(offer)); |
| 1950 | |
| 1951 | auto recv_transceiver = callee->pc()->GetTransceivers().front(); |
| 1952 | recv_transceiver->SetCodecPreferences(video_codecs_vpx_reverse); |
| 1953 | |
| 1954 | auto answer = callee->CreateAnswerAndSetAsLocal(); |
| 1955 | |
| 1956 | auto recv_codecs = answer->description() |
| 1957 | ->contents()[0] |
| 1958 | .media_description() |
Florent Castelli | 2d9d82e | 2019-04-23 17:25:51 | [diff] [blame] | 1959 | ->codecs(); |
| 1960 | |
| 1961 | EXPECT_TRUE(CompareCodecs(video_codecs_vpx_reverse, recv_codecs)); |
| 1962 | } |
| 1963 | |
Philipp Hancke | 3ac73bd | 2021-05-11 12:13:06 | [diff] [blame] | 1964 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1965 | SetCodecPreferencesVoiceActivityDetection) { |
| 1966 | auto fake_engine = std::make_unique<FakeMediaEngine>(); |
| 1967 | AddComfortNoiseCodecsToSend(fake_engine.get()); |
| 1968 | auto caller = CreatePeerConnectionWithAudio(std::move(fake_engine)); |
| 1969 | |
| 1970 | RTCOfferAnswerOptions options; |
| 1971 | auto offer = caller->CreateOffer(options); |
| 1972 | EXPECT_TRUE(HasAnyComfortNoiseCodecs(offer->description())); |
| 1973 | |
| 1974 | auto transceiver = caller->pc()->GetTransceivers().front(); |
| 1975 | auto capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 1976 | cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 1977 | EXPECT_TRUE(transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 1978 | |
| 1979 | options.voice_activity_detection = false; |
| 1980 | offer = caller->CreateOffer(options); |
| 1981 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(offer->description())); |
| 1982 | } |
| 1983 | |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 1984 | // If the "default" payload types of audio/video codecs are the same, and |
| 1985 | // audio/video are bundled (as is the default), payload types should be |
| 1986 | // remapped to avoid conflict, as normally happens without using |
| 1987 | // SetCodecPreferences. |
| 1988 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 1989 | SetCodecPreferencesAvoidsPayloadTypeConflictInOffer) { |
| 1990 | auto fake_engine = std::make_unique<cricket::FakeMediaEngine>(); |
| 1991 | |
| 1992 | std::vector<cricket::AudioCodec> audio_codecs; |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1993 | audio_codecs.emplace_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
| 1994 | audio_codecs.emplace_back(cricket::CreateAudioRtxCodec(101, 100)); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 1995 | fake_engine->SetAudioCodecs(audio_codecs); |
| 1996 | |
| 1997 | std::vector<cricket::VideoCodec> video_codecs; |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 1998 | video_codecs.emplace_back(cricket::CreateVideoCodec(100, "bar")); |
| 1999 | video_codecs.emplace_back(cricket::CreateVideoRtxCodec(101, 100)); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 2000 | fake_engine->SetVideoCodecs(video_codecs); |
| 2001 | |
| 2002 | auto caller = CreatePeerConnectionWithAudioVideo(std::move(fake_engine)); |
| 2003 | auto transceivers = caller->pc()->GetTransceivers(); |
| 2004 | ASSERT_EQ(2u, transceivers.size()); |
| 2005 | |
| 2006 | auto audio_transceiver = caller->pc()->GetTransceivers()[0]; |
| 2007 | auto capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 2008 | cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 2009 | EXPECT_TRUE(audio_transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 2010 | |
| 2011 | auto video_transceiver = caller->pc()->GetTransceivers()[1]; |
| 2012 | capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 2013 | cricket::MediaType::MEDIA_TYPE_VIDEO); |
| 2014 | EXPECT_TRUE(video_transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 2015 | |
| 2016 | RTCOfferAnswerOptions options; |
| 2017 | auto offer = caller->CreateOffer(options); |
| 2018 | EXPECT_FALSE(HasPayloadTypeConflict(offer->description())); |
| 2019 | // Sanity check that we got the primary codec and RTX. |
| 2020 | EXPECT_EQ(2u, cricket::GetFirstAudioContentDescription(offer->description()) |
| 2021 | ->codecs() |
| 2022 | .size()); |
| 2023 | EXPECT_EQ(2u, cricket::GetFirstVideoContentDescription(offer->description()) |
| 2024 | ->codecs() |
| 2025 | .size()); |
| 2026 | } |
| 2027 | |
| 2028 | // Same as above, but preferences set for the answer. |
| 2029 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 2030 | SetCodecPreferencesAvoidsPayloadTypeConflictInAnswer) { |
| 2031 | auto fake_engine = std::make_unique<cricket::FakeMediaEngine>(); |
| 2032 | |
| 2033 | std::vector<cricket::AudioCodec> audio_codecs; |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 2034 | audio_codecs.emplace_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
| 2035 | audio_codecs.emplace_back(cricket::CreateAudioRtxCodec(101, 100)); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 2036 | fake_engine->SetAudioCodecs(audio_codecs); |
| 2037 | |
| 2038 | std::vector<cricket::VideoCodec> video_codecs; |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 2039 | video_codecs.emplace_back(cricket::CreateVideoCodec(100, "bar")); |
| 2040 | video_codecs.emplace_back(cricket::CreateVideoRtxCodec(101, 100)); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 2041 | fake_engine->SetVideoCodecs(video_codecs); |
| 2042 | |
| 2043 | auto caller = CreatePeerConnectionWithAudioVideo(std::move(fake_engine)); |
| 2044 | |
| 2045 | RTCOfferAnswerOptions options; |
| 2046 | caller->SetRemoteDescription(caller->CreateOffer(options)); |
| 2047 | |
| 2048 | auto transceivers = caller->pc()->GetTransceivers(); |
| 2049 | ASSERT_EQ(2u, transceivers.size()); |
| 2050 | |
| 2051 | auto audio_transceiver = caller->pc()->GetTransceivers()[0]; |
| 2052 | auto capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 2053 | cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 2054 | EXPECT_TRUE(audio_transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 2055 | |
| 2056 | auto video_transceiver = caller->pc()->GetTransceivers()[1]; |
| 2057 | capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 2058 | cricket::MediaType::MEDIA_TYPE_VIDEO); |
| 2059 | EXPECT_TRUE(video_transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 2060 | |
| 2061 | auto answer = caller->CreateAnswer(options); |
| 2062 | |
| 2063 | EXPECT_FALSE(HasPayloadTypeConflict(answer->description())); |
| 2064 | // Sanity check that we got the primary codec and RTX. |
| 2065 | EXPECT_EQ(2u, cricket::GetFirstAudioContentDescription(answer->description()) |
| 2066 | ->codecs() |
| 2067 | .size()); |
| 2068 | EXPECT_EQ(2u, cricket::GetFirstVideoContentDescription(answer->description()) |
| 2069 | ->codecs() |
| 2070 | .size()); |
| 2071 | } |
| 2072 | |
| 2073 | // Same as above, but preferences set for a subsequent offer. |
| 2074 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 2075 | SetCodecPreferencesAvoidsPayloadTypeConflictInSubsequentOffer) { |
| 2076 | auto fake_engine = std::make_unique<cricket::FakeMediaEngine>(); |
| 2077 | |
| 2078 | std::vector<cricket::AudioCodec> audio_codecs; |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 2079 | audio_codecs.emplace_back(cricket::CreateAudioCodec(100, "foo", 0, 1)); |
| 2080 | audio_codecs.emplace_back(cricket::CreateAudioRtxCodec(101, 100)); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 2081 | fake_engine->SetAudioCodecs(audio_codecs); |
| 2082 | |
| 2083 | std::vector<cricket::VideoCodec> video_codecs; |
Florent Castelli | d0b8e8e | 2023-06-04 23:22:36 | [diff] [blame] | 2084 | video_codecs.emplace_back(cricket::CreateVideoCodec(100, "bar")); |
| 2085 | video_codecs.emplace_back(cricket::CreateVideoRtxCodec(101, 100)); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 2086 | fake_engine->SetVideoCodecs(video_codecs); |
| 2087 | |
| 2088 | auto caller = CreatePeerConnectionWithAudioVideo(std::move(fake_engine)); |
| 2089 | |
| 2090 | RTCOfferAnswerOptions options; |
| 2091 | caller->SetRemoteDescription(caller->CreateOffer(options)); |
| 2092 | caller->SetLocalDescription(caller->CreateAnswer(options)); |
| 2093 | |
| 2094 | auto transceivers = caller->pc()->GetTransceivers(); |
| 2095 | ASSERT_EQ(2u, transceivers.size()); |
| 2096 | |
| 2097 | auto audio_transceiver = caller->pc()->GetTransceivers()[0]; |
| 2098 | auto capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 2099 | cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 2100 | EXPECT_TRUE(audio_transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 2101 | |
| 2102 | auto video_transceiver = caller->pc()->GetTransceivers()[1]; |
| 2103 | capabilities = caller->pc_factory()->GetRtpSenderCapabilities( |
| 2104 | cricket::MediaType::MEDIA_TYPE_VIDEO); |
| 2105 | EXPECT_TRUE(video_transceiver->SetCodecPreferences(capabilities.codecs).ok()); |
| 2106 | |
| 2107 | auto reoffer = caller->CreateOffer(options); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 2108 | ASSERT_THAT(reoffer, NotNull()); |
Taylor Brandstetter | f7fcfb7 | 2021-09-09 20:39:38 | [diff] [blame] | 2109 | |
| 2110 | EXPECT_FALSE(HasPayloadTypeConflict(reoffer->description())); |
| 2111 | // Sanity check that we got the primary codec and RTX. |
| 2112 | EXPECT_EQ(2u, cricket::GetFirstAudioContentDescription(reoffer->description()) |
| 2113 | ->codecs() |
| 2114 | .size()); |
| 2115 | EXPECT_EQ(2u, cricket::GetFirstVideoContentDescription(reoffer->description()) |
| 2116 | ->codecs() |
| 2117 | .size()); |
| 2118 | } |
| 2119 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 2120 | INSTANTIATE_TEST_SUITE_P(PeerConnectionMediaTest, |
| 2121 | PeerConnectionMediaTest, |
Florent Castelli | 15a38de | 2022-04-05 22:38:21 | [diff] [blame] | 2122 | Values(SdpSemantics::kPlanB_DEPRECATED, |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 2123 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 2124 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 2125 | } // namespace webrtc |