Commit 0ccbe36b authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#2165] Record a conference, instanciate recorder thread

parent 56985ee9
...@@ -203,6 +203,22 @@ void MainBuffer::bindCallID (CallID call_id1, CallID call_id2) ...@@ -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) void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2)
{ {
...@@ -216,7 +232,7 @@ 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); ringbuffer = getRingBuffer (call_id2);
if (ringbuffer != NULL) { if (ringbuffer) {
ringbuffer->removeReadPointer (call_id1); ringbuffer->removeReadPointer (call_id1);
...@@ -229,18 +245,36 @@ void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2) ...@@ -229,18 +245,36 @@ void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2)
ringbuffer = getRingBuffer (call_id1); ringbuffer = getRingBuffer (call_id1);
if (ringbuffer != NULL) { if (ringbuffer) {
ringbuffer->removeReadPointer (call_id2); ringbuffer->removeReadPointer (call_id2);
if (ringbuffer->getNbReadPointer() == 0) { if (ringbuffer->getNbReadPointer() == 0) {
removeCallIDSet (call_id1); removeCallIDSet (call_id1);
removeRingBuffer (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) void MainBuffer::unBindAll (CallID call_id)
{ {
...@@ -268,10 +302,32 @@ 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); RingBuffer* ring_buffer = getRingBuffer (call_id);
...@@ -281,7 +337,6 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID ...@@ -281,7 +337,6 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID
int a; int a;
// ost::MutexLock guard (_mutex);
a = ring_buffer->AvailForPut(); a = ring_buffer->AvailForPut();
if (a >= toCopy) { if (a >= toCopy) {
...@@ -298,8 +353,6 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID ...@@ -298,8 +353,6 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, CallID
int MainBuffer::availForPut (CallID call_id) int MainBuffer::availForPut (CallID call_id)
{ {
// ost::MutexLock guard (_mutex);
RingBuffer* ringbuffer = getRingBuffer (call_id); RingBuffer* ringbuffer = getRingBuffer (call_id);
if (ringbuffer == NULL) if (ringbuffer == NULL)
...@@ -312,7 +365,6 @@ int MainBuffer::availForPut (CallID call_id) ...@@ -312,7 +365,6 @@ int MainBuffer::availForPut (CallID call_id)
int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, 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); CallIDSet* callid_set = getCallIDSet (call_id);
...@@ -377,8 +429,6 @@ int MainBuffer::getDataByID (void *buffer, int toCopy, unsigned short volume, Ca ...@@ -377,8 +429,6 @@ int MainBuffer::getDataByID (void *buffer, int toCopy, unsigned short volume, Ca
int MainBuffer::availForGet (CallID call_id) int MainBuffer::availForGet (CallID call_id)
{ {
// ost::MutexLock guard (_mutex);
CallIDSet* callid_set = getCallIDSet (call_id); CallIDSet* callid_set = getCallIDSet (call_id);
if (callid_set == NULL) if (callid_set == NULL)
...@@ -396,10 +446,10 @@ int MainBuffer::availForGet (CallID call_id) ...@@ -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()); _debug ("This problem should not occur since we have %i element", (int) callid_set->size());
} }
// else
return availForGetByID (*iter_id, call_id); return availForGetByID (*iter_id, call_id);
} else { } else {
// _debug("CallIDSet with ID: \"%s\" is a conference!", call_id.c_str());
int avail_bytes = 99999; int avail_bytes = 99999;
int nb_bytes; int nb_bytes;
CallIDSet::iterator iter_id = callid_set->begin(); CallIDSet::iterator iter_id = callid_set->begin();
...@@ -437,9 +487,6 @@ int MainBuffer::availForGetByID (CallID call_id, CallID reader_id) ...@@ -437,9 +487,6 @@ int MainBuffer::availForGetByID (CallID call_id, CallID reader_id)
int MainBuffer::discard (int toDiscard, CallID call_id) int MainBuffer::discard (int toDiscard, CallID call_id)
{ {
// _debug("MainBuffer::discard");
// ost::MutexLock guard (_mutex);
CallIDSet* callid_set = getCallIDSet (call_id); CallIDSet* callid_set = getCallIDSet (call_id);
...@@ -447,7 +494,6 @@ int MainBuffer::discard (int toDiscard, CallID call_id) ...@@ -447,7 +494,6 @@ int MainBuffer::discard (int toDiscard, CallID call_id)
return 0; return 0;
if (callid_set->empty()) { if (callid_set->empty()) {
// _debug("CallIDSet with ID: \"%s\" is empty!", call_id.c_str());
return 0; return 0;
} }
......
...@@ -51,7 +51,7 @@ typedef std::map<CallID, CallIDSet*> CallIDMap; ...@@ -51,7 +51,7 @@ typedef std::map<CallID, CallIDSet*> CallIDMap;
class MainBuffer { class MainBuffer {
public: public:
MainBuffer(); MainBuffer();
...@@ -67,20 +67,40 @@ public: ...@@ -67,20 +67,40 @@ public:
bool removeCallIDSet(CallID set_id); bool removeCallIDSet(CallID set_id);
/**
* Add a new call id to this set
*/
void addCallIDtoSet(CallID set_id, CallID call_id); void addCallIDtoSet(CallID set_id, CallID call_id);
void removeCallIDfromSet(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); RingBuffer* createRingBuffer(CallID call_id);
bool removeRingBuffer(CallID call_id); bool removeRingBuffer(CallID call_id);
void bindCallID(CallID call_id1, CallID call_id2 = default_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 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 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 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); int getData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);
......
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
#include "recordable.h" #include "recordable.h"
#include "manager.h" #include "manager.h"
#include "mainbuffer.h"
Recordable::Recordable() Recordable::Recordable() : recorder(&recAudio)
{ {
FILE_TYPE fileType = FILE_WAV; FILE_TYPE fileType = FILE_WAV;
...@@ -61,3 +62,5 @@ void Recordable::setRecordingSmplRate (int smplRate) ...@@ -61,3 +62,5 @@ void Recordable::setRecordingSmplRate (int smplRate)
recAudio.setSndSamplingRate (smplRate); recAudio.setSndSamplingRate (smplRate);
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define RECORDABLE_H #define RECORDABLE_H
#include "../plug-in/audiorecorder/audiorecord.h" #include "../plug-in/audiorecorder/audiorecord.h"
#include "../plug-in/audiorecorder/audiorecorder.h"
class Recordable { class Recordable {
...@@ -42,7 +43,7 @@ class Recordable { ...@@ -42,7 +43,7 @@ class Recordable {
bool isRecording(){ return recAudio.isRecording(); } bool isRecording(){ return recAudio.isRecording(); }
bool setRecording(){ return recAudio.setRecording(); } virtual bool setRecording() = 0;
void stopRecording(){ recAudio.stopRecording(); } void stopRecording(){ recAudio.stopRecording(); }
...@@ -61,13 +62,12 @@ class Recordable { ...@@ -61,13 +62,12 @@ class Recordable {
*/ */
AudioRecord recAudio; AudioRecord recAudio;
AudioRecorder recorder;
private: private:
/** File name for his call : time YY-MM-DD */ /** File name for his call : time YY-MM-DD */
// std::string _filename; // std::string _filename;
}; };
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
*/ */
#include "call.h" #include "call.h"
#include "manager.h" #include "manager.h"
#include "audio/mainbuffer.h"
Call::Call (const CallID& id, Call::CallType type) Call::Call (const CallID& id, Call::CallType type)
: _callMutex() : _callMutex()
...@@ -184,3 +185,23 @@ Call::isAudioStarted() ...@@ -184,3 +185,23 @@ Call::isAudioStarted()
return _audioStarted; 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;
}
...@@ -235,9 +235,11 @@ class Call: public Recordable{ ...@@ -235,9 +235,11 @@ class Call: public Recordable{
*/ */
unsigned int getLocalAudioPort(); 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: protected:
/** Protect every attribute that can be changed by two threads */ /** Protect every attribute that can be changed by two threads */
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "conference.h" #include "conference.h"
#include "manager.h" #include "manager.h"
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
#include "audio/mainbuffer.h"
int Conference::count = 0; int Conference::count = 0;
...@@ -157,3 +158,30 @@ ParticipantSet Conference::getParticipantList() ...@@ -157,3 +158,30 @@ ParticipantSet Conference::getParticipantList()
return _participants; 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;
}
...@@ -75,6 +75,8 @@ class Conference: public Recordable{ ...@@ -75,6 +75,8 @@ class Conference: public Recordable{
std::string getRecFileId(){ return getConfID(); } std::string getRecFileId(){ return getConfID(); }
virtual bool setRecording();
private: private:
/** Unique ID of the conference */ /** Unique ID of the conference */
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cc++/thread.h> #include <cc++/thread.h>
class VoIPLink; class VoIPLink;
class AlsaLayer; class AlsaLayer;
......
...@@ -2556,16 +2556,19 @@ void ManagerImpl::setVolumeControls (bool display) { ...@@ -2556,16 +2556,19 @@ void ManagerImpl::setVolumeControls (bool display) {
} }
void ManagerImpl::setRecordingCall (const CallID& id) { void ManagerImpl::setRecordingCall (const CallID& id) {
/* /*
_debug ("ManagerImpl::setRecording()! "); _debug ("ManagerImpl::setRecording()! ");
AccountID accountid = getAccountFromCall (id); 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) { bool ManagerImpl::isRecording (const CallID& id) {
......
...@@ -93,7 +93,6 @@ typedef std::map<CallID, Conference*> ConferenceMap; ...@@ -93,7 +93,6 @@ typedef std::map<CallID, Conference*> ConferenceMap;
static CallID default_conf = "conf"; static CallID default_conf = "conf";
static char * mapStateToChar[] = { static char * mapStateToChar[] = {
(char*) "UNREGISTERED", (char*) "UNREGISTERED",
(char*) "TRYING", (char*) "TRYING",
...@@ -1241,6 +1240,7 @@ class ManagerImpl { ...@@ -1241,6 +1240,7 @@ class ManagerImpl {
void unloadAccountMap(); void unloadAccountMap();
public:
/** /**
* Instance of the MainBuffer for the whole application * Instance of the MainBuffer for the whole application
* *
...@@ -1250,8 +1250,6 @@ class ManagerImpl { ...@@ -1250,8 +1250,6 @@ class ManagerImpl {
*/ */
MainBuffer _mainBuffer; MainBuffer _mainBuffer;
public:
/** /**
* Tell if there is a current call processed * Tell if there is a current call processed
...@@ -1309,14 +1307,12 @@ class ManagerImpl { ...@@ -1309,14 +1307,12 @@ class ManagerImpl {
int isStunEnabled (void); int isStunEnabled (void);
void enableStun (void); void enableStun (void);
// Map // Map containing reference between conferences and calls
ConferenceCallMap _conferencecall; ConferenceCallMap _conferencecall;
// // Map containing conference pointers
ConferenceMap _conferencemap; ConferenceMap _conferencemap;
private: private:
// Copy Constructor // Copy Constructor
......
...@@ -3,4 +3,5 @@ include $(top_srcdir)/globals.mak ...@@ -3,4 +3,5 @@ include $(top_srcdir)/globals.mak
noinst_LTLIBRARIES = libaudiorecorder.la noinst_LTLIBRARIES = libaudiorecorder.la
libaudiorecorder_la_SOURCES = \ libaudiorecorder_la_SOURCES = \
audiorecord.cpp audiorecord.cpp \
\ No newline at end of file audiorecorder.cpp
\ No newline at end of file
Markdown is supported
0% or .