19a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org/*
29a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
39a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *
49a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  Use of this source code is governed by a BSD-style license
59a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  that can be found in the LICENSE file in the root of the source
69a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  tree. An additional intellectual property rights grant can be found
79a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  in the file PATENTS.  All contributing project authors may
89a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
99a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org */
109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
119a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Test to verify correct stereo and multi-channel operation.
129a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
13dbe95166cbc22553a4518309835cf5f36663042ehenrik.lundin@webrtc.org#include <algorithm>
149a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include <string>
159a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include <list>
169a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1749d62206ededc5905d6121d42fdcce8ed665b2c0kjellander@webrtc.org#include "testing/gtest/include/gtest/gtest.h"
189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
19e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
20e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
21e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/tools/rtp_generator.h"
229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "webrtc/system_wrappers/interface/scoped_ptr.h"
239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org#include "webrtc/test/testsupport/fileutils.h"
247537dde7698d151f5c50b5f160e4ed28347b0c90henrike@webrtc.org#include "webrtc/test/testsupport/gtest_disable.h"
259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgnamespace webrtc {
279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgstruct TestParameters {
299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int frame_size;
309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int sample_rate;
319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int num_channels;
329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// This is a parameterized test. The test parameters are supplied through a
359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// TestParameters struct, which is obtained through the GetParam() method.
369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org//
379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// The objective of the test is to create a mono input signal and a
389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// multi-channel input signal, where each channel is identical to the mono
399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// input channel. The two input signals are processed through their respective
409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// NetEq instances. After that, the output signals are compared. The expected
419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// result is that each channel in the multi-channel output is identical to the
429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// mono output.
439a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass NetEqStereoTest : public ::testing::TestWithParam<TestParameters> {
449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org protected:
459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const int kTimeStepMs = 10;
469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const int kMaxBlockSize = 480;  // 10 ms @ 48 kHz.
479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const uint8_t kPayloadTypeMono = 95;
489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const uint8_t kPayloadTypeMulti = 96;
499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEqStereoTest()
519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : num_channels_(GetParam().num_channels),
529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        sample_rate_hz_(GetParam().sample_rate),
539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        samples_per_ms_(sample_rate_hz_ / 1000),
549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        frame_size_ms_(GetParam().frame_size),
559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        frame_size_samples_(frame_size_ms_ * samples_per_ms_),
569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        output_size_samples_(10 * samples_per_ms_),
579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        rtp_generator_mono_(samples_per_ms_),
589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        rtp_generator_(samples_per_ms_),
599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        payload_size_bytes_(0),
609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        multi_payload_size_bytes_(0),
619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        last_send_time_(0),
629a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        last_arrival_time_(0) {
634087215f83d5a77b86fde9ebf8598dfe7ecd70a1henrik.lundin@webrtc.org    NetEq::Config config;
644087215f83d5a77b86fde9ebf8598dfe7ecd70a1henrik.lundin@webrtc.org    config.sample_rate_hz = sample_rate_hz_;
654087215f83d5a77b86fde9ebf8598dfe7ecd70a1henrik.lundin@webrtc.org    neteq_mono_ = NetEq::Create(config);
664087215f83d5a77b86fde9ebf8598dfe7ecd70a1henrik.lundin@webrtc.org    neteq_ = NetEq::Create(config);
679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    input_ = new int16_t[frame_size_samples_];
689a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    encoded_ = new uint8_t[2 * frame_size_samples_];
699a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    input_multi_channel_ = new int16_t[frame_size_samples_ * num_channels_];
709a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    encoded_multi_channel_ = new uint8_t[frame_size_samples_ * 2 *
719a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                         num_channels_];
729a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    output_multi_channel_ = new int16_t[kMaxBlockSize * num_channels_];
739a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
749a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
759a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  ~NetEqStereoTest() {
769a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete neteq_mono_;
779a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete neteq_;
789a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete [] input_;
799a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete [] encoded_;
809a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete [] input_multi_channel_;
819a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete [] encoded_multi_channel_;
829a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    delete [] output_multi_channel_;
839a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
849a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
859a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual void SetUp() {
869a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    const std::string file_name =
879a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
889a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    input_file_.reset(new test::InputAudioFile(file_name));
899a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    NetEqDecoder mono_decoder;
909a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    NetEqDecoder multi_decoder;
919a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    switch (sample_rate_hz_) {
929a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      case 8000:
939a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        mono_decoder = kDecoderPCM16B;
949a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        if (num_channels_ == 2) {
959a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          multi_decoder = kDecoderPCM16B_2ch;
969a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        } else if (num_channels_ == 5) {
979a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          multi_decoder = kDecoderPCM16B_5ch;
989a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        } else {
999a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          FAIL() << "Only 2 and 5 channels supported for 8000 Hz.";
1009a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        }
1019a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        break;
1029a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      case 16000:
1039a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        mono_decoder = kDecoderPCM16Bwb;
1049a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        if (num_channels_ == 2) {
1059a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          multi_decoder = kDecoderPCM16Bwb_2ch;
1069a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        } else {
1079a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          FAIL() << "More than 2 channels is not supported for 16000 Hz.";
1089a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        }
1099a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        break;
1109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      case 32000:
1119a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        mono_decoder = kDecoderPCM16Bswb32kHz;
1129a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        if (num_channels_ == 2) {
1139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          multi_decoder = kDecoderPCM16Bswb32kHz_2ch;
1149a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        } else {
1159a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          FAIL() << "More than 2 channels is not supported for 32000 Hz.";
1169a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        }
1179a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        break;
1189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      case 48000:
1199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        mono_decoder = kDecoderPCM16Bswb48kHz;
1209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        if (num_channels_ == 2) {
1219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          multi_decoder = kDecoderPCM16Bswb48kHz_2ch;
1229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        } else {
1239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          FAIL() << "More than 2 channels is not supported for 48000 Hz.";
1249a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        }
1259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        break;
1269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      default:
1279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        FAIL() << "We shouldn't get here.";
1289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
1299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ASSERT_EQ(NetEq::kOK,
1309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org              neteq_mono_->RegisterPayloadType(mono_decoder,
1319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                               kPayloadTypeMono));
1329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    ASSERT_EQ(NetEq::kOK,
1339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org              neteq_->RegisterPayloadType(multi_decoder,
1349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                          kPayloadTypeMulti));
1359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
1369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual void TearDown() {}
1389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int GetNewPackets() {
1409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    if (!input_file_->Read(frame_size_samples_, input_)) {
1419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      return -1;
1429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
1439a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    payload_size_bytes_ = WebRtcPcm16b_Encode(input_, frame_size_samples_,
1449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                             encoded_);
1459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    if (frame_size_samples_ * 2 != payload_size_bytes_) {
1469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      return -1;
1479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
1489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int next_send_time = rtp_generator_mono_.GetRtpHeader(kPayloadTypeMono,
1499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                                          frame_size_samples_,
1509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                                          &rtp_header_mono_);
1519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    test::InputAudioFile::DuplicateInterleaved(input_, frame_size_samples_,
1529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                               num_channels_,
1539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                               input_multi_channel_);
1549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    multi_payload_size_bytes_ = WebRtcPcm16b_Encode(
1559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        input_multi_channel_, frame_size_samples_ * num_channels_,
1569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        encoded_multi_channel_);
1579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    if (frame_size_samples_ * 2 * num_channels_ != multi_payload_size_bytes_) {
1589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      return -1;
1599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
1609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    rtp_generator_.GetRtpHeader(kPayloadTypeMulti, frame_size_samples_,
1619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                &rtp_header_);
1629a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return next_send_time;
1639a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
1649a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1659a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  void VerifyOutput(size_t num_samples) {
1669a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    for (size_t i = 0; i < num_samples; ++i) {
1679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      for (int j = 0; j < num_channels_; ++j) {
1689a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        ASSERT_EQ(output_[i], output_multi_channel_[i * num_channels_ + j]) <<
1699a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org            "Diff in sample " << i << ", channel " << j << ".";
1709a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      }
1719a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
1729a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
1739a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1749a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual int GetArrivalTime(int send_time) {
1759a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int arrival_time = last_arrival_time_ + (send_time - last_send_time_);
1769a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_send_time_ = send_time;
1779a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_arrival_time_ = arrival_time;
1789a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return arrival_time;
1799a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
1809a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1819a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual bool Lost() { return false; }
1829a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1839a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  void RunTest(int num_loops) {
1849a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // Get next input packets (mono and multi-channel).
1859a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int next_send_time;
1869a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int next_arrival_time;
1879a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    do {
1889a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      next_send_time = GetNewPackets();
1899a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      ASSERT_NE(-1, next_send_time);
1909a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      next_arrival_time = GetArrivalTime(next_send_time);
1919a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    } while (Lost());  // If lost, immediately read the next packet.
1929a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
1939a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int time_now = 0;
1949a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    for (int k = 0; k < num_loops; ++k) {
1959a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      while (time_now >= next_arrival_time) {
1969a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        // Insert packet in mono instance.
1979a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        ASSERT_EQ(NetEq::kOK,
1989a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                  neteq_mono_->InsertPacket(rtp_header_mono_, encoded_,
1999a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                            payload_size_bytes_,
2009a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                            next_arrival_time));
2019a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        // Insert packet in multi-channel instance.
2029a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        ASSERT_EQ(NetEq::kOK,
2039a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                  neteq_->InsertPacket(rtp_header_, encoded_multi_channel_,
2049a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                       multi_payload_size_bytes_,
2059a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                       next_arrival_time));
2069a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        // Get next input packets (mono and multi-channel).
2079a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        do {
2089a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          next_send_time = GetNewPackets();
2099a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          ASSERT_NE(-1, next_send_time);
2109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org          next_arrival_time = GetArrivalTime(next_send_time);
2119a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        } while (Lost());  // If lost, immediately read the next packet.
2129a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      }
2139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      NetEqOutputType output_type;
2149a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      // Get audio from mono instance.
2159a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int samples_per_channel;
2169a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      int num_channels;
2179a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      EXPECT_EQ(NetEq::kOK,
2189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                neteq_mono_->GetAudio(kMaxBlockSize, output_,
2199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                      &samples_per_channel, &num_channels,
2209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                      &output_type));
2219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      EXPECT_EQ(1, num_channels);
2229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      EXPECT_EQ(output_size_samples_, samples_per_channel);
2239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      // Get audio from multi-channel instance.
2249a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      ASSERT_EQ(NetEq::kOK,
2259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                neteq_->GetAudio(kMaxBlockSize * num_channels_,
2269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                 output_multi_channel_,
2279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                 &samples_per_channel, &num_channels,
2289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                                 &output_type));
2299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      EXPECT_EQ(num_channels_, num_channels);
2309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      EXPECT_EQ(output_size_samples_, samples_per_channel);
2319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      std::ostringstream ss;
2329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      ss << "Lap number " << k << ".";
2339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      SCOPED_TRACE(ss.str());  // Print out the parameter values on failure.
2349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      // Compare mono and multi-channel.
2359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      ASSERT_NO_FATAL_FAILURE(VerifyOutput(output_size_samples_));
2369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
2379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      time_now += kTimeStepMs;
2389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
2399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
2409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
2419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int num_channels_;
2429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int sample_rate_hz_;
2439a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int samples_per_ms_;
2449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int frame_size_ms_;
2459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int frame_size_samples_;
2469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int output_size_samples_;
2479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEq* neteq_mono_;
2489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEq* neteq_;
2499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  test::RtpGenerator rtp_generator_mono_;
2509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  test::RtpGenerator rtp_generator_;
2519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int16_t* input_;
2529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int16_t* input_multi_channel_;
2539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  uint8_t* encoded_;
2549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  uint8_t* encoded_multi_channel_;
2559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int16_t output_[kMaxBlockSize];
2569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int16_t* output_multi_channel_;
2579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  WebRtcRTPHeader rtp_header_mono_;
2589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  WebRtcRTPHeader rtp_header_;
2599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int payload_size_bytes_;
2609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int multi_payload_size_bytes_;
2619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int last_send_time_;
2629a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int last_arrival_time_;
2639a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  scoped_ptr<test::InputAudioFile> input_file_;
2649a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
2659a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
2669a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass NetEqStereoTestNoJitter : public NetEqStereoTest {
2679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org protected:
2689a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEqStereoTestNoJitter()
2699a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : NetEqStereoTest() {
2709a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // Start the sender 100 ms before the receiver to pre-fill the buffer.
2719a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // This is to avoid doing preemptive expand early in the test.
2729a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // TODO(hlundin): Mock the decision making instead to control the modes.
2739a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_arrival_time_ = -100;
2749a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
2759a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
2769a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
2777537dde7698d151f5c50b5f160e4ed28347b0c90henrike@webrtc.orgTEST_P(NetEqStereoTestNoJitter, DISABLED_ON_ANDROID(RunTest)) {
2789a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  RunTest(8);
2799a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
2809a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
2819a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass NetEqStereoTestPositiveDrift : public NetEqStereoTest {
2829a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org protected:
2839a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEqStereoTestPositiveDrift()
2849a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : NetEqStereoTest(),
2859a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        drift_factor(0.9) {
2869a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // Start the sender 100 ms before the receiver to pre-fill the buffer.
2879a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // This is to avoid doing preemptive expand early in the test.
2889a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // TODO(hlundin): Mock the decision making instead to control the modes.
2899a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_arrival_time_ = -100;
2909a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
2919a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual int GetArrivalTime(int send_time) {
2929a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int arrival_time = last_arrival_time_ +
2939a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        drift_factor * (send_time - last_send_time_);
2949a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_send_time_ = send_time;
2959a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_arrival_time_ = arrival_time;
2969a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return arrival_time;
2979a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
2989a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
2999a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  double drift_factor;
3009a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
3019a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3027537dde7698d151f5c50b5f160e4ed28347b0c90henrike@webrtc.orgTEST_P(NetEqStereoTestPositiveDrift, DISABLED_ON_ANDROID(RunTest)) {
3039a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  RunTest(100);
3049a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
3059a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3069a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass NetEqStereoTestNegativeDrift : public NetEqStereoTestPositiveDrift {
3079a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org protected:
3089a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEqStereoTestNegativeDrift()
3099a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : NetEqStereoTestPositiveDrift() {
3109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    drift_factor = 1.1;
3119a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_arrival_time_ = 0;
3129a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
3139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
3149a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3157537dde7698d151f5c50b5f160e4ed28347b0c90henrike@webrtc.orgTEST_P(NetEqStereoTestNegativeDrift, DISABLED_ON_ANDROID(RunTest)) {
3169a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  RunTest(100);
3179a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
3189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass NetEqStereoTestDelays : public NetEqStereoTest {
3209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org protected:
3219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const int kDelayInterval = 10;
3229a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const int kDelay = 1000;
3239a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEqStereoTestDelays()
3249a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : NetEqStereoTest(),
3259a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        frame_index_(0) {
3269a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
3279a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3289a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual int GetArrivalTime(int send_time) {
3299a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // Deliver immediately, unless we have a back-log.
3309a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int arrival_time = std::min(last_arrival_time_, send_time);
3319a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    if (++frame_index_ % kDelayInterval == 0) {
3329a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      // Delay this packet.
3339a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      arrival_time += kDelay;
3349a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
3359a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_send_time_ = send_time;
3369a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    last_arrival_time_ = arrival_time;
3379a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return arrival_time;
3389a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
3399a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3409a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int frame_index_;
3419a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
3429a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3437537dde7698d151f5c50b5f160e4ed28347b0c90henrike@webrtc.orgTEST_P(NetEqStereoTestDelays, DISABLED_ON_ANDROID(RunTest)) {
3449a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  RunTest(1000);
3459a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
3469a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3479a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgclass NetEqStereoTestLosses : public NetEqStereoTest {
3489a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org protected:
3499a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  static const int kLossInterval = 10;
3509a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  NetEqStereoTestLosses()
3519a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      : NetEqStereoTest(),
3529a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        frame_index_(0) {
3539a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
3549a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3559a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  virtual bool Lost() {
3569a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    return (++frame_index_) % kLossInterval == 0;
3579a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
3589a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3599a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  int frame_index_;
3609a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org};
3619a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3627537dde7698d151f5c50b5f160e4ed28347b0c90henrike@webrtc.orgTEST_P(NetEqStereoTestLosses, DISABLED_ON_ANDROID(RunTest)) {
3639a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  RunTest(100);
3649a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
3659a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3669a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3679a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Creates a list of parameter sets.
3689a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgstd::list<TestParameters> GetTestParameters() {
3699a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  std::list<TestParameters> l;
3709a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int sample_rates[] = {8000, 16000, 32000};
3719a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  const int num_rates = sizeof(sample_rates) / sizeof(sample_rates[0]);
3729a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  // Loop through sample rates.
3739a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  for (int rate_index = 0; rate_index < num_rates; ++rate_index) {
3749a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    int sample_rate = sample_rates[rate_index];
3759a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    // Loop through all frame sizes between 10 and 60 ms.
3769a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    for (int frame_size = 10; frame_size <= 60; frame_size += 10) {
3779a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      TestParameters p;
3789a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      p.frame_size = frame_size;
3799a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      p.sample_rate = sample_rate;
3809a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      p.num_channels = 2;
3819a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      l.push_back(p);
3829a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      if (sample_rate == 8000) {
3839a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        // Add a five-channel test for 8000 Hz.
3849a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        p.num_channels = 5;
3859a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org        l.push_back(p);
3869a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      }
3879a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org    }
3889a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  }
3899a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  return l;
3909a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
3919a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3929a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Pretty-printing the test parameters in case of an error.
3939a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgvoid PrintTo(const TestParameters& p, ::std::ostream* os) {
3949a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org  *os << "{frame_size = " << p.frame_size <<
3959a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      ", num_channels = " << p.num_channels <<
3969a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org      ", sample_rate = " << p.sample_rate << "}";
3979a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}
3989a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
3999a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// Instantiate the tests. Each test is instantiated using the function above,
4009a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org// so that all different parameter combinations are tested.
4019a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgINSTANTIATE_TEST_CASE_P(MultiChannel,
4029a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        NetEqStereoTestNoJitter,
4039a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        ::testing::ValuesIn(GetTestParameters()));
4049a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
4059a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgINSTANTIATE_TEST_CASE_P(MultiChannel,
4069a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        NetEqStereoTestPositiveDrift,
4079a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        ::testing::ValuesIn(GetTestParameters()));
4089a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
4099a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgINSTANTIATE_TEST_CASE_P(MultiChannel,
4109a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        NetEqStereoTestNegativeDrift,
4119a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        ::testing::ValuesIn(GetTestParameters()));
4129a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
4139a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgINSTANTIATE_TEST_CASE_P(MultiChannel,
4149a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        NetEqStereoTestDelays,
4159a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        ::testing::ValuesIn(GetTestParameters()));
4169a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
4179a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.orgINSTANTIATE_TEST_CASE_P(MultiChannel,
4189a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        NetEqStereoTestLosses,
4199a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org                        ::testing::ValuesIn(GetTestParameters()));
4209a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org
4219a400812ca0006d12e538d465ab6728a8ecd07aahenrik.lundin@webrtc.org}  // namespace webrtc
422