blob: ec957663798a23f53fd8f6d10e74aade1160a267 [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/test/PCMFile.h"
19#include "modules/audio_coding/test/RTPFile.h"
Fredrik Solenbergbbf21a32018-04-12 22:44:09 +020020#include "modules/include/module_common_types.h"
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000021
22namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24#define MAX_INCOMING_PAYLOAD 8096
niklase@google.com470e71d2011-07-07 08:21:25 +000025
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000026// TestPacketization callback which writes the encoded payloads to file
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000027class TestPacketization : public AudioPacketizationCallback {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000028 public:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000029 TestPacketization(RTPStream *rtpStream, uint16_t frequency);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000030 ~TestPacketization();
Niels Möller87e2d782019-03-07 10:18:23 +010031 int32_t SendData(const AudioFrameType frameType,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000032 const uint8_t payloadType,
33 const uint32_t timeStamp,
34 const uint8_t* payloadData,
Niels Möllerc35b6e62019-04-25 16:31:18 +020035 const size_t payloadSize) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000037 private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000038 static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039 int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000040 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000041 int32_t _frequency;
42 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000043};
44
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000045class Sender {
46 public:
47 Sender();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000048 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
Fredrik Solenberg657b2962018-12-05 10:30:25 +010049 std::string in_file_name, int in_sample_rate,
50 int payload_type, SdpAudioFormat format);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000051 void Teardown();
52 void Run();
53 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000054
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000055 protected:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000056 AudioCodingModule* _acm;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000057
58 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000059 PCMFile _pcmFile;
60 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000061 TestPacketization* _packetization;
62};
63
64class Receiver {
65 public:
66 Receiver();
Mirko Bonadeic4dd7302019-02-25 09:12:02 +010067 virtual ~Receiver() {}
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000068 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
Fredrik Solenberg657b2962018-12-05 10:30:25 +010069 std::string out_file_name, size_t channels, int file_num);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000070 void Teardown();
71 void Run();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000072 virtual bool IncomingPacket();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000073 bool PlayoutData();
74
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000075 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000076 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000077 int16_t* _playoutBuffer;
78 uint16_t _playoutLengthSmpls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000079 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000080 bool _firstTime;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000081
82 protected:
83 AudioCodingModule* _acm;
84 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
85 RTPStream* _rtpStream;
Niels Möllerbf474952019-02-18 12:00:06 +010086 RTPHeader _rtpHeader;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000087 size_t _realPayloadSizeBytes;
88 size_t _payloadSizeBytes;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000089 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000090};
91
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020092class EncodeDecodeTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000093 public:
Fredrik Solenberg657b2962018-12-05 10:30:25 +010094 EncodeDecodeTest();
Karl Wiberg3ff52ff2018-10-01 12:31:22 +020095 void Perform();
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +000096};
niklase@google.com470e71d2011-07-07 08:21:25 +000097
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000098} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000099
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200100#endif // MODULES_AUDIO_CODING_TEST_ENCODEDECODETEST_H_