Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_coding / main / test / TestStereo.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_TESTSTEREO_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TESTSTEREO_H_
13
14 #include <math.h>
15
16 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
17 #include "webrtc/modules/audio_coding/main/test/ACMTest.h"
18 #include "webrtc/modules/audio_coding/main/test/Channel.h"
19 #include "webrtc/modules/audio_coding/main/test/PCMFile.h"
20
21 namespace webrtc {
22
23 enum StereoMonoMode {
24   kNotSet,
25   kMono,
26   kStereo
27 };
28
29 class TestPackStereo : public AudioPacketizationCallback {
30  public:
31   TestPackStereo();
32   ~TestPackStereo();
33
34   void RegisterReceiverACM(AudioCodingModule* acm);
35
36   virtual int32_t SendData(const FrameType frame_type,
37                            const uint8_t payload_type,
38                            const uint32_t timestamp,
39                            const uint8_t* payload_data,
40                            const uint16_t payload_size,
41                            const RTPFragmentationHeader* fragmentation);
42
43   uint16_t payload_size();
44   uint32_t timestamp_diff();
45   void reset_payload_size();
46   void set_codec_mode(StereoMonoMode mode);
47   void set_lost_packet(bool lost);
48
49  private:
50   AudioCodingModule* receiver_acm_;
51   int16_t seq_no_;
52   uint32_t timestamp_diff_;
53   uint32_t last_in_timestamp_;
54   uint64_t total_bytes_;
55   uint16_t payload_size_;
56   StereoMonoMode codec_mode_;
57   // Simulate packet losses
58   bool lost_packet_;
59 };
60
61 class TestStereo : public ACMTest {
62  public:
63   explicit TestStereo(int test_mode);
64   ~TestStereo();
65
66   void Perform();
67  private:
68   // The default value of '-1' indicates that the registration is based only on
69   // codec name and a sampling frequncy matching is not required. This is useful
70   // for codecs which support several sampling frequency.
71   void RegisterSendCodec(char side, char* codec_name, int32_t samp_freq_hz,
72                          int rate, int pack_size, int channels,
73                          int payload_type);
74
75   void Run(TestPackStereo* channel, int in_channels, int out_channels,
76            int percent_loss = 0);
77   void OpenOutFile(int16_t test_number);
78   void DisplaySendReceiveCodec();
79
80   int32_t SendData(const FrameType frame_type, const uint8_t payload_type,
81                    const uint32_t timestamp, const uint8_t* payload_data,
82                    const uint16_t payload_size,
83                    const RTPFragmentationHeader* fragmentation);
84
85   int test_mode_;
86
87   scoped_ptr<AudioCodingModule> acm_a_;
88   scoped_ptr<AudioCodingModule> acm_b_;
89
90   TestPackStereo* channel_a2b_;
91
92   PCMFile* in_file_stereo_;
93   PCMFile* in_file_mono_;
94   PCMFile out_file_;
95   int16_t test_cntr_;
96   uint16_t pack_size_samp_;
97   uint16_t pack_size_bytes_;
98   int counter_;
99   char* send_codec_name_;
100
101   // Payload types for stereo codecs and CNG
102   int g722_pltype_;
103   int l16_8khz_pltype_;
104   int l16_16khz_pltype_;
105   int l16_32khz_pltype_;
106   int pcma_pltype_;
107   int pcmu_pltype_;
108   int celt_pltype_;
109   int opus_pltype_;
110   int cn_8khz_pltype_;
111   int cn_16khz_pltype_;
112   int cn_32khz_pltype_;
113 };
114
115 }  // namespace webrtc
116
117 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TESTSTEREO_H_