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

Commit 74e504c4 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Android (Google) Code Review
Browse files

Merge "Spatializer: API to query real channel masks being spatialized" into main

parents 3b0bf852 a4d8368e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25615,6 +25615,7 @@ package android.media {
    method public void addOnSpatializerStateChangedListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.Spatializer.OnSpatializerStateChangedListener);
    method public boolean canBeSpatialized(@NonNull android.media.AudioAttributes, @NonNull android.media.AudioFormat);
    method public int getImmersiveAudioLevel();
    method @FlaggedApi("android.media.audio.spatializer_capabilities") @NonNull public java.util.List<java.lang.Integer> getSpatializedChannelMasks();
    method public boolean isAvailable();
    method public boolean isEnabled();
    method public boolean isHeadTrackerAvailable();
+3 −0
Original line number Diff line number Diff line
@@ -640,6 +640,9 @@ interface IAudioService {

    boolean canBeSpatialized(in AudioAttributes aa, in AudioFormat af);

    /* Returns a List<Integer> */
    List getSpatializedChannelMasks();

    void registerSpatializerCallback(in ISpatializerCallback cb);

    void unregisterSpatializerCallback(in ISpatializerCallback cb);
+26 −0
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@

package android.media;

import static android.media.audio.Flags.FLAG_SPATIALIZER_CAPABILITIES;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -35,6 +38,7 @@ import com.android.internal.annotations.GuardedBy;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
@@ -526,6 +530,28 @@ public class Spatializer {
        }
    }

    /**
     * Returns a list of channel masks that represent the widest channel masks the spatializer
     * is capable of rendering with individual channel positions.
     * For instance a spatializer may only support virtual speaker positions for 5.1, it would
     * therefore return {@link AudioFormat#CHANNEL_OUT_5POINT1}. But it would still return
     * <code>true</code> when querying {@link #canBeSpatialized(AudioAttributes, AudioFormat)} it
     * with a channel mask of {@link AudioFormat#CHANNEL_OUT_7POINT1POINT2}: the sound present
     * in each channel would still be heard, but the sounds from the rear, side and top pairs would
     * be mixed together, and be spatialized at the same location.
     * @return a list of channel masks following the <code>CHANNEL_OUT_*</code> output channel
     *     definitions found in {@link AudioFormat}.
     */
    @FlaggedApi(FLAG_SPATIALIZER_CAPABILITIES)
    public @NonNull List<Integer> getSpatializedChannelMasks() {
        try {
            return mAm.getService().getSpatializedChannelMasks();
        } catch (RemoteException e) {
            Log.e(TAG, "Error querying getSpatializedChannelMasks", e);
            return Collections.emptyList();
        }
    }

    /**
     * Adds a listener to be notified of changes to the enabled state of the
     * {@code Spatializer}.
+4 −0
Original line number Diff line number Diff line
@@ -11434,6 +11434,10 @@ public class AudioService extends IAudioService.Stub
        return mSpatializerHelper.canBeSpatialized(attributes, format);
    }
    public @NonNull List<Integer> getSpatializedChannelMasks() {
        return mSpatializerHelper.getSpatializedChannelMasks();
    }
    /** @see Spatializer.SpatializerInfoDispatcherStub */
    public void registerSpatializerCallback(
            @NonNull ISpatializerCallback cb) {
+19 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ import com.android.server.utils.EventLogger;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
@@ -1100,6 +1102,23 @@ public class SpatializerHelper {
        return able;
    }

    synchronized @NonNull List<Integer> getSpatializedChannelMasks() {
        if (!checkSpatializer("getSpatializedChannelMasks")) {
            return Collections.emptyList();
        }
        try {
            final int[] nativeMasks = new int[0]; // FIXME mSpat query goes here
            for (int i = 0; i < nativeMasks.length; i++) {
                nativeMasks[i] = AudioFormat.convertNativeChannelMaskToOutMask(nativeMasks[i]);
            }
            final List<Integer> masks = Arrays.stream(nativeMasks).boxed().toList();
            return masks;
        } catch (Exception e) { // just catch Exception in case nativeMasks is null
            Log.e(TAG, "Error calling getSpatializedChannelMasks", e);
            return Collections.emptyList();
        }
    }

    //------------------------------------------------------
    // head tracking
    final RemoteCallbackList<ISpatializerHeadTrackingModeCallback> mHeadTrackingModeCallbacks =