Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
mediastreamer2
Commits
39c53082
Commit
39c53082
authored
Nov 07, 2012
by
Ghislain MARY
Browse files
Improve flow control in Android sound writer.
parent
ce42b22f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
src/android/androidsound.cpp
src/android/androidsound.cpp
+23
-6
No files found.
src/android/androidsound.cpp
View file @
39c53082
...
@@ -40,6 +40,9 @@ static MSFilter * ms_android_snd_write_new(void);
...
@@ -40,6 +40,9 @@ static MSFilter * ms_android_snd_write_new(void);
static
Library
*
libmedia
=
0
;
static
Library
*
libmedia
=
0
;
static
Library
*
libutils
=
0
;
static
Library
*
libutils
=
0
;
static
const
int
flowControlIntervalMs
=
2500
;
static
const
int
flowControlThresholdMs
=
80
;
static
int
std_sample_rates
[]
=
{
static
int
std_sample_rates
[]
=
{
48000
,
44100
,
32000
,
22050
,
16000
,
8000
,
-
1
48000
,
44100
,
32000
,
22050
,
16000
,
8000
,
-
1
};
};
...
@@ -180,6 +183,8 @@ struct AndroidSndWriteData{
...
@@ -180,6 +183,8 @@ struct AndroidSndWriteData{
int
nbufs
;
int
nbufs
;
int
nFramesRequested
;
int
nFramesRequested
;
bool
mStarted
;
bool
mStarted
;
uint64_t
flowControlStart
;
int
minBufferFilling
;
};
};
static
MSFilter
*
android_snd_card_create_reader
(
MSSndCard
*
card
){
static
MSFilter
*
android_snd_card_create_reader
(
MSSndCard
*
card
){
...
@@ -451,17 +456,18 @@ static void android_snd_write_cb(int event, void *user, void * p_info){
...
@@ -451,17 +456,18 @@ static void android_snd_write_cb(int event, void *user, void * p_info){
if
(
event
==
AudioTrack
::
EVENT_MORE_DATA
){
if
(
event
==
AudioTrack
::
EVENT_MORE_DATA
){
AudioTrack
::
Buffer
*
info
=
reinterpret_cast
<
AudioTrack
::
Buffer
*>
(
p_info
);
AudioTrack
::
Buffer
*
info
=
reinterpret_cast
<
AudioTrack
::
Buffer
*>
(
p_info
);
int
maxbuf
=
(
200
*
ad
->
nchannels
*
2
*
ad
->
rate
)
/
1000
;
/* Bufferize 200 ms max */
int
avail
;
int
avail
;
int
ask
;
int
ask
;
ms_mutex_lock
(
&
ad
->
mutex
);
ms_mutex_lock
(
&
ad
->
mutex
);
ask
=
info
->
size
;
ask
=
info
->
size
;
avail
=
ms_bufferizer_get_avail
(
&
ad
->
bf
);
avail
=
ms_bufferizer_get_avail
(
&
ad
->
bf
);
if
(
avail
>
maxbuf
)
{
if
(
avail
!=
0
)
{
ms_warning
(
"Too many samples waiting in sound writer, dropping %i bytes"
,
avail
-
maxbuf
);
if
((
ad
->
minBufferFilling
==
-
1
))
{
ms_bufferizer_skip_bytes
(
&
ad
->
bf
,
avail
-
maxbuf
);
ad
->
minBufferFilling
=
avail
;
avail
=
maxbuf
;
}
else
if
(
avail
<
ad
->
minBufferFilling
)
{
ad
->
minBufferFilling
=
avail
;
}
}
}
info
->
size
=
MIN
(
avail
,
ask
);
info
->
size
=
MIN
(
avail
,
ask
);
#ifdef TRACE_SND_WRITE_TIMINGS
#ifdef TRACE_SND_WRITE_TIMINGS
...
@@ -535,6 +541,8 @@ static void android_snd_write_preprocess(MSFilter *obj){
...
@@ -535,6 +541,8 @@ static void android_snd_write_preprocess(MSFilter *obj){
ad
->
nbufs
=
0
;
ad
->
nbufs
=
0
;
ms_message
(
"AudioTrack latency estimated to %i ms"
,
ad
->
tr
->
latency
());
ms_message
(
"AudioTrack latency estimated to %i ms"
,
ad
->
tr
->
latency
());
ad
->
mStarted
=
false
;
ad
->
mStarted
=
false
;
ad
->
flowControlStart
=
obj
->
ticker
->
time
;
ad
->
minBufferFilling
=
-
1
;
}
}
static
void
android_snd_write_process
(
MSFilter
*
obj
){
static
void
android_snd_write_process
(
MSFilter
*
obj
){
...
@@ -558,6 +566,15 @@ static void android_snd_write_process(MSFilter *obj){
...
@@ -558,6 +566,15 @@ static void android_snd_write_process(MSFilter *obj){
#else
#else
ms_bufferizer_put_from_queue
(
&
ad
->
bf
,
obj
->
inputs
[
0
]);
ms_bufferizer_put_from_queue
(
&
ad
->
bf
,
obj
->
inputs
[
0
]);
#endif
#endif
if
(((
uint32_t
)(
obj
->
ticker
->
time
-
ad
->
flowControlStart
))
>=
flowControlIntervalMs
)
{
int
threshold
=
(
flowControlThresholdMs
*
ad
->
nchannels
*
2
*
ad
->
rate
)
/
1000
;
if
(
ad
->
minBufferFilling
>
threshold
)
{
ms_warning
(
"Too many samples waiting in sound writer, dropping %i bytes"
,
threshold
);
ms_bufferizer_skip_bytes
(
&
ad
->
bf
,
threshold
);
}
ad
->
flowControlStart
=
obj
->
ticker
->
time
;
ad
->
minBufferFilling
=
-
1
;
}
ms_mutex_unlock
(
&
ad
->
mutex
);
ms_mutex_unlock
(
&
ad
->
mutex
);
if
(
ad
->
tr
->
stopped
())
{
if
(
ad
->
tr
->
stopped
())
{
ms_warning
(
"AudioTrack stopped unexpectedly, needs to be restarted"
);
ms_warning
(
"AudioTrack stopped unexpectedly, needs to be restarted"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment