Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4e44f42 authored by vivek mehta's avatar vivek mehta Committed by Gerrit Code Review
Browse files

Squashed commit of audio changes from CodeAurora

MediaFile: Add DIVX and MPEG2TS file format

Change-Id: I9f8cfbe8138c6d3d0d824bff2542b91d72a06b82

audio: Define ANC headset and proxy device

Change-Id: I681d73433d874ec66ec0b1f1f39869008d7d7d0d
(cherry picked from commit 1e6c410eadfc510a9f116bb3da142214fe761225)

audio: add support for QCOM WiFi display

- Define QCOM WFD intents
- Register and handle WFD intends in AudioSystem

Change-Id: I1e5a73d4aa5595bed44d24652647c12b7ef4ae1f

audio: add support for QCOM audio formats

- Add support for EVRC, QCELP, and WMA formats

Change-Id: If3676b88fa287b484ef8616c0a6b67177b61a720

PhoneWindowManager: Changes for WFD.

- WFD now sends WIFI_DISPLAY_VIDEO intent to set UI orientation.
- PhoneWindowManager to listen for WFD intents.
- Display on WFD should be same as seen on the HDMI, so set the
  orientation to HDMI orientation

Change-Id: I638adaa906e2151b1c6ae496343714fe828f5dbd

audio: add support for QCOM vocoders

- Add support for EVRC,QCELP and other
  QCOM vocoders

