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