Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
29147e10
Commit
29147e10
authored
13 years ago
by
Rafaël Carré
Browse files
Options
Downloads
Patches
Plain Diff
RingBuffer: simplify
parent
40d29c3b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sflphone-common/src/audio/ringbuffer.cpp
+18
-95
18 additions, 95 deletions
sflphone-common/src/audio/ringbuffer.cpp
sflphone-common/src/audio/ringbuffer.h
+1
-4
1 addition, 4 deletions
sflphone-common/src/audio/ringbuffer.h
with
19 additions
and
99 deletions
sflphone-common/src/audio/ringbuffer.cpp
+
18
−
95
View file @
29147e10
...
...
@@ -90,56 +90,30 @@ RingBuffer::flushAll ()
int
RingBuffer
::
putLen
()
{
int
mStart
;
if
(
_readpointer
.
size
()
>=
1
)
{
mStart
=
getSmallestReadPointer
();
}
else
{
mStart
=
0
;
}
int
length
=
(
mEnd
+
mBufferSize
-
mStart
)
%
mBufferSize
;
return
length
;
int
mStart
=
(
_readpointer
.
size
()
>=
1
)
?
getSmallestReadPointer
()
:
0
;
return
(
mEnd
+
mBufferSize
-
mStart
)
%
mBufferSize
;
}
int
RingBuffer
::
getLen
(
std
::
string
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
;
return
(
mEnd
+
mBufferSize
-
getReadPointer
(
call_id
))
%
mBufferSize
;
}
void
RingBuffer
::
debug
()
{
int
mStart
=
getSmallestReadPointer
();
_debug
(
"Start=%d; End=%d; BufferSize=%d"
,
mStart
,
mEnd
,
mBufferSize
);
_debug
(
"Start=%d; End=%d; BufferSize=%d"
,
getSmallestReadPointer
(),
mEnd
,
mBufferSize
);
}
int
RingBuffer
::
getReadPointer
(
std
::
string
call_id
)
{
if
(
getNbReadPointer
()
==
0
)
return
0
;
ReadPointer
::
iterator
iter
=
_readpointer
.
find
(
call_id
);
if
(
iter
==
_readpointer
.
end
())
{
return
0
;
}
else
{
return
iter
->
second
;
}
return
(
iter
!=
_readpointer
.
end
())
?
iter
->
second
:
0
;
}
int
...
...
@@ -150,22 +124,17 @@ RingBuffer::getSmallestReadPointer()
int
smallest
=
mBufferSize
;
ReadPointer
::
iterator
iter
=
_readpointer
.
begin
();
while
(
iter
!=
_readpointer
.
end
())
{
ReadPointer
::
iterator
iter
;
for
(
iter
=
_readpointer
.
begin
();
iter
!=
_readpointer
.
end
();
++
iter
)
if
(
iter
->
second
<
smallest
)
smallest
=
iter
->
second
;
iter
++
;
}
return
smallest
;
}
void
RingBuffer
::
storeReadPointer
(
int
pointer_value
,
std
::
string
call_id
)
{
ReadPointer
::
iterator
iter
=
_readpointer
.
find
(
call_id
);
if
(
iter
!=
_readpointer
.
end
())
{
...
...
@@ -173,7 +142,6 @@ RingBuffer::storeReadPointer (int pointer_value, std::string call_id)
}
else
{
_debug
(
"storeReadPointer: Cannot find
\"
%s
\"
readPointer in
\"
%s
\"
ringbuffer"
,
call_id
.
c_str
(),
buffer_id
.
c_str
());
}
}
...
...
@@ -182,7 +150,6 @@ RingBuffer::createReadPointer (std::string call_id)
{
if
(
!
hasThisReadPointer
(
call_id
))
_readpointer
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
call_id
,
mEnd
));
}
...
...
@@ -190,7 +157,6 @@ void
RingBuffer
::
removeReadPointer
(
std
::
string
call_id
)
{
ReadPointer
::
iterator
iter
=
_readpointer
.
find
(
call_id
);
if
(
iter
!=
_readpointer
.
end
())
_readpointer
.
erase
(
iter
);
}
...
...
@@ -199,13 +165,7 @@ RingBuffer::removeReadPointer (std::string call_id)
bool
RingBuffer
::
hasThisReadPointer
(
std
::
string
call_id
)
{
ReadPointer
::
iterator
iter
=
_readpointer
.
find
(
call_id
);
if
(
iter
==
_readpointer
.
end
())
{
return
false
;
}
else
{
return
true
;
}
return
_readpointer
.
find
(
call_id
)
!=
_readpointer
.
end
();
}
...
...
@@ -230,42 +190,24 @@ RingBuffer::AvailForPut()
int
RingBuffer
::
Put
(
void
*
buffer
,
int
toCopy
)
{
samplePtr
src
;
int
block
;
int
copied
;
int
pos
;
int
len
=
putLen
();
if
(
toCopy
>
mBufferSize
-
len
)
toCopy
=
mBufferSize
-
len
;
int
copied
=
toCopy
;
src
=
(
samplePtr
)
buffer
;
copied
=
0
;
unsigned
char
*
src
=
(
unsigned
char
*
)
buffer
;
pos
=
mEnd
;
int
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
;
}
int
block
=
toCopy
;
if
(
block
>
mBufferSize
-
pos
)
// Wrap block around ring ?
block
=
mBufferSize
-
pos
;
// Fill in to the end of the buffer
memcpy
(
mBuffer
+
pos
,
src
,
block
);
src
+=
block
;
pos
=
(
pos
+
block
)
%
mBufferSize
;
toCopy
-=
block
;
copied
+=
block
;
}
mEnd
=
pos
;
...
...
@@ -290,51 +232,32 @@ RingBuffer::AvailForGet (std::string call_id)
int
RingBuffer
::
Get
(
void
*
buffer
,
int
toCopy
,
std
::
string
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
;
int
copied
=
toCopy
;
dest
=
(
samplePtr
)
buffer
;
copied
=
0
;
unsigned
char
*
dest
=
(
unsigned
char
*
)
buffer
;
int
mStart
=
getReadPointer
(
call_id
);
while
(
toCopy
)
{
block
=
toCopy
;
if
(
block
>
(
mBufferSize
-
mStart
))
{
int
block
=
toCopy
;
if
(
block
>
mBufferSize
-
mStart
)
block
=
mBufferSize
-
mStart
;
}
memcpy
(
dest
,
mBuffer
+
mStart
,
block
);
dest
+=
block
;
mStart
=
(
mStart
+
block
)
%
mBufferSize
;
toCopy
-=
block
;
copied
+=
block
;
}
storeReadPointer
(
mStart
,
call_id
);
return
copied
;
}
...
...
This diff is collapsed.
Click to expand it.
sflphone-common/src/audio/ringbuffer.h
+
1
−
4
View file @
29147e10
...
...
@@ -26,9 +26,6 @@
#include
<fstream>
typedef
unsigned
char
*
samplePtr
;
typedef
std
::
map
<
std
::
string
,
int
>
ReadPointer
;
static
std
::
string
default_id
=
"audiolayer_id"
;
...
...
@@ -159,7 +156,7 @@ class RingBuffer
/** Buffer size */
int
mBufferSize
;
/** Data */
samplePtr
mBuffer
;
unsigned
char
*
mBuffer
;
ReadPointer
_readpointer
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment