phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_device/dummy/file_audio_device_factory.h" |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stdio.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 14 | |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 15 | #include <cstdlib> |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_device/dummy/file_audio_device.h" |
| 18 | #include "rtc_base/logging.h" |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
phoglund@webrtc.org | 5c9f69f | 2015-03-12 10:27:52 +0000 | [diff] [blame] | 22 | bool FileAudioDeviceFactory::_isConfigured = false; |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 23 | char FileAudioDeviceFactory::_inputAudioFilename[MAX_FILENAME_LEN] = ""; |
| 24 | char FileAudioDeviceFactory::_outputAudioFilename[MAX_FILENAME_LEN] = ""; |
| 25 | |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 26 | FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice() { |
phoglund@webrtc.org | 5c9f69f | 2015-03-12 10:27:52 +0000 | [diff] [blame] | 27 | // Bail out here if the files haven't been set explicitly. |
noahric | 6a35590 | 2016-08-17 15:19:50 -0700 | [diff] [blame] | 28 | // audio_device_impl.cc should then fall back to dummy audio. |
phoglund@webrtc.org | 5c9f69f | 2015-03-12 10:27:52 +0000 | [diff] [blame] | 29 | if (!_isConfigured) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 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."; |
noahric | 6a35590 | 2016-08-17 15:19:50 -0700 | [diff] [blame] | 34 | |
| 35 | return nullptr; |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 36 | } |
henrika | 5ff6483 | 2017-10-11 15:14:51 +0200 | [diff] [blame] | 37 | return new FileAudioDevice(_inputAudioFilename, _outputAudioFilename); |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void FileAudioDeviceFactory::SetFilenamesToUse( |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 41 | const char* inputAudioFilename, |
| 42 | const char* outputAudioFilename) { |
phoglund@webrtc.org | 241a9b0 | 2014-07-08 11:48:37 +0000 | [diff] [blame] | 43 | #ifdef WEBRTC_DUMMY_FILE_DEVICES |
kwiberg | ee89e78 | 2017-08-09 17:22:01 -0700 | [diff] [blame] | 44 | RTC_DCHECK_LT(strlen(inputAudioFilename), MAX_FILENAME_LEN); |
| 45 | RTC_DCHECK_LT(strlen(outputAudioFilename), MAX_FILENAME_LEN); |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 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); |
phoglund@webrtc.org | 5c9f69f | 2015-03-12 10:27:52 +0000 | [diff] [blame] | 50 | _isConfigured = true; |
phoglund@webrtc.org | 241a9b0 | 2014-07-08 11:48:37 +0000 | [diff] [blame] | 51 | #else |
| 52 | // Sanity: must be compiled with the right define to run this. |
Mirko Bonadei | 72c4250 | 2017-11-09 09:33:23 +0100 | [diff] [blame] | 53 | printf( |
| 54 | "Trying to use dummy file devices, but is not compiled " |
| 55 | "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n"); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 56 | std::exit(1); |
phoglund@webrtc.org | 241a9b0 | 2014-07-08 11:48:37 +0000 | [diff] [blame] | 57 | #endif |
phoglund@webrtc.org | 8454ad1 | 2014-06-11 14:12:04 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace webrtc |