Commit bf312a82 authored by Alexandre Savard's avatar Alexandre Savard

[#2165] Fix undind half duplex audio streams in mainbuffer

parent 8735167e
......@@ -471,9 +471,7 @@ void AudioRecord::recMicData (SFLDataFormat* buffer, int nSamples)
void AudioRecord::recData (SFLDataFormat* buffer, int nSamples)
{
if (recordingEnabled_) {
_debug("Recording enabled");
if (recordingEnabled_) {
if (fp == 0) {
_debug ("AudioRecord: Can't record data, a file has not yet been opened!");
......@@ -488,7 +486,6 @@ void AudioRecord::recData (SFLDataFormat* buffer, int nSamples)
else {
fflush (fp);
byteCounter_ += (unsigned long) (nSamples*sizeof (SFLDataFormat));
_debug("AudioRecord: wrote %d bytes", byteCounter_);
}
}
}
......
......@@ -31,13 +31,26 @@
#include "audiorecorder.h"
#include "mainbuffer.h"
AudioRecorder::AudioRecorder (AudioRecord *arec, MainBuffer *mb)
: Thread(), recorderId("recorder_id")
int AudioRecorder::count = 0;
AudioRecorder::AudioRecorder (AudioRecord *arec, MainBuffer *mb) : Thread()
{
setCancel (cancelDeferred);
++count;
std::string id("processid_");
// convert count into string
std::string s;
std::stringstream out;
out << count;
s = out.str();
recorderId = id.append(s);
arecord = arec;
mbuffer = mb;
mbuffer = mb;
}
......@@ -55,18 +68,12 @@ void AudioRecorder::run (void)
int availBytes = mbuffer->availForGet(recorderId);
_debug("Audiorecord: avail for get (before) %d", availBytes);
if(availBytes > 0) {
int got = mbuffer->getData(buffer, availBytes, 100, recorderId);
_debug("Audiorecord: audio get from main buffer %d", got);
int availBytesAfter = mbuffer->availForGet(recorderId);
_debug("Audiorecord: avail for get (after) %d", availBytesAfter);
arecord->recData(buffer, availBytes/sizeof(SFLDataFormat));
}
......
......@@ -44,6 +44,8 @@ class AudioRecorder : public ost::Thread {
~AudioRecorder(void){ terminate(); }
static int count;
std::string getRecorderID() { return recorderId; }
virtual void run();
......
......@@ -255,23 +255,33 @@ void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2)
}
}
void MainBuffer::unBindHalfDuplexOut(CallID call_id, CallID process_id)
void MainBuffer::unBindHalfDuplexOut(CallID process_id, CallID call_id)
{
removeCallIDfromSet(process_id, call_id);
RingBuffer* ringbuffer;
ringbuffer = getRingBuffer(process_id);
RingBuffer* ringbuffer = getRingBuffer(call_id);
if(ringbuffer) {
ringbuffer->removeReadPointer(call_id);
ringbuffer->removeReadPointer(process_id);
if(ringbuffer->getNbReadPointer() == 0) {
removeCallIDSet(process_id);
removeRingBuffer(process_id);
removeCallIDSet(call_id);
removeRingBuffer(call_id);
}
}
else {
_debug("Error: did not found ringbuffer %s", process_id.c_str());
removeCallIDSet(process_id);
}
CallIDSet* callid_set = getCallIDSet(process_id);
if(callid_set) {
if(callid_set->empty())
removeCallIDSet(process_id);
}
}
......@@ -387,9 +397,7 @@ int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, CallID
return 0;
} else {
for (int k = 0; k < nbSmplToCopy; k++) {
( (SFLDataFormat*) (buffer)) [k] = 0;
}
memset(buffer, 0, nbSmplToCopy*sizeof(SFLDataFormat*));
int size = 0;
......
......@@ -162,23 +162,45 @@ ParticipantSet Conference::getParticipantList()
bool Conference::setRecording() {
bool recordStatus = Recordable::recAudio.setRecording();
bool recordStatus = Recordable::recAudio.isRecording();
if(!recordStatus)
return false;
Recordable::recAudio.setRecording();
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
// start recording
if(!recordStatus){
ParticipantSet::iterator iter = _participants.begin();
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
CallID process_id = Recordable::recorder.getRecorderID();
ParticipantSet::iterator iter = _participants.begin();
while(iter != _participants.end()) {
CallID process_id = Recordable::recorder.getRecorderID();
while(iter != _participants.end()) {
mbuffer->bindHalfDuplexOut(process_id, *iter);
iter++;
}
mbuffer->bindHalfDuplexOut(process_id);
}
// stop recording
else {
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
ParticipantSet::iterator iter = _participants.begin();
CallID process_id = Recordable::recorder.getRecorderID();
while(iter != _participants.end()) {
mbuffer->unBindHalfDuplexOut(process_id, *iter);
iter++;
}
mbuffer->unBindHalfDuplexOut(process_id);
}
mbuffer->bindHalfDuplexOut(process_id);
Recordable::recorder.start();
......
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