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 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_ 13 14 #include <stdio.h> 15 #include <string.h> 16 17 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" 18 #include "webrtc/modules/audio_coding/test/ACMTest.h" 19 #include "webrtc/modules/audio_coding/test/PCMFile.h" 20 #include "webrtc/modules/audio_coding/test/RTPFile.h" 21 #include "webrtc/typedefs.h" 22 23 namespace webrtc { 24 25 #define MAX_INCOMING_PAYLOAD 8096 26 27 // TestPacketization callback which writes the encoded payloads to file 28 class TestPacketization : public AudioPacketizationCallback { 29 public: 30 TestPacketization(RTPStream *rtpStream, uint16_t frequency); 31 ~TestPacketization(); 32 int32_t SendData(const FrameType frameType, 33 const uint8_t payloadType, 34 const uint32_t timeStamp, 35 const uint8_t* payloadData, 36 const size_t payloadSize, 37 const RTPFragmentationHeader* fragmentation) override; 38 39 private: 40 static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, 41 int16_t seqNo, uint32_t timeStamp, uint32_t ssrc); 42 RTPStream* _rtpStream; 43 int32_t _frequency; 44 int16_t _seqNo; 45 }; 46 47 class Sender { 48 public: 49 Sender(); 50 void Setup(AudioCodingModule *acm, RTPStream *rtpStream, 51 std::string in_file_name, int sample_rate, size_t channels); 52 void Teardown(); 53 void Run(); 54 bool Add10MsData(); 55 56 //for auto_test and logging 57 uint8_t testMode; 58 uint8_t codeId; 59 60 protected: 61 AudioCodingModule* _acm; 62 63 private: 64 PCMFile _pcmFile; 65 AudioFrame _audioFrame; 66 TestPacketization* _packetization; 67 }; 68 69 class Receiver { 70 public: 71 Receiver(); 72 virtual ~Receiver() {}; 73 void Setup(AudioCodingModule *acm, RTPStream *rtpStream, 74 std::string out_file_name, size_t channels); 75 void Teardown(); 76 void Run(); 77 virtual bool IncomingPacket(); 78 bool PlayoutData(); 79 80 //for auto_test and logging 81 uint8_t codeId; 82 uint8_t testMode; 83 84 private: 85 PCMFile _pcmFile; 86 int16_t* _playoutBuffer; 87 uint16_t _playoutLengthSmpls; 88 int32_t _frequency; 89 bool _firstTime; 90 91 protected: 92 AudioCodingModule* _acm; 93 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD]; 94 RTPStream* _rtpStream; 95 WebRtcRTPHeader _rtpInfo; 96 size_t _realPayloadSizeBytes; 97 size_t _payloadSizeBytes; 98 uint32_t _nextTime; 99 }; 100 101 class EncodeDecodeTest : public ACMTest { 102 public: 103 EncodeDecodeTest(); 104 explicit EncodeDecodeTest(int testMode); 105 void Perform() override; 106 107 uint16_t _playoutFreq; 108 uint8_t _testMode; 109 110 private: 111 std::string EncodeToFile(int fileType, 112 int codeId, 113 int* codePars, 114 int testMode); 115 116 protected: 117 Sender _sender; 118 Receiver _receiver; 119 }; 120 121 } // namespace webrtc 122 123 #endif // WEBRTC_MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_ 124