ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 11 | #include <cstddef> |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include "api/video/video_timing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "modules/video_coding/generic_encoder.h" |
| 16 | #include "modules/video_coding/include/video_coding_defines.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 17 | #include "rtc_base/fake_clock.h" |
| 18 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "test/gtest.h" |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | namespace test { |
| 23 | namespace { |
| 24 | inline size_t FrameSize(const size_t& min_frame_size, |
| 25 | const size_t& max_frame_size, |
| 26 | const int& s, |
| 27 | const int& i) { |
| 28 | return min_frame_size + (s + 1) * i % (max_frame_size - min_frame_size); |
| 29 | } |
| 30 | |
| 31 | class FakeEncodedImageCallback : public EncodedImageCallback { |
| 32 | public: |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 33 | FakeEncodedImageCallback() |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 34 | : last_frame_was_timing_(false), |
| 35 | num_frames_dropped_(0), |
| 36 | last_capture_timestamp_(-1) {} |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 37 | Result OnEncodedImage(const EncodedImage& encoded_image, |
| 38 | const CodecSpecificInfo* codec_specific_info, |
| 39 | const RTPFragmentationHeader* fragmentation) override { |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 40 | last_frame_was_timing_ = |
Ilya Nikolaevskiy | b6c462d | 2018-06-05 15:21:32 +0200 | [diff] [blame] | 41 | encoded_image.timing_.flags != VideoSendTiming::kInvalid && |
| 42 | encoded_image.timing_.flags != VideoSendTiming::kNotTriggered; |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 43 | last_capture_timestamp_ = encoded_image.capture_time_ms_; |
mflodman | 351424e | 2017-08-10 02:43:14 -0700 | [diff] [blame] | 44 | return Result(Result::OK); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 47 | void OnDroppedFrame(DropReason reason) override { ++num_frames_dropped_; } |
| 48 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 49 | bool WasTimingFrame() { return last_frame_was_timing_; } |
| 50 | |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 51 | size_t GetNumFramesDropped() { return num_frames_dropped_; } |
| 52 | |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 53 | int64_t GetLastCaptureTimestamp() { return last_capture_timestamp_; } |
| 54 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 55 | private: |
| 56 | bool last_frame_was_timing_; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 57 | size_t num_frames_dropped_; |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 58 | int64_t last_capture_timestamp_; |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | enum class FrameType { |
| 62 | kNormal, |
| 63 | kTiming, |
| 64 | kDropped, |
| 65 | }; |
| 66 | |
| 67 | // Emulates |num_frames| on |num_streams| frames with capture timestamps |
| 68 | // increased by 1 from 0. Size of each frame is between |
| 69 | // |min_frame_size| and |max_frame_size|, outliers are counted relatevely to |
| 70 | // |average_frame_sizes[]| for each stream. |
| 71 | std::vector<std::vector<FrameType>> GetTimingFrames( |
| 72 | const int64_t delay_ms, |
| 73 | const size_t min_frame_size, |
| 74 | const size_t max_frame_size, |
| 75 | std::vector<size_t> average_frame_sizes, |
| 76 | const int num_streams, |
| 77 | const int num_frames) { |
| 78 | FakeEncodedImageCallback sink; |
Niels Möller | 6bb5ab9 | 2019-01-11 11:11:10 +0100 | [diff] [blame] | 79 | VCMEncodedFrameCallback callback(&sink); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 80 | const size_t kFramerate = 30; |
| 81 | callback.SetTimingFramesThresholds( |
| 82 | {delay_ms, kDefaultOutlierFrameSizePercent}); |
| 83 | callback.OnFrameRateChanged(kFramerate); |
| 84 | int s, i; |
| 85 | std::vector<std::vector<FrameType>> result(num_streams); |
| 86 | for (s = 0; s < num_streams; ++s) |
| 87 | callback.OnTargetBitrateChanged(average_frame_sizes[s] * kFramerate, s); |
| 88 | int64_t current_timestamp = 0; |
| 89 | for (i = 0; i < num_frames; ++i) { |
| 90 | current_timestamp += 1; |
| 91 | for (s = 0; s < num_streams; ++s) { |
| 92 | // every (5+s)-th frame is dropped on s-th stream by design. |
| 93 | bool dropped = i % (5 + s) == 0; |
| 94 | |
| 95 | EncodedImage image; |
| 96 | CodecSpecificInfo codec_specific; |
Niels Möller | 663844d | 2019-02-14 16:15:54 +0100 | [diff] [blame] | 97 | image.Allocate(max_frame_size); |
Niels Möller | 77536a2 | 2019-01-15 08:50:01 +0100 | [diff] [blame] | 98 | image.set_size(FrameSize(min_frame_size, max_frame_size, s, i)); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 99 | image.capture_time_ms_ = current_timestamp; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 100 | image.SetTimestamp(static_cast<uint32_t>(current_timestamp * 90)); |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 101 | image.SetSpatialIndex(s); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 102 | codec_specific.codecType = kVideoCodecGeneric; |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 103 | callback.OnEncodeStarted(static_cast<uint32_t>(current_timestamp * 90), |
| 104 | current_timestamp, s); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 105 | if (dropped) { |
| 106 | result[s].push_back(FrameType::kDropped); |
| 107 | continue; |
| 108 | } |
| 109 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 110 | if (sink.WasTimingFrame()) { |
| 111 | result[s].push_back(FrameType::kTiming); |
| 112 | } else { |
| 113 | result[s].push_back(FrameType::kNormal); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | return result; |
| 118 | } |
| 119 | } // namespace |
| 120 | |
| 121 | TEST(TestVCMEncodedFrameCallback, MarksTimingFramesPeriodicallyTogether) { |
| 122 | const int64_t kDelayMs = 29; |
| 123 | const size_t kMinFrameSize = 10; |
| 124 | const size_t kMaxFrameSize = 20; |
| 125 | const int kNumFrames = 1000; |
| 126 | const int kNumStreams = 3; |
| 127 | // No outliers as 1000 is larger than anything from range [10,20]. |
| 128 | const std::vector<size_t> kAverageSize = {1000, 1000, 1000}; |
| 129 | auto frames = GetTimingFrames(kDelayMs, kMinFrameSize, kMaxFrameSize, |
| 130 | kAverageSize, kNumStreams, kNumFrames); |
| 131 | // Timing frames should be tirggered every delayMs. |
| 132 | // As no outliers are expected, frames on all streams have to be |
| 133 | // marked together. |
| 134 | int last_timing_frame = -1; |
| 135 | for (int i = 0; i < kNumFrames; ++i) { |
| 136 | int num_normal = 0; |
| 137 | int num_timing = 0; |
| 138 | int num_dropped = 0; |
| 139 | for (int s = 0; s < kNumStreams; ++s) { |
| 140 | if (frames[s][i] == FrameType::kTiming) { |
| 141 | ++num_timing; |
| 142 | } else if (frames[s][i] == FrameType::kNormal) { |
| 143 | ++num_normal; |
| 144 | } else { |
| 145 | ++num_dropped; |
| 146 | } |
| 147 | } |
| 148 | // Can't have both normal and timing frames at the same timstamp. |
| 149 | EXPECT_TRUE(num_timing == 0 || num_normal == 0); |
| 150 | if (num_dropped < kNumStreams) { |
| 151 | if (last_timing_frame == -1 || i >= last_timing_frame + kDelayMs) { |
| 152 | // If didn't have timing frames for a period, current sent frame has to |
| 153 | // be one. No normal frames should be sent. |
| 154 | EXPECT_EQ(num_normal, 0); |
| 155 | } else { |
| 156 | // No unneeded timing frames should be sent. |
| 157 | EXPECT_EQ(num_timing, 0); |
| 158 | } |
| 159 | } |
| 160 | if (num_timing > 0) |
| 161 | last_timing_frame = i; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | TEST(TestVCMEncodedFrameCallback, MarksOutliers) { |
| 166 | const int64_t kDelayMs = 29; |
| 167 | const size_t kMinFrameSize = 2495; |
| 168 | const size_t kMaxFrameSize = 2505; |
| 169 | const int kNumFrames = 1000; |
| 170 | const int kNumStreams = 3; |
| 171 | // Possible outliers as 1000 lies in range [995, 1005]. |
| 172 | const std::vector<size_t> kAverageSize = {998, 1000, 1004}; |
| 173 | auto frames = GetTimingFrames(kDelayMs, kMinFrameSize, kMaxFrameSize, |
| 174 | kAverageSize, kNumStreams, kNumFrames); |
| 175 | // All outliers should be marked. |
| 176 | for (int i = 0; i < kNumFrames; ++i) { |
| 177 | for (int s = 0; s < kNumStreams; ++s) { |
| 178 | if (FrameSize(kMinFrameSize, kMaxFrameSize, s, i) >= |
| 179 | kAverageSize[s] * kDefaultOutlierFrameSizePercent / 100) { |
| 180 | // Too big frame. May be dropped or timing, but not normal. |
| 181 | EXPECT_NE(frames[s][i], FrameType::kNormal); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 187 | TEST(TestVCMEncodedFrameCallback, NoTimingFrameIfNoEncodeStartTime) { |
| 188 | EncodedImage image; |
| 189 | CodecSpecificInfo codec_specific; |
| 190 | int64_t timestamp = 1; |
Niels Möller | 663844d | 2019-02-14 16:15:54 +0100 | [diff] [blame] | 191 | constexpr size_t kFrameSize = 500; |
| 192 | image.Allocate(kFrameSize); |
| 193 | image.set_size(kFrameSize); |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 194 | image.capture_time_ms_ = timestamp; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 195 | image.SetTimestamp(static_cast<uint32_t>(timestamp * 90)); |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 196 | codec_specific.codecType = kVideoCodecGeneric; |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 197 | FakeEncodedImageCallback sink; |
Niels Möller | 6bb5ab9 | 2019-01-11 11:11:10 +0100 | [diff] [blame] | 198 | VCMEncodedFrameCallback callback(&sink); |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 199 | VideoCodec::TimingFrameTriggerThresholds thresholds; |
| 200 | thresholds.delay_ms = 1; // Make all frames timing frames. |
| 201 | callback.SetTimingFramesThresholds(thresholds); |
Ilya Nikolaevskiy | e0da9ea | 2017-11-08 14:39:02 +0100 | [diff] [blame] | 202 | callback.OnTargetBitrateChanged(500, 0); |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 203 | |
| 204 | // Verify a single frame works with encode start time set. |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 205 | callback.OnEncodeStarted(static_cast<uint32_t>(timestamp * 90), timestamp, 0); |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 206 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 207 | EXPECT_TRUE(sink.WasTimingFrame()); |
| 208 | |
| 209 | // New frame, now skip OnEncodeStarted. Should not result in timing frame. |
| 210 | image.capture_time_ms_ = ++timestamp; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 211 | image.SetTimestamp(static_cast<uint32_t>(timestamp * 90)); |
sprang | ba050a6 | 2017-08-18 02:51:12 -0700 | [diff] [blame] | 212 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 213 | EXPECT_FALSE(sink.WasTimingFrame()); |
| 214 | } |
| 215 | |
Ilya Nikolaevskiy | 764aeb7 | 2018-04-03 10:01:52 +0200 | [diff] [blame] | 216 | TEST(TestVCMEncodedFrameCallback, AdjustsCaptureTimeForInternalSourceEncoder) { |
| 217 | rtc::ScopedFakeClock clock; |
| 218 | clock.SetTimeMicros(1234567); |
| 219 | EncodedImage image; |
| 220 | CodecSpecificInfo codec_specific; |
| 221 | const int64_t kEncodeStartDelayMs = 2; |
| 222 | const int64_t kEncodeFinishDelayMs = 10; |
| 223 | int64_t timestamp = 1; |
Niels Möller | 663844d | 2019-02-14 16:15:54 +0100 | [diff] [blame] | 224 | constexpr size_t kFrameSize = 500; |
| 225 | image.Allocate(kFrameSize); |
| 226 | image.set_size(kFrameSize); |
Ilya Nikolaevskiy | 764aeb7 | 2018-04-03 10:01:52 +0200 | [diff] [blame] | 227 | image.capture_time_ms_ = timestamp; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 228 | image.SetTimestamp(static_cast<uint32_t>(timestamp * 90)); |
Ilya Nikolaevskiy | 764aeb7 | 2018-04-03 10:01:52 +0200 | [diff] [blame] | 229 | codec_specific.codecType = kVideoCodecGeneric; |
Ilya Nikolaevskiy | 764aeb7 | 2018-04-03 10:01:52 +0200 | [diff] [blame] | 230 | FakeEncodedImageCallback sink; |
Niels Möller | 6bb5ab9 | 2019-01-11 11:11:10 +0100 | [diff] [blame] | 231 | VCMEncodedFrameCallback callback(&sink); |
Ilya Nikolaevskiy | 764aeb7 | 2018-04-03 10:01:52 +0200 | [diff] [blame] | 232 | callback.SetInternalSource(true); |
| 233 | VideoCodec::TimingFrameTriggerThresholds thresholds; |
| 234 | thresholds.delay_ms = 1; // Make all frames timing frames. |
| 235 | callback.SetTimingFramesThresholds(thresholds); |
| 236 | callback.OnTargetBitrateChanged(500, 0); |
| 237 | |
| 238 | // Verify a single frame without encode timestamps isn't a timing frame. |
| 239 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 240 | EXPECT_FALSE(sink.WasTimingFrame()); |
| 241 | |
| 242 | // New frame, but this time with encode timestamps set in timing_. |
| 243 | // This should be a timing frame. |
| 244 | image.capture_time_ms_ = ++timestamp; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 245 | image.SetTimestamp(static_cast<uint32_t>(timestamp * 90)); |
Ilya Nikolaevskiy | 764aeb7 | 2018-04-03 10:01:52 +0200 | [diff] [blame] | 246 | image.timing_.encode_start_ms = timestamp + kEncodeStartDelayMs; |
| 247 | image.timing_.encode_finish_ms = timestamp + kEncodeFinishDelayMs; |
| 248 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 249 | EXPECT_TRUE(sink.WasTimingFrame()); |
| 250 | // Frame is captured kEncodeFinishDelayMs before it's encoded, so restored |
| 251 | // capture timestamp should be kEncodeFinishDelayMs in the past. |
| 252 | EXPECT_EQ( |
| 253 | sink.GetLastCaptureTimestamp(), |
| 254 | clock.TimeNanos() / rtc::kNumNanosecsPerMillisec - kEncodeFinishDelayMs); |
| 255 | } |
| 256 | |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 257 | TEST(TestVCMEncodedFrameCallback, NotifiesAboutDroppedFrames) { |
| 258 | EncodedImage image; |
| 259 | CodecSpecificInfo codec_specific; |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 260 | const int64_t kTimestampMs1 = 47721840; |
| 261 | const int64_t kTimestampMs2 = 47721850; |
| 262 | const int64_t kTimestampMs3 = 47721860; |
| 263 | const int64_t kTimestampMs4 = 47721870; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 264 | codec_specific.codecType = kVideoCodecGeneric; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 265 | FakeEncodedImageCallback sink; |
Niels Möller | 6bb5ab9 | 2019-01-11 11:11:10 +0100 | [diff] [blame] | 266 | VCMEncodedFrameCallback callback(&sink); |
Ilya Nikolaevskiy | e0da9ea | 2017-11-08 14:39:02 +0100 | [diff] [blame] | 267 | // Any non-zero bitrate needed to be set before the first frame. |
| 268 | callback.OnTargetBitrateChanged(500, 0); |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 269 | image.capture_time_ms_ = kTimestampMs1; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 270 | image.SetTimestamp(static_cast<uint32_t>(image.capture_time_ms_ * 90)); |
| 271 | callback.OnEncodeStarted(image.Timestamp(), image.capture_time_ms_, 0); |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 272 | EXPECT_EQ(0u, sink.GetNumFramesDropped()); |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 273 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 274 | |
| 275 | image.capture_time_ms_ = kTimestampMs2; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 276 | image.SetTimestamp(static_cast<uint32_t>(image.capture_time_ms_ * 90)); |
| 277 | callback.OnEncodeStarted(image.Timestamp(), image.capture_time_ms_, 0); |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 278 | // No OnEncodedImageCall for timestamp2. Yet, at this moment it's not known |
| 279 | // that frame with timestamp2 was dropped. |
| 280 | EXPECT_EQ(0u, sink.GetNumFramesDropped()); |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 281 | |
| 282 | image.capture_time_ms_ = kTimestampMs3; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 283 | image.SetTimestamp(static_cast<uint32_t>(image.capture_time_ms_ * 90)); |
| 284 | callback.OnEncodeStarted(image.Timestamp(), image.capture_time_ms_, 0); |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 285 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 286 | EXPECT_EQ(1u, sink.GetNumFramesDropped()); |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 287 | |
| 288 | image.capture_time_ms_ = kTimestampMs4; |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 289 | image.SetTimestamp(static_cast<uint32_t>(image.capture_time_ms_ * 90)); |
| 290 | callback.OnEncodeStarted(image.Timestamp(), image.capture_time_ms_, 0); |
Ilya Nikolaevskiy | d79314f | 2017-10-23 10:45:37 +0200 | [diff] [blame] | 291 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 292 | EXPECT_EQ(1u, sink.GetNumFramesDropped()); |
| 293 | } |
| 294 | |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 295 | TEST(TestVCMEncodedFrameCallback, RestoresCaptureTimestamps) { |
| 296 | EncodedImage image; |
| 297 | CodecSpecificInfo codec_specific; |
| 298 | const int64_t kTimestampMs = 123456; |
| 299 | codec_specific.codecType = kVideoCodecGeneric; |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 300 | FakeEncodedImageCallback sink; |
Niels Möller | 6bb5ab9 | 2019-01-11 11:11:10 +0100 | [diff] [blame] | 301 | VCMEncodedFrameCallback callback(&sink); |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 302 | // Any non-zero bitrate needed to be set before the first frame. |
| 303 | callback.OnTargetBitrateChanged(500, 0); |
| 304 | image.capture_time_ms_ = kTimestampMs; // Incorrect timesetamp. |
Niels Möller | 2377588 | 2018-08-16 10:24:12 +0200 | [diff] [blame] | 305 | image.SetTimestamp(static_cast<uint32_t>(image.capture_time_ms_ * 90)); |
| 306 | callback.OnEncodeStarted(image.Timestamp(), image.capture_time_ms_, 0); |
Ilya Nikolaevskiy | 76f2a85 | 2017-11-16 14:33:53 +0100 | [diff] [blame] | 307 | image.capture_time_ms_ = 0; // Incorrect timesetamp. |
| 308 | callback.OnEncodedImage(image, &codec_specific, nullptr); |
| 309 | EXPECT_EQ(kTimestampMs, sink.GetLastCaptureTimestamp()); |
| 310 | } |
| 311 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 312 | } // namespace test |
| 313 | } // namespace webrtc |