CamcorderProfile.java revision 4af0dfd6cbc13fa6a89ec1430cbe6f619cd64d8a
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
19/**
20 * The CamcorderProfile class is used to retrieve the
21 * predefined camcorder profile settings for camcorder applications.
22 * These settings are read-only.
23 *
24 * The compressed output from a recording session with a given
25 * CamcorderProfile contains two tracks: one for auido and one for video.
26 *
27 * <p>Each profile specifies the following set of parameters:
28 * <ul>
29 * <li> The file output format
30 * <li> Video codec format
31 * <li> Video bit rate in bits per second
32 * <li> Video frame rate in frames per second
33 * <li> Video frame width and height,
34 * <li> Audio codec format
35 * <li> Audio bit rate in bits per second,
36 * <li> Audio sample rate
37 * <li> Number of audio channels for recording.
38 * </ul>
39 */
40public class CamcorderProfile
41{
42    // Do not change these values/ordinals without updating their counterpart
43    // in include/media/MediaProfiles.h!
44
45    /**
46     * Quality level corresponding to the lowest available resolution.
47     */
48    public static final int QUALITY_LOW  = 0;
49
50    /**
51     * Quality level corresponding to the highest available resolution.
52     */
53    public static final int QUALITY_HIGH = 1;
54
55    /**
56     * Quality level corresponding to the qcif (176 × 144) resolution.
57     */
58    private static final int QUALITY_QCIF = 2;
59
60    /**
61     * Quality level corresponding to the 480p (720 x 480) resolution.
62     */
63    private static final int QUALITY_480P = 3;
64
65    /**
66     * Quality level corresponding to the 720p (1280 x 720) resolution.
67     */
68    private static final int QUALITY_720P = 4;
69
70    /**
71     * Quality level corresponding to the 1080p (1920 x 1088) resolution.
72     */
73    private static final int QUALITY_1080P = 5;
74
75    /**
76     * Time lapse quality level corresponding to the lowest available resolution.
77     */
78    private static final int QUALITY_TIME_LAPSE_LOW  = 1000;
79
80    /**
81     * Time lapse quality level corresponding to the highest available resolution.
82     */
83    private static final int QUALITY_TIME_LAPSE_HIGH = 1001;
84
85    /**
86     * Time lapse quality level corresponding to the qcif (176 × 144) resolution.
87     */
88    private static final int QUALITY_TIME_LAPSE_QCIF = 1002;
89
90    /**
91     * Time lapse quality level corresponding to the 480p (720 x 480) resolution.
92     */
93    private static final int QUALITY_TIME_LAPSE_480P = 1003;
94
95    /**
96     * Time lapse quality level corresponding to the 720p (1280 x 720) resolution.
97     */
98    private static final int QUALITY_TIME_LAPSE_720P = 1004;
99
100    /**
101     * Time lapse quality level corresponding to the 1080p (1920 x 1088) resolution.
102     */
103    private static final int QUALITY_TIME_LAPSE_1080P = 1005;
104
105    /**
106     * Default recording duration in seconds before the session is terminated.
107     * This is useful for applications like MMS has limited file size requirement.
108     */
109    public int duration;
110
111    /**
112     * The quality level of the camcorder profile
113     */
114    public int quality;
115
116    /**
117     * The file output format of the camcorder profile
118     * @see android.media.MediaRecorder.OutputFormat
119     */
120    public int fileFormat;
121
122    /**
123     * The video encoder being used for the video track
124     * @see android.media.MediaRecorder.VideoEncoder
125     */
126    public int videoCodec;
127
128    /**
129     * The target video output bit rate in bits per second
130     */
131    public int videoBitRate;
132
133    /**
134     * The target video frame rate in frames per second
135     */
136    public int videoFrameRate;
137
138    /**
139     * The target video frame width in pixels
140     */
141    public int videoFrameWidth;
142
143    /**
144     * The target video frame height in pixels
145     */
146    public int videoFrameHeight;
147
148    /**
149     * The audio encoder being used for the audio track.
150     * @see android.media.MediaRecorder.AudioEncoder
151     */
152    public int audioCodec;
153
154    /**
155     * The target audio output bit rate in bits per second
156     */
157    public int audioBitRate;
158
159    /**
160     * The audio sampling rate used for the audio track
161     */
162    public int audioSampleRate;
163
164    /**
165     * The number of audio channels used for the audio track
166     */
167    public int audioChannels;
168
169    /**
170     * Returns the camcorder profile for the default camera at the given
171     * quality level.
172     * @param quality the target quality level for the camcorder profile
173     * @see #get(int, int)
174     */
175    public static CamcorderProfile get(int quality) {
176        return get(0, quality);
177    }
178
179    /**
180     * Returns the camcorder profile for the given camera at the given
181     * quality level.
182     *
183     * Quality levels QUALITY_LOW, QUALITY_HIGH are guaranteed to be supported, while
184     * other levels may or may not be supported.
185     * QUALITY_LOW refers to the lowest quality available, while QUALITY_HIGH refers to
186     * the highest quality available.
187     * QUALITY_LOW/QUALITY_HIGH have to match one of qcif, 480p, 720p, or 1080p.
188     * E.g. if the device supports 480p, 720p, and 1080p, then low is 480p and high is
189     * 1080p.
190     *
191     * A camcorder recording session with higher quality level usually has higher output
192     * bit rate, better video and/or audio recording quality, larger video frame
193     * resolution and higher audio sampling rate, etc, than those with lower quality
194     * level.
195     *
196     * @param cameraId the id for the camera
197     * @param quality the target quality level for the camcorder profile.
198     */
199    public static CamcorderProfile get(int cameraId, int quality) {
200        if (!((quality >= QUALITY_LOW && quality <= QUALITY_1080P) ||
201                (quality >= QUALITY_TIME_LAPSE_LOW && quality <= QUALITY_TIME_LAPSE_1080P))) {
202            String errMessage = "Unsupported quality level: " + quality;
203            throw new IllegalArgumentException(errMessage);
204        }
205        return native_get_camcorder_profile(cameraId, quality);
206    }
207
208    static {
209        System.loadLibrary("media_jni");
210        native_init();
211    }
212
213    // Private constructor called by JNI
214    private CamcorderProfile(int duration,
215                             int quality,
216                             int fileFormat,
217                             int videoCodec,
218                             int videoBitRate,
219                             int videoFrameRate,
220                             int videoWidth,
221                             int videoHeight,
222                             int audioCodec,
223                             int audioBitRate,
224                             int audioSampleRate,
225                             int audioChannels) {
226
227        this.duration         = duration;
228        this.quality          = quality;
229        this.fileFormat       = fileFormat;
230        this.videoCodec       = videoCodec;
231        this.videoBitRate     = videoBitRate;
232        this.videoFrameRate   = videoFrameRate;
233        this.videoFrameWidth  = videoWidth;
234        this.videoFrameHeight = videoHeight;
235        this.audioCodec       = audioCodec;
236        this.audioBitRate     = audioBitRate;
237        this.audioSampleRate  = audioSampleRate;
238        this.audioChannels    = audioChannels;
239    }
240
241    // Methods implemented by JNI
242    private static native final void native_init();
243    private static native final CamcorderProfile native_get_camcorder_profile(
244            int cameraId, int quality);
245}
246