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 "api/frame_transformer_factory.h"
12
13 #include <cstdio>
14 #include <memory>
15 #include <utility>
16 #include <vector>
17
18 #include "absl/memory/memory.h"
19 #include "api/call/transport.h"
20 #include "call/video_receive_stream.h"
21 #include "modules/rtp_rtcp/source/rtp_descriptor_authentication.h"
22 #include "rtc_base/event.h"
23 #include "test/gmock.h"
24 #include "test/gtest.h"
25 #include "test/mock_frame_transformer.h"
26
27 namespace webrtc {
28 namespace {
29
30 using testing::NiceMock;
31 using testing::Return;
32
33 class MockTransformableVideoFrame
34 : public webrtc::TransformableVideoFrameInterface {
35 public:
36 MOCK_METHOD(rtc::ArrayView<const uint8_t>, GetData, (), (const override));
37 MOCK_METHOD(void, SetData, (rtc::ArrayView<const uint8_t> data), (override));
38 MOCK_METHOD(uint8_t, GetPayloadType, (), (const, override));
39 MOCK_METHOD(uint32_t, GetSsrc, (), (const, override));
40 MOCK_METHOD(uint32_t, GetTimestamp, (), (const, override));
41 MOCK_METHOD(TransformableFrameInterface::Direction,
42 GetDirection,
43 (),
44 (const, override));
45 MOCK_METHOD(bool, IsKeyFrame, (), (const, override));
46 MOCK_METHOD(std::vector<uint8_t>, GetAdditionalData, (), (const, override));
47 MOCK_METHOD(const webrtc::VideoFrameMetadata&,
48 GetMetadata,
49 (),
50 (const, override));
51 };
52
TEST(FrameTransformerFactory,CloneVideoFrame)53 TEST(FrameTransformerFactory, CloneVideoFrame) {
54 NiceMock<MockTransformableVideoFrame> original_frame;
55 uint8_t data[10];
56 std::fill_n(data, 10, 5);
57 rtc::ArrayView<uint8_t> data_view(data);
58 EXPECT_CALL(original_frame, GetData()).WillRepeatedly(Return(data_view));
59 auto cloned_frame = CloneVideoFrame(&original_frame);
60 EXPECT_EQ(cloned_frame->GetData().size(), 10u);
61 EXPECT_THAT(cloned_frame->GetData(), testing::Each(5u));
62 }
63
64 } // namespace
65 } // namespace webrtc
66