From 0f26a198cea55bffcb545cf94dd092ef0ee59c14 Mon Sep 17 00:00:00 2001 From: Ray Essick Date: Wed, 16 Mar 2022 21:02:02 -0700 Subject: [PATCH] Define MediaFormat crop-related constants MediaFormat used literals "crop-left", "crop-right", crop-bottom and crop-top. Define appropriate MediaFormat.KEY_XXX for these. Bug: 178687730 Test: build, boot Test: atest android.media.codec.cts.EncodeDecodeTest Change-Id: I1782caa5ff320d3dca19272c5532466199ef72f0 --- core/api/current.txt | 4 +++ media/java/android/media/MediaCodec.java | 20 ++++++++----- media/java/android/media/MediaFormat.java | 36 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index b5493a3fa8c75..0652ec0afd6bd 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -22195,6 +22195,10 @@ package android.media { field public static final String KEY_COLOR_TRANSFER_REQUEST = "color-transfer-request"; field public static final String KEY_COMPLEXITY = "complexity"; field public static final String KEY_CREATE_INPUT_SURFACE_SUSPENDED = "create-input-buffers-suspended"; + field public static final String KEY_CROP_BOTTOM = "crop-bottom"; + field public static final String KEY_CROP_LEFT = "crop-left"; + field public static final String KEY_CROP_RIGHT = "crop-right"; + field public static final String KEY_CROP_TOP = "crop-top"; field public static final String KEY_DURATION = "durationUs"; field public static final String KEY_ENCODER_DELAY = "encoder-delay"; field public static final String KEY_ENCODER_PADDING = "encoder-padding"; diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index 4563259c31f28..e39914db4d0ff 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -223,19 +223,19 @@ import java.util.concurrent.locks.ReentrantLock; - {@code "crop-left"} + {@link MediaFormat#KEY_CROP_LEFT} Integer The left-coordinate (x) of the crop rectangle - {@code "crop-top"} + {@link MediaFormat#KEY_CROP_TOP} Integer The top-coordinate (y) of the crop rectangle - {@code "crop-right"} + {@link MediaFormat#KEY_CROP_RIGHT} Integer The right-coordinate (x) MINUS 1 of the crop rectangle - {@code "crop-bottom"} + {@link MediaFormat#KEY_CROP_BOTTOM} Integer The bottom-coordinate (y) MINUS 1 of the crop rectangle @@ -251,12 +251,16 @@ import java.util.concurrent.locks.ReentrantLock;
  MediaFormat format = decoder.getOutputFormat(…);
  int width = format.getInteger(MediaFormat.KEY_WIDTH);
- if (format.containsKey("crop-left") && format.containsKey("crop-right")) {
-     width = format.getInteger("crop-right") + 1 - format.getInteger("crop-left");
+ if (format.containsKey(MediaFormat.KEY_CROP_LEFT)
+         && format.containsKey(MediaFormat.KEY_CROP_RIGHT)) {
+     width = format.getInteger(MediaFormat.KEY_CROP_RIGHT) + 1
+                 - format.getInteger(MediaFormat.KEY_CROP_LEFT);
  }
  int height = format.getInteger(MediaFormat.KEY_HEIGHT);
- if (format.containsKey("crop-top") && format.containsKey("crop-bottom")) {
-     height = format.getInteger("crop-bottom") + 1 - format.getInteger("crop-top");
+ if (format.containsKey(MediaFormat.KEY_CROP_TOP)
+         && format.containsKey(MediaFormat.KEY_CROP_BOTTOM)) {
+     height = format.getInteger(MediaFormat.KEY_CROP_BOTTOM) + 1
+                  - format.getInteger(MediaFormat.KEY_CROP_TOP);
  }
  

diff --git a/media/java/android/media/MediaFormat.java b/media/java/android/media/MediaFormat.java index 4956dbefa240b..de193f5f05787 100644 --- a/media/java/android/media/MediaFormat.java +++ b/media/java/android/media/MediaFormat.java @@ -358,6 +358,42 @@ public final class MediaFormat { */ public static final String KEY_HEIGHT = "height"; + /** + * A key describing the bottom-coordinate (y) of the crop rectangle. + * This is the bottom-most row included in the crop frame, + * where row indices start at 0. + * Additional information on the crop rectangle semantics can be found at + * {@link android.media.MediaCodec}. + */ + public static final String KEY_CROP_BOTTOM = "crop-bottom"; + + /** + * A key describing the left-coordinate (x) of the crop rectangle. + * This is the left-most column included in the crop frame, + * where column indices start at 0. + * Additional information on the crop rectangle semantics can be found at + * {@link android.media.MediaCodec}. + */ + public static final String KEY_CROP_LEFT = "crop-left"; + + /** + * A key describing the right-coordinate (x) of the crop rectangle. + * This is the right-most column included in the crop frame, + * where column indices start at 0. + * Additional information on the crop rectangle semantics can be found at + * {@link android.media.MediaCodec}. + */ + public static final String KEY_CROP_RIGHT = "crop-right"; + + /** + * A key describing the top-coordinate (y) of the crop rectangle. + * This is the top-most row included in the crop frame, + * where row indices start at 0. + * Additional information on the crop rectangle semantics can be found at + * {@link android.media.MediaCodec}. + */ + public static final String KEY_CROP_TOP = "crop-top"; + /** * A key describing the maximum expected width of the content in a video * decoder format, in case there are resolution changes in the video content.