blob: 87b8cc8c8e5589a93350a01073a7535c5bc9aa2f [file] [log] [blame]
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +00001/*
2 * Copyright (c) 2014 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef TEST_MOCK_AUDIO_ENCODER_H_
12#define TEST_MOCK_AUDIO_ENCODER_H_
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +000013
ossu264087f2016-04-18 08:07:24 -070014#include <string>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/array_view.h"
17#include "api/audio_codecs/audio_encoder.h"
18#include "test/gmock.h"
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +000019
20namespace webrtc {
21
ossu2903ba52016-04-18 06:14:33 -070022class MockAudioEncoder : public AudioEncoder {
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +000023 public:
ossueb1fde42017-05-02 06:46:30 -070024 MockAudioEncoder();
25 ~MockAudioEncoder();
Danil Chapovalov54706d62020-05-14 19:50:01 +020026 MOCK_METHOD(int, SampleRateHz, (), (const, override));
27 MOCK_METHOD(size_t, NumChannels, (), (const, override));
28 MOCK_METHOD(int, RtpTimestampRateHz, (), (const, override));
29 MOCK_METHOD(size_t, Num10MsFramesInNextPacket, (), (const, override));
30 MOCK_METHOD(size_t, Max10MsFramesInAPacket, (), (const, override));
31 MOCK_METHOD(int, GetTargetBitrate, (), (const, override));
32 MOCK_METHOD((absl::optional<std::pair<TimeDelta, TimeDelta>>),
33 GetFrameLengthRange,
34 (),
35 (const, override));
Sebastian Jansson62aee932019-10-02 12:27:06 +020036
Danil Chapovalov54706d62020-05-14 19:50:01 +020037 MOCK_METHOD(void, Reset, (), (override));
38 MOCK_METHOD(bool, SetFec, (bool enable), (override));
39 MOCK_METHOD(bool, SetDtx, (bool enable), (override));
40 MOCK_METHOD(bool, SetApplication, (Application application), (override));
41 MOCK_METHOD(void, SetMaxPlaybackRate, (int frequency_hz), (override));
42 MOCK_METHOD(void,
43 OnReceivedUplinkBandwidth,
44 (int target_audio_bitrate_bps,
45 absl::optional<int64_t> probing_interval_ms),
46 (override));
47 MOCK_METHOD(void,
48 OnReceivedUplinkPacketLossFraction,
49 (float uplink_packet_loss_fraction),
50 (override));
Jakob Ivarssonfde2b242020-08-20 16:48:49 +020051 MOCK_METHOD(void,
52 OnReceivedOverhead,
53 (size_t overhead_bytes_per_packet),
54 (override));
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020055
Danil Chapovalov54706d62020-05-14 19:50:01 +020056 MOCK_METHOD(bool,
57 EnableAudioNetworkAdaptor,
58 (const std::string& config_string, RtcEventLog*),
59 (override));
ossu20a4b3f2017-04-27 02:08:52 -070060
ossu10a029e2016-03-01 00:41:31 -080061 // Note, we explicitly chose not to create a mock for the Encode method.
Danil Chapovalov54706d62020-05-14 19:50:01 +020062 MOCK_METHOD(EncodedInfo,
63 EncodeImpl,
64 (uint32_t timestamp,
65 rtc::ArrayView<const int16_t> audio,
66 rtc::Buffer*),
67 (override));
ossu10a029e2016-03-01 00:41:31 -080068
69 class FakeEncoding {
70 public:
71 // Creates a functor that will return |info| and adjust the rtc::Buffer
72 // given as input to it, so it is info.encoded_bytes larger.
ossu264087f2016-04-18 08:07:24 -070073 explicit FakeEncoding(const AudioEncoder::EncodedInfo& info);
ossu10a029e2016-03-01 00:41:31 -080074
75 // Shorthand version of the constructor above, for when only setting
76 // encoded_bytes in the EncodedInfo object matters.
ossu264087f2016-04-18 08:07:24 -070077 explicit FakeEncoding(size_t encoded_bytes);
ossu10a029e2016-03-01 00:41:31 -080078
79 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
80 rtc::ArrayView<const int16_t> audio,
81 rtc::Buffer* encoded);
82
83 private:
84 AudioEncoder::EncodedInfo info_;
85 };
86
87 class CopyEncoding {
88 public:
ossueb1fde42017-05-02 06:46:30 -070089 ~CopyEncoding();
90
ossu10a029e2016-03-01 00:41:31 -080091 // Creates a functor that will return |info| and append the data in the
92 // payload to the buffer given as input to it. Up to info.encoded_bytes are
93 // appended - make sure the payload is big enough! Since it uses an
94 // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out
95 // of scope!
96 CopyEncoding(AudioEncoder::EncodedInfo info,
97 rtc::ArrayView<const uint8_t> payload);
98
99 // Shorthand version of the constructor above, for when you wish to append
100 // the whole payload and do not care about any EncodedInfo attribute other
101 // than encoded_bytes.
ossu264087f2016-04-18 08:07:24 -0700102 explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload);
ossu10a029e2016-03-01 00:41:31 -0800103
104 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
105 rtc::ArrayView<const int16_t> audio,
106 rtc::Buffer* encoded);
ossu264087f2016-04-18 08:07:24 -0700107
ossu10a029e2016-03-01 00:41:31 -0800108 private:
109 AudioEncoder::EncodedInfo info_;
110 rtc::ArrayView<const uint8_t> payload_;
111 };
ossu10a029e2016-03-01 00:41:31 -0800112};
113
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +0000114} // namespace webrtc
115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // TEST_MOCK_AUDIO_ENCODER_H_