blob: 9cd2c23c18c532e8cd4a8112f8cd1a25948e9219 [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"
Henrik Lundin84f75692023-02-01 12:07:10 +000018#include "modules/audio_coding/acm2/acm_receiver.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/audio_coding/include/audio_coding_module.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_coding/test/PCMFile.h"
21#include "modules/audio_coding/test/RTPFile.h"
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020022#include "modules/include/module_common_types.h"
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:
Jonas Olssona4d87372019-07-05 19:08:33 +020031 TestPacketization(RTPStream* rtpStream, uint16_t frequency);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000032 ~TestPacketization();
Ali Tofigh62238092022-01-25 13:27:19 +010033 int32_t SendData(AudioFrameType frameType,
34 uint8_t payloadType,
35 uint32_t timeStamp,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000036 const uint8_t* payloadData,
Ali Tofigh62238092022-01-25 13:27:19 +010037 size_t payloadSize,
Minyue Liff0e4db2020-01-23 13:45:50 +010038 int64_t absolute_capture_timestamp_ms) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000039
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000040 private:
Jonas Olssona4d87372019-07-05 19:08:33 +020041 static void MakeRTPheader(uint8_t* rtpHeader,
42 uint8_t payloadType,
43 int16_t seqNo,
44 uint32_t timeStamp,
45 uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000046 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000047 int32_t _frequency;
48 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000049};
50
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000051class Sender {
52 public:
53 Sender();
Jonas Olssona4d87372019-07-05 19:08:33 +020054 void Setup(AudioCodingModule* acm,
55 RTPStream* rtpStream,
Ali Tofigh714e3cb2022-07-20 12:53:07 +020056 absl::string_view in_file_name,
Jonas Olssona4d87372019-07-05 19:08:33 +020057 int in_sample_rate,
58 int payload_type,
59 SdpAudioFormat format);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000060 void Teardown();
61 void Run();
62 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000063
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000064 protected:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000065 AudioCodingModule* _acm;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000066
67 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000068 PCMFile _pcmFile;
69 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000070 TestPacketization* _packetization;
71};
72
73class Receiver {
74 public:
75 Receiver();
Mirko Bonadeic4dd7302019-02-25 09:12:02 +010076 virtual ~Receiver() {}
Henrik Lundin84f75692023-02-01 12:07:10 +000077 void Setup(acm2::AcmReceiver* acm_receiver,
Jonas Olssona4d87372019-07-05 19:08:33 +020078 RTPStream* rtpStream,
Ali Tofigh714e3cb2022-07-20 12:53:07 +020079 absl::string_view out_file_name,
Jonas Olssona4d87372019-07-05 19:08:33 +020080 size_t channels,
81 int file_num);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000082 void Teardown();
83 void Run();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000084 virtual bool IncomingPacket();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000085 bool PlayoutData();
86
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000087 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000088 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000089 int16_t* _playoutBuffer;
90 uint16_t _playoutLengthSmpls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000091 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000092 bool _firstTime;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000093
94 protected:
Henrik Lundin84f75692023-02-01 12:07:10 +000095 acm2::AcmReceiver* _acm_receiver;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000096 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
97 RTPStream* _rtpStream;
Niels Möllerbf474952019-02-18 12:00:06 +010098 RTPHeader _rtpHeader;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000099 size_t _realPayloadSizeBytes;
100 size_t _payloadSizeBytes;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000101 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000102};
103
Karl Wiberg3ff52ff2018-10-01 12:31:22 +0200104class EncodeDecodeTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000105 public:
Fredrik Solenberg657b2962018-12-05 10:30:25 +0100106 EncodeDecodeTest();
Karl Wiberg3ff52ff2018-10-01 12:31:22 +0200107 void Perform();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000108};
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000110} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200112#endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_