1/*
2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
11#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_
12#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_
13
14#include <stdio.h>
15#include <string.h>
16
17#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"
22
23namespace webrtc {
24
25#define MAX_INCOMING_PAYLOAD 8096
26
27// TestPacketization callback which writes the encoded payloads to file
28class TestPacketization : public AudioPacketizationCallback {
29 public:
30  TestPacketization(RTPStream *rtpStream, uint16_t frequency);
31  ~TestPacketization();
32  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;
37
38 private:
39  static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
40                            int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
41  RTPStream* _rtpStream;
42  int32_t _frequency;
43  int16_t _seqNo;
44};
45
46class Sender {
47 public:
48  Sender();
49  void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
50             std::string in_file_name, int sample_rate, int channels);
51  void Teardown();
52  void Run();
53  bool Add10MsData();
54
55  //for auto_test and logging
56  uint8_t testMode;
57  uint8_t codeId;
58
59 protected:
60  AudioCodingModule* _acm;
61
62 private:
63  PCMFile _pcmFile;
64  AudioFrame _audioFrame;
65  TestPacketization* _packetization;
66};
67
68class Receiver {
69 public:
70  Receiver();
71  virtual ~Receiver() {};
72  void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
73             std::string out_file_name, int channels);
74  void Teardown();
75  void Run();
76  virtual bool IncomingPacket();
77  bool PlayoutData();
78
79  //for auto_test and logging
80  uint8_t codeId;
81  uint8_t testMode;
82
83 private:
84  PCMFile _pcmFile;
85  int16_t* _playoutBuffer;
86  uint16_t _playoutLengthSmpls;
87  int32_t _frequency;
88  bool _firstTime;
89
90 protected:
91  AudioCodingModule* _acm;
92  uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
93  RTPStream* _rtpStream;
94  WebRtcRTPHeader _rtpInfo;
95  uint16_t _realPayloadSizeBytes;
96  uint16_t _payloadSizeBytes;
97  uint32_t _nextTime;
98};
99
100class EncodeDecodeTest : public ACMTest {
101 public:
102  EncodeDecodeTest();
103  explicit EncodeDecodeTest(int testMode);
104  virtual void Perform() OVERRIDE;
105
106  uint16_t _playoutFreq;
107  uint8_t _testMode;
108
109 private:
110  void EncodeToFile(int fileType, int codeId, int* codePars, int testMode);
111
112 protected:
113  Sender _sender;
114  Receiver _receiver;
115};
116
117}  // namespace webrtc
118
119#endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_
120