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

Commit 3008f627 authored by Chong Zhang's avatar Chong Zhang Committed by Android (Google) Code Review
Browse files

Merge "ExifInterface: prefer metadata from image track"

parents 8ed09f85 869d1234
Loading
Loading
Loading
Loading
+49 −34
Original line number Diff line number Diff line
@@ -2564,15 +2564,33 @@ public class ExifInterface {
                });
            }

            String hasImage = retriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_HAS_IMAGE);
            String hasVideo = retriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO);

            final String METADATA_HAS_VIDEO_VALUE_YES = "yes";
            if (METADATA_HAS_VIDEO_VALUE_YES.equals(hasVideo)) {
                String width = retriever.extractMetadata(
            String width = null;
            String height = null;
            String rotation = null;
            final String METADATA_VALUE_YES = "yes";
            // If the file has both image and video, prefer image info over video info.
            // App querying ExifInterface is most likely using the bitmap path which
            // picks the image first.
            if (METADATA_VALUE_YES.equals(hasImage)) {
                width = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_IMAGE_WIDTH);
                height = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_IMAGE_HEIGHT);
                rotation = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_IMAGE_ROTATION);
            } else if (METADATA_VALUE_YES.equals(hasVideo)) {
                width = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
                String height = retriever.extractMetadata(
                height = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
                rotation = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
            }

            if (width != null) {
                mAttributes[IFD_TYPE_PRIMARY].put(TAG_IMAGE_WIDTH,
@@ -2584,8 +2602,6 @@ public class ExifInterface {
                        ExifAttribute.createUShort(Integer.parseInt(height), mExifByteOrder));
            }

                String rotation = retriever.extractMetadata(
                        MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
            if (rotation != null) {
                int orientation = ExifInterface.ORIENTATION_NORMAL;

@@ -2609,7 +2625,6 @@ public class ExifInterface {
            if (DEBUG) {
                Log.d(TAG, "Heif meta: " + width + "x" + height + ", rotation " + rotation);
            }
            }
        } finally {
            retriever.release();
        }