EncodeDecodeTest.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_ENCODEDECODETEST_H_
  11. #define MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "modules/audio_coding/include/audio_coding_module.h"
  15. #include "modules/audio_coding/test/PCMFile.h"
  16. #include "modules/audio_coding/test/RTPFile.h"
  17. #include "modules/include/module_common_types.h"
  18. namespace webrtc {
  19. #define MAX_INCOMING_PAYLOAD 8096
  20. // TestPacketization callback which writes the encoded payloads to file
  21. class TestPacketization : public AudioPacketizationCallback {
  22. public:
  23. TestPacketization(RTPStream* rtpStream, uint16_t frequency);
  24. ~TestPacketization();
  25. int32_t SendData(const AudioFrameType frameType,
  26. const uint8_t payloadType,
  27. const uint32_t timeStamp,
  28. const uint8_t* payloadData,
  29. const size_t payloadSize,
  30. int64_t absolute_capture_timestamp_ms) override;
  31. private:
  32. static void MakeRTPheader(uint8_t* rtpHeader,
  33. uint8_t payloadType,
  34. int16_t seqNo,
  35. uint32_t timeStamp,
  36. uint32_t ssrc);
  37. RTPStream* _rtpStream;
  38. int32_t _frequency;
  39. int16_t _seqNo;
  40. };
  41. class Sender {
  42. public:
  43. Sender();
  44. void Setup(AudioCodingModule* acm,
  45. RTPStream* rtpStream,
  46. std::string in_file_name,
  47. int in_sample_rate,
  48. int payload_type,
  49. SdpAudioFormat format);
  50. void Teardown();
  51. void Run();
  52. bool Add10MsData();
  53. protected:
  54. AudioCodingModule* _acm;
  55. private:
  56. PCMFile _pcmFile;
  57. AudioFrame _audioFrame;
  58. TestPacketization* _packetization;
  59. };
  60. class Receiver {
  61. public:
  62. Receiver();
  63. virtual ~Receiver() {}
  64. void Setup(AudioCodingModule* acm,
  65. RTPStream* rtpStream,
  66. std::string out_file_name,
  67. size_t channels,
  68. int file_num);
  69. void Teardown();
  70. void Run();
  71. virtual bool IncomingPacket();
  72. bool PlayoutData();
  73. private:
  74. PCMFile _pcmFile;
  75. int16_t* _playoutBuffer;
  76. uint16_t _playoutLengthSmpls;
  77. int32_t _frequency;
  78. bool _firstTime;
  79. protected:
  80. AudioCodingModule* _acm;
  81. uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
  82. RTPStream* _rtpStream;
  83. RTPHeader _rtpHeader;
  84. size_t _realPayloadSizeBytes;
  85. size_t _payloadSizeBytes;
  86. uint32_t _nextTime;
  87. };
  88. class EncodeDecodeTest {
  89. public:
  90. EncodeDecodeTest();
  91. void Perform();
  92. };
  93. } // namespace webrtc
  94. #endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_