OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ | 11 #ifndef WEBRTC_TEST_MOCK_AUDIO_ENCODER_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ | 12 #define WEBRTC_TEST_MOCK_AUDIO_ENCODER_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
| 16 #include "webrtc/api/audio_codecs/audio_encoder.h" |
16 #include "webrtc/base/array_view.h" | 17 #include "webrtc/base/array_view.h" |
17 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | |
18 #include "webrtc/test/gmock.h" | 18 #include "webrtc/test/gmock.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 class MockAudioEncoder : public AudioEncoder { | 22 class MockAudioEncoder : public AudioEncoder { |
23 public: | 23 public: |
24 // TODO(nisse): Valid overrides commented out, because the gmock | 24 // TODO(nisse): Valid overrides commented out, because the gmock |
25 // methods don't use any override declarations, and we want to avoid | 25 // methods don't use any override declarations, and we want to avoid |
26 // warnings from -Winconsistent-missing-override. See | 26 // warnings from -Winconsistent-missing-override. See |
27 // http://crbug.com/428099. | 27 // http://crbug.com/428099. |
28 ~MockAudioEncoder() /* override */ { Die(); } | 28 MockAudioEncoder(); |
| 29 ~MockAudioEncoder(); |
29 MOCK_METHOD0(Die, void()); | 30 MOCK_METHOD0(Die, void()); |
30 MOCK_METHOD1(Mark, void(std::string desc)); | 31 MOCK_METHOD1(Mark, void(std::string desc)); |
31 MOCK_CONST_METHOD0(SampleRateHz, int()); | 32 MOCK_CONST_METHOD0(SampleRateHz, int()); |
32 MOCK_CONST_METHOD0(NumChannels, size_t()); | 33 MOCK_CONST_METHOD0(NumChannels, size_t()); |
33 MOCK_CONST_METHOD0(RtpTimestampRateHz, int()); | 34 MOCK_CONST_METHOD0(RtpTimestampRateHz, int()); |
34 MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t()); | 35 MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t()); |
35 MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t()); | 36 MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t()); |
36 MOCK_CONST_METHOD0(GetTargetBitrate, int()); | 37 MOCK_CONST_METHOD0(GetTargetBitrate, int()); |
37 MOCK_METHOD0(Reset, void()); | 38 MOCK_METHOD0(Reset, void()); |
38 MOCK_METHOD1(SetFec, bool(bool enable)); | 39 MOCK_METHOD1(SetFec, bool(bool enable)); |
39 MOCK_METHOD1(SetDtx, bool(bool enable)); | 40 MOCK_METHOD1(SetDtx, bool(bool enable)); |
40 MOCK_METHOD1(SetApplication, bool(Application application)); | 41 MOCK_METHOD1(SetApplication, bool(Application application)); |
41 MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz)); | 42 MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz)); |
42 MOCK_METHOD1(SetMaxBitrate, void(int max_bps)); | 43 MOCK_METHOD1(SetMaxBitrate, void(int max_bps)); |
43 MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes)); | 44 MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes)); |
44 MOCK_METHOD2(OnReceivedUplinkBandwidth, | 45 MOCK_METHOD2(OnReceivedUplinkBandwidth, |
45 void(int target_audio_bitrate_bps, | 46 void(int target_audio_bitrate_bps, |
46 rtc::Optional<int64_t> probing_interval_ms)); | 47 rtc::Optional<int64_t> probing_interval_ms)); |
47 MOCK_METHOD1(OnReceivedUplinkPacketLossFraction, | 48 MOCK_METHOD1(OnReceivedUplinkPacketLossFraction, |
48 void(float uplink_packet_loss_fraction)); | 49 void(float uplink_packet_loss_fraction)); |
49 | 50 |
50 MOCK_METHOD2(EnableAudioNetworkAdaptor, | 51 MOCK_METHOD2(EnableAudioNetworkAdaptor, |
51 bool(const std::string& config_string, | 52 bool(const std::string& config_string, RtcEventLog* event_log)); |
52 RtcEventLog* event_log)); | |
53 | 53 |
54 // Note, we explicitly chose not to create a mock for the Encode method. | 54 // Note, we explicitly chose not to create a mock for the Encode method. |
55 MOCK_METHOD3(EncodeImpl, | 55 MOCK_METHOD3(EncodeImpl, |
56 EncodedInfo(uint32_t timestamp, | 56 EncodedInfo(uint32_t timestamp, |
57 rtc::ArrayView<const int16_t> audio, | 57 rtc::ArrayView<const int16_t> audio, |
58 rtc::Buffer* encoded)); | 58 rtc::Buffer* encoded)); |
59 | 59 |
60 class FakeEncoding { | 60 class FakeEncoding { |
61 public: | 61 public: |
62 // Creates a functor that will return |info| and adjust the rtc::Buffer | 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. | 63 // given as input to it, so it is info.encoded_bytes larger. |
64 explicit FakeEncoding(const AudioEncoder::EncodedInfo& info); | 64 explicit FakeEncoding(const AudioEncoder::EncodedInfo& info); |
65 | 65 |
66 // Shorthand version of the constructor above, for when only setting | 66 // Shorthand version of the constructor above, for when only setting |
67 // encoded_bytes in the EncodedInfo object matters. | 67 // encoded_bytes in the EncodedInfo object matters. |
68 explicit FakeEncoding(size_t encoded_bytes); | 68 explicit FakeEncoding(size_t encoded_bytes); |
69 | 69 |
70 AudioEncoder::EncodedInfo operator()(uint32_t timestamp, | 70 AudioEncoder::EncodedInfo operator()(uint32_t timestamp, |
71 rtc::ArrayView<const int16_t> audio, | 71 rtc::ArrayView<const int16_t> audio, |
72 rtc::Buffer* encoded); | 72 rtc::Buffer* encoded); |
73 | 73 |
74 private: | 74 private: |
75 AudioEncoder::EncodedInfo info_; | 75 AudioEncoder::EncodedInfo info_; |
76 }; | 76 }; |
77 | 77 |
78 class CopyEncoding { | 78 class CopyEncoding { |
79 public: | 79 public: |
| 80 ~CopyEncoding(); |
| 81 |
80 // Creates a functor that will return |info| and append the data in the | 82 // Creates a functor that will return |info| and append the data in the |
81 // payload to the buffer given as input to it. Up to info.encoded_bytes are | 83 // payload to the buffer given as input to it. Up to info.encoded_bytes are |
82 // appended - make sure the payload is big enough! Since it uses an | 84 // appended - make sure the payload is big enough! Since it uses an |
83 // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out | 85 // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out |
84 // of scope! | 86 // of scope! |
85 CopyEncoding(AudioEncoder::EncodedInfo info, | 87 CopyEncoding(AudioEncoder::EncodedInfo info, |
86 rtc::ArrayView<const uint8_t> payload); | 88 rtc::ArrayView<const uint8_t> payload); |
87 | 89 |
88 // Shorthand version of the constructor above, for when you wish to append | 90 // Shorthand version of the constructor above, for when you wish to append |
89 // the whole payload and do not care about any EncodedInfo attribute other | 91 // the whole payload and do not care about any EncodedInfo attribute other |
90 // than encoded_bytes. | 92 // than encoded_bytes. |
91 explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload); | 93 explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload); |
92 | 94 |
93 AudioEncoder::EncodedInfo operator()(uint32_t timestamp, | 95 AudioEncoder::EncodedInfo operator()(uint32_t timestamp, |
94 rtc::ArrayView<const int16_t> audio, | 96 rtc::ArrayView<const int16_t> audio, |
95 rtc::Buffer* encoded); | 97 rtc::Buffer* encoded); |
96 | 98 |
97 private: | 99 private: |
98 AudioEncoder::EncodedInfo info_; | 100 AudioEncoder::EncodedInfo info_; |
99 rtc::ArrayView<const uint8_t> payload_; | 101 rtc::ArrayView<const uint8_t> payload_; |
100 }; | 102 }; |
101 }; | 103 }; |
102 | 104 |
103 } // namespace webrtc | 105 } // namespace webrtc |
104 | 106 |
105 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ | 107 #endif // WEBRTC_TEST_MOCK_AUDIO_ENCODER_H_ |
OLD | NEW |