• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.os.Build;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 /**
26  * The EncoderCapabilities class is used to retrieve the
27  * capabilities for different video and audio
28  * encoders supported on a specific Android platform.
29  * {@hide}
30  */
31 public class EncoderCapabilities
32 {
33     private static final String TAG = "EncoderCapabilities";
34 
35     /**
36      * The VideoEncoderCap class represents a video encoder's
37      * supported parameter range in:
38      *
39      * <ul>
40      * <li>Resolution: the frame size (width/height) in pixels;
41      * <li>Bit rate: the compressed output bit rate in bits per second;
42      * <li>Frame rate: the output number of frames per second.
43      * </ul>
44      *
45      */
46     static public class VideoEncoderCap {
47         // These are not modifiable externally, thus are public accessible
48         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
49         public final int mCodec;                // @see android.media.MediaRecorder.VideoEncoder
50         public final int mMinBitRate;           // min bit rate (bps)
51         public final int mMaxBitRate;           // max bit rate (bps)
52         public final int mMinFrameRate;         // min frame rate (fps)
53         public final int mMaxFrameRate;         // max frame rate (fps)
54         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
55         public final int mMinFrameWidth;        // min frame width (pixel)
56         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
57         public final int mMaxFrameWidth;        // max frame width (pixel)
58         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
59         public final int mMinFrameHeight;       // min frame height (pixel)
60         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
61         public final int mMaxFrameHeight;       // max frame height (pixel)
62 
63         // Private constructor called by JNI
VideoEncoderCap(int codec, int minBitRate, int maxBitRate, int minFrameRate, int maxFrameRate, int minFrameWidth, int maxFrameWidth, int minFrameHeight, int maxFrameHeight)64         private VideoEncoderCap(int codec,
65                                 int minBitRate, int maxBitRate,
66                                 int minFrameRate, int maxFrameRate,
67                                 int minFrameWidth, int maxFrameWidth,
68                                 int minFrameHeight, int maxFrameHeight) {
69             mCodec = codec;
70             mMinBitRate = minBitRate;
71             mMaxBitRate = maxBitRate;
72             mMinFrameRate = minFrameRate;
73             mMaxFrameRate = maxFrameRate;
74             mMinFrameWidth = minFrameWidth;
75             mMaxFrameWidth = maxFrameWidth;
76             mMinFrameHeight = minFrameHeight;
77             mMaxFrameHeight = maxFrameHeight;
78         }
79     };
80 
81     /**
82      * The AudioEncoderCap class represents an audio encoder's
83      * parameter range in:
84      *
85      * <ul>
86      * <li>Bit rate: the compressed output bit rate in bits per second;
87      * <li>Sample rate: the sampling rate used for recording the audio in samples per second;
88      * <li>Number of channels: the number of channels the audio is recorded.
89      * </ul>
90      *
91      */
92     static public class AudioEncoderCap {
93         // These are not modifiable externally, thus are public accessible
94         public final int mCodec;                         // @see android.media.MediaRecorder.AudioEncoder
95         public final int mMinChannels, mMaxChannels;     // min and max number of channels
96         public final int mMinSampleRate, mMaxSampleRate; // min and max sample rate (hz)
97         public final int mMinBitRate, mMaxBitRate;       // min and max bit rate (bps)
98 
99         // Private constructor called by JNI
AudioEncoderCap(int codec, int minBitRate, int maxBitRate, int minSampleRate, int maxSampleRate, int minChannels, int maxChannels)100         private AudioEncoderCap(int codec,
101                                 int minBitRate, int maxBitRate,
102                                 int minSampleRate, int maxSampleRate,
103                                 int minChannels, int maxChannels) {
104            mCodec = codec;
105            mMinBitRate = minBitRate;
106            mMaxBitRate = maxBitRate;
107            mMinSampleRate = minSampleRate;
108            mMaxSampleRate = maxSampleRate;
109            mMinChannels = minChannels;
110            mMaxChannels = maxChannels;
111        }
112     };
113 
114     static {
115         System.loadLibrary("media_jni");
native_init()116         native_init();
117     }
118 
119     /**
120      * Returns the array of supported output file formats.
121      * @see android.media.MediaRecorder.OutputFormat
122      */
getOutputFileFormats()123     public static int[] getOutputFileFormats() {
124         int nFormats = native_get_num_file_formats();
125         if (nFormats == 0) return null;
126 
127         int[] formats = new int[nFormats];
128         for (int i = 0; i < nFormats; ++i) {
129             formats[i] = native_get_file_format(i);
130         }
131         return formats;
132     }
133 
134     /**
135      * Returns the capabilities of the supported video encoders.
136      * @see android.media.EncoderCapabilities.VideoEncoderCap
137      */
138     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getVideoEncoders()139     public static List<VideoEncoderCap> getVideoEncoders() {
140         int nEncoders = native_get_num_video_encoders();
141         if (nEncoders == 0) return null;
142 
143         List<VideoEncoderCap> encoderList = new ArrayList<VideoEncoderCap>();
144         for (int i = 0; i < nEncoders; ++i) {
145             encoderList.add(native_get_video_encoder_cap(i));
146         }
147         return encoderList;
148     }
149 
150     /**
151      * Returns the capabilities of the supported audio encoders.
152      * @see android.media.EncoderCapabilities.AudioEncoderCap
153      */
getAudioEncoders()154     public static List<AudioEncoderCap> getAudioEncoders() {
155         int nEncoders = native_get_num_audio_encoders();
156         if (nEncoders == 0) return null;
157 
158         List<AudioEncoderCap> encoderList = new ArrayList<AudioEncoderCap>();
159         for (int i = 0; i < nEncoders; ++i) {
160             encoderList.add(native_get_audio_encoder_cap(i));
161         }
162         return encoderList;
163     }
164 
165 
EncoderCapabilities()166     private EncoderCapabilities() {}  // Don't call me
167 
168     // Implemented by JNI
native_init()169     private static native final void native_init();
native_get_num_file_formats()170     private static native final int native_get_num_file_formats();
native_get_file_format(int index)171     private static native final int native_get_file_format(int index);
native_get_num_video_encoders()172     private static native final int native_get_num_video_encoders();
native_get_video_encoder_cap(int index)173     private static native final VideoEncoderCap native_get_video_encoder_cap(int index);
native_get_num_audio_encoders()174     private static native final int native_get_num_audio_encoders();
native_get_audio_encoder_cap(int index)175     private static native final AudioEncoderCap native_get_audio_encoder_cap(int index);
176 }
177