Problem using AudioRecord in Motorola Milestone


Last Updated:

  1. Sir^Knigget

    Sir^Knigget Member This Topic's Starter

    Joined:
    Sep 30, 2009
    Messages:
    11
    Likes Received:
    0
    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::eek:penInputStream 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 (Text):
    1. sp<IAudioRecord> AudioFlinger::openRecord(
    2. 2890         pid_t pid,
    3. 2891         int input,
    4. 2892         uint32_t sampleRate,
    5. 2893         int format,
    6. 2894         int channelCount,
    7. 2895         int frameCount,
    8. 2896         uint32_t flags,
    9. 2897         status_t *status)
    10. 2898 {
    11. 2899     sp<RecordThread::RecordTrack> recordTrack;
    12. 2900     sp<RecordHandle> recordHandle;
    13. 2901     sp<Client> client;
    14. 2902     wp<Client> wclient;
    15. 2903     status_t lStatus;
    16. 2904     RecordThread *thread;
    17. 2905     size_t inFrameCount;
    18. 2906
    19. 2907     // check calling permissions
    20. 2908     if (!recordingAllowed()) {
    21. 2909         lStatus = PERMISSION_DENIED;
    22. 2910         goto Exit;
    23. 2911     }
    24. 2912
    25. 2913     // add client to list
    26. 2914     { // scope for mLock
    27. 2915         Mutex::Autolock _l(mLock);
    28. 2916         thread = checkRecordThread_l(input);
    29. 2917         if (thread == NULL) {
    30. 2918             lStatus = BAD_VALUE;
    31. 2919             goto Exit;
    32. 2920         }
    33. 2921
    34. 2922         wclient = mClients.valueFor(pid);
    35. 2923         if (wclient != NULL) {
    36. 2924             client = wclient.promote();
    37. 2925         } else {
    38. 2926             client = new Client(this, pid);
    39. 2927             mClients.add(pid, client);
    40. 2928         }
    41. 2929
    42. 2930         // create new record track. The record track uses one track in mHardwareMixerThread by convention.
    43. 2931         recordTrack = new RecordThread::RecordTrack(thread, client, sampleRate,
    44. 2932                                                    format, channelCount, frameCount, flags);
    45. 2933     }
    46. 2934     if (recordTrack->getCblk() == NULL) {
    47. 2935         // remove local strong reference to Client before deleting the RecordTrack so that the Client
    48. 2936         // destructor is called by the TrackBase destructor with mLock held
    49. 2937         client.clear();
    50. 2938         recordTrack.clear();
    51. 2939         lStatus = NO_MEMORY;
    52. 2940         goto Exit;
    53. 2941     }
    54. 2942
    55. 2943     // return to handle to client
    56. 2944     recordHandle = new RecordHandle(recordTrack);
    57. 2945     lStatus = NO_ERROR;
    58. 2946
    59. 2947 Exit:
    60. 2948     if (status) {
    61. 2949         *status = lStatus;
    62. 2950     }
    63. 2951     return recordHandle;
    64. 2952 }
    The code that initializes AudioRecord:

    Code (Text):
    1. record = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
    2.                     AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(8000,
    3.                             AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4);
    Again, it works fine on any other device, including Droid.

    Thanks for any help!
     

    Advertisement

Share This Page

Loading...