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

[#2165] Record a conference, instanciate recorder thread

parent 56985ee9
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
}
......@@ -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;
};
......
......@@ -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;
}
......@@ -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 */
......
......@@ -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;
}
......@@ -75,6 +75,8 @@ class Conference: public Recordable{
std::string getRecFileId(){ return getConfID(); }
virtual bool setRecording();
private:
/** Unique ID of the conference */
......
......@@ -33,6 +33,7 @@
#include <cc++/thread.h>
class VoIPLink;
class AlsaLayer;
......
......@@ -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) {
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment