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