AudioRecorder_to_android.cpp revision e9b57cefb954e7c1bffc5d4b59f89aca5e050797
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#include "sles_allinclusive.h"
19#include "android_prompts.h"
20
21#include <utils/String16.h>
22
23#include <system/audio.h>
24
25#define KEY_RECORDING_SOURCE_PARAMSIZE  sizeof(SLuint32)
26#define KEY_RECORDING_PRESET_PARAMSIZE  sizeof(SLuint32)
27
28//-----------------------------------------------------------------------------
29// Internal utility functions
30//----------------------------
31
32SLresult audioRecorder_setPreset(CAudioRecorder* ar, SLuint32 recordPreset) {
33    SLresult result = SL_RESULT_SUCCESS;
34
35    audio_source_t newRecordSource = AUDIO_SOURCE_DEFAULT;
36    switch (recordPreset) {
37    case SL_ANDROID_RECORDING_PRESET_GENERIC:
38        newRecordSource = AUDIO_SOURCE_DEFAULT;
39        break;
40    case SL_ANDROID_RECORDING_PRESET_CAMCORDER:
41        newRecordSource = AUDIO_SOURCE_CAMCORDER;
42        break;
43    case SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION:
44        newRecordSource = AUDIO_SOURCE_VOICE_RECOGNITION;
45        break;
46    case SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION:
47        newRecordSource = AUDIO_SOURCE_VOICE_COMMUNICATION;
48        break;
49    case SL_ANDROID_RECORDING_PRESET_UNPROCESSED:
50            newRecordSource = AUDIO_SOURCE_UNPROCESSED;
51            break;
52    case SL_ANDROID_RECORDING_PRESET_NONE:
53        // it is an error to set preset "none"
54    default:
55        SL_LOGE(ERROR_RECORDERPRESET_SET_UNKNOWN_PRESET);
56        result = SL_RESULT_PARAMETER_INVALID;
57    }
58
59    // recording preset needs to be set before the object is realized
60    // (ap->mAudioRecord is supposed to be 0 until then)
61    if (SL_OBJECT_STATE_UNREALIZED != ar->mObject.mState) {
62        SL_LOGE(ERROR_RECORDERPRESET_REALIZED);
63        result = SL_RESULT_PRECONDITIONS_VIOLATED;
64    } else {
65        ar->mRecordSource = newRecordSource;
66    }
67
68    return result;
69}
70
71
72SLresult audioRecorder_getPreset(CAudioRecorder* ar, SLuint32* pPreset) {
73    SLresult result = SL_RESULT_SUCCESS;
74
75    switch (ar->mRecordSource) {
76    case AUDIO_SOURCE_DEFAULT:
77    case AUDIO_SOURCE_MIC:
78        *pPreset = SL_ANDROID_RECORDING_PRESET_GENERIC;
79        break;
80    case AUDIO_SOURCE_VOICE_UPLINK:
81    case AUDIO_SOURCE_VOICE_DOWNLINK:
82    case AUDIO_SOURCE_VOICE_CALL:
83        *pPreset = SL_ANDROID_RECORDING_PRESET_NONE;
84        break;
85    case AUDIO_SOURCE_VOICE_RECOGNITION:
86        *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
87        break;
88    case AUDIO_SOURCE_CAMCORDER:
89        *pPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER;
90        break;
91    case AUDIO_SOURCE_VOICE_COMMUNICATION:
92        *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
93        break;
94    case AUDIO_SOURCE_UNPROCESSED:
95        *pPreset = SL_ANDROID_RECORDING_PRESET_UNPROCESSED;
96        break;
97    default:
98        *pPreset = SL_ANDROID_RECORDING_PRESET_NONE;
99        result = SL_RESULT_INTERNAL_ERROR;
100        break;
101    }
102
103    return result;
104}
105
106
107void audioRecorder_handleNewPos_lockRecord(CAudioRecorder* ar) {
108    //SL_LOGV("received event EVENT_NEW_POS from AudioRecord");
109    slRecordCallback callback = NULL;
110    void* callbackPContext = NULL;
111
112    interface_lock_shared(&ar->mRecord);
113    callback = ar->mRecord.mCallback;
114    callbackPContext = ar->mRecord.mContext;
115    interface_unlock_shared(&ar->mRecord);
116
117    if (NULL != callback) {
118        // getting this event implies SL_RECORDEVENT_HEADATNEWPOS was set in the event mask
119        (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATNEWPOS);
120    }
121}
122
123
124void audioRecorder_handleMarker_lockRecord(CAudioRecorder* ar) {
125    //SL_LOGV("received event EVENT_MARKER from AudioRecord");
126    slRecordCallback callback = NULL;
127    void* callbackPContext = NULL;
128
129    interface_lock_shared(&ar->mRecord);
130    callback = ar->mRecord.mCallback;
131    callbackPContext = ar->mRecord.mContext;
132    interface_unlock_shared(&ar->mRecord);
133
134    if (NULL != callback) {
135        // getting this event implies SL_RECORDEVENT_HEADATMARKER was set in the event mask
136        (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATMARKER);
137    }
138}
139
140
141void audioRecorder_handleOverrun_lockRecord(CAudioRecorder* ar) {
142    //SL_LOGV("received event EVENT_OVERRUN from AudioRecord");
143    slRecordCallback callback = NULL;
144    void* callbackPContext = NULL;
145
146    interface_lock_shared(&ar->mRecord);
147    if (ar->mRecord.mCallbackEventsMask & SL_RECORDEVENT_HEADSTALLED) {
148        callback = ar->mRecord.mCallback;
149        callbackPContext = ar->mRecord.mContext;
150    }
151    interface_unlock_shared(&ar->mRecord);
152
153    if (NULL != callback) {
154        (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADSTALLED);
155    }
156}
157
158//-----------------------------------------------------------------------------
159SLresult android_audioRecorder_checkSourceSink(CAudioRecorder* ar) {
160
161    const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource;
162    const SLDataSink   *pAudioSnk = &ar->mDataSink.u.mSink;
163
164    const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator;
165    const SLuint32 sinkFormatType = *(SLuint32 *)pAudioSnk->pFormat;
166
167    const SLuint32 *df_representation = NULL; // pointer to representation field, if it exists
168
169    // sink must be an Android simple buffer queue with PCM data format
170    switch (sinkLocatorType) {
171    case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: {
172        switch (sinkFormatType) {
173        case SL_ANDROID_DATAFORMAT_PCM_EX: {
174            const SLAndroidDataFormat_PCM_EX *df_pcm =
175                    (SLAndroidDataFormat_PCM_EX *) pAudioSnk->pFormat;
176            // checkDataFormat() already checked representation
177            df_representation = &df_pcm->representation;
178        } // SL_ANDROID_DATAFORMAT_PCM_EX - fall through to next test.
179        case SL_DATAFORMAT_PCM: {
180            const SLDataFormat_PCM *df_pcm = (const SLDataFormat_PCM *) pAudioSnk->pFormat;
181            // FIXME validate channel mask and number of channels
182
183            // checkDataFormat already checked sample rate
184
185            ar->mNumChannels = df_pcm->numChannels;
186
187            if (df_pcm->endianness != ar->mObject.mEngine->mEngine.mNativeEndianness) {
188                SL_LOGE("Cannot create audio recorder: unsupported byte order %u",
189                        df_pcm->endianness);
190                return SL_RESULT_CONTENT_UNSUPPORTED;
191            }
192
193            ar->mSampleRateMilliHz = df_pcm->samplesPerSec; // Note: bad field name in SL ES
194            SL_LOGV("AudioRecorder requested sample rate = %u mHz, %u channel(s)",
195                    ar->mSampleRateMilliHz, ar->mNumChannels);
196
197            // we don't support container size != sample depth
198            if (df_pcm->containerSize != df_pcm->bitsPerSample) {
199                SL_LOGE("Cannot create audio recorder: unsupported container size %u bits for "
200                        "sample depth %u bits",
201                        df_pcm->containerSize, (SLuint32)df_pcm->bitsPerSample);
202                return SL_RESULT_CONTENT_UNSUPPORTED;
203            }
204
205            } break;
206        default:
207            SL_LOGE(ERROR_RECORDER_SINK_FORMAT_MUST_BE_PCM);
208            return SL_RESULT_PARAMETER_INVALID;
209        }   // switch (sourceFormatType)
210        } break;    // case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE
211    default:
212        SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE);
213        return SL_RESULT_PARAMETER_INVALID;
214    }   // switch (sourceLocatorType)
215
216    // Source check:
217    // only input device sources are supported
218    // check it's an IO device
219    if (SL_DATALOCATOR_IODEVICE != *(SLuint32 *)pAudioSrc->pLocator) {
220        SL_LOGE(ERROR_RECORDER_SOURCE_MUST_BE_IODEVICE);
221        return SL_RESULT_PARAMETER_INVALID;
222    } else {
223
224        // check it's an input device
225        SLDataLocator_IODevice *dl_iod = (SLDataLocator_IODevice *) pAudioSrc->pLocator;
226        if (SL_IODEVICE_AUDIOINPUT != dl_iod->deviceType) {
227            SL_LOGE(ERROR_RECORDER_IODEVICE_MUST_BE_AUDIOINPUT);
228            return SL_RESULT_PARAMETER_INVALID;
229        }
230
231        // check it's the default input device, others aren't supported here
232        if (SL_DEFAULTDEVICEID_AUDIOINPUT != dl_iod->deviceID) {
233            SL_LOGE(ERROR_RECORDER_INPUT_ID_MUST_BE_DEFAULT);
234            return SL_RESULT_PARAMETER_INVALID;
235        }
236    }
237
238    return SL_RESULT_SUCCESS;
239}
240//-----------------------------------------------------------------------------
241static void audioRecorder_callback(int event, void* user, void *info) {
242    //SL_LOGV("audioRecorder_callback(%d, %p, %p) entering", event, user, info);
243
244    CAudioRecorder *ar = (CAudioRecorder *)user;
245
246    if (!android::CallbackProtector::enterCbIfOk(ar->mCallbackProtector)) {
247        // it is not safe to enter the callback (the track is about to go away)
248        return;
249    }
250
251    void * callbackPContext = NULL;
252
253    switch (event) {
254    case android::AudioRecord::EVENT_MORE_DATA: {
255        slBufferQueueCallback callback = NULL;
256        android::AudioRecord::Buffer* pBuff = (android::AudioRecord::Buffer*)info;
257
258        // push data to the buffer queue
259        interface_lock_exclusive(&ar->mBufferQueue);
260
261        if (ar->mBufferQueue.mState.count != 0) {
262            assert(ar->mBufferQueue.mFront != ar->mBufferQueue.mRear);
263
264            BufferHeader *oldFront = ar->mBufferQueue.mFront;
265            BufferHeader *newFront = &oldFront[1];
266
267            size_t availSink = oldFront->mSize - ar->mBufferQueue.mSizeConsumed;
268            size_t availSource = pBuff->size;
269            size_t bytesToCopy = availSink < availSource ? availSink : availSource;
270            void *pDest = (char *)oldFront->mBuffer + ar->mBufferQueue.mSizeConsumed;
271            memcpy(pDest, pBuff->raw, bytesToCopy);
272
273            if (bytesToCopy < availSink) {
274                // can't consume the whole or rest of the buffer in one shot
275                ar->mBufferQueue.mSizeConsumed += availSource;
276                // pBuff->size is already equal to bytesToCopy in this case
277            } else {
278                // finish pushing the buffer or push the buffer in one shot
279                pBuff->size = bytesToCopy;
280                ar->mBufferQueue.mSizeConsumed = 0;
281                if (newFront == &ar->mBufferQueue.mArray[ar->mBufferQueue.mNumBuffers + 1]) {
282                    newFront = ar->mBufferQueue.mArray;
283                }
284                ar->mBufferQueue.mFront = newFront;
285
286                ar->mBufferQueue.mState.count--;
287                ar->mBufferQueue.mState.playIndex++;
288
289                // data has been copied to the buffer, and the buffer queue state has been updated
290                // we will notify the client if applicable
291                callback = ar->mBufferQueue.mCallback;
292                // save callback data
293                callbackPContext = ar->mBufferQueue.mContext;
294            }
295        } else { // empty queue
296            // no destination to push the data
297            pBuff->size = 0;
298        }
299
300        interface_unlock_exclusive(&ar->mBufferQueue);
301
302        // notify client
303        if (NULL != callback) {
304            (*callback)(&ar->mBufferQueue.mItf, callbackPContext);
305        }
306        }
307        break;
308
309    case android::AudioRecord::EVENT_OVERRUN:
310        audioRecorder_handleOverrun_lockRecord(ar);
311        break;
312
313    case android::AudioRecord::EVENT_MARKER:
314        audioRecorder_handleMarker_lockRecord(ar);
315        break;
316
317    case android::AudioRecord::EVENT_NEW_POS:
318        audioRecorder_handleNewPos_lockRecord(ar);
319        break;
320
321    case android::AudioRecord::EVENT_NEW_IAUDIORECORD:
322        // ignore for now
323        break;
324
325    default:
326        SL_LOGE("Encountered unknown AudioRecord event %d for CAudioRecord %p", event, ar);
327        break;
328    }
329
330    ar->mCallbackProtector->exitCb();
331}
332
333
334//-----------------------------------------------------------------------------
335SLresult android_audioRecorder_create(CAudioRecorder* ar) {
336    SL_LOGV("android_audioRecorder_create(%p) entering", ar);
337
338    const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource;
339    const SLDataSink *pAudioSnk = &ar->mDataSink.u.mSink;
340    SLresult result = SL_RESULT_SUCCESS;
341
342    const SLuint32 sourceLocatorType = *(SLuint32 *)pAudioSrc->pLocator;
343    const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator;
344
345    //  the following platform-independent fields have been initialized in CreateAudioRecorder()
346    //    ar->mNumChannels
347    //    ar->mSampleRateMilliHz
348
349    if ((SL_DATALOCATOR_IODEVICE == sourceLocatorType) &&
350            (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE == sinkLocatorType)) {
351        // microphone to simple buffer queue
352        ar->mAndroidObjType = AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE;
353        ar->mAudioRecord.clear();
354        ar->mCallbackProtector = new android::CallbackProtector();
355        ar->mRecordSource = AUDIO_SOURCE_DEFAULT;
356    } else {
357        result = SL_RESULT_CONTENT_UNSUPPORTED;
358    }
359
360    return result;
361}
362
363
364//-----------------------------------------------------------------------------
365SLresult android_audioRecorder_setConfig(CAudioRecorder* ar, const SLchar *configKey,
366        const void *pConfigValue, SLuint32 valueSize) {
367
368    SLresult result;
369
370    assert(NULL != ar && NULL != configKey && NULL != pConfigValue);
371    if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
372
373        // recording preset
374        if (KEY_RECORDING_PRESET_PARAMSIZE > valueSize) {
375            SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW);
376            result = SL_RESULT_BUFFER_INSUFFICIENT;
377        } else {
378            result = audioRecorder_setPreset(ar, *(SLuint32*)pConfigValue);
379        }
380
381    } else {
382        SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY);
383        result = SL_RESULT_PARAMETER_INVALID;
384    }
385
386    return result;
387}
388
389
390//-----------------------------------------------------------------------------
391SLresult android_audioRecorder_getConfig(CAudioRecorder* ar, const SLchar *configKey,
392        SLuint32* pValueSize, void *pConfigValue) {
393
394    SLresult result;
395
396    assert(NULL != ar && NULL != configKey && NULL != pValueSize);
397    if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
398
399        // recording preset
400        if (NULL == pConfigValue) {
401            result = SL_RESULT_SUCCESS;
402        } else if (KEY_RECORDING_PRESET_PARAMSIZE > *pValueSize) {
403            SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW);
404            result = SL_RESULT_BUFFER_INSUFFICIENT;
405        } else {
406            result = audioRecorder_getPreset(ar, (SLuint32*)pConfigValue);
407        }
408        *pValueSize = KEY_RECORDING_PRESET_PARAMSIZE;
409
410    } else {
411        SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY);
412        result = SL_RESULT_PARAMETER_INVALID;
413    }
414
415    return result;
416}
417
418
419//-----------------------------------------------------------------------------
420SLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async) {
421    SL_LOGV("android_audioRecorder_realize(%p) entering", ar);
422
423    SLresult result = SL_RESULT_SUCCESS;
424
425    // already checked in created and checkSourceSink
426    assert(ar->mDataSink.mLocator.mLocatorType == SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE);
427
428    const SLDataLocator_BufferQueue *dl_bq = &ar->mDataSink.mLocator.mBufferQueue;
429    const SLDataFormat_PCM *df_pcm = &ar->mDataSink.mFormat.mPCM;
430
431    //  the following platform-independent fields have been initialized in CreateAudioRecorder()
432    //    ar->mNumChannels
433    //    ar->mSampleRateMilliHz
434
435    uint32_t sampleRate = sles_to_android_sampleRate(df_pcm->samplesPerSec);
436
437    // currently nothing analogous to canUseFastTrack() for recording
438    audio_input_flags_t policy = AUDIO_INPUT_FLAG_FAST;
439
440    // initialize platform-specific CAudioRecorder fields
441    ar->mAudioRecord = new android::AudioRecord(
442            ar->mRecordSource,     // source
443            sampleRate,            // sample rate in Hertz
444            sles_to_android_sampleFormat(df_pcm),               // format
445            // FIXME ignores df_pcm->channelMask,
446            //       and assumes positional mask for mono or stereo,
447            //       or indexed mask for > 2 channels
448            audio_channel_in_mask_from_count(df_pcm->numChannels),
449            android::String16(),   // app ops
450            0,                     // frameCount
451            audioRecorder_callback,// callback_t
452            (void*)ar,             // user, callback data, here the AudioRecorder
453            0,                     // notificationFrames
454            0,                     // session ID
455            android::AudioRecord::TRANSFER_CALLBACK,
456                                   // transfer type
457            policy);               // audio_input_flags_t
458
459    android::status_t status = ar->mAudioRecord->initCheck();
460    if (android::NO_ERROR != status) {
461        SL_LOGE("android_audioRecorder_realize(%p) error creating AudioRecord object; status %d",
462                ar, status);
463        // FIXME should return a more specific result depending on status
464        result = SL_RESULT_CONTENT_UNSUPPORTED;
465        ar->mAudioRecord.clear();
466    }
467
468    return result;
469}
470
471
472//-----------------------------------------------------------------------------
473/**
474 * Called with a lock on AudioRecorder, and blocks until safe to destroy
475 */
476void android_audioRecorder_preDestroy(CAudioRecorder* ar) {
477    object_unlock_exclusive(&ar->mObject);
478    if (ar->mCallbackProtector != 0) {
479        ar->mCallbackProtector->requestCbExitAndWait();
480    }
481    object_lock_exclusive(&ar->mObject);
482}
483
484
485//-----------------------------------------------------------------------------
486void android_audioRecorder_destroy(CAudioRecorder* ar) {
487    SL_LOGV("android_audioRecorder_destroy(%p) entering", ar);
488
489    if (ar->mAudioRecord != 0) {
490        ar->mAudioRecord->stop();
491        ar->mAudioRecord.clear();
492    }
493    // explicit destructor
494    ar->mAudioRecord.~sp();
495    ar->mCallbackProtector.~sp();
496}
497
498
499//-----------------------------------------------------------------------------
500void android_audioRecorder_setRecordState(CAudioRecorder* ar, SLuint32 state) {
501    SL_LOGV("android_audioRecorder_setRecordState(%p, %u) entering", ar, state);
502
503    if (ar->mAudioRecord == 0) {
504        return;
505    }
506
507    switch (state) {
508     case SL_RECORDSTATE_STOPPED:
509         ar->mAudioRecord->stop();
510         break;
511     case SL_RECORDSTATE_PAUSED:
512         // Note that pausing is treated like stop as this implementation only records to a buffer
513         //  queue, so there is no notion of destination being "opened" or "closed" (See description
514         //  of SL_RECORDSTATE in specification)
515         ar->mAudioRecord->stop();
516         break;
517     case SL_RECORDSTATE_RECORDING:
518         ar->mAudioRecord->start();
519         break;
520     default:
521         break;
522     }
523
524}
525
526
527//-----------------------------------------------------------------------------
528void android_audioRecorder_useRecordEventMask(CAudioRecorder *ar) {
529    IRecord *pRecordItf = &ar->mRecord;
530    SLuint32 eventFlags = pRecordItf->mCallbackEventsMask;
531
532    if (ar->mAudioRecord == 0) {
533        return;
534    }
535
536    if ((eventFlags & SL_RECORDEVENT_HEADATMARKER) && (pRecordItf->mMarkerPosition != 0)) {
537        ar->mAudioRecord->setMarkerPosition((uint32_t)((((int64_t)pRecordItf->mMarkerPosition
538                * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000));
539    } else {
540        // clear marker
541        ar->mAudioRecord->setMarkerPosition(0);
542    }
543
544    if (eventFlags & SL_RECORDEVENT_HEADATNEWPOS) {
545        SL_LOGV("pos update period %d", pRecordItf->mPositionUpdatePeriod);
546         ar->mAudioRecord->setPositionUpdatePeriod(
547                (uint32_t)((((int64_t)pRecordItf->mPositionUpdatePeriod
548                * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000));
549    } else {
550        // clear periodic update
551        ar->mAudioRecord->setPositionUpdatePeriod(0);
552    }
553
554    if (eventFlags & SL_RECORDEVENT_HEADATLIMIT) {
555        // FIXME support SL_RECORDEVENT_HEADATLIMIT
556        SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADATLIMIT) on an "
557                    "SL_OBJECTID_AUDIORECORDER to be implemented ]");
558    }
559
560    if (eventFlags & SL_RECORDEVENT_HEADMOVING) {
561        // FIXME support SL_RECORDEVENT_HEADMOVING
562        SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADMOVING) on an "
563                "SL_OBJECTID_AUDIORECORDER to be implemented ]");
564    }
565
566    if (eventFlags & SL_RECORDEVENT_BUFFER_FULL) {
567        // nothing to do for SL_RECORDEVENT_BUFFER_FULL since this will not be encountered on
568        // recording to buffer queues
569    }
570
571    if (eventFlags & SL_RECORDEVENT_HEADSTALLED) {
572        // nothing to do for SL_RECORDEVENT_HEADSTALLED, callback event will be checked against mask
573        // when AudioRecord::EVENT_OVERRUN is encountered
574
575    }
576
577}
578
579
580//-----------------------------------------------------------------------------
581void android_audioRecorder_getPosition(CAudioRecorder *ar, SLmillisecond *pPosMsec) {
582    if ((NULL == ar) || (ar->mAudioRecord == 0)) {
583        *pPosMsec = 0;
584    } else {
585        uint32_t positionInFrames;
586        ar->mAudioRecord->getPosition(&positionInFrames);
587        if (ar->mSampleRateMilliHz == UNKNOWN_SAMPLERATE) {
588            *pPosMsec = 0;
589        } else {
590            *pPosMsec = ((int64_t)positionInFrames * 1000) /
591                    sles_to_android_sampleRate(ar->mSampleRateMilliHz);
592        }
593    }
594}
595