diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc')
-rw-r--r-- | third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc | 116 |
1 files changed, 101 insertions, 15 deletions
diff --git a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc index f75d4a8ab7..4dcd15cd95 100644 --- a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc +++ b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc @@ -12,7 +12,9 @@ #include <memory> #include <utility> +#include <vector> +#include "absl/memory/memory.h" #include "rtc_base/task_queue_for_test.h" #include "test/gmock.h" #include "test/gtest.h" @@ -24,10 +26,13 @@ namespace { using ::testing::_; using ::testing::ElementsAre; +using ::testing::ElementsAreArray; using ::testing::NiceMock; using ::testing::Return; using ::testing::SaveArg; +const uint8_t mock_data[] = {1, 2, 3, 4}; + class MockChannelSend { public: MockChannelSend() = default; @@ -39,30 +44,56 @@ class MockChannelSend { uint8_t payloadType, uint32_t rtp_timestamp, rtc::ArrayView<const uint8_t> payload, - int64_t absolute_capture_timestamp_ms)); + int64_t absolute_capture_timestamp_ms, + rtc::ArrayView<const uint32_t> csrcs)); ChannelSendFrameTransformerDelegate::SendFrameCallback callback() { return [this](AudioFrameType frameType, uint8_t payloadType, uint32_t rtp_timestamp, rtc::ArrayView<const uint8_t> payload, - int64_t absolute_capture_timestamp_ms) { + int64_t absolute_capture_timestamp_ms, + rtc::ArrayView<const uint32_t> csrcs) { return SendFrame(frameType, payloadType, rtp_timestamp, payload, - absolute_capture_timestamp_ms); + absolute_capture_timestamp_ms, csrcs); }; } }; -std::unique_ptr<MockTransformableAudioFrame> CreateMockReceiverFrame() { - const uint8_t mock_data[] = {1, 2, 3, 4}; +std::unique_ptr<TransformableAudioFrameInterface> CreateMockReceiverFrame( + std::vector<const uint32_t> csrcs) { std::unique_ptr<MockTransformableAudioFrame> mock_frame = - std::make_unique<MockTransformableAudioFrame>(); + std::make_unique<NiceMock<MockTransformableAudioFrame>>(); rtc::ArrayView<const uint8_t> payload(mock_data); ON_CALL(*mock_frame, GetData).WillByDefault(Return(payload)); ON_CALL(*mock_frame, GetPayloadType).WillByDefault(Return(0)); ON_CALL(*mock_frame, GetDirection) .WillByDefault(Return(TransformableFrameInterface::Direction::kReceiver)); + ON_CALL(*mock_frame, GetContributingSources).WillByDefault(Return(csrcs)); return mock_frame; } +std::unique_ptr<TransformableAudioFrameInterface> CreateFrame() { + TaskQueueForTest channel_queue("channel_queue"); + rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = + rtc::make_ref_counted<NiceMock<MockFrameTransformer>>(); + MockChannelSend mock_channel; + rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = + rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( + mock_channel.callback(), mock_frame_transformer, &channel_queue); + + std::unique_ptr<TransformableFrameInterface> frame; + ON_CALL(*mock_frame_transformer, Transform) + .WillByDefault( + [&frame]( + std::unique_ptr<TransformableFrameInterface> transform_frame) { + frame = std::move(transform_frame); + }); + delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, mock_data, + sizeof(mock_data), 0, + /*ssrc=*/0, /*mimeType=*/"audio/opus"); + return absl::WrapUnique( + static_cast<webrtc::TransformableAudioFrameInterface*>(frame.release())); +} + // Test that the delegate registers itself with the frame transformer on Init(). TEST(ChannelSendFrameTransformerDelegateTest, RegisterTransformedFrameCallbackOnInit) { @@ -115,7 +146,7 @@ TEST(ChannelSendFrameTransformerDelegateTest, callback->OnTransformedFrame(std::move(frame)); }); delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, data, sizeof(data), 0, - 0); + /*ssrc=*/0, /*mimeType=*/"audio/opus"); channel_queue.WaitForPreviouslyPostedTasks(); } @@ -136,16 +167,17 @@ TEST(ChannelSendFrameTransformerDelegateTest, delegate->Init(); ASSERT_TRUE(callback); - const uint8_t data[] = {1, 2, 3, 4}; + std::vector<const uint32_t> csrcs = {123, 234, 345, 456}; EXPECT_CALL(mock_channel, SendFrame).Times(0); - EXPECT_CALL(mock_channel, SendFrame(_, 0, 0, ElementsAre(1, 2, 3, 4), _)); + EXPECT_CALL(mock_channel, SendFrame(_, 0, 0, ElementsAreArray(mock_data), _, + ElementsAreArray(csrcs))); ON_CALL(*mock_frame_transformer, Transform) - .WillByDefault( - [&callback](std::unique_ptr<TransformableFrameInterface> frame) { - callback->OnTransformedFrame(CreateMockReceiverFrame()); - }); - delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, data, sizeof(data), 0, - 0); + .WillByDefault([&](std::unique_ptr<TransformableFrameInterface> frame) { + callback->OnTransformedFrame(CreateMockReceiverFrame(csrcs)); + }); + delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, mock_data, + sizeof(mock_data), 0, + /*ssrc=*/0, /*mimeType=*/"audio/opus"); channel_queue.WaitForPreviouslyPostedTasks(); } @@ -168,5 +200,59 @@ TEST(ChannelSendFrameTransformerDelegateTest, channel_queue.WaitForPreviouslyPostedTasks(); } +TEST(ChannelSendFrameTransformerDelegateTest, ShortCircuitingSkipsTransform) { + TaskQueueForTest channel_queue("channel_queue"); + rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = + rtc::make_ref_counted<testing::NiceMock<MockFrameTransformer>>(); + MockChannelSend mock_channel; + rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = + rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( + mock_channel.callback(), mock_frame_transformer, &channel_queue); + + delegate->StartShortCircuiting(); + + // Will not call the actual transformer. + EXPECT_CALL(*mock_frame_transformer, Transform).Times(0); + // Will pass the frame straight to the channel. + EXPECT_CALL(mock_channel, SendFrame); + const uint8_t data[] = {1, 2, 3, 4}; + delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, data, sizeof(data), 0, + /*ssrc=*/0, /*mimeType=*/"audio/opus"); +} + +TEST(ChannelSendFrameTransformerDelegateTest, + CloningSenderFramePreservesInformation) { + std::unique_ptr<TransformableAudioFrameInterface> frame = CreateFrame(); + std::unique_ptr<TransformableAudioFrameInterface> cloned_frame = + CloneSenderAudioFrame(frame.get()); + + EXPECT_EQ(cloned_frame->GetTimestamp(), frame->GetTimestamp()); + EXPECT_EQ(cloned_frame->GetSsrc(), frame->GetSsrc()); + EXPECT_EQ(cloned_frame->Type(), frame->Type()); + EXPECT_EQ(cloned_frame->GetPayloadType(), frame->GetPayloadType()); + EXPECT_EQ(cloned_frame->GetMimeType(), frame->GetMimeType()); + EXPECT_THAT(cloned_frame->GetContributingSources(), + ElementsAreArray(frame->GetContributingSources())); +} + +TEST(ChannelSendFrameTransformerDelegateTest, CloningReceiverFrameWithCsrcs) { + std::unique_ptr<TransformableAudioFrameInterface> frame = + CreateMockReceiverFrame(/*csrcs=*/{123, 234, 345}); + std::unique_ptr<TransformableAudioFrameInterface> cloned_frame = + CloneSenderAudioFrame(frame.get()); + + EXPECT_EQ(cloned_frame->GetTimestamp(), frame->GetTimestamp()); + EXPECT_EQ(cloned_frame->GetSsrc(), frame->GetSsrc()); + EXPECT_EQ(cloned_frame->Type(), frame->Type()); + EXPECT_EQ(cloned_frame->GetPayloadType(), frame->GetPayloadType()); + EXPECT_EQ(cloned_frame->GetMimeType(), frame->GetMimeType()); + EXPECT_EQ(cloned_frame->AbsoluteCaptureTimestamp(), + frame->AbsoluteCaptureTimestamp()); + + ASSERT_NE(frame->GetContributingSources().size(), 0u); + EXPECT_THAT(cloned_frame->GetContributingSources(), + ElementsAreArray(frame->GetContributingSources())); +} + } // namespace } // namespace webrtc |