TestVADDTX.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // This class records the frame type, and delegates actual sending to the
  21. // |next_| AudioPacketizationCallback.
  22. class MonitoringAudioPacketizationCallback : public AudioPacketizationCallback {
  23. public:
  24. explicit MonitoringAudioPacketizationCallback(
  25. AudioPacketizationCallback* next);
  26. int32_t SendData(AudioFrameType frame_type,
  27. uint8_t payload_type,
  28. uint32_t timestamp,
  29. const uint8_t* payload_data,
  30. size_t payload_len_bytes,
  31. int64_t absolute_capture_timestamp_ms) override;
  32. void PrintStatistics();
  33. void ResetStatistics();
  34. void GetStatistics(uint32_t* stats);
  35. private:
  36. // 0 - kEmptyFrame
  37. // 1 - kAudioFrameSpeech
  38. // 2 - kAudioFrameCN
  39. uint32_t counter_[3];
  40. AudioPacketizationCallback* const next_;
  41. };
  42. // TestVadDtx is to verify that VAD/DTX perform as they should. It runs through
  43. // an audio file and check if the occurrence of various packet types follows
  44. // expectation. TestVadDtx needs its derived class to implement the Perform()
  45. // to put the test together.
  46. class TestVadDtx {
  47. public:
  48. static const int kOutputFreqHz = 16000;
  49. TestVadDtx();
  50. protected:
  51. // Returns true iff CN was added.
  52. bool RegisterCodec(const SdpAudioFormat& codec_format,
  53. absl::optional<Vad::Aggressiveness> vad_mode);
  54. // Encoding a file and see if the numbers that various packets occur follow
  55. // the expectation. Saves result to a file.
  56. // expects[x] means
  57. // -1 : do not care,
  58. // 0 : there have been no packets of type |x|,
  59. // 1 : there have been packets of type |x|,
  60. // with |x| indicates the following packet types
  61. // 0 - kEmptyFrame
  62. // 1 - kAudioFrameSpeech
  63. // 2 - kAudioFrameCN
  64. void Run(std::string in_filename,
  65. int frequency,
  66. int channels,
  67. std::string out_filename,
  68. bool append,
  69. const int* expects);
  70. const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
  71. const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
  72. std::unique_ptr<AudioCodingModule> acm_send_;
  73. std::unique_ptr<AudioCodingModule> acm_receive_;
  74. std::unique_ptr<Channel> channel_;
  75. std::unique_ptr<MonitoringAudioPacketizationCallback> packetization_callback_;
  76. uint32_t time_stamp_ = 0x12345678;
  77. };
  78. // TestWebRtcVadDtx is to verify that the WebRTC VAD/DTX perform as they should.
  79. class TestWebRtcVadDtx final : public TestVadDtx {
  80. public:
  81. TestWebRtcVadDtx();
  82. void Perform();
  83. private:
  84. void RunTestCases(const SdpAudioFormat& codec_format);
  85. void Test(bool new_outfile, bool expect_dtx_enabled);
  86. int output_file_num_;
  87. };
  88. // TestOpusDtx is to verify that the Opus DTX performs as it should.
  89. class TestOpusDtx final : public TestVadDtx {
  90. public:
  91. void Perform();
  92. };
  93. } // namespace webrtc
  94. #endif // MODULES_AUDIO_CODING_TEST_TESTVADDTX_H_