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

Commit f3fd84ad authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Offloaded playback: use AudioAttributes in support check

AudioAttributes can influence offload support, add them in
  method to check for support

Bug: 86837964
Test: cts-tradefed run cts -m CtsMediaTestCases -t android.media.cts.AudioTrackOffloadTest#testAudioTrackOffload
Change-Id: If4037d0611ec1264d23d1779b9ac6efd9fd1244c
parent 70974aa1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23247,7 +23247,7 @@ package android.media {
    method public static boolean isHapticPlaybackSupported();
    method public boolean isMicrophoneMute();
    method public boolean isMusicActive();
    method public static boolean isOffloadedPlaybackSupported(@NonNull android.media.AudioFormat);
    method public static boolean isOffloadedPlaybackSupported(@NonNull android.media.AudioFormat, @NonNull android.media.AudioAttributes);
    method public boolean isSpeakerphoneOn();
    method public boolean isStreamMute(int);
    method public boolean isVolumeFixed();
+3 −3
Original line number Diff line number Diff line
@@ -2038,13 +2038,13 @@ android_media_AudioSystem_getStreamVolumeDB(JNIEnv *env, jobject thiz,

static jboolean
android_media_AudioSystem_isOffloadSupported(JNIEnv *env, jobject thiz,
        jint encoding, jint sampleRate, jint channelMask, jint channelIndexMask)
        jint encoding, jint sampleRate, jint channelMask, jint channelIndexMask, jint streamType)
{
    audio_offload_info_t format = AUDIO_INFO_INITIALIZER;
    format.format = (audio_format_t) audioFormatToNative(encoding);
    format.sample_rate = (uint32_t) sampleRate;
    format.channel_mask = nativeChannelMaskFromJavaChannelMasks(channelMask, channelIndexMask);
    format.stream_type = AUDIO_STREAM_MUSIC;
    format.stream_type = (audio_stream_type_t) streamType;
    format.has_video = false;
    format.is_streaming = false;
    // offload duration unknown at this point:
@@ -2292,7 +2292,7 @@ static const JNINativeMethod gMethods[] = {
                                    (void *)android_media_AudioSystem_registerRecordingCallback},
    {"systemReady", "()I", (void *)android_media_AudioSystem_systemReady},
    {"getStreamVolumeDB", "(III)F", (void *)android_media_AudioSystem_getStreamVolumeDB},
    {"native_is_offload_supported", "(IIII)Z", (void *)android_media_AudioSystem_isOffloadSupported},
    {"native_is_offload_supported", "(IIIII)Z", (void *)android_media_AudioSystem_isOffloadSupported},
    {"getMicrophones", "(Ljava/util/ArrayList;)I", (void *)android_media_AudioSystem_getMicrophones},
    {"getSurroundFormats", "(Ljava/util/Map;Z)I", (void *)android_media_AudioSystem_getSurroundFormats},
    {"setSurroundFormatEnabled", "(IZ)I", (void *)android_media_AudioSystem_setSurroundFormatEnabled},
+3 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ public class MediaPlayer2Utils {
                .setSampleRate(sampleRate)
                .setChannelMask(channelMask)
                .build();
        return AudioManager.isOffloadedPlaybackSupported(format);
        //TODO MP2 needs to pass AudioAttributes for this query, instead of using default attr
        return AudioManager.isOffloadedPlaybackSupported(format,
                (new AudioAttributes.Builder()).build());
    }
}
+8 −3
Original line number Diff line number Diff line
@@ -1488,13 +1488,18 @@ public class AudioManager {
     * it does not indicate whether the resources necessary for the offloaded playback are
     * available at that instant.
     * @param format the audio format (codec, sample rate, channels) being checked.
     * @param attributes the {@link AudioAttributes} to be used for playback
     * @return true if the given audio format can be offloaded.
     */
    public static boolean isOffloadedPlaybackSupported(@NonNull AudioFormat format) {
    public static boolean isOffloadedPlaybackSupported(@NonNull AudioFormat format,
            @NonNull AudioAttributes attributes) {
        if (format == null) {
            throw new IllegalArgumentException("Illegal null AudioFormat");
            throw new NullPointerException("Illegal null AudioFormat");
        }
        return AudioSystem.isOffloadSupported(format);
        if (attributes == null) {
            throw new NullPointerException("Illegal null AudioAttributes");
        }
        return AudioSystem.isOffloadSupported(format, attributes);
    }

    //====================================================================
+4 −3
Original line number Diff line number Diff line
@@ -1022,13 +1022,14 @@ public class AudioSystem

    public static native float getStreamVolumeDB(int stream, int index, int device);

    static boolean isOffloadSupported(@NonNull AudioFormat format) {
    static boolean isOffloadSupported(@NonNull AudioFormat format, @NonNull AudioAttributes attr) {
        return native_is_offload_supported(format.getEncoding(), format.getSampleRate(),
                format.getChannelMask(), format.getChannelIndexMask());
                format.getChannelMask(), format.getChannelIndexMask(),
                attr.getVolumeControlStream());
    }

    private static native boolean native_is_offload_supported(int encoding, int sampleRate,
            int channelMask, int channelIndexMask);
            int channelMask, int channelIndexMask, int streamType);

    public static native int getMicrophones(ArrayList<MicrophoneInfo> microphonesInfo);

Loading