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 | #include "test/fake_encoded_frame.h" |
| 12 | |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
| 15 | #include "api/video/video_frame_type.h" |
| 16 | |
Evan Shrubsole | 214cab5 | 2022-08-16 09:48:23 | [diff] [blame] | 17 | namespace webrtc { |
Evan Shrubsole | 214cab5 | 2022-08-16 09:48:23 | [diff] [blame] | 18 | namespace test { |
| 19 | |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 20 | int64_t FakeEncodedFrame::ReceivedTime() const { |
| 21 | return received_time_; |
| 22 | } |
| 23 | |
| 24 | int64_t FakeEncodedFrame::RenderTime() const { |
| 25 | return _renderTimeMs; |
| 26 | } |
| 27 | |
| 28 | void FakeEncodedFrame::SetReceivedTime(int64_t received_time) { |
| 29 | received_time_ = received_time; |
| 30 | } |
| 31 | |
| 32 | void FakeEncodedFrame::SetPayloadType(int payload_type) { |
| 33 | _payloadType = payload_type; |
| 34 | } |
| 35 | |
| 36 | FakeFrameBuilder& FakeFrameBuilder::Time(uint32_t rtp_timestamp) { |
| 37 | rtp_timestamp_ = rtp_timestamp; |
| 38 | return *this; |
| 39 | } |
| 40 | |
| 41 | FakeFrameBuilder& FakeFrameBuilder::Id(int64_t frame_id) { |
| 42 | frame_id_ = frame_id; |
| 43 | return *this; |
| 44 | } |
| 45 | |
| 46 | FakeFrameBuilder& FakeFrameBuilder::AsLast() { |
| 47 | last_spatial_layer_ = true; |
| 48 | return *this; |
| 49 | } |
| 50 | |
| 51 | FakeFrameBuilder& FakeFrameBuilder::Refs( |
| 52 | const std::vector<int64_t>& references) { |
| 53 | references_ = references; |
| 54 | return *this; |
| 55 | } |
| 56 | |
| 57 | FakeFrameBuilder& FakeFrameBuilder::PlayoutDelay( |
| 58 | VideoPlayoutDelay playout_delay) { |
| 59 | playout_delay_ = playout_delay; |
| 60 | return *this; |
| 61 | } |
| 62 | |
| 63 | FakeFrameBuilder& FakeFrameBuilder::SpatialLayer(int spatial_layer) { |
| 64 | spatial_layer_ = spatial_layer; |
| 65 | return *this; |
| 66 | } |
| 67 | |
| 68 | FakeFrameBuilder& FakeFrameBuilder::ReceivedTime(Timestamp receive_time) { |
| 69 | received_time_ = receive_time; |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | FakeFrameBuilder& FakeFrameBuilder::Size(size_t size) { |
| 74 | size_ = size; |
| 75 | return *this; |
| 76 | } |
| 77 | |
| 78 | std::unique_ptr<FakeEncodedFrame> FakeFrameBuilder::Build() { |
| 79 | RTC_CHECK_LE(references_.size(), EncodedFrame::kMaxFrameReferences); |
| 80 | |
| 81 | auto frame = std::make_unique<FakeEncodedFrame>(); |
| 82 | frame->is_last_spatial_layer = last_spatial_layer_; |
| 83 | frame->SetEncodedData(EncodedImageBuffer::Create(size_)); |
| 84 | |
| 85 | if (rtp_timestamp_) |
Danil Chapovalov | 9c58483 | 2023-09-18 13:48:49 | [diff] [blame] | 86 | frame->SetRtpTimestamp(*rtp_timestamp_); |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 87 | if (frame_id_) |
| 88 | frame->SetId(*frame_id_); |
| 89 | if (playout_delay_) |
| 90 | frame->SetPlayoutDelay(*playout_delay_); |
Evan Shrubsole | a406272 | 2022-05-02 15:46:07 | [diff] [blame] | 91 | frame->SetFrameType(references_.empty() ? VideoFrameType::kVideoFrameKey |
| 92 | : VideoFrameType::kVideoFrameDelta); |
Evan Shrubsole | a0ee64c | 2022-04-26 08:09:04 | [diff] [blame] | 93 | for (int64_t ref : references_) { |
| 94 | frame->references[frame->num_references] = ref; |
| 95 | frame->num_references++; |
| 96 | } |
| 97 | if (spatial_layer_) |
| 98 | frame->SetSpatialIndex(spatial_layer_); |
| 99 | if (received_time_) |
| 100 | frame->SetReceivedTime(received_time_->ms()); |
| 101 | if (payload_type_) |
| 102 | frame->SetPayloadType(*payload_type_); |
| 103 | if (ntp_time_) |
| 104 | frame->ntp_time_ms_ = ntp_time_->ms(); |
| 105 | if (rotation_) |
| 106 | frame->rotation_ = *rotation_; |
| 107 | if (packet_infos_) |
| 108 | frame->SetPacketInfos(*packet_infos_); |
| 109 | return frame; |
| 110 | } |
| 111 | |
| 112 | FakeFrameBuilder& FakeFrameBuilder::PayloadType(int payload_type) { |
| 113 | payload_type_ = payload_type; |
| 114 | return *this; |
| 115 | } |
| 116 | |
| 117 | FakeFrameBuilder& FakeFrameBuilder::NtpTime(Timestamp ntp_time) { |
| 118 | ntp_time_ = ntp_time; |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | FakeFrameBuilder& FakeFrameBuilder::Rotation(VideoRotation rotation) { |
| 123 | rotation_ = rotation; |
| 124 | return *this; |
| 125 | } |
| 126 | |
| 127 | FakeFrameBuilder& FakeFrameBuilder::PacketInfos(RtpPacketInfos packet_infos) { |
| 128 | packet_infos_ = packet_infos; |
| 129 | return *this; |
| 130 | } |
| 131 | |
Evan Shrubsole | 214cab5 | 2022-08-16 09:48:23 | [diff] [blame] | 132 | } // namespace test |
| 133 | } // namespace webrtc |