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

Commit 69306143 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "MediaCodecInfo: consider only critical flags for level support check"...

Merge "MediaCodecInfo: consider only critical flags for level support check" into udc-dev am: 4b084316

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



Change-Id: I1f8f84279aadf1cff8772c12b83a6660e2b35677
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d9860cba 4b084316
Loading
Loading
Loading
Loading
+38 −7
Original line number Original line Diff line number Diff line
@@ -934,15 +934,27 @@ public final class MediaCodecInfo {
                    }
                    }
                }
                }
                levelCaps = createFromProfileLevel(mMime, profile, maxLevel);
                levelCaps = createFromProfileLevel(mMime, profile, maxLevel);
                // remove profile from this format otherwise levelCaps.isFormatSupported will
                // We must remove the profile from this format otherwise levelCaps.isFormatSupported
                // get into this same conditon and loop forever.
                // will get into this same condition and loop forever. Furthermore, since levelCaps
                Map<String, Object> mapWithoutProfile = new HashMap<>(map);
                // does not contain features and bitrate specific keys, keep only keys relevant for
                mapWithoutProfile.remove(MediaFormat.KEY_PROFILE);
                // a level check.
                MediaFormat formatWithoutProfile = new MediaFormat(mapWithoutProfile);
                Map<String, Object> levelCriticalFormatMap = new HashMap<>(map);
                if (levelCaps != null && !levelCaps.isFormatSupported(formatWithoutProfile)) {
                final Set<String> criticalKeys =
                    isVideo() ? VideoCapabilities.VIDEO_LEVEL_CRITICAL_FORMAT_KEYS :
                    isAudio() ? AudioCapabilities.AUDIO_LEVEL_CRITICAL_FORMAT_KEYS :
                    null;

                // critical keys will always contain KEY_MIME, but should also contain others to be
                // meaningful
                if (criticalKeys != null && criticalKeys.size() > 1 && levelCaps != null) {
                    levelCriticalFormatMap.keySet().retainAll(criticalKeys);

                    MediaFormat levelCriticalFormat = new MediaFormat(levelCriticalFormatMap);
                    if (!levelCaps.isFormatSupported(levelCriticalFormat)) {
                        return false;
                        return false;
                    }
                    }
                }
                }
            }
            if (mAudioCaps != null && !mAudioCaps.supportsFormat(format)) {
            if (mAudioCaps != null && !mAudioCaps.supportsFormat(format)) {
                return false;
                return false;
            }
            }
@@ -1633,6 +1645,16 @@ public final class MediaCodecInfo {
            }
            }
        }
        }


        /* package private */
        // must not contain KEY_PROFILE
        static final Set<String> AUDIO_LEVEL_CRITICAL_FORMAT_KEYS = Set.of(
                // We don't set level-specific limits for audio codecs today. Key candidates would
                // be sample rate, bit rate or channel count.
                // MediaFormat.KEY_SAMPLE_RATE,
                // MediaFormat.KEY_CHANNEL_COUNT,
                // MediaFormat.KEY_BIT_RATE,
                MediaFormat.KEY_MIME);

        /** @hide */
        /** @hide */
        public boolean supportsFormat(MediaFormat format) {
        public boolean supportsFormat(MediaFormat format) {
            Map<String, Object> map = format.getMap();
            Map<String, Object> map = format.getMap();
@@ -2357,6 +2379,15 @@ public final class MediaCodecInfo {
            return ok;
            return ok;
        }
        }


        /* package private */
        // must not contain KEY_PROFILE
        static final Set<String> VIDEO_LEVEL_CRITICAL_FORMAT_KEYS = Set.of(
                MediaFormat.KEY_WIDTH,
                MediaFormat.KEY_HEIGHT,
                MediaFormat.KEY_FRAME_RATE,
                MediaFormat.KEY_BIT_RATE,
                MediaFormat.KEY_MIME);

        /**
        /**
         * @hide
         * @hide
         * @throws java.lang.ClassCastException */
         * @throws java.lang.ClassCastException */