blob: 9056646812e181c71730166dae682943262b4e57 [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
25FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice(
26 const int32_t id) {
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) {
noahric6a355902016-08-17 15:19:50 -070030 LOG(LS_WARNING) << "WebRTC configured with WEBRTC_DUMMY_FILE_DEVICES but "
31 << "no device files supplied. Will fall back to dummy "
32 << "audio.";
33
34 return nullptr;
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000035 }
36 return new FileAudioDevice(id, _inputAudioFilename, _outputAudioFilename);
37}
38
39void FileAudioDeviceFactory::SetFilenamesToUse(
40 const char* inputAudioFilename, const char* outputAudioFilename) {
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000041#ifdef WEBRTC_DUMMY_FILE_DEVICES
kwibergee89e782017-08-09 17:22:01 -070042 RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN);
43 RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000044
45 // Copy the strings since we don't know the lifetime of the input pointers.
46 strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN);
47 strncpy(_outputAudioFilename, outputAudioFilename, MAX_FILENAME_LEN);
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000048 _isConfigured = true;
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000049#else
50 // Sanity: must be compiled with the right define to run this.
51 printf("Trying to use dummy file devices, but is not compiled "
52 "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n");
kwibergfd8be342016-05-14 19:44:11 -070053 std::exit(1);
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000054#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000055}
56
57} // namespace webrtc