blob: 87b8cc8c8e5589a93350a01073a7535c5bc9aa2f [file] [log] [blame]
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:081/*
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 04:47:3111#ifndef TEST_MOCK_AUDIO_ENCODER_H_
12#define TEST_MOCK_AUDIO_ENCODER_H_
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:0813
ossu264087f2016-04-18 15:07:2414#include <string>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#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:0819
20namespace webrtc {
21
ossu2903ba52016-04-18 13:14:3322class MockAudioEncoder : public AudioEncoder {
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:0823 public:
ossueb1fde42017-05-02 13:46:3024 MockAudioEncoder();
25 ~MockAudioEncoder();
Danil Chapovalov54706d62020-05-14 17:50:0126 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 10:27:0636
Danil Chapovalov54706d62020-05-14 17:50:0137 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 14:48:4951 MOCK_METHOD(void,
52 OnReceivedOverhead,
53 (size_t overhead_bytes_per_packet),
54 (override));
Karl Wiberg7e0c7d42015-05-18 12:52:2955
Danil Chapovalov54706d62020-05-14 17:50:0156 MOCK_METHOD(bool,
57 EnableAudioNetworkAdaptor,
58 (const std::string& config_string, RtcEventLog*),
59 (override));
ossu20a4b3f2017-04-27 09:08:5260
ossu10a029e2016-03-01 08:41:3161 // Note, we explicitly chose not to create a mock for the Encode method.
Danil Chapovalov54706d62020-05-14 17:50:0162 MOCK_METHOD(EncodedInfo,
63 EncodeImpl,
64 (uint32_t timestamp,
65 rtc::ArrayView<const int16_t> audio,
66 rtc::Buffer*),
67 (override));
ossu10a029e2016-03-01 08:41:3168
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 15:07:2473 explicit FakeEncoding(const AudioEncoder::EncodedInfo& info);
ossu10a029e2016-03-01 08:41:3174
75 // Shorthand version of the constructor above, for when only setting
76 // encoded_bytes in the EncodedInfo object matters.
ossu264087f2016-04-18 15:07:2477 explicit FakeEncoding(size_t encoded_bytes);
ossu10a029e2016-03-01 08:41:3178
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 13:46:3089 ~CopyEncoding();
90
ossu10a029e2016-03-01 08:41:3191 // 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 15:07:24102 explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload);
ossu10a029e2016-03-01 08:41:31103
104 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
105 rtc::ArrayView<const int16_t> audio,
106 rtc::Buffer* encoded);
ossu264087f2016-04-18 15:07:24107
ossu10a029e2016-03-01 08:41:31108 private:
109 AudioEncoder::EncodedInfo info_;
110 rtc::ArrayView<const uint8_t> payload_;
111 };
ossu10a029e2016-03-01 08:41:31112};
113
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08114} // namespace webrtc
115
Mirko Bonadei92ea95e2017-09-15 04:47:31116#endif // TEST_MOCK_AUDIO_ENCODER_H_