1360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org/*
2360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *
4360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *  Use of this source code is governed by a BSD-style license
5360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *  that can be found in the LICENSE file in the root of the source
6360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *  tree. An additional intellectual property rights grant can be found
7360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *  in the file PATENTS.  All contributing project authors may
8360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org */
10360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
117623ce4aeb9130c937ba5836490cbb3a35679e79Peter Boström#ifndef WEBRTC_TEST_FAKE_ENCODER_H_
127623ce4aeb9130c937ba5836490cbb3a35679e79Peter Boström#define WEBRTC_TEST_FAKE_ENCODER_H_
13360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
14360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org#include <vector>
15360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
16ab990ae43a2b84b103cb3c50bc38502375c13e68pbos@webrtc.org#include "webrtc/common_types.h"
1798f53510b222f71fdd8b799b2f33737ceeb28c61Henrik Kjellander#include "webrtc/system_wrappers/include/clock.h"
18ab990ae43a2b84b103cb3c50bc38502375c13e68pbos@webrtc.org#include "webrtc/video_encoder.h"
19360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
20360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.orgnamespace webrtc {
21cb5118c14cc578cf232f381c23da8c252c95a4fapbos@webrtc.orgnamespace test {
22360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
23360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.orgclass FakeEncoder : public VideoEncoder {
24360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org public:
25360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org  explicit FakeEncoder(Clock* clock);
26360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org  virtual ~FakeEncoder();
27360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
283349ae0cdcff9d2d3cae2e82a938b8db806c36f6pbos@webrtc.org  // Sets max bitrate. Not thread-safe, call before registering the encoder.
293349ae0cdcff9d2d3cae2e82a938b8db806c36f6pbos@webrtc.org  void SetMaxBitrate(int max_kbps);
30cb5118c14cc578cf232f381c23da8c252c95a4fapbos@webrtc.org
3114665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t InitEncode(const VideoCodec* config,
3214665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org                     int32_t number_of_cores,
3314665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org                     size_t max_payload_size) override;
344765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez  int32_t Encode(const VideoFrame& input_image,
3514665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org                 const CodecSpecificInfo* codec_specific_info,
3622993e1a0c114122fc1b9de0fc74d4096ec868bdpbos                 const std::vector<FrameType>* frame_types) override;
3714665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t RegisterEncodeCompleteCallback(
3814665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org      EncodedImageCallback* callback) override;
3914665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t Release() override;
4014665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
4114665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override;
42b7d9a97ce41022e984348efb5f28bf6dd6c6b779Peter Boström  const char* ImplementationName() const override;
43b7d9a97ce41022e984348efb5f28bf6dd6c6b779Peter Boström
44b7d9a97ce41022e984348efb5f28bf6dd6c6b779Peter Boström  static const char* kImplementationName;
45360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
46273a414b0ec2e58fdf3b817ad8b1a02f4ce15287pbos@webrtc.org protected:
47de1429e9ad9a3a207ca191e1d748aa7271066860pbos@webrtc.org  Clock* const clock_;
48360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org  VideoCodec config_;
49360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org  EncodedImageCallback* callback_;
50360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org  int target_bitrate_kbps_;
513349ae0cdcff9d2d3cae2e82a938b8db806c36f6pbos@webrtc.org  int max_target_bitrate_kbps_;
52360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org  int64_t last_encode_time_ms_;
53c095f510b6fb7a36131bd4e8c753c7e2c146faacpbos@webrtc.org  uint8_t encoded_buffer_[100000];
54360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org};
5579c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org
5679c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.orgclass FakeH264Encoder : public FakeEncoder, public EncodedImageCallback {
5779c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org public:
5879c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org  explicit FakeH264Encoder(Clock* clock);
5979c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org  virtual ~FakeH264Encoder() {}
6079c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org
6114665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t RegisterEncodeCompleteCallback(
6214665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org      EncodedImageCallback* callback) override;
6379c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org
6414665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org  int32_t Encoded(const EncodedImage& encodedImage,
6514665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org                  const CodecSpecificInfo* codecSpecificInfo,
6614665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org                  const RTPFragmentationHeader* fragments) override;
6779c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org
6879c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org private:
6979c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org  EncodedImageCallback* callback_;
7079c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org  int idr_counter_;
7179c3359e67bdbf3394a19f9251927c9482174043stefan@webrtc.org};
72049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org
73049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.orgclass DelayedEncoder : public test::FakeEncoder {
74049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org public:
75049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org  DelayedEncoder(Clock* clock, int delay_ms);
76049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org  virtual ~DelayedEncoder() {}
77049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org
784765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez  int32_t Encode(const VideoFrame& input_image,
7914665ff7d4024d07e58622f498b23fd980001871kjellander@webrtc.org                 const CodecSpecificInfo* codec_specific_info,
8022993e1a0c114122fc1b9de0fc74d4096ec868bdpbos                 const std::vector<FrameType>* frame_types) override;
81049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org
82049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org private:
83049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org  const int delay_ms_;
84049e4ece30b3901790949f9bbbeb5649a5c8932dasapersson@webrtc.org};
85cb5118c14cc578cf232f381c23da8c252c95a4fapbos@webrtc.org}  // namespace test
86360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org}  // namespace webrtc
87360e3768729d40a10543641cee2cf56e0cf7dddestefan@webrtc.org
887623ce4aeb9130c937ba5836490cbb3a35679e79Peter Boström#endif  // WEBRTC_TEST_FAKE_ENCODER_H_
89