tor-browser

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

mock_video_decoder.h (2877B)


      1 /*
      2 *  Copyright (c) 2018 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 #ifndef API_TEST_MOCK_VIDEO_DECODER_H_
     12 #define API_TEST_MOCK_VIDEO_DECODER_H_
     13 
     14 #include <cstdint>
     15 #include <optional>
     16 
     17 #include "api/video/encoded_image.h"
     18 #include "api/video/video_frame.h"
     19 #include "api/video_codecs/video_decoder.h"
     20 #include "test/gmock.h"
     21 
     22 namespace webrtc {
     23 
     24 using testing::_;
     25 using testing::Invoke;
     26 
     27 class MockDecodedImageCallback : public DecodedImageCallback {
     28 public:
     29  MOCK_METHOD(int32_t,
     30              Decoded,
     31              (VideoFrame & decoded_image),  // NOLINT
     32              (override));
     33  MOCK_METHOD(int32_t,
     34              Decoded,
     35              (VideoFrame & decoded_image,  // NOLINT
     36               int64_t decode_time_ms),
     37              (override));
     38  MOCK_METHOD(void,
     39              Decoded,
     40              (VideoFrame & decoded_image,  // NOLINT
     41               std::optional<int32_t> decode_time_ms,
     42               std::optional<uint8_t> qp),
     43              (override));
     44 };
     45 
     46 class MockVideoDecoder : public VideoDecoder {
     47 public:
     48  MockVideoDecoder() {
     49    // Make `Configure` succeed by default, so that individual tests that
     50    // verify other methods wouldn't need to stub `Configure`.
     51    ON_CALL(*this, Configure).WillByDefault(testing::Return(true));
     52 
     53    // TODO(bugs.webrtc.org/15444): Remove once all tests have been migrated to
     54    // expecting calls Decode without a missing_frames param.
     55    ON_CALL(*this, Decode(_, _))
     56        .WillByDefault(Invoke([this](const EncodedImage& input_image,
     57                                     int64_t render_time_ms) {
     58          return Decode(input_image, /*missing_frames=*/false, render_time_ms);
     59        }));
     60  }
     61 
     62  ~MockVideoDecoder() override { Destruct(); }
     63 
     64  MOCK_METHOD(bool, Configure, (const Settings& settings), (override));
     65  MOCK_METHOD(int32_t,
     66              Decode,
     67              (const EncodedImage& input_image, int64_t render_time_ms),
     68              (override));
     69  MOCK_METHOD(int32_t,
     70              Decode,
     71              (const EncodedImage& input_image,
     72               bool missing_frames,
     73               int64_t render_time_ms));
     74  MOCK_METHOD(int32_t,
     75              RegisterDecodeCompleteCallback,
     76              (DecodedImageCallback * callback),
     77              (override));
     78  MOCK_METHOD(int32_t, Release, (), (override));
     79 
     80  // Special utility method that allows a test to monitor/verify when
     81  // destruction of the decoder instance occurs.
     82  MOCK_METHOD(void, Destruct, (), ());
     83 };
     84 
     85 }  // namespace webrtc
     86 
     87 #endif  // API_TEST_MOCK_VIDEO_DECODER_H_