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_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(
     37       const FrameType frame_type,
     38       const uint8_t payload_type,
     39       const uint32_t timestamp,
     40       const uint8_t* payload_data,
     41       const uint16_t payload_size,
     42       const RTPFragmentationHeader* fragmentation) OVERRIDE;
     43 
     44   uint16_t payload_size();
     45   uint32_t timestamp_diff();
     46   void reset_payload_size();
     47   void set_codec_mode(StereoMonoMode mode);
     48   void set_lost_packet(bool lost);
     49 
     50  private:
     51   AudioCodingModule* receiver_acm_;
     52   int16_t seq_no_;
     53   uint32_t timestamp_diff_;
     54   uint32_t last_in_timestamp_;
     55   uint64_t total_bytes_;
     56   int payload_size_;
     57   StereoMonoMode codec_mode_;
     58   // Simulate packet losses
     59   bool lost_packet_;
     60 };
     61 
     62 class TestStereo : public ACMTest {
     63  public:
     64   explicit TestStereo(int test_mode);
     65   ~TestStereo();
     66 
     67   virtual void Perform() OVERRIDE;
     68  private:
     69   // The default value of '-1' indicates that the registration is based only on
     70   // codec name and a sampling frequncy matching is not required. This is useful
     71   // for codecs which support several sampling frequency.
     72   void RegisterSendCodec(char side, char* codec_name, int32_t samp_freq_hz,
     73                          int rate, int pack_size, int channels,
     74                          int payload_type);
     75 
     76   void Run(TestPackStereo* channel, int in_channels, int out_channels,
     77            int percent_loss = 0);
     78   void OpenOutFile(int16_t test_number);
     79   void DisplaySendReceiveCodec();
     80 
     81   int32_t SendData(const FrameType frame_type, const uint8_t payload_type,
     82                    const uint32_t timestamp, const uint8_t* payload_data,
     83                    const uint16_t payload_size,
     84                    const RTPFragmentationHeader* fragmentation);
     85 
     86   int test_mode_;
     87 
     88   scoped_ptr<AudioCodingModule> acm_a_;
     89   scoped_ptr<AudioCodingModule> acm_b_;
     90 
     91   TestPackStereo* channel_a2b_;
     92 
     93   PCMFile* in_file_stereo_;
     94   PCMFile* in_file_mono_;
     95   PCMFile out_file_;
     96   int16_t test_cntr_;
     97   uint16_t pack_size_samp_;
     98   uint16_t pack_size_bytes_;
     99   int counter_;
    100   char* send_codec_name_;
    101 
    102   // Payload types for stereo codecs and CNG
    103   int g722_pltype_;
    104   int l16_8khz_pltype_;
    105   int l16_16khz_pltype_;
    106   int l16_32khz_pltype_;
    107   int pcma_pltype_;
    108   int pcmu_pltype_;
    109   int celt_pltype_;
    110   int opus_pltype_;
    111   int cn_8khz_pltype_;
    112   int cn_16khz_pltype_;
    113   int cn_32khz_pltype_;
    114 };
    115 
    116 }  // namespace webrtc
    117 
    118 #endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TESTSTEREO_H_
    119