blob: 548f172f8eda01adc854551e4608ba12b311c444 [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>
15
16#include "ACMTest.h"
17#include "audio_coding_module.h"
18#include "RTPFile.h"
19#include "PCMFile.h"
20#include "typedefs.h"
21
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();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000031 virtual int32_t SendData(const FrameType frameType, const uint8_t payloadType,
32 const uint32_t timeStamp, const uint8_t* payloadData,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000033 const uint16_t payloadSize,
34 const RTPFragmentationHeader* fragmentation);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000036 private:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000037 static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000038 int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000039 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000040 int32_t _frequency;
41 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000042};
43
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000044class Sender {
45 public:
46 Sender();
47 void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
48 void Teardown();
49 void Run();
50 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000051
52 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000053 uint8_t testMode;
54 uint8_t codeId;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000055
56 private:
57 AudioCodingModule* _acm;
58 PCMFile _pcmFile;
59 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000060 TestPacketization* _packetization;
61};
62
63class Receiver {
64 public:
65 Receiver();
66 void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
67 void Teardown();
68 void Run();
69 bool IncomingPacket();
70 bool PlayoutData();
71
72 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000073 uint8_t codeId;
74 uint8_t testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000075
76 private:
77 AudioCodingModule* _acm;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000078 RTPStream* _rtpStream;
79 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000080 int16_t* _playoutBuffer;
81 uint16_t _playoutLengthSmpls;
82 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
83 uint16_t _payloadSizeBytes;
84 uint16_t _realPayloadSizeBytes;
85 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000086 bool _firstTime;
87 WebRtcRTPHeader _rtpInfo;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000088 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000089};
90
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000091class EncodeDecodeTest : public ACMTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000092 public:
93 EncodeDecodeTest();
94 EncodeDecodeTest(int testMode);
95 virtual void Perform();
96
pbos@webrtc.org0946a562013-04-09 00:28:06 +000097 uint16_t _playoutFreq;
98 uint8_t _testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000099
100 private:
101 void EncodeToFile(int fileType, int codeId, int* codePars, int testMode);
102
103 protected:
104 Sender _sender;
105 Receiver _receiver;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000106};
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
110#endif