AudioRecorder_to_android.cpp revision b05ea38e5131001884aa226f90fd50cf594a23f3
13af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi/*
23af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * Copyright (C) 2010 The Android Open Source Project
33af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi *
43af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License");
53af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * you may not use this file except in compliance with the License.
63af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * You may obtain a copy of the License at
73af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi *
83af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi *      http://www.apache.org/licenses/LICENSE-2.0
93af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi *
103af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software
113af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS,
123af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * See the License for the specific language governing permissions and
143af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi * limitations under the License.
153af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi */
163af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
173af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
183af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#include "sles_allinclusive.h"
1975e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi#include "android_prompts.h"
203af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
213af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi// use this flag to dump all recorded audio into a file
223af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//#define MONITOR_RECORDING
233af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#ifdef MONITOR_RECORDING
243af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#define MONITOR_TARGET "/sdcard/monitor.raw"
253af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#include <stdio.h>
263af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivistatic FILE* gMonitorFp = NULL;
273af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#endif
283af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
29b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
30b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi#define KEY_RECORDING_SOURCE_PARAMSIZE  sizeof(SLuint32)
31b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi#define KEY_RECORDING_PRESET_PARAMSIZE  sizeof(SLuint32)
32b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
33b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi//-----------------------------------------------------------------------------
34b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi// Internal utility functions
35b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi//----------------------------
36b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
37b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel TriviSLresult audioRecorder_setPreset(CAudioRecorder* ar, SLuint32 recordPreset) {
38b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
39b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
4075e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi    int newRecordSource = android::AUDIO_SOURCE_DEFAULT;
41b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    switch (recordPreset) {
42e214a8c49938e7356943b59db53474e5fc3ae07cJean-Michel Trivi    case SL_ANDROID_RECORDING_PRESET_GENERIC:
4375e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        newRecordSource = android::AUDIO_SOURCE_DEFAULT;
44b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
45b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case SL_ANDROID_RECORDING_PRESET_CAMCORDER:
4675e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        newRecordSource = android::AUDIO_SOURCE_CAMCORDER;
47b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
48b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION:
4975e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        newRecordSource = android::AUDIO_SOURCE_VOICE_RECOGNITION;
50b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
51a4b4d478171631eaa97e933eb46c1ff01bd04daaJean-Michel Trivi    case SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION:
52a4b4d478171631eaa97e933eb46c1ff01bd04daaJean-Michel Trivi        newRecordSource = android::AUDIO_SOURCE_VOICE_COMMUNICATION;
53a4b4d478171631eaa97e933eb46c1ff01bd04daaJean-Michel Trivi        break;
54b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case SL_ANDROID_RECORDING_PRESET_NONE:
55b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        // it is an error to set preset "none"
56b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    default:
5775e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_RECORDERPRESET_SET_UNKNOWN_PRESET);
58b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_PARAMETER_INVALID;
59b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    }
60b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
6175e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi    // recording preset needs to be set before the object is realized
6275e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi    // (ap->mAudioRecord is supposed to be NULL until then)
635f71e35da153d194d805e030ab38935599e065d2Jean-Michel Trivi    if (SL_OBJECT_STATE_UNREALIZED != ar->mObject.mState) {
6475e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_RECORDERPRESET_REALIZED);
6575e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        result = SL_RESULT_PRECONDITIONS_VIOLATED;
6675e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi    } else {
6775e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        ar->mRecordSource = newRecordSource;
6875e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi    }
6975e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi
70b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    return result;
71b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi}
72b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
73b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
74b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel TriviSLresult audioRecorder_getPreset(CAudioRecorder* ar, SLuint32* pPreset) {
75b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
76b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
77b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    switch (ar->mRecordSource) {
78b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_DEFAULT:
79b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_MIC:
80e214a8c49938e7356943b59db53474e5fc3ae07cJean-Michel Trivi        *pPreset = SL_ANDROID_RECORDING_PRESET_GENERIC;
81b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
82b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_VOICE_UPLINK:
83b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_VOICE_DOWNLINK:
84b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_VOICE_CALL:
85b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        *pPreset = SL_ANDROID_RECORDING_PRESET_NONE;
86b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
87b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_VOICE_RECOGNITION:
88b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
89b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
90b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    case android::AUDIO_SOURCE_CAMCORDER:
91b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        *pPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER;
92b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
93a4b4d478171631eaa97e933eb46c1ff01bd04daaJean-Michel Trivi    case android::AUDIO_SOURCE_VOICE_COMMUNICATION:
94a4b4d478171631eaa97e933eb46c1ff01bd04daaJean-Michel Trivi        *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
95a4b4d478171631eaa97e933eb46c1ff01bd04daaJean-Michel Trivi        break;
96b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    default:
97b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        *pPreset = SL_ANDROID_RECORDING_PRESET_NONE;
98b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_INTERNAL_ERROR;
99b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        break;
100b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    }
101b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
102b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    return result;
103b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi}
104b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
1053af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
1063b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivivoid audioRecorder_handleNewPos_lockRecord(CAudioRecorder* ar) {
1073b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    //SL_LOGV("received event EVENT_NEW_POS from AudioRecord");
1083b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    slRecordCallback callback = NULL;
1093b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    void* callbackPContext = NULL;
1103b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1113b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    interface_lock_shared(&ar->mRecord);
1123b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    callback = ar->mRecord.mCallback;
1133b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    callbackPContext = ar->mRecord.mContext;
1143b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    interface_unlock_shared(&ar->mRecord);
1153b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1163b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (NULL != callback) {
1173b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        // getting this event implies SL_RECORDEVENT_HEADATNEWPOS was set in the event mask
1183b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATNEWPOS);
1193b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
1203b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi}
1213b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1223b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1233b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivivoid audioRecorder_handleMarker_lockRecord(CAudioRecorder* ar) {
1243b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    //SL_LOGV("received event EVENT_MARKER from AudioRecord");
1253b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    slRecordCallback callback = NULL;
1263b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    void* callbackPContext = NULL;
1273b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1283b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    interface_lock_shared(&ar->mRecord);
1293b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    callback = ar->mRecord.mCallback;
1303b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    callbackPContext = ar->mRecord.mContext;
1313b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    interface_unlock_shared(&ar->mRecord);
1323b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1333b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (NULL != callback) {
1343b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        // getting this event implies SL_RECORDEVENT_HEADATMARKER was set in the event mask
1353b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATMARKER);
1363b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
1373b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi}
1383b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1393b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1403b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivivoid audioRecorder_handleOverrun_lockRecord(CAudioRecorder* ar) {
1413b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    //SL_LOGV("received event EVENT_OVERRUN from AudioRecord");
1423b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    slRecordCallback callback = NULL;
1433b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    void* callbackPContext = NULL;
1443b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1453b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    interface_lock_shared(&ar->mRecord);
146f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi    if (ar->mRecord.mCallbackEventsMask & SL_RECORDEVENT_HEADSTALLED) {
1473b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        callback = ar->mRecord.mCallback;
1483b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        callbackPContext = ar->mRecord.mContext;
1493b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
1503b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    interface_unlock_shared(&ar->mRecord);
1513b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1523b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (NULL != callback) {
153f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi        (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADSTALLED);
1543b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
1553b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi}
1563b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
1573af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//-----------------------------------------------------------------------------
1583af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel TriviSLresult android_audioRecorder_checkSourceSinkSupport(CAudioRecorder* ar) {
1593af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
1603af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource;
1613af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    const SLDataSink   *pAudioSnk = &ar->mDataSink.u.mSink;
1623af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
1633af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    // Sink check:
1643af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    // only buffer queue sinks are supported, regardless of the data source
16501e9f5fa4698856f92bcfd88188ee4c8397b22dbGlenn Kasten    if (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE != *(SLuint32 *)pAudioSnk->pLocator) {
16601e9f5fa4698856f92bcfd88188ee4c8397b22dbGlenn Kasten        SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE);
1673af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
168712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi    } else {
169712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        // only PCM buffer queues are supported
170712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        SLuint32 formatType = *(SLuint32 *)pAudioSnk->pFormat;
171712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        if (SL_DATAFORMAT_PCM == formatType) {
172712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi            SLDataFormat_PCM *df_pcm = (SLDataFormat_PCM *)ar->mDataSink.u.mSink.pFormat;
173712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi            ar->mSampleRateMilliHz = df_pcm->samplesPerSec;
174712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi            ar->mNumChannels = df_pcm->numChannels;
175712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi            SL_LOGV("AudioRecorder requested sample rate = %lumHz, %u channel(s)",
176712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi                    ar->mSampleRateMilliHz, ar->mNumChannels);
177712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        }
178712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        else {
17975e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            SL_LOGE(ERROR_RECORDER_SINK_FORMAT_MUST_BE_PCM);
180712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi            return SL_RESULT_PARAMETER_INVALID;
181712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        }
1823af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    }
1833af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
1843af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    // Source check:
1853af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    // only input device sources are supported
1863af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    // check it's an IO device
1873af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    if (SL_DATALOCATOR_IODEVICE != *(SLuint32 *)pAudioSrc->pLocator) {
18875e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_RECORDER_SOURCE_MUST_BE_IODEVICE);
1893af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        return SL_RESULT_PARAMETER_INVALID;
1903af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    } else {
1913af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
1923af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        // check it's an input device
1933af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        SLDataLocator_IODevice *dl_iod =  (SLDataLocator_IODevice *) pAudioSrc->pLocator;
1943af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        if (SL_IODEVICE_AUDIOINPUT != dl_iod->deviceType) {
19575e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            SL_LOGE(ERROR_RECORDER_IODEVICE_MUST_BE_AUDIOINPUT);
1963af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            return SL_RESULT_PARAMETER_INVALID;
1973af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        }
1983af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
1993af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        // check it's the default input device, others aren't supported here
2003af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        if (SL_DEFAULTDEVICEID_AUDIOINPUT != dl_iod->deviceID) {
20175e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            SL_LOGE(ERROR_RECORDER_INPUT_ID_MUST_BE_DEFAULT);
2023af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            return SL_RESULT_PARAMETER_INVALID;
2033af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        }
2043af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    }
2053af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2063af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    return SL_RESULT_SUCCESS;
2073af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi}
2083af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//-----------------------------------------------------------------------------
2093af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivistatic void audioRecorder_callback(int event, void* user, void *info) {
2103af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    //SL_LOGV("audioRecorder_callback(%d, %p, %p) entering", event, user, info);
2113af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2123af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    CAudioRecorder *ar = (CAudioRecorder *)user;
2133af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    void * callbackPContext = NULL;
2143af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2153af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    switch(event) {
2163af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    case android::AudioRecord::EVENT_MORE_DATA: {
2173af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        slBufferQueueCallback callback = NULL;
2183af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        android::AudioRecord::Buffer* pBuff = (android::AudioRecord::Buffer*)info;
2193af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2203af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        // push data to the buffer queue
2213af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        interface_lock_exclusive(&ar->mBufferQueue);
2223af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2233af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        if (ar->mBufferQueue.mState.count != 0) {
2243af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            assert(ar->mBufferQueue.mFront != ar->mBufferQueue.mRear);
2253af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2263af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            BufferHeader *oldFront = ar->mBufferQueue.mFront;
2273af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            BufferHeader *newFront = &oldFront[1];
2283af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2293af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            // FIXME handle 8bit based on buffer format
2303af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            short *pDest = (short*)((char *)oldFront->mBuffer + ar->mBufferQueue.mSizeConsumed);
2313af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            if (ar->mBufferQueue.mSizeConsumed + pBuff->size < oldFront->mSize) {
2323af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // can't consume the whole or rest of the buffer in one shot
2333af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                ar->mBufferQueue.mSizeConsumed += pBuff->size;
2343af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // leave pBuff->size untouched
2353af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // consume data
2363af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // FIXME can we avoid holding the lock during the copy?
2373af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                memcpy (pDest, pBuff->i16, pBuff->size);
2383af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#ifdef MONITOR_RECORDING
2393af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                if (NULL != gMonitorFp) { fwrite(pBuff->i16, pBuff->size, 1, gMonitorFp); }
2403af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#endif
2413af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            } else {
2423af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // finish pushing the buffer or push the buffer in one shot
2433af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                pBuff->size = oldFront->mSize - ar->mBufferQueue.mSizeConsumed;
2443af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                ar->mBufferQueue.mSizeConsumed = 0;
2453af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                if (newFront ==  &ar->mBufferQueue.mArray[ar->mBufferQueue.mNumBuffers + 1]) {
2463af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                    newFront = ar->mBufferQueue.mArray;
2473af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                }
2483af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                ar->mBufferQueue.mFront = newFront;
2493af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2503af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                ar->mBufferQueue.mState.count--;
2513af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                ar->mBufferQueue.mState.playIndex++;
2523af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // consume data
2533af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // FIXME can we avoid holding the lock during the copy?
2543af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                memcpy (pDest, pBuff->i16, pBuff->size);
2553af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#ifdef MONITOR_RECORDING
2563af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                if (NULL != gMonitorFp) { fwrite(pBuff->i16, pBuff->size, 1, gMonitorFp); }
2573af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#endif
2583af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // data has been copied to the buffer, and the buffer queue state has been updated
2593af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // we will notify the client if applicable
2603af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                callback = ar->mBufferQueue.mCallback;
2613af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                // save callback data
2623af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                callbackPContext = ar->mBufferQueue.mContext;
2633af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            }
2643af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        } else {
2653af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            // no destination to push the data
2663af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            pBuff->size = 0;
2673af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        }
2683af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2693af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        interface_unlock_exclusive(&ar->mBufferQueue);
2703af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        // notify client
2713af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        if (NULL != callback) {
2723af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            (*callback)(&ar->mBufferQueue.mItf, callbackPContext);
2733af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        }
2743af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        }
2753af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        break;
2763af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2773b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    case android::AudioRecord::EVENT_OVERRUN:
2783b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        audioRecorder_handleOverrun_lockRecord(ar);
2793b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        break;
2803b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
2813af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    case android::AudioRecord::EVENT_MARKER:
2823b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        audioRecorder_handleMarker_lockRecord(ar);
2833af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        break;
2843af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2853af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    case android::AudioRecord::EVENT_NEW_POS:
2863b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        audioRecorder_handleNewPos_lockRecord(ar);
2873af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        break;
2883af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2893af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    }
2903af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi}
2913af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2923af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
2933af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//-----------------------------------------------------------------------------
2943af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel TriviSLresult android_audioRecorder_create(CAudioRecorder* ar) {
2953af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    SL_LOGV("android_audioRecorder_create(%p) entering", ar);
2963af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
297b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource;
298b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    const SLDataSink *pAudioSnk = &ar->mDataSink.u.mSink;
2993af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
3003af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
301b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    const SLuint32 sourceLocatorType = *(SLuint32 *)pAudioSrc->pLocator;
302b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator;
303b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi
304b0cf731f4d81a3d6f8cac31de3cdddbbf555c305Jean-Michel Trivi    //  the following platform-independent fields have been initialized in CreateAudioRecorder()
305b0cf731f4d81a3d6f8cac31de3cdddbbf555c305Jean-Michel Trivi    //    ar->mNumChannels
306b0cf731f4d81a3d6f8cac31de3cdddbbf555c305Jean-Michel Trivi    //    ar->mSampleRateMilliHz
307b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi
308b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    if ((SL_DATALOCATOR_IODEVICE == sourceLocatorType) &&
309b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi            (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE == sinkLocatorType)) {
310b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi        // microphone to simple buffer queue
311b05ea38e5131001884aa226f90fd50cf594a23f3Jean-Michel Trivi        ar->mAndroidObjType = AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE;
312b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi        ar->mAudioRecord = NULL;
313b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi        ar->mRecordSource = android::AUDIO_SOURCE_DEFAULT;
314b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    } else {
315b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi        result = SL_RESULT_CONTENT_UNSUPPORTED;
316b2aeb0f1009555181dabb944fe05901cb6e6f632Jean-Michel Trivi    }
317b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
318b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    return result;
319b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi}
320b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
321b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
322b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi//-----------------------------------------------------------------------------
323b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel TriviSLresult android_audioRecorder_setConfig(CAudioRecorder* ar, const SLchar *configKey,
324b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        const void *pConfigValue, SLuint32 valueSize) {
325b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
326b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
327b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
328b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    if (NULL == ar) {
329b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_INTERNAL_ERROR;
330b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    } else if (NULL == pConfigValue) {
33175e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_CONFIG_NULL_PARAM);
332b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_PARAMETER_INVALID;
333b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
334b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    } else if(strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
335b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
336b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        // recording preset
337b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        if (KEY_RECORDING_PRESET_PARAMSIZE > valueSize) {
33875e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW);
339b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi            result = SL_RESULT_PARAMETER_INVALID;
340b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        } else {
341b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi            result = audioRecorder_setPreset(ar, *(SLuint32*)pConfigValue);
342b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        }
343b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
344b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    } else {
34575e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY);
346b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_PARAMETER_INVALID;
347b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    }
348b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
349b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    return result;
350b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi}
351b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
352b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
353b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi//-----------------------------------------------------------------------------
354b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel TriviSLresult android_audioRecorder_getConfig(CAudioRecorder* ar, const SLchar *configKey,
355b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        SLuint32* pValueSize, void *pConfigValue) {
356b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
357b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
358b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
359b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    if (NULL == ar) {
360b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        return SL_RESULT_INTERNAL_ERROR;
36175e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi    } else if (NULL == pValueSize) {
36275e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_CONFIG_NULL_PARAM);
363b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_PARAMETER_INVALID;
364b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
365b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    } else if(strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
366b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
367b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        // recording preset
368b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        if (KEY_RECORDING_PRESET_PARAMSIZE > *pValueSize) {
36975e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW);
370b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi            result = SL_RESULT_PARAMETER_INVALID;
371b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        } else {
372b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi            *pValueSize = KEY_RECORDING_PRESET_PARAMSIZE;
37375e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            if (NULL != pConfigValue) {
37475e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi                result = audioRecorder_getPreset(ar, (SLuint32*)pConfigValue);
37575e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi            }
376b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        }
377b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi
378b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    } else {
37975e22870e41386cdc597bd29c76744d74d4c22adJean-Michel Trivi        SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY);
380b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi        result = SL_RESULT_PARAMETER_INVALID;
381b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    }
3823af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
3833af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    return result;
3843af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi}
3853af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
3863af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
3873af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//-----------------------------------------------------------------------------
3883af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel TriviSLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async) {
3893af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    SL_LOGV("android_audioRecorder_realize(%p) entering", ar);
3903af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
3913af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    SLresult result = SL_RESULT_SUCCESS;
3923af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
393712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi    // initialize platform-independent CAudioRecorder fields
39401e9f5fa4698856f92bcfd88188ee4c8397b22dbGlenn Kasten    if (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE != ar->mDataSink.mLocator.mLocatorType) {
39501e9f5fa4698856f92bcfd88188ee4c8397b22dbGlenn Kasten        SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE);
396712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi        return SL_RESULT_CONTENT_UNSUPPORTED;
397712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi    }
398b0cf731f4d81a3d6f8cac31de3cdddbbf555c305Jean-Michel Trivi    //  the following platform-independent fields have been initialized in CreateAudioRecorder()
399712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi    //    ar->mNumChannels
400712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi    //    ar->mSampleRateMilliHz
401712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi
40249e4076e940559bc204d0f0aa7ab412986445bfaGlenn Kasten    SL_LOGV("new AudioRecord %u channels, %lu mHz", ar->mNumChannels, ar->mSampleRateMilliHz);
403712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi
404712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi    // initialize platform-specific CAudioRecorder fields
4053af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    ar->mAudioRecord = new android::AudioRecord();
406b3e52a63baaea367cf411348b68ecd8fd429b029Jean-Michel Trivi    ar->mAudioRecord->set(ar->mRecordSource, // source
407712b490060e4164fbe47986be1d2584d1610d8ddJean-Michel Trivi            sles_to_android_sampleRate(ar->mSampleRateMilliHz), // sample rate in Hertz
4083af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            android::AudioSystem::PCM_16_BIT,   //FIXME use format from buffer queue sink
4091d081e49a10543018e1ae33792bd3d30504719baGlenn Kasten            sles_to_android_channelMaskIn(ar->mNumChannels, 0 /*no channel mask*/),
4101d081e49a10543018e1ae33792bd3d30504719baGlenn Kasten                                   // channel config
4113af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            0,                     //frameCount min
4123af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            0,                     // flags
4133af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            audioRecorder_callback,// callback_t
4143af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            (void*)ar,             // user, callback data, here the AudioRecorder
4153af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            0,                     // notificationFrames
4163af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi            false);                // threadCanCallJava, note: this will prevent direct Java
4173af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi                                   //   callbacks, but we don't want them in the recording loop
4183af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4193af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    if (android::NO_ERROR != ar->mAudioRecord->initCheck()) {
4203af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        SL_LOGE("android_audioRecorder_realize(%p) error creating AudioRecord object", ar);
4213af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        result = SL_RESULT_CONTENT_UNSUPPORTED;
4223af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    }
4233af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4243af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#ifdef MONITOR_RECORDING
4253af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    gMonitorFp = fopen(MONITOR_TARGET, "w");
4263af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    if (NULL == gMonitorFp) { SL_LOGE("error opening %s", MONITOR_TARGET); }
427a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten    else { SL_LOGE("recording to %s", MONITOR_TARGET); } // SL_LOGE so it's always displayed
4283af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#endif
4293af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4303af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    return result;
4313af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi}
4323af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4333af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4343af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//-----------------------------------------------------------------------------
4353af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivivoid android_audioRecorder_destroy(CAudioRecorder* ar) {
4363af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    SL_LOGV("android_audioRecorder_destroy(%p) entering", ar);
4373af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4383af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    if (NULL != ar->mAudioRecord) {
4393af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        ar->mAudioRecord->stop();
4403af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        delete ar->mAudioRecord;
4413af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        ar->mAudioRecord = NULL;
4423af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    }
4433af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4443af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#ifdef MONITOR_RECORDING
445a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten    if (NULL != gMonitorFp) {
446a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten        fclose(gMonitorFp);
447a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten        gMonitorFp = NULL;
448a9a70a4451545034c9263dd55b181f2912534c37Glenn Kasten    }
4493af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi#endif
4503af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi}
4513af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4523af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4533af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi//-----------------------------------------------------------------------------
4543af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivivoid android_audioRecorder_setRecordState(CAudioRecorder* ar, SLuint32 state) {
4553af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    SL_LOGV("android_audioRecorder_setRecordState(%p, %lu) entering", ar, state);
4563af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4573af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    if (NULL == ar->mAudioRecord) {
4583af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi        return;
4593af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    }
4603af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4613af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi    switch (state) {
4623af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi     case SL_RECORDSTATE_STOPPED:
4633af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         ar->mAudioRecord->stop();
4643af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         break;
4653af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi     case SL_RECORDSTATE_PAUSED:
4663af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         // Note that pausing is treated like stop as this implementation only records to a buffer
4673af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         //  queue, so there is no notion of destination being "opened" or "closed" (See description
4683af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         //  of SL_RECORDSTATE in specification)
4693af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         ar->mAudioRecord->stop();
4703af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         break;
4713af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi     case SL_RECORDSTATE_RECORDING:
4723af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         ar->mAudioRecord->start();
4733af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         break;
4743af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi     default:
4753af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi         break;
4763af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi     }
4773af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi
4783af2a8dd03f3113d5da1000dd79c143a9f0c4f36Jean-Michel Trivi}
4793b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
4803b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
4813b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi//-----------------------------------------------------------------------------
4823b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivivoid android_audioRecorder_useEventMask(CAudioRecorder *ar) {
4833b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    IRecord *pRecordItf = &ar->mRecord;
4843b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    SLuint32 eventFlags = pRecordItf->mCallbackEventsMask;
4853b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
4863b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (NULL == ar->mAudioRecord) {
4873b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        return;
4883b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
4893b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
4903b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if ((eventFlags & SL_RECORDEVENT_HEADATMARKER) && (pRecordItf->mMarkerPosition != 0)) {
4913b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        ar->mAudioRecord->setMarkerPosition((uint32_t)((((int64_t)pRecordItf->mMarkerPosition
4923b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi                * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000));
4933b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    } else {
4943b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        // clear marker
4953b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        ar->mAudioRecord->setMarkerPosition(0);
4963b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
4973b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
4983b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (eventFlags & SL_RECORDEVENT_HEADATNEWPOS) {
499b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        SL_LOGV("pos update period %ld", pRecordItf->mPositionUpdatePeriod);
5003b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi         ar->mAudioRecord->setPositionUpdatePeriod(
5013b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi                (uint32_t)((((int64_t)pRecordItf->mPositionUpdatePeriod
5023b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi                * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000));
5033b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    } else {
5043b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        // clear periodic update
5053b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        ar->mAudioRecord->setPositionUpdatePeriod(0);
5063b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
5073b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
5083b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (eventFlags & SL_RECORDEVENT_HEADATLIMIT) {
5093b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        // FIXME support SL_RECORDEVENT_HEADATLIMIT
510a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten        SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADATLIMIT) on an "
5113b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi                    "SL_OBJECTID_AUDIORECORDER to be implemented ]");
5123b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
5133b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
5143b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (eventFlags & SL_RECORDEVENT_HEADMOVING) {
5153b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi        // FIXME support SL_RECORDEVENT_HEADMOVING
516a7b79e766ec6d95e9236168c27461c2ebaef4659Glenn Kasten        SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADMOVING) on an "
5173b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi                "SL_OBJECTID_AUDIORECORDER to be implemented ]");
5183b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
5193b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
5203b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (eventFlags & SL_RECORDEVENT_BUFFER_FULL) {
521f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi        // nothing to do for SL_RECORDEVENT_BUFFER_FULL since this will not be encountered on
522f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi        // recording to buffer queues
5233b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
5243b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
5253b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    if (eventFlags & SL_RECORDEVENT_HEADSTALLED) {
526f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi        // nothing to do for SL_RECORDEVENT_HEADSTALLED, callback event will be checked against mask
527f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi        // when AudioRecord::EVENT_OVERRUN is encountered
528f6cca2f731329d101651348d1b7e51ead7b1290aJean-Michel Trivi
5293b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi    }
5303b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi
5313b142e50f4ae068f50f8e3d277e0f19910c67001Jean-Michel Trivi}
532b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi
533b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi
534b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi//-----------------------------------------------------------------------------
535b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivivoid android_audioRecorder_getPosition(CAudioRecorder *ar, SLmillisecond *pPosMsec) {
536b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi    if ((NULL == ar) || (NULL == ar->mAudioRecord)) {
537b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        *pPosMsec = 0;
538b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi    } else {
539b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        uint32_t positionInFrames;
540b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        ar->mAudioRecord->getPosition(&positionInFrames);
541b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        if (ar->mSampleRateMilliHz == 0) {
542b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi            *pPosMsec = 0;
543b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        } else {
544b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi            *pPosMsec = ((int64_t)positionInFrames * 1000) /
545b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi                    sles_to_android_sampleRate(ar->mSampleRateMilliHz);
546b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi        }
547b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi    }
548b5ef0195d7b8fa1fceae5ef8a256ed19eb03cbedJean-Michel Trivi}
549