blob: 5aa359636ce177716f3332104db2cc4f6ba7bca0 [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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000016#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
17#include "webrtc/modules/audio_coding/main/test/ACMTest.h"
18#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
19#include "webrtc/modules/audio_coding/main/test/RTPFile.h"
20#include "webrtc/typedefs.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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000026class Config;
27
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:
pbos@webrtc.org0946a562013-04-09 00:28:06 +000031 TestPacketization(RTPStream *rtpStream, uint16_t frequency);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000032 ~TestPacketization();
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000033 virtual int32_t SendData(const FrameType frameType, const uint8_t payloadType,
34 const uint32_t timeStamp, const uint8_t* payloadData,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000035 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,
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();
49 void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
50 void Teardown();
51 void Run();
52 bool Add10MsData();
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000053
54 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000055 uint8_t testMode;
56 uint8_t codeId;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000057
58 private:
59 AudioCodingModule* _acm;
60 PCMFile _pcmFile;
61 AudioFrame _audioFrame;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000062 TestPacketization* _packetization;
63};
64
65class Receiver {
66 public:
67 Receiver();
68 void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
69 void Teardown();
70 void Run();
71 bool IncomingPacket();
72 bool PlayoutData();
73
74 //for auto_test and logging
pbos@webrtc.org0946a562013-04-09 00:28:06 +000075 uint8_t codeId;
76 uint8_t testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000077
78 private:
79 AudioCodingModule* _acm;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000080 RTPStream* _rtpStream;
81 PCMFile _pcmFile;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000082 int16_t* _playoutBuffer;
83 uint16_t _playoutLengthSmpls;
84 uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
85 uint16_t _payloadSizeBytes;
86 uint16_t _realPayloadSizeBytes;
87 int32_t _frequency;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000088 bool _firstTime;
89 WebRtcRTPHeader _rtpInfo;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000090 uint32_t _nextTime;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000091};
92
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000093class EncodeDecodeTest : public ACMTest {
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000094 public:
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000095 explicit EncodeDecodeTest(const Config& config);
96 EncodeDecodeTest(int testMode, const Config& config);
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000097 virtual void Perform();
98
pbos@webrtc.org0946a562013-04-09 00:28:06 +000099 uint16_t _playoutFreq;
100 uint8_t _testMode;
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000101
102 private:
103 void EncodeToFile(int fileType, int codeId, int* codePars, int testMode);
104
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000105 const Config& config_;
106
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000107 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.orgd5726a12013-05-03 07:34:12 +0000112} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +0000114#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_