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

Commit 3caa10c6 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "audio: add implementation for TV related API" am: f57ff9e7

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1562807

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I3ecaa15c7d3dfbd38be54065d8dc09ba630c33ea
parents 8fa4c0f3 f57ff9e7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ enum {
    AUDIO_JAVA_WOULD_BLOCK        = -7,
};

static inline jint nativeToJavaStatus(status_t status) {
static constexpr inline jint nativeToJavaStatus(status_t status) {
    switch (status) {
    case NO_ERROR:
        return AUDIO_JAVA_SUCCESS;
+26 −28
Original line number Diff line number Diff line
@@ -263,18 +263,7 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
        return (jint) AUDIO_JAVA_ERROR;
    }

    // TODO: replace when we land matching AudioTrack::set() in frameworks/av in r or r-tv-dev.
    if (tunerConfiguration != nullptr) {
    const TunerConfigurationHelper tunerHelper(env, tunerConfiguration);
        ALOGE("Error creating AudioTrack: unsupported tuner contentId:%d syncId:%d",
              tunerHelper.getContentId(), tunerHelper.getSyncId());
        return (jint)AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
    }
    // TODO: replace when we land matching AudioTrack::set() in frameworks/av in r or r-tv-dev.
    if (encapsulationMode != 0 /* ENCAPSULATION_MODE_NONE */) {
        ALOGE("Error creating AudioTrack: unsupported encapsulationMode %d", encapsulationMode);
        return (jint)AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
    }

    jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
    if (nSession == NULL) {
@@ -369,6 +358,18 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
            offloadInfo.stream_type = AUDIO_STREAM_MUSIC; //required for offload
        }

        if (encapsulationMode != 0) {
            offloadInfo = AUDIO_INFO_INITIALIZER;
            offloadInfo.format = format;
            offloadInfo.sample_rate = sampleRateInHertz;
            offloadInfo.channel_mask = nativeChannelMask;
            offloadInfo.stream_type = AUDIO_STREAM_MUSIC;
            offloadInfo.encapsulation_mode =
                    static_cast<audio_encapsulation_mode_t>(encapsulationMode);
            offloadInfo.content_id = tunerHelper.getContentId();
            offloadInfo.sync_id = tunerHelper.getSyncId();
        }

        // initialize the native AudioTrack object
        status_t status = NO_ERROR;
        switch (memoryMode) {
@@ -389,7 +390,8 @@ static jint android_media_AudioTrack_setup(JNIEnv *env, jobject thiz, jobject we
                                  sessionId, // audio session ID
                                  offload ? AudioTrack::TRANSFER_SYNC_NOTIF_CALLBACK
                                          : AudioTrack::TRANSFER_SYNC,
                                  offload ? &offloadInfo : NULL, -1, -1, // default uid, pid values
                                  (offload || encapsulationMode) ? &offloadInfo : NULL, -1,
                                  -1, // default uid, pid values
                                  paa.get());
            break;

@@ -1364,8 +1366,7 @@ static jint android_media_AudioTrack_setAudioDescriptionMixLeveldB(JNIEnv *env,
        return (jint)AUDIO_JAVA_ERROR;
    }

    // TODO: replace in r-dev or r-tv-dev with code if HW is able to set audio mix level.
    return (jint)AUDIO_JAVA_ERROR;
    return nativeToJavaStatus(lpTrack->setAudioDescriptionMixLevel(level));
}

static jint android_media_AudioTrack_getAudioDescriptionMixLeveldB(JNIEnv *env, jobject thiz,
@@ -1381,12 +1382,10 @@ static jint android_media_AudioTrack_getAudioDescriptionMixLeveldB(JNIEnv *env,
        return (jint)AUDIO_JAVA_ERROR;
    }

    // TODO: replace in r-dev or r-tv-dev with code if HW is able to set audio mix level.
    // By contract we can return -infinity if unsupported.
    *nativeLevel = -std::numeric_limits<float>::infinity();
    status_t status = lpTrack->getAudioDescriptionMixLevel(reinterpret_cast<float *>(nativeLevel));
    env->ReleasePrimitiveArrayCritical(level, nativeLevel, 0 /* mode */);
    nativeLevel = nullptr;
    return (jint)AUDIO_JAVA_SUCCESS;

    return nativeToJavaStatus(status);
}

static jint android_media_AudioTrack_setDualMonoMode(JNIEnv *env, jobject thiz, jint dualMonoMode) {
@@ -1396,8 +1395,8 @@ static jint android_media_AudioTrack_setDualMonoMode(JNIEnv *env, jobject thiz,
        return (jint)AUDIO_JAVA_ERROR;
    }

    // TODO: replace in r-dev or r-tv-dev with code if HW is able to set audio mix level.
    return (jint)AUDIO_JAVA_ERROR;
    return nativeToJavaStatus(
            lpTrack->setDualMonoMode(static_cast<audio_dual_mono_mode_t>(dualMonoMode)));
}

static jint android_media_AudioTrack_getDualMonoMode(JNIEnv *env, jobject thiz,
@@ -1407,18 +1406,17 @@ static jint android_media_AudioTrack_getDualMonoMode(JNIEnv *env, jobject thiz,
        ALOGE("%s: AudioTrack not initialized", __func__);
        return (jint)AUDIO_JAVA_ERROR;
    }
    jfloat *nativeDualMonoMode = (jfloat *)env->GetPrimitiveArrayCritical(dualMonoMode, NULL);
    jint *nativeDualMonoMode = (jint *)env->GetPrimitiveArrayCritical(dualMonoMode, NULL);
    if (nativeDualMonoMode == nullptr) {
        ALOGE("%s: Cannot retrieve dualMonoMode pointer", __func__);
        return (jint)AUDIO_JAVA_ERROR;
    }

    // TODO: replace in r-dev or r-tv-dev with code if HW is able to select dual mono mode.
    // By contract we can return DUAL_MONO_MODE_OFF if unsupported.
    *nativeDualMonoMode = 0; // DUAL_MONO_MODE_OFF for now.
    status_t status = lpTrack->getDualMonoMode(
            reinterpret_cast<audio_dual_mono_mode_t *>(nativeDualMonoMode));
    env->ReleasePrimitiveArrayCritical(dualMonoMode, nativeDualMonoMode, 0 /* mode */);
    nativeDualMonoMode = nullptr;
    return (jint)AUDIO_JAVA_SUCCESS;

    return nativeToJavaStatus(status);
}

// ----------------------------------------------------------------------------
+17 −6
Original line number Diff line number Diff line
@@ -5434,8 +5434,12 @@ public class AudioManager {
    public boolean setAdditionalOutputDeviceDelay(
            @NonNull AudioDeviceInfo device, @IntRange(from = 0) long delayMillis) {
        Objects.requireNonNull(device);
        // Implement the setter in r-dev or r-tv-dev as needed.
        return false;
        try {
            return getService().setAdditionalOutputDeviceDelay(
                new AudioDeviceAttributes(device), delayMillis);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -5450,8 +5454,11 @@ public class AudioManager {
    @IntRange(from = 0)
    public long getAdditionalOutputDeviceDelay(@NonNull AudioDeviceInfo device) {
        Objects.requireNonNull(device);
        // Implement the getter in r-dev or r-tv-dev as needed.
        return 0;
        try {
            return getService().getAdditionalOutputDeviceDelay(new AudioDeviceAttributes(device));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
@@ -5468,8 +5475,12 @@ public class AudioManager {
    @IntRange(from = 0)
    public long getMaxAdditionalOutputDeviceDelay(@NonNull AudioDeviceInfo device) {
        Objects.requireNonNull(device);
        // Implement the getter in r-dev or r-tv-dev as needed.
        return 0;
        try {
            return getService().getMaxAdditionalOutputDeviceDelay(
                    new AudioDeviceAttributes(device));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
+6 −4
Original line number Diff line number Diff line
@@ -1269,11 +1269,13 @@ public class AudioTrack extends PlayerBase
            // native code figure out the minimum buffer size.
            if (mMode == MODE_STREAM && mBufferSizeInBytes == 0) {
                int bytesPerSample = 1;
                if (AudioFormat.isEncodingLinearFrames(mFormat.getEncoding())) {
                    try {
                        bytesPerSample = mFormat.getBytesPerSample(mFormat.getEncoding());
                    } catch (IllegalArgumentException e) {
                        // do nothing
                    }
                }
                mBufferSizeInBytes = mFormat.getChannelCount() * bytesPerSample;
            }

+6 −0
Original line number Diff line number Diff line
@@ -330,4 +330,10 @@ interface IAudioService {

    oneway void unregisterCommunicationDeviceDispatcher(
            ICommunicationDeviceDispatcher dispatcher);

    boolean setAdditionalOutputDeviceDelay(in AudioDeviceAttributes device, long delayMillis);

    long getAdditionalOutputDeviceDelay(in AudioDeviceAttributes device);

    long getMaxAdditionalOutputDeviceDelay(in AudioDeviceAttributes device);
}
Loading