tor-browser

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

time_stamp_test.cc (3485B)


      1 /*
      2 * Copyright (c) 2019, Alliance for Open Media. All rights reserved.
      3 *
      4 * This source code is subject to the terms of the BSD 2 Clause License and
      5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      6 * was not distributed with this source code in the LICENSE file, you can
      7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      8 * Media Patent License 1.0 was not distributed with this source code in the
      9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
     10 */
     11 
     12 //  Test AOM timestamp handling
     13 
     14 #include "gtest/gtest.h"
     15 #include "test/codec_factory.h"
     16 #include "test/encode_test_driver.h"
     17 #include "test/util.h"
     18 #include "test/video_source.h"
     19 
     20 namespace {
     21 
     22 const int kVideoSourceWidth = 320;
     23 const int kVideoSourceHeight = 240;
     24 const int kFramesToEncode = 3;
     25 
     26 // A video source that exposes functions to set the timebase, framerate and
     27 // starting pts.
     28 class DummyTimebaseVideoSource : public ::libaom_test::DummyVideoSource {
     29 public:
     30  // Parameters num and den set the timebase for the video source.
     31  DummyTimebaseVideoSource(int num, int den)
     32      : framerate_numerator_(30), framerate_denominator_(1), starting_pts_(0) {
     33    SetSize(kVideoSourceWidth, kVideoSourceHeight);
     34    set_limit(kFramesToEncode);
     35    timebase_.num = num;
     36    timebase_.den = den;
     37  }
     38 
     39  void SetFramerate(int numerator, int denominator) {
     40    framerate_numerator_ = numerator;
     41    framerate_denominator_ = denominator;
     42  }
     43 
     44  // Returns one frames duration in timebase units as a double.
     45  double FrameDuration() const {
     46    return (static_cast<double>(timebase_.den) / timebase_.num) /
     47           (static_cast<double>(framerate_numerator_) / framerate_denominator_);
     48  }
     49 
     50  aom_codec_pts_t pts() const override {
     51    return static_cast<aom_codec_pts_t>(frame_ * FrameDuration() +
     52                                        starting_pts_ + 0.5);
     53  }
     54 
     55  unsigned long duration() const override {
     56    return static_cast<unsigned long>(FrameDuration() + 0.5);
     57  }
     58 
     59  aom_rational_t timebase() const override { return timebase_; }
     60 
     61  void set_starting_pts(int64_t starting_pts) { starting_pts_ = starting_pts; }
     62 
     63 private:
     64  aom_rational_t timebase_;
     65  int framerate_numerator_;
     66  int framerate_denominator_;
     67  int64_t starting_pts_;
     68 };
     69 
     70 class TimestampTest
     71    : public ::libaom_test::EncoderTest,
     72      public ::libaom_test::CodecTestWithParam<libaom_test::TestMode> {
     73 protected:
     74  TimestampTest() : EncoderTest(GET_PARAM(0)) {}
     75  ~TimestampTest() override = default;
     76 
     77  void SetUp() override { InitializeConfig(GET_PARAM(1)); }
     78 };
     79 
     80 // Tests encoding in millisecond timebase.
     81 TEST_P(TimestampTest, EncodeFrames) {
     82  DummyTimebaseVideoSource video(1, 1000);
     83  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
     84 }
     85 
     86 TEST_P(TimestampTest, TestMicrosecondTimebase) {
     87  // Set the timebase to microseconds.
     88  DummyTimebaseVideoSource video(1, 1000000);
     89  video.set_limit(1);
     90  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
     91 }
     92 
     93 TEST_P(TimestampTest, TestAv1Rollover) {
     94  DummyTimebaseVideoSource video(1, 1000);
     95  video.set_starting_pts(922337170351ll);
     96  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
     97 }
     98 #if CONFIG_REALTIME_ONLY
     99 AV1_INSTANTIATE_TEST_SUITE(TimestampTest,
    100                           ::testing::Values(::libaom_test::kRealTime));
    101 #else
    102 AV1_INSTANTIATE_TEST_SUITE(TimestampTest,
    103                           ::testing::Values(::libaom_test::kRealTime,
    104                                             ::libaom_test::kTwoPassGood));
    105 #endif
    106 
    107 }  // namespace