blob: 60ef92bea986a4b67a40e41b3429adfd1f77e7be [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
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stdio.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
kwibergfd8be342016-05-14 19:44:11 -070015#include <cstdlib>
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_device/dummy/file_audio_device.h"
18#include "rtc_base/logging.h"
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000019
20namespace webrtc {
21
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000022bool FileAudioDeviceFactory::_isConfigured = false;
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000023char FileAudioDeviceFactory::_inputAudioFilename[MAX_FILENAME_LEN] = "";
24char FileAudioDeviceFactory::_outputAudioFilename[MAX_FILENAME_LEN] = "";
25
henrika5ff64832017-10-11 15:14:51 +020026FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice() {
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000027 // Bail out here if the files haven't been set explicitly.
noahric6a355902016-08-17 15:19:50 -070028 // audio_device_impl.cc should then fall back to dummy audio.
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000029 if (!_isConfigured) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010030 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.";
noahric6a355902016-08-17 15:19:50 -070034
35 return nullptr;
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000036 }
henrika5ff64832017-10-11 15:14:51 +020037 return new FileAudioDevice(_inputAudioFilename, _outputAudioFilename);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000038}
39
40void FileAudioDeviceFactory::SetFilenamesToUse(
Mirko Bonadei72c42502017-11-09 09:33:23 +010041 const char* inputAudioFilename,
42 const char* outputAudioFilename) {
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000043#ifdef WEBRTC_DUMMY_FILE_DEVICES
kwibergee89e782017-08-09 17:22:01 -070044 RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN);
45 RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000046
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);
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000050 _isConfigured = true;
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000051#else
52 // Sanity: must be compiled with the right define to run this.
Mirko Bonadei72c42502017-11-09 09:33:23 +010053 printf(
54 "Trying to use dummy file devices, but is not compiled "
55 "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n");
kwibergfd8be342016-05-14 19:44:11 -070056 std::exit(1);
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000057#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000058}
59
60} // namespace webrtc