Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ |
| 13 | 13 |
| 14 #include "webrtc/base/array_view.h" | |
| 14 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 15 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
| 15 | 16 |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 | 18 |
| 19 #include <functional> | |
| 20 | |
| 18 namespace webrtc { | 21 namespace webrtc { |
| 19 | 22 |
| 20 class MockAudioEncoder final : public AudioEncoder { | 23 class MockAudioEncoderBase : public AudioEncoder { |
| 21 public: | 24 public: |
| 22 ~MockAudioEncoder() override { Die(); } | 25 ~MockAudioEncoderBase() override { Die(); } |
| 23 MOCK_METHOD0(Die, void()); | 26 MOCK_METHOD0(Die, void()); |
| 24 MOCK_METHOD1(Mark, void(std::string desc)); | 27 MOCK_METHOD1(Mark, void(std::string desc)); |
| 25 MOCK_CONST_METHOD0(MaxEncodedBytes, size_t()); | 28 MOCK_CONST_METHOD0(MaxEncodedBytes, size_t()); |
| 26 MOCK_CONST_METHOD0(SampleRateHz, int()); | 29 MOCK_CONST_METHOD0(SampleRateHz, int()); |
| 27 MOCK_CONST_METHOD0(NumChannels, size_t()); | 30 MOCK_CONST_METHOD0(NumChannels, size_t()); |
| 28 MOCK_CONST_METHOD0(RtpTimestampRateHz, int()); | 31 MOCK_CONST_METHOD0(RtpTimestampRateHz, int()); |
| 29 MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t()); | 32 MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t()); |
| 30 MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t()); | 33 MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t()); |
| 31 MOCK_CONST_METHOD0(GetTargetBitrate, int()); | 34 MOCK_CONST_METHOD0(GetTargetBitrate, int()); |
| 32 // Note, we explicitly chose not to create a mock for the Encode method. | |
| 33 MOCK_METHOD4(EncodeInternal, | |
| 34 EncodedInfo(uint32_t timestamp, | |
| 35 rtc::ArrayView<const int16_t> audio, | |
| 36 size_t max_encoded_bytes, | |
| 37 uint8_t* encoded)); | |
| 38 MOCK_METHOD0(Reset, void()); | 35 MOCK_METHOD0(Reset, void()); |
| 39 MOCK_METHOD1(SetFec, bool(bool enable)); | 36 MOCK_METHOD1(SetFec, bool(bool enable)); |
| 40 MOCK_METHOD1(SetDtx, bool(bool enable)); | 37 MOCK_METHOD1(SetDtx, bool(bool enable)); |
| 41 MOCK_METHOD1(SetApplication, bool(Application application)); | 38 MOCK_METHOD1(SetApplication, bool(Application application)); |
| 42 MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz)); | 39 MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz)); |
| 43 MOCK_METHOD1(SetProjectedPacketLossRate, void(double fraction)); | 40 MOCK_METHOD1(SetProjectedPacketLossRate, void(double fraction)); |
| 44 MOCK_METHOD1(SetTargetBitrate, void(int target_bps)); | 41 MOCK_METHOD1(SetTargetBitrate, void(int target_bps)); |
| 45 MOCK_METHOD1(SetMaxBitrate, void(int max_bps)); | 42 MOCK_METHOD1(SetMaxBitrate, void(int max_bps)); |
| 46 MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes)); | 43 MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes)); |
| 47 }; | 44 }; |
| 48 | 45 |
| 46 class MockAudioEncoder final : public MockAudioEncoderBase { | |
| 47 public: | |
| 48 // Note, we explicitly chose not to create a mock for the Encode method. | |
| 49 MOCK_METHOD3(EncodeInternal, | |
| 50 EncodedInfo(uint32_t timestamp, | |
| 51 rtc::ArrayView<const int16_t> audio, | |
| 52 rtc::Buffer* encoded)); | |
| 53 }; | |
| 54 | |
| 55 class MockAudioEncoderDeprecated final : public MockAudioEncoderBase { | |
| 56 public: | |
| 57 // Note, we explicitly chose not to create a mock for the Encode method. | |
| 58 MOCK_METHOD4(EncodeInternal, | |
| 59 EncodedInfo(uint32_t timestamp, | |
| 60 rtc::ArrayView<const int16_t> audio, | |
| 61 size_t max_encoded_bytes, | |
| 62 uint8_t* encoded)); | |
| 63 }; | |
| 64 | |
| 65 // Contains helper functions for mocking AudioEncoder::Encode calls. There are | |
| 66 // checks in place, for example in AudioEncoder::Encode, that ensure the | |
| 67 // rtc::Buffer provided grows as many bytes as the EncodeInternal implementation | |
| 68 // claims it has written. These functions make sure to grow the Buffer | |
| 69 // appropriately. | |
| 70 namespace MockAudioEncoderHelper { | |
|
kwiberg-webrtc
2016/02/27 19:21:46
Why a namespace? And if you do end up having one a
ossu
2016/02/29 08:51:24
Namespace because it's no longer a class. The name
| |
| 71 using EncodeFunction = | |
| 72 std::function<AudioEncoder::EncodedInfo(uint32_t timestamp, | |
|
kwiberg-webrtc
2016/02/27 19:21:46
Bad news: std::function is not yet allowed. https:
ossu
2016/02/29 08:51:24
Awww, daaang. :/
Well, I'll see what I can do. Not
| |
| 73 rtc::ArrayView<const int16_t> audio, | |
| 74 rtc::Buffer* encoded)>; | |
| 75 | |
| 76 using DeprecatedEncodeFunction = | |
| 77 std::function<AudioEncoder::EncodedInfo(uint32_t timestamp, | |
| 78 rtc::ArrayView<const int16_t> audio, | |
| 79 size_t max_bytes_encoded, | |
| 80 uint8_t* encoded)>; | |
| 81 | |
| 82 // Returns a function that will return |info| and adjust the rtc::Buffer | |
| 83 // given as input to it, so it is info.encoded_bytes larger. | |
| 84 EncodeFunction FakeEncoding(AudioEncoder::EncodedInfo info); | |
| 85 | |
| 86 // Shorthand version of the function above, for when only setting encoded_bytes | |
| 87 // in the EncodedInfo object matters. | |
| 88 EncodeFunction FakeEncoding(size_t encoded_bytes); | |
| 89 | |
| 90 // Returns a function that will return |info| and append the data in the payload | |
| 91 // to the buffer given as input to it. Up to info.encoded_bytes are appended - | |
| 92 // make sure the payload is big enough! | |
| 93 // Since it uses an ArrayView, it _does not_ copy the payload. Make sure it | |
| 94 // doesn't fall out of scope! | |
| 95 | |
| 96 EncodeFunction CopyEncoding(AudioEncoder::EncodedInfo info, | |
| 97 rtc::ArrayView<const uint8_t> payload); | |
| 98 | |
| 99 // Shorthand version of the function above, for when you wish to append the | |
| 100 // whole payload and do not care about any EncodedInfo attribute other than | |
| 101 // encoded_bytes. | |
| 102 EncodeFunction CopyEncoding(rtc::ArrayView<const uint8_t> payload); | |
| 103 | |
| 104 // Returns a function like CopyEncoding above, but which has the deprecated | |
| 105 // Encode signature. Currently only used in one test and should be removed | |
| 106 // once that backwards compatibility is. | |
| 107 DeprecatedEncodeFunction DEPRECATED_CopyEncoding( | |
| 108 AudioEncoder::EncodedInfo info, | |
| 109 rtc::ArrayView<const uint8_t> payload); | |
| 110 | |
| 111 DeprecatedEncodeFunction DEPRECATED_CopyEncoding( | |
| 112 rtc::ArrayView<const uint8_t> payload); | |
| 113 | |
| 114 } // namespace MockAudioEncoderHelper | |
| 115 | |
| 49 } // namespace webrtc | 116 } // namespace webrtc |
| 50 | 117 |
| 51 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ | 118 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_MOCK_MOCK_AUDIO_ENCODER_H_ |
| OLD | NEW |