blob: 7a74bf98e939726b1a15615088ca20c8a430fd45 [file] [log] [blame]
Evan Shrubsolea0ee64c2022-04-26 08:09:041/*
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 Shrubsolea4062722022-05-02 15:46:0713#include <memory>
14
15#include "api/video/video_frame_type.h"
16
Evan Shrubsole214cab52022-08-16 09:48:2317namespace webrtc {
Evan Shrubsole214cab52022-08-16 09:48:2318namespace test {
19
Evan Shrubsolea0ee64c2022-04-26 08:09:0420int64_t FakeEncodedFrame::ReceivedTime() const {
21 return received_time_;
22}
23
24int64_t FakeEncodedFrame::RenderTime() const {
25 return _renderTimeMs;
26}
27
28void FakeEncodedFrame::SetReceivedTime(int64_t received_time) {
29 received_time_ = received_time;
30}
31
32void FakeEncodedFrame::SetPayloadType(int payload_type) {
33 _payloadType = payload_type;
34}
35
36FakeFrameBuilder& FakeFrameBuilder::Time(uint32_t rtp_timestamp) {
37 rtp_timestamp_ = rtp_timestamp;
38 return *this;
39}
40
41FakeFrameBuilder& FakeFrameBuilder::Id(int64_t frame_id) {
42 frame_id_ = frame_id;
43 return *this;
44}
45
46FakeFrameBuilder& FakeFrameBuilder::AsLast() {
47 last_spatial_layer_ = true;
48 return *this;
49}
50
51FakeFrameBuilder& FakeFrameBuilder::Refs(
52 const std::vector<int64_t>& references) {
53 references_ = references;
54 return *this;
55}
56
57FakeFrameBuilder& FakeFrameBuilder::PlayoutDelay(
58 VideoPlayoutDelay playout_delay) {
59 playout_delay_ = playout_delay;
60 return *this;
61}
62
63FakeFrameBuilder& FakeFrameBuilder::SpatialLayer(int spatial_layer) {
64 spatial_layer_ = spatial_layer;
65 return *this;
66}
67
68FakeFrameBuilder& FakeFrameBuilder::ReceivedTime(Timestamp receive_time) {
69 received_time_ = receive_time;
70 return *this;
71}
72
73FakeFrameBuilder& FakeFrameBuilder::Size(size_t size) {
74 size_ = size;
75 return *this;
76}
77
78std::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 Chapovalov9c584832023-09-18 13:48:4986 frame->SetRtpTimestamp(*rtp_timestamp_);
Evan Shrubsolea0ee64c2022-04-26 08:09:0487 if (frame_id_)
88 frame->SetId(*frame_id_);
89 if (playout_delay_)
90 frame->SetPlayoutDelay(*playout_delay_);
Evan Shrubsolea4062722022-05-02 15:46:0791 frame->SetFrameType(references_.empty() ? VideoFrameType::kVideoFrameKey
92 : VideoFrameType::kVideoFrameDelta);
Evan Shrubsolea0ee64c2022-04-26 08:09:0493 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
112FakeFrameBuilder& FakeFrameBuilder::PayloadType(int payload_type) {
113 payload_type_ = payload_type;
114 return *this;
115}
116
117FakeFrameBuilder& FakeFrameBuilder::NtpTime(Timestamp ntp_time) {
118 ntp_time_ = ntp_time;
119 return *this;
120}
121
122FakeFrameBuilder& FakeFrameBuilder::Rotation(VideoRotation rotation) {
123 rotation_ = rotation;
124 return *this;
125}
126
127FakeFrameBuilder& FakeFrameBuilder::PacketInfos(RtpPacketInfos packet_infos) {
128 packet_infos_ = packet_infos;
129 return *this;
130}
131
Evan Shrubsole214cab52022-08-16 09:48:23132} // namespace test
133} // namespace webrtc