CamcorderProfile.java revision 09b9005769f2b717f637131578ce6cfa6bd62bd9
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    /**
43     * The output from camcorder recording sessions can have different quality levels.
44     *
45     * Currently, we define two quality levels: high quality and low quality.
46     * A camcorder recording session with high quality level usually has higher output bit
47     * rate, better video and/or audio recording quality, larger video frame
48     * resolution and higher audio sampling rate, etc, than those with low quality
49     * level.
50     *
51     * Do not change these values/ordinals without updating their counterpart
52     * in include/media/MediaProfiles.h!
53     */
54    public static final int QUALITY_LOW  = 0;
55    public static final int QUALITY_HIGH = 1;
56
57    /**
58     * Default recording duration in seconds before the session is terminated.
59     * This is useful for applications like MMS has limited file size requirement.
60     */
61    public int duration;
62
63    /**
64     * The quality level of the camcorder profile
65     */
66    public int quality;
67
68    /**
69     * The file output format of the camcorder profile
70     * @see android.media.MediaRecorder.OutputFormat
71     */
72    public int fileFormat;
73
74    /**
75     * The video encoder being used for the video track
76     * @see android.media.MediaRecorder.VideoEncoder
77     */
78    public int videoCodec;
79
80    /**
81     * The target video output bit rate in bits per second
82     */
83    public int videoBitRate;
84
85    /**
86     * The target video frame rate in frames per second
87     */
88    public int videoFrameRate;
89
90    /**
91     * The target video frame width in pixels
92     */
93    public int videoFrameWidth;
94
95    /**
96     * The target video frame height in pixels
97     */
98    public int videoFrameHeight;
99
100    /**
101     * The audio encoder being used for the audio track.
102     * @see android.media.MediaRecorder.AudioEncoder
103     */
104    public int audioCodec;
105
106    /**
107     * The target audio output bit rate in bits per second
108     */
109    public int audioBitRate;
110
111    /**
112     * The audio sampling rate used for the audio track
113     */
114    public int audioSampleRate;
115
116    /**
117     * The number of audio channels used for the audio track
118     */
119    public int audioChannels;
120
121    /**
122     * Returns the camcorder profile for the default camera at the given
123     * quality level.
124     * @param quality the target quality level for the camcorder profile
125     */
126    public static CamcorderProfile get(int quality) {
127        return get(0, quality);
128    }
129
130    /**
131     * Returns the camcorder profile for the given camera at the given
132     * quality level.
133     * @param cameraId the id for the camera
134     * @param quality the target quality level for the camcorder profile
135     */
136    public static CamcorderProfile get(int cameraId, int quality) {
137        if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
138            String errMessage = "Unsupported quality level: " + quality;
139            throw new IllegalArgumentException(errMessage);
140        }
141        return native_get_camcorder_profile(cameraId, quality);
142    }
143
144    static {
145        System.loadLibrary("media_jni");
146        native_init();
147    }
148
149    // Private constructor called by JNI
150    private CamcorderProfile(int duration,
151                             int quality,
152                             int fileFormat,
153                             int videoCodec,
154                             int videoBitRate,
155                             int videoFrameRate,
156                             int videoWidth,
157                             int videoHeight,
158                             int audioCodec,
159                             int audioBitRate,
160                             int audioSampleRate,
161                             int audioChannels) {
162
163        this.duration         = duration;
164        this.quality          = quality;
165        this.fileFormat       = fileFormat;
166        this.videoCodec       = videoCodec;
167        this.videoBitRate     = videoBitRate;
168        this.videoFrameRate   = videoFrameRate;
169        this.videoFrameWidth  = videoWidth;
170        this.videoFrameHeight = videoHeight;
171        this.audioCodec       = audioCodec;
172        this.audioBitRate     = audioBitRate;
173        this.audioSampleRate  = audioSampleRate;
174        this.audioChannels    = audioChannels;
175    }
176
177    // Methods implemented by JNI
178    private static native final void native_init();
179    private static native final CamcorderProfile native_get_camcorder_profile(
180            int cameraId, int quality);
181}
182