opensles: finish remaining bits for source element.

This commit is contained in:
Josep Torra 2012-09-21 16:11:42 +02:00 committed by Sebastian Dröge
parent c006973a4e
commit 5612936d1a
2 changed files with 40 additions and 35 deletions

View file

@ -107,22 +107,30 @@ _opensles_format (GstRingBufferSpec * spec, SLDataFormat_PCM * format)
static void static void
_opensles_recorder_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context) _opensles_recorder_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context)
{ {
#if 0
GstRingBuffer *rb = GST_RING_BUFFER_CAST (context); GstRingBuffer *rb = GST_RING_BUFFER_CAST (context);
GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb);
assert (bq == bqRecorderBufferQueue);
assert (NULL == context);
// for streaming recording, here we would call Enqueue to give recorder the next buffer to fill
// but instead, this is a one-time buffer so we stop recording
SLresult result; SLresult result;
result = guint8 *writeptr;
(*recorderRecord)->SetRecordState (recorderRecord, gint writeseg;
SL_RECORDSTATE_STOPPED); gint len;
if (SL_RESULT_SUCCESS == result) {
recorderSize = RECORDER_FRAMES * sizeof (short); if (!gst_ring_buffer_prepare_read (rb, &writeseg, &writeptr, &len)) {
recorderSR = SL_SAMPLINGRATE_16; GST_WARNING_OBJECT (rb, "No segment available");
return;
} }
#endif
/* Enqueue a buffer */
GST_LOG_OBJECT (thiz, "enqueue: %p size %d segment: %d",
writeptr, len, writeseg);
result = (*thiz->bufferQueue)->Enqueue (thiz->bufferQueue, writeptr, len);
if (result != SL_RESULT_SUCCESS) {
GST_ERROR_OBJECT (thiz, "bufferQueue.Enqueue failed(0x%08x)",
(guint32) result);
return;
}
gst_ring_buffer_advance (rb, 1);
} }
static gboolean static gboolean
@ -133,24 +141,25 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
SLDataFormat_PCM format; SLDataFormat_PCM format;
/* Configure audio source */ /* Configure audio source */
SLDataLocator_IODevice loc_dev = SLDataLocator_IODevice loc_dev = {
{ SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT, SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
SL_DEFAULTDEVICEID_AUDIOINPUT, NULL SL_DEFAULTDEVICEID_AUDIOINPUT, NULL
}; };
SLDataSource audioSrc = { &loc_dev, NULL }; SLDataSource audioSrc = { &loc_dev, NULL };
/* Configure audio sink */ /* Configure audio sink */
SLDataLocator_AndroidSimpleBufferQueue loc_bq = SLDataLocator_AndroidSimpleBufferQueue loc_bq = {
{ SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 }; SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2
};
SLDataSink audioSink = { &loc_bq, &format }; SLDataSink audioSink = { &loc_bq, &format };
/* Create audio recorder (requires the RECORD_AUDIO permission) */
const SLInterfaceID id[1] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE }; const SLInterfaceID id[1] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
const SLboolean req[1] = { SL_BOOLEAN_TRUE }; const SLboolean req[1] = { SL_BOOLEAN_TRUE };
/* Define the format in OpenSL ES terms */ /* Define the format in OpenSL ES terms */
_opensles_format (spec, &format); _opensles_format (spec, &format);
/* Create audio recorder (requires the RECORD_AUDIO permission) */
result = (*thiz->engineEngine)->CreateAudioRecorder (thiz->engineEngine, result = (*thiz->engineEngine)->CreateAudioRecorder (thiz->engineEngine,
&thiz->recorderObject, &audioSrc, &audioSink, 1, id, req); &thiz->recorderObject, &audioSrc, &audioSink, 1, id, req);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
@ -197,8 +206,8 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
} }
/* Define our ringbuffer in terms of number of buffers and buffer size. */ /* Define our ringbuffer in terms of number of buffers and buffer size. */
spec->segsize = (spec->rate * spec->bytes_per_sample) >> 1; spec->segsize = (spec->rate * spec->bytes_per_sample) >> 2;
spec->segtotal = 3; spec->segtotal = 16;
return TRUE; return TRUE;
@ -227,8 +236,8 @@ _opensles_recorder_start (GstRingBuffer * rb)
return FALSE; return FALSE;
} }
/* FIXME: Maybe we should enqueue some buffers here first by calling _opensles_recorder_cb (NULL, rb);
* _opensles_recorder_cb */ _opensles_recorder_cb (NULL, rb);
/* start recording */ /* start recording */
result = result =
@ -351,13 +360,15 @@ _opensles_player_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
SLDataFormat_PCM format; SLDataFormat_PCM format;
/* Configure audio source */ /* Configure audio source */
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {
{ SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 }; SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2
};
SLDataSource audioSrc = { &loc_bufq, &format }; SLDataSource audioSrc = { &loc_bufq, &format };
/* Configure audio sink */ /* Configure audio sink */
SLDataLocator_OutputMix loc_outmix = SLDataLocator_OutputMix loc_outmix = {
{ SL_DATALOCATOR_OUTPUTMIX, thiz->outputMixObject }; SL_DATALOCATOR_OUTPUTMIX, thiz->outputMixObject
};
SLDataSink audioSink = { &loc_outmix, NULL }; SLDataSink audioSink = { &loc_outmix, NULL };
/* Create an audio player */ /* Create an audio player */

View file

@ -26,8 +26,7 @@
GST_DEBUG_CATEGORY_STATIC (opensles_src_debug); GST_DEBUG_CATEGORY_STATIC (opensles_src_debug);
#define GST_CAT_DEFAULT opensles_src_debug #define GST_CAT_DEFAULT opensles_src_debug
#define RATES "8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000" /* *INDENT-OFF* */
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
@ -36,15 +35,10 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
"signed = (boolean) { TRUE }, " "signed = (boolean) { TRUE }, "
"width = (int) 16, " "width = (int) 16, "
"depth = (int) 16, " "depth = (int) 16, "
"rate = (int) { " RATES "}, " "rate = (int) 16000, "
"channels = (int) [1, 2];" "channels = (int) 1")
"audio/x-raw-int, "
"endianness = (int) {" G_STRINGIFY (G_BYTE_ORDER) " }, "
"signed = (boolean) { TRUE }, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) { " RATES "}, " "channels = (int) [1, 2]")
); );
/* *INDENT-ON* */
static void static void
_do_init (GType type) _do_init (GType type)