blob: f1209c5594910d63235a428d31f365bd64eadb32 [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"
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020021#include "modules/include/module_common_types.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020022#include "typedefs.h" // NOLINT(build/include)
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000023
24namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
26#define MAX_INCOMING_PAYLOAD 8096
niklase@google.com470e71d2011-07-07 08:21:25 +000027
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000028// TestPacketization callback which writes the encoded payloads to file
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000029class TestPacketization : public AudioPacketizationCallback {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000030 public:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000031 TestPacketization(RTPStream *rtpStream, uint16_t frequency);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000032 ~TestPacketization();
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000033 int32_t SendData(const FrameType frameType,
34 const uint8_t payloadType,
35 const uint32_t timeStamp,
36 const uint8_t* payloadData,
37 const size_t payloadSize,
38 const RTPFragmentationHeader* fragmentation) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000040 private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000041 static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000042 int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000043 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000044 int32_t _frequency;
45 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000046};
47
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000048class Sender {
49 public:
50 Sender();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000051 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
Peter Kasting69558702016-01-12 16:26:35 -080052 std::string in_file_name, int sample_rate, size_t channels);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000053 void Teardown();
54 void Run();
55 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000056
pbos@webrtc.org0946a562013-04-09 00:28:06 +000057 uint8_t codeId;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000058
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000059 protected:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000060 AudioCodingModule* _acm;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000061
62 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000063 PCMFile _pcmFile;
64 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000065 TestPacketization* _packetization;
66};
67
68class Receiver {
69 public:
70 Receiver();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000071 virtual ~Receiver() {};
72 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
Peter Kasting69558702016-01-12 16:26:35 -080073 std::string out_file_name, size_t channels);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000074 void Teardown();
75 void Run();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000076 virtual bool IncomingPacket();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000077 bool PlayoutData();
78
79 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000080 uint8_t codeId;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000081
82 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000083 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000084 int16_t* _playoutBuffer;
85 uint16_t _playoutLengthSmpls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000086 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000087 bool _firstTime;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000088
89 protected:
90 AudioCodingModule* _acm;
91 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
92 RTPStream* _rtpStream;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000093 WebRtcRTPHeader _rtpInfo;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000094 size_t _realPayloadSizeBytes;
95 size_t _payloadSizeBytes;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000096 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000097};
98
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000099class EncodeDecodeTest : public ACMTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000100 public:
Karl Wiberg88aee282018-06-14 13:12:05 +0200101 explicit EncodeDecodeTest(int test_mode);
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000102 void Perform() override;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000103
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000104 uint16_t _playoutFreq;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000105
106 private:
Karl Wiberg88aee282018-06-14 13:12:05 +0200107 std::string EncodeToFile(int fileType, int codeId, int* codePars);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000108
109 protected:
110 Sender _sender;
111 Receiver _receiver;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000112};
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000114} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_