From 1e70d8cccfa6d73be27c4fa7f06b0176fd9aee9f Mon Sep 17 00:00:00 2001
From: alexandresavard <alexandresavard@alexandresavard-desktop.(none)>
Date: Fri, 6 Feb 2009 16:33:59 -0500
Subject: [PATCH] Now recording in HOME folder

---
 src/call.cpp                              | 30 +-----------
 src/plug-in/audiorecorder/audiorecord.cpp | 60 +++++++++++++++++++++--
 src/plug-in/audiorecorder/audiorecord.h   | 14 +++++-
 3 files changed, 69 insertions(+), 35 deletions(-)

diff --git a/src/call.cpp b/src/call.cpp
index 1de89c3dda..3130959e94 100644
--- a/src/call.cpp
+++ b/src/call.cpp
@@ -36,39 +36,11 @@ Call::Call(const CallID& id, Call::CallType type)
            , _peerName()
            , _peerNumber()
 {
-    time_t rawtime;
-    struct tm * timeinfo;
-
-    rawtime = std::time(NULL);
-    timeinfo = localtime ( &rawtime );
-
-    std::stringstream out;
-
-    out << timeinfo->tm_year+1900;
-    if (timeinfo->tm_mon < 9) // january is 01, not 1
-      out << 0;
-    out << timeinfo->tm_mon+1;
-    if (timeinfo->tm_mday < 10) // 01 02 03, not 1 2 3
-      out << 0;
-    out << timeinfo->tm_mday;
-    if (timeinfo->tm_hour < 10) // 01 02 03, not 1 2 3
-      out << 0;
-    out << timeinfo->tm_hour;
-    if (timeinfo->tm_min < 10) // 01 02 03, not 1 2 3
-      out << 0;
-    out << timeinfo->tm_min;
-    if (timeinfo->tm_sec < 10) // 01 02 03,  not 1 2 3
-      out << 0;
-    out << timeinfo->tm_sec;
-
-    _filename = out.str();
-
-    printf("Call::constructor filename for this call %s \n",_filename.c_str());
  
     FILE_TYPE fileType = FILE_WAV;
     SOUND_FORMAT soundFormat = INT16;
-    recAudio.setRecordingOption(_filename.c_str(),fileType,soundFormat,44100);
 
+    recAudio.setRecordingOption(fileType,soundFormat,44100);
     _debug("CALL::Constructor for this clss is called \n");    
 }
 
diff --git a/src/plug-in/audiorecorder/audiorecord.cpp b/src/plug-in/audiorecorder/audiorecord.cpp
index 181ed2e78f..fdbe9654ef 100644
--- a/src/plug-in/audiorecorder/audiorecord.cpp
+++ b/src/plug-in/audiorecorder/audiorecord.cpp
@@ -29,6 +29,8 @@ AudioRecord::AudioRecord(){
   recordingEnabled_ = false;
   fp = 0;
 
+  createFilename();
+  
 }
 
 
@@ -36,9 +38,7 @@ void AudioRecord::setSndSamplingRate(int smplRate){
   sndSmplRate_ = smplRate;  
 }
 
-void AudioRecord::setRecordingOption(std::string name, FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate){
-
-  strncpy(fileName_, name.c_str(), 8192);
+void AudioRecord::setRecordingOption(FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate){
  
   fileType_ = type;
   sndFormat_ = format;
@@ -61,10 +61,22 @@ void AudioRecord::setRecordingOption(std::string name, FILE_TYPE type, SOUND_FOR
 
 void AudioRecord::openFile(){
   
+   
    _debug("AudioRecord::openFile()\n");  
   
+   savePath_ = getenv("HOME");
+  
+   std::string fName(fileName_);
+ 
+   savePath_ += "/";
+   
+   
+   savePath_.append(fName);
+  
+
    bool result = false;
    
+   _debug("AudioRecord::openFile()\n");
    if(isFileExist()) {
      _debug("AudioRecord::Filename does not exist, creating one \n");
      byteCounter_ = 0;
@@ -160,9 +172,47 @@ void AudioRecord::stopRecording() {
 }
 
 
+void AudioRecord::createFilename(){
+    
+    time_t rawtime;
+    struct tm * timeinfo;
+
+    rawtime = time(NULL);
+    timeinfo = localtime ( &rawtime );
+
+    stringstream out;
+    
+    // DATE
+    out << timeinfo->tm_year+1900;
+    if (timeinfo->tm_mon < 9) // january is 01, not 1
+      out << 0;
+    out << timeinfo->tm_mon+1;
+    if (timeinfo->tm_mday < 10) // 01 02 03, not 1 2 3
+      out << 0;
+    out << timeinfo->tm_mday;
+ 
+    out << '-';
+   
+    // hour
+    if (timeinfo->tm_hour < 10) // 01 02 03, not 1 2 3
+      out << 0;
+    out << timeinfo->tm_hour;
+    if (timeinfo->tm_min < 10) // 01 02 03, not 1 2 3
+      out << 0;
+    out << timeinfo->tm_min;
+    if (timeinfo->tm_sec < 10) // 01 02 03,  not 1 2 3
+      out << 0;
+    out << timeinfo->tm_sec;
+
+    // fileName_ = out.str();
+    strncpy(fileName_, out.str().c_str(), 8192);
+
+    printf("AudioRecord::createFilename::filename for this call %s \n",fileName_);
+}
+
 bool AudioRecord::setRawFile() {
 
-  fp = fopen(fileName_, "wb");
+  fp = fopen(savePath_.c_str(), "wb");
   if ( !fp ) {
     _debug("AudioRecord::setRawFile() : could not create RAW file!\n");
     return false;
@@ -180,7 +230,7 @@ bool AudioRecord::setRawFile() {
 
 bool AudioRecord::setWavFile() {
   
-  fp = fopen(fileName_, "wb");
+  fp = fopen(savePath_.c_str(), "wb");
   if ( !fp ) {
     _debug("AudioRecord::setWavFile() : could not create WAV file.\n");
     return false;
diff --git a/src/plug-in/audiorecorder/audiorecord.h b/src/plug-in/audiorecorder/audiorecord.h
index 0fd451a03b..83a95936a2 100644
--- a/src/plug-in/audiorecorder/audiorecord.h
+++ b/src/plug-in/audiorecorder/audiorecord.h
@@ -21,6 +21,8 @@
 #include <iostream>
 #include <string.h>
 #include <sndfile.h>
+#include <stdlib.h>
+#include <sstream>
 
 #include "global.h"
 #include "plug-in/plugin.h"
@@ -55,7 +57,7 @@ public:
 
   void setSndSamplingRate(int smplRate);
 
-  void setRecordingOption(std::string name, FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate);
+  void setRecordingOption(FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate);
 
   /** 
    * Check if no otehr file is opened, then create a new one
@@ -113,6 +115,11 @@ public:
 
 protected:
 
+  /**
+   * Create name file according to current date
+   */
+  void createFilename();
+  
   /**
    * Set the header for raw files
    */
@@ -188,5 +195,10 @@ protected:
    */
   char fileName_[8192];
 
+  /**
+   * Path for this recording
+   */
+  std::string savePath_;
+
 
 };
-- 
GitLab