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

Commit 0c423693 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extract exif data from mp4 extractor if available" into pi-dev

parents 9c2c8f5d 2cc0a2ec
Loading
Loading
Loading
Loading
+58 −34
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ import libcore.io.Streams;
/**
 * This is a class for reading and writing Exif tags in a JPEG file or a RAW image file.
 * <p>
 * Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW and RAF.
 * Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW, RAF and HEIF.
 * <p>
 * Attribute mutation is supported for JPEG image files.
 */
@@ -2524,9 +2524,6 @@ public class ExifInterface {
    private void getHeifAttributes(ByteOrderedDataInputStream in) throws IOException {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            if (mSeekableFileDescriptor != null) {
                retriever.setDataSource(mSeekableFileDescriptor);
            } else {
            retriever.setDataSource(new MediaDataSource() {
                long mPosition;

@@ -2562,8 +2559,11 @@ public class ExifInterface {
                    return -1;
                }
            });
            }

            String exifOffsetStr = retriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_EXIF_OFFSET);
            String exifLengthStr = retriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_EXIF_LENGTH);
            String hasImage = retriever.extractMetadata(
                    MediaMetadataRetriever.METADATA_KEY_HAS_IMAGE);
            String hasVideo = retriever.extractMetadata(
@@ -2622,6 +2622,30 @@ public class ExifInterface {
                        ExifAttribute.createUShort(orientation, mExifByteOrder));
            }

            if (exifOffsetStr != null && exifLengthStr != null) {
                int offset = Integer.parseInt(exifOffsetStr);
                int length = Integer.parseInt(exifLengthStr);
                if (length <= 6) {
                    throw new IOException("Invalid exif length");
                }
                in.seek(offset);
                byte[] identifier = new byte[6];
                if (in.read(identifier) != 6) {
                    throw new IOException("Can't read identifier");
                }
                offset += 6;
                length -= 6;
                if (!Arrays.equals(identifier, IDENTIFIER_EXIF_APP1)) {
                    throw new IOException("Invalid identifier");
                }

                byte[] bytes = new byte[length];
                if (in.read(bytes) != length) {
                    throw new IOException("Can't read exif");
                }
                readExifSegment(bytes, IFD_TYPE_PRIMARY);
            }

            if (DEBUG) {
                Log.d(TAG, "Heif meta: " + width + "x" + height + ", rotation " + rotation);
            }
+9 −0
Original line number Diff line number Diff line
@@ -890,5 +890,14 @@ public class MediaMetadataRetriever
     */
    public static final int METADATA_KEY_VIDEO_FRAME_COUNT = 32;

    /**
     * @hide
     */
    public static final int METADATA_KEY_EXIF_OFFSET = 33;

    /**
     * @hide
     */
    public static final int METADATA_KEY_EXIF_LENGTH = 34;
    // Add more here...
}