Home | History | Annotate | Download | only in dummy
      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 
     11 #include "webrtc/modules/audio_device/dummy/file_audio_device_factory.h"
     12 
     13 #include <cstring>
     14 
     15 #include "webrtc/modules/audio_device/dummy/file_audio_device.h"
     16 
     17 namespace webrtc {
     18 
     19 bool FileAudioDeviceFactory::_isConfigured = false;
     20 char FileAudioDeviceFactory::_inputAudioFilename[MAX_FILENAME_LEN] = "";
     21 char FileAudioDeviceFactory::_outputAudioFilename[MAX_FILENAME_LEN] = "";
     22 
     23 FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice(
     24     const int32_t id) {
     25   // Bail out here if the files haven't been set explicitly.
     26   if (!_isConfigured) {
     27     printf("Was compiled with WEBRTC_DUMMY_AUDIO_PLAY_STATIC_FILE "
     28            "but did not set input/output files to use. Bailing out.\n");
     29     exit(1);
     30   }
     31   return new FileAudioDevice(id, _inputAudioFilename, _outputAudioFilename);
     32 }
     33 
     34 void FileAudioDeviceFactory::SetFilenamesToUse(
     35     const char* inputAudioFilename, const char* outputAudioFilename) {
     36 #ifdef WEBRTC_DUMMY_FILE_DEVICES
     37   assert(strlen(inputAudioFilename) < MAX_FILENAME_LEN &&
     38          strlen(outputAudioFilename) < MAX_FILENAME_LEN);
     39 
     40   // Copy the strings since we don't know the lifetime of the input pointers.
     41   strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN);
     42   strncpy(_outputAudioFilename, outputAudioFilename, MAX_FILENAME_LEN);
     43   _isConfigured = true;
     44 #else
     45   // Sanity: must be compiled with the right define to run this.
     46   printf("Trying to use dummy file devices, but is not compiled "
     47          "with WEBRTC_DUMMY_FILE_DEVICES. Bailing out.\n");
     48   exit(1);
     49 #endif
     50 }
     51 
     52 }  // namespace webrtc
     53