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.

103 lines
3.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2011 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_TEST_TESTVADDTX_H_
  11. #define MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_
  12. #include <memory>
  13. #include "api/audio_codecs/audio_decoder_factory.h"
  14. #include "api/audio_codecs/audio_encoder_factory.h"
  15. #include "common_audio/vad/include/vad.h"
  16. #include "modules/audio_coding/include/audio_coding_module.h"
  17. #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
  18. #include "modules/audio_coding/test/Channel.h"
  19. namespace webrtc {
  20. class ActivityMonitor : public ACMVADCallback {
  21. public:
  22. ActivityMonitor();
  23. int32_t InFrameType(AudioFrameType frame_type);
  24. void PrintStatistics();
  25. void ResetStatistics();
  26. void GetStatistics(uint32_t* stats);
  27. private:
  28. // 0 - kEmptyFrame
  29. // 1 - kAudioFrameSpeech
  30. // 2 - kAudioFrameCN
  31. uint32_t counter_[3];
  32. };
  33. // TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
  34. // an audio file and check if the occurrence of various packet types follows
  35. // expectation. TestVadDtx needs its derived class to implement the Perform()
  36. // to put the test together.
  37. class TestVadDtx {
  38. public:
  39. static const int kOutputFreqHz = 16000;
  40. TestVadDtx();
  41. protected:
  42. // Returns true iff CN was added.
  43. bool RegisterCodec(const SdpAudioFormat& codec_format,
  44. absl::optional<Vad::Aggressiveness> vad_mode);
  45. // Encoding a file and see if the numbers that various packets occur follow
  46. // the expectation. Saves result to a file.
  47. // expects[x] means
  48. // -1 : do not care,
  49. // 0 : there have been no packets of type |x|,
  50. // 1 : there have been packets of type |x|,
  51. // with |x| indicates the following packet types
  52. // 0 - kEmptyFrame
  53. // 1 - kAudioFrameSpeech
  54. // 2 - kAudioFrameCN
  55. void Run(std::string in_filename,
  56. int frequency,
  57. int channels,
  58. std::string out_filename,
  59. bool append,
  60. const int* expects);
  61. const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
  62. const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
  63. std::unique_ptr<AudioCodingModule> acm_send_;
  64. std::unique_ptr<AudioCodingModule> acm_receive_;
  65. std::unique_ptr<Channel> channel_;
  66. std::unique_ptr<ActivityMonitor> monitor_;
  67. uint32_t time_stamp_ = 0x12345678;
  68. };
  69. // TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.
  70. class TestWebRtcVadDtx final : public TestVadDtx {
  71. public:
  72. TestWebRtcVadDtx();
  73. void Perform();
  74. private:
  75. void RunTestCases(const SdpAudioFormat& codec_format);
  76. void Test(bool new_outfile, bool expect_dtx_enabled);
  77. int output_file_num_;
  78. };
  79. // TestOpusDtx is to verify that the Opus DTX performs as it should.
  80. class TestOpusDtx final : public TestVadDtx {
  81. public:
  82. void Perform();
  83. };
  84. } // namespace webrtc
  85. #endif // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_