webrtc_m130/pc/rtp_transceiver_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

409 lines
17 KiB
C++
Raw Normal View History

/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// This file contains tests for `RtpTransceiver`.
#include "pc/rtp_transceiver.h"
#include <memory>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/rtp_parameters.h"
#include "media/base/fake_media_engine.h"
#include "media/base/media_engine.h"
#include "pc/test/mock_channel_interface.h"
#include "pc/test/mock_rtp_receiver_internal.h"
#include "pc/test/mock_rtp_sender_internal.h"
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
using ::testing::_;
using ::testing::ElementsAre;
using ::testing::Optional;
using ::testing::Property;
using ::testing::Return;
using ::testing::ReturnRef;
namespace webrtc {
namespace {
class ChannelManagerForTest : public cricket::ChannelManager {
public:
ChannelManagerForTest()
: cricket::ChannelManager(std::make_unique<cricket::FakeMediaEngine>(),
true,
rtc::Thread::Current(),
rtc::Thread::Current()) {}
MOCK_METHOD(void, DestroyChannel, (cricket::ChannelInterface*), (override));
};
} // namespace
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// Checks that a channel cannot be set on a stopped `RtpTransceiver`.
TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
ChannelManagerForTest cm;
const std::string content_name("my_mid");
auto transceiver = rtc::make_ref_counted<RtpTransceiver>(
cricket::MediaType::MEDIA_TYPE_AUDIO, &cm);
cricket::MockChannelInterface channel1;
EXPECT_CALL(channel1, media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
EXPECT_CALL(channel1, mid()).WillRepeatedly(ReturnRef(content_name));
EXPECT_CALL(channel1, SetFirstPacketReceivedCallback(_));
EXPECT_CALL(channel1, SetRtpTransport(_)).WillRepeatedly(Return(true));
transceiver->SetChannel(&channel1, [&](const std::string& mid) {
EXPECT_EQ(mid, content_name);
return nullptr;
});
EXPECT_EQ(&channel1, transceiver->channel());
// Stop the transceiver.
transceiver->StopInternal();
EXPECT_EQ(&channel1, transceiver->channel());
cricket::MockChannelInterface channel2;
EXPECT_CALL(channel2, media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
// Channel can no longer be set, so this call should be a no-op.
transceiver->SetChannel(&channel2,
[](const std::string&) { return nullptr; });
EXPECT_EQ(&channel1, transceiver->channel());
// Clear the current channel before `transceiver` goes out of scope.
EXPECT_CALL(channel1, SetFirstPacketReceivedCallback(_));
EXPECT_CALL(cm, DestroyChannel(&channel1)).WillRepeatedly(testing::Return());
transceiver->ClearChannel();
}
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// Checks that a channel can be unset on a stopped `RtpTransceiver`
TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
ChannelManagerForTest cm;
const std::string content_name("my_mid");
auto transceiver = rtc::make_ref_counted<RtpTransceiver>(
cricket::MediaType::MEDIA_TYPE_VIDEO, &cm);
cricket::MockChannelInterface channel;
EXPECT_CALL(channel, media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO));
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
EXPECT_CALL(channel, mid()).WillRepeatedly(ReturnRef(content_name));
EXPECT_CALL(channel, SetFirstPacketReceivedCallback(_))
.WillRepeatedly(testing::Return());
EXPECT_CALL(channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
EXPECT_CALL(cm, DestroyChannel(&channel)).WillRepeatedly(testing::Return());
transceiver->SetChannel(&channel, [&](const std::string& mid) {
EXPECT_EQ(mid, content_name);
return nullptr;
});
EXPECT_EQ(&channel, transceiver->channel());
// Stop the transceiver.
transceiver->StopInternal();
EXPECT_EQ(&channel, transceiver->channel());
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// Set the channel to `nullptr`.
transceiver->ClearChannel();
EXPECT_EQ(nullptr, transceiver->channel());
}
class RtpTransceiverUnifiedPlanTest : public ::testing::Test {
public:
RtpTransceiverUnifiedPlanTest()
: transceiver_(rtc::make_ref_counted<RtpTransceiver>(
RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
rtc::Thread::Current(),
sender_),
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
rtc::Thread::Current(),
rtc::Thread::Current(),
receiver_),
&channel_manager_,
channel_manager_.GetSupportedAudioRtpHeaderExtensions(),
/* on_negotiation_needed= */ [] {})) {}
static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
EXPECT_CALL(*receiver.get(), media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
return receiver;
}
static rtc::scoped_refptr<MockRtpSenderInternal> MockSender() {
auto sender = rtc::make_ref_counted<MockRtpSenderInternal>();
EXPECT_CALL(*sender.get(), media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
return sender;
}
rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
rtc::scoped_refptr<MockRtpSenderInternal> sender_ = MockSender();
ChannelManagerForTest channel_manager_;
rtc::scoped_refptr<RtpTransceiver> transceiver_;
};
// Basic tests for Stop()
TEST_F(RtpTransceiverUnifiedPlanTest, StopSetsDirection) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
EXPECT_EQ(RtpTransceiverDirection::kInactive, transceiver_->direction());
EXPECT_FALSE(transceiver_->current_direction());
transceiver_->StopStandard();
EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_->direction());
EXPECT_FALSE(transceiver_->current_direction());
transceiver_->StopTransceiverProcedure();
EXPECT_TRUE(transceiver_->current_direction());
EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_->direction());
EXPECT_EQ(RtpTransceiverDirection::kStopped,
*transceiver_->current_direction());
}
class RtpTransceiverTestForHeaderExtensions : public ::testing::Test {
public:
RtpTransceiverTestForHeaderExtensions()
: extensions_(
{RtpHeaderExtensionCapability("uri1",
1,
RtpTransceiverDirection::kSendOnly),
RtpHeaderExtensionCapability("uri2",
2,
RtpTransceiverDirection::kRecvOnly),
RtpHeaderExtensionCapability(RtpExtension::kMidUri,
3,
RtpTransceiverDirection::kSendRecv),
RtpHeaderExtensionCapability(RtpExtension::kVideoRotationUri,
4,
RtpTransceiverDirection::kSendRecv)}),
transceiver_(rtc::make_ref_counted<RtpTransceiver>(
RtpSenderProxyWithInternal<RtpSenderInternal>::Create(
rtc::Thread::Current(),
sender_),
RtpReceiverProxyWithInternal<RtpReceiverInternal>::Create(
rtc::Thread::Current(),
rtc::Thread::Current(),
receiver_),
&channel_manager_,
extensions_,
/* on_negotiation_needed= */ [] {})) {}
static rtc::scoped_refptr<MockRtpReceiverInternal> MockReceiver() {
auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>();
EXPECT_CALL(*receiver.get(), media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
return receiver;
}
static rtc::scoped_refptr<MockRtpSenderInternal> MockSender() {
auto sender = rtc::make_ref_counted<MockRtpSenderInternal>();
EXPECT_CALL(*sender.get(), media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
return sender;
}
void ClearChannel(cricket::MockChannelInterface& mock_channel) {
EXPECT_CALL(*sender_.get(), SetMediaChannel(_));
EXPECT_CALL(mock_channel, SetFirstPacketReceivedCallback(_));
EXPECT_CALL(channel_manager_, DestroyChannel(&mock_channel))
.WillRepeatedly(testing::Return());
transceiver_->ClearChannel();
}
rtc::scoped_refptr<MockRtpReceiverInternal> receiver_ = MockReceiver();
rtc::scoped_refptr<MockRtpSenderInternal> sender_ = MockSender();
ChannelManagerForTest channel_manager_;
std::vector<RtpHeaderExtensionCapability> extensions_;
rtc::scoped_refptr<RtpTransceiver> transceiver_;
};
TEST_F(RtpTransceiverTestForHeaderExtensions, OffersChannelManagerList) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
}
TEST_F(RtpTransceiverTestForHeaderExtensions, ModifiesDirection) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
auto modified_extensions = extensions_;
modified_extensions[0].direction = RtpTransceiverDirection::kSendOnly;
EXPECT_TRUE(
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
modified_extensions[0].direction = RtpTransceiverDirection::kRecvOnly;
EXPECT_TRUE(
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
modified_extensions[0].direction = RtpTransceiverDirection::kSendRecv;
EXPECT_TRUE(
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
modified_extensions[0].direction = RtpTransceiverDirection::kInactive;
EXPECT_TRUE(
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
}
TEST_F(RtpTransceiverTestForHeaderExtensions, AcceptsStoppedExtension) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
auto modified_extensions = extensions_;
modified_extensions[0].direction = RtpTransceiverDirection::kStopped;
EXPECT_TRUE(
transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions).ok());
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), modified_extensions);
}
TEST_F(RtpTransceiverTestForHeaderExtensions, RejectsUnsupportedExtension) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
std::vector<RtpHeaderExtensionCapability> modified_extensions(
{RtpHeaderExtensionCapability("uri3", 1,
RtpTransceiverDirection::kSendRecv)});
EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
Property(&RTCError::type, RTCErrorType::UNSUPPORTED_PARAMETER));
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
}
TEST_F(RtpTransceiverTestForHeaderExtensions,
RejectsStoppedMandatoryExtensions) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
std::vector<RtpHeaderExtensionCapability> modified_extensions = extensions_;
// Attempting to stop the mandatory MID extension.
modified_extensions[2].direction = RtpTransceiverDirection::kStopped;
EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
modified_extensions = extensions_;
// Attempting to stop the mandatory video orientation extension.
modified_extensions[3].direction = RtpTransceiverDirection::kStopped;
EXPECT_THAT(transceiver_->SetOfferedRtpHeaderExtensions(modified_extensions),
Property(&RTCError::type, RTCErrorType::INVALID_MODIFICATION));
EXPECT_EQ(transceiver_->HeaderExtensionsToOffer(), extensions_);
}
TEST_F(RtpTransceiverTestForHeaderExtensions,
NoNegotiatedHdrExtsWithoutChannel) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(), ElementsAre());
}
TEST_F(RtpTransceiverTestForHeaderExtensions,
NoNegotiatedHdrExtsWithChannelWithoutNegotiation) {
const std::string content_name("my_mid");
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_)).WillRepeatedly(Return());
EXPECT_CALL(*receiver_.get(), Stop()).WillRepeatedly(Return());
EXPECT_CALL(*sender_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
cricket::MockChannelInterface mock_channel;
EXPECT_CALL(mock_channel, SetFirstPacketReceivedCallback(_));
EXPECT_CALL(mock_channel, media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
EXPECT_CALL(mock_channel, media_channel()).WillRepeatedly(Return(nullptr));
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
EXPECT_CALL(mock_channel, mid()).WillRepeatedly(ReturnRef(content_name));
EXPECT_CALL(mock_channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
transceiver_->SetChannel(&mock_channel,
[](const std::string&) { return nullptr; });
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(), ElementsAre());
ClearChannel(mock_channel);
}
TEST_F(RtpTransceiverTestForHeaderExtensions, ReturnsNegotiatedHdrExts) {
const std::string content_name("my_mid");
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_)).WillRepeatedly(Return());
EXPECT_CALL(*receiver_.get(), Stop()).WillRepeatedly(Return());
EXPECT_CALL(*sender_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
cricket::MockChannelInterface mock_channel;
EXPECT_CALL(mock_channel, SetFirstPacketReceivedCallback(_));
EXPECT_CALL(mock_channel, media_type())
.WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
EXPECT_CALL(mock_channel, media_channel()).WillRepeatedly(Return(nullptr));
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
EXPECT_CALL(mock_channel, mid()).WillRepeatedly(ReturnRef(content_name));
EXPECT_CALL(mock_channel, SetRtpTransport(_)).WillRepeatedly(Return(true));
cricket::RtpHeaderExtensions extensions = {webrtc::RtpExtension("uri1", 1),
webrtc::RtpExtension("uri2", 2)};
cricket::AudioContentDescription description;
description.set_rtp_header_extensions(extensions);
transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
transceiver_->SetChannel(&mock_channel,
[](const std::string&) { return nullptr; });
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
ElementsAre(RtpHeaderExtensionCapability(
"uri1", 1, RtpTransceiverDirection::kSendRecv),
RtpHeaderExtensionCapability(
"uri2", 2, RtpTransceiverDirection::kSendRecv)));
ClearChannel(mock_channel);
}
TEST_F(RtpTransceiverTestForHeaderExtensions,
ReturnsNegotiatedHdrExtsSecondTime) {
EXPECT_CALL(*receiver_.get(), Stop());
EXPECT_CALL(*receiver_.get(), SetMediaChannel(_));
EXPECT_CALL(*sender_.get(), SetTransceiverAsStopped());
EXPECT_CALL(*sender_.get(), Stop());
cricket::RtpHeaderExtensions extensions = {webrtc::RtpExtension("uri1", 1),
webrtc::RtpExtension("uri2", 2)};
cricket::AudioContentDescription description;
description.set_rtp_header_extensions(extensions);
transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
ElementsAre(RtpHeaderExtensionCapability(
"uri1", 1, RtpTransceiverDirection::kSendRecv),
RtpHeaderExtensionCapability(
"uri2", 2, RtpTransceiverDirection::kSendRecv)));
extensions = {webrtc::RtpExtension("uri3", 4),
webrtc::RtpExtension("uri5", 6)};
description.set_rtp_header_extensions(extensions);
transceiver_->OnNegotiationUpdate(SdpType::kAnswer, &description);
EXPECT_THAT(transceiver_->HeaderExtensionsNegotiated(),
ElementsAre(RtpHeaderExtensionCapability(
"uri3", 4, RtpTransceiverDirection::kSendRecv),
RtpHeaderExtensionCapability(
"uri5", 6, RtpTransceiverDirection::kSendRecv)));
}
} // namespace webrtc