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 <system/audio.h>
22
23 // use this flag to dump all recorded audio into a file
24 //#define MONITOR_RECORDING
25 #ifdef MONITOR_RECORDING
26 #define MONITOR_TARGET "/sdcard/monitor.raw"
27 #include <stdio.h>
28 static FILE* gMonitorFp = NULL;
29 #endif
30
31
32 #define KEY_RECORDING_SOURCE_PARAMSIZE sizeof(SLuint32)
33 #define KEY_RECORDING_PRESET_PARAMSIZE sizeof(SLuint32)
34
35 //-----------------------------------------------------------------------------
36 // Internal utility functions
37 //----------------------------
38
audioRecorder_setPreset(CAudioRecorder * ar,SLuint32 recordPreset)39 SLresult audioRecorder_setPreset(CAudioRecorder* ar, SLuint32 recordPreset) {
40 SLresult result = SL_RESULT_SUCCESS;
41
42 audio_source_t newRecordSource = AUDIO_SOURCE_DEFAULT;
43 switch (recordPreset) {
44 case SL_ANDROID_RECORDING_PRESET_GENERIC:
45 newRecordSource = AUDIO_SOURCE_DEFAULT;
46 break;
47 case SL_ANDROID_RECORDING_PRESET_CAMCORDER:
48 newRecordSource = AUDIO_SOURCE_CAMCORDER;
49 break;
50 case SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION:
51 newRecordSource = AUDIO_SOURCE_VOICE_RECOGNITION;
52 break;
53 case SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION:
54 newRecordSource = AUDIO_SOURCE_VOICE_COMMUNICATION;
55 break;
56 case SL_ANDROID_RECORDING_PRESET_NONE:
57 // it is an error to set preset "none"
58 default:
59 SL_LOGE(ERROR_RECORDERPRESET_SET_UNKNOWN_PRESET);
60 result = SL_RESULT_PARAMETER_INVALID;
61 }
62
63 // recording preset needs to be set before the object is realized
64 // (ap->mAudioRecord is supposed to be NULL until then)
65 if (SL_OBJECT_STATE_UNREALIZED != ar->mObject.mState) {
66 SL_LOGE(ERROR_RECORDERPRESET_REALIZED);
67 result = SL_RESULT_PRECONDITIONS_VIOLATED;
68 } else {
69 ar->mRecordSource = newRecordSource;
70 }
71
72 return result;
73 }
74
75
audioRecorder_getPreset(CAudioRecorder * ar,SLuint32 * pPreset)76 SLresult audioRecorder_getPreset(CAudioRecorder* ar, SLuint32* pPreset) {
77 SLresult result = SL_RESULT_SUCCESS;
78
79 switch (ar->mRecordSource) {
80 case AUDIO_SOURCE_DEFAULT:
81 case AUDIO_SOURCE_MIC:
82 *pPreset = SL_ANDROID_RECORDING_PRESET_GENERIC;
83 break;
84 case AUDIO_SOURCE_VOICE_UPLINK:
85 case AUDIO_SOURCE_VOICE_DOWNLINK:
86 case AUDIO_SOURCE_VOICE_CALL:
87 *pPreset = SL_ANDROID_RECORDING_PRESET_NONE;
88 break;
89 case AUDIO_SOURCE_VOICE_RECOGNITION:
90 *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
91 break;
92 case AUDIO_SOURCE_CAMCORDER:
93 *pPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER;
94 break;
95 case AUDIO_SOURCE_VOICE_COMMUNICATION:
96 *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
97 break;
98 default:
99 *pPreset = SL_ANDROID_RECORDING_PRESET_NONE;
100 result = SL_RESULT_INTERNAL_ERROR;
101 break;
102 }
103
104 return result;
105 }
106
107
audioRecorder_handleNewPos_lockRecord(CAudioRecorder * ar)108 void audioRecorder_handleNewPos_lockRecord(CAudioRecorder* ar) {
109 //SL_LOGV("received event EVENT_NEW_POS from AudioRecord");
110 slRecordCallback callback = NULL;
111 void* callbackPContext = NULL;
112
113 interface_lock_shared(&ar->mRecord);
114 callback = ar->mRecord.mCallback;
115 callbackPContext = ar->mRecord.mContext;
116 interface_unlock_shared(&ar->mRecord);
117
118 if (NULL != callback) {
119 // getting this event implies SL_RECORDEVENT_HEADATNEWPOS was set in the event mask
120 (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATNEWPOS);
121 }
122 }
123
124
audioRecorder_handleMarker_lockRecord(CAudioRecorder * ar)125 void audioRecorder_handleMarker_lockRecord(CAudioRecorder* ar) {
126 //SL_LOGV("received event EVENT_MARKER from AudioRecord");
127 slRecordCallback callback = NULL;
128 void* callbackPContext = NULL;
129
130 interface_lock_shared(&ar->mRecord);
131 callback = ar->mRecord.mCallback;
132 callbackPContext = ar->mRecord.mContext;
133 interface_unlock_shared(&ar->mRecord);
134
135 if (NULL != callback) {
136 // getting this event implies SL_RECORDEVENT_HEADATMARKER was set in the event mask
137 (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATMARKER);
138 }
139 }
140
141
audioRecorder_handleOverrun_lockRecord(CAudioRecorder * ar)142 void audioRecorder_handleOverrun_lockRecord(CAudioRecorder* ar) {
143 //SL_LOGV("received event EVENT_OVERRUN from AudioRecord");
144 slRecordCallback callback = NULL;
145 void* callbackPContext = NULL;
146
147 interface_lock_shared(&ar->mRecord);
148 if (ar->mRecord.mCallbackEventsMask & SL_RECORDEVENT_HEADSTALLED) {
149 callback = ar->mRecord.mCallback;
150 callbackPContext = ar->mRecord.mContext;
151 }
152 interface_unlock_shared(&ar->mRecord);
153
154 if (NULL != callback) {
155 (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADSTALLED);
156 }
157 }
158
159 //-----------------------------------------------------------------------------
android_audioRecorder_checkSourceSinkSupport(CAudioRecorder * ar)160 SLresult android_audioRecorder_checkSourceSinkSupport(CAudioRecorder* ar) {
161
162 const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource;
163 const SLDataSink *pAudioSnk = &ar->mDataSink.u.mSink;
164
165 // Sink check:
166 // only buffer queue sinks are supported, regardless of the data source
167 if (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE != *(SLuint32 *)pAudioSnk->pLocator) {
168 SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE);
169 return SL_RESULT_PARAMETER_INVALID;
170 } else {
171 // only PCM buffer queues are supported
172 SLuint32 formatType = *(SLuint32 *)pAudioSnk->pFormat;
173 if (SL_DATAFORMAT_PCM == formatType) {
174 SLDataFormat_PCM *df_pcm = (SLDataFormat_PCM *)ar->mDataSink.u.mSink.pFormat;
175 ar->mSampleRateMilliHz = df_pcm->samplesPerSec;
176 ar->mNumChannels = df_pcm->numChannels;
177 SL_LOGV("AudioRecorder requested sample rate = %u mHz, %u channel(s)",
178 ar->mSampleRateMilliHz, ar->mNumChannels);
179 }
180 else {
181 SL_LOGE(ERROR_RECORDER_SINK_FORMAT_MUST_BE_PCM);
182 return SL_RESULT_PARAMETER_INVALID;
183 }
184 }
185
186 // Source check:
187 // only input device sources are supported
188 // check it's an IO device
189 if (SL_DATALOCATOR_IODEVICE != *(SLuint32 *)pAudioSrc->pLocator) {
190 SL_LOGE(ERROR_RECORDER_SOURCE_MUST_BE_IODEVICE);
191 return SL_RESULT_PARAMETER_INVALID;
192 } else {
193
194 // check it's an input device
195 SLDataLocator_IODevice *dl_iod = (SLDataLocator_IODevice *) pAudioSrc->pLocator;
196 if (SL_IODEVICE_AUDIOINPUT != dl_iod->deviceType) {
197 SL_LOGE(ERROR_RECORDER_IODEVICE_MUST_BE_AUDIOINPUT);
198 return SL_RESULT_PARAMETER_INVALID;
199 }
200
201 // check it's the default input device, others aren't supported here
202 if (SL_DEFAULTDEVICEID_AUDIOINPUT != dl_iod->deviceID) {
203 SL_LOGE(ERROR_RECORDER_INPUT_ID_MUST_BE_DEFAULT);
204 return SL_RESULT_PARAMETER_INVALID;
205 }
206 }
207
208 return SL_RESULT_SUCCESS;
209 }
210 //-----------------------------------------------------------------------------
audioRecorder_callback(int event,void * user,void * info)211 static void audioRecorder_callback(int event, void* user, void *info) {
212 //SL_LOGV("audioRecorder_callback(%d, %p, %p) entering", event, user, info);
213
214 CAudioRecorder *ar = (CAudioRecorder *)user;
215 void * callbackPContext = NULL;
216
217 switch(event) {
218 case android::AudioRecord::EVENT_MORE_DATA: {
219 slBufferQueueCallback callback = NULL;
220 android::AudioRecord::Buffer* pBuff = (android::AudioRecord::Buffer*)info;
221
222 // push data to the buffer queue
223 interface_lock_exclusive(&ar->mBufferQueue);
224
225 if (ar->mBufferQueue.mState.count != 0) {
226 assert(ar->mBufferQueue.mFront != ar->mBufferQueue.mRear);
227
228 BufferHeader *oldFront = ar->mBufferQueue.mFront;
229 BufferHeader *newFront = &oldFront[1];
230
231 // FIXME handle 8bit based on buffer format
232 short *pDest = (short*)((char *)oldFront->mBuffer + ar->mBufferQueue.mSizeConsumed);
233 if (ar->mBufferQueue.mSizeConsumed + pBuff->size < oldFront->mSize) {
234 // can't consume the whole or rest of the buffer in one shot
235 ar->mBufferQueue.mSizeConsumed += pBuff->size;
236 // leave pBuff->size untouched
237 // consume data
238 // FIXME can we avoid holding the lock during the copy?
239 memcpy (pDest, pBuff->i16, pBuff->size);
240 #ifdef MONITOR_RECORDING
241 if (NULL != gMonitorFp) { fwrite(pBuff->i16, pBuff->size, 1, gMonitorFp); }
242 #endif
243 } else {
244 // finish pushing the buffer or push the buffer in one shot
245 pBuff->size = oldFront->mSize - ar->mBufferQueue.mSizeConsumed;
246 ar->mBufferQueue.mSizeConsumed = 0;
247 if (newFront == &ar->mBufferQueue.mArray[ar->mBufferQueue.mNumBuffers + 1]) {
248 newFront = ar->mBufferQueue.mArray;
249 }
250 ar->mBufferQueue.mFront = newFront;
251
252 ar->mBufferQueue.mState.count--;
253 ar->mBufferQueue.mState.playIndex++;
254 // consume data
255 // FIXME can we avoid holding the lock during the copy?
256 memcpy (pDest, pBuff->i16, pBuff->size);
257 #ifdef MONITOR_RECORDING
258 if (NULL != gMonitorFp) { fwrite(pBuff->i16, pBuff->size, 1, gMonitorFp); }
259 #endif
260 // data has been copied to the buffer, and the buffer queue state has been updated
261 // we will notify the client if applicable
262 callback = ar->mBufferQueue.mCallback;
263 // save callback data
264 callbackPContext = ar->mBufferQueue.mContext;
265 }
266 } else {
267 // no destination to push the data
268 pBuff->size = 0;
269 }
270
271 interface_unlock_exclusive(&ar->mBufferQueue);
272 // notify client
273 if (NULL != callback) {
274 (*callback)(&ar->mBufferQueue.mItf, callbackPContext);
275 }
276 }
277 break;
278
279 case android::AudioRecord::EVENT_OVERRUN:
280 audioRecorder_handleOverrun_lockRecord(ar);
281 break;
282
283 case android::AudioRecord::EVENT_MARKER:
284 audioRecorder_handleMarker_lockRecord(ar);
285 break;
286
287 case android::AudioRecord::EVENT_NEW_POS:
288 audioRecorder_handleNewPos_lockRecord(ar);
289 break;
290
291 }
292 }
293
294
295 //-----------------------------------------------------------------------------
android_audioRecorder_create(CAudioRecorder * ar)296 SLresult android_audioRecorder_create(CAudioRecorder* ar) {
297 SL_LOGV("android_audioRecorder_create(%p) entering", ar);
298
299 const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource;
300 const SLDataSink *pAudioSnk = &ar->mDataSink.u.mSink;
301 SLresult result = SL_RESULT_SUCCESS;
302
303 const SLuint32 sourceLocatorType = *(SLuint32 *)pAudioSrc->pLocator;
304 const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator;
305
306 // the following platform-independent fields have been initialized in CreateAudioRecorder()
307 // ar->mNumChannels
308 // ar->mSampleRateMilliHz
309
310 if ((SL_DATALOCATOR_IODEVICE == sourceLocatorType) &&
311 (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE == sinkLocatorType)) {
312 // microphone to simple buffer queue
313 ar->mAndroidObjType = AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE;
314 ar->mAudioRecord = NULL;
315 ar->mRecordSource = AUDIO_SOURCE_DEFAULT;
316 } else {
317 result = SL_RESULT_CONTENT_UNSUPPORTED;
318 }
319
320 return result;
321 }
322
323
324 //-----------------------------------------------------------------------------
android_audioRecorder_setConfig(CAudioRecorder * ar,const SLchar * configKey,const void * pConfigValue,SLuint32 valueSize)325 SLresult android_audioRecorder_setConfig(CAudioRecorder* ar, const SLchar *configKey,
326 const void *pConfigValue, SLuint32 valueSize) {
327
328 SLresult result;
329
330 assert(NULL != ar && NULL != configKey && NULL != pConfigValue);
331 if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
332
333 // recording preset
334 if (KEY_RECORDING_PRESET_PARAMSIZE > valueSize) {
335 SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW);
336 result = SL_RESULT_BUFFER_INSUFFICIENT;
337 } else {
338 result = audioRecorder_setPreset(ar, *(SLuint32*)pConfigValue);
339 }
340
341 } else {
342 SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY);
343 result = SL_RESULT_PARAMETER_INVALID;
344 }
345
346 return result;
347 }
348
349
350 //-----------------------------------------------------------------------------
android_audioRecorder_getConfig(CAudioRecorder * ar,const SLchar * configKey,SLuint32 * pValueSize,void * pConfigValue)351 SLresult android_audioRecorder_getConfig(CAudioRecorder* ar, const SLchar *configKey,
352 SLuint32* pValueSize, void *pConfigValue) {
353
354 SLresult result;
355
356 assert(NULL != ar && NULL != configKey && NULL != pValueSize);
357 if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
358
359 // recording preset
360 if (NULL == pConfigValue) {
361 result = SL_RESULT_SUCCESS;
362 } else if (KEY_RECORDING_PRESET_PARAMSIZE > *pValueSize) {
363 SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW);
364 result = SL_RESULT_BUFFER_INSUFFICIENT;
365 } else {
366 result = audioRecorder_getPreset(ar, (SLuint32*)pConfigValue);
367 }
368 *pValueSize = KEY_RECORDING_PRESET_PARAMSIZE;
369
370 } else {
371 SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY);
372 result = SL_RESULT_PARAMETER_INVALID;
373 }
374
375 return result;
376 }
377
378
379 //-----------------------------------------------------------------------------
android_audioRecorder_realize(CAudioRecorder * ar,SLboolean async)380 SLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async) {
381 SL_LOGV("android_audioRecorder_realize(%p) entering", ar);
382
383 SLresult result = SL_RESULT_SUCCESS;
384
385 // initialize platform-independent CAudioRecorder fields
386 if (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE != ar->mDataSink.mLocator.mLocatorType) {
387 SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE);
388 return SL_RESULT_CONTENT_UNSUPPORTED;
389 }
390 // the following platform-independent fields have been initialized in CreateAudioRecorder()
391 // ar->mNumChannels
392 // ar->mSampleRateMilliHz
393
394 SL_LOGV("new AudioRecord %u channels, %u mHz", ar->mNumChannels, ar->mSampleRateMilliHz);
395
396 // initialize platform-specific CAudioRecorder fields
397 ar->mAudioRecord = new android::AudioRecord();
398 ar->mAudioRecord->set(ar->mRecordSource, // source
399 sles_to_android_sampleRate(ar->mSampleRateMilliHz), // sample rate in Hertz
400 AUDIO_FORMAT_PCM_16_BIT, //FIXME use format from buffer queue sink
401 sles_to_android_channelMaskIn(ar->mNumChannels, 0 /*no channel mask*/),
402 // channel config
403 0, //frameCount min
404 audioRecorder_callback,// callback_t
405 (void*)ar, // user, callback data, here the AudioRecorder
406 0, // notificationFrames
407 false); // threadCanCallJava, note: this will prevent direct Java
408 // callbacks, but we don't want them in the recording loop
409
410 if (android::NO_ERROR != ar->mAudioRecord->initCheck()) {
411 SL_LOGE("android_audioRecorder_realize(%p) error creating AudioRecord object", ar);
412 result = SL_RESULT_CONTENT_UNSUPPORTED;
413 }
414
415 #ifdef MONITOR_RECORDING
416 gMonitorFp = fopen(MONITOR_TARGET, "w");
417 if (NULL == gMonitorFp) { SL_LOGE("error opening %s", MONITOR_TARGET); }
418 else { SL_LOGE("recording to %s", MONITOR_TARGET); } // SL_LOGE so it's always displayed
419 #endif
420
421 return result;
422 }
423
424
425 //-----------------------------------------------------------------------------
android_audioRecorder_destroy(CAudioRecorder * ar)426 void android_audioRecorder_destroy(CAudioRecorder* ar) {
427 SL_LOGV("android_audioRecorder_destroy(%p) entering", ar);
428
429 if (NULL != ar->mAudioRecord) {
430 ar->mAudioRecord->stop();
431 delete ar->mAudioRecord;
432 ar->mAudioRecord = NULL;
433 }
434
435 #ifdef MONITOR_RECORDING
436 if (NULL != gMonitorFp) {
437 fclose(gMonitorFp);
438 gMonitorFp = NULL;
439 }
440 #endif
441 }
442
443
444 //-----------------------------------------------------------------------------
android_audioRecorder_setRecordState(CAudioRecorder * ar,SLuint32 state)445 void android_audioRecorder_setRecordState(CAudioRecorder* ar, SLuint32 state) {
446 SL_LOGV("android_audioRecorder_setRecordState(%p, %u) entering", ar, state);
447
448 if (NULL == ar->mAudioRecord) {
449 return;
450 }
451
452 switch (state) {
453 case SL_RECORDSTATE_STOPPED:
454 ar->mAudioRecord->stop();
455 break;
456 case SL_RECORDSTATE_PAUSED:
457 // Note that pausing is treated like stop as this implementation only records to a buffer
458 // queue, so there is no notion of destination being "opened" or "closed" (See description
459 // of SL_RECORDSTATE in specification)
460 ar->mAudioRecord->stop();
461 break;
462 case SL_RECORDSTATE_RECORDING:
463 ar->mAudioRecord->start();
464 break;
465 default:
466 break;
467 }
468
469 }
470
471
472 //-----------------------------------------------------------------------------
android_audioRecorder_useRecordEventMask(CAudioRecorder * ar)473 void android_audioRecorder_useRecordEventMask(CAudioRecorder *ar) {
474 IRecord *pRecordItf = &ar->mRecord;
475 SLuint32 eventFlags = pRecordItf->mCallbackEventsMask;
476
477 if (NULL == ar->mAudioRecord) {
478 return;
479 }
480
481 if ((eventFlags & SL_RECORDEVENT_HEADATMARKER) && (pRecordItf->mMarkerPosition != 0)) {
482 ar->mAudioRecord->setMarkerPosition((uint32_t)((((int64_t)pRecordItf->mMarkerPosition
483 * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000));
484 } else {
485 // clear marker
486 ar->mAudioRecord->setMarkerPosition(0);
487 }
488
489 if (eventFlags & SL_RECORDEVENT_HEADATNEWPOS) {
490 SL_LOGV("pos update period %d", pRecordItf->mPositionUpdatePeriod);
491 ar->mAudioRecord->setPositionUpdatePeriod(
492 (uint32_t)((((int64_t)pRecordItf->mPositionUpdatePeriod
493 * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000));
494 } else {
495 // clear periodic update
496 ar->mAudioRecord->setPositionUpdatePeriod(0);
497 }
498
499 if (eventFlags & SL_RECORDEVENT_HEADATLIMIT) {
500 // FIXME support SL_RECORDEVENT_HEADATLIMIT
501 SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADATLIMIT) on an "
502 "SL_OBJECTID_AUDIORECORDER to be implemented ]");
503 }
504
505 if (eventFlags & SL_RECORDEVENT_HEADMOVING) {
506 // FIXME support SL_RECORDEVENT_HEADMOVING
507 SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADMOVING) on an "
508 "SL_OBJECTID_AUDIORECORDER to be implemented ]");
509 }
510
511 if (eventFlags & SL_RECORDEVENT_BUFFER_FULL) {
512 // nothing to do for SL_RECORDEVENT_BUFFER_FULL since this will not be encountered on
513 // recording to buffer queues
514 }
515
516 if (eventFlags & SL_RECORDEVENT_HEADSTALLED) {
517 // nothing to do for SL_RECORDEVENT_HEADSTALLED, callback event will be checked against mask
518 // when AudioRecord::EVENT_OVERRUN is encountered
519
520 }
521
522 }
523
524
525 //-----------------------------------------------------------------------------
android_audioRecorder_getPosition(CAudioRecorder * ar,SLmillisecond * pPosMsec)526 void android_audioRecorder_getPosition(CAudioRecorder *ar, SLmillisecond *pPosMsec) {
527 if ((NULL == ar) || (NULL == ar->mAudioRecord)) {
528 *pPosMsec = 0;
529 } else {
530 uint32_t positionInFrames;
531 ar->mAudioRecord->getPosition(&positionInFrames);
532 if (ar->mSampleRateMilliHz == UNKNOWN_SAMPLERATE) {
533 *pPosMsec = 0;
534 } else {
535 *pPosMsec = ((int64_t)positionInFrames * 1000) /
536 sles_to_android_sampleRate(ar->mSampleRateMilliHz);
537 }
538 }
539 }
540