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_VIDEO_ENGINE_TEST_COMMON_FAKE_ENCODER_H_
     12 #define WEBRTC_VIDEO_ENGINE_TEST_COMMON_FAKE_ENCODER_H_
     13 
     14 #include <vector>
     15 
     16 #include "webrtc/common_types.h"
     17 #include "webrtc/system_wrappers/interface/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   virtual int32_t InitEncode(const VideoCodec* config,
     32                              int32_t number_of_cores,
     33                              uint32_t max_payload_size) OVERRIDE;
     34   virtual int32_t Encode(
     35      const I420VideoFrame& input_image,
     36      const CodecSpecificInfo* codec_specific_info,
     37      const std::vector<VideoFrameType>* frame_types) OVERRIDE;
     38   virtual int32_t RegisterEncodeCompleteCallback(
     39       EncodedImageCallback* callback) OVERRIDE;
     40   virtual int32_t Release() OVERRIDE;
     41   virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt) OVERRIDE;
     42   virtual int32_t SetRates(uint32_t new_target_bitrate,
     43                            uint32_t framerate) OVERRIDE;
     44 
     45  private:
     46   Clock* const clock_;
     47   VideoCodec config_;
     48   EncodedImageCallback* callback_;
     49   int target_bitrate_kbps_;
     50   int max_target_bitrate_kbps_;
     51   int64_t last_encode_time_ms_;
     52   uint8_t encoded_buffer_[100000];
     53 };
     54 
     55 class FakeH264Encoder : public FakeEncoder, public EncodedImageCallback {
     56  public:
     57   explicit FakeH264Encoder(Clock* clock);
     58   virtual ~FakeH264Encoder() {}
     59 
     60   virtual int32_t RegisterEncodeCompleteCallback(
     61       EncodedImageCallback* callback) OVERRIDE;
     62 
     63   virtual int32_t Encoded(
     64       EncodedImage& encodedImage,
     65       const CodecSpecificInfo* codecSpecificInfo = NULL,
     66       const RTPFragmentationHeader* fragments = NULL) OVERRIDE;
     67 
     68  private:
     69   EncodedImageCallback* callback_;
     70   int idr_counter_;
     71 };
     72 }  // namespace test
     73 }  // namespace webrtc
     74 
     75 #endif  // WEBRTC_VIDEO_ENGINE_TEST_COMMON_FAKE_ENCODER_H_
     76