Home | History | Annotate | Download | only in standard
      1 /*
      2  *  Copyright (c) 2012 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/test/testsupport/fileutils.h"
     12 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
     13 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h"
     14 
     15 
     16 class FileTest : public AfterStreamingFixture {
     17  protected:
     18   // Creates the string .pcm.
     19   std::string CreateTrickyFilenameInUtf8() {
     20     char filename[16] = { (char)0xc3, (char)0xa5,
     21                           (char)0xc3, (char)0xa4,
     22                           (char)0xc3, (char)0xb6,
     23                           static_cast<char>(0) };
     24     return std::string(filename) + ".pcm";
     25   }
     26 };
     27 
     28 TEST_F(FileTest, ManualRecordToFileForThreeSecondsAndPlayback) {
     29   if (!FLAGS_include_timing_dependent_tests) {
     30     TEST_LOG("Skipping test - running in slow execution environment...\n");
     31     return;
     32   }
     33 
     34   SwitchToManualMicrophone();
     35 
     36   std::string recording_filename =
     37       webrtc::test::OutputPath() + CreateTrickyFilenameInUtf8();
     38 
     39   TEST_LOG("Recording to %s for 3 seconds.\n", recording_filename.c_str());
     40   EXPECT_EQ(0, voe_file_->StartRecordingMicrophone(recording_filename.c_str()));
     41   Sleep(3000);
     42   EXPECT_EQ(0, voe_file_->StopRecordingMicrophone());
     43 
     44   TEST_LOG("Playing back %s.\n", recording_filename.c_str());
     45   EXPECT_EQ(0, voe_file_->StartPlayingFileLocally(
     46       channel_, recording_filename.c_str()));
     47 
     48   // Play the file to the user and ensure the is-playing-locally.
     49   // The clip is 3 seconds long.
     50   Sleep(250);
     51   EXPECT_EQ(1, voe_file_->IsPlayingFileLocally(channel_));
     52   Sleep(1500);
     53 }
     54 
     55 TEST_F(FileTest, ManualRecordPlayoutToWavFileForThreeSecondsAndPlayback) {
     56   webrtc::CodecInst send_codec;
     57   voe_codec_->GetSendCodec(channel_, send_codec);
     58 
     59   std::string recording_filename =
     60       webrtc::test::OutputPath() + "playout.wav";
     61 
     62   TEST_LOG("Recording playout to %s.\n", recording_filename.c_str());
     63   EXPECT_EQ(0, voe_file_->StartRecordingPlayout(
     64       channel_, recording_filename.c_str(), &send_codec));
     65   Sleep(3000);
     66   EXPECT_EQ(0, voe_file_->StopRecordingPlayout(channel_));
     67 
     68   TEST_LOG("Playing back the recording in looping mode.\n");
     69   EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
     70       channel_, recording_filename.c_str(), true, false,
     71       webrtc::kFileFormatWavFile));
     72 
     73   Sleep(2000);
     74   EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
     75   Sleep(2000);
     76   // We should still be playing since we're looping.
     77   EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
     78 }
     79