157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org/*
257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *
457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *  Use of this source code is governed by a BSD-style license
557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *  that can be found in the LICENSE file in the root of the source
657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *  tree. An additional intellectual property rights grant can be found
757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *  in the file PATENTS.  All contributing project authors may
857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org */
1057e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
1157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org#include "webrtc/voice_engine/test/auto_test/fixtures/before_streaming_fixture.h"
1257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
1357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgBeforeStreamingFixture::BeforeStreamingFixture()
1457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org    : channel_(voe_base_->CreateChannel()),
1557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org      transport_(NULL) {
1657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_GE(channel_, 0);
1757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
1857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  fake_microphone_input_file_ = resource_manager_.long_audio_file_path();
1957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_FALSE(fake_microphone_input_file_.empty());
2057e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
2157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  SetUpLocalPlayback();
2257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  RestartFakeMicrophone();
2357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
2457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
2557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgBeforeStreamingFixture::~BeforeStreamingFixture() {
2657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  voe_file_->StopPlayingFileAsMicrophone(channel_);
2757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  PausePlaying();
2857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
2957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(channel_));
3057e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  voe_base_->DeleteChannel(channel_);
3157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  delete transport_;
3257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
3357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
3457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgvoid BeforeStreamingFixture::SwitchToManualMicrophone() {
3557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_));
3657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
3757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  TEST_LOG("You need to speak manually into the microphone for this test.\n");
3857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  TEST_LOG("Please start speaking now.\n");
3957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  Sleep(1000);
4057e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
4157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
4257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgvoid BeforeStreamingFixture::RestartFakeMicrophone() {
4357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
4457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org        channel_, fake_microphone_input_file_.c_str(), true, true));
4557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
4657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
4757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgvoid BeforeStreamingFixture::PausePlaying() {
4857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_base_->StopSend(channel_));
4957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_base_->StopPlayout(channel_));
5057e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_base_->StopReceive(channel_));
5157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
5257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
5357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgvoid BeforeStreamingFixture::ResumePlaying() {
5457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_base_->StartReceive(channel_));
5557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_base_->StartPlayout(channel_));
5657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_base_->StartSend(channel_));
5757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
5857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
598db5854eb03770cfef78a5c5f5df8e15d65d4eb4solenberg@webrtc.orgvoid BeforeStreamingFixture::WaitForTransmittedPackets(int32_t packet_count) {
608db5854eb03770cfef78a5c5f5df8e15d65d4eb4solenberg@webrtc.org  transport_->WaitForTransmittedPackets(packet_count);
618db5854eb03770cfef78a5c5f5df8e15d65d4eb4solenberg@webrtc.org}
628db5854eb03770cfef78a5c5f5df8e15d65d4eb4solenberg@webrtc.org
6357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.orgvoid BeforeStreamingFixture::SetUpLocalPlayback() {
64ac547a653862744d0aae560713f8418ad2852085Peter Boström  transport_ = new LoopBackTransport(voe_network_, channel_);
6557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  EXPECT_EQ(0, voe_network_->RegisterExternalTransport(channel_, *transport_));
6657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org
6757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  webrtc::CodecInst codec;
6857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  codec.channels = 1;
6957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  codec.pacsize = 160;
7057e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  codec.plfreq = 8000;
7157e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  codec.pltype = 0;
7257e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  codec.rate = 64000;
7357e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org#if defined(_MSC_VER) && defined(_WIN32)
7457e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  _snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE - 1, "PCMU");
7557e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org#else
7657e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE, "PCMU");
7757e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org#endif
7857e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org  voe_codec_->SetSendCodec(channel_, codec);
7957e060251af925c3c12693b7f8598c85c97aa9a4solenberg@webrtc.org}
80