Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 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 | #ifndef TEST_FAKE_ENCODED_FRAME_H_ |
| 12 | #define TEST_FAKE_ENCODED_FRAME_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <ostream> // no-presubmit-check TODO(webrtc:8982) |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "api/rtp_packet_infos.h" |
| 19 | #include "api/video/encoded_frame.h" |
| 20 | #include "api/video/video_rotation.h" |
| 21 | #include "test/gmock.h" |
| 22 | |
Evan Shrubsole | 214cab5 | 2022-08-16 09:48:23 | [diff] [blame] | 23 | namespace webrtc { |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 24 | |
| 25 | // For test printing. |
| 26 | void PrintTo(const EncodedFrame& frame, |
| 27 | std::ostream* os); // no-presubmit-check TODO(webrtc:8982) |
| 28 | |
Evan Shrubsole | 214cab5 | 2022-08-16 09:48:23 | [diff] [blame] | 29 | namespace test { |
| 30 | |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 31 | class FakeEncodedFrame : public EncodedFrame { |
| 32 | public: |
| 33 | // Always 10ms delay and on time. |
| 34 | int64_t ReceivedTime() const override; |
| 35 | int64_t RenderTime() const override; |
| 36 | |
| 37 | // Setters for protected variables. |
| 38 | void SetReceivedTime(int64_t received_time); |
| 39 | void SetPayloadType(int payload_type); |
| 40 | |
| 41 | private: |
| 42 | int64_t received_time_; |
| 43 | }; |
| 44 | |
| 45 | MATCHER_P(WithId, id, "") { |
| 46 | return ::testing::Matches(::testing::Eq(id))(arg.Id()); |
| 47 | } |
| 48 | |
| 49 | MATCHER_P(FrameWithSize, id, "") { |
| 50 | return ::testing::Matches(::testing::Eq(id))(arg.size()); |
| 51 | } |
| 52 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 53 | MATCHER_P(RtpTimestamp, ts, "") { |
| 54 | return ts == arg.Timestamp(); |
| 55 | } |
| 56 | |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 57 | class FakeFrameBuilder { |
| 58 | public: |
| 59 | FakeFrameBuilder& Time(uint32_t rtp_timestamp); |
| 60 | FakeFrameBuilder& Id(int64_t frame_id); |
| 61 | FakeFrameBuilder& AsLast(); |
| 62 | FakeFrameBuilder& Refs(const std::vector<int64_t>& references); |
| 63 | FakeFrameBuilder& PlayoutDelay(VideoPlayoutDelay playout_delay); |
| 64 | FakeFrameBuilder& SpatialLayer(int spatial_layer); |
| 65 | FakeFrameBuilder& ReceivedTime(Timestamp receive_time); |
| 66 | FakeFrameBuilder& Size(size_t size); |
| 67 | FakeFrameBuilder& PayloadType(int payload_type); |
| 68 | FakeFrameBuilder& NtpTime(Timestamp ntp_time); |
| 69 | FakeFrameBuilder& Rotation(VideoRotation rotation); |
| 70 | FakeFrameBuilder& PacketInfos(RtpPacketInfos packet_infos); |
| 71 | std::unique_ptr<FakeEncodedFrame> Build(); |
| 72 | |
| 73 | private: |
| 74 | absl::optional<uint32_t> rtp_timestamp_; |
| 75 | absl::optional<int64_t> frame_id_; |
| 76 | absl::optional<VideoPlayoutDelay> playout_delay_; |
| 77 | absl::optional<int> spatial_layer_; |
| 78 | absl::optional<Timestamp> received_time_; |
| 79 | absl::optional<int> payload_type_; |
| 80 | absl::optional<Timestamp> ntp_time_; |
| 81 | absl::optional<VideoRotation> rotation_; |
| 82 | absl::optional<RtpPacketInfos> packet_infos_; |
| 83 | std::vector<int64_t> references_; |
| 84 | bool last_spatial_layer_ = false; |
| 85 | size_t size_ = 10; |
| 86 | }; |
| 87 | |
Evan Shrubsole | 214cab5 | 2022-08-16 09:48:23 | [diff] [blame] | 88 | } // namespace test |
| 89 | } // namespace webrtc |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 90 | |
| 91 | #endif // TEST_FAKE_ENCODED_FRAME_H_ |