Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / main / test / EncodeDecodeTest.h
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
23 namespace webrtc {
24
25 #define MAX_INCOMING_PAYLOAD 8096
26
27 // TestPacketization callback which writes the encoded payloads to file
28 class TestPacketization : public AudioPacketizationCallback {
29  public:
30   TestPacketization(RTPStream *rtpStream, uint16_t frequency);
31   ~TestPacketization();
32   virtual int32_t SendData(const FrameType frameType, const uint8_t payloadType,
33                            const uint32_t timeStamp, const uint8_t* payloadData,
34                            const uint16_t payloadSize,
35                            const RTPFragmentationHeader* fragmentation);
36
37  private:
38   static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
39                             int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
40   RTPStream* _rtpStream;
41   int32_t _frequency;
42   int16_t _seqNo;
43 };
44
45 class Sender {
46  public:
47   Sender();
48   void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
49              std::string in_file_name, int sample_rate, int channels);
50   void Teardown();
51   void Run();
52   bool Add10MsData();
53
54   //for auto_test and logging
55   uint8_t testMode;
56   uint8_t codeId;
57
58  protected:
59   AudioCodingModule* _acm;
60
61  private:
62   PCMFile _pcmFile;
63   AudioFrame _audioFrame;
64   TestPacketization* _packetization;
65 };
66
67 class Receiver {
68  public:
69   Receiver();
70   virtual ~Receiver() {};
71   void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
72              std::string out_file_name, int channels);
73   void Teardown();
74   void Run();
75   virtual bool IncomingPacket();
76   bool PlayoutData();
77
78   //for auto_test and logging
79   uint8_t codeId;
80   uint8_t testMode;
81
82  private:
83   PCMFile _pcmFile;
84   int16_t* _playoutBuffer;
85   uint16_t _playoutLengthSmpls;
86   int32_t _frequency;
87   bool _firstTime;
88
89  protected:
90   AudioCodingModule* _acm;
91   uint8_t _incomingPayload[MAX_INCOMING_PAYLOAD];
92   RTPStream* _rtpStream;
93   WebRtcRTPHeader _rtpInfo;
94   uint16_t _realPayloadSizeBytes;
95   uint16_t _payloadSizeBytes;
96   uint32_t _nextTime;
97 };
98
99 class EncodeDecodeTest : public ACMTest {
100  public:
101   EncodeDecodeTest();
102   explicit EncodeDecodeTest(int testMode);
103   virtual void Perform();
104
105   uint16_t _playoutFreq;
106   uint8_t _testMode;
107
108  private:
109   void EncodeToFile(int fileType, int codeId, int* codePars, int testMode);
110
111  protected:
112   Sender _sender;
113   Receiver _receiver;
114 };
115
116 }  // namespace webrtc
117
118 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_