Upstream version 7.36.149.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
16 #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"
21
22 namespace webrtc {
23
24 #define MAX_INCOMING_PAYLOAD 8096
25
26 // TestPacketization callback which writes the encoded payloads to file
27 class TestPacketization : public AudioPacketizationCallback {
28  public:
29   TestPacketization(RTPStream *rtpStream, uint16_t frequency);
30   ~TestPacketization();
31   virtual int32_t SendData(const FrameType frameType, const uint8_t payloadType,
32                            const uint32_t timeStamp, const uint8_t* payloadData,
33                            const uint16_t payloadSize,
34                            const RTPFragmentationHeader* fragmentation);
35
36  private:
37   static void MakeRTPheader(uint8_t* rtpHeader, uint8_t payloadType,
38                             int16_t seqNo, uint32_t timeStamp, uint32_t ssrc);
39   RTPStream* _rtpStream;
40   int32_t _frequency;
41   int16_t _seqNo;
42 };
43
44 class Sender {
45  public:
46   Sender();
47   void Setup(AudioCodingModule *acm, RTPStream *rtpStream);
48   void Teardown();
49   void Run();
50   bool Add10MsData();
51
52   //for auto_test and logging
53   uint8_t testMode;
54   uint8_t codeId;
55
56  private:
57   AudioCodingModule* _acm;
58   PCMFile _pcmFile;
59   AudioFrame _audioFrame;
60   TestPacketization* _packetization;
61 };
62
63 class 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
73   uint8_t codeId;
74   uint8_t testMode;
75
76  private:
77   AudioCodingModule* _acm;
78   RTPStream* _rtpStream;
79   PCMFile _pcmFile;
80   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;
86   bool _firstTime;
87   WebRtcRTPHeader _rtpInfo;
88   uint32_t _nextTime;
89 };
90
91 class EncodeDecodeTest : public ACMTest {
92  public:
93   EncodeDecodeTest();
94   explicit EncodeDecodeTest(int testMode);
95   virtual void Perform();
96
97   uint16_t _playoutFreq;
98   uint8_t _testMode;
99
100  private:
101   void EncodeToFile(int fileType, int codeId, int* codePars, int testMode);
102
103  protected:
104   Sender _sender;
105   Receiver _receiver;
106 };
107
108 }  // namespace webrtc
109
110 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_ENCODEDECODETEST_H_