Home | History | Annotate | Download | only in test
      1 /*
      2  *  Copyright (c) 2013 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 WEBRTC_TEST_FAKE_ENCODER_H_
     12 #define WEBRTC_TEST_FAKE_ENCODER_H_
     13 
     14 #include <vector>
     15 
     16 #include "webrtc/common_types.h"
     17 #include "webrtc/system_wrappers/include/clock.h"
     18 #include "webrtc/video_encoder.h"
     19 
     20 namespace webrtc {
     21 namespace test {
     22 
     23 class FakeEncoder : public VideoEncoder {
     24  public:
     25   explicit FakeEncoder(Clock* clock);
     26   virtual ~FakeEncoder();
     27 
     28   // Sets max bitrate. Not thread-safe, call before registering the encoder.
     29   void SetMaxBitrate(int max_kbps);
     30 
     31   int32_t InitEncode(const VideoCodec* config,
     32                      int32_t number_of_cores,
     33                      size_t max_payload_size) override;
     34   int32_t Encode(const VideoFrame& input_image,
     35                  const CodecSpecificInfo* codec_specific_info,
     36                  const std::vector<FrameType>* frame_types) override;
     37   int32_t RegisterEncodeCompleteCallback(
     38       EncodedImageCallback* callback) override;
     39   int32_t Release() override;
     40   int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
     41   int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override;
     42   const char* ImplementationName() const override;
     43 
     44   static const char* kImplementationName;
     45 
     46  protected:
     47   Clock* const clock_;
     48   VideoCodec config_;
     49   EncodedImageCallback* callback_;
     50   int target_bitrate_kbps_;
     51   int max_target_bitrate_kbps_;
     52   int64_t last_encode_time_ms_;
     53   uint8_t encoded_buffer_[100000];
     54 };
     55 
     56 class FakeH264Encoder : public FakeEncoder, public EncodedImageCallback {
     57  public:
     58   explicit FakeH264Encoder(Clock* clock);
     59   virtual ~FakeH264Encoder() {}
     60 
     61   int32_t RegisterEncodeCompleteCallback(
     62       EncodedImageCallback* callback) override;
     63 
     64   int32_t Encoded(const EncodedImage& encodedImage,
     65                   const CodecSpecificInfo* codecSpecificInfo,
     66                   const RTPFragmentationHeader* fragments) override;
     67 
     68  private:
     69   EncodedImageCallback* callback_;
     70   int idr_counter_;
     71 };
     72 
     73 class DelayedEncoder : public test::FakeEncoder {
     74  public:
     75   DelayedEncoder(Clock* clock, int delay_ms);
     76   virtual ~DelayedEncoder() {}
     77 
     78   int32_t Encode(const VideoFrame& input_image,
     79                  const CodecSpecificInfo* codec_specific_info,
     80                  const std::vector<FrameType>* frame_types) override;
     81 
     82  private:
     83   const int delay_ms_;
     84 };
     85 }  // namespace test
     86 }  // namespace webrtc
     87 
     88 #endif  // WEBRTC_TEST_FAKE_ENCODER_H_
     89