You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. // TODO(nisse): Valid overrides commented out, because the gmock
  20. // methods don't use any override declarations, and we want to avoid
  21. // warnings from -Winconsistent-missing-override. See
  22. // http://crbug.com/428099.
  23. MockAudioEncoder();
  24. ~MockAudioEncoder();
  25. MOCK_METHOD1(Mark, void(std::string desc));
  26. MOCK_CONST_METHOD0(SampleRateHz, int());
  27. MOCK_CONST_METHOD0(NumChannels, size_t());
  28. MOCK_CONST_METHOD0(RtpTimestampRateHz, int());
  29. MOCK_CONST_METHOD0(Num10MsFramesInNextPacket, size_t());
  30. MOCK_CONST_METHOD0(Max10MsFramesInAPacket, size_t());
  31. MOCK_CONST_METHOD0(GetTargetBitrate, int());
  32. MOCK_CONST_METHOD0(GetFrameLengthRange,
  33. absl::optional<std::pair<TimeDelta, TimeDelta>>());
  34. MOCK_METHOD0(Reset, void());
  35. MOCK_METHOD1(SetFec, bool(bool enable));
  36. MOCK_METHOD1(SetDtx, bool(bool enable));
  37. MOCK_METHOD1(SetApplication, bool(Application application));
  38. MOCK_METHOD1(SetMaxPlaybackRate, void(int frequency_hz));
  39. MOCK_METHOD1(SetMaxBitrate, void(int max_bps));
  40. MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes));
  41. MOCK_METHOD2(OnReceivedUplinkBandwidth,
  42. void(int target_audio_bitrate_bps,
  43. absl::optional<int64_t> probing_interval_ms));
  44. MOCK_METHOD1(OnReceivedUplinkPacketLossFraction,
  45. void(float uplink_packet_loss_fraction));
  46. MOCK_METHOD2(EnableAudioNetworkAdaptor,
  47. bool(const std::string& config_string, RtcEventLog* event_log));
  48. // Note, we explicitly chose not to create a mock for the Encode method.
  49. MOCK_METHOD3(EncodeImpl,
  50. EncodedInfo(uint32_t timestamp,
  51. rtc::ArrayView<const int16_t> audio,
  52. rtc::Buffer* encoded));
  53. class FakeEncoding {
  54. public:
  55. // Creates a functor that will return |info| and adjust the rtc::Buffer
  56. // given as input to it, so it is info.encoded_bytes larger.
  57. explicit FakeEncoding(const AudioEncoder::EncodedInfo& info);
  58. // Shorthand version of the constructor above, for when only setting
  59. // encoded_bytes in the EncodedInfo object matters.
  60. explicit FakeEncoding(size_t encoded_bytes);
  61. AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
  62. rtc::ArrayView<const int16_t> audio,
  63. rtc::Buffer* encoded);
  64. private:
  65. AudioEncoder::EncodedInfo info_;
  66. };
  67. class CopyEncoding {
  68. public:
  69. ~CopyEncoding();
  70. // Creates a functor that will return |info| and append the data in the
  71. // payload to the buffer given as input to it. Up to info.encoded_bytes are
  72. // appended - make sure the payload is big enough! Since it uses an
  73. // ArrayView, it _does not_ copy the payload. Make sure it doesn't fall out
  74. // of scope!
  75. CopyEncoding(AudioEncoder::EncodedInfo info,
  76. rtc::ArrayView<const uint8_t> payload);
  77. // Shorthand version of the constructor above, for when you wish to append
  78. // the whole payload and do not care about any EncodedInfo attribute other
  79. // than encoded_bytes.
  80. explicit CopyEncoding(rtc::ArrayView<const uint8_t> payload);
  81. AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
  82. rtc::ArrayView<const int16_t> audio,
  83. rtc::Buffer* encoded);
  84. private:
  85. AudioEncoder::EncodedInfo info_;
  86. rtc::ArrayView<const uint8_t> payload_;
  87. };
  88. };
  89. } // namespace webrtc
  90. #endif // TEST_MOCK_AUDIO_ENCODER_H_