blob: 941a92fb59022f415794a096826d0a0b9206f52e [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
12#define MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000014#include <stdio.h>
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000015#include <string.h>
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/include/audio_coding_module.h"
18#include "modules/audio_coding/test/ACMTest.h"
19#include "modules/audio_coding/test/PCMFile.h"
20#include "modules/audio_coding/test/RTPFile.h"
21#include "typedefs.h"
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000022
23namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25#define MAX_INCOMING_PAYLOAD 8096
niklase@google.com470e71d2011-07-07 08:21:25 +000026
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000027// TestPacketization callback which writes the encoded payloads to file
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000028class TestPacketization : public AudioPacketizationCallback {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000029 public:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000030 TestPacketization(RTPStream *rtpStream, uint16_t frequency);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000031 ~TestPacketization();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000032 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;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000039 private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000040 static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000041 int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000042 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000043 int32_t _frequency;
44 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000045};
46
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000047class Sender {
48 public:
49 Sender();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000050 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
Peter Kasting69558702016-01-12 16:26:35 -080051 std::string in_file_name, int sample_rate, size_t channels);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000052 void Teardown();
53 void Run();
54 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000055
56 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000057 uint8_t testMode;
58 uint8_t codeId;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000059
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000060 protected:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000061 AudioCodingModule* _acm;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000062
63 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000064 PCMFile _pcmFile;
65 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000066 TestPacketization* _packetization;
67};
68
69class Receiver {
70 public:
71 Receiver();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000072 virtual ~Receiver() {};
73 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
Peter Kasting69558702016-01-12 16:26:35 -080074 std::string out_file_name, size_t channels);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000075 void Teardown();
76 void Run();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000077 virtual bool IncomingPacket();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000078 bool PlayoutData();
79
80 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000081 uint8_t codeId;
82 uint8_t testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000083
84 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000085 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000086 int16_t* _playoutBuffer;
87 uint16_t _playoutLengthSmpls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000088 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000089 bool _firstTime;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000090
91 protected:
92 AudioCodingModule* _acm;
93 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
94 RTPStream* _rtpStream;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000095 WebRtcRTPHeader _rtpInfo;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000096 size_t _realPayloadSizeBytes;
97 size_t _payloadSizeBytes;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000098 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000099};
100
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101class EncodeDecodeTest : public ACMTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000102 public:
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000103 EncodeDecodeTest();
104 explicit EncodeDecodeTest(int testMode);
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000105 void Perform() override;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000106
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000107 uint16_t _playoutFreq;
108 uint8_t _testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000109
110 private:
pbos@webrtc.orgc86e45d2014-10-01 10:05:40 +0000111 std::string EncodeToFile(int fileType,
112 int codeId,
113 int* codePars,
114 int testMode);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000115
116 protected:
117 Sender _sender;
118 Receiver _receiver;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000119};
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000121} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200123#endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_