diff --git a/sflphone-common/src/audio/mainbuffer.cpp b/sflphone-common/src/audio/mainbuffer.cpp index 4782b6ddf71e79757b3e03890938532909eb7d05..91e0d238d850ce61b14d3fe563156c084a498263 100644 --- a/sflphone-common/src/audio/mainbuffer.cpp +++ b/sflphone-common/src/audio/mainbuffer.cpp @@ -203,6 +203,22 @@ void MainBuffer::bindCallID (CallID call_id1, CallID call_id2) } +void MainBuffer::bindHalfDuplexOut(CallID process_id, CallID call_id) +{ + + // This method is used only for active calls, if this call does not exist, do nothing + if(!getRingBuffer(call_id)) + return; + + if(!getCallIDSet(process_id)) + createCallIDSet(process_id); + + getRingBuffer(call_id)->createReadPointer(process_id); + + addCallIDtoSet(process_id, call_id); + +} + void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2) { @@ -216,7 +232,7 @@ void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2) ringbuffer = getRingBuffer (call_id2); - if (ringbuffer != NULL) { + if (ringbuffer) { ringbuffer->removeReadPointer (call_id1); @@ -229,18 +245,36 @@ void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2) ringbuffer = getRingBuffer (call_id1); - if (ringbuffer != NULL) { - ringbuffer->removeReadPointer (call_id2); - - if (ringbuffer->getNbReadPointer() == 0) { - removeCallIDSet (call_id1); - removeRingBuffer (call_id1); - } + if (ringbuffer) { + ringbuffer->removeReadPointer (call_id2); + + if (ringbuffer->getNbReadPointer() == 0) { + removeCallIDSet (call_id1); + removeRingBuffer (call_id1); + } } +} +void MainBuffer::unBindHalfDuplexOut(CallID call_id, CallID process_id) +{ + + removeCallIDfromSet(process_id, call_id); + + RingBuffer* ringbuffer; + + ringbuffer = getRingBuffer(process_id); + + if(ringbuffer) { + ringbuffer->removeReadPointer(call_id); + if(ringbuffer->getNbReadPointer() == 0) { + removeCallIDSet(process_id); + removeRingBuffer(process_id); + } + } } + void MainBuffer::unBindAll (CallID call_id) { @@ -268,10 +302,32 @@ void MainBuffer::unBindAll (CallID call_id) } -int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID call_id) +void MainBuffer::unBindAllHalfDuplexOut(CallID process_id) { - // ost::MutexLock guard (_mutex); + CallIDSet* callid_set = getCallIDSet(process_id); + + if(!callid_set) + return; + + if(callid_set->empty()) + return; + + CallIDSet temp_set = *callid_set; + + CallIDSet::iterator iter_set = temp_set.begin(); + + while(iter_set != temp_set.end()) { + CallID call_id_in_set = *iter_set; + unBindCallID(process_id, call_id_in_set); + + iter_set++; + } +} + + +int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID call_id) +{ RingBuffer* ring_buffer = getRingBuffer (call_id); @@ -281,7 +337,6 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID int a; - // ost::MutexLock guard (_mutex); a = ring_buffer->AvailForPut(); if (a >= toCopy) { @@ -298,8 +353,6 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID int MainBuffer::availForPut (CallID call_id) { - // ost::MutexLock guard (_mutex); - RingBuffer* ringbuffer = getRingBuffer (call_id); if (ringbuffer == NULL) @@ -312,7 +365,6 @@ int MainBuffer::availForPut (CallID call_id) int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, CallID call_id) { - // ost::MutexLock guard (_mutex); CallIDSet* callid_set = getCallIDSet (call_id); @@ -377,8 +429,6 @@ int MainBuffer::getDataByID (void *buffer, int toCopy, unsigned short volume, Ca int MainBuffer::availForGet (CallID call_id) { - // ost::MutexLock guard (_mutex); - CallIDSet* callid_set = getCallIDSet (call_id); if (callid_set == NULL) @@ -396,10 +446,10 @@ int MainBuffer::availForGet (CallID call_id) _debug ("This problem should not occur since we have %i element", (int) callid_set->size()); } - // else return availForGetByID (*iter_id, call_id); + } else { - // _debug("CallIDSet with ID: \"%s\" is a conference!", call_id.c_str()); + int avail_bytes = 99999; int nb_bytes; CallIDSet::iterator iter_id = callid_set->begin(); @@ -437,9 +487,6 @@ int MainBuffer::availForGetByID (CallID call_id, CallID reader_id) int MainBuffer::discard (int toDiscard, CallID call_id) { - // _debug("MainBuffer::discard"); - - // ost::MutexLock guard (_mutex); CallIDSet* callid_set = getCallIDSet (call_id); @@ -447,7 +494,6 @@ int MainBuffer::discard (int toDiscard, CallID call_id) return 0; if (callid_set->empty()) { - // _debug("CallIDSet with ID: \"%s\" is empty!", call_id.c_str()); return 0; } diff --git a/sflphone-common/src/audio/mainbuffer.h b/sflphone-common/src/audio/mainbuffer.h index 402fe84d6d745b172876db958106f29a094104d3..551cf8c0871d92f3fd3b686515505b9b94997c28 100644 --- a/sflphone-common/src/audio/mainbuffer.h +++ b/sflphone-common/src/audio/mainbuffer.h @@ -51,7 +51,7 @@ typedef std::map<CallID, CallIDSet*> CallIDMap; class MainBuffer { -public: + public: MainBuffer(); @@ -67,20 +67,40 @@ public: bool removeCallIDSet(CallID set_id); + /** + * Add a new call id to this set + */ void addCallIDtoSet(CallID set_id, CallID call_id); void removeCallIDfromSet(CallID set_id, CallID call_id); + /** + * Create a new ringbuffer with default readpointer + */ RingBuffer* createRingBuffer(CallID call_id); bool removeRingBuffer(CallID call_id); void bindCallID(CallID call_id1, CallID call_id2 = default_id); + /** + * Add a new call_id to unidirectional outgoing stream + * \param call_id New call id to be added for this stream + * \param process_id Process that require this stream + */ + void bindHalfDuplexOut(CallID process_id, CallID call_id = default_id); + + /** + * Unbind two calls + */ void unBindCallID(CallID call_id1, CallID call_id2 = default_id); + void unBindHalfDuplexOut(CallID process_id, CallID call_id = default_id); + void unBindAll(CallID call_id); + void unBindAllHalfDuplexOut(CallID process_id); + int putData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id); int getData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id); diff --git a/sflphone-common/src/audio/recordable.cpp b/sflphone-common/src/audio/recordable.cpp index f8044c12a4f7376cd34851cc54c04a42393877f6..7e3c37addf2db1648db1f1cf00ead48922502090 100644 --- a/sflphone-common/src/audio/recordable.cpp +++ b/sflphone-common/src/audio/recordable.cpp @@ -29,8 +29,9 @@ #include "recordable.h" #include "manager.h" +#include "mainbuffer.h" -Recordable::Recordable() +Recordable::Recordable() : recorder(&recAudio) { FILE_TYPE fileType = FILE_WAV; @@ -61,3 +62,5 @@ void Recordable::setRecordingSmplRate (int smplRate) recAudio.setSndSamplingRate (smplRate); } + + diff --git a/sflphone-common/src/audio/recordable.h b/sflphone-common/src/audio/recordable.h index 8ab5281cc9fe0509b8e33876bbf47455ecf32464..4cd83dcc5064efb43a664363a80272e367469009 100644 --- a/sflphone-common/src/audio/recordable.h +++ b/sflphone-common/src/audio/recordable.h @@ -31,6 +31,7 @@ #define RECORDABLE_H #include "../plug-in/audiorecorder/audiorecord.h" +#include "../plug-in/audiorecorder/audiorecorder.h" class Recordable { @@ -42,7 +43,7 @@ class Recordable { bool isRecording(){ return recAudio.isRecording(); } - bool setRecording(){ return recAudio.setRecording(); } + virtual bool setRecording() = 0; void stopRecording(){ recAudio.stopRecording(); } @@ -61,13 +62,12 @@ class Recordable { */ AudioRecord recAudio; + AudioRecorder recorder; private: /** File name for his call : time YY-MM-DD */ - // std::string _filename; - - + // std::string _filename; }; diff --git a/sflphone-common/src/call.cpp b/sflphone-common/src/call.cpp index 93e71226af15973500be6978febde563a6946d85..65195f5f50c5230641298ea18dc79d59ffccec0b 100644 --- a/sflphone-common/src/call.cpp +++ b/sflphone-common/src/call.cpp @@ -30,6 +30,7 @@ */ #include "call.h" #include "manager.h" +#include "audio/mainbuffer.h" Call::Call (const CallID& id, Call::CallType type) : _callMutex() @@ -184,3 +185,23 @@ Call::isAudioStarted() return _audioStarted; } + +bool +Call::setRecording() +{ + bool recordStatus = Recordable::recAudio.setRecording(); + + if(!recordStatus) + return false; + + MainBuffer *mbuffer = &(Manager::instance()._mainBuffer); + + CallID process_id = Recordable::recorder.getRecorderID(); + + mbuffer->bindHalfDuplexOut(process_id, _id); + mbuffer->bindHalfDuplexOut(process_id); + + Recordable::recorder.start(); + + return recordStatus; +} diff --git a/sflphone-common/src/call.h b/sflphone-common/src/call.h index 6fcc87fd2f9908fb6b5bdbb744d80e927618a0be..89c81c1f67b0c196243e5e2a678d8c213b151dba 100644 --- a/sflphone-common/src/call.h +++ b/sflphone-common/src/call.h @@ -235,9 +235,11 @@ class Call: public Recordable{ */ unsigned int getLocalAudioPort(); - std::string getRecFileId(){ return getPeerName(); } + std::string getRecFileId(void){ return getPeerName(); } - std::string getFileName() { return _filename; } + std::string getFileName(void) { return _filename; } + + virtual bool setRecording(void); protected: /** Protect every attribute that can be changed by two threads */ diff --git a/sflphone-common/src/conference.cpp b/sflphone-common/src/conference.cpp index d93cf8a0a486b8a97ac08e233e04f02462b096d3..17ee9a39b50cf1334f780e1c33c63a8694e795b4 100644 --- a/sflphone-common/src/conference.cpp +++ b/sflphone-common/src/conference.cpp @@ -34,6 +34,7 @@ #include "conference.h" #include "manager.h" #include "audio/audiolayer.h" +#include "audio/mainbuffer.h" int Conference::count = 0; @@ -157,3 +158,30 @@ ParticipantSet Conference::getParticipantList() return _participants; } + + +bool Conference::setRecording() { + + bool recordStatus = Recordable::recAudio.setRecording(); + + if(!recordStatus) + return false; + + MainBuffer *mbuffer = &(Manager::instance()._mainBuffer); + + ParticipantSet::iterator iter = _participants.begin(); + + CallID process_id = Recordable::recorder.getRecorderID(); + + while(iter != _participants.end()) { + mbuffer->bindHalfDuplexOut(process_id, *iter); + iter++; + } + + mbuffer->bindHalfDuplexOut(process_id); + + Recordable::recorder.start(); + + return recordStatus; + +} diff --git a/sflphone-common/src/conference.h b/sflphone-common/src/conference.h index a20a9a25842faf1ff97f13048f4a98d9b9902468..77952531d1a7b979e6bcfb9c1d7e1a99c59d21b2 100644 --- a/sflphone-common/src/conference.h +++ b/sflphone-common/src/conference.h @@ -75,6 +75,8 @@ class Conference: public Recordable{ std::string getRecFileId(){ return getConfID(); } + virtual bool setRecording(); + private: /** Unique ID of the conference */ diff --git a/sflphone-common/src/eventthread.h b/sflphone-common/src/eventthread.h index aed9f5b5159052acb9cb776c94948798cf3cb384..eca20c22dc8c40ec39135eaf2539943f85373876 100644 --- a/sflphone-common/src/eventthread.h +++ b/sflphone-common/src/eventthread.h @@ -33,6 +33,7 @@ #include <cc++/thread.h> + class VoIPLink; class AlsaLayer; diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 69ae92be43194567ee0ada907f07e6012d3a0720..da9bbcf51f4c5b0d39c2541c9d25035863727533 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -2556,16 +2556,19 @@ void ManagerImpl::setVolumeControls (bool display) { } void ManagerImpl::setRecordingCall (const CallID& id) { - /* - _debug ("ManagerImpl::setRecording()! "); - AccountID accountid = getAccountFromCall (id); + /* + _debug ("ManagerImpl::setRecording()! "); + AccountID accountid = getAccountFromCall (id); + + getAccountLink (accountid)->setRecording (id); + */ - getAccountLink (accountid)->setRecording (id); - */ - AccountID accountid = getAccountFromCall(id); - Recordable* rec = (Recordable*) getAccountLink(accountid)->getCall(id); + AccountID accountid = getAccountFromCall(id); + Recordable* rec = (Recordable *) getAccountLink(accountid)->getCall(id); - rec->setRecording(); + rec->setRecording(); + + } bool ManagerImpl::isRecording (const CallID& id) { diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h index 3c88ba6a14ce54c51141d528cdaefe3ea4a1f73a..700bb1721d5a906a7df5d8112f9ece9fe251728d 100644 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -93,7 +93,6 @@ typedef std::map<CallID, Conference*> ConferenceMap; static CallID default_conf = "conf"; - static char * mapStateToChar[] = { (char*) "UNREGISTERED", (char*) "TRYING", @@ -1241,6 +1240,7 @@ class ManagerImpl { void unloadAccountMap(); + public: /** * Instance of the MainBuffer for the whole application * @@ -1250,8 +1250,6 @@ class ManagerImpl { */ MainBuffer _mainBuffer; - - public: /** * Tell if there is a current call processed @@ -1309,14 +1307,12 @@ class ManagerImpl { int isStunEnabled (void); void enableStun (void); - // Map + // Map containing reference between conferences and calls ConferenceCallMap _conferencecall; - // + // Map containing conference pointers ConferenceMap _conferencemap; - - private: // Copy Constructor diff --git a/sflphone-common/src/plug-in/audiorecorder/Makefile.am b/sflphone-common/src/plug-in/audiorecorder/Makefile.am index 2a37f147295de545974f83dbf48e097a5a0d53dc..811f75102fd1d58b44a735ce14b7158340dd326a 100644 --- a/sflphone-common/src/plug-in/audiorecorder/Makefile.am +++ b/sflphone-common/src/plug-in/audiorecorder/Makefile.am @@ -3,4 +3,5 @@ include $(top_srcdir)/globals.mak noinst_LTLIBRARIES = libaudiorecorder.la libaudiorecorder_la_SOURCES = \ - audiorecord.cpp \ No newline at end of file + audiorecord.cpp \ + audiorecorder.cpp \ No newline at end of file