• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2014 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_NETEQ_TOOLS_NETEQ_QUALITY_TEST_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_QUALITY_TEST_H_
13 
14 #include <string>
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
17 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
18 #include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h"
19 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
20 #include "webrtc/typedefs.h"
21 
22 namespace webrtc {
23 namespace test {
24 
25 class NetEqQualityTest : public ::testing::Test {
26  protected:
27   NetEqQualityTest(int block_duration_ms,
28                    int in_sampling_khz,
29                    int out_sampling_khz,
30                    enum NetEqDecoder decoder_type,
31                    int channels,
32                    double drift_factor,
33                    std::string in_filename,
34                    std::string out_filename);
35   virtual void SetUp() OVERRIDE;
36   virtual void TearDown() OVERRIDE;
37 
38   // EncodeBlock(...) does the following:
39   // 1. encodes a block of audio, saved in |in_data| and has a length of
40   // |block_size_samples| (samples per channel),
41   // 2. save the bit stream to |payload| of |max_bytes| bytes in size,
42   // 3. returns the length of the payload (in bytes),
43   virtual int EncodeBlock(int16_t* in_data, int block_size_samples,
44                           uint8_t* payload, int max_bytes) = 0;
45 
46   // PacketLoss(...) determines weather a packet sent at an indicated time gets
47   // lost or not.
PacketLost(int packet_input_time_ms)48   virtual bool PacketLost(int packet_input_time_ms) { return false; }
49 
50   // DecodeBlock() decodes a block of audio using the payload stored in
51   // |payload_| with the length of |payload_size_bytes_| (bytes). The decoded
52   // audio is to be stored in |out_data_|.
53   int DecodeBlock();
54 
55   // Transmit() uses |rtp_generator_| to generate a packet and passes it to
56   // |neteq_|.
57   int Transmit();
58 
59   // Simulate(...) runs encoding / transmitting / decoding up to |end_time_ms|
60   // (miliseconds), the resulted audio is stored in the file with the name of
61   // |out_filename_|.
62   void Simulate(int end_time_ms);
63 
64  private:
65   int decoded_time_ms_;
66   int decodable_time_ms_;
67   double drift_factor_;
68   const int block_duration_ms_;
69   const int in_sampling_khz_;
70   const int out_sampling_khz_;
71   const enum NetEqDecoder decoder_type_;
72   const int channels_;
73   const std::string in_filename_;
74   const std::string out_filename_;
75 
76   // Number of samples per channel in a frame.
77   const int in_size_samples_;
78 
79   // Expected output number of samples per channel in a frame.
80   const int out_size_samples_;
81 
82   int payload_size_bytes_;
83   int max_payload_bytes_;
84 
85   scoped_ptr<InputAudioFile> in_file_;
86   FILE* out_file_;
87 
88   scoped_ptr<RtpGenerator> rtp_generator_;
89   scoped_ptr<NetEq> neteq_;
90 
91   scoped_ptr<int16_t[]> in_data_;
92   scoped_ptr<uint8_t[]> payload_;
93   scoped_ptr<int16_t[]> out_data_;
94   WebRtcRTPHeader rtp_header_;
95 };
96 
97 }  // namespace test
98 }  // namespace webrtc
99 
100 #endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_QUALITY_TEST_H_
101