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

Commit f50ac2e3 authored by Kuowei Li's avatar Kuowei Li Committed by Andy Hung
Browse files

audio: add implementation for TV related API

1. TunerConfiguration.
2. AudioDescriptionMixLevel getter/setter.
3. DualMonoMode getter/setter.
4. PlaybackRate getter/setter.

Test: TIS player with instrumented HAL
Test: atest AudioTrackTest#testTunerConfiguration
Test: atest AudioTrackTest#testDualMonoMode
Test: atest AudioTrackTest#testAudioDescriptionMixLevel
Test: atest AudioManagerTest#testGetAdditionalOutputDeviceDelay
Bug: 173482792
Change-Id: I47b022154983283aeeac41cf506818009e88995b
parent 285be6fe
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
@@ -5625,8 +5625,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();
        }
    }

    /**
@@ -5641,8 +5645,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();
        }
    }

    /**
@@ -5659,8 +5666,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
@@ -1270,11 +1270,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
@@ -356,4 +356,10 @@ interface IAudioService {
    boolean isHomeSoundEffectEnabled();

    oneway void setHomeSoundEffectEnabled(boolean enabled);

    boolean setAdditionalOutputDeviceDelay(in AudioDeviceAttributes device, long delayMillis);

    long getAdditionalOutputDeviceDelay(in AudioDeviceAttributes device);

    long getMaxAdditionalOutputDeviceDelay(in AudioDeviceAttributes device);
}
Loading