niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | 16b6b90 | 2012-04-12 11:02:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 15 | #include <string.h> |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 16 | |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
| 18 | #include "webrtc/modules/audio_coding/main/test/ACMTest.h" |
| 19 | #include "webrtc/modules/audio_coding/main/test/PCMFile.h" |
| 20 | #include "webrtc/modules/audio_coding/main/test/RTPFile.h" |
| 21 | #include "webrtc/typedefs.h" |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | #define MAX_INCOMING_PAYLOAD 8096 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 27 | // TestPacketization callback which writes the encoded payloads to file |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 28 | class TestPacketization : public AudioPacketizationCallback { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 29 | public: |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 30 | TestPacketization(RTPStream *rtpStream, uint16_t frequency); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 31 | ~TestPacketization(); |
henrike@webrtc.org | 47658f1 | 2014-09-10 22:14:59 +0000 | [diff] [blame] | 32 | virtual int32_t SendData( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 33 | const FrameType frameType, |
| 34 | const uint8_t payloadType, |
| 35 | const uint32_t timeStamp, |
| 36 | const uint8_t* payloadData, |
| 37 | const size_t payloadSize, |
henrike@webrtc.org | 47658f1 | 2014-09-10 22:14:59 +0000 | [diff] [blame] | 38 | const RTPFragmentationHeader* fragmentation) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 40 | private: |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 41 | static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 42 | int16_t seqNo, uint32_t timeStamp, uint32_t ssrc); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 43 | RTPStream* _rtpStream; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 44 | int32_t _frequency; |
| 45 | int16_t _seqNo; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 48 | class Sender { |
| 49 | public: |
| 50 | Sender(); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 51 | void Setup(AudioCodingModule *acm, RTPStream *rtpStream, |
| 52 | std::string in_file_name, int sample_rate, int channels); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 53 | void Teardown(); |
| 54 | void Run(); |
| 55 | bool Add10MsData(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 56 | |
| 57 | //for auto_test and logging |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 58 | uint8_t testMode; |
| 59 | uint8_t codeId; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 60 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 61 | protected: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 62 | AudioCodingModule* _acm; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 63 | |
| 64 | private: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 65 | PCMFile _pcmFile; |
| 66 | AudioFrame _audioFrame; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 67 | TestPacketization* _packetization; |
| 68 | }; |
| 69 | |
| 70 | class Receiver { |
| 71 | public: |
| 72 | Receiver(); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 73 | virtual ~Receiver() {}; |
| 74 | void Setup(AudioCodingModule *acm, RTPStream *rtpStream, |
| 75 | std::string out_file_name, int channels); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 76 | void Teardown(); |
| 77 | void Run(); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 78 | virtual bool IncomingPacket(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 79 | bool PlayoutData(); |
| 80 | |
| 81 | //for auto_test and logging |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 82 | uint8_t codeId; |
| 83 | uint8_t testMode; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 84 | |
| 85 | private: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 86 | PCMFile _pcmFile; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 87 | int16_t* _playoutBuffer; |
| 88 | uint16_t _playoutLengthSmpls; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 89 | int32_t _frequency; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 90 | bool _firstTime; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 91 | |
| 92 | protected: |
| 93 | AudioCodingModule* _acm; |
| 94 | uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD]; |
| 95 | RTPStream* _rtpStream; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 96 | WebRtcRTPHeader _rtpInfo; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 97 | size_t _realPayloadSizeBytes; |
| 98 | size_t _payloadSizeBytes; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 99 | uint32_t _nextTime; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 102 | class EncodeDecodeTest : public ACMTest { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 103 | public: |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 104 | EncodeDecodeTest(); |
| 105 | explicit EncodeDecodeTest(int testMode); |
henrike@webrtc.org | 47658f1 | 2014-09-10 22:14:59 +0000 | [diff] [blame] | 106 | virtual void Perform() OVERRIDE; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 107 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 108 | uint16_t _playoutFreq; |
| 109 | uint8_t _testMode; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 110 | |
| 111 | private: |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 112 | std::string EncodeToFile(int fileType, |
| 113 | int codeId, |
| 114 | int* codePars, |
| 115 | int testMode); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 116 | |
| 117 | protected: |
| 118 | Sender _sender; |
| 119 | Receiver _receiver; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 120 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 122 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 124 | #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_ |