blob: 9b58d4d1bc185226b304ec796617c4080042d2c3 [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
27class TestPacketization: public AudioPacketizationCallback {
28 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();
pbos@webrtc.org0946a562013-04-09 00:28:06 +000031 virtual int32_t SendData(const FrameType frameType,
32 const uint8_t payloadType,
33 const uint32_t timeStamp,
34 const uint8_t* payloadData,
35 const uint16_t payloadSize,
36 const RTPFragmentationHeader* fragmentation);
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,
40 int16_t seqNo, uint32_t timeStamp,
41 uint32_t ssrc);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000042 RTPStream* _rtpStream;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000043 int32_t _frequency;
44 int16_t _seqNo;
niklase@google.com470e71d2011-07-07 08:21:25 +000045};
46
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000047class Sender {
48 public:
49 Sender();
50 void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
51 void Teardown();
52 void Run();
53 bool Add10MsData();
54 bool Process();
55
56 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000057 uint8_t testMode;
58 uint8_t codeId;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000059
60 private:
61 AudioCodingModule* _acm;
62 PCMFile _pcmFile;
63 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000064 TestPacketization* _packetization;
65};
66
67class Receiver {
68 public:
69 Receiver();
70 void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
71 void Teardown();
72 void Run();
73 bool IncomingPacket();
74 bool PlayoutData();
75
76 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000077 uint8_t codeId;
78 uint8_t testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000079
80 private:
81 AudioCodingModule* _acm;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000082 RTPStream* _rtpStream;
83 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000084 int16_t* _playoutBuffer;
85 uint16_t _playoutLengthSmpls;
86 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
87 uint16_t _payloadSizeBytes;
88 uint16_t _realPayloadSizeBytes;
89 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000090 bool _firstTime;
91 WebRtcRTPHeader _rtpInfo;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000092 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000093};
94
95class EncodeDecodeTest: public ACMTest {
96 public:
97 EncodeDecodeTest();
98 EncodeDecodeTest(int testMode);
99 virtual void Perform();
100
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000101 uint16_t _playoutFreq;
102 uint8_t _testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000103
104 private:
105 void EncodeToFile(int fileType, int codeId, int* codePars, int testMode);
106
107 protected:
108 Sender _sender;
109 Receiver _receiver;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000110};
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000112} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
114#endif