Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
32a89484
Commit
32a89484
authored
Oct 13, 2011
by
Tristan Matthews
Browse files
* #7131: more cleanup in audio
parent
02bfd071
Changes
6
Hide whitespace changes
Inline
Side-by-side
daemon/src/audio/mainbuffer.cpp
View file @
32a89484
...
...
@@ -33,36 +33,33 @@
#include
<utility>
// for std::pair
#include
"manager.h"
MainBuffer
::
MainBuffer
()
:
_internalSamplingRate
(
8000
)
{
}
MainBuffer
::
MainBuffer
()
:
internalSamplingRate_
(
8000
)
{}
MainBuffer
::~
MainBuffer
()
{
// delete any ring buffers that didn't get removed
for
(
RingBufferMap
::
iterator
iter
=
_
ringBufferMap
.
begin
();
iter
!=
_
ringBufferMap
.
end
();
++
iter
)
for
(
RingBufferMap
::
iterator
iter
=
ringBufferMap
_
.
begin
();
iter
!=
ringBufferMap
_
.
end
();
++
iter
)
delete
iter
->
second
;
}
void
MainBuffer
::
setInternalSamplingRate
(
int
sr
)
{
if
(
sr
>
_
internalSamplingRate
)
{
if
(
sr
>
internalSamplingRate
_
)
{
flushAllBuffers
();
_
internalSamplingRate
=
sr
;
internalSamplingRate
_
=
sr
;
}
}
CallIDSet
*
MainBuffer
::
getCallIDSet
(
const
std
::
string
&
call_id
)
{
CallIDMap
::
iterator
iter
=
_
callIDMap
.
find
(
call_id
);
return
(
iter
!=
_
callIDMap
.
end
())
?
iter
->
second
:
NULL
;
CallIDMap
::
iterator
iter
=
callIDMap
_
.
find
(
call_id
);
return
(
iter
!=
callIDMap
_
.
end
())
?
iter
->
second
:
NULL
;
}
void
MainBuffer
::
createCallIDSet
(
const
std
::
string
&
set_id
)
{
_
callIDMap
.
insert
(
std
::
pair
<
std
::
string
,
CallIDSet
*>
(
set_id
,
new
CallIDSet
));
callIDMap
_
.
insert
(
std
::
pair
<
std
::
string
,
CallIDSet
*>
(
set_id
,
new
CallIDSet
));
}
bool
MainBuffer
::
removeCallIDSet
(
const
std
::
string
&
set_id
)
...
...
@@ -74,7 +71,7 @@ bool MainBuffer::removeCallIDSet(const std::string & set_id)
return
false
;
}
if
(
_
callIDMap
.
erase
(
set_id
)
==
0
)
{
if
(
callIDMap
_
.
erase
(
set_id
)
==
0
)
{
_debug
(
"removeCallIDSet error while removing callid set %s!"
,
set_id
.
c_str
());
return
false
;
}
...
...
@@ -100,29 +97,25 @@ void MainBuffer::removeCallIDfromSet(const std::string & set_id, const std::stri
_error
(
"removeCallIDfromSet error while removing callid %s from set %s!"
,
call_id
.
c_str
(),
set_id
.
c_str
());
}
RingBuffer
*
MainBuffer
::
getRingBuffer
(
const
std
::
string
&
call_id
)
{
RingBufferMap
::
iterator
iter
=
_ringBufferMap
.
find
(
call_id
);
return
(
iter
!=
_ringBufferMap
.
end
())
?
iter
->
second
:
NULL
;
RingBufferMap
::
iterator
iter
=
ringBufferMap_
.
find
(
call_id
);
return
(
iter
!=
ringBufferMap_
.
end
())
?
iter
->
second
:
NULL
;
}
RingBuffer
*
MainBuffer
::
createRingBuffer
(
const
std
::
string
&
call_id
)
{
RingBuffer
*
newRingBuffer
=
new
RingBuffer
(
SIZEBUF
,
call_id
);
_
ringBufferMap
.
insert
(
std
::
pair
<
std
::
string
,
RingBuffer
*>
(
call_id
,
newRingBuffer
));
ringBufferMap
_
.
insert
(
std
::
pair
<
std
::
string
,
RingBuffer
*>
(
call_id
,
newRingBuffer
));
return
newRingBuffer
;
}
bool
MainBuffer
::
removeRingBuffer
(
const
std
::
string
&
call_id
)
{
RingBuffer
*
ring_buffer
=
getRingBuffer
(
call_id
);
if
(
ring_buffer
!=
NULL
)
{
if
(
_
ringBufferMap
.
erase
(
call_id
)
!=
0
)
{
if
(
ringBufferMap
_
.
erase
(
call_id
)
!=
0
)
{
delete
ring_buffer
;
return
true
;
}
else
{
...
...
@@ -135,10 +128,9 @@ bool MainBuffer::removeRingBuffer(const std::string & call_id)
}
}
void
MainBuffer
::
bindCallID
(
const
std
::
string
&
call_id1
,
const
std
::
string
&
call_id2
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
RingBuffer
*
ring_buffer
;
CallIDSet
*
callid_set
;
...
...
@@ -156,18 +148,14 @@ void MainBuffer::bindCallID(const std::string & call_id1, const std::string & ca
createCallIDSet
(
call_id2
);
getRingBuffer
(
call_id1
)
->
createReadPointer
(
call_id2
);
getRingBuffer
(
call_id2
)
->
createReadPointer
(
call_id1
);
addCallIDtoSet
(
call_id1
,
call_id2
);
addCallIDtoSet
(
call_id2
,
call_id1
);
}
void
MainBuffer
::
bindHalfDuplexOut
(
const
std
::
string
&
process_id
,
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
// This method is used only for active calls, if this call does not exist, do nothing
if
(
!
getRingBuffer
(
call_id
))
...
...
@@ -177,15 +165,12 @@ void MainBuffer::bindHalfDuplexOut(const std::string & process_id, const std::st
createCallIDSet
(
process_id
);
getRingBuffer
(
call_id
)
->
createReadPointer
(
process_id
);
addCallIDtoSet
(
process_id
,
call_id
);
}
void
MainBuffer
::
unBindCallID
(
const
std
::
string
&
call_id1
,
const
std
::
string
&
call_id2
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
removeCallIDfromSet
(
call_id1
,
call_id2
);
removeCallIDfromSet
(
call_id2
,
call_id1
);
...
...
@@ -193,20 +178,17 @@ void MainBuffer::unBindCallID(const std::string & call_id1, const std::string &
RingBuffer
*
ringbuffer
=
getRingBuffer
(
call_id2
);
if
(
ringbuffer
)
{
ringbuffer
->
removeReadPointer
(
call_id1
);
if
(
ringbuffer
->
getNbReadPointer
()
==
0
)
{
removeCallIDSet
(
call_id2
);
removeRingBuffer
(
call_id2
);
}
}
ringbuffer
=
getRingBuffer
(
call_id1
);
if
(
ringbuffer
)
{
ringbuffer
->
removeReadPointer
(
call_id2
);
if
(
ringbuffer
->
getNbReadPointer
()
==
0
)
{
...
...
@@ -218,7 +200,7 @@ void MainBuffer::unBindCallID(const std::string & call_id1, const std::string &
void
MainBuffer
::
unBindHalfDuplexOut
(
const
std
::
string
&
process_id
,
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
removeCallIDfromSet
(
process_id
,
call_id
);
...
...
@@ -236,17 +218,12 @@ void MainBuffer::unBindHalfDuplexOut(const std::string & process_id, const std::
removeCallIDSet
(
process_id
);
}
CallIDSet
*
callid_set
=
getCallIDSet
(
process_id
);
if
(
callid_set
)
{
if
(
callid_set
->
empty
())
removeCallIDSet
(
process_id
);
}
if
(
callid_set
and
callid_set
->
empty
())
removeCallIDSet
(
process_id
);
}
void
MainBuffer
::
unBindAll
(
const
std
::
string
&
call_id
)
{
CallIDSet
*
callid_set
=
getCallIDSet
(
call_id
);
...
...
@@ -267,13 +244,11 @@ void MainBuffer::unBindAll(const std::string & call_id)
iter_set
++
;
}
}
void
MainBuffer
::
putData
(
void
*
buffer
,
int
toCopy
,
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
RingBuffer
*
ring_buffer
=
getRingBuffer
(
call_id
);
...
...
@@ -283,21 +258,20 @@ void MainBuffer::putData(void *buffer, int toCopy, const std::string & call_id)
int
MainBuffer
::
getData
(
void
*
buffer
,
int
toCopy
,
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
CallIDSet
*
callid_set
=
getCallIDSet
(
call_id
);
if
(
!
callid_set
||
callid_set
->
empty
())
{
if
(
not
callid_set
or
callid_set
->
empty
())
return
0
;
}
if
(
callid_set
->
size
()
==
1
)
{
CallIDSet
::
iterator
iter_id
=
callid_set
->
begin
();
if
(
iter_id
!=
callid_set
->
end
())
{
if
(
iter_id
!=
callid_set
->
end
())
return
getDataByID
(
buffer
,
toCopy
,
*
iter_id
,
call_id
);
}
else
else
return
0
;
}
else
{
memset
(
buffer
,
0
,
toCopy
);
...
...
@@ -313,9 +287,8 @@ int MainBuffer::getData(void *buffer, int toCopy, const std::string & call_id)
size
=
getDataByID
(
mixBuffer
,
toCopy
,
*
iter_id
,
call_id
);
if
(
size
>
0
)
{
for
(
int
k
=
0
;
k
<
nbSmplToCopy
;
k
++
)
{
for
(
int
k
=
0
;
k
<
nbSmplToCopy
;
k
++
)
((
SFLDataFormat
*
)(
buffer
))[
k
]
+=
mixBuffer
[
k
];
}
}
iter_id
++
;
...
...
@@ -325,34 +298,29 @@ int MainBuffer::getData(void *buffer, int toCopy, const std::string & call_id)
}
}
int
MainBuffer
::
getDataByID
(
void
*
buffer
,
int
toCopy
,
const
std
::
string
&
call_id
,
const
std
::
string
&
reader_id
)
{
RingBuffer
*
ring_buffer
=
getRingBuffer
(
call_id
);
return
ring_buffer
?
ring_buffer
->
Get
(
buffer
,
toCopy
,
reader_id
)
:
0
;
}
int
MainBuffer
::
availForGet
(
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
CallIDSet
*
callid_set
=
getCallIDSet
(
call_id
);
if
(
callid_set
==
NULL
)
return
0
;
if
(
callid_set
->
empty
())
{
if
(
callid_set
->
empty
())
return
0
;
}
if
(
callid_set
->
size
()
==
1
)
{
CallIDSet
::
iterator
iter_id
=
callid_set
->
begin
();
if
((
call_id
!=
Call
::
DEFAULT_ID
)
&&
(
*
iter_id
==
call_id
))
{
if
((
call_id
!=
Call
::
DEFAULT_ID
)
&&
(
*
iter_id
==
call_id
))
_debug
(
"This problem should not occur since we have %i element"
,
(
int
)
callid_set
->
size
());
}
return
availForGetByID
(
*
iter_id
,
call_id
);
...
...
@@ -373,15 +341,12 @@ int MainBuffer::availForGet(const std::string & call_id)
return
avail_bytes
!=
99999
?
avail_bytes
:
0
;
}
}
int
MainBuffer
::
availForGetByID
(
const
std
::
string
&
call_id
,
const
std
::
string
&
reader_id
)
{
if
((
call_id
!=
Call
::
DEFAULT_ID
)
&&
(
reader_id
==
call_id
))
{
if
((
call_id
!=
Call
::
DEFAULT_ID
)
and
(
reader_id
==
call_id
))
_error
(
"MainBuffer: Error: RingBuffer has a readpointer on tiself"
);
}
RingBuffer
*
ringbuffer
=
getRingBuffer
(
call_id
);
...
...
@@ -393,14 +358,13 @@ int MainBuffer::availForGetByID(const std::string & call_id, const std::string &
}
int
MainBuffer
::
discard
(
int
toDiscard
,
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
CallIDSet
*
callid_set
=
getCallIDSet
(
call_id
);
if
(
!
callid_set
||
callid_set
->
empty
())
if
(
!
callid_set
or
callid_set
->
empty
())
return
0
;
for
(
CallIDSet
::
iterator
iter
=
callid_set
->
begin
();
iter
!=
callid_set
->
end
();
iter
++
)
...
...
@@ -409,7 +373,6 @@ int MainBuffer::discard(int toDiscard, const std::string & call_id)
return
toDiscard
;
}
void
MainBuffer
::
discardByID
(
int
toDiscard
,
const
std
::
string
&
call_id
,
const
std
::
string
&
reader_id
)
{
RingBuffer
*
ringbuffer
=
getRingBuffer
(
call_id
);
...
...
@@ -418,11 +381,9 @@ void MainBuffer::discardByID(int toDiscard, const std::string & call_id, const s
ringbuffer
->
Discard
(
toDiscard
,
reader_id
);
}
void
MainBuffer
::
flush
(
const
std
::
string
&
call_id
)
{
ost
::
MutexLock
guard
(
_
mutex
);
ost
::
MutexLock
guard
(
mutex
_
);
CallIDSet
*
callid_set
=
getCallIDSet
(
call_id
);
...
...
@@ -445,7 +406,7 @@ void MainBuffer::flushByID(const std::string & call_id, const std::string & read
void
MainBuffer
::
flushAllBuffers
()
{
for
(
RingBufferMap
::
iterator
iter
=
_
ringBufferMap
.
begin
();
iter
!=
_
ringBufferMap
.
end
();
++
iter
)
for
(
RingBufferMap
::
iterator
iter
=
ringBufferMap
_
.
begin
();
iter
!=
ringBufferMap
_
.
end
();
++
iter
)
iter
->
second
->
flushAll
();
}
...
...
@@ -475,12 +436,10 @@ void MainBuffer::syncBuffers(const std::string & call_id)
discardByID
(
640
,
*
iter
,
call_id
);
}
void
MainBuffer
::
stateInfo
()
{
// print each call and bound call ids
for
(
CallIDMap
::
iterator
iter_call
=
_callIDMap
.
begin
();
iter_call
!=
_callIDMap
.
end
();
++
iter_call
)
{
for
(
CallIDMap
::
iterator
iter_call
=
callIDMap_
.
begin
();
iter_call
!=
callIDMap_
.
end
();
++
iter_call
)
{
std
::
string
dbg_str
(
" Call:
\t
"
);
dbg_str
.
append
(
iter_call
->
first
);
dbg_str
.
append
(
" is bound to:
\t
"
);
...
...
@@ -496,7 +455,7 @@ void MainBuffer::stateInfo()
}
// Print ringbuffers ids and readpointers
for
(
RingBufferMap
::
iterator
iter_buffer
=
_
ringBufferMap
.
begin
();
iter_buffer
!=
_
ringBufferMap
.
end
();
++
iter_buffer
)
{
for
(
RingBufferMap
::
iterator
iter_buffer
=
ringBufferMap
_
.
begin
();
iter_buffer
!=
ringBufferMap
_
.
end
();
++
iter_buffer
)
{
RingBuffer
*
rbuffer
=
iter_buffer
->
second
;
ReadPointer
*
rpointer
=
NULL
;
...
...
@@ -514,8 +473,6 @@ void MainBuffer::stateInfo()
dbg_str
.
append
(
", "
);
}
}
_debug
(
"%s"
,
dbg_str
.
c_str
());
}
}
daemon/src/audio/mainbuffer.h
View file @
32a89484
...
...
@@ -58,7 +58,7 @@ class MainBuffer {
void
setInternalSamplingRate
(
int
sr
);
int
getInternalSamplingRate
()
{
return
_
internalSamplingRate
;
return
internalSamplingRate
_
;
}
/**
...
...
@@ -134,13 +134,13 @@ class MainBuffer {
void
flushByID
(
const
std
::
string
&
call_id
,
const
std
::
string
&
reader_id
);
RingBufferMap
_
ringBufferMap
;
RingBufferMap
ringBufferMap
_
;
CallIDMap
_
callIDMap
;
CallIDMap
callIDMap
_
;
ost
::
Mutex
_
mutex
;
ost
::
Mutex
mutex
_
;
int
_
internalSamplingRate
;
int
internalSamplingRate
_
;
public:
...
...
daemon/src/audio/ringbuffer.cpp
View file @
32a89484
...
...
@@ -45,24 +45,24 @@
int
RingBuffer
::
count_rb
=
0
;
// Create a ring buffer with 'size' bytes
RingBuffer
::
RingBuffer
(
int
size
,
const
std
::
string
&
call_id
)
:
mEnd
(
0
)
,
mB
ufferSize
(
size
>
MIN_BUFFER_SIZE
?
size
:
MIN_BUFFER_SIZE
)
,
mB
uffer
(
NULL
)
,
buffer_id
(
call_id
)
RingBuffer
::
RingBuffer
(
int
size
,
const
std
::
string
&
call_id
)
:
endPos_
(
0
)
,
b
ufferSize
_
(
size
>
MIN_BUFFER_SIZE
?
size
:
MIN_BUFFER_SIZE
)
,
b
uffer
_
(
NULL
)
,
buffer_id
_
(
call_id
)
{
mB
uffer
=
new
unsigned
char
[
mB
ufferSize
];
b
uffer
_
=
new
unsigned
char
[
b
ufferSize
_
];
count_rb
++
;
}
RingBuffer
::~
RingBuffer
()
{
delete
[]
mB
uffer
;
delete
[]
b
uffer
_
;
}
void
RingBuffer
::
flush
(
const
std
::
string
&
call_id
)
{
storeReadPointer
(
mEnd
,
call_id
);
storeReadPointer
(
endPos_
,
call_id
);
}
...
...
@@ -71,27 +71,27 @@ RingBuffer::flushAll()
{
ReadPointer
::
iterator
iter
;
for
(
iter
=
_
readpointer
.
begin
();
iter
!=
_
readpointer
.
end
();
++
iter
)
iter
->
second
=
mEnd
;
for
(
iter
=
readpointer
_
.
begin
();
iter
!=
readpointer
_
.
end
();
++
iter
)
iter
->
second
=
endPos_
;
}
int
RingBuffer
::
putLen
()
{
int
mS
tart
=
(
_
readpointer
.
size
()
>=
1
)
?
getSmallestReadPointer
()
:
0
;
return
(
mEnd
+
mB
ufferSize
-
mS
tart
)
%
mB
ufferSize
;
int
s
tart
Pos
=
(
readpointer
_
.
size
()
>=
1
)
?
getSmallestReadPointer
()
:
0
;
return
(
endPos_
+
b
ufferSize
_
-
s
tart
Pos
)
%
b
ufferSize
_
;
}
int
RingBuffer
::
getLen
(
const
std
::
string
&
call_id
)
{
return
(
mEnd
+
mB
ufferSize
-
getReadPointer
(
call_id
))
%
mB
ufferSize
;
return
(
endPos_
+
b
ufferSize
_
-
getReadPointer
(
call_id
))
%
b
ufferSize
_
;
}
void
RingBuffer
::
debug
()
{
_debug
(
"Start=%d; End=%d; BufferSize=%d"
,
getSmallestReadPointer
(),
mEnd
,
mB
ufferSize
);
_debug
(
"Start=%d; End=%d; BufferSize=%d"
,
getSmallestReadPointer
(),
endPos_
,
b
ufferSize
_
);
}
int
...
...
@@ -100,8 +100,8 @@ RingBuffer::getReadPointer(const std::string &call_id)
if
(
getNbReadPointer
()
==
0
)
return
0
;
ReadPointer
::
iterator
iter
=
_
readpointer
.
find
(
call_id
);
return
(
iter
!=
_
readpointer
.
end
())
?
iter
->
second
:
0
;
ReadPointer
::
iterator
iter
=
readpointer
_
.
find
(
call_id
);
return
(
iter
!=
readpointer
_
.
end
())
?
iter
->
second
:
0
;
}
int
...
...
@@ -110,11 +110,11 @@ RingBuffer::getSmallestReadPointer()
if
(
getNbReadPointer
()
==
0
)
return
0
;
int
smallest
=
mB
ufferSize
;
int
smallest
=
b
ufferSize
_
;
ReadPointer
::
iterator
iter
;
for
(
iter
=
_
readpointer
.
begin
();
iter
!=
_
readpointer
.
end
();
++
iter
)
for
(
iter
=
readpointer
_
.
begin
();
iter
!=
readpointer
_
.
end
();
++
iter
)
if
(
iter
->
second
<
smallest
)
smallest
=
iter
->
second
;
...
...
@@ -124,13 +124,12 @@ RingBuffer::getSmallestReadPointer()
void
RingBuffer
::
storeReadPointer
(
int
pointer_value
,
const
std
::
string
&
call_id
)
{
ReadPointer
::
iterator
iter
=
_
readpointer
.
find
(
call_id
);
ReadPointer
::
iterator
iter
=
readpointer
_
.
find
(
call_id
);
if
(
iter
!=
_
readpointer
.
end
())
{
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
());
}
else
_debug
(
"storeReadPointer: Cannot find
\"
%s
\"
readPointer in
\"
%s
\"
ringbuffer"
,
call_id
.
c_str
(),
buffer_id_
.
c_str
());
}
...
...
@@ -138,31 +137,31 @@ void
RingBuffer
::
createReadPointer
(
const
std
::
string
&
call_id
)
{
if
(
!
hasThisReadPointer
(
call_id
))
_
readpointer
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
call_id
,
mEnd
));
readpointer
_
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
call_id
,
endPos_
));
}
void
RingBuffer
::
removeReadPointer
(
const
std
::
string
&
call_id
)
{
ReadPointer
::
iterator
iter
=
_
readpointer
.
find
(
call_id
);
ReadPointer
::
iterator
iter
=
readpointer
_
.
find
(
call_id
);
if
(
iter
!=
_
readpointer
.
end
())
_
readpointer
.
erase
(
iter
);
if
(
iter
!=
readpointer
_
.
end
())
readpointer
_
.
erase
(
iter
);
}
bool
RingBuffer
::
hasThisReadPointer
(
const
std
::
string
&
call_id
)
{
return
_
readpointer
.
find
(
call_id
)
!=
_
readpointer
.
end
();
return
readpointer
_
.
find
(
call_id
)
!=
readpointer
_
.
end
();
}
int
RingBuffer
::
getNbReadPointer
()
{
return
_
readpointer
.
size
();
return
readpointer
_
.
size
();
}
//
...
...
@@ -175,26 +174,25 @@ RingBuffer::Put(void* buffer, int toCopy)
{
int
len
=
putLen
();
if
(
toCopy
>
mB
ufferSize
-
len
)
toCopy
=
mB
ufferSize
-
len
;
if
(
toCopy
>
b
ufferSize
_
-
len
)
toCopy
=
b
ufferSize
_
-
len
;
unsigned
char
*
src
=
(
unsigned
char
*
)
buffer
;
int
pos
=
mEnd
;
int
pos
=
endPos_
;
while
(
toCopy
)
{
int
block
=
toCopy
;
if
(
block
>
mB
ufferSize
-
pos
)
// Wrap block around ring ?
block
=
mB
ufferSize
-
pos
;
// Fill in to the end of the buffer
if
(
block
>
b
ufferSize
_
-
pos
)
// Wrap block around ring ?
block
=
b
ufferSize
_
-
pos
;
// Fill in to the end of the buffer
memcpy
(
mB
uffer
+
pos
,
src
,
block
);
memcpy
(
b
uffer
_
+
pos
,
src
,
block
);
src
+=
block
;
pos
=
(
pos
+
block
)
%
mB
ufferSize
;
pos
=
(
pos
+
block
)
%
b
ufferSize
_
;
toCopy
-=
block
;
}
mEnd
=
pos
;
endPos_
=
pos
;
}
//
...
...
@@ -227,21 +225,21 @@ RingBuffer::Get(void *buffer, int toCopy, const std::string &call_id)
int
copied
=
toCopy
;
unsigned
char
*
dest
=
(
unsigned
char
*
)
buffer
;
int
mS
tart
=
getReadPointer
(
call_id
);
int
s
tart
Pos
=
getReadPointer
(
call_id
);
while
(
toCopy
)
{
int
block
=
toCopy
;
if
(
block
>
mB
ufferSize
-
mS
tart
)
block
=
mB
ufferSize
-
mS
tart
;
if
(
block
>
b
ufferSize
_
-
s
tart
Pos
)
block
=
b
ufferSize
_
-
s
tart
Pos
;
memcpy
(
dest
,
mB
uffer
+
mS
tart
,
block
);
memcpy
(
dest
,
b
uffer
_
+
s
tart
Pos
,
block
);
dest
+=
block
;
mS
tart
=
(
mS
tart
+
block
)
%
mB
ufferSize
;
s
tart
Pos
=
(
s
tart
Pos
+
block
)
%
b
ufferSize
_
;
toCopy
-=
block
;
}
storeReadPointer
(
mS
tart
,
call_id
);
storeReadPointer
(
s
tart
Pos
,
call_id
);
return
copied
;
}
...
...
@@ -253,9 +251,9 @@ RingBuffer::Discard(int toDiscard, const std::string &call_id)
if
(
toDiscard
>
len
)
toDiscard
=
len
;
int
mS
tart
=
(
getReadPointer
(
call_id
)
+
toDiscard
)
%
mB
ufferSize
;
int
s
tart
Pos
=
(
getReadPointer
(
call_id
)
+
toDiscard
)
%
b
ufferSize
_
;
storeReadPointer
(
mS
tart
,
call_id
);
storeReadPointer
(
s
tart
Pos
,
call_id
);
return
toDiscard
;
}
daemon/src/audio/ringbuffer.h
View file @
32a89484
...
...
@@ -42,7 +42,7 @@ class RingBuffer {
~
RingBuffer
();
std
::
string
getBufferId
()
{
return
buffer_id
;
return
buffer_id
_
;
}