diff --git a/sflphone-client-gnome/src/contacts/calltree.c b/sflphone-client-gnome/src/contacts/calltree.c index 5505e21d971bb54ad1d76b7ef4756b991893947b..89a48d47d082e2f46dc6942b8ec5fd566610025f 100644 --- a/sflphone-client-gnome/src/contacts/calltree.c +++ b/sflphone-client-gnome/src/contacts/calltree.c @@ -1355,165 +1355,150 @@ static void drag_end_cb(GtkWidget * widget, GdkDragContext * context, gpointer d conference_obj_t* conf; - if(selected_path_depth == 1) - { - if(dragged_path_depth == 1) - { + if(selected_path_depth == 1) { - if (selected_type == A_CALL && dragged_type == A_CALL) - { + if(dragged_path_depth == 1) { - if(gtk_tree_path_compare (dpath, spath) == 0) - { - // draged a call on itself - } - else - { - // dragged a single call on a single call - if(selected_call != NULL && dragged_call != NULL) - sflphone_join_participant(selected_call->_callID, dragged_call->_callID); - } - } - else if(selected_type == A_CALL && dragged_type == A_CONFERENCE) - { - // dragged a single call on a conference - selected_call->_confID = g_strdup(dragged_call_id); - sflphone_add_participant(selected_call_id, dragged_call_id); - } - else if(selected_type == A_CONFERENCE && dragged_type == A_CALL) - { - // dragged a conference on a single call (make no sence) - calltree_remove_conference(current_calls, selected_conf, NULL); - calltree_add_conference(current_calls, selected_conf); + if (selected_type == A_CALL && dragged_type == A_CALL) { + if(gtk_tree_path_compare (dpath, spath) == 0) { + // draged a call on itself + } + else { + // dragged a single call on a single call + if(selected_call != NULL && dragged_call != NULL) + sflphone_join_participant(selected_call->_callID, dragged_call->_callID); + } + } + else if(selected_type == A_CALL && dragged_type == A_CONFERENCE) { + // dragged a single call on a conference + selected_call->_confID = g_strdup(dragged_call_id); + sflphone_add_participant(selected_call_id, dragged_call_id); + } + else if(selected_type == A_CONFERENCE && dragged_type == A_CALL) { - } - else if(selected_type == A_CONFERENCE && dragged_type == A_CONFERENCE) - { - // dragged a conference on a conference - if(gtk_tree_path_compare (dpath, spath) == 0) - { - DEBUG("Joined the same conference!\n"); - gtk_tree_view_expand_row(GTK_TREE_VIEW(current_calls->view), path, FALSE); - } - else - { - DEBUG("Joined two conference %s, %s!\n", dragged_path, selected_path); - sflphone_join_conference(selected_conf->_confID, dragged_conf->_confID); - } - } + conf = selected_conf; - // TODO: dragged a single call on a NULL element (should do nothing) - // TODO: dragged a conference on a NULL element (should do nothing) + // dragged a conference on a single call (make no sence) + calltree_remove_conference(current_calls, conf, NULL); + calltree_add_conference(current_calls, conf); } - else // dragged_path_depth == 2 - { - if (selected_type == A_CALL && dragged_type == A_CALL) - { - // TODO: dragged a call on a conference call - calltree_remove_call(current_calls, selected_call, NULL); - calltree_add_call(current_calls, selected_call, NULL); - } - else if(selected_type == A_CONFERENCE && dragged_type == A_CALL) - { - // TODO: dragged a conference on a conference call - calltree_remove_conference(current_calls, selected_conf, NULL); - calltree_add_conference(current_calls, selected_conf); - } - - // TODO: dragged a single call on a NULL element - // TODO: dragged a conference on a NULL element + else if(selected_type == A_CONFERENCE && dragged_type == A_CONFERENCE) { + // dragged a conference on a conference + if(gtk_tree_path_compare (dpath, spath) == 0) { + DEBUG("Joined the same conference!\n"); + gtk_tree_view_expand_row(GTK_TREE_VIEW(current_calls->view), path, FALSE); + } + else { + DEBUG("Joined two conference %s, %s!\n", dragged_path, selected_path); + sflphone_join_conference(selected_conf->_confID, dragged_conf->_confID); + } } - } - else // selected_path_depth == 2 - { - - if(dragged_path_depth == 1) - { - if(selected_type == A_CALL && dragged_type == A_CALL) - { + // TODO: dragged a single call on a NULL element (should do nothing) + // TODO: dragged a conference on a NULL element (should do nothing) - // dragged a conference call on a call - sflphone_detach_participant(selected_call_id); + } + else { + // dragged_path_depth == 2 - if(selected_call != NULL && dragged_call != NULL) - sflphone_join_participant(selected_call->_callID, dragged_call->_callID); + if (selected_type == A_CALL && dragged_type == A_CALL) { + // TODO: dragged a call on a conference call + calltree_remove_call(current_calls, selected_call, NULL); + calltree_add_call(current_calls, selected_call, NULL); + } + else if(selected_type == A_CONFERENCE && dragged_type == A_CALL) { + // TODO: dragged a conference on a conference call + conf = selected_conf; - } - else if(selected_type == A_CALL && dragged_type == A_CONFERENCE) - { - // dragged a conference call on a conference - sflphone_detach_participant(selected_call_id); + calltree_remove_conference(current_calls, conf, NULL); + calltree_add_conference(current_calls, conf); + } + + // TODO: dragged a single call on a NULL element + // TODO: dragged a conference on a NULL element + } + } + else { - if(selected_call != NULL && dragged_conf != NULL) - { - DEBUG("Adding a participant, since dragged call on a conference"); + // selected_path_depth == 2 - sflphone_add_participant(selected_call_id, dragged_call_id); - } - } - else - { - // dragged a conference call on a NULL element - sflphone_detach_participant(selected_call_id); - } + if(dragged_path_depth == 1) { + if(selected_type == A_CALL && dragged_type == A_CALL) { + + // dragged a conference call on a call + sflphone_detach_participant(selected_call_id); + + if(selected_call != NULL && dragged_call != NULL) + sflphone_join_participant(selected_call->_callID, dragged_call->_callID); + } - else // dragged_path_depth == 2 - { - // dragged a conference call on another conference call (same conference) - // TODO: dragged a conference call on another conference call (different conference) + else if(selected_type == A_CALL && dragged_type == A_CONFERENCE) { + // dragged a conference call on a conference + sflphone_detach_participant(selected_call_id); - gtk_tree_path_up(path); + if(selected_call != NULL && dragged_conf != NULL) { + DEBUG("Adding a participant, since dragged call on a conference"); - gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &parent_conference, path); + sflphone_add_participant(selected_call_id, dragged_call_id); + } + } + else { + // dragged a conference call on a NULL element + sflphone_detach_participant(selected_call_id); + } + + } + else { + // dragged_path_depth == 2 + // dragged a conference call on another conference call (same conference) + // TODO: dragged a conference call on another conference call (different conference) - gtk_tree_path_up(dpath); - gtk_tree_path_up(spath); + gtk_tree_path_up(path); + + gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &parent_conference, path); + + gtk_tree_path_up(dpath); + gtk_tree_path_up(spath); - if(gtk_tree_path_compare (dpath, spath) == 0) - { + if(gtk_tree_path_compare (dpath, spath) == 0) { - DEBUG("Dragged a call in the same conference"); - calltree_remove_call (current_calls, selected_call, NULL); - calltree_add_call (current_calls, selected_call, &parent_conference); - } - else - { - DEBUG("Dragged a conference call onto another conference call %s, %s", gtk_tree_path_to_string(dpath), gtk_tree_path_to_string(spath)); + DEBUG("Dragged a call in the same conference"); + calltree_remove_call (current_calls, selected_call, NULL); + calltree_add_call (current_calls, selected_call, &parent_conference); + } + else { + DEBUG("Dragged a conference call onto another conference call %s, %s", gtk_tree_path_to_string(dpath), gtk_tree_path_to_string(spath)); - conf = NULL; + conf = NULL; - val.g_type = 0; - if(gtk_tree_model_get_iter (model, &iter, dpath)) - { - DEBUG("we got an iter!"); - gtk_tree_model_get_value (model, &iter, COLUMN_ACCOUNT_PTR, &val); + val.g_type = 0; + if(gtk_tree_model_get_iter (model, &iter, dpath)) { + DEBUG("we got an iter!"); + gtk_tree_model_get_value (model, &iter, COLUMN_ACCOUNT_PTR, &val); - conf = (conference_obj_t*)g_value_get_pointer(&val); - } - g_value_unset(&val); + conf = (conference_obj_t*)g_value_get_pointer(&val); + } + g_value_unset(&val); - sflphone_detach_participant(selected_call_id); + sflphone_detach_participant(selected_call_id); - if(conf) - { - DEBUG("we got a conf!"); - sflphone_add_participant(selected_call_id, conf->_confID); - } - else - { - DEBUG("didn't find a conf!"); - } - } + if(conf) { + DEBUG("we got a conf!"); + sflphone_add_participant(selected_call_id, conf->_confID); + } + else { + DEBUG("didn't find a conf!"); + } + } - // TODO: dragged a conference call on another conference call (different conference) - // TODO: dragged a conference call on a NULL element (same conference) - // TODO: dragged a conference call on a NULL element (different conference) - } + // TODO: dragged a conference call on another conference call (different conference) + // TODO: dragged a conference call on a NULL element (same conference) + // TODO: dragged a conference call on a NULL element (different conference) + } } diff --git a/sflphone-common/src/audio/mainbuffer.cpp b/sflphone-common/src/audio/mainbuffer.cpp index 052e729259131da39342e252bc9214a5a9ca1f8d..069864b1d65b0d8d7af8d3731ec0200271ac6ff6 100644 --- a/sflphone-common/src/audio/mainbuffer.cpp +++ b/sflphone-common/src/audio/mainbuffer.cpp @@ -39,14 +39,12 @@ void MainBuffer::setInternalSamplingRate (int sr) ost::MutexLock guard (_mutex); if (sr != _internalSamplingRate) { - // flushAllBuffers(); + _internalSamplingRate = sr; flushAllBuffers(); } - - // flushAllBuffers(); } CallIDSet* MainBuffer::getCallIDSet (CallID call_id) @@ -63,7 +61,6 @@ CallIDSet* MainBuffer::getCallIDSet (CallID call_id) bool MainBuffer::createCallIDSet (CallID set_id) { - _debug ("---- MainBuffer::createCallIDSet %s", set_id.c_str()); CallIDSet* newCallIDSet = new CallIDSet; @@ -77,21 +74,19 @@ bool MainBuffer::createCallIDSet (CallID set_id) bool MainBuffer::removeCallIDSet (CallID set_id) { - _debug ("---- MainBuffer::removeCallIDSet %s", set_id.c_str()); - CallIDSet* callid_set = getCallIDSet (set_id); if (callid_set != NULL) { if (_callIDMap.erase (set_id) != 0) { - _debug (" callid set %s erased!", set_id.c_str()); + // _debug (" callid set %s erased!", set_id.c_str()); return true; } else { - _debug (" error while removing callid set %s!", set_id.c_str()); + _debug ("removeCallIDSet error while removing callid set %s!", set_id.c_str()); return false; } } else { - _debug (" callid set %s does not exist!", set_id.c_str()); + _debug ("removeCallIDSet error callid set %s does not exist!", set_id.c_str()); return false; } @@ -99,7 +94,6 @@ bool MainBuffer::removeCallIDSet (CallID set_id) void MainBuffer::addCallIDtoSet (CallID set_id, CallID call_id) { - _debug ("---- MainBuffer::addCallIDtoSet %s in %s", set_id.c_str(), call_id.c_str()); CallIDSet* callid_set = getCallIDSet (set_id); callid_set->insert (call_id); @@ -108,18 +102,17 @@ void MainBuffer::addCallIDtoSet (CallID set_id, CallID call_id) void MainBuffer::removeCallIDfromSet (CallID set_id, CallID call_id) { - _debug ("---- MainBuffer::removeCallIDfromSet element %s from %s", call_id.c_str(), set_id.c_str()); CallIDSet* callid_set = getCallIDSet (set_id); if (callid_set != NULL) { if (callid_set->erase (call_id) != 0) { - _debug (" callid %s erased from set %s!", call_id.c_str(), set_id.c_str()); + // _debug (" callid %s erased from set %s!", call_id.c_str(), set_id.c_str()); } else { - _debug (" error while removing callid %s from set %s!", call_id.c_str(), set_id.c_str()); + _debug ("removeCallIDfromSet error while removing callid %s from set %s!", call_id.c_str(), set_id.c_str()); } } else { - _debug (" callid set %s does not exist!", set_id.c_str()); + _debug ("removeCallIDfromSet error callid set %s does not exist!", set_id.c_str()); } } @@ -140,8 +133,6 @@ RingBuffer* MainBuffer::getRingBuffer (CallID call_id) RingBuffer* MainBuffer::createRingBuffer (CallID call_id) { - _debug ("---- MainBuffer::createRingBuffer callid %s", call_id.c_str()); - RingBuffer* newRingBuffer = new RingBuffer (SIZEBUF, call_id); _ringBufferMap.insert (pair<CallID, RingBuffer*> (call_id, newRingBuffer)); @@ -153,20 +144,18 @@ RingBuffer* MainBuffer::createRingBuffer (CallID call_id) bool MainBuffer::removeRingBuffer (CallID call_id) { - _debug ("---- MainBuffer::removeRingBuffer call_id %s", call_id.c_str()); - RingBuffer* ring_buffer = getRingBuffer (call_id); if (ring_buffer != NULL) { if (_ringBufferMap.erase (call_id) != 0) { - _debug (" ringbuffer %s removed!", call_id.c_str()); + // _debug ("removeRingBuffer ringbuffer %s removed!", call_id.c_str()); return true; } else { - _debug (" error while deleting ringbuffer %s!", call_id.c_str()); + _debug ("removeRingBuffer error while deleting ringbuffer %s!", call_id.c_str()); return false; } } else { - _debug (" error ringbuffer %s does not exist!", call_id.c_str()); + _debug ("removeRingBuffer error ringbuffer %s does not exist!", call_id.c_str()); return true; } } @@ -177,8 +166,6 @@ void MainBuffer::bindCallID (CallID call_id1, CallID call_id2) ost::MutexLock guard (_mutex); - _debug ("---- MainBuffer::bindCallID %s and callid %s", call_id1.c_str(), call_id2.c_str()); - RingBuffer* ring_buffer; CallIDSet* callid_set; @@ -210,8 +197,6 @@ void MainBuffer::unBindCallID (CallID call_id1, CallID call_id2) ost::MutexLock guard (_mutex); - _debug ("---- MainBuffer::unBindCallID %s and callid %s", call_id1.c_str(), call_id2.c_str()); - removeCallIDfromSet (call_id1, call_id2); removeCallIDfromSet (call_id2, call_id1); @@ -261,8 +246,6 @@ void MainBuffer::unBindAll (CallID call_id) CallIDSet::iterator iter_set = temp_set.begin(); - _debug ("MainBuffer::unBindAll"); - while (iter_set != temp_set.end()) { CallID call_id_in_set = *iter_set; unBindCallID (call_id, call_id_in_set); @@ -369,12 +352,10 @@ int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, CallID int MainBuffer::getDataByID (void *buffer, int toCopy, unsigned short volume, CallID call_id, CallID reader_id) { - // _debug("MainBuffer::getDataByID in buffer %s by %s ", call_id.c_str(), reader_id.c_str()); - RingBuffer* ring_buffer = getRingBuffer (call_id); if (ring_buffer == NULL) { - // _debug("Output RingBuffer ID: \"%s\" does not exist!", call_id.c_str()); + return 0; } @@ -402,7 +383,6 @@ int MainBuffer::availForGet (CallID call_id) if (callid_set->size() == 1) { CallIDSet::iterator iter_id = callid_set->begin(); - // _debug("MainBuffer::availForGet availForGetByID(%s,%s)", (*iter_id).c_str(), call_id.c_str()); if ( (call_id != default_id) && (*iter_id == call_id)) { _debug ("This problem should not occur since we have %i element", (int) callid_set->size()); @@ -433,6 +413,7 @@ int MainBuffer::availForGetByID (CallID call_id, CallID reader_id) { if ( (call_id != default_id) && (reader_id == call_id)) { + _debug ("**********************************************************************"); _debug ("Error an RTP session ring buffer is not supposed to have a readpointer on tiself"); } @@ -466,11 +447,13 @@ int MainBuffer::discard (int toDiscard, CallID call_id) if (callid_set->size() == 1) { + CallIDSet::iterator iter_id = callid_set->begin(); - // _debug("Discard Data in \"%s\" RingBuffer for \"%s\" ReaderPointer",(*iter_id).c_str(),call_id.c_str()); + return discardByID (toDiscard, *iter_id, call_id); } else { - // _debug("CallIDSet with ID: \"%s\" is a conference!", call_id.c_str()); + + CallIDSet::iterator iter_id; for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) { @@ -501,8 +484,6 @@ void MainBuffer::flush (CallID call_id) { ost::MutexLock guard (_mutex); - // _debug("MainBuffer::flush"); - CallIDSet* callid_set = getCallIDSet (call_id); if (callid_set == NULL) @@ -516,7 +497,7 @@ void MainBuffer::flush (CallID call_id) CallIDSet::iterator iter_id = callid_set->begin(); flushByID (*iter_id, call_id); } else { - // _debug("CallIDSet with ID: \"%s\" is a conference!", call_id.c_str()); + CallIDSet::iterator iter_id; for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) { @@ -548,12 +529,9 @@ void MainBuffer::flushByID (CallID call_id, CallID reader_id) void MainBuffer::flushAllBuffers() { - // _debug("-------------------------- flushAllBuffers()"); - RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); while (iter_buffer != _ringBufferMap.end()) { - // _debug("-------------------------- flushing: %s",iter_buffer->second->getBufferId().c_str()); iter_buffer->second->flushAll(); @@ -566,27 +544,68 @@ void MainBuffer::stateInfo() { _debug ("MainBuffer state info"); - CallIDMap::iterator iter_map = _callIDMap.begin(); + CallIDMap::iterator iter_call = _callIDMap.begin(); + + // print each call and bound call ids + while(iter_call != _callIDMap.end()) { + + std::string dbg_str(" Call: "); + dbg_str.append(std::string(iter_call->first.c_str())); + dbg_str.append(std::string(" is bound to: ")); + + CallIDSet* call_id_set = (CallIDSet*)iter_call->second; - while (iter_map != _callIDMap.end()) { - CallIDSet* id_set = getCallIDSet (iter_map->first); + CallIDSet::iterator iter_call_id = call_id_set->begin(); + + while (iter_call_id != call_id_set->end()) { + + dbg_str.append (std::string (*iter_call_id)); + dbg_str.append (std::string (", ")); + + iter_call_id++; + } + + _debug ("%s\n", dbg_str.c_str()); + + iter_call++; + } + + // Print ringbuffers ids and readpointers + RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); + + while (iter_buffer != _ringBufferMap.end()) { + + RingBuffer* rbuffer = (RingBuffer*)iter_buffer->second; + ReadPointer* rpointer = NULL; std::string dbg_str (" Buffer: "); - dbg_str.append (string (iter_map->first.c_str())); - dbg_str.append (string (" bound to ")); + dbg_str.append (std::string (iter_buffer->first.c_str())); + dbg_str.append (std::string (" as read pointer: ")); - if (id_set != NULL) { - CallIDSet::iterator iter_set = id_set->begin(); + if(rbuffer) + rpointer = rbuffer->getReadPointerList(); - while (iter_set != id_set->end()) { - dbg_str.append (string (iter_set->c_str())); + if(rpointer) { + + ReadPointer::iterator iter_pointer = rpointer->begin(); + + while(iter_pointer != rpointer->end()) { + + dbg_str.append (string (iter_pointer->first.c_str())); dbg_str.append (string (", ")); - } - } - _debug ("%s", dbg_str.c_str()); - iter_map++; + iter_pointer++; + } + } + + _debug ("%s\n", dbg_str.c_str()); + + iter_buffer++; } + + + + } diff --git a/sflphone-common/src/audio/ringbuffer.cpp b/sflphone-common/src/audio/ringbuffer.cpp index 6e08859c70c796367a8b68ad13750043b22afb34..905377a4f12dc32f679156e88c73e84bd8ab4cfe 100644 --- a/sflphone-common/src/audio/ringbuffer.cpp +++ b/sflphone-common/src/audio/ringbuffer.cpp @@ -1,391 +1,370 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2009Savoir-Faire Linux inc. - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> - * Author: Yan Morin <yan.morin@savoirfairelinux.com> - * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> - * - * Portions (c) Dominic Mazzoni (Audacity) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <assert.h> -#include <stdlib.h> -#include <string.h> - -#include "ringbuffer.h" -#include "global.h" - -#define MIN_BUFFER_SIZE 1280 - -int RingBuffer::count_rb = 0; - -// Create a ring buffer with 'size' bytes -RingBuffer::RingBuffer (int size, CallID call_id) : mEnd (0) - , mBufferSize (size > MIN_BUFFER_SIZE ? size : MIN_BUFFER_SIZE) - , mBuffer (NULL) - , buffer_id (call_id) -{ - mBuffer = new unsigned char[mBufferSize]; - assert (mBuffer != NULL); - - count_rb++; -} - -// Free memory on object deletion -RingBuffer::~RingBuffer() -{ - delete[] mBuffer; - mBuffer = NULL; -} - -void -RingBuffer::flush (CallID call_id) -{ - _debug ("flush: reinit \"%s\" readpointer in \"%s\" ringbuffer", call_id.c_str(), buffer_id.c_str()); - storeReadPointer (mEnd, call_id); -} - - -void -RingBuffer::flushAll () -{ - // _debug("flushall: reinit all readpointer in \"%s\" ringbuffer", buffer_id.c_str()); - - // _debug("------------------------------ flushAll() in \"%s\" ringbuffer", buffer_id.c_str()); - - ReadPointer::iterator iter_pointer = _readpointer.begin(); - - while (iter_pointer != _readpointer.end()) { - // _debug("------------------------------ reinit readpointer %s", iter_pointer->first.c_str()); - iter_pointer->second = mEnd; - - iter_pointer++; - } -} - -int -RingBuffer::putLen() -{ - int mStart; - - if (_readpointer.size() >= 1) { - mStart = getSmallestReadPointer(); - } else { - mStart = 0; - } - - int length = (mEnd + mBufferSize - mStart) % mBufferSize; - - // _debug("RingBuffer::putLen length %i", length); - // _debug(" *RingBuffer::putLen: buffer_id %s, mStart %i, mEnd %i, length %i, buffersie %i", buffer_id.c_str(), mStart, mEnd, length, mBufferSize); - return length; -} - -int -RingBuffer::getLen (CallID call_id) -{ - - int mStart = getReadPointer (call_id); - - int length = (mEnd + mBufferSize - mStart) % mBufferSize; - // _debug(" *RingBuffer::getLen: buffer_id %s, call_id %s, mStart %i, mEnd %i, length %i, buffersie %i", buffer_id.c_str(), call_id.c_str(), mStart, mEnd, length, mBufferSize); - return length; - -} - -void -RingBuffer::debug() -{ - int mStart = getSmallestReadPointer(); - - _debug ("Start=%d; End=%d; BufferSize=%d", mStart, mEnd, mBufferSize); -} - -int -RingBuffer::getReadPointer (CallID call_id) -{ - - if (getNbReadPointer() == 0) - return 0; - - // _debug("RingBuffer::getReadPointer() id %s", call_id.c_str()); - - ReadPointer::iterator iter = _readpointer.find (call_id); - - if (iter == _readpointer.end()) { - // _debug(" RingBuffer::getReadPointer Error read pointer size: %i", _readpointer.size()); - // _debug(" RingBuffer::getReadPointer Error read pointer \"%s\" is null", call_id.c_str()); - ReadPointer::iterator iter2; - - for (iter2 = _readpointer.begin(); iter2 != _readpointer.end(); iter2++) { - // x_debug(" RingBuffer::getReadPointer list avail pointer \"%s\"", iter2->first.c_str()); - } - - return 0; - } else { - return iter->second; - } - -} - -int -RingBuffer::getSmallestReadPointer() -{ - if (getNbReadPointer() == 0) - return 0; - - int smallest = mBufferSize; - - ReadPointer::iterator iter = _readpointer.begin(); - - while (iter != _readpointer.end()) { - if (iter->second < smallest) - smallest = iter->second; - - iter++; - } - - return smallest; -} - -void -RingBuffer::storeReadPointer (int pointer_value, CallID call_id) -{ - - ReadPointer::iterator iter = _readpointer.find (call_id); - - if (iter != _readpointer.end()) { - iter->second = pointer_value; - // _debug("store read pointer call_id %s, size: %i ",call_id.c_str(), _readpointer.size()); - } else { - _debug ("storeReadPointer: Cannot find \"%s\" readPointer in \"%s\" ringbuffer", call_id.c_str(), buffer_id.c_str()); - } - -} - - -void -RingBuffer::createReadPointer (CallID call_id) -{ - - _debug ("---- createReadPointer ringbuffer_id %s, call_id %s", buffer_id.c_str(), call_id.c_str()); - - _readpointer.insert (pair<CallID, int> (call_id, mEnd)); - _debug ("---- createReadPointer ringbuffer_id %s, size %i", buffer_id.c_str(), (int) _readpointer.size()); - -} - - -void -RingBuffer::removeReadPointer (CallID call_id) -{ - - _debug ("---- removeReadPointer ringbuffer_id %s, call_id %s", buffer_id.c_str(), call_id.c_str()); - - _readpointer.erase (call_id); - _debug ("---- removeReadPointer ringbuffer_id %s, size %i", buffer_id.c_str(), (int) _readpointer.size()); - -} - - -bool -RingBuffer::hasThisReadPointer (CallID call_id) -{ - ReadPointer::iterator iter = _readpointer.find (call_id); - - if (iter == _readpointer.end()) { - return false; - } else { - return true; - } -} - - -int -RingBuffer::getNbReadPointer() -{ - return _readpointer.size(); -} - -// -// For the writer only: -// -int -RingBuffer::AvailForPut() -{ - // Always keep 4 bytes safe (?) - // z_debug("RingBuffer::AvailForPut: putLen %i", putLen()); - // _debug("RingBuffer::AvailForPut %s --------------------", buffer_id.c_str()); - return (mBufferSize-4) - putLen(); -} - -// This one puts some data inside the ring buffer. -// Change the volume if it's not 100 -int -RingBuffer::Put (void* buffer, int toCopy, unsigned short volume) -{ - samplePtr src; - int block; - int copied; - int pos; - // _debug("RingBuffer::Put buffer_id %s, call_id %s --------------------", buffer_id.c_str(), call_id.c_str()); - int len = putLen(); - // _debug(" RingBuffer::Put bufferid %s, putlen %i", buffer_id.c_str(), len); - - if (toCopy > (mBufferSize-4) - len) - toCopy = (mBufferSize-4) - len; - - src = (samplePtr) buffer; - - - copied = 0; - - pos = mEnd; - - while (toCopy) { - block = toCopy; - - // Wrap block around ring ? - - if (block > (mBufferSize - pos)) { - // Fill in to the end of the buffer - block = mBufferSize - pos; - } - - // Gain adjustment (when Mic vol. is changed) - if (volume != 100) { - SFLDataFormat* start = (SFLDataFormat*) src; - int nbSample = block / sizeof (SFLDataFormat); - - for (int i=0; i<nbSample; i++) { - start[i] = start[i] * volume / 100; - } - } - - // bcopy(src, dest, len) - //fprintf(stderr, "has %d put %d\t", len, block); - bcopy (src, mBuffer + pos, block); - - src += block; - - pos = (pos + block) % mBufferSize; - - toCopy -= block; - - copied += block; - } - - mEnd = pos; - - // How many items copied. - return copied; -} - -// -// For the reader only: -// - -int -RingBuffer::AvailForGet (CallID call_id) -{ - // Used space - // _debug("RingBuffer::AvailForGet buffer_id %s, call_id %s --------------------", buffer_id.c_str(), call_id.c_str()); - return getLen (call_id); -} - -// Get will move 'toCopy' bytes from the internal FIFO to 'buffer' -int -RingBuffer::Get (void *buffer, int toCopy, unsigned short volume, CallID call_id) -{ - - if (getNbReadPointer() == 0) - return 0; - - if (!hasThisReadPointer (call_id)) - return 0; - - samplePtr dest; - - int block; - - int copied; - - // _debug("RingBuffer::Get buffer_id %s, call_id %s --------------------", buffer_id.c_str(), call_id.c_str()); - int len = getLen (call_id); - - // _debug(" RingBuffer::Get bufferid %s, getlen %i", buffer_id.c_str(), len); - - if (toCopy > len) - toCopy = len; - - dest = (samplePtr) buffer; - - copied = 0; - - int mStart = getReadPointer (call_id); - - //fprintf(stderr, "G"); - while (toCopy) { - block = toCopy; - - if (block > (mBufferSize - mStart)) { - block = mBufferSize - mStart; - } - - if (volume!=100) { - SFLDataFormat* start = (SFLDataFormat*) (mBuffer + mStart); - int nbSample = block / sizeof (SFLDataFormat); - - for (int i=0; i<nbSample; i++) { - start[i] = start[i] * volume / 100; - } - } - - // bcopy(src, dest, len) - bcopy (mBuffer + mStart, dest, block); - - dest += block; - - mStart = (mStart + block) % mBufferSize; - - toCopy -= block; - - copied += block; - } - - storeReadPointer (mStart, call_id); - - return copied; -} - -// Used to discard some bytes. -int -RingBuffer::Discard (int toDiscard, CallID call_id) -{ - // _debug("RingBuffer::Discard buffer_id %s, call_id %s --------------------", buffer_id.c_str(), call_id.c_str()); - int len = getLen (call_id); - - int mStart = getReadPointer (call_id); - - if (toDiscard > len) - toDiscard = len; - - mStart = (mStart + toDiscard) % mBufferSize; - - storeReadPointer (mStart, call_id); - - return toDiscard; -} +/* + * Copyright (C) 2004, 2005, 2006, 2009Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * Author: Yan Morin <yan.morin@savoirfairelinux.com> + * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> + * + * Portions (c) Dominic Mazzoni (Audacity) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +#include "ringbuffer.h" +#include "global.h" + +#define MIN_BUFFER_SIZE 1280 + +int RingBuffer::count_rb = 0; + +// Create a ring buffer with 'size' bytes +RingBuffer::RingBuffer (int size, CallID call_id) : mEnd (0) + , mBufferSize (size > MIN_BUFFER_SIZE ? size : MIN_BUFFER_SIZE) + , mBuffer (NULL) + , buffer_id (call_id) +{ + mBuffer = new unsigned char[mBufferSize]; + assert (mBuffer != NULL); + + count_rb++; +} + +// Free memory on object deletion +RingBuffer::~RingBuffer() +{ + delete[] mBuffer; + mBuffer = NULL; +} + +void +RingBuffer::flush (CallID call_id) +{ + + storeReadPointer (mEnd, call_id); +} + + +void +RingBuffer::flushAll () +{ + + + ReadPointer::iterator iter_pointer = _readpointer.begin(); + + while (iter_pointer != _readpointer.end()) { + + iter_pointer->second = mEnd; + + iter_pointer++; + } +} + +int +RingBuffer::putLen() +{ + int mStart; + + if (_readpointer.size() >= 1) { + mStart = getSmallestReadPointer(); + } else { + mStart = 0; + } + + int length = (mEnd + mBufferSize - mStart) % mBufferSize; + + return length; +} + +int +RingBuffer::getLen (CallID call_id) +{ + + int mStart = getReadPointer (call_id); + + int length = (mEnd + mBufferSize - mStart) % mBufferSize; + // _debug(" *RingBuffer::getLen: buffer_id %s, call_id %s, mStart %i, mEnd %i, length %i, buffersie %i", buffer_id.c_str(), call_id.c_str(), mStart, mEnd, length, mBufferSize); + return length; + +} + +void +RingBuffer::debug() +{ + int mStart = getSmallestReadPointer(); + + _debug ("Start=%d; End=%d; BufferSize=%d", mStart, mEnd, mBufferSize); +} + +int +RingBuffer::getReadPointer (CallID call_id) +{ + + if (getNbReadPointer() == 0) + return 0; + + ReadPointer::iterator iter = _readpointer.find (call_id); + + if (iter == _readpointer.end()) { + return 0; + } else { + return iter->second; + } + +} + +int +RingBuffer::getSmallestReadPointer() +{ + if (getNbReadPointer() == 0) + return 0; + + int smallest = mBufferSize; + + ReadPointer::iterator iter = _readpointer.begin(); + + while (iter != _readpointer.end()) { + if (iter->second < smallest) + smallest = iter->second; + + iter++; + } + + return smallest; +} + +void +RingBuffer::storeReadPointer (int pointer_value, CallID call_id) +{ + + ReadPointer::iterator iter = _readpointer.find (call_id); + + if (iter != _readpointer.end()) { + iter->second = pointer_value; + } else { + _debug ("storeReadPointer: Cannot find \"%s\" readPointer in \"%s\" ringbuffer", call_id.c_str(), buffer_id.c_str()); + } + +} + + +void +RingBuffer::createReadPointer (CallID call_id) +{ + + _readpointer.insert (pair<CallID, int> (call_id, mEnd)); + +} + + +void +RingBuffer::removeReadPointer (CallID call_id) +{ + + + _readpointer.erase (call_id); + + +} + + +bool +RingBuffer::hasThisReadPointer (CallID call_id) +{ + ReadPointer::iterator iter = _readpointer.find (call_id); + + if (iter == _readpointer.end()) { + return false; + } else { + return true; + } +} + + +int +RingBuffer::getNbReadPointer() +{ + return _readpointer.size(); +} + +// +// For the writer only: +// +int +RingBuffer::AvailForPut() +{ + // Always keep 4 bytes safe (?) + + return (mBufferSize-4) - putLen(); +} + +// This one puts some data inside the ring buffer. +// Change the volume if it's not 100 +int +RingBuffer::Put (void* buffer, int toCopy, unsigned short volume) +{ + samplePtr src; + int block; + int copied; + int pos; + + int len = putLen(); + + + if (toCopy > (mBufferSize-4) - len) + toCopy = (mBufferSize-4) - len; + + src = (samplePtr) buffer; + + + copied = 0; + + pos = mEnd; + + while (toCopy) { + block = toCopy; + + // Wrap block around ring ? + + if (block > (mBufferSize - pos)) { + // Fill in to the end of the buffer + block = mBufferSize - pos; + } + + // Gain adjustment (when Mic vol. is changed) + if (volume != 100) { + SFLDataFormat* start = (SFLDataFormat*) src; + int nbSample = block / sizeof (SFLDataFormat); + + for (int i=0; i<nbSample; i++) { + start[i] = start[i] * volume / 100; + } + } + + // bcopy(src, dest, len) + //fprintf(stderr, "has %d put %d\t", len, block); + bcopy (src, mBuffer + pos, block); + + src += block; + + pos = (pos + block) % mBufferSize; + + toCopy -= block; + + copied += block; + } + + mEnd = pos; + + // How many items copied. + return copied; +} + +// +// For the reader only: +// + +int +RingBuffer::AvailForGet (CallID call_id) +{ + // Used space + + return getLen (call_id); +} + +// Get will move 'toCopy' bytes from the internal FIFO to 'buffer' +int +RingBuffer::Get (void *buffer, int toCopy, unsigned short volume, CallID call_id) +{ + + if (getNbReadPointer() == 0) + return 0; + + if (!hasThisReadPointer (call_id)) + return 0; + + samplePtr dest; + + int block; + + int copied; + + + int len = getLen (call_id); + + + if (toCopy > len) + toCopy = len; + + dest = (samplePtr) buffer; + + copied = 0; + + int mStart = getReadPointer (call_id); + + //fprintf(stderr, "G"); + while (toCopy) { + block = toCopy; + + if (block > (mBufferSize - mStart)) { + block = mBufferSize - mStart; + } + + if (volume!=100) { + SFLDataFormat* start = (SFLDataFormat*) (mBuffer + mStart); + int nbSample = block / sizeof (SFLDataFormat); + + for (int i=0; i<nbSample; i++) { + start[i] = start[i] * volume / 100; + } + } + + // bcopy(src, dest, len) + bcopy (mBuffer + mStart, dest, block); + + dest += block; + + mStart = (mStart + block) % mBufferSize; + + toCopy -= block; + + copied += block; + } + + storeReadPointer (mStart, call_id); + + return copied; +} + +// Used to discard some bytes. +int +RingBuffer::Discard (int toDiscard, CallID call_id) +{ + + int len = getLen (call_id); + + int mStart = getReadPointer (call_id); + + if (toDiscard > len) + toDiscard = len; + + mStart = (mStart + toDiscard) % mBufferSize; + + storeReadPointer (mStart, call_id); + + return toDiscard; +} diff --git a/sflphone-common/src/audio/ringbuffer.h b/sflphone-common/src/audio/ringbuffer.h index ac559e98c1db50c4571d33f8ea97e5c508e03125..96871f825db937f91a9cb1a3c6e1ed44f9d4a8cf 100644 --- a/sflphone-common/src/audio/ringbuffer.h +++ b/sflphone-common/src/audio/ringbuffer.h @@ -57,9 +57,10 @@ class RingBuffer { void flushAll(); - int getReadPointer(CallID call_id = default_id); + ReadPointer* getReadPointerList() { return &_readpointer; } + int getSmallestReadPointer(); void storeReadPointer(int pointer_value, CallID call_id = default_id); diff --git a/sflphone-common/src/conference.cpp b/sflphone-common/src/conference.cpp index 667664dfb6ff7bc66ead16cd08a5c353f5d882a8..2b99db9a27a27ded2b8dd140d220eab6453b58f5 100644 --- a/sflphone-common/src/conference.cpp +++ b/sflphone-common/src/conference.cpp @@ -71,7 +71,7 @@ void Conference::setState (ConferenceState state) void Conference::add (CallID participant_id) { - _debug ("---- Conference:: add participant %s", participant_id.c_str()); + _debug ("Conference:: add participant %s", participant_id.c_str()); _participants.insert (participant_id); @@ -82,7 +82,8 @@ void Conference::add (CallID participant_id) void Conference::remove (CallID participant_id) { - _debug ("---- Conference::remove participant %s", participant_id.c_str()); + + _debug ("Conference::remove participant %s", participant_id.c_str()); _participants.erase (participant_id); @@ -100,7 +101,6 @@ void Conference::bindParticipant (CallID participant_id) if (participant_id != (*iter)) { - _debug ("---- Conference:: bind callid %s with %s in conference add", participant_id.c_str(), (*iter).c_str()); Manager::instance().getAudioDriver()->getMainBuffer()->bindCallID (participant_id, *iter); } @@ -109,7 +109,6 @@ void Conference::bindParticipant (CallID participant_id) } - _debug ("---- Conference::bind callid %s with default_id in conference add", participant_id.c_str()); Manager::instance().getAudioDriver()->getMainBuffer()->bindCallID (participant_id); diff --git a/sflphone-common/src/iax/iaxvoiplink.cpp b/sflphone-common/src/iax/iaxvoiplink.cpp index 7054e00d1aa4bb8e564320f10ff65b26b21e9bfb..342c9e3faf00d2ba6ac7cea14996fd339654af59 100644 --- a/sflphone-common/src/iax/iaxvoiplink.cpp +++ b/sflphone-common/src/iax/iaxvoiplink.cpp @@ -364,7 +364,7 @@ IAXVoIPLink::sendAudioFromMic (void) _mutexIAX.enterMutex(); // Make sure the session and the call still exists. - if (currentCall->getSession() && micDataEncoded != NULL) { + if (currentCall->getSession() && (micDataEncoded != NULL) && (nbSample_ > 0)) { if (iax_send_voice (currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, nbSample_) == -1) { _debug ("IAX: Error sending voice data."); } diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 6b1d15aa1e61d9b901d0a557c39d1c70d63599e8..0c583cffad61c021bd7c47c5a13fb496f76a71a8 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1246,6 +1246,9 @@ ManagerImpl::joinParticipant (const CallID& call_id1, const CallID& call_id2) // switchCall(conf->getConfID()); + if(_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); + } @@ -1346,6 +1349,9 @@ ManagerImpl::removeParticipant (const CallID& call_id) } + if(_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); + } @@ -1459,7 +1465,6 @@ ManagerImpl::addStream (const CallID& call_id) if (iter != _conferencemap.end()) { Conference* conf = iter->second; - _debug (" addStream: bind call %s to conference %s", call_id.c_str(), conf->getConfID().c_str()); conf->bindParticipant (call_id); @@ -1481,7 +1486,6 @@ ManagerImpl::addStream (const CallID& call_id) } else { - _debug (" addStream: bind call %s to main", call_id.c_str()); // bind to main getAudioDriver()->getMainBuffer()->bindCallID (call_id); @@ -1491,6 +1495,9 @@ ManagerImpl::addStream (const CallID& call_id) _audiodriver->flushMain(); } + + if(_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); } void @@ -1504,6 +1511,8 @@ ManagerImpl::removeStream (const CallID& call_id) removeParticipant (call_id); } + if(_audiodriver) + _audiodriver->getMainBuffer()->stateInfo(); } //THREAD=Main diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 7ee1d1f13fa1e3b2c4645bdc761e5bd7b8d59d0e..6ed46e39b63ef4c3170608789066c7461099e0d1 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -2859,13 +2859,37 @@ void call_on_forked (pjsip_inv_session *inv, pjsip_event *e) void call_on_tsx_changed (pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e) { - _debug ("call_on_tsx_changed to state %s", transactionStateMap[tsx->state]); + + _debug("call_on_tsx_changed to state %s", transactionStateMap[tsx->state]); if (tsx->role==PJSIP_ROLE_UAS && tsx->state==PJSIP_TSX_STATE_TRYING && - pjsip_method_cmp (&tsx->method, &pjsip_refer_method) ==0) { + pjsip_method_cmp (&tsx->method, &pjsip_refer_method) ==0) { /** Handle the refer method **/ onCallTransfered (inv, e->body.tsx_state.src.rdata); } + else if (tsx->role==PJSIP_ROLE_UAS && tsx->state==PJSIP_TSX_STATE_TRYING) { + + if (e && e->body.rx_msg.rdata) { + + pjsip_tx_data* t_data; + pjsip_rx_data* r_data = e->body.rx_msg.rdata; + + if(r_data->msg_info.msg->line.req.method.id == PJSIP_OTHER_METHOD) { + + std::string method_name = "INFO"; + std::string request = r_data->msg_info.msg->line.req.method.name.ptr; + + if (request.find (method_name) != (size_t)-1) { + + _debug("%s\n", pjsip_rx_data_get_info(r_data)); + + pjsip_dlg_create_response (inv->dlg, r_data, PJSIP_SC_OK, NULL, &t_data); + + pjsip_dlg_send_response(inv->dlg, tsx, t_data); + } + } + } + } } void regc_cb (struct pjsip_regc_cbparam *param)