Update the dummy file_audio_video_device to allow empty file name

Landing this on behalf of malmnas@.

The semantics is as follows:

* if the output filename is empty, then don't log to file
* if the input filename is empty, then don't stream any audio from file

This is useful for long running tests with multiple participants.
With logging turned on, having 10 bots running for 2 hours results in
more then 7 GB of data.

BUG=None
R=henrika@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/41219004

Cr-Commit-Position: refs/heads/master@{#8691}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8691 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.cc b/webrtc/modules/audio_device/dummy/file_audio_device.cc
index 182c43d..28dc389 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device.cc
+++ b/webrtc/modules/audio_device/dummy/file_audio_device.cc
@@ -25,7 +25,7 @@
 
 FileAudioDevice::FileAudioDevice(const int32_t id,
                                  const char* inputFilename,
-                                 const char* outputFile):
+                                 const char* outputFilename):
     _ptrAudioBuffer(NULL),
     _recordingBuffer(NULL),
     _playoutBuffer(NULL),
@@ -45,17 +45,21 @@
     _lastCallRecordMillis(0),
     _outputFile(*FileWrapper::Create()),
     _inputFile(*FileWrapper::Create()),
-    _outputFilename(outputFile),
+    _outputFilename(outputFilename),
     _inputFilename(inputFilename),
     _clock(Clock::GetRealTimeClock()) {
 }
 
 FileAudioDevice::~FileAudioDevice() {
-  _outputFile.Flush();
-  _outputFile.CloseFile();
+  if (_outputFile.Open()) {
+      _outputFile.Flush();
+      _outputFile.CloseFile();
+  }
   delete &_outputFile;
-  _inputFile.Flush();
-  _inputFile.CloseFile();
+  if (_inputFile.Open()) {
+      _inputFile.Flush();
+      _inputFile.CloseFile();
+  }
   delete &_inputFile;
 }
 
