mirror of https://github.com/FreeRDP/FreeRDP
Fixed queue initialization and overflow checks.
This commit is contained in:
parent
6d14739ada
commit
8ccf7f8ca2
|
@ -66,9 +66,16 @@ static SLresult openSLPlayOpen(OPENSL_STREAM *p)
|
|||
SLuint32 sr = p->sr;
|
||||
SLuint32 channels = p->outchannels;
|
||||
|
||||
assert(p->engineObject);
|
||||
assert(p->engineEngine);
|
||||
|
||||
if(channels){
|
||||
// configure audio source
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq =
|
||||
{
|
||||
SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
|
||||
p->queuesize
|
||||
};
|
||||
|
||||
switch(sr){
|
||||
|
||||
|
@ -227,6 +234,7 @@ OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes
|
|||
p = (OPENSL_STREAM *) calloc(sizeof(OPENSL_STREAM),1);
|
||||
memset(p, 0, sizeof(OPENSL_STREAM));
|
||||
|
||||
p->queuesize = bufferframes;
|
||||
p->outchannels = outchannels;
|
||||
p->sr = sr;
|
||||
|
||||
|
@ -240,7 +248,6 @@ OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes
|
|||
return NULL;
|
||||
}
|
||||
|
||||
p->time = 0.;
|
||||
p->queue = Queue_New(TRUE, -1, -1);
|
||||
|
||||
return p;
|
||||
|
@ -253,16 +260,12 @@ void android_CloseAudioDevice(OPENSL_STREAM *p){
|
|||
return;
|
||||
|
||||
openSLDestroyEngine(p);
|
||||
Queue_Free(p->queue);
|
||||
if (p->queue)
|
||||
Queue_Free(p->queue);
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
// returns timestamp of the processed stream
|
||||
double android_GetTimestamp(OPENSL_STREAM *p){
|
||||
return p->time;
|
||||
}
|
||||
|
||||
// this callback handler is called every time a buffer finishes playing
|
||||
void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||
{
|
||||
|
@ -282,6 +285,10 @@ int android_AudioOut(OPENSL_STREAM *p, const short *buffer,int size)
|
|||
assert(buffer);
|
||||
assert(size > 0);
|
||||
|
||||
/* Assure, that the queue is not full. */
|
||||
if (p->queuesize <= Queue_Count(p->queue))
|
||||
WaitForSingleObject(p->queue->event, INFINITE);
|
||||
|
||||
void *data = calloc(size, sizeof(short));
|
||||
memcpy(data, buffer, size * sizeof(short));
|
||||
(*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue,
|
||||
|
|
|
@ -54,10 +54,10 @@ typedef struct opensl_stream {
|
|||
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
|
||||
SLEffectSendItf bqPlayerEffectSend;
|
||||
|
||||
double time;
|
||||
unsigned int outchannels;
|
||||
unsigned int sr;
|
||||
unsigned int sr;
|
||||
|
||||
unsigned int queuesize;
|
||||
wQueue *queue;
|
||||
} OPENSL_STREAM;
|
||||
|
||||
|
@ -74,11 +74,6 @@ typedef struct opensl_stream {
|
|||
Write a buffer to the OpenSL stream *p, of size samples. Returns the number of samples written.
|
||||
*/
|
||||
int android_AudioOut(OPENSL_STREAM *p, const short *buffer, int size);
|
||||
/*
|
||||
Get the current IO block time in seconds
|
||||
*/
|
||||
double android_GetTimestamp(OPENSL_STREAM *p);
|
||||
|
||||
/*
|
||||
* Set the volume input level.
|
||||
*/
|
||||
|
|
|
@ -89,15 +89,12 @@ static bool rdpsnd_opensles_check_handle(const rdpsndopenslesPlugin *hdl)
|
|||
{
|
||||
bool rc = true;
|
||||
|
||||
assert(hdl);
|
||||
if (!hdl)
|
||||
rc = false;
|
||||
else
|
||||
{
|
||||
assert(hdl->dsp_context);
|
||||
if (!hdl->dsp_context)
|
||||
rc = false;
|
||||
assert(hdl->stream);
|
||||
if (!hdl->stream)
|
||||
rc = false;
|
||||
}
|
||||
|
@ -111,13 +108,14 @@ static void rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device,
|
|||
static int rdpsnd_opensles_set_params(rdpsndopenslesPlugin* opensles)
|
||||
{
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
rdpsnd_opensles_check_handle(opensles);
|
||||
if (!rdpsnd_opensles_check_handle(opensles))
|
||||
return;
|
||||
|
||||
if (opensles->stream)
|
||||
android_CloseAudioDevice(opensles->stream);
|
||||
|
||||
opensles->stream = android_OpenAudioDevice(
|
||||
opensles->rate, opensles->channels, opensles->rate);
|
||||
opensles->rate, opensles->channels, 20);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -180,11 +178,12 @@ static void rdpsnd_opensles_open(rdpsndDevicePlugin* device,
|
|||
|
||||
DEBUG_SND("opensles=%p format=%p, latency=%d, rate=%d",
|
||||
opensles, format, latency, opensles->rate);
|
||||
if (opensles->stream)
|
||||
|
||||
if( rdpsnd_opensles_check_handle(opensles))
|
||||
return;
|
||||
|
||||
opensles->stream = android_OpenAudioDevice(
|
||||
opensles->rate, opensles->channels, opensles->rate);
|
||||
opensles->rate, opensles->channels, 20);
|
||||
assert(opensles->stream);
|
||||
|
||||
if (!opensles->stream)
|
||||
|
@ -198,10 +197,9 @@ static void rdpsnd_opensles_open(rdpsndDevicePlugin* device,
|
|||
static void rdpsnd_opensles_close(rdpsndDevicePlugin* device)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
rdpsnd_opensles_check_handle(opensles);
|
||||
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
if (!opensles->stream)
|
||||
if( !rdpsnd_opensles_check_handle(opensles))
|
||||
return;
|
||||
|
||||
android_CloseAudioDevice(opensles->stream);
|
||||
|
@ -302,7 +300,6 @@ static void rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device,
|
|||
|
||||
opensles->volume = value;
|
||||
|
||||
return;
|
||||
if (opensles->stream)
|
||||
{
|
||||
if (0 == opensles->volume)
|
||||
|
@ -364,6 +361,7 @@ static void rdpsnd_opensles_play(rdpsndDevicePlugin* device,
|
|||
assert(0 == size % 2);
|
||||
assert(size > 0);
|
||||
assert(src.b);
|
||||
|
||||
ret = android_AudioOut(opensles->stream, src.s, size / 2);
|
||||
if (ret < 0)
|
||||
DEBUG_WARN("android_AudioOut failed (%d)", ret);
|
||||
|
|
Loading…
Reference in New Issue