~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/ringbuffer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "ringbuffer.h"
40
40
#include "global.h"
41
41
 
 
42
// corespond to 106 ms (about 5 rtp packets)
42
43
#define MIN_BUFFER_SIZE 1280
43
44
 
44
45
int RingBuffer::count_rb = 0;
45
46
 
46
47
// Create  a ring buffer with 'size' bytes
47
48
RingBuffer::RingBuffer (int size, CallID call_id) : mEnd (0)
48
 
        , mBufferSize (size > MIN_BUFFER_SIZE ? size : MIN_BUFFER_SIZE)
49
 
        , mBuffer (NULL)
50
 
        , buffer_id (call_id)
 
49
    , mBufferSize (size > MIN_BUFFER_SIZE ? size : MIN_BUFFER_SIZE)
 
50
    , mBuffer (NULL)
 
51
    , buffer_id (call_id)
51
52
{
52
53
    mBuffer = new unsigned char[mBufferSize];
53
54
    assert (mBuffer != NULL);
108
109
    int mStart = getReadPointer (call_id);
109
110
 
110
111
    int length = (mEnd + mBufferSize - mStart) % mBufferSize;
 
112
 
 
113
 
111
114
    // _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);
112
115
    return length;
113
116
 
176
179
void
177
180
RingBuffer::createReadPointer (CallID call_id)
178
181
{
179
 
 
180
 
    _readpointer.insert (pair<CallID, int> (call_id, mEnd));
 
182
    if (!hasThisReadPointer (call_id))
 
183
        _readpointer.insert (pair<CallID, int> (call_id, mEnd));
181
184
 
182
185
}
183
186
 
185
188
void
186
189
RingBuffer::removeReadPointer (CallID call_id)
187
190
{
188
 
 
189
 
 
190
 
    _readpointer.erase (call_id);
191
 
 
192
 
 
 
191
    ReadPointer::iterator iter = _readpointer.find (call_id);
 
192
 
 
193
    if (iter != _readpointer.end())
 
194
        _readpointer.erase (iter);
193
195
}
194
196
 
195
197
 
220
222
{
221
223
    // Always keep 4 bytes safe (?)
222
224
 
223
 
    return (mBufferSize-4) - putLen();
 
225
    return mBufferSize - putLen();
224
226
}
225
227
 
226
228
// This one puts some data inside the ring buffer.
236
238
    int len = putLen();
237
239
 
238
240
 
239
 
    if (toCopy > (mBufferSize-4) - len)
240
 
        toCopy = (mBufferSize-4) - len;
 
241
    if (toCopy > mBufferSize - len)
 
242
        toCopy = mBufferSize - len;
241
243
 
242
244
    src = (samplePtr) buffer;
243
245
 
250
252
        block = toCopy;
251
253
 
252
254
        // Wrap block around ring ?
253
 
 
254
255
        if (block > (mBufferSize - pos)) {
255
256
            // Fill in to the end of the buffer
256
257
            block = mBufferSize - pos;
270
271
        //fprintf(stderr, "has %d put %d\t", len, block);
271
272
        bcopy (src, mBuffer + pos, block);
272
273
 
273
 
          src += block;
 
274
        src += block;
274
275
 
275
276
        pos = (pos + block) % mBufferSize;
276
277
 
314
315
 
315
316
    int copied;
316
317
 
317
 
 
318
318
    int len = getLen (call_id);
319
319
 
320
320