henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 +0000 | [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 06:47:31 +0200 | [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 +0000 | [diff] [blame] | 13 | |
ossu | 264087f | 2016-04-18 08:07:24 -0700 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [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 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
ossu | 2903ba5 | 2016-04-18 06:14:33 -0700 | [diff] [blame] | 22 | class MockAudioEncoder : public AudioEncoder { |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 +0000 | [diff] [blame] | 23 | public: |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 24 | // 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. |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 28 | MockAudioEncoder(); |
| 29 | ~MockAudioEncoder(); |
kwiberg | 9b66d3b | 2015-09-10 05:09:45 -0700 | [diff] [blame] | 30 | MOCK_METHOD1(Mark, void(std::string desc)); |
kwiberg@webrtc.org | 0521127 | 2015-02-18 12:00:32 +0000 | [diff] [blame] | 31 | MOCK_CONST_METHOD0(SampleRateHz, int()); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 32 | MOCK_CONST_METHOD0(NumChannels, size_t()); |
kwiberg | 12cfc9b | 2015-09-08 05:57:53 -0700 | [diff] [blame] | 33 | MOCK_CONST_METHOD0(RtpTimestampRateHz, int()); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 34 | MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t()); |
| 35 | MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t()); |
Henrik Lundin | 3e89dbf | 2015-06-18 14:58:34 +0200 | [diff] [blame] | 36 | MOCK_CONST_METHOD0(GetTargetBitrate, int()); |
Karl Wiberg | 7e0c7d4 | 2015-05-18 14:52:29 +0200 | [diff] [blame] | 37 | MOCK_METHOD0(Reset, void()); |
| 38 | MOCK_METHOD1(SetFec, bool(bool enable)); |
| 39 | MOCK_METHOD1(SetDtx, bool(bool enable)); |
| 40 | MOCK_METHOD1(SetApplication, bool(Application application)); |
kwiberg | 3f5f1c2 | 2015-09-08 23:15:33 -0700 | [diff] [blame] | 41 | MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz)); |
kwiberg | 12cfc9b | 2015-09-08 05:57:53 -0700 | [diff] [blame] | 42 | MOCK_METHOD1(SetMaxBitrate, void(int max_bps)); |
| 43 | MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes)); |
michaelt | 566d820 | 2017-01-12 10:17:38 -0800 | [diff] [blame] | 44 | MOCK_METHOD2(OnReceivedUplinkBandwidth, |
| 45 | void(int target_audio_bitrate_bps, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 46 | absl::optional<int64_t> probing_interval_ms)); |
minyue | 4b9a2cb | 2016-11-30 06:49:59 -0800 | [diff] [blame] | 47 | MOCK_METHOD1(OnReceivedUplinkPacketLossFraction, |
| 48 | void(float uplink_packet_loss_fraction)); |
Karl Wiberg | 7e0c7d4 | 2015-05-18 14:52:29 +0200 | [diff] [blame] | 49 | |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 50 | MOCK_METHOD2(EnableAudioNetworkAdaptor, |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 51 | bool(const std::string& config_string, RtcEventLog* event_log)); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 52 | |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 53 | // Note, we explicitly chose not to create a mock for the Encode method. |
ossu | 4f43fcf | 2016-03-04 00:54:32 -0800 | [diff] [blame] | 54 | MOCK_METHOD3(EncodeImpl, |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 55 | EncodedInfo(uint32_t timestamp, |
| 56 | rtc::ArrayView<const int16_t> audio, |
| 57 | rtc::Buffer* encoded)); |
| 58 | |
| 59 | class FakeEncoding { |
| 60 | public: |
| 61 | // Creates a functor that will return |info| and adjust the rtc::Buffer |
| 62 | // given as input to it, so it is info.encoded_bytes larger. |
ossu | 264087f | 2016-04-18 08:07:24 -0700 | [diff] [blame] | 63 | explicit FakeEncoding(const AudioEncoder::EncodedInfo& info); |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 64 | |
| 65 | // Shorthand version of the constructor above, for when only setting |
| 66 | // encoded_bytes in the EncodedInfo object matters. |
ossu | 264087f | 2016-04-18 08:07:24 -0700 | [diff] [blame] | 67 | explicit FakeEncoding(size_t encoded_bytes); |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 68 | |
| 69 | AudioEncoder::EncodedInfo operator()(uint32_t timestamp, |
| 70 | rtc::ArrayView<const int16_t> audio, |
| 71 | rtc::Buffer* encoded); |
| 72 | |
| 73 | private: |
| 74 | AudioEncoder::EncodedInfo info_; |
| 75 | }; |
| 76 | |
| 77 | class CopyEncoding { |
| 78 | public: |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 79 | ~CopyEncoding(); |
| 80 | |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 81 | // Creates a functor that will return |info| and append the data in the |
| 82 | // payload to the buffer given as input to it. Up to info.encoded_bytes are |
| 83 | // appended - make sure the payload is big enough! Since it uses an |
| 84 | // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out |
| 85 | // of scope! |
| 86 | CopyEncoding(AudioEncoder::EncodedInfo info, |
| 87 | rtc::ArrayView<const uint8_t> payload); |
| 88 | |
| 89 | // Shorthand version of the constructor above, for when you wish to append |
| 90 | // the whole payload and do not care about any EncodedInfo attribute other |
| 91 | // than encoded_bytes. |
ossu | 264087f | 2016-04-18 08:07:24 -0700 | [diff] [blame] | 92 | explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload); |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 93 | |
| 94 | AudioEncoder::EncodedInfo operator()(uint32_t timestamp, |
| 95 | rtc::ArrayView<const int16_t> audio, |
| 96 | rtc::Buffer* encoded); |
ossu | 264087f | 2016-04-18 08:07:24 -0700 | [diff] [blame] | 97 | |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 98 | private: |
| 99 | AudioEncoder::EncodedInfo info_; |
| 100 | rtc::ArrayView<const uint8_t> payload_; |
| 101 | }; |
ossu | 10a029e | 2016-03-01 00:41:31 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
henrik.lundin@webrtc.org | ff1a3e3 | 2014-12-10 07:29:08 +0000 | [diff] [blame] | 104 | } // namespace webrtc |
| 105 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 106 | #endif // TEST_MOCK_AUDIO_ENCODER_H_ |