• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "modules/audio_device/dummy/file_audio_device_factory.h"
12 
13 #include <stdio.h>
14 
15 #include <cstdlib>
16 
17 #include "modules/audio_device/dummy/file_audio_device.h"
18 #include "rtc_base/logging.h"
19 
20 namespace webrtc {
21 
22 bool FileAudioDeviceFactory::_isConfigured = false;
23 char FileAudioDeviceFactory::_inputAudioFilename[MAX_FILENAME_LEN] = "";
24 char FileAudioDeviceFactory::_outputAudioFilename[MAX_FILENAME_LEN] = "";
25 
CreateFileAudioDevice()26 FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice() {
27   // Bail out here if the files haven't been set explicitly.
28   // audio_device_impl.cc should then fall back to dummy audio.
29   if (!_isConfigured) {
30     RTC_LOG(LS_WARNING)
31         << "WebRTC configured with WEBRTC_DUMMY_FILE_DEVICES but "
32            "no device files supplied. Will fall back to dummy "
33            "audio.";
34 
35     return nullptr;
36   }
37   return new FileAudioDevice(_inputAudioFilename, _outputAudioFilename);
38 }
39 
SetFilenamesToUse(const char * inputAudioFilename,const char * outputAudioFilename)40 void FileAudioDeviceFactory::SetFilenamesToUse(
41     const char* inputAudioFilename,
42     const char* outputAudioFilename) {
43 #ifdef WEBRTC_DUMMY_FILE_DEVICES
44   RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN);
45   RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN);
46 
47   // Copy the strings since we don't know the lifetime of the input pointers.
48   strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN);
49   strncpy(_outputAudioFilename, outputAudioFilename, MAX_FILENAME_LEN);
50   _isConfigured = true;
51 #else
52   // Sanity: must be compiled with the right define to run this.
53   printf(
54       "Trying to use dummy file devices, but is not compiled "
55       "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n");
56   std::exit(1);
57 #endif
58 }
59 
60 }  // namespace webrtc
61