1 /* 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "webrtc/voice_engine/test/auto_test/fixtures/before_streaming_fixture.h" 12 13 BeforeStreamingFixture::BeforeStreamingFixture() 14 : channel_(voe_base_->CreateChannel()), 15 transport_(NULL) { 16 EXPECT_GE(channel_, 0); 17 18 fake_microphone_input_file_ = resource_manager_.long_audio_file_path(); 19 EXPECT_FALSE(fake_microphone_input_file_.empty()); 20 21 SetUpLocalPlayback(); 22 RestartFakeMicrophone(); 23 } 24 25 BeforeStreamingFixture::~BeforeStreamingFixture() { 26 voe_file_->StopPlayingFileAsMicrophone(channel_); 27 PausePlaying(); 28 29 EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(channel_)); 30 voe_base_->DeleteChannel(channel_); 31 delete transport_; 32 } 33 34 void BeforeStreamingFixture::SwitchToManualMicrophone() { 35 EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_)); 36 37 TEST_LOG("You need to speak manually into the microphone for this test.\n"); 38 TEST_LOG("Please start speaking now.\n"); 39 Sleep(1000); 40 } 41 42 void BeforeStreamingFixture::RestartFakeMicrophone() { 43 EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone( 44 channel_, fake_microphone_input_file_.c_str(), true, true)); 45 } 46 47 void BeforeStreamingFixture::PausePlaying() { 48 EXPECT_EQ(0, voe_base_->StopSend(channel_)); 49 EXPECT_EQ(0, voe_base_->StopPlayout(channel_)); 50 EXPECT_EQ(0, voe_base_->StopReceive(channel_)); 51 } 52 53 void BeforeStreamingFixture::ResumePlaying() { 54 EXPECT_EQ(0, voe_base_->StartReceive(channel_)); 55 EXPECT_EQ(0, voe_base_->StartPlayout(channel_)); 56 EXPECT_EQ(0, voe_base_->StartSend(channel_)); 57 } 58 59 void BeforeStreamingFixture::SetUpLocalPlayback() { 60 transport_ = new LoopBackTransport(voe_network_); 61 EXPECT_EQ(0, voe_network_->RegisterExternalTransport(channel_, *transport_)); 62 63 webrtc::CodecInst codec; 64 codec.channels = 1; 65 codec.pacsize = 160; 66 codec.plfreq = 8000; 67 codec.pltype = 0; 68 codec.rate = 64000; 69 #if defined(_MSC_VER) && defined(_WIN32) 70 _snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE - 1, "PCMU"); 71 #else 72 snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE, "PCMU"); 73 #endif 74 voe_codec_->SetSendCodec(channel_, codec); 75 } 76