acm_receive_test.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_
  11. #define MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_
  12. #include <stddef.h> // for size_t
  13. #include <memory>
  14. #include <string>
  15. #include "api/audio_codecs/audio_decoder_factory.h"
  16. #include "api/scoped_refptr.h"
  17. #include "rtc_base/constructor_magic.h"
  18. #include "system_wrappers/include/clock.h"
  19. namespace webrtc {
  20. class AudioCodingModule;
  21. class AudioDecoder;
  22. namespace test {
  23. class AudioSink;
  24. class PacketSource;
  25. class AcmReceiveTestOldApi {
  26. public:
  27. enum NumOutputChannels : size_t {
  28. kArbitraryChannels = 0,
  29. kMonoOutput = 1,
  30. kStereoOutput = 2,
  31. kQuadOutput = 4
  32. };
  33. AcmReceiveTestOldApi(PacketSource* packet_source,
  34. AudioSink* audio_sink,
  35. int output_freq_hz,
  36. NumOutputChannels exptected_output_channels,
  37. rtc::scoped_refptr<AudioDecoderFactory> decoder_factory);
  38. virtual ~AcmReceiveTestOldApi();
  39. // Registers the codecs with default parameters from ACM.
  40. void RegisterDefaultCodecs();
  41. // Registers codecs with payload types matching the pre-encoded NetEq test
  42. // files.
  43. void RegisterNetEqTestCodecs();
  44. // Runs the test and returns true if successful.
  45. void Run();
  46. AudioCodingModule* get_acm() { return acm_.get(); }
  47. protected:
  48. // Method is called after each block of output audio is received from ACM.
  49. virtual void AfterGetAudio() {}
  50. SimulatedClock clock_;
  51. std::unique_ptr<AudioCodingModule> acm_;
  52. PacketSource* packet_source_;
  53. AudioSink* audio_sink_;
  54. int output_freq_hz_;
  55. NumOutputChannels exptected_output_channels_;
  56. RTC_DISALLOW_COPY_AND_ASSIGN(AcmReceiveTestOldApi);
  57. };
  58. // This test toggles the output frequency every |toggle_period_ms|. The test
  59. // starts with |output_freq_hz_1|. Except for the toggling, it does the same
  60. // thing as AcmReceiveTestOldApi.
  61. class AcmReceiveTestToggleOutputFreqOldApi : public AcmReceiveTestOldApi {
  62. public:
  63. AcmReceiveTestToggleOutputFreqOldApi(
  64. PacketSource* packet_source,
  65. AudioSink* audio_sink,
  66. int output_freq_hz_1,
  67. int output_freq_hz_2,
  68. int toggle_period_ms,
  69. NumOutputChannels exptected_output_channels);
  70. protected:
  71. void AfterGetAudio() override;
  72. const int output_freq_hz_1_;
  73. const int output_freq_hz_2_;
  74. const int toggle_period_ms_;
  75. int64_t last_toggle_time_ms_;
  76. };
  77. } // namespace test
  78. } // namespace webrtc
  79. #endif // MODULES_AUDIO_CODING_ACM2_ACM_RECEIVE_TEST_H_