mock_audio_encoder.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef TEST_MOCK_AUDIO_ENCODER_H_
  11. #define TEST_MOCK_AUDIO_ENCODER_H_
  12. #include <string>
  13. #include "api/array_view.h"
  14. #include "api/audio_codecs/audio_encoder.h"
  15. #include "test/gmock.h"
  16. namespace webrtc {
  17. class MockAudioEncoder : public AudioEncoder {
  18. public:
  19. MockAudioEncoder();
  20. ~MockAudioEncoder();
  21. MOCK_METHOD(int, SampleRateHz, (), (const, override));
  22. MOCK_METHOD(size_t, NumChannels, (), (const, override));
  23. MOCK_METHOD(int, RtpTimestampRateHz, (), (const, override));
  24. MOCK_METHOD(size_t, Num10MsFramesInNextPacket, (), (const, override));
  25. MOCK_METHOD(size_t, Max10MsFramesInAPacket, (), (const, override));
  26. MOCK_METHOD(int, GetTargetBitrate, (), (const, override));
  27. MOCK_METHOD((absl::optional<std::pair<TimeDelta, TimeDelta>>),
  28. GetFrameLengthRange,
  29. (),
  30. (const, override));
  31. MOCK_METHOD(void, Reset, (), (override));
  32. MOCK_METHOD(bool, SetFec, (bool enable), (override));
  33. MOCK_METHOD(bool, SetDtx, (bool enable), (override));
  34. MOCK_METHOD(bool, SetApplication, (Application application), (override));
  35. MOCK_METHOD(void, SetMaxPlaybackRate, (int frequency_hz), (override));
  36. MOCK_METHOD(void,
  37. OnReceivedUplinkBandwidth,
  38. (int target_audio_bitrate_bps,
  39. absl::optional<int64_t> probing_interval_ms),
  40. (override));
  41. MOCK_METHOD(void,
  42. OnReceivedUplinkPacketLossFraction,
  43. (float uplink_packet_loss_fraction),
  44. (override));
  45. MOCK_METHOD(void,
  46. OnReceivedOverhead,
  47. (size_t overhead_bytes_per_packet),
  48. (override));
  49. MOCK_METHOD(bool,
  50. EnableAudioNetworkAdaptor,
  51. (const std::string& config_string, RtcEventLog*),
  52. (override));
  53. // Note, we explicitly chose not to create a mock for the Encode method.
  54. MOCK_METHOD(EncodedInfo,
  55. EncodeImpl,
  56. (uint32_t timestamp,
  57. rtc::ArrayView<const int16_t> audio,
  58. rtc::Buffer*),
  59. (override));
  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.
  64. explicit FakeEncoding(const AudioEncoder::EncodedInfo& info);
  65. // Shorthand version of the constructor above, for when only setting
  66. // encoded_bytes in the EncodedInfo object matters.
  67. explicit FakeEncoding(size_t encoded_bytes);
  68. AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
  69. rtc::ArrayView<const int16_t> audio,
  70. rtc::Buffer* encoded);
  71. private:
  72. AudioEncoder::EncodedInfo info_;
  73. };
  74. class CopyEncoding {
  75. public:
  76. ~CopyEncoding();
  77. // Creates a functor that will return |info| and append the data in the
  78. // payload to the buffer given as input to it. Up to info.encoded_bytes are
  79. // appended - make sure the payload is big enough! Since it uses an
  80. // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out
  81. // of scope!
  82. CopyEncoding(AudioEncoder::EncodedInfo info,
  83. rtc::ArrayView<const uint8_t> payload);
  84. // Shorthand version of the constructor above, for when you wish to append
  85. // the whole payload and do not care about any EncodedInfo attribute other
  86. // than encoded_bytes.
  87. explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload);
  88. AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
  89. rtc::ArrayView<const int16_t> audio,
  90. rtc::Buffer* encoded);
  91. private:
  92. AudioEncoder::EncodedInfo info_;
  93. rtc::ArrayView<const uint8_t> payload_;
  94. };
  95. };
  96. } // namespace webrtc
  97. #endif // TEST_MOCK_AUDIO_ENCODER_H_