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

Commit 9a964b91 authored by Vlad Popa's avatar Vlad Popa Committed by Android (Google) Code Review
Browse files

Merge "CTA2075: Optimize data sent to client" into main

parents 3b102424 65ff422a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -739,7 +739,7 @@ interface IAudioService {

    oneway void stopLoudnessCodecUpdates(int piid);

    oneway void addLoudnessCodecInfo(int piid, in LoudnessCodecInfo codecInfo);
    oneway void addLoudnessCodecInfo(int piid, int mediaCodecHash, in LoudnessCodecInfo codecInfo);

    oneway void removeLoudnessCodecInfo(int piid, in LoudnessCodecInfo codecInfo);

+7 −9
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -284,7 +283,7 @@ public class LoudnessCodecConfigurator {
            }

            if (piid != PLAYER_PIID_INVALID) {
                mLcDispatcher.addLoudnessCodecInfo(piid, mcInfo);
                mLcDispatcher.addLoudnessCodecInfo(piid, mediaCodec.hashCode(), mcInfo);
            }
        }
    }
@@ -305,7 +304,7 @@ public class LoudnessCodecConfigurator {
    public void removeMediaCodec(@NonNull MediaCodec mediaCodec) {
        int piid = PLAYER_PIID_INVALID;
        LoudnessCodecInfo mcInfo;
        AtomicBoolean removed = new AtomicBoolean(false);
        AtomicBoolean removeInfo = new AtomicBoolean(false);

        mcInfo = getCodecInfo(Objects.requireNonNull(mediaCodec,
                "MediaCodec for removeMediaCodec cannot be null"));
@@ -316,16 +315,17 @@ public class LoudnessCodecConfigurator {
                    piid = mAudioTrack.getPlayerIId();
                }
                mMediaCodecs.computeIfPresent(mcInfo, (format, mcs) -> {
                    removed.set(mcs.remove(mediaCodec));
                    mcs.remove(mediaCodec);
                    if (mcs.isEmpty()) {
                        // remove the entry
                        removeInfo.set(true);
                        return null;
                    }
                    return mcs;
                });
            }

            if (piid != PLAYER_PIID_INVALID && removed.get()) {
            if (piid != PLAYER_PIID_INVALID && removeInfo.get()) {
                mLcDispatcher.removeLoudnessCodecInfo(piid, mcInfo);
            }
        }
@@ -375,9 +375,9 @@ public class LoudnessCodecConfigurator {
    }

    /** @hide */
    /*package*/ List<MediaCodec> getRegisteredMediaCodecList() {
    /*package*/ HashMap<LoudnessCodecInfo, Set<MediaCodec>> getRegisteredMediaCodecs() {
        synchronized (mConfiguratorLock) {
            return mMediaCodecs.values().stream().flatMap(Collection::stream).toList();
            return mMediaCodecs;
        }
    }

@@ -429,8 +429,6 @@ public class LoudnessCodecConfigurator {
        lci.isDownmixing = outputFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)
                < inputFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);

        lci.mediaCodecHashCode = mediaCodec.hashCode();

        return lci;
    }
}
+34 −16
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;

/**
@@ -71,33 +72,49 @@ public class LoudnessCodecDispatcher implements CallbackUtil.DispatcherStub {

        @Override
        public void dispatchLoudnessCodecParameterChange(int piid, PersistableBundle params) {
            if (DEBUG) {
                Log.d(TAG, "dispatchLoudnessCodecParameterChange for piid " + piid
                        + " persistable bundle: " + params);
            }
            mLoudnessListenerMgr.callListeners(listener -> {
                synchronized (mLock) {
                    mConfiguratorListener.computeIfPresent(listener, (l, lcConfig) -> {
                        // send the appropriate bundle for the user to update
                        if (lcConfig.getAssignedTrackPiid() == piid) {
                            final List<MediaCodec> mediaCodecs =
                                    lcConfig.getRegisteredMediaCodecList();
                            for (MediaCodec mediaCodec : mediaCodecs) {
                                final String infoKey = Integer.toString(mediaCodec.hashCode());
                            final HashMap<LoudnessCodecInfo, Set<MediaCodec>> mediaCodecsMap =
                                    lcConfig.getRegisteredMediaCodecs();
                            for (LoudnessCodecInfo codecInfo : mediaCodecsMap.keySet()) {
                                final String infoKey = Integer.toString(codecInfo.hashCode());
                                Bundle bundle = null;
                                if (params.containsKey(infoKey)) {
                                    Bundle bundle = new Bundle(
                                            params.getPersistableBundle(infoKey));
                                    if (DEBUG) {
                                        Log.d(TAG,
                                                "Received for piid " + piid + " bundle: " + bundle);
                                    bundle = new Bundle(params.getPersistableBundle(infoKey));
                                }

                                final Set<MediaCodec> mediaCodecs = mediaCodecsMap.get(codecInfo);
                                for (MediaCodec mediaCodec : mediaCodecs) {
                                    final String mediaCodecKey = Integer.toString(
                                            mediaCodec.hashCode());
                                    if (bundle == null && !params.containsKey(mediaCodecKey)) {
                                        continue;
                                    }
                                    boolean canBreak = false;
                                    if (bundle == null) {
                                        // key was set by media codec hash to update single codec
                                        bundle = new Bundle(
                                                params.getPersistableBundle(mediaCodecKey));
                                        canBreak = true;
                                    }
                                    bundle =
                                            LoudnessCodecUpdatesDispatcherStub.filterLoudnessParams(
                                                    l.onLoudnessCodecUpdate(mediaCodec, bundle));
                                    if (DEBUG) {
                                        Log.d(TAG, "User changed for piid " + piid
                                                + " to filtered bundle: " + bundle);
                                    }
                                                    l.onLoudnessCodecUpdate(mediaCodec,
                                                            bundle));

                                    if (!bundle.isDefinitelyEmpty()) {
                                        mediaCodec.setParameters(bundle);
                                    }
                                    if (canBreak) {
                                        break;
                                    }
                                }
                            }
                        }
@@ -221,9 +238,10 @@ public class LoudnessCodecDispatcher implements CallbackUtil.DispatcherStub {
    }

    /** @hide */
    public void addLoudnessCodecInfo(int piid, @NonNull LoudnessCodecInfo mcInfo) {
    public void addLoudnessCodecInfo(int piid, int mediaCodecHash,
            @NonNull LoudnessCodecInfo mcInfo) {
        try {
            mAudioService.addLoudnessCodecInfo(piid, mcInfo);
            mAudioService.addLoudnessCodecInfo(piid, mediaCodecHash, mcInfo);
        }  catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
+0 −1
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ parcelable LoudnessCodecInfo {
        CODEC_METADATA_TYPE_DTS_UHD = 6
    }

    int mediaCodecHashCode;
    CodecMetadataType metadataType;
    boolean isDownmixing;
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ public class LoudnessCodecConfiguratorTest {
        verify(mAudioService).startLoudnessCodecUpdates(eq(track.getPlayerIId()), anyList());

        mLcc.addMediaCodec(createAndConfigureMediaCodec());
        verify(mAudioService).addLoudnessCodecInfo(eq(track.getPlayerIId()), any());
        verify(mAudioService).addLoudnessCodecInfo(eq(track.getPlayerIId()), anyInt(), any());
    }

    @Test
Loading