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