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