• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem using AudioRecord in Motorola Milestone

My application uses AudioRecord to record streaming voice. On ANY OTHER Android device it initializes properly and works great, excluding Motorola Milestone, which force closes and the log shows:

01-17 14:08:41.124: DEBUG/AudioHardwareMot(1059): AudioMgr:AudioHardwareMot::openInputStream enter
01-17 14:08:41.124: DEBUG/AudioHardwareMot(1059): AudioMgr:AudioStreamInMot::set(0xaf00, 40000, 1, 10, 8000)
01-17 14:08:41.124: ERROR/AudioRecord(2190): AudioFlinger could not create record track, status: -22
01-17 14:08:41.124: ERROR/AudioRecord-JNI(2190): Error creating AudioRecord instance: initialization check failed.
01-17 14:08:41.124: ERROR/AudioRecord-Java(2190): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.

Sometimes it happens, sometimes it doesn't, and looking into the platform source code doesn't clarify it. It returns with BAD_VALUE error code. The code in AudioFlinger.cpp that does that:

Code:
sp<IAudioRecord> AudioFlinger::openRecord(
2890         pid_t pid,
2891         int input,
2892         uint32_t sampleRate,
2893         int format,
2894         int channelCount,
2895         int frameCount,
2896         uint32_t flags,
2897         status_t *status)
2898 {
2899     sp<RecordThread::RecordTrack> recordTrack;
2900     sp<RecordHandle> recordHandle;
2901     sp<Client> client;
2902     wp<Client> wclient;
2903     status_t lStatus;
2904     RecordThread *thread;
2905     size_t inFrameCount;
2906 
2907     // check calling permissions
2908     if (!recordingAllowed()) {
2909         lStatus = PERMISSION_DENIED;
2910         goto Exit;
2911     }
2912 
2913     // add client to list
2914     { // scope for mLock
2915         Mutex::Autolock _l(mLock);
2916         thread = checkRecordThread_l(input);
2917         if (thread == NULL) {
2918             lStatus = BAD_VALUE;
2919             goto Exit;
2920         }
2921 
2922         wclient = mClients.valueFor(pid);
2923         if (wclient != NULL) {
2924             client = wclient.promote();
2925         } else {
2926             client = new Client(this, pid);
2927             mClients.add(pid, client);
2928         }
2929 
2930         // create new record track. The record track uses one track in mHardwareMixerThread by convention.
2931         recordTrack = new RecordThread::RecordTrack(thread, client, sampleRate,
2932                                                    format, channelCount, frameCount, flags);
2933     }
2934     if (recordTrack->getCblk() == NULL) {
2935         // remove local strong reference to Client before deleting the RecordTrack so that the Client
2936         // destructor is called by the TrackBase destructor with mLock held
2937         client.clear();
2938         recordTrack.clear();
2939         lStatus = NO_MEMORY;
2940         goto Exit;
2941     }
2942 
2943     // return to handle to client
2944     recordHandle = new RecordHandle(recordTrack);
2945     lStatus = NO_ERROR;
2946 
2947 Exit:
2948     if (status) {
2949         *status = lStatus;
2950     }
2951     return recordHandle;
2952 }

The code that initializes AudioRecord:

Code:
record = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
					AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(8000,
							AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4);

Again, it works fine on any other device, including Droid.

Thanks for any help!
 
Back
Top Bottom