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