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
BeforeStreamingFixture()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
~BeforeStreamingFixture()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
SwitchToManualMicrophone()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
RestartFakeMicrophone()42 void BeforeStreamingFixture::RestartFakeMicrophone() {
43 EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
44 channel_, fake_microphone_input_file_.c_str(), true, true));
45 }
46
PausePlaying()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
ResumePlaying()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
WaitForTransmittedPackets(int32_t packet_count)59 void BeforeStreamingFixture::WaitForTransmittedPackets(int32_t packet_count) {
60 transport_->WaitForTransmittedPackets(packet_count);
61 }
62
SetUpLocalPlayback()63 void BeforeStreamingFixture::SetUpLocalPlayback() {
64 transport_ = new LoopBackTransport(voe_network_, channel_);
65 EXPECT_EQ(0, voe_network_->RegisterExternalTransport(channel_, *transport_));
66
67 webrtc::CodecInst codec;
68 codec.channels = 1;
69 codec.pacsize = 160;
70 codec.plfreq = 8000;
71 codec.pltype = 0;
72 codec.rate = 64000;
73 #if defined(_MSC_VER) && defined(_WIN32)
74 _snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE - 1, "PCMU");
75 #else
76 snprintf(codec.plname, RTP_PAYLOAD_NAME_SIZE, "PCMU");
77 #endif
78 voe_codec_->SetSendCodec(channel_, codec);
79 }
80