@@ -144,8 +148,7 @@
 }
 
 int32_t FileAudioDevice::InitPlayout() {
-  if (_ptrAudioBuffer)
-  {
+  if (_ptrAudioBuffer) {
       // Update webrtc audio buffer with the selected parameters
       _ptrAudioBuffer->SetPlayoutSampleRate(kPlayoutFixedSampleRate);
       _ptrAudioBuffer->SetPlayoutChannels(kPlayoutNumChannels);
@@ -187,21 +190,20 @@
 }
 
 int32_t FileAudioDevice::StartPlayout() {
-  if (_playing)
-  {
+  if (_playing) {
       return 0;
   }
 
+  _playoutFramesIn10MS = kPlayoutFixedSampleRate/100;
   _playing = true;
   _playoutFramesLeft = 0;
-  _playoutFramesIn10MS = kPlayoutFixedSampleRate/100;
 
-  if (!_playoutBuffer)
+  if (!_playoutBuffer) {
       _playoutBuffer = new int8_t[2 *
                                   kPlayoutNumChannels *
                                   kPlayoutFixedSampleRate/100];
-  if (!_playoutBuffer)
-  {
+  }
+  if (!_playoutBuffer) {
     _playing = false;
     return -1;
   }
@@ -212,17 +214,16 @@
                                                 this,
                                                 kRealtimePriority,
                                                 threadName);
-  if (_ptrThreadPlay == NULL)
-  {
+  if (_ptrThreadPlay == NULL) {
       _playing = false;
       delete [] _playoutBuffer;
       _playoutBuffer = NULL;
       return -1;
   }
 
-  if (_outputFile.OpenFile(_outputFilename.c_str(),
-                           false, false, false) == -1) {
-    printf("Failed to open playout file %s!", _outputFilename.c_str());
+  if (!_outputFilename.empty() && _outputFile.OpenFile(
+        _outputFilename.c_str(), false, false, false) == -1) {
+    printf("Failed to open playout file %s!\n", _outputFilename.c_str());
     _playing = false;
     delete [] _playoutBuffer;
     _playoutBuffer = NULL;
@@ -230,8 +231,7 @@
   }
 
   unsigned int threadID(0);
-  if (!_ptrThreadPlay->Start(threadID))
-  {
+  if (!_ptrThreadPlay->Start(threadID)) {
       _playing = false;
       delete _ptrThreadPlay;
       _ptrThreadPlay = NULL;
@@ -251,11 +251,9 @@
   }
 
   // stop playout thread first
-  if (_ptrThreadPlay && !_ptrThreadPlay->Stop())
-  {
+  if (_ptrThreadPlay && !_ptrThreadPlay->Stop()) {
       return -1;
-  }
-  else {
+  } else {
       delete _ptrThreadPlay;
       _ptrThreadPlay = NULL;
   }
@@ -265,8 +263,10 @@
   _playoutFramesLeft = 0;
   delete [] _playoutBuffer;
   _playoutBuffer = NULL;
-  _outputFile.Flush();
-  _outputFile.CloseFile();
+  if (_outputFile.Open()) {
+      _outputFile.Flush();
+      _outputFile.CloseFile();
+  }
    return 0;
 }
 
@@ -285,8 +285,8 @@
       _recordingBuffer = new int8_t[_recordingBufferSizeIn10MS];
   }
 
-  if (_inputFile.OpenFile(_inputFilename.c_str(), true,
-                              true, false) == -1) {
+  if (!_inputFilename.empty() && _inputFile.OpenFile(
+        _inputFilename.c_str(), true, true, false) == -1) {
     printf("Failed to open audio input file %s!\n",
            _inputFilename.c_str());
     _recording = false;
@@ -300,8 +300,7 @@
                                               this,
                                               kRealtimePriority,
                                               threadName);
-  if (_ptrThreadRec == NULL)
-  {
+  if (_ptrThreadRec == NULL) {
       _recording = false;
       delete [] _recordingBuffer;
       _recordingBuffer = NULL;
@@ -309,8 +308,7 @@
   }
 
   unsigned int threadID(0);
-  if (!_ptrThreadRec->Start(threadID))
-  {
+  if (!_ptrThreadRec->Start(threadID)) {
       _recording = false;
       delete _ptrThreadRec;
       _ptrThreadRec = NULL;
@@ -330,19 +328,16 @@
     _recording = false;
   }
 
-  if (_ptrThreadRec && !_ptrThreadRec->Stop())
-  {
+  if (_ptrThreadRec && !_ptrThreadRec->Stop()) {
       return -1;
-  }
-  else {
+  } else {
       delete _ptrThreadRec;
       _ptrThreadRec = NULL;
   }
 
   CriticalSectionScoped lock(&_critSect);
   _recordingFramesLeft = 0;
-  if (_recordingBuffer)
-  {
+  if (_recordingBuffer) {
       delete [] _recordingBuffer;
       _recordingBuffer = NULL;
   }
@@ -528,15 +523,14 @@
 
 bool FileAudioDevice::PlayThreadProcess()
 {
-    if(!_playing)
+    if(!_playing) {
         return false;
-
+    }
     uint64_t currentTime = _clock->CurrentNtpInMilliseconds();
     _critSect.Enter();
 
     if (_lastCallPlayoutMillis == 0 ||
-        currentTime - _lastCallPlayoutMillis >= 10)
-    {
+        currentTime - _lastCallPlayoutMillis >= 10) {
         _critSect.Leave();
         _ptrAudioBuffer->RequestPlayoutData(_playoutFramesIn10MS);
         _critSect.Enter();
@@ -557,8 +551,9 @@
 
 bool FileAudioDevice::RecThreadProcess()
 {
-    if (!_recording)
+    if (!_recording) {
         return false;
+    }
 
     uint64_t currentTime = _clock->CurrentNtpInMilliseconds();
     _critSect.Enter();
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc b/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc
index 5e25230..2a6ac1f 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc
+++ b/webrtc/modules/audio_device/dummy/file_audio_device_factory.cc
@@ -16,13 +16,14 @@
 
 namespace webrtc {
 
+bool FileAudioDeviceFactory::_isConfigured = false;
 char FileAudioDeviceFactory::_inputAudioFilename[MAX_FILENAME_LEN] = "";
 char FileAudioDeviceFactory::_outputAudioFilename[MAX_FILENAME_LEN] = "";
 
 FileAudioDevice* FileAudioDeviceFactory::CreateFileAudioDevice(
     const int32_t id) {
-  // Bail out here if the files aren't set.
-  if (strlen(_inputAudioFilename) == 0 || strlen(_outputAudioFilename) == 0) {
+  // Bail out here if the files haven't been set explicitly.
+  if (!_isConfigured) {
     printf("Was compiled with WEBRTC_DUMMY_AUDIO_PLAY_STATIC_FILE "
            "but did not set input/output files to use. Bailing out.\n");
     exit(1);
@@ -39,6 +40,7 @@
   // Copy the strings since we don't know the lifetime of the input pointers.
   strncpy(_inputAudioFilename, inputAudioFilename, MAX_FILENAME_LEN);
   strncpy(_outputAudioFilename, outputAudioFilename, MAX_FILENAME_LEN);
+  _isConfigured = true;
 #else
   // Sanity: must be compiled with the right define to run this.
   printf("Trying to use dummy file devices, but is not compiled "
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device_factory.h b/webrtc/modules/audio_device/dummy/file_audio_device_factory.h
index 9975d7b..96cab67 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device_factory.h
+++ b/webrtc/modules/audio_device/dummy/file_audio_device_factory.h
@@ -32,6 +32,7 @@
 
  private:
   static const uint32_t MAX_FILENAME_LEN = 256;
+  static bool _isConfigured;
   static char _inputAudioFilename[MAX_FILENAME_LEN];
   static char _outputAudioFilename[MAX_FILENAME_LEN];
 };