blob: f6b55538fe04438d02915fe92033732df8604b26 [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
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000017#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
18#include "webrtc/modules/audio_coding/main/test/ACMTest.h"
19#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
20#include "webrtc/modules/audio_coding/main/test/RTPFile.h"
21#include "webrtc/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();
henrike@webrtc.org47658f12014-09-10 22:14:59 +000032 virtual int32_t SendData(
33 const FrameType frameType, const uint8_t payloadType,
34 const uint32_t timeStamp, const uint8_t* payloadData,
35 const uint16_t payloadSize,
36 const RTPFragmentationHeader* fragmentation) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000038 private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000039 static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000040 int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000041 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000042 int32_t _frequency;
43 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000044};
45
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000046class Sender {
47 public:
48 Sender();
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000049 void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
50 std::string in_file_name, int sample_rate, int channels);
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
55 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000056 uint8_t testMode;
57 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,
73 std::string out_file_name, int 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;
81 uint8_t testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000082
83 private:
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000084 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000085 int16_t* _playoutBuffer;
86 uint16_t _playoutLengthSmpls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000087 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000088 bool _firstTime;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000089
90 protected:
91 AudioCodingModule* _acm;
92 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
93 RTPStream* _rtpStream;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000094 WebRtcRTPHeader _rtpInfo;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000095 uint16_t _realPayloadSizeBytes;
96 uint16_t _payloadSizeBytes;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000097 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000098};
99
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000100class EncodeDecodeTest : public ACMTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000101 public:
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +0000102 EncodeDecodeTest();
103 explicit EncodeDecodeTest(int testMode);
henrike@webrtc.org47658f12014-09-10 22:14:59 +0000104 virtual void Perform() OVERRIDE;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000105
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000106 uint16_t _playoutFreq;
107 uint8_t _testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000108
109 private:
pbos@webrtc.orgc86e45d2014-10-01 10:05:40 +0000110 std::string EncodeToFile(int fileType,
111 int codeId,
112 int* codePars,
113 int testMode);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000114
115 protected:
116 Sender _sender;
117 Receiver _receiver;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000118};
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000120} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000122#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_