CamcorderProfile.java revision e64d9a236e4704abf53d3b7eea2eb066f23cf402
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 given quality level.
123     * @param quality the target quality level for the camcorder profile
124     */
125    public static CamcorderProfile get(int quality) {
126        if (quality < QUALITY_LOW || quality > QUALITY_HIGH) {
127            String errMessage = "Unsupported quality level: " + quality;
128            throw new IllegalArgumentException(errMessage);
129        }
130        return native_get_camcorder_profile(quality);
131    }
132
133    static {
134        System.loadLibrary("media_jni");
135        native_init();
136    }
137
138    // Private constructor called by JNI
139    private CamcorderProfile(int duration,
140                             int quality,
141                             int fileFormat,
142                             int videoCodec,
143                             int videoBitRate,
144                             int videoFrameRate,
145                             int videoWidth,
146                             int videoHeight,
147                             int audioCodec,
148                             int audioBitRate,
149                             int audioSampleRate,
150                             int audioChannels) {
151
152        this.duration         = duration;
153        this.quality          = quality;
154        this.fileFormat       = fileFormat;
155        this.videoCodec       = videoCodec;
156        this.videoBitRate     = videoBitRate;
157        this.videoFrameRate   = videoFrameRate;
158        this.videoFrameWidth  = videoWidth;
159        this.videoFrameHeight = videoHeight;
160        this.audioCodec       = audioCodec;
161        this.audioBitRate     = audioBitRate;
162        this.audioSampleRate  = audioSampleRate;
163        this.audioChannels    = audioChannels;
164    }
165
166    // Methods implemented by JNI
167    private static native final void native_init();
168    private static native final CamcorderProfile native_get_camcorder_profile(int quality);
169}
170