acm_send_test.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_SEND_TEST_H_
  11. #define MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/audio/audio_frame.h"
  15. #include "modules/audio_coding/include/audio_coding_module.h"
  16. #include "modules/audio_coding/neteq/tools/packet_source.h"
  17. #include "rtc_base/constructor_magic.h"
  18. #include "system_wrappers/include/clock.h"
  19. namespace webrtc {
  20. class AudioEncoder;
  21. namespace test {
  22. class InputAudioFile;
  23. class Packet;
  24. class AcmSendTestOldApi : public AudioPacketizationCallback,
  25. public PacketSource {
  26. public:
  27. AcmSendTestOldApi(InputAudioFile* audio_source,
  28. int source_rate_hz,
  29. int test_duration_ms);
  30. ~AcmSendTestOldApi() override;
  31. // Registers the send codec. Returns true on success, false otherwise.
  32. bool RegisterCodec(const char* payload_name,
  33. int sampling_freq_hz,
  34. int channels,
  35. int payload_type,
  36. int frame_size_samples);
  37. // Registers an external send codec.
  38. void RegisterExternalCodec(
  39. std::unique_ptr<AudioEncoder> external_speech_encoder);
  40. // Inherited from PacketSource.
  41. std::unique_ptr<Packet> NextPacket() override;
  42. // Inherited from AudioPacketizationCallback.
  43. int32_t SendData(AudioFrameType frame_type,
  44. uint8_t payload_type,
  45. uint32_t timestamp,
  46. const uint8_t* payload_data,
  47. size_t payload_len_bytes,
  48. int64_t absolute_capture_timestamp_ms) override;
  49. AudioCodingModule* acm() { return acm_.get(); }
  50. private:
  51. static const int kBlockSizeMs = 10;
  52. // Creates a Packet object from the last packet produced by ACM (and received
  53. // through the SendData method as a callback).
  54. std::unique_ptr<Packet> CreatePacket();
  55. SimulatedClock clock_;
  56. std::unique_ptr<AudioCodingModule> acm_;
  57. InputAudioFile* audio_source_;
  58. int source_rate_hz_;
  59. const size_t input_block_size_samples_;
  60. AudioFrame input_frame_;
  61. bool codec_registered_;
  62. int test_duration_ms_;
  63. // The following member variables are set whenever SendData() is called.
  64. AudioFrameType frame_type_;
  65. int payload_type_;
  66. uint32_t timestamp_;
  67. uint16_t sequence_number_;
  68. std::vector<uint8_t> last_payload_vec_;
  69. bool data_to_send_;
  70. RTC_DISALLOW_COPY_AND_ASSIGN(AcmSendTestOldApi);
  71. };
  72. } // namespace test
  73. } // namespace webrtc
  74. #endif // MODULES_AUDIO_CODING_ACM2_ACM_SEND_TEST_H_