blob: d5e7b480dfeac2bb47057921f38f16db8c764022 [file] [log] [blame]
stefan@webrtc.org360e3762013-08-22 09:29:56 +00001/*
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
Peter Boström7623ce42015-12-09 12:13:30 +010011#ifndef WEBRTC_TEST_FAKE_ENCODER_H_
12#define WEBRTC_TEST_FAKE_ENCODER_H_
stefan@webrtc.org360e3762013-08-22 09:29:56 +000013
14#include <vector>
15
perkj803d97f2016-11-01 11:45:46 -070016#include "webrtc/base/criticalsection.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000017#include "webrtc/common_types.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010018#include "webrtc/system_wrappers/include/clock.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000019#include "webrtc/video_encoder.h"
stefan@webrtc.org360e3762013-08-22 09:29:56 +000020
21namespace webrtc {
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000022namespace test {
stefan@webrtc.org360e3762013-08-22 09:29:56 +000023
24class FakeEncoder : public VideoEncoder {
25 public:
26 explicit FakeEncoder(Clock* clock);
stefan@webrtc.org360e3762013-08-22 09:29:56 +000027 virtual ~FakeEncoder();
28
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000029 // Sets max bitrate. Not thread-safe, call before registering the encoder.
30 void SetMaxBitrate(int max_kbps);
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000031
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000032 int32_t InitEncode(const VideoCodec* config,
33 int32_t number_of_cores,
34 size_t max_payload_size) override;
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070035 int32_t Encode(const VideoFrame& input_image,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 const CodecSpecificInfo* codec_specific_info,
pbos22993e12015-10-19 02:39:06 -070037 const std::vector<FrameType>* frame_types) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000038 int32_t RegisterEncodeCompleteCallback(
39 EncodedImageCallback* callback) override;
40 int32_t Release() override;
41 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
42 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override;
Peter Boströmb7d9a972015-12-18 16:01:11 +010043 const char* ImplementationName() const override;
44
45 static const char* kImplementationName;
stefan@webrtc.org360e3762013-08-22 09:29:56 +000046
pbos@webrtc.org273a4142014-12-01 15:23:21 +000047 protected:
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000048 Clock* const clock_;
stefan@webrtc.org360e3762013-08-22 09:29:56 +000049 VideoCodec config_;
50 EncodedImageCallback* callback_;
51 int target_bitrate_kbps_;
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000052 int max_target_bitrate_kbps_;
stefan@webrtc.org360e3762013-08-22 09:29:56 +000053 int64_t last_encode_time_ms_;
pbos@webrtc.orgc095f512013-08-22 12:34:58 +000054 uint8_t encoded_buffer_[100000];
stefan@webrtc.org360e3762013-08-22 09:29:56 +000055};
stefan@webrtc.org79c33592014-08-06 09:24:53 +000056
57class FakeH264Encoder : public FakeEncoder, public EncodedImageCallback {
58 public:
59 explicit FakeH264Encoder(Clock* clock);
60 virtual ~FakeH264Encoder() {}
61
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000062 int32_t RegisterEncodeCompleteCallback(
63 EncodedImageCallback* callback) override;
stefan@webrtc.org79c33592014-08-06 09:24:53 +000064
Sergey Ulanov525df3f2016-08-02 17:46:41 -070065 Result OnEncodedImage(const EncodedImage& encodedImage,
66 const CodecSpecificInfo* codecSpecificInfo,
67 const RTPFragmentationHeader* fragments) override;
stefan@webrtc.org79c33592014-08-06 09:24:53 +000068
69 private:
70 EncodedImageCallback* callback_;
71 int idr_counter_;
72};
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +000073
74class DelayedEncoder : public test::FakeEncoder {
75 public:
76 DelayedEncoder(Clock* clock, int delay_ms);
77 virtual ~DelayedEncoder() {}
78
perkj803d97f2016-11-01 11:45:46 -070079 void SetDelay(int delay_ms);
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070080 int32_t Encode(const VideoFrame& input_image,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000081 const CodecSpecificInfo* codec_specific_info,
pbos22993e12015-10-19 02:39:06 -070082 const std::vector<FrameType>* frame_types) override;
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +000083
84 private:
perkj803d97f2016-11-01 11:45:46 -070085 rtc::CriticalSection lock_;
86 int delay_ms_ GUARDED_BY(&lock_);
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +000087};
pbos@webrtc.orgcb5118c2013-09-03 09:10:37 +000088} // namespace test
stefan@webrtc.org360e3762013-08-22 09:29:56 +000089} // namespace webrtc
90
Peter Boström7623ce42015-12-09 12:13:30 +010091#endif // WEBRTC_TEST_FAKE_ENCODER_H_