blob: 89b76440efb6b507691412c2d568279646aa4ae3 [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
Ali Tofigh714e3cb2022-07-20 12:53:07 +020017#include "absl/strings/string_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#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"
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:
Jonas Olssona4d87372019-07-05 19:08:33 +020030 TestPacketization(RTPStream* rtpStream, uint16_t frequency);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000031 ~TestPacketization();
Ali Tofigh62238092022-01-25 13:27:19 +010032 int32_t SendData(AudioFrameType frameType,
33 uint8_t payloadType,
34 uint32_t timeStamp,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000035 const uint8_t* payloadData,
Ali Tofigh62238092022-01-25 13:27:19 +010036 size_t payloadSize,
Minyue Liff0e4db2020-01-23 13:45:50 +010037 int64_t absolute_capture_timestamp_ms) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000039 private:
Jonas Olssona4d87372019-07-05 19:08:33 +020040 static void MakeRTPheader(uint8_t* rtpHeader,
41 uint8_t payloadType,
42 int16_t seqNo,
43 uint32_t timeStamp,
44 uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000045 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000046 int32_t _frequency;
47 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000048};
49
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000050class Sender {
51 public:
52 Sender();
Jonas Olssona4d87372019-07-05 19:08:33 +020053 void Setup(AudioCodingModule* acm,
54 RTPStream* rtpStream,
Ali Tofigh714e3cb2022-07-20 12:53:07 +020055 absl::string_view in_file_name,
Jonas Olssona4d87372019-07-05 19:08:33 +020056 int in_sample_rate,
57 int payload_type,
58 SdpAudioFormat format);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000059 void Teardown();
60 void Run();
61 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000062
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000063 protected:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000064 AudioCodingModule* _acm;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000065
66 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000067 PCMFile _pcmFile;
68 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000069 TestPacketization* _packetization;
70};
71
72class Receiver {
73 public:
74 Receiver();
Mirko Bonadeic4dd7302019-02-25 09:12:02 +010075 virtual ~Receiver() {}
Jonas Olssona4d87372019-07-05 19:08:33 +020076 void Setup(AudioCodingModule* acm,
77 RTPStream* rtpStream,
Ali Tofigh714e3cb2022-07-20 12:53:07 +020078 absl::string_view out_file_name,
Jonas Olssona4d87372019-07-05 19:08:33 +020079 size_t channels,
80 int file_num);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000081 void Teardown();
82 void Run();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000083 virtual bool IncomingPacket();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000084 bool PlayoutData();
85
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000086 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000087 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000088 int16_t* _playoutBuffer;
89 uint16_t _playoutLengthSmpls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000090 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000091 bool _firstTime;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000092
93 protected:
94 AudioCodingModule* _acm;
95 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
96 RTPStream* _rtpStream;
Niels Möllerbf474952019-02-18 12:00:06 +010097 RTPHeader _rtpHeader;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000098 size_t _realPayloadSizeBytes;
99 size_t _payloadSizeBytes;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000100 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000101};
102
Karl Wiberg3ff52ff2018-10-01 12:31:22 +0200103class EncodeDecodeTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000104 public:
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100105 EncodeDecodeTest();
Karl Wiberg3ff52ff2018-10-01 12:31:22 +0200106 void Perform();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000107};
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000109} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200111#endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_