From a6ecd1ebb5ddee3eebc4d066b8ce6ea5942dfa01 Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Thu, 26 Apr 2012 07:54:30 +0000 Subject: [PATCH] Refactoring one of the ACM tests: TestStereo, to follow the style guide. (First patch: formatting the test file) TEST=audio_coding_module_test Review URL: https://webrtc-codereview.appspot.com/507001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2124 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/modules/audio_coding/main/test/PCMFile.cc | 436 ++--- src/modules/audio_coding/main/test/PCMFile.h | 94 +- .../audio_coding/main/test/TestStereo.cc | 1493 ++++++++--------- .../audio_coding/main/test/TestStereo.h | 169 +- 4 files changed, 1043 insertions(+), 1149 deletions(-) diff --git a/src/modules/audio_coding/main/test/PCMFile.cc b/src/modules/audio_coding/main/test/PCMFile.cc index 520ddbebb..092033b04 100644 --- a/src/modules/audio_coding/main/test/PCMFile.cc +++ b/src/modules/audio_coding/main/test/PCMFile.cc @@ -21,282 +21,212 @@ namespace webrtc { #define MAX_FILE_NAME_LENGTH_BYTE 500 -PCMFile::PCMFile(): -_pcmFile(NULL), -_nSamples10Ms(160), -_frequency(16000), -_endOfFile(false), -_autoRewind(false), -_rewinded(false), -_timestamp(0), -_readStereo(false), -_saveStereo(false) -{ - _timestamp = (((WebRtc_UWord32)rand() & 0x0000FFFF) << 16) | - ((WebRtc_UWord32)rand() & 0x0000FFFF); +PCMFile::PCMFile() + : pcm_file_(NULL), + samples_10ms_(160), + frequency_(16000), + end_of_file_(false), + auto_rewind_(false), + rewinded_(false), + read_stereo_(false), + save_stereo_(false) { + timestamp_ = (((WebRtc_UWord32)rand() & 0x0000FFFF) << 16) | + ((WebRtc_UWord32)rand() & 0x0000FFFF); } -/* -PCMFile::~PCMFile() -{ - if(_pcmFile != NULL) - { - fclose(_pcmFile); - _pcmFile = NULL; - } -} -*/ - -WebRtc_Word16 -PCMFile::ChooseFile( - char* fileName, - WebRtc_Word16 maxLen) -{ - char tmpName[MAX_FILE_NAME_LENGTH_BYTE]; - //strcpy(_fileName, "in.pcm"); - //printf("\n\nPlease enter the input file: "); - EXPECT_TRUE(fgets(tmpName, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL); - tmpName[MAX_FILE_NAME_LENGTH_BYTE-1] = '\0'; - WebRtc_Word16 n = 0; - - // removing leading spaces - while((isspace(tmpName[n]) || iscntrl(tmpName[n])) && - (tmpName[n] != 0) && - (n < MAX_FILE_NAME_LENGTH_BYTE)) - { - n++; - } - if(n > 0) - { - memmove(tmpName, &tmpName[n], MAX_FILE_NAME_LENGTH_BYTE - n); - } - - //removing trailing spaces - n = (WebRtc_Word16)(strlen(tmpName) - 1); - if(n >= 0) - { - while((isspace(tmpName[n]) || iscntrl(tmpName[n])) && - (n >= 0)) - { - n--; - } - } - if(n >= 0) - { - tmpName[n + 1] = '\0'; - } - - WebRtc_Word16 len = (WebRtc_Word16)strlen(tmpName); - if(len > maxLen) - { - return -1; - } - if(len > 0) - { - strncpy(fileName, tmpName, len+1); - } - return 0; +PCMFile::PCMFile(WebRtc_UWord32 timestamp) + : pcm_file_(NULL), + samples_10ms_(160), + frequency_(16000), + end_of_file_(false), + auto_rewind_(false), + rewinded_(false), + read_stereo_(false), + save_stereo_(false) { + timestamp_ = timestamp; } -WebRtc_Word16 -PCMFile::ChooseFile( - char* fileName, - WebRtc_Word16 maxLen, - WebRtc_UWord16* frequencyHz) -{ - char tmpName[MAX_FILE_NAME_LENGTH_BYTE]; - //strcpy(_fileName, "in.pcm"); - //printf("\n\nPlease enter the input file: "); - EXPECT_TRUE(fgets(tmpName, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL); - tmpName[MAX_FILE_NAME_LENGTH_BYTE-1] = '\0'; - WebRtc_Word16 n = 0; +WebRtc_Word16 PCMFile::ChooseFile(char* filename, WebRtc_Word16 max_len) { + char tmp_name[MAX_FILE_NAME_LENGTH_BYTE]; - // removing leading spaces - while((isspace(tmpName[n]) || iscntrl(tmpName[n])) && - (tmpName[n] != 0) && - (n < MAX_FILE_NAME_LENGTH_BYTE)) - { - n++; + EXPECT_TRUE(fgets(tmp_name, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL); + tmp_name[MAX_FILE_NAME_LENGTH_BYTE - 1] = '\0'; + WebRtc_Word16 n = 0; + + // Removing leading spaces. + while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0) + && (n < MAX_FILE_NAME_LENGTH_BYTE)) { + n++; + } + if (n > 0) { + memmove(tmp_name, &tmp_name[n], MAX_FILE_NAME_LENGTH_BYTE - n); + } + + // Removing trailing spaces. + n = (WebRtc_Word16)(strlen(tmp_name) - 1); + if (n >= 0) { + while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (n >= 0)) { + n--; } - if(n > 0) - { - memmove(tmpName, &tmpName[n], MAX_FILE_NAME_LENGTH_BYTE - n); + } + if (n >= 0) { + tmp_name[n + 1] = '\0'; + } + + WebRtc_Word16 len = (WebRtc_Word16) strlen(tmp_name); + if (len > max_len) { + return -1; + } + if (len > 0) { + strncpy(filename, tmp_name, len + 1); + } + return 0; +} + +WebRtc_Word16 PCMFile::ChooseFile(char* filename, WebRtc_Word16 max_len, + WebRtc_UWord16* frequency_hz) { + char tmp_name[MAX_FILE_NAME_LENGTH_BYTE]; + + EXPECT_TRUE(fgets(tmp_name, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL); + tmp_name[MAX_FILE_NAME_LENGTH_BYTE - 1] = '\0'; + WebRtc_Word16 n = 0; + + // Removing trailing spaces. + while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (tmp_name[n] != 0) + && (n < MAX_FILE_NAME_LENGTH_BYTE)) { + n++; + } + if (n > 0) { + memmove(tmp_name, &tmp_name[n], MAX_FILE_NAME_LENGTH_BYTE - n); + } + + // Removing trailing spaces. + n = (WebRtc_Word16)(strlen(tmp_name) - 1); + if (n >= 0) { + while ((isspace(tmp_name[n]) || iscntrl(tmp_name[n])) && (n >= 0)) { + n--; } + } + if (n >= 0) { + tmp_name[n + 1] = '\0'; + } - //removing trailing spaces - n = (WebRtc_Word16)(strlen(tmpName) - 1); - if(n >= 0) - { - while((isspace(tmpName[n]) || iscntrl(tmpName[n])) && - (n >= 0)) - { - n--; - } + WebRtc_Word16 len = (WebRtc_Word16) strlen(tmp_name); + if (len > max_len) { + return -1; + } + if (len > 0) { + strncpy(filename, tmp_name, len + 1); + } + printf("Enter the sampling frequency (in Hz) of the above file [%u]: ", + *frequency_hz); + EXPECT_TRUE(fgets(tmp_name, 10, stdin) != NULL); + WebRtc_UWord16 tmp_frequency = (WebRtc_UWord16) atoi(tmp_name); + if (tmp_frequency > 0) { + *frequency_hz = tmp_frequency; + } + return 0; +} + +void PCMFile::Open(const char* filename, WebRtc_UWord16 frequency, + const char* mode, bool auto_rewind) { + if ((pcm_file_ = fopen(filename, mode)) == NULL) { + printf("Cannot open file %s.\n", filename); + ADD_FAILURE() << "Unable to read file"; + } + frequency_ = frequency; + samples_10ms_ = (WebRtc_UWord16)(frequency_ / 100); + auto_rewind_ = auto_rewind; + end_of_file_ = false; + rewinded_ = false; +} + +WebRtc_Word32 PCMFile::SamplingFrequency() const { + return frequency_; +} + +WebRtc_UWord16 PCMFile::PayloadLength10Ms() const { + return samples_10ms_; +} + +WebRtc_Word32 PCMFile::Read10MsData(AudioFrame& audio_frame) { + WebRtc_UWord16 channels = 1; + if (read_stereo_) { + channels = 2; + } + + WebRtc_Word32 payload_size = (WebRtc_Word32) fread(audio_frame._payloadData, + sizeof(WebRtc_UWord16), + samples_10ms_ * channels, + pcm_file_); + if (payload_size < samples_10ms_ * channels) { + for (int k = payload_size; k < samples_10ms_ * channels; k++) { + audio_frame._payloadData[k] = 0; } - if(n >= 0) - { - tmpName[n + 1] = '\0'; + if (auto_rewind_) { + rewind(pcm_file_); + rewinded_ = true; + } else { + end_of_file_ = true; } + } + audio_frame._payloadDataLengthInSamples = samples_10ms_; + audio_frame._frequencyInHz = frequency_; + audio_frame._audioChannel = channels; + audio_frame._timeStamp = timestamp_; + timestamp_ += samples_10ms_; + return samples_10ms_; +} - WebRtc_Word16 len = (WebRtc_Word16)strlen(tmpName); - if(len > maxLen) - { - return -1; - } - if(len > 0) - { - strncpy(fileName, tmpName, len+1); +void PCMFile::Write10MsData(AudioFrame& audio_frame) { + if (audio_frame._audioChannel == 1) { + if (!save_stereo_) { + fwrite(audio_frame._payloadData, sizeof(WebRtc_UWord16), + audio_frame._payloadDataLengthInSamples, pcm_file_); + } else { + WebRtc_Word16* stereo_audio = + new WebRtc_Word16[2 * audio_frame._payloadDataLengthInSamples]; + int k; + for (k = 0; k < audio_frame._payloadDataLengthInSamples; k++) { + stereo_audio[k << 1] = audio_frame._payloadData[k]; + stereo_audio[(k << 1) + 1] = audio_frame._payloadData[k]; + } + fwrite(stereo_audio, sizeof(WebRtc_Word16), + 2 * audio_frame._payloadDataLengthInSamples, pcm_file_); + delete[] stereo_audio; } - printf("Enter the sampling frequency (in Hz) of the above file [%u]: ", *frequencyHz); - EXPECT_TRUE(fgets(tmpName, 10, stdin) != NULL); - WebRtc_UWord16 tmpFreq = (WebRtc_UWord16)atoi(tmpName); - if(tmpFreq > 0) - { - *frequencyHz = tmpFreq; - } - return 0; + } else { + fwrite(audio_frame._payloadData, sizeof(WebRtc_Word16), + audio_frame._audioChannel * audio_frame._payloadDataLengthInSamples, + pcm_file_); + } } -void -PCMFile::Open( - const char* filename, - WebRtc_UWord16 frequency, - const char* mode, - bool autoRewind) -{ - if ((_pcmFile = fopen(filename, mode)) == NULL) - { - printf("Cannot open file %s.\n", filename); - ADD_FAILURE() << "Unable to read file"; - } - _frequency = frequency; - _nSamples10Ms = (WebRtc_UWord16)(_frequency / 100); - _autoRewind = autoRewind; - _endOfFile = false; - _rewinded = false; +void PCMFile::Write10MsData(WebRtc_Word16* playout_buffer, + WebRtc_UWord16 length_smpls) { + fwrite(playout_buffer, sizeof(WebRtc_UWord16), length_smpls, pcm_file_); } -WebRtc_Word32 -PCMFile::SamplingFrequency() const -{ - return _frequency; +void PCMFile::Close() { + fclose(pcm_file_); + pcm_file_ = NULL; } -WebRtc_UWord16 -PCMFile::PayloadLength10Ms() const -{ - return _nSamples10Ms; +void PCMFile::Rewind() { + rewind(pcm_file_); + end_of_file_ = false; } -WebRtc_Word32 -PCMFile::Read10MsData( - AudioFrame& audioFrame) -{ - WebRtc_UWord16 noChannels = 1; - if (_readStereo) - { - noChannels = 2; - } - - WebRtc_Word32 payloadSize = (WebRtc_Word32)fread(audioFrame._payloadData, sizeof(WebRtc_UWord16), _nSamples10Ms*noChannels, _pcmFile); - if (payloadSize < _nSamples10Ms*noChannels) { - for (int k = payloadSize; k < _nSamples10Ms*noChannels; k++) - { - audioFrame._payloadData[k] = 0; - } - if(_autoRewind) - { - rewind(_pcmFile); - _rewinded = true; - } - else - { - _endOfFile = true; - } - } - audioFrame._payloadDataLengthInSamples = _nSamples10Ms; - audioFrame._frequencyInHz = _frequency; - audioFrame._audioChannel = noChannels; - audioFrame._timeStamp = _timestamp; - _timestamp += _nSamples10Ms; - return _nSamples10Ms; +bool PCMFile::Rewinded() { + return rewinded_; } -void -PCMFile::Write10MsData( - AudioFrame& audioFrame) -{ - if(audioFrame._audioChannel == 1) - { - if(!_saveStereo) - { - fwrite(audioFrame._payloadData, sizeof(WebRtc_UWord16), - audioFrame._payloadDataLengthInSamples, _pcmFile); - } - else - { - WebRtc_Word16* stereoAudio = new WebRtc_Word16[2 * - audioFrame._payloadDataLengthInSamples]; - int k; - for(k = 0; k < audioFrame._payloadDataLengthInSamples; k++) - { - stereoAudio[k<<1] = audioFrame._payloadData[k]; - stereoAudio[(k<<1) + 1] = audioFrame._payloadData[k]; - } - fwrite(stereoAudio, sizeof(WebRtc_Word16), 2*audioFrame._payloadDataLengthInSamples, - _pcmFile); - delete [] stereoAudio; - } - } - else - { - fwrite(audioFrame._payloadData, sizeof(WebRtc_Word16), - audioFrame._audioChannel * audioFrame._payloadDataLengthInSamples, _pcmFile); - } +void PCMFile::SaveStereo(bool is_stereo) { + save_stereo_ = is_stereo; } - -void -PCMFile::Write10MsData( - WebRtc_Word16* playoutBuffer, - WebRtc_UWord16 playoutLengthSmpls) -{ - fwrite(playoutBuffer, sizeof(WebRtc_UWord16), playoutLengthSmpls, _pcmFile); +void PCMFile::ReadStereo(bool is_stereo) { + read_stereo_ = is_stereo; } - -void -PCMFile::Close() -{ - fclose(_pcmFile); - _pcmFile = NULL; -} - -void -PCMFile::Rewind() -{ - rewind(_pcmFile); - _endOfFile = false; -} - -bool -PCMFile::Rewinded() -{ - return _rewinded; -} - -void -PCMFile::SaveStereo( - bool saveStereo) -{ - _saveStereo = saveStereo; -} - -void -PCMFile::ReadStereo( - bool readStereo) -{ - _readStereo = readStereo; -} - -} // namespace webrtc +} // namespace webrtc diff --git a/src/modules/audio_coding/main/test/PCMFile.h b/src/modules/audio_coding/main/test/PCMFile.h index a9cb9cf66..491f61516 100644 --- a/src/modules/audio_coding/main/test/PCMFile.h +++ b/src/modules/audio_coding/main/test/PCMFile.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -8,60 +8,60 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef PCMFILE_H -#define PCMFILE_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_ -#include "typedefs.h" -#include "module_common_types.h" #include #include +#include "module_common_types.h" +#include "typedefs.h" + namespace webrtc { -class PCMFile -{ -public: - PCMFile(); - ~PCMFile() - { - if(_pcmFile != NULL) - { - fclose(_pcmFile); - } +class PCMFile { + public: + PCMFile(); + PCMFile(WebRtc_UWord32 timestamp); + ~PCMFile() { + if (pcm_file_ != NULL) { + fclose(pcm_file_); } - void Open(const char *filename, WebRtc_UWord16 frequency, const char *mode, - bool autoRewind = false); - - WebRtc_Word32 Read10MsData(AudioFrame& audioFrame); - - void Write10MsData(WebRtc_Word16 *playoutBuffer, WebRtc_UWord16 playoutLengthSmpls); - void Write10MsData(AudioFrame& audioFrame); + } + void Open(const char *filename, WebRtc_UWord16 frequency, const char *mode, + bool auto_rewind = false); - WebRtc_UWord16 PayloadLength10Ms() const; - WebRtc_Word32 SamplingFrequency() const; - void Close(); - bool EndOfFile() const { return _endOfFile; } - void Rewind(); - static WebRtc_Word16 ChooseFile(char* fileName, WebRtc_Word16 maxLen, - WebRtc_UWord16* frequencyHz); - static WebRtc_Word16 ChooseFile(char* fileName, WebRtc_Word16 maxLen); - bool Rewinded(); - void SaveStereo( - bool saveStereo = true); - void ReadStereo( - bool readStereo = true); -private: - FILE* _pcmFile; - WebRtc_UWord16 _nSamples10Ms; - WebRtc_Word32 _frequency; - bool _endOfFile; - bool _autoRewind; - bool _rewinded; - WebRtc_UWord32 _timestamp; - bool _readStereo; - bool _saveStereo; + WebRtc_Word32 Read10MsData(AudioFrame& audio_frame); + + void Write10MsData(WebRtc_Word16 *playout_buffer, + WebRtc_UWord16 length_smpls); + void Write10MsData(AudioFrame& audio_frame); + + WebRtc_UWord16 PayloadLength10Ms() const; + WebRtc_Word32 SamplingFrequency() const; + void Close(); + bool EndOfFile() const { + return end_of_file_; + } + void Rewind(); + static WebRtc_Word16 ChooseFile(char* filename, WebRtc_Word16 max_len, + WebRtc_UWord16* frequency_hz); + static WebRtc_Word16 ChooseFile(char* filename, WebRtc_Word16 max_len); + bool Rewinded(); + void SaveStereo(bool is_stereo = true); + void ReadStereo(bool is_stereo = true); + private: + FILE* pcm_file_; + WebRtc_UWord16 samples_10ms_; + WebRtc_Word32 frequency_; + bool end_of_file_; + bool auto_rewind_; + bool rewinded_; + WebRtc_UWord32 timestamp_; + bool read_stereo_; + bool save_stereo_; }; -} // namespace webrtc +} // namespace webrtc -#endif +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_PCMFILE_H_ diff --git a/src/modules/audio_coding/main/test/TestStereo.cc b/src/modules/audio_coding/main/test/TestStereo.cc index bd07fca28..26b503b5c 100644 --- a/src/modules/audio_coding/main/test/TestStereo.cc +++ b/src/modules/audio_coding/main/test/TestStereo.cc @@ -23,543 +23,523 @@ namespace webrtc { // Class for simulating packet handling -TestPackStereo::TestPackStereo(): -_receiverACM(NULL), -_seqNo(0), -_timeStampDiff(0), -_lastInTimestamp(0), -_totalBytes(0), -_payloadSize(0), -_codec_mode(kNotSet), -_lost_packet(false) -{ -} -TestPackStereo::~TestPackStereo() -{ -} +TestPackStereo::TestPackStereo() + : receiver_acm_(NULL), + seq_no_(0), + timestamp_diff_(0), + last_in_timestamp_(0), + total_bytes_(0), + payload_size_(0), + codec_mode_(kNotSet), + lost_packet_(false) {} -void -TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) -{ - _receiverACM = acm; - return; -} +TestPackStereo::~TestPackStereo() {} +void TestPackStereo::RegisterReceiverACM(AudioCodingModule* acm) { + receiver_acm_ = acm; + return; +} WebRtc_Word32 TestPackStereo::SendData( - const FrameType frameType, - const WebRtc_UWord8 payloadType, - const WebRtc_UWord32 timeStamp, - const WebRtc_UWord8* payloadData, - const WebRtc_UWord16 payloadSize, + const FrameType frame_type, + const WebRtc_UWord8 payload_type, + const WebRtc_UWord32 timestamp, + const WebRtc_UWord8* payload_data, + const WebRtc_UWord16 payload_size, const RTPFragmentationHeader* fragmentation) { - WebRtcRTPHeader rtpInfo; + WebRtcRTPHeader rtp_info; WebRtc_Word32 status = 0; - rtpInfo.header.markerBit = false; - rtpInfo.header.ssrc = 0; - rtpInfo.header.sequenceNumber = _seqNo++; - rtpInfo.header.payloadType = payloadType; - rtpInfo.header.timestamp = timeStamp; - if (frameType == kFrameEmpty) { + rtp_info.header.markerBit = false; + rtp_info.header.ssrc = 0; + rtp_info.header.sequenceNumber = seq_no_++; + rtp_info.header.payloadType = payload_type; + rtp_info.header.timestamp = timestamp; + if (frame_type == kFrameEmpty) { // Skip this frame return 0; } - if (_lost_packet == false) { - if (frameType != kAudioFrameCN) { - rtpInfo.type.Audio.isCNG = false; - rtpInfo.type.Audio.channel = (int) _codec_mode; + if (lost_packet_ == false) { + if (frame_type != kAudioFrameCN) { + rtp_info.type.Audio.isCNG = false; + rtp_info.type.Audio.channel = (int) codec_mode_; } else { - rtpInfo.type.Audio.isCNG = true; - rtpInfo.type.Audio.channel = (int) kMono; + rtp_info.type.Audio.isCNG = true; + rtp_info.type.Audio.channel = (int) kMono; } - status = _receiverACM->IncomingPacket(payloadData, payloadSize, - rtpInfo); + status = receiver_acm_->IncomingPacket(payload_data, payload_size, + rtp_info); - if (frameType != kAudioFrameCN) { - _payloadSize = payloadSize; + if (frame_type != kAudioFrameCN) { + payload_size_ = payload_size; } else { - _payloadSize = -1; + payload_size_ = -1; } - _timeStampDiff = timeStamp - _lastInTimestamp; - _lastInTimestamp = timeStamp; - _totalBytes += payloadSize; + timestamp_diff_ = timestamp - last_in_timestamp_; + last_in_timestamp_ = timestamp; + total_bytes_ += payload_size; } return status; } -WebRtc_UWord16 -TestPackStereo::GetPayloadSize() -{ - return _payloadSize; +WebRtc_UWord16 TestPackStereo::payload_size() { + return payload_size_; } - -WebRtc_UWord32 -TestPackStereo::GetTimeStampDiff() -{ - return _timeStampDiff; +WebRtc_UWord32 TestPackStereo::timestamp_diff() { + return timestamp_diff_; } -void -TestPackStereo::ResetPayloadSize() -{ - _payloadSize = 0; +void TestPackStereo::reset_payload_size() { + payload_size_ = 0; } void TestPackStereo::set_codec_mode(enum StereoMonoMode mode) { - _codec_mode = mode; + codec_mode_ = mode; } void TestPackStereo::set_lost_packet(bool lost) { - _lost_packet = lost; + lost_packet_ = lost; } -TestStereo::TestStereo(int testMode): -_acmA(NULL), -_acmB(NULL), -_channelA2B(NULL), -_testCntr(0), -_packSizeSamp(0), -_packSizeBytes(0), -_counter(0), -g722_pltype_(0), -l16_8khz_pltype_(-1), -l16_16khz_pltype_(-1), -l16_32khz_pltype_(-1), -pcma_pltype_(-1), -pcmu_pltype_(-1), -celt_pltype_(-1), -cn_8khz_pltype_(-1), -cn_16khz_pltype_(-1), -cn_32khz_pltype_(-1) -{ - // testMode = 0 for silent test (auto test) - _testMode = testMode; +TestStereo::TestStereo(int test_mode) + : acm_a_(NULL), + acm_b_(NULL), + channel_a2b_(NULL), + test_cntr_(0), + pack_size_samp_(0), + pack_size_bytes_(0), + counter_(0), + g722_pltype_(0), + l16_8khz_pltype_(-1), + l16_16khz_pltype_(-1), + l16_32khz_pltype_(-1), + pcma_pltype_(-1), + pcmu_pltype_(-1), + celt_pltype_(-1), + cn_8khz_pltype_(-1), + cn_16khz_pltype_(-1), + cn_32khz_pltype_(-1) { + // testMode = 0 for silent test (auto test) + test_mode_ = test_mode; } -TestStereo::~TestStereo() -{ - if(_acmA != NULL) - { - AudioCodingModule::Destroy(_acmA); - _acmA = NULL; - } - if(_acmB != NULL) - { - AudioCodingModule::Destroy(_acmB); - _acmB = NULL; - } - if(_channelA2B != NULL) - { - delete _channelA2B; - _channelA2B = NULL; - } +TestStereo::~TestStereo() { + if (acm_a_ != NULL) { + AudioCodingModule::Destroy(acm_a_); + acm_a_ = NULL; + } + if (acm_b_ != NULL) { + AudioCodingModule::Destroy(acm_b_); + acm_b_ = NULL; + } + if (channel_a2b_ != NULL) { + delete channel_a2b_; + channel_a2b_ = NULL; + } } -void TestStereo::Perform() -{ - char file_name_stereo[500]; - char file_name_mono[500]; - WebRtc_UWord16 frequencyHz; - int audio_channels; - int codec_channels; - int status; +void TestStereo::Perform() { + char file_name_stereo[500]; + char file_name_mono[500]; + WebRtc_UWord16 frequency_hz; + int audio_channels; + int codec_channels; + int status; - if(_testMode == 0) - { - printf("Running Stereo Test"); - WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, - "---------- TestStereo ----------"); + if (test_mode_ == 0) { + printf("Running Stereo Test"); + WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, + "---------- TestStereo ----------"); + } + + strcpy(file_name_stereo, "./test/data/audio_coding/teststereo32kHz.pcm"); + strcpy(file_name_mono, "./test/data/audio_coding/testfile32kHz.pcm"); + frequency_hz = 32000; + + in_file_stereo_ = new PCMFile(); + in_file_mono_ = new PCMFile(); + + in_file_stereo_->Open(file_name_stereo, frequency_hz, "rb"); + in_file_stereo_->ReadStereo(true); + in_file_mono_->Open(file_name_mono, frequency_hz, "rb"); + in_file_mono_->ReadStereo(false); + + acm_a_ = AudioCodingModule::Create(0); + acm_b_ = AudioCodingModule::Create(1); + + acm_a_->InitializeReceiver(); + acm_b_->InitializeReceiver(); + + WebRtc_UWord8 num_encoders = acm_a_->NumberOfCodecs(); + CodecInst my_codec_param; + + // Register receiving codecs, some of them as stereo. + for (WebRtc_UWord8 n = 0; n < num_encoders; n++) { + acm_b_->Codec(n, my_codec_param); + if (!strcmp(my_codec_param.plname, "L16")) { + if (my_codec_param.plfreq == 8000) { + l16_8khz_pltype_ = my_codec_param.pltype; + } else if (my_codec_param.plfreq == 16000) { + l16_16khz_pltype_ = my_codec_param.pltype; + } else if (my_codec_param.plfreq == 32000) { + l16_32khz_pltype_ = my_codec_param.pltype; } - - strcpy(file_name_stereo, "./test/data/audio_coding/teststereo32kHz.pcm"); - strcpy(file_name_mono, "./test/data/audio_coding/testfile32kHz.pcm"); - frequencyHz = 32000; - - _in_file_stereo.Open(file_name_stereo, frequencyHz, "rb"); - _in_file_stereo.ReadStereo(true); - _in_file_mono.Open(file_name_mono, frequencyHz, "rb"); - _in_file_mono.ReadStereo(false); - - _acmA = AudioCodingModule::Create(0); - _acmB = AudioCodingModule::Create(1); - - _acmA->InitializeReceiver(); - _acmB->InitializeReceiver(); - - WebRtc_UWord8 numEncoders = _acmA->NumberOfCodecs(); - CodecInst myCodecParam; - - // Register receiving codecs, some of them as stereo. - for(WebRtc_UWord8 n = 0; n < numEncoders; n++) { - _acmB->Codec(n, myCodecParam); - if (!strcmp(myCodecParam.plname, "L16")) { - if (myCodecParam.plfreq == 8000) { - l16_8khz_pltype_ = myCodecParam.pltype; - } else if (myCodecParam.plfreq == 16000) { - l16_16khz_pltype_ = myCodecParam.pltype; - } else if (myCodecParam.plfreq == 32000) { - l16_32khz_pltype_ = myCodecParam.pltype; - } - myCodecParam.channels=2; - } else if (!strcmp(myCodecParam.plname, "PCMA")) { - pcma_pltype_ = myCodecParam.pltype; - myCodecParam.channels=2; - } else if (!strcmp(myCodecParam.plname, "PCMU")) { - pcmu_pltype_ = myCodecParam.pltype; - myCodecParam.channels=2; - } else if (!strcmp(myCodecParam.plname, "G722")) { - g722_pltype_ = myCodecParam.pltype; - myCodecParam.channels=2; - } else if (!strcmp(myCodecParam.plname, "CELT")) { - celt_pltype_ = myCodecParam.pltype; - myCodecParam.channels=2; - } - - _acmB->RegisterReceiveCodec(myCodecParam); + my_codec_param.channels = 2; + } else if (!strcmp(my_codec_param.plname, "PCMA")) { + pcma_pltype_ = my_codec_param.pltype; + my_codec_param.channels = 2; + } else if (!strcmp(my_codec_param.plname, "PCMU")) { + pcmu_pltype_ = my_codec_param.pltype; + my_codec_param.channels = 2; + } else if (!strcmp(my_codec_param.plname, "G722")) { + g722_pltype_ = my_codec_param.pltype; + my_codec_param.channels = 2; + } else if (!strcmp(my_codec_param.plname, "CELT")) { + celt_pltype_ = my_codec_param.pltype; + my_codec_param.channels = 2; } - // Test that unregister all receive codecs works for stereo. - for(WebRtc_UWord8 n = 0; n < numEncoders; n++) - { - status = _acmB->Codec(n, myCodecParam); - if (status < 0) { - printf("Error in Codec(), no matching codec found"); - } - status = _acmB->UnregisterReceiveCodec(myCodecParam.pltype); - if (status < 0) { - printf("Error in UnregisterReceiveCodec() for payload type %d", - myCodecParam.pltype); - } + acm_b_->RegisterReceiveCodec(my_codec_param); + } + + // Test that unregister all receive codecs works for stereo. + for (WebRtc_UWord8 n = 0; n < num_encoders; n++) { + status = acm_b_->Codec(n, my_codec_param); + if (status < 0) { + printf("Error in Codec(), no matching codec found"); } - - // Register receiving mono codecs, except comfort noise. - for(WebRtc_UWord8 n = 0; n < numEncoders; n++) - { - status = _acmB->Codec(n, myCodecParam); - if (status < 0) { - printf("Error in Codec(), no matching codec found"); - } - if(!strcmp(myCodecParam.plname, "L16") || - !strcmp(myCodecParam.plname, "PCMA")|| - !strcmp(myCodecParam.plname, "PCMU")|| - !strcmp(myCodecParam.plname, "G722")|| - !strcmp(myCodecParam.plname, "CELT")|| - !strcmp(myCodecParam.plname, "CN")){ - } else { - status = _acmB->RegisterReceiveCodec(myCodecParam); - if (status < 0) { - printf("Error in UnregisterReceiveCodec() for codec number %d", - n); - } - } + status = acm_b_->UnregisterReceiveCodec(my_codec_param.pltype); + if (status < 0) { + printf("Error in UnregisterReceiveCodec() for payload type %d", + my_codec_param.pltype); } + } - // TODO(tlegrand): Take care of return values of all function calls. - // Re-register all stereo codecs needed in the test, with new payload - // numbers. - g722_pltype_ = 117; - l16_8khz_pltype_ = 120; - l16_16khz_pltype_ = 121; - l16_32khz_pltype_ = 122; - pcma_pltype_ = 110; - pcmu_pltype_ = 118; - celt_pltype_ = 119; - cn_8khz_pltype_ = 123; - cn_16khz_pltype_ = 124; - cn_32khz_pltype_ = 125; + // Register receiving mono codecs, except comfort noise. + for (WebRtc_UWord8 n = 0; n < num_encoders; n++) { + status = acm_b_->Codec(n, my_codec_param); + if (status < 0) { + printf("Error in Codec(), no matching codec found"); + } + if (!strcmp(my_codec_param.plname, "L16") + || !strcmp(my_codec_param.plname, "PCMA") + || !strcmp(my_codec_param.plname, "PCMU") + || !strcmp(my_codec_param.plname, "G722") + || !strcmp(my_codec_param.plname, "CELT") + || !strcmp(my_codec_param.plname, "CN")) { + } else { + status = acm_b_->RegisterReceiveCodec(my_codec_param); + if (status < 0) { + printf("Error in UnregisterReceiveCodec() for codec number %d", n); + } + } + } - // Register all stereo codecs with new payload types. + // TODO(tlegrand): Take care of return values of all function calls. + // Re-register all stereo codecs needed in the test, with new payload + // numbers. + g722_pltype_ = 117; + l16_8khz_pltype_ = 120; + l16_16khz_pltype_ = 121; + l16_32khz_pltype_ = 122; + pcma_pltype_ = 110; + pcmu_pltype_ = 118; + celt_pltype_ = 119; + cn_8khz_pltype_ = 123; + cn_16khz_pltype_ = 124; + cn_32khz_pltype_ = 125; + + // Register all stereo codecs with new payload types. #ifdef WEBRTC_CODEC_G722 - // G722 - _acmB->Codec("G722", myCodecParam, 16000); - myCodecParam.pltype = g722_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); + // G722 + acm_b_->Codec("G722", my_codec_param, 16000); + my_codec_param.pltype = g722_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); #endif #ifdef WEBRTC_CODEC_PCM16 - // L16 - _acmB->Codec("L16", myCodecParam, 8000); - myCodecParam.pltype = l16_8khz_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); - _acmB->Codec("L16", myCodecParam, 16000); - myCodecParam.pltype = l16_16khz_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); - _acmB->Codec("L16", myCodecParam, 32000); - myCodecParam.pltype = l16_32khz_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); + // L16 + acm_b_->Codec("L16", my_codec_param, 8000); + my_codec_param.pltype = l16_8khz_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); + acm_b_->Codec("L16", my_codec_param, 16000); + my_codec_param.pltype = l16_16khz_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); + acm_b_->Codec("L16", my_codec_param, 32000); + my_codec_param.pltype = l16_32khz_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); #endif - // PCM Alaw and u-law - _acmB->Codec("PCMA", myCodecParam ,8000); - myCodecParam.pltype = pcma_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); - _acmB->Codec("PCMU", myCodecParam, 8000); - myCodecParam.pltype = pcmu_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); + // PCM Alaw and u-law + acm_b_->Codec("PCMA", my_codec_param, 8000); + my_codec_param.pltype = pcma_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); + acm_b_->Codec("PCMU", my_codec_param, 8000); + my_codec_param.pltype = pcmu_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); #ifdef WEBRTC_CODEC_CELT - // Celt - _acmB->Codec("CELT", myCodecParam, 32000); - myCodecParam.pltype = celt_pltype_; - myCodecParam.channels = 2; - _acmB->RegisterReceiveCodec(myCodecParam); + // Celt + acm_b_->Codec("CELT", my_codec_param, 32000); + my_codec_param.pltype = celt_pltype_; + my_codec_param.channels = 2; + acm_b_->RegisterReceiveCodec(my_codec_param); #endif - // Register CNG with new payload type on both send and receive side. - _acmB->Codec("CN", myCodecParam, 8000); - myCodecParam.pltype = cn_8khz_pltype_; - _acmA->RegisterSendCodec(myCodecParam); - _acmB->RegisterReceiveCodec(myCodecParam); - _acmB->Codec("CN", myCodecParam, 16000); - myCodecParam.pltype = cn_16khz_pltype_; - _acmA->RegisterSendCodec(myCodecParam); - _acmB->RegisterReceiveCodec(myCodecParam); - _acmB->Codec("CN", myCodecParam, 32000); - myCodecParam.pltype = cn_32khz_pltype_; - _acmA->RegisterSendCodec(myCodecParam); - _acmB->RegisterReceiveCodec(myCodecParam); + // Register CNG with new payload type on both send and receive side. + acm_b_->Codec("CN", my_codec_param, 8000); + my_codec_param.pltype = cn_8khz_pltype_; + acm_a_->RegisterSendCodec(my_codec_param); + acm_b_->RegisterReceiveCodec(my_codec_param); + acm_b_->Codec("CN", my_codec_param, 16000); + my_codec_param.pltype = cn_16khz_pltype_; + acm_a_->RegisterSendCodec(my_codec_param); + acm_b_->RegisterReceiveCodec(my_codec_param); + acm_b_->Codec("CN", my_codec_param, 32000); + my_codec_param.pltype = cn_32khz_pltype_; + acm_a_->RegisterSendCodec(my_codec_param); + acm_b_->RegisterReceiveCodec(my_codec_param); - // Create and connect the channel. - _channelA2B = new TestPackStereo; - _acmA->RegisterTransportCallback(_channelA2B); - _channelA2B->RegisterReceiverACM(_acmB); + // Create and connect the channel. + channel_a2b_ = new TestPackStereo; + acm_a_->RegisterTransportCallback(channel_a2b_); + channel_a2b_->RegisterReceiverACM(acm_b_); - // - // Test Stereo-To-Stereo for all codecs. - // - audio_channels = 2; - codec_channels = 2; + // + // Test Stereo-To-Stereo for all codecs. + // + audio_channels = 2; + codec_channels = 2; - // All codecs are tested for all allowed sampling frequencies, rates and - // packet sizes. + // All codecs are tested for all allowed sampling frequencies, rates and + // packet sizes. #ifdef WEBRTC_CODEC_G722 - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _channelA2B->set_codec_mode(kStereo); - _testCntr++; - OpenOutFile(_testCntr); - char codecG722[] = "G722"; - RegisterSendCodec('A', codecG722, 16000, 64000, 160, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecG722, 16000, 64000, 320, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecG722, 16000, 64000, 480, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecG722, 16000, 64000, 640, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecG722, 16000, 64000, 800, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecG722, 16000, 64000, 960, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecG722, 16000, 64000, 320, codec_channels, - g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); + if(test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n",test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + channel_a2b_->set_codec_mode(kStereo); + test_cntr_++; + OpenOutFile(test_cntr_); + char codec_g722[] = "G722"; + RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_g722, 16000, 64000, 480, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_g722, 16000, 64000, 640, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_g722, 16000, 64000, 800, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_g722, 16000, 64000, 960, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_g722, 16000, 64000, 320, codec_channels, + g722_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); #endif #ifdef WEBRTC_CODEC_PCM16 - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _channelA2B->set_codec_mode(kStereo); - _testCntr++; - OpenOutFile(_testCntr); - char codecL16[] = "L16"; - RegisterSendCodec('A', codecL16, 8000, 128000, 80, codec_channels, - l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 8000, 128000, 160, codec_channels, - l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 8000, 128000, 240, codec_channels, - l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 8000, 128000, 320, codec_channels, - l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecL16, 8000, 128000, 80, codec_channels, - l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); + if(test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n",test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + channel_a2b_->set_codec_mode(kStereo); + test_cntr_++; + OpenOutFile(test_cntr_); + char codec_l16[] = "L16"; + RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, + l16_8khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 8000, 128000, 160, codec_channels, + l16_8khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 8000, 128000, 240, codec_channels, + l16_8khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 8000, 128000, 320, codec_channels, + l16_8khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, + l16_8khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 16000, 256000, 160, codec_channels, - l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 16000, 256000, 320, codec_channels, - l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 16000, 256000, 480, codec_channels, - l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 16000, 256000, 640, codec_channels, - l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecL16, 16000, 256000, 160, codec_channels, - l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); + if(test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n",test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, + l16_16khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 16000, 256000, 320, codec_channels, + l16_16khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 16000, 256000, 480, codec_channels, + l16_16khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 16000, 256000, 640, codec_channels, + l16_16khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, + l16_16khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 32000, 512000, 320, codec_channels, - l16_32khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecL16, 32000, 512000, 640, codec_channels, - l16_32khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecL16, 32000, 512000, 320, codec_channels, - l16_32khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); + if(test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n",test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, + l16_32khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_l16, 32000, 512000, 640, codec_channels, + l16_32khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, + l16_32khz_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); #endif #define PCMA_AND_PCMU #ifdef PCMA_AND_PCMU - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _channelA2B->set_codec_mode(kStereo); - audio_channels = 2; - codec_channels = 2; - _testCntr++; - OpenOutFile(_testCntr); - char codecPCMA[] = "PCMA"; - RegisterSendCodec('A', codecPCMA, 8000, 64000, 80, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 160, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 240, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 320, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 400, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 480, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 80, codec_channels, - pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _testCntr++; - OpenOutFile(_testCntr); - char codecPCMU[] = "PCMU"; - RegisterSendCodec('A', codecPCMU, 8000, 64000, 80, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 160, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 240, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 320, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 400, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 480, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 80, codec_channels, - pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); + if (test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n", test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + channel_a2b_->set_codec_mode(kStereo); + audio_channels = 2; + codec_channels = 2; + test_cntr_++; + OpenOutFile(test_cntr_); + char codec_pcma[] = "PCMA"; + RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 160, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 240, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 320, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 400, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, + pcma_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); + if (test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n", test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + test_cntr_++; + OpenOutFile(test_cntr_); + char codec_pcmu[] = "PCMU"; + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 160, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 240, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 320, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 400, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 480, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, + pcmu_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); #endif #ifdef WEBRTC_CODEC_CELT - if(_testMode != 0) { - printf("===========================================================\n"); - printf("Test number: %d\n",_testCntr + 1); - printf("Test type: Stereo-to-stereo\n"); - } else { - printf("."); - } - _channelA2B->set_codec_mode(kStereo); - audio_channels = 2; - codec_channels = 2; - _testCntr++; - OpenOutFile(_testCntr); - char codecCELT[] = "CELT"; - RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels, - celt_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels, - celt_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecCELT, 32000, 128000, 320, codec_channels, - celt_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(true, true, VADNormal); - RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels, - celt_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _acmA->SetVAD(false, false, VADNormal); - _outFileB.Close(); + if(test_mode_ != 0) { + printf("===========================================================\n"); + printf("Test number: %d\n",test_cntr_ + 1); + printf("Test type: Stereo-to-stereo\n"); + } else { + printf("."); + } + channel_a2b_->set_codec_mode(kStereo); + audio_channels = 2; + codec_channels = 2; + test_cntr_++; + OpenOutFile(test_cntr_); + char codec_celt[] = "CELT"; + RegisterSendCodec('A', codec_celt, 32000, 48000, 320, codec_channels, + celt_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_celt, 32000, 64000, 320, codec_channels, + celt_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_celt, 32000, 128000, 320, codec_channels, + celt_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(true, true, VADNormal); + RegisterSendCodec('A', codec_celt, 32000, 48000, 320, codec_channels, + celt_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + acm_a_->SetVAD(false, false, VADNormal); + out_file_.Close(); #endif // // Test Mono-To-Stereo for all codecs. @@ -568,85 +548,85 @@ void TestStereo::Perform() codec_channels = 2; #ifdef WEBRTC_CODEC_G722 - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); } - _testCntr++; - _channelA2B->set_codec_mode(kStereo); - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecG722, 16000, 64000, 160, codec_channels, + test_cntr_++; + channel_a2b_->set_codec_mode(kStereo); + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif #ifdef WEBRTC_CODEC_PCM16 - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); } - _testCntr++; - _channelA2B->set_codec_mode(kStereo); - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 8000, 128000, 80, codec_channels, + test_cntr_++; + channel_a2b_->set_codec_mode(kStereo); + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); - if(_testMode != 0) { + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 16000, 256000, 160, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); - if(_testMode != 0) { + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 32000, 512000, 320, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, l16_32khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif #ifdef PCMA_AND_PCMU - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); } - _testCntr++; - _channelA2B->set_codec_mode(kStereo); - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 80, codec_channels, + test_cntr_++; + channel_a2b_->set_codec_mode(kStereo); + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 80, codec_channels, + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif #ifdef WEBRTC_CODEC_CELT - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); } - _testCntr++; - _channelA2B->set_codec_mode(kStereo); - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels, + test_cntr_++; + channel_a2b_->set_codec_mode(kStereo); + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_celt, 32000, 64000, 320, codec_channels, celt_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif // @@ -654,314 +634,305 @@ void TestStereo::Perform() // audio_channels = 2; codec_channels = 1; - _channelA2B->set_codec_mode(kMono); + channel_a2b_->set_codec_mode(kMono); // Register receivers as mono. - for(WebRtc_UWord8 n = 0; n < numEncoders; n++) { - _acmB->Codec(n, myCodecParam); - if (!strcmp(myCodecParam.plname, "L16")) { - if (myCodecParam.plfreq == 8000) { - myCodecParam.pltype = l16_8khz_pltype_; - } else if (myCodecParam.plfreq == 16000) { - myCodecParam.pltype = l16_16khz_pltype_ ; - } else if (myCodecParam.plfreq == 32000) { - myCodecParam.pltype = l16_32khz_pltype_; - } - } else if (!strcmp(myCodecParam.plname, "PCMA")) { - myCodecParam.pltype = pcma_pltype_; - } else if (!strcmp(myCodecParam.plname, "PCMU")) { - myCodecParam.pltype = pcmu_pltype_; - } else if (!strcmp(myCodecParam.plname, "G722")) { - myCodecParam.pltype = g722_pltype_; - } else if (!strcmp(myCodecParam.plname, "CELT")) { - myCodecParam.pltype = celt_pltype_; - myCodecParam.channels = 1; + for (WebRtc_UWord8 n = 0; n < num_encoders; n++) { + acm_b_->Codec(n, my_codec_param); + if (!strcmp(my_codec_param.plname, "L16")) { + if (my_codec_param.plfreq == 8000) { + my_codec_param.pltype = l16_8khz_pltype_; + } else if (my_codec_param.plfreq == 16000) { + my_codec_param.pltype = l16_16khz_pltype_; + } else if (my_codec_param.plfreq == 32000) { + my_codec_param.pltype = l16_32khz_pltype_; } - _acmB->RegisterReceiveCodec(myCodecParam); + } else if (!strcmp(my_codec_param.plname, "PCMA")) { + my_codec_param.pltype = pcma_pltype_; + } else if (!strcmp(my_codec_param.plname, "PCMU")) { + my_codec_param.pltype = pcmu_pltype_; + } else if (!strcmp(my_codec_param.plname, "G722")) { + my_codec_param.pltype = g722_pltype_; + } else if (!strcmp(my_codec_param.plname, "CELT")) { + my_codec_param.pltype = celt_pltype_; + my_codec_param.channels = 1; + } + acm_b_->RegisterReceiveCodec(my_codec_param); } #ifdef WEBRTC_CODEC_G722 // Run stereo audio and mono codec. - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecG722, 16000, 64000, 160, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels, g722_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif #ifdef WEBRTC_CODEC_PCM16 - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 8000, 128000, 80, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels, l16_8khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); - if(_testMode != 0) { + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 16000, 256000, 160, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels, l16_16khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); - if(_testMode != 0) { + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); + if(test_mode_ != 0) { printf("==============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecL16, 32000, 512000, 320, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels, l16_32khz_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif #ifdef PCMA_AND_PCMU - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecPCMU, 8000, 64000, 80, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels, pcmu_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - RegisterSendCodec('A', codecPCMA, 8000, 64000, 80, codec_channels, + Run(channel_a2b_, audio_channels, codec_channels); + RegisterSendCodec('A', codec_pcma, 8000, 64000, 80, codec_channels, pcma_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif #ifdef WEBRTC_CODEC_CELT - if(_testMode != 0) { + if(test_mode_ != 0) { printf("===============================================================\n"); - printf("Test number: %d\n",_testCntr + 1); + printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); } - _testCntr++; - OpenOutFile(_testCntr); - RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels, + test_cntr_++; + OpenOutFile(test_cntr_); + RegisterSendCodec('A', codec_celt, 32000, 64000, 320, codec_channels, celt_pltype_); - Run(_channelA2B, audio_channels, codec_channels); - _outFileB.Close(); + Run(channel_a2b_, audio_channels, codec_channels); + out_file_.Close(); #endif - // Print out which codecs were tested, and which were not, in the run. - if(_testMode != 0) { - printf("\nThe following codecs was INCLUDED in the test:\n"); + // Print out which codecs were tested, and which were not, in the run. + if (test_mode_ != 0) { + printf("\nThe following codecs was INCLUDED in the test:\n"); #ifdef WEBRTC_CODEC_G722 - printf(" G.722\n"); + printf(" G.722\n"); #endif #ifdef WEBRTC_CODEC_PCM16 - printf(" PCM16\n"); + printf(" PCM16\n"); #endif - printf(" G.711\n"); + printf(" G.711\n"); - printf("\nTo complete the test, listen to the %d number of output " - "files.\n", _testCntr); - } else { - printf("Done!\n"); - } + printf("\nTo complete the test, listen to the %d number of output " + "files.\n", + test_cntr_); + } else { + printf("Done!\n"); + } + + // Delete the file pointers. + delete in_file_stereo_; + delete in_file_mono_; } // Register Codec to use in the test // -// Input: side - which ACM to use, 'A' or 'B' -// codecName - name to use when register the codec -// samplingFreqHz - sampling frequency in Herz -// rate - bitrate in bytes -// packSize - packet size in samples -// extraByte - if extra bytes needed compared to the bitrate -// used when registering, can be an internal header -// set to -1 if the codec is a variable rate codec -WebRtc_Word16 TestStereo::RegisterSendCodec(char side, - char* codecName, - WebRtc_Word32 samplingFreqHz, - int rate, - int packSize, - int channels, - int payload_type) -{ - if(_testMode != 0) { - // Print out codec and settings - printf("Codec: %s Freq: %d Rate: %d PackSize: %d", codecName, - samplingFreqHz, rate, packSize); +// Input: side - which ACM to use, 'A' or 'B' +// codec_name - name to use when register the codec +// sampling_freq_hz - sampling frequency in Herz +// rate - bitrate in bytes +// pack_size - packet size in samples +// channels - number of channels; 1 for mono, 2 for stereo +// payload_type - payload type for the codec +WebRtc_Word16 TestStereo::RegisterSendCodec(char side, char* codec_name, + WebRtc_Word32 sampling_freq_hz, + int rate, int pack_size, + int channels, int payload_type) { + if (test_mode_ != 0) { + // Print out codec and settings + printf("Codec: %s Freq: %d Rate: %d PackSize: %d", codec_name, + sampling_freq_hz, rate, pack_size); + } + + // Store packet size in samples, used to validate the received packet + pack_size_samp_ = pack_size; + + // Store the expected packet size in bytes, used to validate the received + // packet. Add 0.875 to always round up to a whole byte. + // For Celt the packet size in bytes is already counting the stereo part. + if (!strcmp(codec_name, "CELT")) { + pack_size_bytes_ = (WebRtc_UWord16)( + (float) (pack_size * rate) / (float) (sampling_freq_hz * 8) + 0.875) + / channels; + } else { + pack_size_bytes_ = (WebRtc_UWord16)( + (float) (pack_size * rate) / (float) (sampling_freq_hz * 8) + 0.875); + } + + // Set pointer to the ACM where to register the codec + AudioCodingModule* my_acm; + switch (side) { + case 'A': { + my_acm = acm_a_; + break; } - - // Store packetsize in samples, used to validate the received packet - _packSizeSamp = packSize; - - // Store the expected packet size in bytes, used to validate the received - // packet. Add 0.875 to always round up to a whole byte. - // For Celt the packet size in bytes is already counting the stereo part. - if (!strcmp(codecName, "CELT")) { - _packSizeBytes = (WebRtc_UWord16)((float)(packSize*rate)/ - (float)(samplingFreqHz*8)+0.875) / channels; - } else { - _packSizeBytes = (WebRtc_UWord16)((float)(packSize*rate)/ - (float)(samplingFreqHz*8)+0.875); + case 'B': { + my_acm = acm_b_; + break; } - - // Set pointer to the ACM where to register the codec - AudioCodingModule* myACM; - switch(side) - { - case 'A': - { - myACM = _acmA; - break; - } - case 'B': - { - myACM = _acmB; - break; - } default: - return -1; - } + return -1; + } - if(myACM == NULL) - { - assert(false); - return -1; - } - CodecInst myCodecParam; + if (my_acm == NULL) { + assert(false); + return -1; + } - // Get all codec parameters before registering - CHECK_ERROR(AudioCodingModule::Codec(codecName, myCodecParam, - samplingFreqHz)); - myCodecParam.rate = rate; - myCodecParam.pacsize = packSize; - myCodecParam.pltype = payload_type; - myCodecParam.channels = channels; - CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam)); + CodecInst my_codec_param; + // Get all codec parameters before registering + CHECK_ERROR(AudioCodingModule::Codec(codec_name, my_codec_param, + sampling_freq_hz)); + my_codec_param.rate = rate; + my_codec_param.pacsize = pack_size; + my_codec_param.pltype = payload_type; + my_codec_param.channels = channels; + CHECK_ERROR(my_acm->RegisterSendCodec(my_codec_param)); - // Initialization was successful. - return 0; + // Initialization was successful. + return 0; } void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels, int percent_loss) { - AudioFrame audioFrame; + AudioFrame audio_frame; - WebRtc_Word32 outFreqHzB = _outFileB.SamplingFrequency(); - WebRtc_UWord16 recSize; - WebRtc_UWord32 timeStampDiff; - channel->ResetPayloadSize(); - int errorCount = 0; + WebRtc_Word32 out_freq_hz_b = out_file_.SamplingFrequency(); + WebRtc_UWord16 rec_size; + WebRtc_UWord32 time_stamp_diff; + channel->reset_payload_size(); + int error_count = 0; - // Only run 1 second for each test case - // TODO(tlegrand): either remove |_counter| or start using it as the comment - // above says. Now |_counter| is always 0. - while(1) - { - // Simulate packet loss by setting |packet_loss_| to "true" in - // |percent_loss| percent of the loops. - if (percent_loss > 0) { - if (_counter == floor((100 / percent_loss) + 0.5)) { - _counter = 0; - channel->set_lost_packet(true); - } else { - channel->set_lost_packet(false); - } - _counter++; - } - - // Add 10 msec to ACM - if (in_channels == 1) { - if (_in_file_mono.EndOfFile()) { - break; - } - _in_file_mono.Read10MsData(audioFrame); - } else { - if (_in_file_stereo.EndOfFile()) { - break; - } - _in_file_stereo.Read10MsData(audioFrame); - } - CHECK_ERROR(_acmA->Add10MsData(audioFrame)); - - // Run sender side of ACM - CHECK_ERROR(_acmA->Process()); - - // Verify that the received packet size matches the settings - recSize = channel->GetPayloadSize(); - if ((0 < recSize) & (recSize < 65535)) { - if ((recSize != _packSizeBytes * out_channels) && - (_packSizeBytes < 65535)) { - errorCount++; - } - - // Verify that the timestamp is updated with expected length - timeStampDiff = channel->GetTimeStampDiff(); - if ((_counter > 10) && (timeStampDiff != _packSizeSamp)) { - errorCount++; - } - } - - // Run received side of ACM - CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, audioFrame)); - - // Write output speech to file - _outFileB.Write10MsData( - audioFrame._payloadData, - audioFrame._payloadDataLengthInSamples * audioFrame._audioChannel); + // Only run 1 second for each test case + // TODO(tlegrand): either remove |counter_| or start using it as the comment + // above says. Now |counter_| is always 0. + while (1) { + // Simulate packet loss by setting |packet_loss_| to "true" in + // |percent_loss| percent of the loops. + if (percent_loss > 0) { + if (counter_ == floor((100 / percent_loss) + 0.5)) { + counter_ = 0; + channel->set_lost_packet(true); + } else { + channel->set_lost_packet(false); + } + counter_++; } - if (errorCount) - { - printf(" - test FAILED\n"); - } - else if(_testMode != 0) - { - printf(" - test PASSED\n"); + // Add 10 msec to ACM + if (in_channels == 1) { + if (in_file_mono_->EndOfFile()) { + break; + } + in_file_mono_->Read10MsData(audio_frame); + } else { + if (in_file_stereo_->EndOfFile()) { + break; + } + in_file_stereo_->Read10MsData(audio_frame); + } + CHECK_ERROR(acm_a_->Add10MsData(audio_frame)); + + // Run sender side of ACM + CHECK_ERROR(acm_a_->Process()); + + // Verify that the received packet size matches the settings + rec_size = channel->payload_size(); + if ((0 < rec_size) & (rec_size < 65535)) { + if ((rec_size != pack_size_bytes_ * out_channels) + && (pack_size_bytes_ < 65535)) { + error_count++; + } + + // Verify that the timestamp is updated with expected length + time_stamp_diff = channel->timestamp_diff(); + if ((counter_ > 10) && (time_stamp_diff != pack_size_samp_)) { + error_count++; + } } - // Reset _counter - if (_counter == 1000) { - _counter = 0; - } - if (_in_file_mono.EndOfFile()) { - _in_file_mono.Rewind(); - } - if (_in_file_stereo.EndOfFile()) { - _in_file_stereo.Rewind(); - } - // Reset in case we ended with a lost packet - channel->set_lost_packet(false); + // Run received side of ACM + CHECK_ERROR(acm_b_->PlayoutData10Ms(out_freq_hz_b, audio_frame)); + + // Write output speech to file + out_file_.Write10MsData( + audio_frame._payloadData, + audio_frame._payloadDataLengthInSamples * audio_frame._audioChannel); + } + + if (error_count) { + printf(" - test FAILED\n"); + } else if (test_mode_ != 0) { + printf(" - test PASSED\n"); + } + + // Reset counter_ + if (counter_ == 1000) { + counter_ = 0; + } + if (in_file_mono_->EndOfFile()) { + in_file_mono_->Rewind(); + } + if (in_file_stereo_->EndOfFile()) { + in_file_stereo_->Rewind(); + } + // Reset in case we ended with a lost packet + channel->set_lost_packet(false); } -void TestStereo::OpenOutFile(WebRtc_Word16 testNumber) -{ - char fileName[500]; - sprintf(fileName, "%s/teststereo_out_%02d.pcm", - webrtc::test::OutputPath().c_str(), testNumber); - _outFileB.Open(fileName, 32000, "wb"); +void TestStereo::OpenOutFile(WebRtc_Word16 test_number) { + char file_name[500]; + sprintf(file_name, "%s/teststereo_out_%02d.pcm", + webrtc::test::OutputPath().c_str(), test_number); + out_file_.Open(file_name, 32000, "wb"); } -void TestStereo::DisplaySendReceiveCodec() -{ - CodecInst myCodecParam; - _acmA->SendCodec(myCodecParam); - if(_testMode != 0) { - printf("%s -> ", myCodecParam.plname); - } - _acmB->ReceiveCodec(myCodecParam); - if(_testMode != 0) { - printf("%s\n", myCodecParam.plname); - } +void TestStereo::DisplaySendReceiveCodec() { + CodecInst my_codec_param; + acm_a_->SendCodec(my_codec_param); + if (test_mode_ != 0) { + printf("%s -> ", my_codec_param.plname); + } + acm_b_->ReceiveCodec(my_codec_param); + if (test_mode_ != 0) { + printf("%s\n", my_codec_param.plname); + } } -} // namespace webrtc +} // namespace webrtc diff --git a/src/modules/audio_coding/main/test/TestStereo.h b/src/modules/audio_coding/main/test/TestStereo.h index 44ec198a7..3b048d814 100644 --- a/src/modules/audio_coding/main/test/TestStereo.h +++ b/src/modules/audio_coding/main/test/TestStereo.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef TEST_STEREO_H -#define TEST_STEREO_H +#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TEST_STEREO_H_ +#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TEST_STEREO_H_ #include @@ -20,106 +20,99 @@ namespace webrtc { enum StereoMonoMode { - kNotSet, - kMono, - kStereo + kNotSet, + kMono, + kStereo }; -class TestPackStereo : public AudioPacketizationCallback -{ -public: - TestPackStereo(); - ~TestPackStereo(); - - void RegisterReceiverACM(AudioCodingModule* acm); - - virtual WebRtc_Word32 SendData(const FrameType frameType, - const WebRtc_UWord8 payloadType, - const WebRtc_UWord32 timeStamp, - const WebRtc_UWord8* payloadData, - const WebRtc_UWord16 payloadSize, - const RTPFragmentationHeader* fragmentation); +class TestPackStereo : public AudioPacketizationCallback { + public: + TestPackStereo(); + ~TestPackStereo(); - WebRtc_UWord16 GetPayloadSize(); - WebRtc_UWord32 GetTimeStampDiff(); - void ResetPayloadSize(); - void set_codec_mode(StereoMonoMode mode); - void set_lost_packet(bool lost); + void RegisterReceiverACM(AudioCodingModule* acm); -private: - AudioCodingModule* _receiverACM; - WebRtc_Word16 _seqNo; - WebRtc_UWord8 _payloadData[60 * 32 * 2 * 2]; - WebRtc_UWord32 _timeStampDiff; - WebRtc_UWord32 _lastInTimestamp; - WebRtc_UWord64 _totalBytes; - WebRtc_UWord16 _payloadSize; - StereoMonoMode _codec_mode; - // Simulate packet losses - bool _lost_packet; + virtual WebRtc_Word32 SendData(const FrameType frame_type, + const WebRtc_UWord8 payload_type, + const WebRtc_UWord32 timestamp, + const WebRtc_UWord8* payload_data, + const WebRtc_UWord16 payload_size, + const RTPFragmentationHeader* fragmentation); + + WebRtc_UWord16 payload_size(); + WebRtc_UWord32 timestamp_diff(); + void reset_payload_size(); + void set_codec_mode(StereoMonoMode mode); + void set_lost_packet(bool lost); + + private: + AudioCodingModule* receiver_acm_; + WebRtc_Word16 seq_no_; + WebRtc_UWord8 payload_data_[60 * 32 * 2 * 2]; + WebRtc_UWord32 timestamp_diff_; + WebRtc_UWord32 last_in_timestamp_; + WebRtc_UWord64 total_bytes_; + WebRtc_UWord16 payload_size_; + StereoMonoMode codec_mode_; + // Simulate packet losses + bool lost_packet_; }; -class TestStereo : public ACMTest -{ -public: - TestStereo(int testMode); - ~TestStereo(); +class TestStereo : public ACMTest { + public: + TestStereo(int test_mode); + ~TestStereo(); - void Perform(); -private: - // The default value of '-1' indicates that the registration is based only on codec name - // and a sampling frequncy matching is not required. This is useful for codecs which support - // several sampling frequency. - WebRtc_Word16 RegisterSendCodec(char side, - char* codecName, - WebRtc_Word32 sampFreqHz, - int rate, - int packSize, - int channels, - int payload_type); + void Perform(); + private: + // The default value of '-1' indicates that the registration is based only on + // codec name and a sampling frequncy matching is not required. This is useful + // for codecs which support several sampling frequency. + WebRtc_Word16 RegisterSendCodec(char side, char* codec_name, + WebRtc_Word32 samp_freq_hz, int rate, + int pack_size, int channels, + int payload_type); - void Run(TestPackStereo* channel, int in_channels, int out_channels, - int percent_loss = 0); - void OpenOutFile(WebRtc_Word16 testNumber); - void DisplaySendReceiveCodec(); + void Run(TestPackStereo* channel, int in_channels, int out_channels, + int percent_loss = 0); + void OpenOutFile(WebRtc_Word16 test_number); + void DisplaySendReceiveCodec(); - WebRtc_Word32 SendData( - const FrameType frameType, - const WebRtc_UWord8 payloadType, - const WebRtc_UWord32 timeStamp, - const WebRtc_UWord8* payloadData, - const WebRtc_UWord16 payloadSize, - const RTPFragmentationHeader* fragmentation); + WebRtc_Word32 SendData(const FrameType frame_type, + const WebRtc_UWord8 payload_type, + const WebRtc_UWord32 timestamp, + const WebRtc_UWord8* payload_data, + const WebRtc_UWord16 payload_size, + const RTPFragmentationHeader* fragmentation); - int _testMode; + int test_mode_; - AudioCodingModule* _acmA; - AudioCodingModule* _acmB; + AudioCodingModule* acm_a_; + AudioCodingModule* acm_b_; - TestPackStereo* _channelA2B; + TestPackStereo* channel_a2b_; - PCMFile _in_file_stereo; - PCMFile _in_file_mono; - PCMFile _outFileB; - WebRtc_Word16 _testCntr; - WebRtc_UWord16 _packSizeSamp; - WebRtc_UWord16 _packSizeBytes; - int _counter; + PCMFile* in_file_stereo_; + PCMFile* in_file_mono_; + PCMFile out_file_; + WebRtc_Word16 test_cntr_; + WebRtc_UWord16 pack_size_samp_; + WebRtc_UWord16 pack_size_bytes_; + int counter_; - // Payload types for stereo codecs and CNG - int g722_pltype_; - int l16_8khz_pltype_; - int l16_16khz_pltype_; - int l16_32khz_pltype_; - int pcma_pltype_; - int pcmu_pltype_; - int celt_pltype_; - int cn_8khz_pltype_; - int cn_16khz_pltype_; - int cn_32khz_pltype_; + // Payload types for stereo codecs and CNG + int g722_pltype_; + int l16_8khz_pltype_; + int l16_16khz_pltype_; + int l16_32khz_pltype_; + int pcma_pltype_; + int pcmu_pltype_; + int celt_pltype_; + int cn_8khz_pltype_; + int cn_16khz_pltype_; + int cn_32khz_pltype_; }; -} // namespace webrtc - -#endif +} // namespace webrtc +#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_TEST_STEREO_H_