From 4ef563a2a52dc235672e21612c6d713bd8c15c06 Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Wed, 21 Apr 2021 22:10:21 -0700 Subject: [PATCH] media: polish EncoderProfiles Made inner classes private. Added IntDef annotations (also to related CamcorderProfiles methods). Deprecated CamcorderProfiles.get methods. Bug: 184714224 Test: atest CamcorderProfileTest Change-Id: Ibbacb7d3c5f3558f82c109bf36a64f6a3e369b31 --- core/api/current.txt | 14 ++--- .../java/android/media/CamcorderProfile.java | 8 ++- media/java/android/media/EncoderProfiles.java | 21 +++---- media/java/android/media/MediaRecorder.java | 55 ++++++++++++++++++- 4 files changed, 72 insertions(+), 26 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index a1e93f853483d..2843a2c86c6b4 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -20958,8 +20958,8 @@ package android.media { } public class CamcorderProfile { - method public static android.media.CamcorderProfile get(int); - method public static android.media.CamcorderProfile get(int, int); + method @Deprecated public static android.media.CamcorderProfile get(int); + method @Deprecated public static android.media.CamcorderProfile get(int, int); method @Nullable public static android.media.EncoderProfiles getAll(@NonNull String, int); method public static boolean hasProfile(int); method public static boolean hasProfile(int, int); @@ -21041,14 +21041,14 @@ package android.media { field @NonNull public final java.util.UUID uuid; } - public class EncoderProfiles { + public final class EncoderProfiles { method @NonNull public java.util.List getAudioProfiles(); - method public int getDurationSeconds(); - method public int getFileFormat(); + method public int getDefaultDurationSeconds(); + method public int getRecommendedFileFormat(); method @NonNull public java.util.List getVideoProfiles(); } - public static class EncoderProfiles.AudioProfile { + public static final class EncoderProfiles.AudioProfile { method public int getBitrate(); method public int getChannels(); method public int getCodec(); @@ -21057,7 +21057,7 @@ package android.media { method public int getSampleRate(); } - public static class EncoderProfiles.VideoProfile { + public static final class EncoderProfiles.VideoProfile { method public int getBitrate(); method public int getCodec(); method public int getFrameRate(); diff --git a/media/java/android/media/CamcorderProfile.java b/media/java/android/media/CamcorderProfile.java index 2059f02c697cb..f6f0a590f0546 100644 --- a/media/java/android/media/CamcorderProfile.java +++ b/media/java/android/media/CamcorderProfile.java @@ -442,6 +442,7 @@ public class CamcorderProfile * camera on the device. If the device has no back-facing camera, this returns null. * @param quality the target quality level for the camcorder profile * @see #get(int, int) + * @deprecated Use {@link #getAll} instead */ public static CamcorderProfile get(int quality) { int numberOfCameras = Camera.getNumberOfCameras(); @@ -508,6 +509,7 @@ public class CamcorderProfile * @see #QUALITY_HIGH_SPEED_720P * @see #QUALITY_HIGH_SPEED_1080P * @see #QUALITY_HIGH_SPEED_2160P + * @deprecated Use {@link #getAll} instead * @throws IllegalArgumentException if quality is not one of the defined QUALITY_ values. */ public static CamcorderProfile get(int cameraId, int quality) { @@ -549,9 +551,9 @@ public class CamcorderProfile * resolution and higher audio sampling rate, etc, than those with lower quality * level. * - * @param cameraId the id for the camera. Numeric camera ids parsed from the list received by - * invoking {@link CameraManager#getCameraIdList} can be used as long as they - * are {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE} + * @param cameraId the id for the camera. Numeric camera ids from the list received by invoking + * {@link CameraManager#getCameraIdList} can be used as long as they are + * {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE} * and not * {@link CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL EXTERNAL}. * @param quality the target quality level for the camcorder profile. diff --git a/media/java/android/media/EncoderProfiles.java b/media/java/android/media/EncoderProfiles.java index ca3daefbdd53e..d9eabbd4903fa 100644 --- a/media/java/android/media/EncoderProfiles.java +++ b/media/java/android/media/EncoderProfiles.java @@ -51,14 +51,14 @@ import java.util.List; *
  • Number of audio channels for recording. * */ -public class EncoderProfiles +public final class EncoderProfiles { /** * Default recording duration in seconds before the session is terminated. - * This is useful for applications like MMS has limited file size requirement. + * This is useful for applications like MMS that have a limited file size requirement. * This could be 0 if there is no default recording duration. */ - public int getDurationSeconds() { + public int getDefaultDurationSeconds() { return durationSecs; } @@ -66,19 +66,19 @@ public class EncoderProfiles * Recommended output file format * @see android.media.MediaRecorder.OutputFormat */ - public int getFileFormat() { + public @MediaRecorder.OutputFormatValues int getRecommendedFileFormat() { return fileFormat; } /** * Configuration for a video encoder. */ - public static class VideoProfile { + public final static class VideoProfile { /** * The video encoder being used for the video track * @see android.media.MediaRecorder.VideoEncoder */ - public int getCodec() { + public @MediaRecorder.VideoEncoderValues int getCodec() { return codec; } @@ -238,12 +238,12 @@ public class EncoderProfiles /** * Configuration for an audio encoder. */ - public static class AudioProfile { + public final static class AudioProfile { /** * The audio encoder being used for the audio track. * @see android.media.MediaRecorder.AudioEncoder */ - public int getCodec() { + public @MediaRecorder.AudioEncoderValues int getCodec() { return codec; } @@ -326,11 +326,6 @@ public class EncoderProfiles private int bitrate; } - //static { - // System.loadLibrary("media_jni"); - //native_init(); - //} - private int durationSecs; private int fileFormat; // non-modifiable lists diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java index 5eb57dae1edc2..499034ea7c416 100644 --- a/media/java/android/media/MediaRecorder.java +++ b/media/java/android/media/MediaRecorder.java @@ -608,6 +608,25 @@ public class MediaRecorder implements AudioRouting, public static final int OGG = 11; }; + /** + * @hide + */ + @IntDef({ + OutputFormat.DEFAULT, + OutputFormat.THREE_GPP, + OutputFormat.MPEG_4, + OutputFormat.AMR_NB, + OutputFormat.AMR_WB, + OutputFormat.AAC_ADIF, + OutputFormat.AAC_ADTS, + OutputFormat.MPEG_2_TS, + OutputFormat.WEBM, + OutputFormat.HEIF, + OutputFormat.OGG, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface OutputFormatValues {} + /** * Defines the audio encoding. These constants are used with * {@link MediaRecorder#setAudioEncoder(int)}. @@ -634,6 +653,22 @@ public class MediaRecorder implements AudioRouting, public static final int OPUS = 7; } + /** + * @hide + */ + @IntDef({ + AudioEncoder.DEFAULT, + AudioEncoder.AMR_NB, + AudioEncoder.AMR_WB, + AudioEncoder.AAC, + AudioEncoder.HE_AAC, + AudioEncoder.AAC_ELD, + AudioEncoder.VORBIS, + AudioEncoder.OPUS, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface AudioEncoderValues {} + /** * Defines the video encoding. These constants are used with * {@link MediaRecorder#setVideoEncoder(int)}. @@ -651,6 +686,20 @@ public class MediaRecorder implements AudioRouting, public static final int HEVC = 5; } + /** + * @hide + */ + @IntDef({ + VideoEncoder.DEFAULT, + VideoEncoder.H263, + VideoEncoder.H264, + VideoEncoder.MPEG_4_SP, + VideoEncoder.VP8, + VideoEncoder.HEVC, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface VideoEncoderValues {} + /** * Sets the audio source to be used for recording. If this method is not * called, the output file will not contain an audio track. The source needs @@ -887,7 +936,7 @@ public class MediaRecorder implements AudioRouting, * setAudioSource()/setVideoSource(). * @see android.media.MediaRecorder.OutputFormat */ - public native void setOutputFormat(int output_format) + public native void setOutputFormat(@OutputFormatValues int output_format) throws IllegalStateException; /** @@ -970,7 +1019,7 @@ public class MediaRecorder implements AudioRouting, * setOutputFormat() or after prepare(). * @see android.media.MediaRecorder.AudioEncoder */ - public native void setAudioEncoder(int audio_encoder) + public native void setAudioEncoder(@AudioEncoderValues int audio_encoder) throws IllegalStateException; /** @@ -983,7 +1032,7 @@ public class MediaRecorder implements AudioRouting, * setOutputFormat() or after prepare() * @see android.media.MediaRecorder.VideoEncoder */ - public native void setVideoEncoder(int video_encoder) + public native void setVideoEncoder(@VideoEncoderValues int video_encoder) throws IllegalStateException; /**