Change-Id: I9b2a18fe7d01a9198eb470e94e7176b7a6da2c7c
parent 7086f427
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -2137,6 +2137,31 @@ public class Intent implements Parcelable, Cloneable {
    public static final String ACTION_HEADSET_PLUG =
            "android.intent.action.HEADSET_PLUG";

    /**
     * Broadcast Action: WiFi Display audio is enabled or disabled
     *
     * <p>The intent will have the following extra values:
     * <ul>
     *   <li><em>state</em> - 0 for disabled, 1 for enabled. </li>
     * </ul>
     * @hide
     */
    public static final String ACTION_WIFI_DISPLAY_AUDIO =
            "qualcomm.intent.action.WIFI_DISPLAY_AUDIO";

    /**
     * Broadcast Action: WiFi Display video is enabled or disabled
     *
     * <p>The intent will have the following extra values:
     * <ul>
     *   <li><em>state</em> - 0 for disabled, 1 for enabled. </li>
     * </ul>
     * @hide
     */

    public static final String ACTION_WIFI_DISPLAY_VIDEO =
            "qualcomm.intent.action.WIFI_DISPLAY_VIDEO";

    /**
     * Broadcast Action: An analog audio speaker/headset plugged in or unplugged.
     *
+74 −9
Original line number Diff line number Diff line
@@ -49,6 +49,11 @@ struct fields_t {
    jmethodID postNativeEventInJava; //... event post callback method
    int       PCM16;                 //...  format constants
    int       PCM8;                  //...  format constants
    int       AMRNB;                 //...  format constants
    int       AMRWB;                 //...  format constants
    int       EVRC;                  //...  format constants
    int       EVRCB;                 //...  format constants
    int       EVRCWB;                //...  format constants
    jfieldID  nativeRecorderInJavaObj; // provides access to the C++ AudioRecord object
    jfieldID  nativeCallbackCookie;    // provides access to the AudioRecord callback data
};
@@ -162,6 +167,24 @@ static sp<AudioRecord> setAudioRecord(JNIEnv* env, jobject thiz, const sp<AudioR
    env->SetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (int)ar.get());
    return old;
}
int getformatrec(int audioformat)
{
    if(audioformat==javaAudioRecordFields.PCM16)
        return AUDIO_FORMAT_PCM_16_BIT;
#ifdef QCOM_HARDWARE
    else if(audioformat==javaAudioRecordFields.AMRNB)
        return AUDIO_FORMAT_AMR_NB;
    else if(audioformat==javaAudioRecordFields.AMRWB)
        return AUDIO_FORMAT_AMR_WB;
    else if(audioformat==javaAudioRecordFields.EVRC)
        return AUDIO_FORMAT_EVRC;
    else if(audioformat==javaAudioRecordFields.EVRCB)
        return AUDIO_FORMAT_EVRCB;
    else if(audioformat==javaAudioRecordFields.EVRCWB)
        return AUDIO_FORMAT_EVRCWB;
#endif
    return AUDIO_FORMAT_PCM_8_BIT;
}

// ----------------------------------------------------------------------------
static int
@@ -181,14 +204,27 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,

    // compare the format against the Java constants
    if ((audioFormat != javaAudioRecordFields.PCM16)
#ifdef QCOM_HARDWARE
        && (audioFormat != javaAudioRecordFields.AMRNB)
        && (audioFormat != javaAudioRecordFields.AMRWB)
        && (audioFormat != javaAudioRecordFields.EVRC)
        && (audioFormat != javaAudioRecordFields.EVRCB)
#endif
        && (audioFormat != javaAudioRecordFields.PCM8)) {
        ALOGE("Error creating AudioRecord: unsupported audio format.");
        return AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
    }

    int bytesPerSample = audioFormat==javaAudioRecordFields.PCM16 ? 2 : 1;
    audio_format_t format = audioFormat==javaAudioRecordFields.PCM16 ?
            AUDIO_FORMAT_PCM_16_BIT : AUDIO_FORMAT_PCM_8_BIT;
    int bytesPerSample;
    if(audioFormat == javaAudioRecordFields.PCM8)
        bytesPerSample = 1;
#ifdef QCOM_HARDWARE
    else if((audioFormat == javaAudioRecordFields.AMRWB) &&
            ((uint32_t)source != AUDIO_SOURCE_VOICE_COMMUNICATION))
        bytesPerSample = 61;
#endif
    else
        bytesPerSample = 2;
    audio_format_t format = (audio_format_t)getformatrec(audioFormat);

    if (buffSizeInBytes == 0) {
         ALOGE("Error creating AudioRecord: frameCount is 0.");
@@ -514,9 +550,8 @@ static jint android_media_AudioRecord_get_min_buff_size(JNIEnv *env, jobject th
    int frameCount = 0;
    status_t result = AudioRecord::getMinFrameCount(&frameCount,
            sampleRateInHertz,
            (audioFormat == javaAudioRecordFields.PCM16 ?
                AUDIO_FORMAT_PCM_16_BIT : AUDIO_FORMAT_PCM_8_BIT),
            audio_channel_in_mask_from_count(nbChannels));
            (audio_format_t)getformatrec(audioFormat),
            nbChannels);

    if (result == BAD_VALUE) {
        return 0;
@@ -524,7 +559,17 @@ static jint android_media_AudioRecord_get_min_buff_size(JNIEnv *env, jobject th
    if (result != NO_ERROR) {
        return -1;
    }
    return frameCount * nbChannels * (audioFormat == javaAudioRecordFields.PCM16 ? 2 : 1);
    int bytesPerSample;
    if(audioFormat == javaAudioRecordFields.PCM8)
        bytesPerSample = 1;
#ifdef QCOM_HARDWARE
    else if(audioFormat == javaAudioRecordFields.AMRWB)
        bytesPerSample = 61;
#endif
    else
        bytesPerSample = 2;

    return frameCount * nbChannels * bytesPerSample;
}


@@ -558,6 +603,11 @@ static JNINativeMethod gMethods[] = {
#define JAVA_POSTEVENT_CALLBACK_NAME  "postEventFromNative"
#define JAVA_CONST_PCM16_NAME         "ENCODING_PCM_16BIT"
#define JAVA_CONST_PCM8_NAME          "ENCODING_PCM_8BIT"
#define JAVA_CONST_AMRNB_NAME         "ENCODING_AMRNB"
#define JAVA_CONST_AMRWB_NAME         "ENCODING_AMRWB"
#define JAVA_CONST_EVRC_NAME          "ENCODING_EVRC"
#define JAVA_CONST_EVRCB_NAME         "ENCODING_EVRCB"
#define JAVA_CONST_EVRCWB_NAME        "ENCODING_EVRCWB"
#define JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME  "mNativeRecorderInJavaObj"
#define JAVA_NATIVECALLBACKINFO_FIELD_NAME       "mNativeCallbackCookie"

@@ -621,7 +671,22 @@ int register_android_media_AudioRecord(JNIEnv *env)
                JAVA_CONST_PCM16_NAME, &(javaAudioRecordFields.PCM16))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_PCM8_NAME, &(javaAudioRecordFields.PCM8)) ) {
                JAVA_CONST_PCM8_NAME, &(javaAudioRecordFields.PCM8))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_AMRNB_NAME, &(javaAudioRecordFields.AMRNB))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_AMRWB_NAME, &(javaAudioRecordFields.AMRWB))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_EVRC_NAME, &(javaAudioRecordFields.EVRC))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_EVRCB_NAME, &(javaAudioRecordFields.EVRCB))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_EVRCWB_NAME, &(javaAudioRecordFields.EVRCWB))) {
        // error log performed in getIntConstantFromClass()
        return -1;
    }
+114 −6
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -49,6 +50,19 @@ struct fields_t {
    jmethodID postNativeEventInJava; //... event post callback method
    int       PCM16;                 //...  format constants
    int       PCM8;                  //...  format constants
    int       AMRNB;                 //...  format constants
    int       AMRWB;                 //...  format constants
    int       EVRC;                  //...  format constants
    int       EVRCB;                 //...  format constants
    int       EVRCWB;                //...  format constants
    int       STREAM_VOICE_CALL;     //...  stream type constants
    int       STREAM_SYSTEM;         //...  stream type constants
    int       STREAM_RING;           //...  stream type constants
    int       STREAM_MUSIC;          //...  stream type constants
    int       STREAM_ALARM;          //...  stream type constants
    int       STREAM_NOTIFICATION;   //...  stream type constants
    int       STREAM_BLUETOOTH_SCO;  //...  stream type constants
    int       STREAM_DTMF;           //...  stream type constants
    int       MODE_STREAM;           //...  memory mode
    int       MODE_STATIC;           //...  memory mode
    jfieldID  nativeTrackInJavaObj;  // stores in Java the native AudioTrack object
@@ -199,6 +213,25 @@ static sp<AudioTrack> setAudioTrack(JNIEnv* env, jobject thiz, const sp<AudioTra
}

// ----------------------------------------------------------------------------
int getformat(int audioformat)
{
    if(audioformat==javaAudioTrackFields.PCM16)
        return AUDIO_FORMAT_PCM_16_BIT;
#ifdef QCOM_HARDWARE
    else if(audioformat==javaAudioTrackFields.AMRNB)
        return AUDIO_FORMAT_AMR_NB;
    else if(audioformat==javaAudioTrackFields.AMRWB)
        return AUDIO_FORMAT_AMR_WB;
    else if(audioformat==javaAudioTrackFields.EVRC)
        return AUDIO_FORMAT_EVRC;
    else if(audioformat==javaAudioTrackFields.EVRCB)
        return AUDIO_FORMAT_EVRCB;
    else if(audioformat==javaAudioTrackFields.EVRCWB)
        return AUDIO_FORMAT_EVRCWB;
#endif
    return AUDIO_FORMAT_PCM_8_BIT;
}

static int
android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
        jint streamType, jint sampleRateInHertz, jint javaChannelMask,
@@ -249,7 +282,15 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th

    // check the format.
    // This function was called from Java, so we compare the format against the Java constants
    if ((audioFormat != javaAudioTrackFields.PCM16) && (audioFormat != javaAudioTrackFields.PCM8)) {
    if ((audioFormat != javaAudioTrackFields.PCM16)
#ifdef QCOM_HARDWARE
        && (audioFormat != javaAudioTrackFields.AMRNB)
        && (audioFormat != javaAudioTrackFields.AMRWB)
        && (audioFormat != javaAudioTrackFields.EVRC)
        && (audioFormat != javaAudioTrackFields.EVRCB)
        && (audioFormat != javaAudioTrackFields.EVRCWB)
#endif
        && (audioFormat != javaAudioTrackFields.PCM8)) {
        ALOGE("Error creating AudioTrack: unsupported audio format.");
        return AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
    }
@@ -268,9 +309,12 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
    }

    // compute the frame count
    int bytesPerSample = audioFormat == javaAudioTrackFields.PCM16 ? 2 : 1;
    audio_format_t format = audioFormat == javaAudioTrackFields.PCM16 ?
            AUDIO_FORMAT_PCM_16_BIT : AUDIO_FORMAT_PCM_8_BIT;
    int bytesPerSample;
    if(audioFormat == javaAudioTrackFields.PCM8)
        bytesPerSample = 1;
    else
        bytesPerSample = 2;
    audio_format_t format = (audio_format_t)getformat(audioFormat);
    int frameCount = buffSizeInBytes / (nbChannels * bytesPerSample);

    jclass clazz = env->GetObjectClass(thiz);
@@ -516,7 +560,16 @@ jint writeToTrack(const sp<AudioTrack>& track, jint audioFormat, jbyte* data,
    if (track->sharedBuffer() == 0) {
        written = track->write(data + offsetInBytes, sizeInBytes);
    } else {
#ifdef QCOM_HARDWARE
        if ((audioFormat == javaAudioTrackFields.PCM16)
        || (audioFormat == javaAudioTrackFields.AMRNB)
        || (audioFormat == javaAudioTrackFields.AMRWB)
        || (audioFormat == javaAudioTrackFields.EVRC)
        || (audioFormat == javaAudioTrackFields.EVRCB)
        || (audioFormat == javaAudioTrackFields.EVRCWB)) {
#else
        if (audioFormat == javaAudioTrackFields.PCM16) {
#endif
            // writing to shared memory, check for capacity
            if ((size_t)sizeInBytes > track->sharedBuffer()->size()) {
                sizeInBytes = track->sharedBuffer()->size();
@@ -791,7 +844,7 @@ static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env, jobject thi
            sampleRateInHertz) != NO_ERROR) {
        return -1;
    }
    return frameCount * nbChannels * (audioFormat == javaAudioTrackFields.PCM16 ? 2 : 1);
    return frameCount * nbChannels * (audioFormat == javaAudioTrackFields.PCM8 ? 1 : 2);
}

// ----------------------------------------------------------------------------
@@ -866,6 +919,11 @@ static JNINativeMethod gMethods[] = {
#define JAVA_POSTEVENT_CALLBACK_NAME                    "postEventFromNative"
#define JAVA_CONST_PCM16_NAME                           "ENCODING_PCM_16BIT"
#define JAVA_CONST_PCM8_NAME                            "ENCODING_PCM_8BIT"
#define JAVA_CONST_AMRNB_NAME                           "ENCODING_AMRNB"
#define JAVA_CONST_AMRWB_NAME                           "ENCODING_AMRWB"
#define JAVA_CONST_EVRC_NAME                            "ENCODING_EVRC"
#define JAVA_CONST_EVRCB_NAME                           "ENCODING_EVRCB"
#define JAVA_CONST_EVRCWB_NAME                          "ENCODING_EVRCWB"
#define JAVA_CONST_BUFFER_COUNT_NAME                    "BUFFER_COUNT"
#define JAVA_CONST_STREAM_VOICE_CALL_NAME               "STREAM_VOICE_CALL"
#define JAVA_CONST_STREAM_SYSTEM_NAME                   "STREAM_SYSTEM"
@@ -963,7 +1021,57 @@ int register_android_media_AudioTrack(JNIEnv *env)
                JAVA_CONST_PCM16_NAME, &(javaAudioTrackFields.PCM16))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_PCM8_NAME, &(javaAudioTrackFields.PCM8)) ) {
                JAVA_CONST_PCM8_NAME, &(javaAudioTrackFields.PCM8))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_AMRNB_NAME, &(javaAudioTrackFields.AMRNB))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_AMRWB_NAME, &(javaAudioTrackFields.AMRWB))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_EVRC_NAME, &(javaAudioTrackFields.EVRC))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_EVRCB_NAME, &(javaAudioTrackFields.EVRCB))
           || !android_media_getIntConstantFromClass(env, audioFormatClass,
                JAVA_AUDIOFORMAT_CLASS_NAME,
                JAVA_CONST_EVRCWB_NAME, &(javaAudioTrackFields.EVRCWB))
) {
        // error log performed in android_media_getIntConstantFromClass()
        return -1;
    }
    // Get the stream types from the AudioManager class
    jclass audioManagerClass = NULL;
    audioManagerClass = env->FindClass(JAVA_AUDIOMANAGER_CLASS_NAME);
    if (audioManagerClass == NULL) {
       ALOGE("Can't find %s", JAVA_AUDIOMANAGER_CLASS_NAME);
       return -1;
    }
    if ( !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_VOICE_CALL_NAME, &(javaAudioTrackFields.STREAM_VOICE_CALL))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_MUSIC_NAME, &(javaAudioTrackFields.STREAM_MUSIC))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_SYSTEM_NAME, &(javaAudioTrackFields.STREAM_SYSTEM))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_RING_NAME, &(javaAudioTrackFields.STREAM_RING))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_ALARM_NAME, &(javaAudioTrackFields.STREAM_ALARM))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_NOTIFICATION_NAME, &(javaAudioTrackFields.STREAM_NOTIFICATION))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_BLUETOOTH_SCO_NAME, &(javaAudioTrackFields.STREAM_BLUETOOTH_SCO))
          || !android_media_getIntConstantFromClass(env, audioManagerClass,
               JAVA_AUDIOMANAGER_CLASS_NAME,
               JAVA_CONST_STREAM_DTMF_NAME, &(javaAudioTrackFields.STREAM_DTMF))) {
        // error log performed in android_media_getIntConstantFromClass()
        return -1;
    }
+10 −0
Original line number Diff line number Diff line
@@ -36,6 +36,16 @@ public class AudioFormat {
    public static final int ENCODING_PCM_16BIT = 2;
    /** Audio data format: PCM 8 bit per sample. Not guaranteed to be supported by devices. */
    public static final int ENCODING_PCM_8BIT = 3;
    /** @hide */
    public static final int ENCODING_AMRNB = 100;   // accessed by native code
    /** @hide */
    public static final int ENCODING_AMRWB = 101;   // accessed by native code
    /** @hide */
    public static final int ENCODING_EVRC = 102;    // accessed by native code
    /** @hide */
    public static final int ENCODING_EVRCB = 103;   // accessed by native code
    /** @hide */
    public static final int ENCODING_EVRCWB = 104;  // accessed by native code

    /** Invalid audio channel configuration */
    /** @deprecated use CHANNEL_INVALID instead  */
+20 −3
Original line number Diff line number Diff line
@@ -308,6 +308,11 @@ public class AudioRecord
            break;
        case AudioFormat.ENCODING_PCM_16BIT:
        case AudioFormat.ENCODING_PCM_8BIT:
        case AudioFormat.ENCODING_AMRNB:
        case AudioFormat.ENCODING_AMRWB:
        case AudioFormat.ENCODING_EVRC:
        case AudioFormat.ENCODING_EVRCB:
        case AudioFormat.ENCODING_EVRCWB:
            mAudioFormat = audioFormat;
            break;
        default:
@@ -327,8 +332,15 @@ public class AudioRecord
    private void audioBuffSizeCheck(int audioBufferSize) {
        // NB: this section is only valid with PCM data. 
        // To update when supporting compressed formats
        int frameSizeInBytes = mChannelCount 
            * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2);
        int bytesPerSample;
        if(mAudioFormat == AudioFormat.ENCODING_PCM_8BIT)
            bytesPerSample = 1;
        else if((mAudioFormat == AudioFormat.ENCODING_AMRWB) &&
                (mRecordSource != MediaRecorder.AudioSource.VOICE_COMMUNICATION))
            bytesPerSample = 61;
        else
            bytesPerSample = 2;
        int frameSizeInBytes = mChannelCount * bytesPerSample;
        if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) {
            throw (new IllegalArgumentException("Invalid audio buffer size."));
        }
@@ -476,7 +488,12 @@ public class AudioRecord
        }
        
        // PCM_8BIT is not supported at the moment
        if (audioFormat != AudioFormat.ENCODING_PCM_16BIT) {
        if (audioFormat != AudioFormat.ENCODING_PCM_16BIT
            && audioFormat != AudioFormat.ENCODING_AMRNB
            && audioFormat != AudioFormat.ENCODING_AMRWB
            && audioFormat != AudioFormat.ENCODING_EVRC
            && audioFormat != AudioFormat.ENCODING_EVRCB
            && audioFormat != AudioFormat.ENCODING_EVRCWB) {
            loge("getMinBufferSize(): Invalid audio format.");
            return AudioRecord.ERROR_BAD_VALUE;
        }
Loading