Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 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 | #include "audio/channel_send_frame_transformer_delegate.h" |
| 12 | |
Harald Alvestrand | 6431a64 | 2024-06-04 21:29:14 | [diff] [blame] | 13 | #include <cstdint> |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 14 | #include <memory> |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 15 | #include <optional> |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 16 | #include <utility> |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 17 | #include <vector> |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 18 | |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 19 | #include "absl/memory/memory.h" |
Harald Alvestrand | 6431a64 | 2024-06-04 21:29:14 | [diff] [blame] | 20 | #include "api/array_view.h" |
| 21 | #include "api/frame_transformer_interface.h" |
| 22 | #include "api/make_ref_counted.h" |
| 23 | #include "api/scoped_refptr.h" |
Tony Herre | 9c687460 | 2024-01-26 10:16:45 | [diff] [blame] | 24 | #include "api/test/mock_frame_transformer.h" |
| 25 | #include "api/test/mock_transformable_audio_frame.h" |
Harald Alvestrand | 6431a64 | 2024-06-04 21:29:14 | [diff] [blame] | 26 | #include "modules/audio_coding/include/audio_coding_module_typedefs.h" |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 27 | #include "rtc_base/task_queue_for_test.h" |
| 28 | #include "test/gmock.h" |
| 29 | #include "test/gtest.h" |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | namespace { |
| 33 | |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 34 | using ::testing::_; |
| 35 | using ::testing::ElementsAre; |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 36 | using ::testing::ElementsAreArray; |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 37 | using ::testing::NiceMock; |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 38 | using ::testing::Optional; |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 39 | using ::testing::Return; |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 40 | using ::testing::SaveArg; |
| 41 | |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 42 | const uint8_t mock_data[] = {1, 2, 3, 4}; |
| 43 | |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 44 | class MockChannelSend { |
| 45 | public: |
| 46 | MockChannelSend() = default; |
| 47 | ~MockChannelSend() = default; |
| 48 | |
| 49 | MOCK_METHOD(int32_t, |
| 50 | SendFrame, |
| 51 | (AudioFrameType frameType, |
| 52 | uint8_t payloadType, |
| 53 | uint32_t rtp_timestamp, |
| 54 | rtc::ArrayView<const uint8_t> payload, |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 55 | int64_t absolute_capture_timestamp_ms, |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 56 | rtc::ArrayView<const uint32_t> csrcs, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 57 | std::optional<uint8_t> audio_level_dbov)); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 58 | |
| 59 | ChannelSendFrameTransformerDelegate::SendFrameCallback callback() { |
| 60 | return [this](AudioFrameType frameType, uint8_t payloadType, |
| 61 | uint32_t rtp_timestamp, rtc::ArrayView<const uint8_t> payload, |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 62 | int64_t absolute_capture_timestamp_ms, |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 63 | rtc::ArrayView<const uint32_t> csrcs, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 64 | std::optional<uint8_t> audio_level_dbov) { |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 65 | return SendFrame(frameType, payloadType, rtp_timestamp, payload, |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 66 | absolute_capture_timestamp_ms, csrcs, audio_level_dbov); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 67 | }; |
| 68 | } |
| 69 | }; |
| 70 | |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 71 | std::unique_ptr<TransformableAudioFrameInterface> CreateMockReceiverFrame( |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 72 | const std::vector<uint32_t>& csrcs, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 73 | std::optional<uint8_t> audio_level_dbov) { |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 74 | std::unique_ptr<MockTransformableAudioFrame> mock_frame = |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 75 | std::make_unique<NiceMock<MockTransformableAudioFrame>>(); |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 76 | rtc::ArrayView<const uint8_t> payload(mock_data); |
| 77 | ON_CALL(*mock_frame, GetData).WillByDefault(Return(payload)); |
| 78 | ON_CALL(*mock_frame, GetPayloadType).WillByDefault(Return(0)); |
| 79 | ON_CALL(*mock_frame, GetDirection) |
| 80 | .WillByDefault(Return(TransformableFrameInterface::Direction::kReceiver)); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 81 | ON_CALL(*mock_frame, GetContributingSources).WillByDefault(Return(csrcs)); |
Tony Herre | 7aa7972 | 2024-01-29 07:31:14 | [diff] [blame] | 82 | ON_CALL(*mock_frame, SequenceNumber).WillByDefault(Return(987654321)); |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 83 | ON_CALL(*mock_frame, AudioLevel).WillByDefault(Return(audio_level_dbov)); |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 84 | return mock_frame; |
| 85 | } |
| 86 | |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 87 | std::unique_ptr<TransformableAudioFrameInterface> CreateFrame() { |
| 88 | TaskQueueForTest channel_queue("channel_queue"); |
| 89 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
| 90 | rtc::make_ref_counted<NiceMock<MockFrameTransformer>>(); |
| 91 | MockChannelSend mock_channel; |
| 92 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
| 93 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Danil Chapovalov | 0f1b9a9 | 2024-01-17 18:32:15 | [diff] [blame] | 94 | mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 95 | |
| 96 | std::unique_ptr<TransformableFrameInterface> frame; |
| 97 | ON_CALL(*mock_frame_transformer, Transform) |
| 98 | .WillByDefault( |
| 99 | [&frame]( |
| 100 | std::unique_ptr<TransformableFrameInterface> transform_frame) { |
| 101 | frame = std::move(transform_frame); |
| 102 | }); |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 103 | delegate->Transform( |
| 104 | AudioFrameType::kEmptyFrame, 0, 0, mock_data, sizeof(mock_data), 0, |
| 105 | /*ssrc=*/0, /*mimeType=*/"audio/opus", /*audio_level_dbov=*/123); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 106 | return absl::WrapUnique( |
| 107 | static_cast<webrtc::TransformableAudioFrameInterface*>(frame.release())); |
| 108 | } |
| 109 | |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 110 | // Test that the delegate registers itself with the frame transformer on Init(). |
| 111 | TEST(ChannelSendFrameTransformerDelegateTest, |
| 112 | RegisterTransformedFrameCallbackOnInit) { |
| 113 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 114 | rtc::make_ref_counted<MockFrameTransformer>(); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 115 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 116 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 117 | ChannelSendFrameTransformerDelegate::SendFrameCallback(), |
| 118 | mock_frame_transformer, nullptr); |
| 119 | EXPECT_CALL(*mock_frame_transformer, RegisterTransformedFrameCallback); |
| 120 | delegate->Init(); |
| 121 | } |
| 122 | |
| 123 | // Test that the delegate unregisters itself from the frame transformer on |
| 124 | // Reset(). |
| 125 | TEST(ChannelSendFrameTransformerDelegateTest, |
| 126 | UnregisterTransformedFrameCallbackOnReset) { |
| 127 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 128 | rtc::make_ref_counted<MockFrameTransformer>(); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 129 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 130 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 131 | ChannelSendFrameTransformerDelegate::SendFrameCallback(), |
| 132 | mock_frame_transformer, nullptr); |
| 133 | EXPECT_CALL(*mock_frame_transformer, UnregisterTransformedFrameCallback); |
| 134 | delegate->Reset(); |
| 135 | } |
| 136 | |
| 137 | // Test that when the delegate receives a transformed frame from the frame |
| 138 | // transformer, it passes it to the channel using the SendFrameCallback. |
| 139 | TEST(ChannelSendFrameTransformerDelegateTest, |
| 140 | TransformRunsChannelSendCallback) { |
| 141 | TaskQueueForTest channel_queue("channel_queue"); |
| 142 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 143 | rtc::make_ref_counted<NiceMock<MockFrameTransformer>>(); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 144 | MockChannelSend mock_channel; |
| 145 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 146 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Danil Chapovalov | 0f1b9a9 | 2024-01-17 18:32:15 | [diff] [blame] | 147 | mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 148 | rtc::scoped_refptr<TransformedFrameCallback> callback; |
| 149 | EXPECT_CALL(*mock_frame_transformer, RegisterTransformedFrameCallback) |
| 150 | .WillOnce(SaveArg<0>(&callback)); |
| 151 | delegate->Init(); |
| 152 | ASSERT_TRUE(callback); |
| 153 | |
| 154 | const uint8_t data[] = {1, 2, 3, 4}; |
| 155 | EXPECT_CALL(mock_channel, SendFrame); |
| 156 | ON_CALL(*mock_frame_transformer, Transform) |
| 157 | .WillByDefault( |
| 158 | [&callback](std::unique_ptr<TransformableFrameInterface> frame) { |
| 159 | callback->OnTransformedFrame(std::move(frame)); |
| 160 | }); |
Tony Herre | 36500ab | 2023-08-29 10:01:32 | [diff] [blame] | 161 | delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, data, sizeof(data), 0, |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 162 | /*ssrc=*/0, /*mimeType=*/"audio/opus", |
| 163 | /*audio_level_dbov=*/31); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 164 | channel_queue.WaitForPreviouslyPostedTasks(); |
| 165 | } |
| 166 | |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 167 | // Test that when the delegate receives a Incoming frame from the frame |
| 168 | // transformer, it passes it to the channel using the SendFrameCallback. |
| 169 | TEST(ChannelSendFrameTransformerDelegateTest, |
| 170 | TransformRunsChannelSendCallbackForIncomingFrame) { |
| 171 | TaskQueueForTest channel_queue("channel_queue"); |
| 172 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
| 173 | rtc::make_ref_counted<NiceMock<MockFrameTransformer>>(); |
| 174 | MockChannelSend mock_channel; |
| 175 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
| 176 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Danil Chapovalov | 0f1b9a9 | 2024-01-17 18:32:15 | [diff] [blame] | 177 | mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 178 | rtc::scoped_refptr<TransformedFrameCallback> callback; |
| 179 | EXPECT_CALL(*mock_frame_transformer, RegisterTransformedFrameCallback) |
| 180 | .WillOnce(SaveArg<0>(&callback)); |
| 181 | delegate->Init(); |
| 182 | ASSERT_TRUE(callback); |
| 183 | |
Dor Hen | 3e613c2 | 2024-02-05 15:58:10 | [diff] [blame] | 184 | const std::vector<uint32_t> csrcs = {123, 234, 345, 456}; |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 185 | const uint8_t audio_level_dbov = 17; |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 186 | EXPECT_CALL(mock_channel, SendFrame).Times(0); |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 187 | EXPECT_CALL(mock_channel, |
| 188 | SendFrame(_, 0, 0, ElementsAreArray(mock_data), _, |
| 189 | ElementsAreArray(csrcs), Optional(audio_level_dbov))); |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 190 | ON_CALL(*mock_frame_transformer, Transform) |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 191 | .WillByDefault([&](std::unique_ptr<TransformableFrameInterface> frame) { |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 192 | callback->OnTransformedFrame(CreateMockReceiverFrame( |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 193 | csrcs, std::optional<uint8_t>(audio_level_dbov))); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 194 | }); |
| 195 | delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, mock_data, |
| 196 | sizeof(mock_data), 0, |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 197 | /*ssrc=*/0, /*mimeType=*/"audio/opus", |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 198 | /*audio_level_dbov=*/std::nullopt); |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 199 | channel_queue.WaitForPreviouslyPostedTasks(); |
| 200 | } |
| 201 | |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 202 | // Test that if the delegate receives a transformed frame after it has been |
| 203 | // reset, it does not run the SendFrameCallback, as the channel is destroyed |
| 204 | // after resetting the delegate. |
| 205 | TEST(ChannelSendFrameTransformerDelegateTest, |
| 206 | OnTransformedDoesNotRunChannelSendCallbackAfterReset) { |
| 207 | TaskQueueForTest channel_queue("channel_queue"); |
| 208 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 209 | rtc::make_ref_counted<testing::NiceMock<MockFrameTransformer>>(); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 210 | MockChannelSend mock_channel; |
| 211 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
Tomas Gunnarsson | c1d5891 | 2021-04-22 17:21:43 | [diff] [blame] | 212 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Danil Chapovalov | 0f1b9a9 | 2024-01-17 18:32:15 | [diff] [blame] | 213 | mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 214 | |
| 215 | delegate->Reset(); |
| 216 | EXPECT_CALL(mock_channel, SendFrame).Times(0); |
Palak Agarwal | 14e5d4c | 2023-08-22 14:58:33 | [diff] [blame] | 217 | delegate->OnTransformedFrame(std::make_unique<MockTransformableAudioFrame>()); |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 218 | channel_queue.WaitForPreviouslyPostedTasks(); |
| 219 | } |
| 220 | |
Tony Herre | 6e95605 | 2023-11-16 13:59:54 | [diff] [blame] | 221 | TEST(ChannelSendFrameTransformerDelegateTest, ShortCircuitingSkipsTransform) { |
| 222 | TaskQueueForTest channel_queue("channel_queue"); |
| 223 | rtc::scoped_refptr<MockFrameTransformer> mock_frame_transformer = |
| 224 | rtc::make_ref_counted<testing::NiceMock<MockFrameTransformer>>(); |
| 225 | MockChannelSend mock_channel; |
| 226 | rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = |
| 227 | rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( |
Danil Chapovalov | 0f1b9a9 | 2024-01-17 18:32:15 | [diff] [blame] | 228 | mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); |
Tony Herre | 6e95605 | 2023-11-16 13:59:54 | [diff] [blame] | 229 | |
| 230 | delegate->StartShortCircuiting(); |
| 231 | |
| 232 | // Will not call the actual transformer. |
| 233 | EXPECT_CALL(*mock_frame_transformer, Transform).Times(0); |
| 234 | // Will pass the frame straight to the channel. |
| 235 | EXPECT_CALL(mock_channel, SendFrame); |
| 236 | const uint8_t data[] = {1, 2, 3, 4}; |
| 237 | delegate->Transform(AudioFrameType::kEmptyFrame, 0, 0, data, sizeof(data), 0, |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 238 | /*ssrc=*/0, /*mimeType=*/"audio/opus", |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 239 | /*audio_level_dbov=*/std::nullopt); |
Tony Herre | 6e95605 | 2023-11-16 13:59:54 | [diff] [blame] | 240 | } |
| 241 | |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 242 | TEST(ChannelSendFrameTransformerDelegateTest, |
| 243 | CloningSenderFramePreservesInformation) { |
| 244 | std::unique_ptr<TransformableAudioFrameInterface> frame = CreateFrame(); |
| 245 | std::unique_ptr<TransformableAudioFrameInterface> cloned_frame = |
| 246 | CloneSenderAudioFrame(frame.get()); |
| 247 | |
| 248 | EXPECT_EQ(cloned_frame->GetTimestamp(), frame->GetTimestamp()); |
| 249 | EXPECT_EQ(cloned_frame->GetSsrc(), frame->GetSsrc()); |
| 250 | EXPECT_EQ(cloned_frame->Type(), frame->Type()); |
| 251 | EXPECT_EQ(cloned_frame->GetPayloadType(), frame->GetPayloadType()); |
| 252 | EXPECT_EQ(cloned_frame->GetMimeType(), frame->GetMimeType()); |
| 253 | EXPECT_THAT(cloned_frame->GetContributingSources(), |
| 254 | ElementsAreArray(frame->GetContributingSources())); |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 255 | EXPECT_EQ(cloned_frame->AudioLevel(), frame->AudioLevel()); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | TEST(ChannelSendFrameTransformerDelegateTest, CloningReceiverFrameWithCsrcs) { |
| 259 | std::unique_ptr<TransformableAudioFrameInterface> frame = |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 260 | CreateMockReceiverFrame(/*csrcs=*/{123, 234, 345}, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 261 | std::optional<uint8_t>(72)); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 262 | std::unique_ptr<TransformableAudioFrameInterface> cloned_frame = |
| 263 | CloneSenderAudioFrame(frame.get()); |
| 264 | |
| 265 | EXPECT_EQ(cloned_frame->GetTimestamp(), frame->GetTimestamp()); |
| 266 | EXPECT_EQ(cloned_frame->GetSsrc(), frame->GetSsrc()); |
| 267 | EXPECT_EQ(cloned_frame->Type(), frame->Type()); |
| 268 | EXPECT_EQ(cloned_frame->GetPayloadType(), frame->GetPayloadType()); |
| 269 | EXPECT_EQ(cloned_frame->GetMimeType(), frame->GetMimeType()); |
| 270 | EXPECT_EQ(cloned_frame->AbsoluteCaptureTimestamp(), |
| 271 | frame->AbsoluteCaptureTimestamp()); |
| 272 | |
| 273 | ASSERT_NE(frame->GetContributingSources().size(), 0u); |
| 274 | EXPECT_THAT(cloned_frame->GetContributingSources(), |
| 275 | ElementsAreArray(frame->GetContributingSources())); |
Tony Herre | 7aa7972 | 2024-01-29 07:31:14 | [diff] [blame] | 276 | EXPECT_EQ(cloned_frame->SequenceNumber(), frame->SequenceNumber()); |
Tony Herre | 64437e8 | 2024-04-29 13:13:48 | [diff] [blame] | 277 | EXPECT_EQ(cloned_frame->AudioLevel(), frame->AudioLevel()); |
Tony Herre | 5f3ac43 | 2023-12-07 11:39:40 | [diff] [blame] | 278 | } |
| 279 | |
Marina Ciocea | d719708 | 2020-05-04 15:50:38 | [diff] [blame] | 280 | } // namespace |
| 281 | } // namespace webrtc |