blob: 96e3eaf94b36b74c6fcbf7ea683786885ae45ff8 [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) {
noahric6a355902016-08-17 15:19:50 -070029 LOG(LS_WARNING) << "WebRTC configured with WEBRTC_DUMMY_FILE_DEVICES but "
30 << "no device files supplied. Will fall back to dummy "
31 << "audio.";
32
33 return nullptr;
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000034 }
henrika5ff64832017-10-11 15:14:51 +020035 return new FileAudioDevice(_inputAudioFilename, _outputAudioFilename);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000036}
37
38void FileAudioDeviceFactory::SetFilenamesToUse(
39 const char* inputAudioFilename, const char* outputAudioFilename) {
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000040#ifdef WEBRTC_DUMMY_FILE_DEVICES
kwibergee89e782017-08-09 17:22:01 -070041 RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN);
42 RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN);
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000043
44 // Copy the strings since we don't know the lifetime of the input pointers.
45 strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN);
46 strncpy(_outputAudioFilename, outputAudioFilename, MAX_FILENAME_LEN);
phoglund@webrtc.org5c9f69f2015-03-12 10:27:52 +000047 _isConfigured = true;
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000048#else
49 // Sanity: must be compiled with the right define to run this.
50 printf("Trying to use dummy file devices, but is not compiled "
51 "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n");
kwibergfd8be342016-05-14 19:44:11 -070052 std::exit(1);
phoglund@webrtc.org241a9b02014-07-08 11:48:37 +000053#endif
phoglund@webrtc.org8454ad12014-06-11 14:12:04 +000054}
55
56} // namespace webrtc