Android: fixed warnings, reformatted.
This commit is contained in:
parent
9adc13297b
commit
6ca5a1324f
@ -34,108 +34,126 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define CONV16BIT 32768
|
||||
#define CONVMYFLT (1./32768.)
|
||||
|
||||
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context);
|
||||
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context);
|
||||
|
||||
// creates the OpenSL ES audio engine
|
||||
static SLresult openSLCreateEngine(OPENSL_STREAM *p)
|
||||
static SLresult openSLCreateEngine(OPENSL_STREAM* p)
|
||||
{
|
||||
SLresult result;
|
||||
// create engine
|
||||
result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL);
|
||||
DEBUG_DVC("engineObject=%p", p->engineObject);
|
||||
if(result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
// realize the engine
|
||||
result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE);
|
||||
DEBUG_DVC("Realize=%d", result);
|
||||
if(result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
// get the engine interface, which is needed in order to create other objects
|
||||
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE, &(p->engineEngine));
|
||||
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE,
|
||||
&(p->engineEngine));
|
||||
DEBUG_DVC("engineEngine=%p", p->engineEngine);
|
||||
if(result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
// get the volume interface - important, this is optional!
|
||||
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_DEVICEVOLUME, &(p->deviceVolume));
|
||||
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_DEVICEVOLUME,
|
||||
&(p->deviceVolume));
|
||||
DEBUG_DVC("deviceVolume=%p", p->deviceVolume);
|
||||
if(result != SL_RESULT_SUCCESS)
|
||||
|
||||
if (result != SL_RESULT_SUCCESS)
|
||||
{
|
||||
p->deviceVolume = NULL;
|
||||
result = SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
engine_end:
|
||||
engine_end:
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Open the OpenSL ES device for input
|
||||
static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
|
||||
static SLresult openSLRecOpen(OPENSL_STREAM* p)
|
||||
{
|
||||
SLresult result;
|
||||
SLuint32 sr = p->sr;
|
||||
SLuint32 channels = p->inchannels;
|
||||
|
||||
assert(!p->recorderObject);
|
||||
|
||||
if(channels){
|
||||
|
||||
switch(sr){
|
||||
|
||||
if (channels)
|
||||
{
|
||||
switch (sr)
|
||||
{
|
||||
case 8000:
|
||||
sr = SL_SAMPLINGRATE_8;
|
||||
break;
|
||||
|
||||
case 11025:
|
||||
sr = SL_SAMPLINGRATE_11_025;
|
||||
break;
|
||||
|
||||
case 16000:
|
||||
sr = SL_SAMPLINGRATE_16;
|
||||
break;
|
||||
|
||||
case 22050:
|
||||
sr = SL_SAMPLINGRATE_22_05;
|
||||
break;
|
||||
|
||||
case 24000:
|
||||
sr = SL_SAMPLINGRATE_24;
|
||||
break;
|
||||
|
||||
case 32000:
|
||||
sr = SL_SAMPLINGRATE_32;
|
||||
break;
|
||||
|
||||
case 44100:
|
||||
sr = SL_SAMPLINGRATE_44_1;
|
||||
break;
|
||||
|
||||
case 48000:
|
||||
sr = SL_SAMPLINGRATE_48;
|
||||
break;
|
||||
|
||||
case 64000:
|
||||
sr = SL_SAMPLINGRATE_64;
|
||||
break;
|
||||
|
||||
case 88200:
|
||||
sr = SL_SAMPLINGRATE_88_2;
|
||||
break;
|
||||
|
||||
case 96000:
|
||||
sr = SL_SAMPLINGRATE_96;
|
||||
break;
|
||||
|
||||
case 192000:
|
||||
sr = SL_SAMPLINGRATE_192;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// configure audio source
|
||||
SLDataLocator_IODevice loc_dev = {SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
|
||||
SL_DEFAULTDEVICEID_AUDIOINPUT, NULL};
|
||||
SL_DEFAULTDEVICEID_AUDIOINPUT, NULL
|
||||
};
|
||||
SLDataSource audioSrc = {&loc_dev, NULL};
|
||||
|
||||
// configure audio sink
|
||||
int speakers;
|
||||
if(channels > 1)
|
||||
|
||||
if (channels > 1)
|
||||
speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
|
||||
else
|
||||
speakers = SL_SPEAKER_FRONT_CENTER;
|
||||
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
|
||||
SLDataFormat_PCM format_pcm;
|
||||
|
||||
format_pcm.formatType = SL_DATAFORMAT_PCM;
|
||||
format_pcm.numChannels = channels;
|
||||
format_pcm.samplesPerSec = sr;
|
||||
@ -156,7 +174,6 @@ static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
assert(0);
|
||||
|
||||
SLDataSink audioSnk = {&loc_bq, &format_pcm};
|
||||
|
||||
// create audio recorder
|
||||
// (requires the RECORD_AUDIO permission)
|
||||
const SLInterfaceID id[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE};
|
||||
@ -165,12 +182,14 @@ static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
&(p->recorderObject), &audioSrc, &audioSnk, 1, id, req);
|
||||
DEBUG_DVC("p->recorderObject=%p", p->recorderObject);
|
||||
assert(!result);
|
||||
|
||||
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
||||
|
||||
// realize the audio recorder
|
||||
result = (*p->recorderObject)->Realize(p->recorderObject, SL_BOOLEAN_FALSE);
|
||||
DEBUG_DVC("Realize=%d", result);
|
||||
assert(!result);
|
||||
|
||||
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
||||
|
||||
// get the record interface
|
||||
@ -178,6 +197,7 @@ static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
SL_IID_RECORD, &(p->recorderRecord));
|
||||
DEBUG_DVC("p->recorderRecord=%p", p->recorderRecord);
|
||||
assert(!result);
|
||||
|
||||
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
||||
|
||||
// get the buffer queue interface
|
||||
@ -186,6 +206,7 @@ static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
&(p->recorderBufferQueue));
|
||||
DEBUG_DVC("p->recorderBufferQueue=%p", p->recorderBufferQueue);
|
||||
assert(!result);
|
||||
|
||||
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
||||
|
||||
// register callback on the buffer queue
|
||||
@ -193,6 +214,7 @@ static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
bqRecorderCallback, p);
|
||||
DEBUG_DVC("p->recorderBufferQueue=%p", p->recorderBufferQueue);
|
||||
assert(!result);
|
||||
|
||||
if (SL_RESULT_SUCCESS != result)
|
||||
goto end_recopen;
|
||||
|
||||
@ -200,17 +222,16 @@ static SLresult openSLRecOpen(OPENSL_STREAM *p){
|
||||
return result;
|
||||
}
|
||||
else return SL_RESULT_SUCCESS;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// close the OpenSL IO and destroy the audio engine
|
||||
static void openSLDestroyEngine(OPENSL_STREAM *p)
|
||||
static void openSLDestroyEngine(OPENSL_STREAM* p)
|
||||
{
|
||||
DEBUG_DVC("p=%p", p);
|
||||
|
||||
// destroy audio recorder object, and invalidate all associated interfaces
|
||||
if (p->recorderObject != NULL) {
|
||||
if (p->recorderObject != NULL)
|
||||
{
|
||||
(*p->recorderObject)->Destroy(p->recorderObject);
|
||||
p->recorderObject = NULL;
|
||||
p->recorderRecord = NULL;
|
||||
@ -218,22 +239,22 @@ static void openSLDestroyEngine(OPENSL_STREAM *p)
|
||||
}
|
||||
|
||||
// destroy engine object, and invalidate all associated interfaces
|
||||
if (p->engineObject != NULL) {
|
||||
if (p->engineObject != NULL)
|
||||
{
|
||||
(*p->engineObject)->Destroy(p->engineObject);
|
||||
p->engineObject = NULL;
|
||||
p->engineEngine = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// open the android audio device for input
|
||||
OPENSL_STREAM *android_OpenRecDevice(char *name, int sr, int inchannels,
|
||||
OPENSL_STREAM* android_OpenRecDevice(char* name, int sr, int inchannels,
|
||||
int bufferframes, int bits_per_sample)
|
||||
{
|
||||
OPENSL_STREAM* p;
|
||||
p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1);
|
||||
|
||||
OPENSL_STREAM *p;
|
||||
p = (OPENSL_STREAM *) calloc(sizeof(OPENSL_STREAM),1);
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
@ -249,13 +270,13 @@ OPENSL_STREAM *android_OpenRecDevice(char *name, int sr, int inchannels,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(openSLCreateEngine(p) != SL_RESULT_SUCCESS)
|
||||
if (openSLCreateEngine(p) != SL_RESULT_SUCCESS)
|
||||
{
|
||||
android_CloseRecDevice(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(openSLRecOpen(p) != SL_RESULT_SUCCESS)
|
||||
if (openSLRecOpen(p) != SL_RESULT_SUCCESS)
|
||||
{
|
||||
android_CloseRecDevice(p);
|
||||
return NULL;
|
||||
@ -265,7 +286,7 @@ OPENSL_STREAM *android_OpenRecDevice(char *name, int sr, int inchannels,
|
||||
}
|
||||
|
||||
// close the android audio device
|
||||
void android_CloseRecDevice(OPENSL_STREAM *p)
|
||||
void android_CloseRecDevice(OPENSL_STREAM* p)
|
||||
{
|
||||
DEBUG_DVC("p=%p", p);
|
||||
|
||||
@ -276,10 +297,11 @@ void android_CloseRecDevice(OPENSL_STREAM *p)
|
||||
{
|
||||
while (Queue_Count(p->queue) > 0)
|
||||
{
|
||||
queue_element *e = Queue_Dequeue(p->queue);
|
||||
queue_element* e = Queue_Dequeue(p->queue);
|
||||
free(e->data);
|
||||
free(e);
|
||||
}
|
||||
|
||||
Queue_Free(p->queue);
|
||||
}
|
||||
|
||||
@ -296,51 +318,46 @@ void android_CloseRecDevice(OPENSL_STREAM *p)
|
||||
}
|
||||
|
||||
openSLDestroyEngine(p);
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
// this callback handler is called every time a buffer finishes recording
|
||||
void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context)
|
||||
{
|
||||
queue_element *e;
|
||||
|
||||
OPENSL_STREAM *p = (OPENSL_STREAM *) context;
|
||||
|
||||
queue_element* e;
|
||||
OPENSL_STREAM* p = (OPENSL_STREAM*) context;
|
||||
DEBUG_DVC("p=%p", p);
|
||||
|
||||
assert(p);
|
||||
assert(p->next);
|
||||
assert(p->prep);
|
||||
assert(p->queue);
|
||||
|
||||
e = calloc(1, sizeof(queue_element));
|
||||
|
||||
if (!e)
|
||||
return;
|
||||
|
||||
e->data = calloc(p->buffersize, p->bits_per_sample / 8);
|
||||
|
||||
if (!e->data)
|
||||
{
|
||||
free(e);
|
||||
return;
|
||||
}
|
||||
e->size = p->buffersize * p->bits_per_sample / 8;
|
||||
|
||||
e->size = p->buffersize * p->bits_per_sample / 8;
|
||||
Queue_Enqueue(p->queue, p->next);
|
||||
p->next = p->prep;
|
||||
p->prep = e;
|
||||
|
||||
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
|
||||
e->data, e->size);
|
||||
|
||||
}
|
||||
|
||||
// gets a buffer of size samples from the device
|
||||
int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
|
||||
int android_RecIn(OPENSL_STREAM* p, short* buffer, int size)
|
||||
{
|
||||
queue_element *e;
|
||||
queue_element* e;
|
||||
int rc;
|
||||
DWORD status;
|
||||
|
||||
assert(p);
|
||||
assert(buffer);
|
||||
assert(size > 0);
|
||||
@ -349,26 +366,24 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
|
||||
if (!p->prep)
|
||||
{
|
||||
p->prep = calloc(1, sizeof(queue_element));
|
||||
|
||||
p->prep->data = calloc(p->buffersize, p->bits_per_sample / 8);
|
||||
p->prep->size = p->buffersize * p->bits_per_sample / 8;
|
||||
|
||||
p->next = calloc(1, sizeof(queue_element));
|
||||
p->next->data = calloc(p->buffersize, p->bits_per_sample / 8);
|
||||
p->next->size = p->buffersize * p->bits_per_sample / 8;
|
||||
|
||||
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
|
||||
p->next->data, p->next->size);
|
||||
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
|
||||
p->prep->data, p->prep->size);
|
||||
|
||||
(*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING);
|
||||
(*p->recorderRecord)->SetRecordState(p->recorderRecord,
|
||||
SL_RECORDSTATE_RECORDING);
|
||||
}
|
||||
|
||||
/* Wait for queue to be filled... */
|
||||
if (!Queue_Count(p->queue))
|
||||
{
|
||||
status = WaitForSingleObject(p->queue->event, INFINITE);
|
||||
|
||||
if (status == WAIT_FAILED)
|
||||
{
|
||||
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", GetLastError());
|
||||
@ -376,8 +391,8 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
e = Queue_Dequeue(p->queue);
|
||||
|
||||
if (!e)
|
||||
{
|
||||
WLog_ERR(TAG, "[ERROR] got e=%p from queue", e);
|
||||
@ -387,11 +402,9 @@ int android_RecIn(OPENSL_STREAM *p,short *buffer,int size)
|
||||
rc = (e->size < size) ? e->size : size;
|
||||
assert(size == e->size);
|
||||
assert(p->buffersize * p->bits_per_sample / 8 == size);
|
||||
|
||||
memcpy(buffer, e->data, rc);
|
||||
free(e->data);
|
||||
free(e);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/collections.h>
|
||||
|
||||
#include <freerdp/api.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -45,10 +47,11 @@ extern "C" {
|
||||
typedef struct
|
||||
{
|
||||
size_t size;
|
||||
void *data;
|
||||
void* data;
|
||||
} queue_element;
|
||||
|
||||
typedef struct opensl_stream {
|
||||
typedef struct opensl_stream
|
||||
{
|
||||
// engine interfaces
|
||||
SLObjectItf engineObject;
|
||||
SLEngineItf engineEngine;
|
||||
@ -66,25 +69,26 @@ typedef struct opensl_stream {
|
||||
unsigned int buffersize;
|
||||
unsigned int bits_per_sample;
|
||||
|
||||
wQueue *queue;
|
||||
queue_element *prep;
|
||||
queue_element *next;
|
||||
wQueue* queue;
|
||||
queue_element* prep;
|
||||
queue_element* next;
|
||||
} OPENSL_STREAM;
|
||||
|
||||
/*
|
||||
Open the audio device with a given sampling rate (sr), input and output channels and IO buffer size
|
||||
in frames. Returns a handle to the OpenSL stream
|
||||
*/
|
||||
OPENSL_STREAM* android_OpenRecDevice(char *name, int sr, int inchannels,
|
||||
/*
|
||||
Open the audio device with a given sampling rate (sr), input and output channels and IO buffer size
|
||||
in frames. Returns a handle to the OpenSL stream
|
||||
*/
|
||||
FREERDP_LOCAL OPENSL_STREAM* android_OpenRecDevice(char* name, int sr,
|
||||
int inchannels,
|
||||
int bufferframes, int bits_per_sample);
|
||||
/*
|
||||
Close the audio device
|
||||
*/
|
||||
void android_CloseRecDevice(OPENSL_STREAM *p);
|
||||
/*
|
||||
Read a buffer from the OpenSL stream *p, of size samples. Returns the number of samples read.
|
||||
*/
|
||||
int android_RecIn(OPENSL_STREAM *p, short *buffer,int size);
|
||||
/*
|
||||
Close the audio device
|
||||
*/
|
||||
FREERDP_LOCAL void android_CloseRecDevice(OPENSL_STREAM* p);
|
||||
/*
|
||||
Read a buffer from the OpenSL stream *p, of size samples. Returns the number of samples read.
|
||||
*/
|
||||
FREERDP_LOCAL int android_RecIn(OPENSL_STREAM* p, short* buffer, int size);
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
@ -34,42 +34,46 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define CONV16BIT 32768
|
||||
#define CONVMYFLT (1./32768.)
|
||||
|
||||
static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context);
|
||||
static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context);
|
||||
|
||||
// creates the OpenSL ES audio engine
|
||||
static SLresult openSLCreateEngine(OPENSL_STREAM *p)
|
||||
static SLresult openSLCreateEngine(OPENSL_STREAM* p)
|
||||
{
|
||||
SLresult result;
|
||||
// create engine
|
||||
result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL);
|
||||
DEBUG_SND("engineObject=%p", p->engineObject);
|
||||
if(result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
// realize the engine
|
||||
result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE);
|
||||
DEBUG_SND("Realize=%d", result);
|
||||
if(result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
// get the engine interface, which is needed in order to create other objects
|
||||
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE, &(p->engineEngine));
|
||||
result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE,
|
||||
&(p->engineEngine));
|
||||
DEBUG_SND("engineEngine=%p", p->engineEngine);
|
||||
if(result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
engine_end:
|
||||
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
||||
|
||||
engine_end:
|
||||
return result;
|
||||
}
|
||||
|
||||
// opens the OpenSL ES device for output
|
||||
static SLresult openSLPlayOpen(OPENSL_STREAM *p)
|
||||
static SLresult openSLPlayOpen(OPENSL_STREAM* p)
|
||||
{
|
||||
SLresult result;
|
||||
SLuint32 sr = p->sr;
|
||||
SLuint32 channels = p->outchannels;
|
||||
|
||||
assert(p->engineObject);
|
||||
assert(p->engineEngine);
|
||||
|
||||
if(channels){
|
||||
if (channels)
|
||||
{
|
||||
// configure audio source
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq =
|
||||
{
|
||||
@ -77,75 +81,90 @@ static SLresult openSLPlayOpen(OPENSL_STREAM *p)
|
||||
p->queuesize
|
||||
};
|
||||
|
||||
switch(sr){
|
||||
|
||||
switch (sr)
|
||||
{
|
||||
case 8000:
|
||||
sr = SL_SAMPLINGRATE_8;
|
||||
break;
|
||||
|
||||
case 11025:
|
||||
sr = SL_SAMPLINGRATE_11_025;
|
||||
break;
|
||||
|
||||
case 16000:
|
||||
sr = SL_SAMPLINGRATE_16;
|
||||
break;
|
||||
|
||||
case 22050:
|
||||
sr = SL_SAMPLINGRATE_22_05;
|
||||
break;
|
||||
|
||||
case 24000:
|
||||
sr = SL_SAMPLINGRATE_24;
|
||||
break;
|
||||
|
||||
case 32000:
|
||||
sr = SL_SAMPLINGRATE_32;
|
||||
break;
|
||||
|
||||
case 44100:
|
||||
sr = SL_SAMPLINGRATE_44_1;
|
||||
break;
|
||||
|
||||
case 48000:
|
||||
sr = SL_SAMPLINGRATE_48;
|
||||
break;
|
||||
|
||||
case 64000:
|
||||
sr = SL_SAMPLINGRATE_64;
|
||||
break;
|
||||
|
||||
case 88200:
|
||||
sr = SL_SAMPLINGRATE_88_2;
|
||||
break;
|
||||
|
||||
case 96000:
|
||||
sr = SL_SAMPLINGRATE_96;
|
||||
break;
|
||||
|
||||
case 192000:
|
||||
sr = SL_SAMPLINGRATE_192;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
const SLInterfaceID ids[] = {SL_IID_VOLUME};
|
||||
const SLboolean req[] = {SL_BOOLEAN_FALSE};
|
||||
result = (*p->engineEngine)->CreateOutputMix(p->engineEngine, &(p->outputMixObject), 1, ids, req);
|
||||
result = (*p->engineEngine)->CreateOutputMix(p->engineEngine,
|
||||
&(p->outputMixObject), 1, ids, req);
|
||||
DEBUG_SND("engineEngine=%p", p->engineEngine);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// realize the output mix
|
||||
result = (*p->outputMixObject)->Realize(p->outputMixObject, SL_BOOLEAN_FALSE);
|
||||
DEBUG_SND("Realize=%d", result);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
int speakers;
|
||||
if(channels > 1)
|
||||
|
||||
if (channels > 1)
|
||||
speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
|
||||
else speakers = SL_SPEAKER_FRONT_CENTER;
|
||||
SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM,channels, sr,
|
||||
|
||||
SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, channels, sr,
|
||||
SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
|
||||
speakers, SL_BYTEORDER_LITTLEENDIAN};
|
||||
|
||||
speakers, SL_BYTEORDER_LITTLEENDIAN
|
||||
};
|
||||
SLDataSource audioSrc = {&loc_bufq, &format_pcm};
|
||||
|
||||
// configure audio sink
|
||||
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, p->outputMixObject};
|
||||
SLDataSink audioSnk = {&loc_outmix, NULL};
|
||||
|
||||
// create audio player
|
||||
const SLInterfaceID ids1[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_VOLUME};
|
||||
const SLboolean req1[] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
|
||||
@ -153,56 +172,68 @@ static SLresult openSLPlayOpen(OPENSL_STREAM *p)
|
||||
&(p->bqPlayerObject), &audioSrc, &audioSnk, 2, ids1, req1);
|
||||
DEBUG_SND("bqPlayerObject=%p", p->bqPlayerObject);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// realize the player
|
||||
result = (*p->bqPlayerObject)->Realize(p->bqPlayerObject, SL_BOOLEAN_FALSE);
|
||||
DEBUG_SND("Realize=%d", result);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// get the play interface
|
||||
result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_PLAY, &(p->bqPlayerPlay));
|
||||
result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_PLAY,
|
||||
&(p->bqPlayerPlay));
|
||||
DEBUG_SND("bqPlayerPlay=%p", p->bqPlayerPlay);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// get the volume interface
|
||||
result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_VOLUME, &(p->bqPlayerVolume));
|
||||
result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_VOLUME,
|
||||
&(p->bqPlayerVolume));
|
||||
DEBUG_SND("bqPlayerVolume=%p", p->bqPlayerVolume);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// get the buffer queue interface
|
||||
result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
|
||||
result = (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject,
|
||||
SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
|
||||
&(p->bqPlayerBufferQueue));
|
||||
DEBUG_SND("bqPlayerBufferQueue=%p", p->bqPlayerBufferQueue);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// register callback on the buffer queue
|
||||
result = (*p->bqPlayerBufferQueue)->RegisterCallback(p->bqPlayerBufferQueue, bqPlayerCallback, p);
|
||||
result = (*p->bqPlayerBufferQueue)->RegisterCallback(p->bqPlayerBufferQueue,
|
||||
bqPlayerCallback, p);
|
||||
DEBUG_SND("bqPlayerCallback=%p", p->bqPlayerCallback);
|
||||
assert(!result);
|
||||
if(result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
if (result != SL_RESULT_SUCCESS) goto end_openaudio;
|
||||
|
||||
// set the player's state to playing
|
||||
result = (*p->bqPlayerPlay)->SetPlayState(p->bqPlayerPlay, SL_PLAYSTATE_PLAYING);
|
||||
result = (*p->bqPlayerPlay)->SetPlayState(p->bqPlayerPlay,
|
||||
SL_PLAYSTATE_PLAYING);
|
||||
DEBUG_SND("SetPlayState=%d", result);
|
||||
assert(!result);
|
||||
|
||||
end_openaudio:
|
||||
assert(!result);
|
||||
return result;
|
||||
}
|
||||
|
||||
return SL_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
// close the OpenSL IO and destroy the audio engine
|
||||
static void openSLDestroyEngine(OPENSL_STREAM *p){
|
||||
|
||||
static void openSLDestroyEngine(OPENSL_STREAM* p)
|
||||
{
|
||||
// destroy buffer queue audio player object, and invalidate all associated interfaces
|
||||
if (p->bqPlayerObject != NULL) {
|
||||
if (p->bqPlayerObject != NULL)
|
||||
{
|
||||
(*p->bqPlayerObject)->Destroy(p->bqPlayerObject);
|
||||
p->bqPlayerObject = NULL;
|
||||
p->bqPlayerVolume = NULL;
|
||||
@ -212,25 +243,29 @@ static void openSLDestroyEngine(OPENSL_STREAM *p){
|
||||
}
|
||||
|
||||
// destroy output mix object, and invalidate all associated interfaces
|
||||
if (p->outputMixObject != NULL) {
|
||||
if (p->outputMixObject != NULL)
|
||||
{
|
||||
(*p->outputMixObject)->Destroy(p->outputMixObject);
|
||||
p->outputMixObject = NULL;
|
||||
}
|
||||
|
||||
// destroy engine object, and invalidate all associated interfaces
|
||||
if (p->engineObject != NULL) {
|
||||
if (p->engineObject != NULL)
|
||||
{
|
||||
(*p->engineObject)->Destroy(p->engineObject);
|
||||
p->engineObject = NULL;
|
||||
p->engineEngine = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// open the android audio device for and/or output
|
||||
OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes){
|
||||
OPENSL_STREAM *p;
|
||||
p = (OPENSL_STREAM *) calloc(sizeof(OPENSL_STREAM), 1);
|
||||
OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels,
|
||||
int bufferframes)
|
||||
{
|
||||
OPENSL_STREAM* p;
|
||||
p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
@ -238,19 +273,20 @@ OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes
|
||||
p->outchannels = outchannels;
|
||||
p->sr = sr;
|
||||
|
||||
if(openSLCreateEngine(p) != SL_RESULT_SUCCESS)
|
||||
if (openSLCreateEngine(p) != SL_RESULT_SUCCESS)
|
||||
{
|
||||
android_CloseAudioDevice(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(openSLPlayOpen(p) != SL_RESULT_SUCCESS)
|
||||
if (openSLPlayOpen(p) != SL_RESULT_SUCCESS)
|
||||
{
|
||||
android_CloseAudioDevice(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p->queue = Queue_New(TRUE, -1, -1);
|
||||
|
||||
if (!p->queue)
|
||||
{
|
||||
android_CloseAudioDevice(p);
|
||||
@ -261,12 +297,13 @@ OPENSL_STREAM *android_OpenAudioDevice(int sr, int outchannels, int bufferframes
|
||||
}
|
||||
|
||||
// close the android audio device
|
||||
void android_CloseAudioDevice(OPENSL_STREAM *p){
|
||||
|
||||
void android_CloseAudioDevice(OPENSL_STREAM* p)
|
||||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
openSLDestroyEngine(p);
|
||||
|
||||
if (p->queue)
|
||||
Queue_Free(p->queue);
|
||||
|
||||
@ -274,94 +311,106 @@ void android_CloseAudioDevice(OPENSL_STREAM *p){
|
||||
}
|
||||
|
||||
// this callback handler is called every time a buffer finishes playing
|
||||
void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||
static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context)
|
||||
{
|
||||
OPENSL_STREAM *p = (OPENSL_STREAM *) context;
|
||||
|
||||
OPENSL_STREAM* p = (OPENSL_STREAM*) context;
|
||||
assert(p);
|
||||
assert(p->queue);
|
||||
|
||||
void *data = Queue_Dequeue(p->queue);
|
||||
void* data = Queue_Dequeue(p->queue);
|
||||
free(data);
|
||||
}
|
||||
|
||||
// puts a buffer of size samples to the device
|
||||
int android_AudioOut(OPENSL_STREAM *p, const short *buffer,int size)
|
||||
int android_AudioOut(OPENSL_STREAM* p, const short* buffer, int size)
|
||||
{
|
||||
assert(p);
|
||||
assert(buffer);
|
||||
assert(size > 0);
|
||||
|
||||
/* Assure, that the queue is not full. */
|
||||
if (p->queuesize <= Queue_Count(p->queue) && WaitForSingleObject(p->queue->event, INFINITE) == WAIT_FAILED)
|
||||
if (p->queuesize <= Queue_Count(p->queue)
|
||||
&& WaitForSingleObject(p->queue->event, INFINITE) == WAIT_FAILED)
|
||||
{
|
||||
DEBUG_SND("WaitForSingleObject failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *data = calloc(size, sizeof(short));
|
||||
void* data = calloc(size, sizeof(short));
|
||||
|
||||
if (!data)
|
||||
{
|
||||
DEBUG_SND("unable to allocate a buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data, buffer, size * sizeof(short));
|
||||
Queue_Enqueue(p->queue, data);
|
||||
(*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue,
|
||||
data, sizeof(short) * size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int android_GetOutputMute(OPENSL_STREAM *p) {
|
||||
int android_GetOutputMute(OPENSL_STREAM* p)
|
||||
{
|
||||
SLboolean mute;
|
||||
|
||||
assert(p);
|
||||
assert(p->bqPlayerVolume);
|
||||
|
||||
SLresult rc = (*p->bqPlayerVolume)->GetMute(p->bqPlayerVolume, &mute);
|
||||
assert(SL_RESULT_SUCCESS == rc);
|
||||
|
||||
if (SL_RESULT_SUCCESS != rc)
|
||||
return SL_BOOLEAN_FALSE;
|
||||
|
||||
return mute;
|
||||
}
|
||||
|
||||
void android_SetOutputMute(OPENSL_STREAM *p, BOOL _mute) {
|
||||
BOOL android_SetOutputMute(OPENSL_STREAM* p, BOOL _mute)
|
||||
{
|
||||
SLboolean mute = _mute;
|
||||
|
||||
assert(p);
|
||||
assert(p->bqPlayerVolume);
|
||||
|
||||
SLresult rc = (*p->bqPlayerVolume)->SetMute(p->bqPlayerVolume, mute);
|
||||
assert(SL_RESULT_SUCCESS == rc);
|
||||
|
||||
if (SL_RESULT_SUCCESS != rc)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int android_GetOutputVolume(OPENSL_STREAM *p){
|
||||
int android_GetOutputVolume(OPENSL_STREAM* p)
|
||||
{
|
||||
SLmillibel level;
|
||||
|
||||
assert(p);
|
||||
assert(p->bqPlayerVolume);
|
||||
|
||||
SLresult rc = (*p->bqPlayerVolume)->GetVolumeLevel(p->bqPlayerVolume, &level);
|
||||
assert(SL_RESULT_SUCCESS == rc);
|
||||
|
||||
if (SL_RESULT_SUCCESS != rc)
|
||||
return 0;
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
int android_GetOutputVolumeMax(OPENSL_STREAM *p){
|
||||
int android_GetOutputVolumeMax(OPENSL_STREAM* p)
|
||||
{
|
||||
SLmillibel level;
|
||||
|
||||
assert(p);
|
||||
assert(p->bqPlayerVolume);
|
||||
SLresult rc = (*p->bqPlayerVolume)->GetMaxVolumeLevel(p->bqPlayerVolume,
|
||||
&level);
|
||||
|
||||
SLresult rc = (*p->bqPlayerVolume)->GetMaxVolumeLevel(p->bqPlayerVolume, &level);
|
||||
assert(SL_RESULT_SUCCESS == rc);
|
||||
if (SL_RESULT_SUCCESS != rc)
|
||||
return 0;
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
void android_SetOutputVolume(OPENSL_STREAM *p, int level){
|
||||
BOOL android_SetOutputVolume(OPENSL_STREAM* p, int level)
|
||||
{
|
||||
SLresult rc = (*p->bqPlayerVolume)->SetVolumeLevel(p->bqPlayerVolume, level);
|
||||
assert(SL_RESULT_SUCCESS == rc);
|
||||
|
||||
if (SL_RESULT_SUCCESS != rc)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <stdlib.h>
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include <freerdp/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct opensl_stream {
|
||||
typedef struct opensl_stream
|
||||
{
|
||||
// engine interfaces
|
||||
SLObjectItf engineObject;
|
||||
SLEngineItf engineEngine;
|
||||
@ -58,47 +61,49 @@ typedef struct opensl_stream {
|
||||
unsigned int sr;
|
||||
|
||||
unsigned int queuesize;
|
||||
wQueue *queue;
|
||||
wQueue* queue;
|
||||
} OPENSL_STREAM;
|
||||
|
||||
/*
|
||||
Open the audio device with a given sampling rate (sr), output channels and IO buffer size
|
||||
in frames. Returns a handle to the OpenSL stream
|
||||
*/
|
||||
OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels, int bufferframes);
|
||||
/*
|
||||
Close the audio device
|
||||
*/
|
||||
void android_CloseAudioDevice(OPENSL_STREAM *p);
|
||||
/*
|
||||
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);
|
||||
/*
|
||||
/*
|
||||
Open the audio device with a given sampling rate (sr), output channels and IO buffer size
|
||||
in frames. Returns a handle to the OpenSL stream
|
||||
*/
|
||||
FREERDP_LOCAL OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels,
|
||||
int bufferframes);
|
||||
/*
|
||||
Close the audio device
|
||||
*/
|
||||
FREERDP_LOCAL void android_CloseAudioDevice(OPENSL_STREAM* p);
|
||||
/*
|
||||
Write a buffer to the OpenSL stream *p, of size samples. Returns the number of samples written.
|
||||
*/
|
||||
FREERDP_LOCAL int android_AudioOut(OPENSL_STREAM* p, const short* buffer,
|
||||
int size);
|
||||
/*
|
||||
* Set the volume input level.
|
||||
*/
|
||||
void android_SetInputVolume(OPENSL_STREAM *p, int level);
|
||||
/*
|
||||
FREERDP_LOCAL void android_SetInputVolume(OPENSL_STREAM* p, int level);
|
||||
/*
|
||||
* Get the current output mute setting.
|
||||
*/
|
||||
int android_GetOutputMute(OPENSL_STREAM *p);
|
||||
/*
|
||||
FREERDP_LOCAL int android_GetOutputMute(OPENSL_STREAM* p);
|
||||
/*
|
||||
* Change the current output mute setting.
|
||||
*/
|
||||
void android_SetOutputMute(OPENSL_STREAM *p, BOOL mute);
|
||||
/*
|
||||
FREERDP_LOCAL BOOL android_SetOutputMute(OPENSL_STREAM* p, BOOL mute);
|
||||
/*
|
||||
* Get the current output volume level.
|
||||
*/
|
||||
int android_GetOutputVolume(OPENSL_STREAM *p);
|
||||
/*
|
||||
FREERDP_LOCAL int android_GetOutputVolume(OPENSL_STREAM* p);
|
||||
/*
|
||||
* Get the maximum output volume level.
|
||||
*/
|
||||
int android_GetOutputVolumeMax(OPENSL_STREAM *p);
|
||||
FREERDP_LOCAL int android_GetOutputVolumeMax(OPENSL_STREAM* p);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Set the volume output level.
|
||||
*/
|
||||
void android_SetOutputVolume(OPENSL_STREAM *p, int level);
|
||||
FREERDP_LOCAL BOOL android_SetOutputVolume(OPENSL_STREAM* p, int level);
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ struct rdpsnd_opensles_plugin
|
||||
int block_size;
|
||||
char* device_name;
|
||||
|
||||
OPENSL_STREAM *stream;
|
||||
OPENSL_STREAM* stream;
|
||||
|
||||
UINT32 volume;
|
||||
|
||||
@ -68,10 +68,8 @@ static int rdpsnd_opensles_volume_to_millibel(unsigned short level, int max)
|
||||
const int min = SL_MILLIBEL_MIN;
|
||||
const int step = max - min;
|
||||
const int rc = (level * step / 0xFFFF) + min;
|
||||
|
||||
DEBUG_SND("level=%d, min=%d, max=%d, step=%d, result=%d",
|
||||
level, min, max, step, rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -80,14 +78,12 @@ static unsigned short rdpsnd_opensles_millibel_to_volume(int millibel, int max)
|
||||
const int min = SL_MILLIBEL_MIN;
|
||||
const int range = max - min;
|
||||
const int rc = ((millibel - min) * 0xFFFF + range / 2 + 1) / range;
|
||||
|
||||
DEBUG_SND("millibel=%d, min=%d, max=%d, range=%d, result=%d",
|
||||
millibel, min, max, range, rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static bool rdpsnd_opensles_check_handle(const rdpsndopenslesPlugin *hdl)
|
||||
static bool rdpsnd_opensles_check_handle(const rdpsndopenslesPlugin* hdl)
|
||||
{
|
||||
bool rc = true;
|
||||
|
||||
@ -97,6 +93,7 @@ static bool rdpsnd_opensles_check_handle(const rdpsndopenslesPlugin *hdl)
|
||||
{
|
||||
if (!hdl->dsp_context)
|
||||
rc = false;
|
||||
|
||||
if (!hdl->stream)
|
||||
rc = false;
|
||||
}
|
||||
@ -110,6 +107,7 @@ static BOOL rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device,
|
||||
static int rdpsnd_opensles_set_params(rdpsndopenslesPlugin* opensles)
|
||||
{
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
|
||||
if (!rdpsnd_opensles_check_handle(opensles))
|
||||
return 0;
|
||||
|
||||
@ -118,7 +116,6 @@ static int rdpsnd_opensles_set_params(rdpsndopenslesPlugin* opensles)
|
||||
|
||||
opensles->stream = android_OpenAudioDevice(
|
||||
opensles->rate, opensles->channels, 20);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -127,7 +124,6 @@ static BOOL rdpsnd_opensles_set_format(rdpsndDevicePlugin* device,
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
rdpsnd_opensles_check_handle(opensles);
|
||||
|
||||
DEBUG_SND("opensles=%p format=%p, latency=%d", opensles, format, latency);
|
||||
|
||||
if (format)
|
||||
@ -135,7 +131,6 @@ static BOOL rdpsnd_opensles_set_format(rdpsndDevicePlugin* device,
|
||||
DEBUG_SND("format=%d, cbsize=%d, samples=%d, bits=%d, channels=%d, align=%d",
|
||||
format->wFormatTag, format->cbSize, format->nSamplesPerSec,
|
||||
format->wBitsPerSample, format->nChannels, format->nBlockAlign);
|
||||
|
||||
opensles->rate = format->nSamplesPerSec;
|
||||
opensles->channels = format->nChannels;
|
||||
opensles->format = format->wFormatTag;
|
||||
@ -144,7 +139,6 @@ static BOOL rdpsnd_opensles_set_format(rdpsndDevicePlugin* device,
|
||||
}
|
||||
|
||||
opensles->latency = latency;
|
||||
|
||||
return (rdpsnd_opensles_set_params(opensles) == 0);
|
||||
}
|
||||
|
||||
@ -152,14 +146,14 @@ static BOOL rdpsnd_opensles_open(rdpsndDevicePlugin* device,
|
||||
AUDIO_FORMAT* format, int latency)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("opensles=%p format=%p, latency=%d, rate=%d",
|
||||
opensles, format, latency, opensles->rate);
|
||||
|
||||
if (rdpsnd_opensles_check_handle(opensles))
|
||||
return TRUE;
|
||||
|
||||
opensles->stream = android_OpenAudioDevice(opensles->rate, opensles->channels, 20);
|
||||
opensles->stream = android_OpenAudioDevice(opensles->rate, opensles->channels,
|
||||
20);
|
||||
assert(opensles->stream);
|
||||
|
||||
if (!opensles->stream)
|
||||
@ -174,9 +168,9 @@ static BOOL rdpsnd_opensles_open(rdpsndDevicePlugin* device,
|
||||
static void rdpsnd_opensles_close(rdpsndDevicePlugin* device)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
if( !rdpsnd_opensles_check_handle(opensles))
|
||||
|
||||
if (!rdpsnd_opensles_check_handle(opensles))
|
||||
return;
|
||||
|
||||
android_CloseAudioDevice(opensles->stream);
|
||||
@ -186,29 +180,22 @@ static void rdpsnd_opensles_close(rdpsndDevicePlugin* device)
|
||||
static void rdpsnd_opensles_free(rdpsndDevicePlugin* device)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
assert(opensles);
|
||||
|
||||
assert(opensles->device_name);
|
||||
free(opensles->device_name);
|
||||
|
||||
assert(opensles->dsp_context);
|
||||
freerdp_dsp_context_free(opensles->dsp_context);
|
||||
|
||||
free(opensles);
|
||||
}
|
||||
|
||||
static BOOL rdpsnd_opensles_format_supported(rdpsndDevicePlugin* device,
|
||||
AUDIO_FORMAT* format)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("format=%d, cbsize=%d, samples=%d, bits=%d, channels=%d, align=%d",
|
||||
format->wFormatTag, format->cbSize, format->nSamplesPerSec,
|
||||
format->wBitsPerSample, format->nChannels, format->nBlockAlign);
|
||||
|
||||
assert(opensles);
|
||||
assert(device);
|
||||
assert(format);
|
||||
|
||||
switch (format->wFormatTag)
|
||||
@ -221,6 +208,7 @@ static BOOL rdpsnd_opensles_format_supported(rdpsndDevicePlugin* device,
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WAVE_FORMAT_ADPCM:
|
||||
@ -231,6 +219,7 @@ static BOOL rdpsnd_opensles_format_supported(rdpsndDevicePlugin* device,
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WAVE_FORMAT_ALAW:
|
||||
@ -246,7 +235,6 @@ static BOOL rdpsnd_opensles_format_supported(rdpsndDevicePlugin* device,
|
||||
static UINT32 rdpsnd_opensles_get_volume(rdpsndDevicePlugin* device)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
assert(opensles);
|
||||
|
||||
@ -271,23 +259,24 @@ static BOOL rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device,
|
||||
UINT32 value)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("opensles=%p, value=%d", opensles, value);
|
||||
assert(opensles);
|
||||
|
||||
opensles->volume = value;
|
||||
|
||||
if (opensles->stream)
|
||||
{
|
||||
if (0 == opensles->volume)
|
||||
android_SetOutputMute(opensles->stream, true);
|
||||
return android_SetOutputMute(opensles->stream, true);
|
||||
else
|
||||
{
|
||||
const int max = android_GetOutputVolumeMax(opensles->stream);
|
||||
const int vol = rdpsnd_opensles_volume_to_millibel(value & 0xFFFF, max);
|
||||
|
||||
android_SetOutputMute(opensles->stream, false);
|
||||
android_SetOutputVolume(opensles->stream, vol);
|
||||
if (!android_SetOutputMute(opensles->stream, false))
|
||||
return FALSE;
|
||||
|
||||
if (!android_SetOutputVolume(opensles->stream, vol))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,17 +284,17 @@ static BOOL rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device,
|
||||
}
|
||||
|
||||
static void rdpsnd_opensles_play(rdpsndDevicePlugin* device,
|
||||
BYTE *data, int size)
|
||||
BYTE* data, int size)
|
||||
{
|
||||
union
|
||||
{
|
||||
BYTE *b;
|
||||
short *s;
|
||||
BYTE* b;
|
||||
short* s;
|
||||
} src;
|
||||
int ret;
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
DEBUG_SND("opensles=%p, data=%p, size=%d", opensles, data, size);
|
||||
|
||||
if (!rdpsnd_opensles_check_handle(opensles))
|
||||
return;
|
||||
|
||||
@ -313,10 +302,8 @@ static void rdpsnd_opensles_play(rdpsndDevicePlugin* device,
|
||||
{
|
||||
DEBUG_SND("dsp_context=%p, channels=%d, block_size=%d",
|
||||
opensles->dsp_context, opensles->channels, opensles->block_size);
|
||||
|
||||
opensles->dsp_context->decode_ms_adpcm(opensles->dsp_context,
|
||||
data, size, opensles->channels, opensles->block_size);
|
||||
|
||||
size = opensles->dsp_context->adpcm_size;
|
||||
src.b = opensles->dsp_context->adpcm_buffer;
|
||||
}
|
||||
@ -324,10 +311,8 @@ static void rdpsnd_opensles_play(rdpsndDevicePlugin* device,
|
||||
{
|
||||
DEBUG_SND("dsp_context=%p, channels=%d, block_size=%d",
|
||||
opensles->dsp_context, opensles->channels, opensles->block_size);
|
||||
|
||||
opensles->dsp_context->decode_ima_adpcm(opensles->dsp_context,
|
||||
data, size, opensles->channels, opensles->block_size);
|
||||
|
||||
size = opensles->dsp_context->adpcm_size;
|
||||
src.b = opensles->dsp_context->adpcm_buffer;
|
||||
}
|
||||
@ -340,8 +325,8 @@ 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)
|
||||
WLog_ERR(TAG, "android_AudioOut failed (%d)", ret);
|
||||
}
|
||||
@ -350,14 +335,15 @@ static void rdpsnd_opensles_start(rdpsndDevicePlugin* device)
|
||||
{
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
rdpsnd_opensles_check_handle(opensles);
|
||||
|
||||
DEBUG_SND("opensles=%p", opensles);
|
||||
}
|
||||
|
||||
static COMMAND_LINE_ARGUMENT_A rdpsnd_opensles_args[] =
|
||||
{
|
||||
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
||||
NULL, NULL, -1, NULL, "device" },
|
||||
{
|
||||
"dev", COMMAND_LINE_VALUE_REQUIRED, "<device>",
|
||||
NULL, NULL, -1, NULL, "device"
|
||||
},
|
||||
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
||||
};
|
||||
|
||||
@ -368,16 +354,14 @@ static int rdpsnd_opensles_parse_addin_args(rdpsndDevicePlugin* device,
|
||||
DWORD flags;
|
||||
COMMAND_LINE_ARGUMENT_A* arg;
|
||||
rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*) device;
|
||||
|
||||
assert(opensles);
|
||||
assert(args);
|
||||
|
||||
DEBUG_SND("opensles=%p, args=%p", opensles, args);
|
||||
|
||||
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
||||
|
||||
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON |
|
||||
COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
||||
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
|
||||
rdpsnd_opensles_args, flags, opensles, NULL, NULL);
|
||||
|
||||
if (status < 0)
|
||||
return status;
|
||||
|
||||
@ -389,14 +373,13 @@ static int rdpsnd_opensles_parse_addin_args(rdpsndDevicePlugin* device,
|
||||
continue;
|
||||
|
||||
CommandLineSwitchStart(arg)
|
||||
|
||||
CommandLineSwitchCase(arg, "dev")
|
||||
{
|
||||
opensles->device_name = _strdup(arg->Value);
|
||||
|
||||
if (!opensles->device_name)
|
||||
return ERROR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
CommandLineSwitchEnd(arg)
|
||||
}
|
||||
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
||||
@ -423,10 +406,9 @@ UINT freerdp_rdpsnd_client_subsystem_entry(
|
||||
ADDIN_ARGV* args;
|
||||
rdpsndopenslesPlugin* opensles;
|
||||
UINT error;
|
||||
|
||||
DEBUG_SND("pEntryPoints=%p", pEntryPoints);
|
||||
|
||||
opensles = (rdpsndopenslesPlugin*) calloc(1, sizeof(rdpsndopenslesPlugin));
|
||||
|
||||
if (!opensles)
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
|
||||
@ -439,13 +421,13 @@ UINT freerdp_rdpsnd_client_subsystem_entry(
|
||||
opensles->device.Play = rdpsnd_opensles_play;
|
||||
opensles->device.Close = rdpsnd_opensles_close;
|
||||
opensles->device.Free = rdpsnd_opensles_free;
|
||||
|
||||
args = pEntryPoints->args;
|
||||
rdpsnd_opensles_parse_addin_args((rdpsndDevicePlugin*) opensles, args);
|
||||
|
||||
if (!opensles->device_name)
|
||||
{
|
||||
opensles->device_name = _strdup("default");
|
||||
|
||||
if (!opensles->device_name)
|
||||
{
|
||||
error = CHANNEL_RC_NO_MEMORY;
|
||||
@ -456,8 +438,8 @@ UINT freerdp_rdpsnd_client_subsystem_entry(
|
||||
opensles->rate = 44100;
|
||||
opensles->channels = 2;
|
||||
opensles->format = WAVE_FORMAT_ADPCM;
|
||||
|
||||
opensles->dsp_context = freerdp_dsp_context_new();
|
||||
|
||||
if (!opensles->dsp_context)
|
||||
{
|
||||
error = CHANNEL_RC_NO_MEMORY;
|
||||
@ -466,7 +448,6 @@ UINT freerdp_rdpsnd_client_subsystem_entry(
|
||||
|
||||
pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd,
|
||||
(rdpsndDevicePlugin*) opensles);
|
||||
|
||||
DEBUG_SND("success");
|
||||
return CHANNEL_RC_OK;
|
||||
out_dsp_new:
|
||||
|
Loading…
Reference in New Issue
Block a user