Commit 00d8956c authored by Alexandre Savard's avatar Alexandre Savard

Revert "Merge branch 'master' of git+ssh://git.sflphone.org/var/repos/sflphone/git/sflphone"

This reverts commit a4256fcb, reversing
changes made to aa2dd717.
parent a4256fcb
......@@ -64,10 +64,6 @@ class AudioLayer {
AudioLayer();
virtual ~AudioLayer();
/**
* Function that returns the list of available audio device provided the stream
* type: AUDIO_STREAM_CAPTURE, AUDIO_STREAM_PLAYBACK.
*/
virtual std::vector<std::string> getAudioDeviceList(AudioStreamDirection dir) const = 0;
/**
......
......@@ -29,7 +29,7 @@
*/
#include "audiorecord.h"
#include <cstring> // for strstr
#include <unistd.h>
#include <sstream> // for stringstream
// structure for the wave header
......@@ -50,7 +50,6 @@ struct wavhdr {
SINT32 data_length; // in bytes
};
AudioRecord::AudioRecord() : fileHandle_(NULL)
, fileType_(FILE_INVALID)
, channels_(1)
......@@ -63,6 +62,7 @@ AudioRecord::AudioRecord() : fileHandle_(NULL)
, mixBuffer_(new SFLDataFormat[nbSamplesMax_])
, micBuffer_(new SFLDataFormat[nbSamplesMax_])
, spkBuffer_(new SFLDataFormat[nbSamplesMax_])
, filename_()
, savePath_()
{
createFilename();
......@@ -93,21 +93,19 @@ void AudioRecord::setRecordingOption(FILE_TYPE type, int sndSmplRate, const std:
savePath_ = path + "/";
}
void AudioRecord::initFileName(std::string peerNumber)
void AudioRecord::initFilename(const std::string &peerNumber)
{
std::string fName = fileName_;
std::string fName(filename_);
fName.append("-" + peerNumber);
if (fileType_ == FILE_RAW) {
if (strstr(fileName_, ".raw") == NULL) {
DEBUG("AudioRecord: concatenate .raw file extension: name : %s", fileName_);
if (filename_.find(".raw") == std::string::npos) {
DEBUG("AudioRecord: concatenate .raw file extension: name : %s", filename_.c_str());
fName.append(".raw");
}
} else if (fileType_ == FILE_WAV) {
if (strstr(fileName_, ".wav") == NULL) {
DEBUG("AudioRecord: concatenate .wav file extension: name : %s", fileName_);
if (filename_.find(".wav") == std::string::npos) {
DEBUG("AudioRecord: concatenate .wav file extension: name : %s", filename_.c_str());
fName.append(".wav");
}
}
......@@ -115,7 +113,7 @@ void AudioRecord::initFileName(std::string peerNumber)
savePath_.append(fName);
}
std::string AudioRecord::getFileName()
std::string AudioRecord::getFilename() const
{
return savePath_;
}
......@@ -145,7 +143,6 @@ bool AudioRecord::openFile()
return result;
}
void AudioRecord::closeFile()
{
if (fileHandle_ == 0) return;
......@@ -153,20 +150,17 @@ void AudioRecord::closeFile()
if (fileType_ == FILE_RAW)
fclose(fileHandle_);
else if (fileType_ == FILE_WAV)
this->closeWavFile();
closeWavFile();
}
bool AudioRecord::isOpenFile()
bool AudioRecord::isOpenFile() const
{
return fileHandle_ != 0;
}
bool AudioRecord::fileExists()
bool AudioRecord::fileExists() const
{
DEBUG("AudioRecord: Trying to open %s ", fileName_);
return fopen(fileName_,"rb") != 0;
return access(savePath_.c_str(), F_OK) != -1;
}
bool AudioRecord::isRecording() const
......@@ -174,7 +168,6 @@ bool AudioRecord::isRecording() const
return recordingEnabled_;
}
bool AudioRecord::setRecording()
{
if (isOpenFile()) {
......@@ -201,7 +194,6 @@ void AudioRecord::stopRecording()
recordingEnabled_ = false;
}
void AudioRecord::createFilename()
{
time_t rawtime;
......@@ -214,7 +206,7 @@ void AudioRecord::createFilename()
std::stringstream out;
// DATE
out << timeinfo->tm_year+1900;
out << timeinfo->tm_year + 1900;
if (timeinfo->tm_mon < 9) // january is 01, not 1
out << 0;
......@@ -247,11 +239,9 @@ void AudioRecord::createFilename()
out << 0;
out << timeinfo->tm_sec;
filename_ = out.str();
// fileName_ = out.str();
strncpy(fileName_, out.str().c_str(), 8192);
DEBUG("AudioRecord: create filename for this call %s ", fileName_);
DEBUG("AudioRecord: create filename for this call %s ", filename_.c_str());
}
bool AudioRecord::setRawFile()
......@@ -268,7 +258,6 @@ bool AudioRecord::setRawFile()
return true;
}
bool AudioRecord::setWavFile()
{
DEBUG("AudioRecord: Create new wave file %s, sampling rate: %d", savePath_.c_str(), sndSmplRate_);
......@@ -311,10 +300,9 @@ bool AudioRecord::setWavFile()
return true;
}
bool AudioRecord::openExistingRawFile()
{
fileHandle_ = fopen(fileName_, "ab+");
fileHandle_ = fopen(filename_.c_str(), "ab+");
if (!fileHandle_) {
WARN("AudioRecord: could not create RAW file!");
......@@ -324,12 +312,11 @@ bool AudioRecord::openExistingRawFile()
return true;
}
bool AudioRecord::openExistingWavFile()
{
DEBUG("%s(%s)\n", __PRETTY_FUNCTION__, fileName_);
DEBUG("%s(%s)\n", __PRETTY_FUNCTION__, filename_.c_str());
fileHandle_ = fopen(fileName_, "rb+");
fileHandle_ = fopen(filename_.c_str(), "rb+");
if (!fileHandle_) {
WARN("AudioRecord: Error: could not open WAV file!");
......@@ -349,7 +336,7 @@ bool AudioRecord::openExistingWavFile()
if (fclose(fileHandle_) != 0)
WARN("AudioRecord: Error: Can't close file r+ ");
fileHandle_ = fopen(fileName_, "ab+");
fileHandle_ = fopen(filename_.c_str(), "ab+");
if (!fileHandle_) {
WARN("AudioRecord: Error: Could not createopen WAV file ab+!");
......@@ -410,7 +397,6 @@ void AudioRecord::recSpkrData(SFLDataFormat* buffer, int nSamples)
}
}
void AudioRecord::recMicData(SFLDataFormat* buffer, int nSamples)
{
if (recordingEnabled_) {
......@@ -422,7 +408,6 @@ void AudioRecord::recMicData(SFLDataFormat* buffer, int nSamples)
}
}
void AudioRecord::recData(SFLDataFormat* buffer, int nSamples)
{
if (recordingEnabled_) {
......@@ -440,7 +425,6 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples)
}
}
void AudioRecord::recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2,
int nSamples_1, int /*nSamples_2*/)
{
......
......@@ -57,16 +57,16 @@ class AudioRecord {
/**
* Init recording file path
*/
void initFileName(std::string peerNumber);
void initFilename(const std::string &peerNumber);
/**
* Return the filepath of the recording
*/
std::string getFileName();
std::string getFilename() const;
/**
* Check if no otehr file is opened, then create a new one
* @param fileName A string containing teh file (with/without extension)
* @param filename A string containing teh file (with/without extension)
* @param type The sound file format (FILE_RAW, FILE_WAVE)
* @param format Internal sound format (INT16 / INT32)
* @return bool True if file was opened
......@@ -81,12 +81,12 @@ class AudioRecord {
/**
* Check if a file is already opened
*/
bool isOpenFile();
bool isOpenFile() const;
/**
* Check if a file already exists
*/
bool fileExists();
bool fileExists() const;
/**
* Check recording state
......@@ -231,7 +231,7 @@ class AudioRecord {
/**
* Filename for this recording
*/
char fileName_[8192];
std::string filename_;
/**
* Path for this recording
......
......@@ -189,16 +189,12 @@ bool PulseLayer::inSourceList(const std::string &deviceName) const
std::vector<std::string> PulseLayer::getAudioDeviceList(AudioStreamDirection dir) const
{
std::vector<std::string> emptyVector;
if(AUDIO_STREAM_CAPTURE == dir) {
return sinkList_;
}
else if(AUDIO_STREAM_PLAYBACK == dir) {
if(AUDIO_STREAM_PLAYBACK) {
return sourceList_;
}
return emptyVector;
}
void PulseLayer::createStreams(pa_context* c)
......
......@@ -30,33 +30,33 @@
#include "recordable.h"
#include "manager.h"
Recordable::Recordable() : recAudio(), recorder(&recAudio, Manager::instance().getMainBuffer())
Recordable::Recordable() : recAudio_(), recorder_(&recAudio_, Manager::instance().getMainBuffer())
{
recAudio.setRecordingOption(AudioRecord::FILE_WAV, 8000, Manager::instance().audioPreference.getRecordpath());
recAudio_.setRecordingOption(AudioRecord::FILE_WAV, 8000, Manager::instance().audioPreference.getRecordpath());
}
Recordable::~Recordable()
{
if (recAudio.isOpenFile())
recAudio.closeFile();
if (recAudio_.isOpenFile())
recAudio_.closeFile();
}
void Recordable::initRecFileName(std::string filename)
void Recordable::initRecFilename(const std::string &filename)
{
recAudio.initFileName(filename);
recAudio_.initFilename(filename);
}
std::string Recordable::getFileName()
std::string Recordable::getFilename() const
{
return recAudio.getFileName();
return recAudio_.getFilename();
}
void Recordable::setRecordingSmplRate(int smplRate)
{
recAudio.setSndSamplingRate(smplRate);
recAudio_.setSndSamplingRate(smplRate);
}
int Recordable::getRecordingSmplRate() const
{
return recAudio.getSndSamplingRate();
return recAudio_.getSndSamplingRate();
}
......@@ -43,8 +43,8 @@ class Recordable {
/**
* Return recording state (true/false)
*/
bool isRecording() {
return recAudio.isRecording();
bool isRecording() const {
return recAudio_.isRecording();
}
/**
......@@ -57,18 +57,18 @@ class Recordable {
* Stop recording
*/
void stopRecording() {
recAudio.stopRecording();
recAudio_.stopRecording();
}
/**
* Init the recording file name according to path specified in configuration
*/
void initRecFileName(std::string filename);
void initRecFilename(const std::string &filename);
/**
* Return the file path for this recording
*/
std::string getFileName();
virtual std::string getFilename() const;
/**
* Set recording sampling rate.
......@@ -82,16 +82,13 @@ class Recordable {
/**
* Virtual method to be implemented in order to the main
* buffer to retreive the recorded id.
* buffer to retrieve the recorded id.
*/
virtual std::string getRecFileId() const = 0;
/**
* An instance of audio recorder
*/
AudioRecord recAudio;
AudioRecorder recorder;
protected:
AudioRecord recAudio_;
AudioRecorder recorder_;
};
#endif
......@@ -31,6 +31,7 @@
#include "call.h"
#include "manager.h"
#include "audio/mainbuffer.h"
#include "history/historyitem.h"
const char * const Call::DEFAULT_ID = "audiolayer_id";
......@@ -41,13 +42,16 @@ Call::Call(const std::string& id, Call::CallType type)
, id_(id)
, confID_()
, type_(type)
, connectionState_(Call::Disconnected)
, callState_(Call::Inactive)
, callConfig_(Call::Classic)
, peerName_()
, connectionState_(Call::DISCONNECTED)
, callState_(Call::INACTIVE)
, isIPToIP_(false)
, peerNumber_()
, displayName_()
{}
, timestamp_start_(0)
, timestamp_stop_(0)
{
time(&timestamp_start_);
}
Call::~Call()
{}
......@@ -66,7 +70,6 @@ Call::getConnectionState()
return connectionState_;
}
void
Call::setState(CallState state)
{
......@@ -85,34 +88,34 @@ std::string
Call::getStateStr()
{
switch (getState()) {
case Active:
case ACTIVE:
switch (getConnectionState()) {
case Ringing:
case RINGING:
return isIncoming() ? "INCOMING" : "RINGING";
case Connected:
case CONNECTED:
default:
return isRecording() ? "RECORD" : "CURRENT";
}
case Hold:
case HOLD:
return "HOLD";
case Busy:
case BUSY:
return "BUSY";
case Inactive:
case INACTIVE:
switch (getConnectionState()) {
case Ringing:
case RINGING:
return isIncoming() ? "INCOMING" : "RINGING";
case Connected:
case CONNECTED:
return "CURRENT";
default:
return "INACTIVE";
}
case Conferencing:
case CONFERENCING:
return "CONFERENCING";
case Refused:
case Error:
case REFUSED:
case ERROR:
default:
return "FAILURE";
}
......@@ -136,17 +139,17 @@ Call::getLocalAudioPort()
bool
Call::setRecording()
{
bool recordStatus = Recordable::recAudio.isRecording();
bool recordStatus = Recordable::recAudio_.isRecording();
Recordable::recAudio.setRecording();
Recordable::recAudio_.setRecording();
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
std::string process_id = Recordable::recorder.getRecorderID();
std::string process_id = Recordable::recorder_.getRecorderID();
if (!recordStatus) {
mbuffer->bindHalfDuplexOut(process_id, id_);
mbuffer->bindHalfDuplexOut(process_id);
Recordable::recorder.start();
Recordable::recorder_.start();
} else {
mbuffer->unBindHalfDuplexOut(process_id, id_);
mbuffer->unBindHalfDuplexOut(process_id);
......@@ -156,3 +159,44 @@ Call::setRecording()
return recordStatus;
}
void Call::time_stop()
{
time(&timestamp_stop_);
}
std::string Call::getTypeStr() const
{
switch (type_) {
case INCOMING:
return "incoming";
case OUTGOING:
return "outgoing";
case MISSED:
return "missed";
default:
return "";
}
}
std::map<std::string, std::string> Call::createHistoryEntry() const
{
std::map<std::string, std::string> result;
result[HistoryItem::ACCOUNT_ID_KEY] = Manager::instance().getAccountFromCall(id_);
result[HistoryItem::CONFID_KEY] = confID_;
result[HistoryItem::CALLID_KEY] = id_;
result[HistoryItem::DISPLAY_NAME_KEY] = displayName_;
result[HistoryItem::PEER_NUMBER_KEY] = peerNumber_;
result[HistoryItem::RECORDING_PATH_KEY] = recAudio_.fileExists() ? getFilename() : "";
std::stringstream time_str;
time_str << timestamp_start_;
result[HistoryItem::TIMESTAMP_START_KEY] = time_str.str();
time_str.str("");
time_str << timestamp_stop_;
result[HistoryItem::TIMESTAMP_STOP_KEY] = time_str.str();
if (connectionState_ == RINGING)
result[HistoryItem::STATE_KEY] = HistoryItem::MISSED_STRING;
else
result[HistoryItem::STATE_KEY] = getTypeStr();
return result;
}
......@@ -47,15 +47,10 @@ class Call : public Recordable {
static const char * const DEFAULT_ID;
/**
* This determines if the call is a direct IP-to-IP call or a classic call, made with an existing account
* This determines if the call originated from the local user (OUTGOING)
* or from some remote peer (INCOMING, MISSED).
*/
enum CallConfiguration {Classic, IPtoIP};
/**
* This determines if the call originated from the local user (Outgoing)
* or from some remote peer (Incoming).
*/
enum CallType {Incoming, Outgoing};
enum CallType {INCOMING, OUTGOING, MISSED};
/**
* Tell where we're at with the call. The call gets Connected when we know
......@@ -65,12 +60,12 @@ class Call : public Recordable {
* Audio should be transmitted when ConnectionState = Connected AND
* CallState = Active.
*/
enum ConnectionState {Disconnected, Trying, Progressing, Ringing, Connected};
enum ConnectionState {DISCONNECTED, TRYING, PROGRESSING, RINGING, CONNECTED};
/**
* The Call State.
*/
enum CallState {Inactive, Active, Hold, Busy, Conferencing, Refused, Error};
enum CallState {INACTIVE, ACTIVE, HOLD, BUSY, CONFERENCING, REFUSED, ERROR};
/**
* Constructor of a call
......@@ -122,24 +117,6 @@ class Call : public Recordable {
return peerNumber_;
}
/**
* Set the peer name (caller in ingoing)
* not protected by mutex (when created)
* @param name The peer name
*/
void setPeerName(const std::string& name) {
peerName_ = name;
}
/**
* Get the peer name (caller in ingoing)
* not protected by mutex (when created)
* @return std::string The peer name
*/
std::string getPeerName() const {
return peerName_;
}
/**
* Set the display name (caller in ingoing)
* not protected by mutex (when created)
......@@ -163,8 +140,8 @@ class Call : public Recordable {
* @return true if yes
* false otherwise
*/
bool isIncoming() {
return type_ == Incoming;
bool isIncoming() const {
return type_ == INCOMING;
}
/**
......@@ -193,12 +170,8 @@ class Call : public Recordable {
std::string getStateStr();
void setCallConfiguration(Call::CallConfiguration callConfig) {
callConfig_ = callConfig;
}
Call::CallConfiguration getCallConfiguration() const {
return callConfig_;
void setIPToIP(bool IPToIP) {
isIPToIP_ = IPToIP;
}
/**
......@@ -230,16 +203,15 @@ class Call : public Recordable {
unsigned int getLocalAudioPort();
std::string getRecFileId() const {
return getPeerName();
}
std::string getFileName() const {
return peerNumber_;
return getDisplayName();
}
void time_stop();
std::map<std::string, std::string> createHistoryEntry() const;
virtual bool setRecording();