1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 21 import java.util.ArrayList; 22 import java.util.List; 23 24 /** 25 * The EncoderCapabilities class is used to retrieve the 26 * capabilities for different video and audio 27 * encoders supported on a specific Android platform. 28 * {@hide} 29 */ 30 public class EncoderCapabilities 31 { 32 private static final String TAG = "EncoderCapabilities"; 33 34 /** 35 * The VideoEncoderCap class represents a video encoder's 36 * supported parameter range in: 37 * 38 * <ul> 39 * <li>Resolution: the frame size (width/height) in pixels; 40 * <li>Bit rate: the compressed output bit rate in bits per second; 41 * <li>Frame rate: the output number of frames per second. 42 * </ul> 43 * 44 */ 45 static public class VideoEncoderCap { 46 // These are not modifiable externally, thus are public accessible 47 @UnsupportedAppUsage 48 public final int mCodec; // @see android.media.MediaRecorder.VideoEncoder 49 public final int mMinBitRate; // min bit rate (bps) 50 public final int mMaxBitRate; // max bit rate (bps) 51 public final int mMinFrameRate; // min frame rate (fps) 52 public final int mMaxFrameRate; // max frame rate (fps) 53 @UnsupportedAppUsage 54 public final int mMinFrameWidth; // min frame width (pixel) 55 @UnsupportedAppUsage 56 public final int mMaxFrameWidth; // max frame width (pixel) 57 @UnsupportedAppUsage 58 public final int mMinFrameHeight; // min frame height (pixel) 59 @UnsupportedAppUsage 60 public final int mMaxFrameHeight; // max frame height (pixel) 61 62 // Private constructor called by JNI VideoEncoderCap(int codec, int minBitRate, int maxBitRate, int minFrameRate, int maxFrameRate, int minFrameWidth, int maxFrameWidth, int minFrameHeight, int maxFrameHeight)63 private VideoEncoderCap(int codec, 64 int minBitRate, int maxBitRate, 65 int minFrameRate, int maxFrameRate, 66 int minFrameWidth, int maxFrameWidth, 67 int minFrameHeight, int maxFrameHeight) { 68 mCodec = codec; 69 mMinBitRate = minBitRate; 70 mMaxBitRate = maxBitRate; 71 mMinFrameRate = minFrameRate; 72 mMaxFrameRate = maxFrameRate; 73 mMinFrameWidth = minFrameWidth; 74 mMaxFrameWidth = maxFrameWidth; 75 mMinFrameHeight = minFrameHeight; 76 mMaxFrameHeight = maxFrameHeight; 77 } 78 }; 79 80 /** 81 * The AudioEncoderCap class represents an audio encoder's 82 * parameter range in: 83 * 84 * <ul> 85 * <li>Bit rate: the compressed output bit rate in bits per second; 86 * <li>Sample rate: the sampling rate used for recording the audio in samples per second; 87 * <li>Number of channels: the number of channels the audio is recorded. 88 * </ul> 89 * 90 */ 91 static public class AudioEncoderCap { 92 // These are not modifiable externally, thus are public accessible 93 public final int mCodec; // @see android.media.MediaRecorder.AudioEncoder 94 public final int mMinChannels, mMaxChannels; // min and max number of channels 95 public final int mMinSampleRate, mMaxSampleRate; // min and max sample rate (hz) 96 public final int mMinBitRate, mMaxBitRate; // min and max bit rate (bps) 97 98 // Private constructor called by JNI AudioEncoderCap(int codec, int minBitRate, int maxBitRate, int minSampleRate, int maxSampleRate, int minChannels, int maxChannels)99 private AudioEncoderCap(int codec, 100 int minBitRate, int maxBitRate, 101 int minSampleRate, int maxSampleRate, 102 int minChannels, int maxChannels) { 103 mCodec = codec; 104 mMinBitRate = minBitRate; 105 mMaxBitRate = maxBitRate; 106 mMinSampleRate = minSampleRate; 107 mMaxSampleRate = maxSampleRate; 108 mMinChannels = minChannels; 109 mMaxChannels = maxChannels; 110 } 111 }; 112 113 static { 114 System.loadLibrary("media_jni"); native_init()115 native_init(); 116 } 117 118 /** 119 * Returns the array of supported output file formats. 120 * @see android.media.MediaRecorder.OutputFormat 121 */ getOutputFileFormats()122 public static int[] getOutputFileFormats() { 123 int nFormats = native_get_num_file_formats(); 124 if (nFormats == 0) return null; 125 126 int[] formats = new int[nFormats]; 127 for (int i = 0; i < nFormats; ++i) { 128 formats[i] = native_get_file_format(i); 129 } 130 return formats; 131 } 132 133 /** 134 * Returns the capabilities of the supported video encoders. 135 * @see android.media.EncoderCapabilities.VideoEncoderCap 136 */ 137 @UnsupportedAppUsage getVideoEncoders()138 public static List<VideoEncoderCap> getVideoEncoders() { 139 int nEncoders = native_get_num_video_encoders(); 140 if (nEncoders == 0) return null; 141 142 List<VideoEncoderCap> encoderList = new ArrayList<VideoEncoderCap>(); 143 for (int i = 0; i < nEncoders; ++i) { 144 encoderList.add(native_get_video_encoder_cap(i)); 145 } 146 return encoderList; 147 } 148 149 /** 150 * Returns the capabilities of the supported audio encoders. 151 * @see android.media.EncoderCapabilities.AudioEncoderCap 152 */ getAudioEncoders()153 public static List<AudioEncoderCap> getAudioEncoders() { 154 int nEncoders = native_get_num_audio_encoders(); 155 if (nEncoders == 0) return null; 156 157 List<AudioEncoderCap> encoderList = new ArrayList<AudioEncoderCap>(); 158 for (int i = 0; i < nEncoders; ++i) { 159 encoderList.add(native_get_audio_encoder_cap(i)); 160 } 161 return encoderList; 162 } 163 164 EncoderCapabilities()165 private EncoderCapabilities() {} // Don't call me 166 167 // Implemented by JNI native_init()168 private static native final void native_init(); native_get_num_file_formats()169 private static native final int native_get_num_file_formats(); native_get_file_format(int index)170 private static native final int native_get_file_format(int index); native_get_num_video_encoders()171 private static native final int native_get_num_video_encoders(); native_get_video_encoder_cap(int index)172 private static native final VideoEncoderCap native_get_video_encoder_cap(int index); native_get_num_audio_encoders()173 private static native final int native_get_num_audio_encoders(); native_get_audio_encoder_cap(int index)174 private static native final AudioEncoderCap native_get_audio_encoder_cap(int index); 175 } 176