TestStereo.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2012 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_TESTSTEREO_H_
  11. #define MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_
  12. #include <math.h>
  13. #include <memory>
  14. #include "modules/audio_coding/include/audio_coding_module.h"
  15. #include "modules/audio_coding/test/PCMFile.h"
  16. #define PCMA_AND_PCMU
  17. namespace webrtc {
  18. enum StereoMonoMode { kNotSet, kMono, kStereo };
  19. class TestPackStereo : public AudioPacketizationCallback {
  20. public:
  21. TestPackStereo();
  22. ~TestPackStereo();
  23. void RegisterReceiverACM(AudioCodingModule* acm);
  24. int32_t SendData(const AudioFrameType frame_type,
  25. const uint8_t payload_type,
  26. const uint32_t timestamp,
  27. const uint8_t* payload_data,
  28. const size_t payload_size,
  29. int64_t absolute_capture_timestamp_ms) override;
  30. uint16_t payload_size();
  31. uint32_t timestamp_diff();
  32. void reset_payload_size();
  33. void set_codec_mode(StereoMonoMode mode);
  34. void set_lost_packet(bool lost);
  35. private:
  36. AudioCodingModule* receiver_acm_;
  37. int16_t seq_no_;
  38. uint32_t timestamp_diff_;
  39. uint32_t last_in_timestamp_;
  40. uint64_t total_bytes_;
  41. int payload_size_;
  42. StereoMonoMode codec_mode_;
  43. // Simulate packet losses
  44. bool lost_packet_;
  45. };
  46. class TestStereo {
  47. public:
  48. TestStereo();
  49. ~TestStereo();
  50. void Perform();
  51. private:
  52. // The default value of '-1' indicates that the registration is based only on
  53. // codec name and a sampling frequncy matching is not required. This is useful
  54. // for codecs which support several sampling frequency.
  55. void RegisterSendCodec(char side,
  56. char* codec_name,
  57. int32_t samp_freq_hz,
  58. int rate,
  59. int pack_size,
  60. int channels);
  61. void Run(TestPackStereo* channel,
  62. int in_channels,
  63. int out_channels,
  64. int percent_loss = 0);
  65. void OpenOutFile(int16_t test_number);
  66. std::unique_ptr<AudioCodingModule> acm_a_;
  67. std::unique_ptr<AudioCodingModule> acm_b_;
  68. TestPackStereo* channel_a2b_;
  69. PCMFile* in_file_stereo_;
  70. PCMFile* in_file_mono_;
  71. PCMFile out_file_;
  72. int16_t test_cntr_;
  73. uint16_t pack_size_samp_;
  74. uint16_t pack_size_bytes_;
  75. int counter_;
  76. char* send_codec_name_;
  77. };
  78. } // namespace webrtc
  79. #endif // MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_