blob: 6b38d8bc055ae8530d1e5285baf705d22aa0b8fb [file] [log] [blame]
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_device/dummy/file_audio_device_factory.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000012
kwibergfd8be342016-05-14 19:44:11 -070013#include <cstdlib>
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000014#include <cstring>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_device/dummy/file_audio_device.h"
17#include "rtc_base/logging.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000018
19namespace webrtc {
20
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000021bool FileAudioDeviceFactory::_isConfigured = false;
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000022char FileAudioDeviceFactory::_inputAudioFilename[MAX_FILENAME_LEN] = "";
23char FileAudioDeviceFactory::_outputAudioFilename[MAX_FILENAME_LEN] = "";
24
henrika5ff64832017-10-11 15:14:51 +020025FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice() {
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000026 // Bail out here if the files haven't been set explicitly.
noahric6a355902016-08-17 15:19:50 -070027 // audio_device_impl.cc should then fall back to dummy audio.
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000028 if (!_isConfigured) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010029 RTC_LOG(LS_WARNING)
30 << "WebRTC configured with WEBRTC_DUMMY_FILE_DEVICES but "
31 << "no device files supplied. Will fall back to dummy "
32 << "audio.";
noahric6a355902016-08-17 15:19:50 -070033
34 return nullptr;
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000035 }
henrika5ff64832017-10-11 15:14:51 +020036 return new FileAudioDevice(_inputAudioFilename, _outputAudioFilename);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000037}
38
39void FileAudioDeviceFactory::SetFilenamesToUse(
Mirko Bonadei72c42502017-11-09 09:33:23 +010040 const char* inputAudioFilename,
41 const char* outputAudioFilename) {
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000042#ifdef WEBRTC_DUMMY_FILE_DEVICES
kwibergee89e782017-08-09 17:22:01 -070043 RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN);
44 RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000045
46 // Copy the strings since we don't know the lifetime of the input pointers.
47 strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN);
48 strncpy(_outputAudioFilename, outputAudioFilename, MAX_FILENAME_LEN);
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000049 _isConfigured = true;
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000050#else
51 // Sanity: must be compiled with the right define to run this.
Mirko Bonadei72c42502017-11-09 09:33:23 +010052 printf(
53 "Trying to use dummy file devices, but is not compiled "
54 "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n");
kwibergfd8be342016-05-14 19:44:11 -070055 std::exit(1);
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000056#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000057}
58
59} // namespace webrtc