tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

frame_helpers_unittest.cc (3915B)


      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 "modules/video_coding/frame_helpers.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 #include <memory>
     16 #include <optional>
     17 #include <utility>
     18 
     19 #include "absl/container/inlined_vector.h"
     20 #include "api/scoped_refptr.h"
     21 #include "api/units/timestamp.h"
     22 #include "api/video/corruption_detection/frame_instrumentation_data.h"
     23 #include "api/video/encoded_frame.h"
     24 #include "api/video/encoded_image.h"
     25 #include "test/gmock.h"
     26 #include "test/gtest.h"
     27 
     28 namespace webrtc {
     29 namespace {
     30 
     31 using ::testing::ElementsAre;
     32 
     33 constexpr uint32_t kRtpTimestamp = 123456710;
     34 
     35 scoped_refptr<EncodedImageBuffer> CreateEncodedImageBufferOfSizeN(size_t n,
     36                                                                  uint8_t x) {
     37  scoped_refptr<EncodedImageBuffer> buffer = EncodedImageBuffer::Create(n);
     38  for (size_t i = 0; i < n; ++i) {
     39    buffer->data()[i] = static_cast<uint8_t>(x + i);
     40  }
     41  return buffer;
     42 }
     43 
     44 // Returns an `EncodedFrame` with data values [x, x+1, ... x+(n-1)].
     45 EncodedFrame CreateEncodedImageOfSizeN(size_t n, uint8_t x) {
     46  EncodedFrame image;
     47  image.SetEncodedData(CreateEncodedImageBufferOfSizeN(n, x));
     48  image.SetRtpTimestamp(kRtpTimestamp);
     49  return image;
     50 }
     51 
     52 TEST(FrameHasBadRenderTimingTest, LargePositiveFrameDelayIsBad) {
     53  Timestamp render_time = Timestamp::Seconds(12);
     54  Timestamp now = Timestamp::Seconds(0);
     55 
     56  EXPECT_TRUE(FrameHasBadRenderTiming(render_time, now));
     57 }
     58 
     59 TEST(FrameHasBadRenderTimingTest, LargeNegativeFrameDelayIsBad) {
     60  Timestamp render_time = Timestamp::Seconds(12);
     61  Timestamp now = Timestamp::Seconds(24);
     62 
     63  EXPECT_TRUE(FrameHasBadRenderTiming(render_time, now));
     64 }
     65 
     66 TEST(FrameInstrumentationDataTest,
     67     CombinedFrameHasSameDataAsHighestSpatialLayer) {
     68  // Assume L2T1 scalability mode.
     69  EncodedFrame spatial_layer_1 = CreateEncodedImageOfSizeN(/*n=*/10, /*x=*/1);
     70  FrameInstrumentationData frame_ins_data_1;
     71  frame_ins_data_1.SetSequenceIndex(100);
     72  frame_ins_data_1.SetStdDev(0.5);
     73  frame_ins_data_1.SetLumaErrorThreshold(5);
     74  frame_ins_data_1.SetChromaErrorThreshold(5);
     75  frame_ins_data_1.SetSampleValues({0.2, 0.7, 1.9});
     76  spatial_layer_1.SetFrameInstrumentationData(frame_ins_data_1);
     77 
     78  EncodedFrame spatial_layer_2 = CreateEncodedImageOfSizeN(/*n=*/10, /*x=*/11);
     79  FrameInstrumentationData frame_ins_data_2;
     80  frame_ins_data_2.SetSequenceIndex(10);
     81  frame_ins_data_2.SetStdDev(1.0);
     82  frame_ins_data_2.SetLumaErrorThreshold(3);
     83  frame_ins_data_2.SetChromaErrorThreshold(4);
     84  frame_ins_data_2.SetSampleValues({0.1, 0.3, 2.1});
     85  spatial_layer_2.SetFrameInstrumentationData(frame_ins_data_2);
     86 
     87  absl::InlinedVector<std::unique_ptr<EncodedFrame>, 4> frames;
     88  frames.push_back(std::make_unique<EncodedFrame>(spatial_layer_1));
     89  frames.push_back(std::make_unique<EncodedFrame>(spatial_layer_2));
     90 
     91  std::optional<FrameInstrumentationData> frame_instrumentation_data =
     92      CombineAndDeleteFrames(std::move(frames))
     93          ->CodecSpecific()
     94          ->frame_instrumentation_data;
     95 
     96  ASSERT_TRUE(frame_instrumentation_data.has_value());
     97 
     98  // Expect to have the same frame_instrumentation_data as the highest spatial
     99  // layer.
    100  EXPECT_EQ(frame_instrumentation_data->sequence_index(), 10);
    101  EXPECT_EQ(frame_instrumentation_data->std_dev(), 1.0);
    102  EXPECT_EQ(frame_instrumentation_data->luma_error_threshold(), 3);
    103  EXPECT_EQ(frame_instrumentation_data->chroma_error_threshold(), 4);
    104  EXPECT_THAT(frame_instrumentation_data->sample_values(),
    105              ElementsAre(0.1, 0.3, 2.1));
    106 }
    107 
    108 }  // namespace
    109 }  // namespace webrtc