blob: 2dfd15ca981f0932bdd84e09e40d82b3abf8c2b8 [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:
nisseef8b61e2016-04-29 06:09:15 -070024 // TODO(nisse): Valid overrides commented out, because the gmock
25 // methods don't use any override declarations, and we want to avoid
26 // warnings from -Winconsistent-missing-override. See
27 // http://crbug.com/428099.
ossueb1fde42017-05-02 06:46:30 -070028 MockAudioEncoder();
29 ~MockAudioEncoder();
kwiberg9b66d3b2015-09-10 05:09:45 -070030 MOCK_METHOD1(Mark, void(std::string desc));
kwiberg@webrtc.org05211272015-02-18 12:00:32 +000031 MOCK_CONST_METHOD0(SampleRateHz, int());
Peter Kasting69558702016-01-12 16:26:35 -080032 MOCK_CONST_METHOD0(NumChannels, size_t());
kwiberg12cfc9b2015-09-08 05:57:53 -070033 MOCK_CONST_METHOD0(RtpTimestampRateHz, int());
Peter Kastingdce40cf2015-08-24 14:52:23 -070034 MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t());
35 MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t());
Henrik Lundin3e89dbf2015-06-18 14:58:34 +020036 MOCK_CONST_METHOD0(GetTargetBitrate, int());
Sebastian Jansson62aee932019-10-02 12:27:06 +020037 MOCK_CONST_METHOD0(GetFrameLengthRange,
38 absl::optional<std::pair<TimeDelta, TimeDelta>>());
39
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020040 MOCK_METHOD0(Reset, void());
41 MOCK_METHOD1(SetFec, bool(bool enable));
42 MOCK_METHOD1(SetDtx, bool(bool enable));
43 MOCK_METHOD1(SetApplication, bool(Application application));
kwiberg3f5f1c22015-09-08 23:15:33 -070044 MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz));
kwiberg12cfc9b2015-09-08 05:57:53 -070045 MOCK_METHOD1(SetMaxBitrate, void(int max_bps));
46 MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes));
michaelt566d8202017-01-12 10:17:38 -080047 MOCK_METHOD2(OnReceivedUplinkBandwidth,
48 void(int target_audio_bitrate_bps,
Danil Chapovalov431abd92018-06-18 12:54:17 +020049 absl::optional<int64_t> probing_interval_ms));
minyue4b9a2cb2016-11-30 06:49:59 -080050 MOCK_METHOD1(OnReceivedUplinkPacketLossFraction,
51 void(float uplink_packet_loss_fraction));
Karl Wiberg7e0c7d42015-05-18 14:52:29 +020052
ossu20a4b3f2017-04-27 02:08:52 -070053 MOCK_METHOD2(EnableAudioNetworkAdaptor,
ossueb1fde42017-05-02 06:46:30 -070054 bool(const std::string& config_string, RtcEventLog* event_log));
ossu20a4b3f2017-04-27 02:08:52 -070055
ossu10a029e2016-03-01 00:41:31 -080056 // Note, we explicitly chose not to create a mock for the Encode method.
ossu4f43fcf2016-03-04 00:54:32 -080057 MOCK_METHOD3(EncodeImpl,
ossu10a029e2016-03-01 00:41:31 -080058 EncodedInfo(uint32_t timestamp,
59 rtc::ArrayView<const int16_t> audio,
60 rtc::Buffer* encoded));
61
62 class FakeEncoding {
63 public:
64 // Creates a functor that will return |info| and adjust the rtc::Buffer
65 // given as input to it, so it is info.encoded_bytes larger.
ossu264087f2016-04-18 08:07:24 -070066 explicit FakeEncoding(const AudioEncoder::EncodedInfo& info);
ossu10a029e2016-03-01 00:41:31 -080067
68 // Shorthand version of the constructor above, for when only setting
69 // encoded_bytes in the EncodedInfo object matters.
ossu264087f2016-04-18 08:07:24 -070070 explicit FakeEncoding(size_t encoded_bytes);
ossu10a029e2016-03-01 00:41:31 -080071
72 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
73 rtc::ArrayView<const int16_t> audio,
74 rtc::Buffer* encoded);
75
76 private:
77 AudioEncoder::EncodedInfo info_;
78 };
79
80 class CopyEncoding {
81 public:
ossueb1fde42017-05-02 06:46:30 -070082 ~CopyEncoding();
83
ossu10a029e2016-03-01 00:41:31 -080084 // Creates a functor that will return |info| and append the data in the
85 // payload to the buffer given as input to it. Up to info.encoded_bytes are
86 // appended - make sure the payload is big enough! Since it uses an
87 // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out
88 // of scope!
89 CopyEncoding(AudioEncoder::EncodedInfo info,
90 rtc::ArrayView<const uint8_t> payload);
91
92 // Shorthand version of the constructor above, for when you wish to append
93 // the whole payload and do not care about any EncodedInfo attribute other
94 // than encoded_bytes.
ossu264087f2016-04-18 08:07:24 -070095 explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload);
ossu10a029e2016-03-01 00:41:31 -080096
97 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
98 rtc::ArrayView<const int16_t> audio,
99 rtc::Buffer* encoded);
ossu264087f2016-04-18 08:07:24 -0700100
ossu10a029e2016-03-01 00:41:31 -0800101 private:
102 AudioEncoder::EncodedInfo info_;
103 rtc::ArrayView<const uint8_t> payload_;
104 };
ossu10a029e2016-03-01 00:41:31 -0800105};
106
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08 +0000107} // namespace webrtc
108
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200109#endif // TEST_MOCK_AUDIO_ENCODER_H_