henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef TEST_MOCK_AUDIO_ENCODER_H_ |
| 12 | #define TEST_MOCK_AUDIO_ENCODER_H_ |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 | [diff] [blame] | 13 | |
ossu | 264087f | 2016-04-18 15:07:24 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "api/array_view.h" |
| 17 | #include "api/audio_codecs/audio_encoder.h" |
| 18 | #include "test/gmock.h" |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
ossu | 2903ba5 | 2016-04-18 13:14:33 | [diff] [blame] | 22 | class MockAudioEncoder : public AudioEncoder { |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 | [diff] [blame] | 23 | public: |
ossu | eb1fde4 | 2017-05-02 13:46:30 | [diff] [blame] | 24 | MockAudioEncoder(); |
| 25 | ~MockAudioEncoder(); |
Danil Chapovalov | 54706d6 | 2020-05-14 17:50:01 | [diff] [blame] | 26 | 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 Jansson | 62aee93 | 2019-10-02 10:27:06 | [diff] [blame] | 36 | |
Danil Chapovalov | 54706d6 | 2020-05-14 17:50:01 | [diff] [blame] | 37 | 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 Ivarsson | fde2b24 | 2020-08-20 14:48:49 | [diff] [blame] | 51 | MOCK_METHOD(void, |
| 52 | OnReceivedOverhead, |
| 53 | (size_t overhead_bytes_per_packet), |
| 54 | (override)); |
Karl Wiberg | 7e0c7d4 | 2015-05-18 12:52:29 | [diff] [blame] | 55 | |
Danil Chapovalov | 54706d6 | 2020-05-14 17:50:01 | [diff] [blame] | 56 | MOCK_METHOD(bool, |
| 57 | EnableAudioNetworkAdaptor, |
| 58 | (const std::string& config_string, RtcEventLog*), |
| 59 | (override)); |
ossu | 20a4b3f | 2017-04-27 09:08:52 | [diff] [blame] | 60 | |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 61 | // Note, we explicitly chose not to create a mock for the Encode method. |
Danil Chapovalov | 54706d6 | 2020-05-14 17:50:01 | [diff] [blame] | 62 | MOCK_METHOD(EncodedInfo, |
| 63 | EncodeImpl, |
| 64 | (uint32_t timestamp, |
| 65 | rtc::ArrayView<const int16_t> audio, |
| 66 | rtc::Buffer*), |
| 67 | (override)); |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 68 | |
| 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. |
ossu | 264087f | 2016-04-18 15:07:24 | [diff] [blame] | 73 | explicit FakeEncoding(const AudioEncoder::EncodedInfo& info); |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 74 | |
| 75 | // Shorthand version of the constructor above, for when only setting |
| 76 | // encoded_bytes in the EncodedInfo object matters. |
ossu | 264087f | 2016-04-18 15:07:24 | [diff] [blame] | 77 | explicit FakeEncoding(size_t encoded_bytes); |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 78 | |
| 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: |
ossu | eb1fde4 | 2017-05-02 13:46:30 | [diff] [blame] | 89 | ~CopyEncoding(); |
| 90 | |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 91 | // 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. |
ossu | 264087f | 2016-04-18 15:07:24 | [diff] [blame] | 102 | explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload); |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 103 | |
| 104 | AudioEncoder::EncodedInfo operator()(uint32_t timestamp, |
| 105 | rtc::ArrayView<const int16_t> audio, |
| 106 | rtc::Buffer* encoded); |
ossu | 264087f | 2016-04-18 15:07:24 | [diff] [blame] | 107 | |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 108 | private: |
| 109 | AudioEncoder::EncodedInfo info_; |
| 110 | rtc::ArrayView<const uint8_t> payload_; |
| 111 | }; |
ossu | 10a029e | 2016-03-01 08:41:31 | [diff] [blame] | 112 | }; |
| 113 | |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 | [diff] [blame] | 114 | } // namespace webrtc |
| 115 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 116 | #endif // TEST_MOCK_AUDIO_ENCODER_H_ |