blob: 7961747b646270a741106130d93ec67f643a6610 [file] [log] [blame]
Amit Hilbuchdd9390c2018-11-14 00:26:051/*
2 * Copyright 2018 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
Artem Titov880fa812021-07-30 20:30:2311// This file contains tests for `RtpTransceiver`.
Amit Hilbuchdd9390c2018-11-14 00:26:0512
Steve Anton10542f22019-01-11 17:11:0013#include "pc/rtp_transceiver.h"
Yves Gerey3e707812018-11-28 15:47:4914
Markus Handell0357b3e2020-03-16 12:40:5115#include <memory>
Harald Alvestrand3af79d12022-04-29 15:04:5816#include <utility>
Markus Handell0357b3e2020-03-16 12:40:5117
Harald Alvestrandc24a2182022-02-23 13:44:5918#include "absl/strings/string_view.h"
Markus Handell5932fe12020-12-17 21:19:4019#include "absl/types/optional.h"
Harald Alvestrandc3fa7c32022-05-22 10:57:0120#include "api/peer_connection_interface.h"
Markus Handell5932fe12020-12-17 21:19:4021#include "api/rtp_parameters.h"
Markus Handell0357b3e2020-03-16 12:40:5122#include "media/base/fake_media_engine.h"
Harald Alvestrandc24a2182022-02-23 13:44:5923#include "media/base/media_engine.h"
Steve Anton10542f22019-01-11 17:11:0024#include "pc/test/mock_channel_interface.h"
Markus Handell0357b3e2020-03-16 12:40:5125#include "pc/test/mock_rtp_receiver_internal.h"
26#include "pc/test/mock_rtp_sender_internal.h"
Harald Alvestrandc24a2182022-02-23 13:44:5927#include "rtc_base/thread.h"
Amit Hilbuchdd9390c2018-11-14 00:26:0528#include "test/gmock.h"
Yves Gerey3e707812018-11-28 15:47:4929#include "test/gtest.h"
Amit Hilbuchdd9390c2018-11-14 00:26:0530
Tommi99c8a802021-04-27 13:00:0031using ::testing::_;
Markus Handell0357b3e2020-03-16 12:40:5132using ::testing::ElementsAre;
Markus Handell5932fe12020-12-17 21:19:4033using ::testing::Optional;
Markus Handell755c65d2020-06-23 23:06:1034using ::testing::Property;
Amit Hilbuchdd9390c2018-11-14 00:26:0535using ::testing::Return;
36using ::testing::ReturnRef;
37
38namespace webrtc {
39
Tomas Gunnarsson16de2162022-01-26 09:21:5740namespace {
Harald Alvestrand0ac50b92022-05-18 07:51:3441
42class RtpTransceiverTest : public testing::Test {
Tomas Gunnarsson16de2162022-01-26 09:21:5743 public:
Harald Alvestrand0ac50b92022-05-18 07:51:3444 RtpTransceiverTest()
Harald Alvestrandc3fa7c32022-05-22 10:57:0145 : dependencies_(MakeDependencies()),
46 context_(ConnectionContext::Create(&dependencies_)) {}
Harald Alvestrand0ac50b92022-05-18 07:51:3447
48 protected:
Harald Alvestrandc3fa7c32022-05-22 10:57:0149 cricket::MediaEngineInterface* media_engine() {
50 return context_->media_engine();
51 }
52 ConnectionContext* context() { return context_.get(); }
Harald Alvestrand0ac50b92022-05-18 07:51:3453
54 private:
Niels Möller83830f32022-05-20 07:12:5755 rtc::AutoThread main_thread_;
Harald Alvestrandc3fa7c32022-05-22 10:57:0156
57 static PeerConnectionFactoryDependencies MakeDependencies() {
58 PeerConnectionFactoryDependencies d;
59 d.network_thread = rtc::Thread::Current();
60 d.worker_thread = rtc::Thread::Current();
61 d.signaling_thread = rtc::Thread::Current();
62 d.media_engine = std::make_unique<cricket::FakeMediaEngine>();
63 return d;
64 }
65
66 PeerConnectionFactoryDependencies dependencies_;
67 rtc::scoped_refptr<ConnectionContext> context_;
Tomas Gunnarsson16de2162022-01-26 09:21:5768};
Tomas Gunnarsson16de2162022-01-26 09:21:5769
Artem Titov880fa812021-07-30 20:30:2370// Checks that a channel cannot be set on a stopped `RtpTransceiver`.
Harald Alvestrand0ac50b92022-05-18 07:51:3471TEST_F(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
Tomas Gunnarsson4f8a58c2022-01-19 10:36:2372 const std::string content_name("my_mid");
Tomas Gunnarsson0d5ce622022-03-18 14:57:1573 auto transceiver = rtc::make_ref_counted<RtpTransceiver>(
Harald Alvestrandc3fa7c32022-05-22 10:57:0174 cricket::MediaType::MEDIA_TYPE_AUDIO, context());
Harald Alvestrand3af79d12022-04-29 15:04:5875 auto channel1 = std::make_unique<cricket::MockChannelInterface>();
76 EXPECT_CALL(*channel1, media_type())
Amit Hilbuchdd9390c2018-11-14 00:26:0577 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
Harald Alvestrand3af79d12022-04-29 15:04:5878 EXPECT_CALL(*channel1, mid()).WillRepeatedly(ReturnRef(content_name));
79 EXPECT_CALL(*channel1, SetFirstPacketReceivedCallback(_));
80 EXPECT_CALL(*channel1, SetRtpTransport(_)).WillRepeatedly(Return(true));
81 auto channel1_ptr = channel1.get();
82 transceiver->SetChannel(std::move(channel1), [&](const std::string& mid) {
Tomas Gunnarsson4f8a58c2022-01-19 10:36:2383 EXPECT_EQ(mid, content_name);
84 return nullptr;
85 });
Harald Alvestrand3af79d12022-04-29 15:04:5886 EXPECT_EQ(channel1_ptr, transceiver->channel());
Amit Hilbuchdd9390c2018-11-14 00:26:0587
88 // Stop the transceiver.
Tomas Gunnarsson0d5ce622022-03-18 14:57:1589 transceiver->StopInternal();
Harald Alvestrand3af79d12022-04-29 15:04:5890 EXPECT_EQ(channel1_ptr, transceiver->channel());
Amit Hilbuchdd9390c2018-11-14 00:26:0591
Harald Alvestrand3af79d12022-04-29 15:04:5892 auto channel2 = std::make_unique<cricket::MockChannelInterface>();
93 EXPECT_CALL(*channel2, media_type())
Amit Hilbuchdd9390c2018-11-14 00:26:0594 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
95
Harald Alvestranddaee8702022-04-29 11:42:5596 // Clear the current channel - required to allow SetChannel()
Harald Alvestrand3af79d12022-04-29 15:04:5897 EXPECT_CALL(*channel1_ptr, SetFirstPacketReceivedCallback(_));
Harald Alvestranddaee8702022-04-29 11:42:5598 transceiver->ClearChannel();
Amit Hilbuchdd9390c2018-11-14 00:26:0599 // Channel can no longer be set, so this call should be a no-op.
Harald Alvestrand3af79d12022-04-29 15:04:58100 transceiver->SetChannel(std::move(channel2),
Tomas Gunnarsson0d5ce622022-03-18 14:57:15101 [](const std::string&) { return nullptr; });
Harald Alvestranddaee8702022-04-29 11:42:55102 EXPECT_EQ(nullptr, transceiver->channel());
Amit Hilbuchdd9390c2018-11-14 00:26:05103}
104
Artem Titov880fa812021-07-30 20:30:23105// Checks that a channel can be unset on a stopped `RtpTransceiver`
Harald Alvestrand0ac50b92022-05-18 07:51:34106TEST_F(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
Tomas Gunnarsson4f8a58c2022-01-19 10:36:23107 const std::string content_name("my_mid");
Tomas Gunnarsson0d5ce622022-03-18 14:57:15108 auto transceiver = rtc::make_ref_counted<RtpTransceiver>(
Harald Alvestrandc3fa7c32022-05-22 10:57:01109 cricket::MediaType::MEDIA_TYPE_VIDEO, context());
Harald Alvestrand3af79d12022-04-29 15:04:58110 auto channel = std::make_unique<cricket::MockChannelInterface>();
111 EXPECT_CALL(*channel, media_type())
Amit Hilbuchdd9390c2018-11-14 00:26:05112 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO));
Harald Alvestrand3af79d12022-04-29 15:04:58113 EXPECT_CALL(*channel, mid()).WillRepeatedly(ReturnRef(content_name));
114 EXPECT_CALL(*channel, SetFirstPacketReceivedCallback(_))
Tommi99c8a802021-04-27 13:00:00115 .WillRepeatedly(testing::Return());
Harald Alvestrand3af79d12022-04-29 15:04:58116 EXPECT_CALL(*channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
Amit Hilbuchdd9390c2018-11-14 00:26:05117
Harald Alvestrand3af79d12022-04-29 15:04:58118 auto channel_ptr = channel.get();
119 transceiver->SetChannel(std::move(channel), [&](const std::string& mid) {
Tomas Gunnarsson4f8a58c2022-01-19 10:36:23120 EXPECT_EQ(mid, content_name);
121 return nullptr;
122 });
Harald Alvestrand3af79d12022-04-29 15:04:58123 EXPECT_EQ(channel_ptr, transceiver->channel());
Amit Hilbuchdd9390c2018-11-14 00:26:05124
125 // Stop the transceiver.
Tomas Gunnarsson0d5ce622022-03-18 14:57:15126 transceiver->StopInternal();
Harald Alvestrand3af79d12022-04-29 15:04:58127 EXPECT_EQ(channel_ptr, transceiver->channel());
Amit Hilbuchdd9390c2018-11-14 00:26:05128
Artem Titov880fa812021-07-30 20:30:23129 // Set the channel to `nullptr`.
Harald Alvestrand19ebabc2022-04-28 13:31:17130 transceiver->ClearChannel();
Tomas Gunnarsson0d5ce622022-03-18 14:57:15131 EXPECT_EQ(nullptr, transceiver->channel());
Amit Hilbuchdd9390c2018-11-14 00:26:05132}
133
Harald Alvestrand0ac50b92022-05-18 07:51:34134class RtpTransceiverUnifiedPlanTest : public RtpTransceiverTest {
Harald Alvestrandc75c4282020-08-26 12:17:54135 public:
136 RtpTransceiverUnifiedPlanTest()
Tomas Gunnarsson0d5ce622022-03-18 14:57:15137 : transceiver_(rtc::make_ref_counted<RtpTransceiver>(
138 RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
139 rtc::Thread::Current(),
140 sender_),
141 RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
142 rtc::Thread::Current(),
143 rtc::Thread::Current(),
144 receiver_),
Harald Alvestrandc3fa7c32022-05-22 10:57:01145 context(),
146 media_engine()->voice().GetRtpHeaderExtensions(),
Tomas Gunnarsson0d5ce622022-03-18 14:57:15147 /* on_negotiation_needed= */ [] {})) {}
Harald Alvestrandc75c4282020-08-26 12:17:54148
Tommi99c8a802021-04-27 13:00:00149 static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
150 auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
151 EXPECT_CALL(*receiver.get(), media_type())
152 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
153 return receiver;
154 }
155
156 static rtc::scoped_refptr<MockRtpSenderInternal> MockSender() {
157 auto sender = rtc::make_ref_counted<MockRtpSenderInternal>();
158 EXPECT_CALL(*sender.get(), media_type())
159 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
160 return sender;
161 }
162
Niels Möller83830f32022-05-20 07:12:57163 rtc::AutoThread main_thread_;
Tommi99c8a802021-04-27 13:00:00164 rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
165 rtc::scoped_refptr<MockRtpSenderInternal> sender_ = MockSender();
Tomas Gunnarsson0d5ce622022-03-18 14:57:15166 rtc::scoped_refptr<RtpTransceiver> transceiver_;
Harald Alvestrandc75c4282020-08-26 12:17:54167};
168
169// Basic tests for Stop()
170TEST_F(RtpTransceiverUnifiedPlanTest, StopSetsDirection) {
Tommi6589def2022-02-17 22:36:47171 EXPECT_CALL(*receiver_.get(), Stop());
172 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00173 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
174 EXPECT_CALL(*sender_.get(), Stop());
175
Tomas Gunnarsson0d5ce622022-03-18 14:57:15176 EXPECT_EQ(RtpTransceiverDirection::kInactive, transceiver_->direction());
177 EXPECT_FALSE(transceiver_->current_direction());
178 transceiver_->StopStandard();
179 EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_->direction());
180 EXPECT_FALSE(transceiver_->current_direction());
181 transceiver_->StopTransceiverProcedure();
182 EXPECT_TRUE(transceiver_->current_direction());
183 EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_->direction());
Harald Alvestrandc75c4282020-08-26 12:17:54184 EXPECT_EQ(RtpTransceiverDirection::kStopped,
Tomas Gunnarsson0d5ce622022-03-18 14:57:15185 *transceiver_->current_direction());
Harald Alvestrandc75c4282020-08-26 12:17:54186}
187
Harald Alvestrand0ac50b92022-05-18 07:51:34188class RtpTransceiverTestForHeaderExtensions : public RtpTransceiverTest {
Markus Handell755c65d2020-06-23 23:06:10189 public:
190 RtpTransceiverTestForHeaderExtensions()
Tomas Gunnarsson16de2162022-01-26 09:21:57191 : extensions_(
Markus Handell755c65d2020-06-23 23:06:10192 {RtpHeaderExtensionCapability("uri1",
193 1,
194 RtpTransceiverDirection::kSendOnly),
195 RtpHeaderExtensionCapability("uri2",
196 2,
197 RtpTransceiverDirection::kRecvOnly),
198 RtpHeaderExtensionCapability(RtpExtension::kMidUri,
199 3,
200 RtpTransceiverDirection::kSendRecv),
201 RtpHeaderExtensionCapability(RtpExtension::kVideoRotationUri,
202 4,
203 RtpTransceiverDirection::kSendRecv)}),
Tomas Gunnarsson0d5ce622022-03-18 14:57:15204 transceiver_(rtc::make_ref_counted<RtpTransceiver>(
205 RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
206 rtc::Thread::Current(),
207 sender_),
208 RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
209 rtc::Thread::Current(),
210 rtc::Thread::Current(),
211 receiver_),
Harald Alvestrandc3fa7c32022-05-22 10:57:01212 context(),
Tomas Gunnarsson0d5ce622022-03-18 14:57:15213 extensions_,
214 /* on_negotiation_needed= */ [] {})) {}
Markus Handell755c65d2020-06-23 23:06:10215
Tommi99c8a802021-04-27 13:00:00216 static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
217 auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
218 EXPECT_CALL(*receiver.get(), media_type())
219 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
220 return receiver;
221 }
222
223 static rtc::scoped_refptr<MockRtpSenderInternal> MockSender() {
224 auto sender = rtc::make_ref_counted<MockRtpSenderInternal>();
225 EXPECT_CALL(*sender.get(), media_type())
226 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
227 return sender;
228 }
229
Harald Alvestrand3af79d12022-04-29 15:04:58230 void ClearChannel() {
Tommi6589def2022-02-17 22:36:47231 EXPECT_CALL(*sender_.get(), SetMediaChannel(_));
Harald Alvestrand19ebabc2022-04-28 13:31:17232 transceiver_->ClearChannel();
Tomas Gunnarsson16de2162022-01-26 09:21:57233 }
234
Niels Möller83830f32022-05-20 07:12:57235 rtc::AutoThread main_thread_;
Tommi99c8a802021-04-27 13:00:00236 rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
237 rtc::scoped_refptr<MockRtpSenderInternal> sender_ = MockSender();
238
Markus Handell755c65d2020-06-23 23:06:10239 std::vector<RtpHeaderExtensionCapability> extensions_;
Tomas Gunnarsson0d5ce622022-03-18 14:57:15240 rtc::scoped_refptr<RtpTransceiver> transceiver_;
Markus Handell755c65d2020-06-23 23:06:10241};
242
243TEST_F(RtpTransceiverTestForHeaderExtensions, OffersChannelManagerList) {
Tommi6589def2022-02-17 22:36:47244 EXPECT_CALL(*receiver_.get(), Stop());
245 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00246 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
247 EXPECT_CALL(*sender_.get(), Stop());
248
Tomas Gunnarsson0d5ce622022-03-18 14:57:15249 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
Markus Handell755c65d2020-06-23 23:06:10250}
251
252TEST_F(RtpTransceiverTestForHeaderExtensions, ModifiesDirection) {
Tommi6589def2022-02-17 22:36:47253 EXPECT_CALL(*receiver_.get(), Stop());
254 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00255 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
256 EXPECT_CALL(*sender_.get(), Stop());
257
Markus Handell755c65d2020-06-23 23:06:10258 auto modified_extensions = extensions_;
259 modified_extensions[0].direction = RtpTransceiverDirection::kSendOnly;
260 EXPECT_TRUE(
Tomas Gunnarsson0d5ce622022-03-18 14:57:15261 transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
262 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
Markus Handell755c65d2020-06-23 23:06:10263 modified_extensions[0].direction = RtpTransceiverDirection::kRecvOnly;
264 EXPECT_TRUE(
Tomas Gunnarsson0d5ce622022-03-18 14:57:15265 transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
266 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
Markus Handell755c65d2020-06-23 23:06:10267 modified_extensions[0].direction = RtpTransceiverDirection::kSendRecv;
268 EXPECT_TRUE(
Tomas Gunnarsson0d5ce622022-03-18 14:57:15269 transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
270 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
Markus Handell755c65d2020-06-23 23:06:10271 modified_extensions[0].direction = RtpTransceiverDirection::kInactive;
272 EXPECT_TRUE(
Tomas Gunnarsson0d5ce622022-03-18 14:57:15273 transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
274 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
Markus Handell755c65d2020-06-23 23:06:10275}
276
277TEST_F(RtpTransceiverTestForHeaderExtensions, AcceptsStoppedExtension) {
Tommi6589def2022-02-17 22:36:47278 EXPECT_CALL(*receiver_.get(), Stop());
279 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00280 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
281 EXPECT_CALL(*sender_.get(), Stop());
282
Markus Handell755c65d2020-06-23 23:06:10283 auto modified_extensions = extensions_;
284 modified_extensions[0].direction = RtpTransceiverDirection::kStopped;
285 EXPECT_TRUE(
Tomas Gunnarsson0d5ce622022-03-18 14:57:15286 transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
287 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
Markus Handell755c65d2020-06-23 23:06:10288}
289
290TEST_F(RtpTransceiverTestForHeaderExtensions, RejectsUnsupportedExtension) {
Tommi6589def2022-02-17 22:36:47291 EXPECT_CALL(*receiver_.get(), Stop());
292 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00293 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
294 EXPECT_CALL(*sender_.get(), Stop());
295
Markus Handell755c65d2020-06-23 23:06:10296 std::vector<RtpHeaderExtensionCapability> modified_extensions(
297 {RtpHeaderExtensionCapability("uri3", 1,
298 RtpTransceiverDirection::kSendRecv)});
Tomas Gunnarsson0d5ce622022-03-18 14:57:15299 EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
Markus Handellc17bca72021-01-14 16:08:01300 Property(&RTCError::type, RTCErrorType::UNSUPPORTED_PARAMETER));
Tomas Gunnarsson0d5ce622022-03-18 14:57:15301 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
Markus Handell755c65d2020-06-23 23:06:10302}
303
304TEST_F(RtpTransceiverTestForHeaderExtensions,
305 RejectsStoppedMandatoryExtensions) {
Tommi6589def2022-02-17 22:36:47306 EXPECT_CALL(*receiver_.get(), Stop());
307 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00308 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
309 EXPECT_CALL(*sender_.get(), Stop());
310
Markus Handell755c65d2020-06-23 23:06:10311 std::vector<RtpHeaderExtensionCapability> modified_extensions = extensions_;
312 // Attempting to stop the mandatory MID extension.
313 modified_extensions[2].direction = RtpTransceiverDirection::kStopped;
Tomas Gunnarsson0d5ce622022-03-18 14:57:15314 EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
Markus Handell755c65d2020-06-23 23:06:10315 Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
Tomas Gunnarsson0d5ce622022-03-18 14:57:15316 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
Markus Handell755c65d2020-06-23 23:06:10317 modified_extensions = extensions_;
318 // Attempting to stop the mandatory video orientation extension.
319 modified_extensions[3].direction = RtpTransceiverDirection::kStopped;
Tomas Gunnarsson0d5ce622022-03-18 14:57:15320 EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
Markus Handell755c65d2020-06-23 23:06:10321 Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
Tomas Gunnarsson0d5ce622022-03-18 14:57:15322 EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
Markus Handell0357b3e2020-03-16 12:40:51323}
324
Markus Handell5932fe12020-12-17 21:19:40325TEST_F(RtpTransceiverTestForHeaderExtensions,
326 NoNegotiatedHdrExtsWithoutChannel) {
Tommi6589def2022-02-17 22:36:47327 EXPECT_CALL(*receiver_.get(), Stop());
328 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00329 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
330 EXPECT_CALL(*sender_.get(), Stop());
Tomas Gunnarsson0d5ce622022-03-18 14:57:15331 EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(), ElementsAre());
Markus Handell5932fe12020-12-17 21:19:40332}
333
334TEST_F(RtpTransceiverTestForHeaderExtensions,
335 NoNegotiatedHdrExtsWithChannelWithoutNegotiation) {
Tomas Gunnarsson4f8a58c2022-01-19 10:36:23336 const std::string content_name("my_mid");
Tommi6589def2022-02-17 22:36:47337 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_)).WillRepeatedly(Return());
338 EXPECT_CALL(*receiver_.get(), Stop()).WillRepeatedly(Return());
Tommi99c8a802021-04-27 13:00:00339 EXPECT_CALL(*sender_.get(), SetMediaChannel(_));
340 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
341 EXPECT_CALL(*sender_.get(), Stop());
Harald Alvestrand3af79d12022-04-29 15:04:58342 auto mock_channel = std::make_unique<cricket::MockChannelInterface>();
343 auto mock_channel_ptr = mock_channel.get();
344 EXPECT_CALL(*mock_channel, SetFirstPacketReceivedCallback(_));
345 EXPECT_CALL(*mock_channel, media_type())
Tommi99c8a802021-04-27 13:00:00346 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
Harald Alvestrand3af79d12022-04-29 15:04:58347 EXPECT_CALL(*mock_channel, media_channel()).WillRepeatedly(Return(nullptr));
348 EXPECT_CALL(*mock_channel, mid()).WillRepeatedly(ReturnRef(content_name));
349 EXPECT_CALL(*mock_channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
350 transceiver_->SetChannel(std::move(mock_channel),
Tomas Gunnarsson0d5ce622022-03-18 14:57:15351 [](const std::string&) { return nullptr; });
352 EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(), ElementsAre());
Tomas Gunnarsson16de2162022-01-26 09:21:57353
Harald Alvestrand3af79d12022-04-29 15:04:58354 EXPECT_CALL(*mock_channel_ptr, SetFirstPacketReceivedCallback(_));
355 ClearChannel();
Markus Handell5932fe12020-12-17 21:19:40356}
357
358TEST_F(RtpTransceiverTestForHeaderExtensions, ReturnsNegotiatedHdrExts) {
Tomas Gunnarsson4f8a58c2022-01-19 10:36:23359 const std::string content_name("my_mid");
Tommi6589def2022-02-17 22:36:47360 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_)).WillRepeatedly(Return());
361 EXPECT_CALL(*receiver_.get(), Stop()).WillRepeatedly(Return());
Tommi99c8a802021-04-27 13:00:00362 EXPECT_CALL(*sender_.get(), SetMediaChannel(_));
363 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
364 EXPECT_CALL(*sender_.get(), Stop());
365
Harald Alvestrand3af79d12022-04-29 15:04:58366 auto mock_channel = std::make_unique<cricket::MockChannelInterface>();
367 auto mock_channel_ptr = mock_channel.get();
368 EXPECT_CALL(*mock_channel, SetFirstPacketReceivedCallback(_));
369 EXPECT_CALL(*mock_channel, media_type())
Tommi99c8a802021-04-27 13:00:00370 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
Harald Alvestrand3af79d12022-04-29 15:04:58371 EXPECT_CALL(*mock_channel, media_channel()).WillRepeatedly(Return(nullptr));
372 EXPECT_CALL(*mock_channel, mid()).WillRepeatedly(ReturnRef(content_name));
373 EXPECT_CALL(*mock_channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
Tommicc7a3682021-05-04 12:59:38374
Markus Handell5932fe12020-12-17 21:19:40375 cricket::RtpHeaderExtensions extensions = {webrtc::RtpExtension("uri1", 1),
376 webrtc::RtpExtension("uri2", 2)};
Tommicc7a3682021-05-04 12:59:38377 cricket::AudioContentDescription description;
378 description.set_rtp_header_extensions(extensions);
Tomas Gunnarsson0d5ce622022-03-18 14:57:15379 transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
Tommicc7a3682021-05-04 12:59:38380
Harald Alvestrand3af79d12022-04-29 15:04:58381 transceiver_->SetChannel(std::move(mock_channel),
Tomas Gunnarsson0d5ce622022-03-18 14:57:15382 [](const std::string&) { return nullptr; });
383 EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
Markus Handell5932fe12020-12-17 21:19:40384 ElementsAre(RtpHeaderExtensionCapability(
385 "uri1", 1, RtpTransceiverDirection::kSendRecv),
386 RtpHeaderExtensionCapability(
387 "uri2", 2, RtpTransceiverDirection::kSendRecv)));
Tomas Gunnarsson16de2162022-01-26 09:21:57388
Harald Alvestrand3af79d12022-04-29 15:04:58389 EXPECT_CALL(*mock_channel_ptr, SetFirstPacketReceivedCallback(_));
390 ClearChannel();
Markus Handell5932fe12020-12-17 21:19:40391}
392
393TEST_F(RtpTransceiverTestForHeaderExtensions,
394 ReturnsNegotiatedHdrExtsSecondTime) {
Tommi6589def2022-02-17 22:36:47395 EXPECT_CALL(*receiver_.get(), Stop());
396 EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
Tommi99c8a802021-04-27 13:00:00397 EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
398 EXPECT_CALL(*sender_.get(), Stop());
399
Markus Handell5932fe12020-12-17 21:19:40400 cricket::RtpHeaderExtensions extensions = {webrtc::RtpExtension("uri1", 1),
401 webrtc::RtpExtension("uri2", 2)};
Tommicc7a3682021-05-04 12:59:38402 cricket::AudioContentDescription description;
403 description.set_rtp_header_extensions(extensions);
Tomas Gunnarsson0d5ce622022-03-18 14:57:15404 transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
Markus Handell5932fe12020-12-17 21:19:40405
Tomas Gunnarsson0d5ce622022-03-18 14:57:15406 EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
Tommicc7a3682021-05-04 12:59:38407 ElementsAre(RtpHeaderExtensionCapability(
408 "uri1", 1, RtpTransceiverDirection::kSendRecv),
409 RtpHeaderExtensionCapability(
410 "uri2", 2, RtpTransceiverDirection::kSendRecv)));
Markus Handell5932fe12020-12-17 21:19:40411
412 extensions = {webrtc::RtpExtension("uri3", 4),
413 webrtc::RtpExtension("uri5", 6)};
Tommicc7a3682021-05-04 12:59:38414 description.set_rtp_header_extensions(extensions);
Tomas Gunnarsson0d5ce622022-03-18 14:57:15415 transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
Tommicc7a3682021-05-04 12:59:38416
Tomas Gunnarsson0d5ce622022-03-18 14:57:15417 EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
Markus Handell5932fe12020-12-17 21:19:40418 ElementsAre(RtpHeaderExtensionCapability(
419 "uri3", 4, RtpTransceiverDirection::kSendRecv),
420 RtpHeaderExtensionCapability(
421 "uri5", 6, RtpTransceiverDirection::kSendRecv)));
422}
423
Harald Alvestrand0ac50b92022-05-18 07:51:34424} // namespace
425
Amit Hilbuchdd9390c2018-11-14 00:26:05426} // namespace webrtc