• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_
12 #define MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_
13 
14 #include <math.h>
15 
16 #include <memory>
17 
18 #include "modules/audio_coding/include/audio_coding_module.h"
19 #include "modules/audio_coding/test/PCMFile.h"
20 
21 #define PCMA_AND_PCMU
22 
23 namespace webrtc {
24 
25 enum StereoMonoMode { kNotSet, kMono, kStereo };
26 
27 class TestPackStereo : public AudioPacketizationCallback {
28  public:
29   TestPackStereo();
30   ~TestPackStereo();
31 
32   void RegisterReceiverACM(AudioCodingModule* acm);
33 
34   int32_t SendData(const AudioFrameType frame_type,
35                    const uint8_t payload_type,
36                    const uint32_t timestamp,
37                    const uint8_t* payload_data,
38                    const size_t payload_size,
39                    int64_t absolute_capture_timestamp_ms) override;
40 
41   uint16_t payload_size();
42   uint32_t timestamp_diff();
43   void reset_payload_size();
44   void set_codec_mode(StereoMonoMode mode);
45   void set_lost_packet(bool lost);
46 
47  private:
48   AudioCodingModule* receiver_acm_;
49   int16_t seq_no_;
50   uint32_t timestamp_diff_;
51   uint32_t last_in_timestamp_;
52   uint64_t total_bytes_;
53   int payload_size_;
54   StereoMonoMode codec_mode_;
55   // Simulate packet losses
56   bool lost_packet_;
57 };
58 
59 class TestStereo {
60  public:
61   TestStereo();
62   ~TestStereo();
63 
64   void Perform();
65 
66  private:
67   // The default value of '-1' indicates that the registration is based only on
68   // codec name and a sampling frequncy matching is not required. This is useful
69   // for codecs which support several sampling frequency.
70   void RegisterSendCodec(char side,
71                          char* codec_name,
72                          int32_t samp_freq_hz,
73                          int rate,
74                          int pack_size,
75                          int channels);
76 
77   void Run(TestPackStereo* channel,
78            int in_channels,
79            int out_channels,
80            int percent_loss = 0);
81   void OpenOutFile(int16_t test_number);
82 
83   std::unique_ptr<AudioCodingModule> acm_a_;
84   std::unique_ptr<AudioCodingModule> acm_b_;
85 
86   TestPackStereo* channel_a2b_;
87 
88   PCMFile* in_file_stereo_;
89   PCMFile* in_file_mono_;
90   PCMFile out_file_;
91   int16_t test_cntr_;
92   uint16_t pack_size_samp_;
93   uint16_t pack_size_bytes_;
94   int counter_;
95   char* send_codec_name_;
96 };
97 
98 }  // namespace webrtc
99 
100 #endif  // MODULES_AUDIO_CODING_TEST_TESTSTEREO_H_
101