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