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

Commit 32f6c7c0 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Improve thumbnail generation utilities.

The existing APIs were pretty limited by only accepting a "kind"
value, so improve them to accept an arbitrary size, and offer a way
to cancel requests when no longer needed.

The older APIs were a mix of both public and @UnsupportedAppUsage,
so mark them all both public and deprecated so we can clearly steer
developers towards better options.  (The deprecated methods are
implemented using the new APIs internally for sanity.)

Use modern ImageDecode internally, which is more robust than
BitmapFactory.  Add CTS to confirm that we generate thumbnails of
reasonable sizes.

Bug: 119887587
Test: atest android.media.cts.ThumbnailUtilsTest
Change-Id: I4ca35569ad5c661b327a0cb24a48ebc21f6087b7
parent b0c363b2
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -24978,8 +24978,9 @@ package android.media {
    field public static final int RATING_KEY_BY_USER = 268435457; // 0x10000001
  }
  public class MediaMetadataRetriever {
  public class MediaMetadataRetriever implements java.lang.AutoCloseable {
    ctor public MediaMetadataRetriever();
    method public void close();
    method public java.lang.String extractMetadata(int);
    method public byte[] getEmbeddedPicture();
    method public android.graphics.Bitmap getFrameAtIndex(int, android.media.MediaMetadataRetriever.BitmapParams);
@@ -26066,7 +26067,12 @@ package android.media {
  public class ThumbnailUtils {
    ctor public ThumbnailUtils();
    method public static android.graphics.Bitmap createVideoThumbnail(java.lang.String, int);
    method public static deprecated android.graphics.Bitmap createAudioThumbnail(java.lang.String, int);
    method public static android.graphics.Bitmap createAudioThumbnail(java.io.File, android.util.Size, android.os.CancellationSignal) throws java.io.IOException;
    method public static deprecated android.graphics.Bitmap createImageThumbnail(java.lang.String, int);
    method public static android.graphics.Bitmap createImageThumbnail(java.io.File, android.util.Size, android.os.CancellationSignal) throws java.io.IOException;
    method public static deprecated android.graphics.Bitmap createVideoThumbnail(java.lang.String, int);
    method public static android.graphics.Bitmap createVideoThumbnail(java.io.File, android.util.Size, android.os.CancellationSignal) throws java.io.IOException;
    method public static android.graphics.Bitmap extractThumbnail(android.graphics.Bitmap, int, int);
    method public static android.graphics.Bitmap extractThumbnail(android.graphics.Bitmap, int, int, int);
    field public static final int OPTIONS_RECYCLE_INPUT = 2; // 0x2
+3 −0
Original line number Diff line number Diff line
@@ -1002,6 +1002,7 @@ public final class MediaStore {
        public static final int MICRO_KIND = 3;

        public static final Point MINI_SIZE = new Point(512, 384);
        public static final Point FULL_SCREEN_SIZE = new Point(1024, 786);
        public static final Point MICRO_SIZE = new Point(96, 96);
    }

@@ -1127,6 +1128,8 @@ public final class MediaStore {
            final Point size;
            if (kind == ThumbnailConstants.MICRO_KIND) {
                size = ThumbnailConstants.MICRO_SIZE;
            } else if (kind == ThumbnailConstants.FULL_SCREEN_KIND) {
                size = ThumbnailConstants.FULL_SCREEN_SIZE;
            } else if (kind == ThumbnailConstants.MINI_KIND) {
                size = ThumbnailConstants.MINI_SIZE;
            } else {
+6 −2
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ import java.util.Map;
 * MediaMetadataRetriever class provides a unified interface for retrieving
 * frame and meta data from an input media file.
 */
public class MediaMetadataRetriever
{
public class MediaMetadataRetriever implements AutoCloseable {
    static {
        System.loadLibrary("media_jni");
        native_init();
@@ -672,6 +671,11 @@ public class MediaMetadataRetriever
    @UnsupportedAppUsage
    private native byte[] getEmbeddedPicture(int pictureType);

    @Override
    public void close() {
        release();
    }

    /**
     * Call it when one is done with the object. This method releases the memory
     * allocated internally.
+256 −310

File changed.

Preview size limit exceeded, changes collapsed.