2013-09-20 13:47:10 +04:00
|
|
|
/*
|
|
|
|
opensl_io.c:
|
|
|
|
Android OpenSL input/output module
|
|
|
|
Copyright (c) 2012, Victor Lazzarini
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2016-10-17 11:21:05 +03:00
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the <organization> nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
2013-09-20 13:47:10 +04:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "audin_main.h"
|
2013-09-20 13:47:10 +04:00
|
|
|
#include "opensl_io.h"
|
|
|
|
#define CONV16BIT 32768
|
|
|
|
#define CONVMYFLT (1./32768.)
|
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
|
|
|
// creates the OpenSL ES audio engine
|
2016-10-17 11:21:05 +03:00
|
|
|
static SLresult openSLCreateEngine(OPENSL_STREAM* p)
|
2013-09-20 13:47:10 +04:00
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
SLresult result;
|
|
|
|
// create engine
|
|
|
|
result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL);
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("engineObject=%p", (void*) p->engineObject);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (result != SL_RESULT_SUCCESS) goto engine_end;
|
|
|
|
|
|
|
|
// realize the engine
|
|
|
|
result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE);
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("Realize=%"PRIu32"", result);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
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));
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("engineEngine=%p", (void*) p->engineEngine);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
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));
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("deviceVolume=%p", (void*) p->deviceVolume);
|
2016-10-17 11:21:05 +03:00
|
|
|
|
|
|
|
if (result != SL_RESULT_SUCCESS)
|
2013-09-26 18:05:16 +04:00
|
|
|
{
|
|
|
|
p->deviceVolume = NULL;
|
|
|
|
result = SL_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
engine_end:
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(SL_RESULT_SUCCESS == result);
|
2016-10-17 11:21:05 +03:00
|
|
|
return result;
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open the OpenSL ES device for input
|
2016-10-17 11:21:05 +03:00
|
|
|
static SLresult openSLRecOpen(OPENSL_STREAM* p)
|
|
|
|
{
|
|
|
|
SLresult result;
|
|
|
|
SLuint32 sr = p->sr;
|
|
|
|
SLuint32 channels = p->inchannels;
|
|
|
|
assert(!p->recorderObject);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (channels)
|
|
|
|
{
|
|
|
|
switch (sr)
|
|
|
|
{
|
|
|
|
case 8000:
|
|
|
|
sr = SL_SAMPLINGRATE_8;
|
|
|
|
break;
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
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;
|
2013-09-26 18:05:16 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// configure audio source
|
|
|
|
SLDataLocator_IODevice loc_dev = {SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
|
|
|
|
SL_DEFAULTDEVICEID_AUDIOINPUT, NULL
|
|
|
|
};
|
|
|
|
SLDataSource audioSrc = {&loc_dev, NULL};
|
|
|
|
// configure audio sink
|
|
|
|
int speakers;
|
|
|
|
|
|
|
|
if (channels > 1)
|
|
|
|
speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
|
|
|
|
else
|
2013-09-26 18:05:16 +04:00
|
|
|
speakers = SL_SPEAKER_FRONT_CENTER;
|
2016-10-17 11:21:05 +03:00
|
|
|
|
|
|
|
SLDataLocator_AndroidSimpleBufferQueue loc_bq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
|
|
|
|
SLDataFormat_PCM format_pcm;
|
2013-09-27 13:39:04 +04:00
|
|
|
format_pcm.formatType = SL_DATAFORMAT_PCM;
|
|
|
|
format_pcm.numChannels = channels;
|
|
|
|
format_pcm.samplesPerSec = sr;
|
|
|
|
format_pcm.channelMask = speakers;
|
2016-10-17 11:21:05 +03:00
|
|
|
format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
|
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
if (16 == p->bits_per_sample)
|
|
|
|
{
|
|
|
|
format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
|
|
|
|
format_pcm.containerSize = 16;
|
|
|
|
}
|
|
|
|
else if (8 == p->bits_per_sample)
|
|
|
|
{
|
|
|
|
format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_8;
|
|
|
|
format_pcm.containerSize = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
SLDataSink audioSnk = {&loc_bq, &format_pcm};
|
|
|
|
// create audio recorder
|
|
|
|
// (requires the RECORD_AUDIO permission)
|
|
|
|
const SLInterfaceID id[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE};
|
|
|
|
const SLboolean req[] = {SL_BOOLEAN_TRUE};
|
|
|
|
result = (*p->engineEngine)->CreateAudioRecorder(p->engineEngine,
|
|
|
|
&(p->recorderObject), &audioSrc, &audioSnk, 1, id, req);
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p->recorderObject=%p", (void*) p->recorderObject);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(!result);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
|
|
|
|
|
|
|
// realize the audio recorder
|
|
|
|
result = (*p->recorderObject)->Realize(p->recorderObject, SL_BOOLEAN_FALSE);
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("Realize=%"PRIu32"", result);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(!result);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
|
|
|
|
|
|
|
// get the record interface
|
|
|
|
result = (*p->recorderObject)->GetInterface(p->recorderObject,
|
|
|
|
SL_IID_RECORD, &(p->recorderRecord));
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p->recorderRecord=%p", (void*) p->recorderRecord);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(!result);
|
2016-10-17 11:21:05 +03:00
|
|
|
|
|
|
|
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
|
|
|
|
|
|
|
// get the buffer queue interface
|
|
|
|
result = (*p->recorderObject)->GetInterface(p->recorderObject,
|
|
|
|
SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
|
|
|
|
&(p->recorderBufferQueue));
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p->recorderBufferQueue=%p", (void*) p->recorderBufferQueue);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(!result);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (SL_RESULT_SUCCESS != result) goto end_recopen;
|
|
|
|
|
|
|
|
// register callback on the buffer queue
|
|
|
|
result = (*p->recorderBufferQueue)->RegisterCallback(p->recorderBufferQueue,
|
|
|
|
bqRecorderCallback, p);
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p->recorderBufferQueue=%p", (void*) p->recorderBufferQueue);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(!result);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (SL_RESULT_SUCCESS != result)
|
|
|
|
goto end_recopen;
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
end_recopen:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else return SL_RESULT_SUCCESS;
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// close the OpenSL IO and destroy the audio engine
|
2016-10-17 11:21:05 +03:00
|
|
|
static void openSLDestroyEngine(OPENSL_STREAM* p)
|
2013-09-26 18:05:16 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p=%p", (void*) p);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
// destroy audio recorder object, and invalidate all associated interfaces
|
|
|
|
if (p->recorderObject != NULL)
|
|
|
|
{
|
|
|
|
(*p->recorderObject)->Destroy(p->recorderObject);
|
|
|
|
p->recorderObject = NULL;
|
|
|
|
p->recorderRecord = NULL;
|
|
|
|
p->recorderBufferQueue = NULL;
|
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
// destroy engine object, and invalidate all associated interfaces
|
|
|
|
if (p->engineObject != NULL)
|
|
|
|
{
|
|
|
|
(*p->engineObject)->Destroy(p->engineObject);
|
|
|
|
p->engineObject = NULL;
|
|
|
|
p->engineEngine = NULL;
|
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
// open the android audio device for input
|
|
|
|
OPENSL_STREAM* android_OpenRecDevice(char* name, int sr, int inchannels,
|
|
|
|
int bufferframes, int bits_per_sample)
|
2013-09-26 18:05:16 +04:00
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
OPENSL_STREAM* p;
|
|
|
|
p = (OPENSL_STREAM*) calloc(sizeof(OPENSL_STREAM), 1);
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
p->inchannels = inchannels;
|
|
|
|
p->sr = sr;
|
2013-09-26 18:05:16 +04:00
|
|
|
p->queue = Queue_New(TRUE, -1, -1);
|
2013-09-27 13:39:04 +04:00
|
|
|
p->buffersize = bufferframes;
|
|
|
|
p->bits_per_sample = bits_per_sample;
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
if ((p->bits_per_sample != 8) && (p->bits_per_sample != 16))
|
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
android_CloseRecDevice(p);
|
2013-09-27 13:39:04 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-10-17 11:21:05 +03:00
|
|
|
|
|
|
|
if (openSLCreateEngine(p) != SL_RESULT_SUCCESS)
|
2013-09-27 13:39:04 +04:00
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
android_CloseRecDevice(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (openSLRecOpen(p) != SL_RESULT_SUCCESS)
|
2013-09-27 13:39:04 +04:00
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
android_CloseRecDevice(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
return p;
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// close the android audio device
|
2016-10-17 11:21:05 +03:00
|
|
|
void android_CloseRecDevice(OPENSL_STREAM* p)
|
2013-09-26 18:05:16 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p=%p", (void*) p);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (p == NULL)
|
|
|
|
return;
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
if (p->queue)
|
2013-09-26 18:05:16 +04:00
|
|
|
{
|
2013-09-27 13:39:04 +04:00
|
|
|
while (Queue_Count(p->queue) > 0)
|
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
queue_element* e = Queue_Dequeue(p->queue);
|
2013-09-27 13:39:04 +04:00
|
|
|
free(e->data);
|
|
|
|
free(e);
|
|
|
|
}
|
2016-10-17 11:21:05 +03:00
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
Queue_Free(p->queue);
|
2013-09-26 18:05:16 +04:00
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
if (p->next)
|
|
|
|
{
|
|
|
|
free(p->next->data);
|
|
|
|
free(p->next);
|
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-27 17:07:32 +04:00
|
|
|
if (p->prep)
|
|
|
|
{
|
|
|
|
free(p->prep->data);
|
|
|
|
free(p->prep);
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
openSLDestroyEngine(p);
|
|
|
|
free(p);
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// this callback handler is called every time a buffer finishes recording
|
2016-10-17 11:21:05 +03:00
|
|
|
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context)
|
2013-09-20 13:47:10 +04:00
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
queue_element* e;
|
|
|
|
OPENSL_STREAM* p = (OPENSL_STREAM*) context;
|
2016-12-14 00:47:08 +03:00
|
|
|
DEBUG_DVC("p=%p", (void*) p);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(p);
|
2013-09-30 12:08:22 +04:00
|
|
|
assert(p->next);
|
|
|
|
assert(p->prep);
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(p->queue);
|
|
|
|
e = calloc(1, sizeof(queue_element));
|
2016-10-17 11:21:05 +03:00
|
|
|
|
2015-03-23 19:25:23 +03:00
|
|
|
if (!e)
|
|
|
|
return;
|
2016-10-17 11:21:05 +03:00
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
e->data = calloc(p->buffersize, p->bits_per_sample / 8);
|
2016-10-17 11:21:05 +03:00
|
|
|
|
2015-03-23 19:25:23 +03:00
|
|
|
if (!e->data)
|
|
|
|
{
|
|
|
|
free(e);
|
|
|
|
return;
|
|
|
|
}
|
2013-09-27 17:13:12 +04:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
e->size = p->buffersize * p->bits_per_sample / 8;
|
2013-09-30 12:08:22 +04:00
|
|
|
Queue_Enqueue(p->queue, p->next);
|
|
|
|
p->next = p->prep;
|
2013-09-27 17:07:32 +04:00
|
|
|
p->prep = e;
|
2016-10-17 11:21:05 +03:00
|
|
|
(*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue,
|
|
|
|
e->data, e->size);
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
2016-10-17 11:21:05 +03:00
|
|
|
|
2013-09-20 13:47:10 +04:00
|
|
|
// gets a buffer of size samples from the device
|
2016-10-17 11:21:05 +03:00
|
|
|
int android_RecIn(OPENSL_STREAM* p, short* buffer, int size)
|
2013-09-20 13:47:10 +04:00
|
|
|
{
|
2016-10-17 11:21:05 +03:00
|
|
|
queue_element* e;
|
2013-09-26 18:05:16 +04:00
|
|
|
int rc;
|
2016-10-17 11:21:05 +03:00
|
|
|
DWORD status;
|
2013-09-26 18:05:16 +04:00
|
|
|
assert(p);
|
|
|
|
assert(buffer);
|
|
|
|
assert(size > 0);
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
/* Initial trigger for the queue. */
|
2013-09-27 17:07:32 +04:00
|
|
|
if (!p->prep)
|
2013-09-26 18:05:16 +04:00
|
|
|
{
|
2013-09-30 12:08:22 +04:00
|
|
|
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;
|
2016-10-17 11:21:05 +03:00
|
|
|
(*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);
|
2013-09-26 18:05:16 +04:00
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-30 12:08:22 +04:00
|
|
|
/* Wait for queue to be filled... */
|
|
|
|
if (!Queue_Count(p->queue))
|
2016-10-17 11:21:05 +03:00
|
|
|
{
|
|
|
|
status = WaitForSingleObject(p->queue->event, INFINITE);
|
2015-07-30 16:49:21 +03:00
|
|
|
|
2016-10-17 11:21:05 +03:00
|
|
|
if (status == WAIT_FAILED)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"", GetLastError());
|
2016-10-17 11:21:05 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 12:08:22 +04:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
e = Queue_Dequeue(p->queue);
|
2016-10-17 11:21:05 +03:00
|
|
|
|
2013-09-26 18:05:16 +04:00
|
|
|
if (!e)
|
2013-09-27 13:39:04 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "[ERROR] got e=NULL from queue");
|
2013-09-26 18:05:16 +04:00
|
|
|
return -1;
|
2013-09-27 13:39:04 +04:00
|
|
|
}
|
2013-09-20 13:47:10 +04:00
|
|
|
|
2013-09-27 13:39:04 +04:00
|
|
|
rc = (e->size < size) ? e->size : size;
|
2013-09-30 12:08:22 +04:00
|
|
|
assert(size == e->size);
|
|
|
|
assert(p->buffersize * p->bits_per_sample / 8 == size);
|
|
|
|
memcpy(buffer, e->data, rc);
|
2013-09-26 18:05:16 +04:00
|
|
|
free(e->data);
|
|
|
|
free(e);
|
2016-10-17 11:21:05 +03:00
|
|
|
return rc;
|
2013-09-20 13:47:10 +04:00
|
|
|
}
|
2013-09-26 18:05:16 +04:00
|
|
|
|