blob: 90e2b9ded8cf21aac2a7a36b97ba80cb13114877 [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
ossueb1fde42017-05-02 13:46:3011#ifndef WEBRTC_TEST_MOCK_AUDIO_ENCODER_H_
12#define WEBRTC_TEST_MOCK_AUDIO_ENCODER_H_
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:0813
ossu264087f2016-04-18 15:07:2414#include <string>
15
ossueb1fde42017-05-02 13:46:3016#include "webrtc/api/audio_codecs/audio_encoder.h"
Edward Lemurc20978e2017-07-06 17:44:3417#include "webrtc/rtc_base/array_view.h"
kwiberg77eab702016-09-29 00:42:0118#include "webrtc/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:
nisseef8b61e2016-04-29 13:09:1524 // 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 13:46:3028 MockAudioEncoder();
29 ~MockAudioEncoder();
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:0830 MOCK_METHOD0(Die, void());
kwiberg9b66d3b2015-09-10 12:09:4531 MOCK_METHOD1(Mark, void(std::string desc));
kwiberg@webrtc.org05211272015-02-18 12:00:3232 MOCK_CONST_METHOD0(SampleRateHz, int());
Peter Kasting69558702016-01-13 00:26:3533 MOCK_CONST_METHOD0(NumChannels, size_t());
kwiberg12cfc9b2015-09-08 12:57:5334 MOCK_CONST_METHOD0(RtpTimestampRateHz, int());
Peter Kastingdce40cf2015-08-24 21:52:2335 MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t());
36 MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t());
Henrik Lundin3e89dbf2015-06-18 12:58:3437 MOCK_CONST_METHOD0(GetTargetBitrate, int());
Karl Wiberg7e0c7d42015-05-18 12:52:2938 MOCK_METHOD0(Reset, void());
39 MOCK_METHOD1(SetFec, bool(bool enable));
40 MOCK_METHOD1(SetDtx, bool(bool enable));
41 MOCK_METHOD1(SetApplication, bool(Application application));
kwiberg3f5f1c22015-09-09 06:15:3342 MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz));
kwiberg12cfc9b2015-09-08 12:57:5343 MOCK_METHOD1(SetMaxBitrate, void(int max_bps));
44 MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes));
michaelt566d8202017-01-12 18:17:3845 MOCK_METHOD2(OnReceivedUplinkBandwidth,
46 void(int target_audio_bitrate_bps,
47 rtc::Optional<int64_t> probing_interval_ms));
minyue4b9a2cb2016-11-30 14:49:5948 MOCK_METHOD1(OnReceivedUplinkPacketLossFraction,
49 void(float uplink_packet_loss_fraction));
Karl Wiberg7e0c7d42015-05-18 12:52:2950
ossu20a4b3f2017-04-27 09:08:5251 MOCK_METHOD2(EnableAudioNetworkAdaptor,
ossueb1fde42017-05-02 13:46:3052 bool(const std::string& config_string, RtcEventLog* event_log));
ossu20a4b3f2017-04-27 09:08:5253
ossu10a029e2016-03-01 08:41:3154 // Note, we explicitly chose not to create a mock for the Encode method.
ossu4f43fcf2016-03-04 08:54:3255 MOCK_METHOD3(EncodeImpl,
ossu10a029e2016-03-01 08:41:3156 EncodedInfo(uint32_t timestamp,
57 rtc::ArrayView<const int16_t> audio,
58 rtc::Buffer* encoded));
59
60 class FakeEncoding {
61 public:
62 // Creates a functor that will return |info| and adjust the rtc::Buffer
63 // given as input to it, so it is info.encoded_bytes larger.
ossu264087f2016-04-18 15:07:2464 explicit FakeEncoding(const AudioEncoder::EncodedInfo& info);
ossu10a029e2016-03-01 08:41:3165
66 // Shorthand version of the constructor above, for when only setting
67 // encoded_bytes in the EncodedInfo object matters.
ossu264087f2016-04-18 15:07:2468 explicit FakeEncoding(size_t encoded_bytes);
ossu10a029e2016-03-01 08:41:3169
70 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
71 rtc::ArrayView<const int16_t> audio,
72 rtc::Buffer* encoded);
73
74 private:
75 AudioEncoder::EncodedInfo info_;
76 };
77
78 class CopyEncoding {
79 public:
ossueb1fde42017-05-02 13:46:3080 ~CopyEncoding();
81
ossu10a029e2016-03-01 08:41:3182 // Creates a functor that will return |info| and append the data in the
83 // payload to the buffer given as input to it. Up to info.encoded_bytes are
84 // appended - make sure the payload is big enough! Since it uses an
85 // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out
86 // of scope!
87 CopyEncoding(AudioEncoder::EncodedInfo info,
88 rtc::ArrayView<const uint8_t> payload);
89
90 // Shorthand version of the constructor above, for when you wish to append
91 // the whole payload and do not care about any EncodedInfo attribute other
92 // than encoded_bytes.
ossu264087f2016-04-18 15:07:2493 explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload);
ossu10a029e2016-03-01 08:41:3194
95 AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
96 rtc::ArrayView<const int16_t> audio,
97 rtc::Buffer* encoded);
ossu264087f2016-04-18 15:07:2498
ossu10a029e2016-03-01 08:41:3199 private:
100 AudioEncoder::EncodedInfo info_;
101 rtc::ArrayView<const uint8_t> payload_;
102 };
ossu10a029e2016-03-01 08:41:31103};
104
henrik.lundin@webrtc.orgff1a3e32014-12-10 07:29:08105} // namespace webrtc
106
ossueb1fde42017-05-02 13:46:30107#endif // WEBRTC_TEST_MOCK_AUDIO_ENCODER_H_