Home | History | Annotate | Download | only in media
      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 
     17 package android.media;
     18 
     19 import android.hardware.Camera;
     20 import android.hardware.Camera.CameraInfo;
     21 
     22 /**
     23  * The CamcorderProfile class is used to retrieve the
     24  * predefined camcorder profile settings for camcorder applications.
     25  * These settings are read-only.
     26  *
     27  * The compressed output from a recording session with a given
     28  * CamcorderProfile contains two tracks: one for auido and one for video.
     29  *
     30  * <p>Each profile specifies the following set of parameters:
     31  * <ul>
     32  * <li> The file output format
     33  * <li> Video codec format
     34  * <li> Video bit rate in bits per second
     35  * <li> Video frame rate in frames per second
     36  * <li> Video frame width and height,
     37  * <li> Audio codec format
     38  * <li> Audio bit rate in bits per second,
     39  * <li> Audio sample rate
     40  * <li> Number of audio channels for recording.
     41  * </ul>
     42  */
     43 public class CamcorderProfile
     44 {
     45     // Do not change these values/ordinals without updating their counterpart
     46     // in include/media/MediaProfiles.h!
     47 
     48     /**
     49      * Quality level corresponding to the lowest available resolution.
     50      */
     51     public static final int QUALITY_LOW  = 0;
     52 
     53     /**
     54      * Quality level corresponding to the highest available resolution.
     55      */
     56     public static final int QUALITY_HIGH = 1;
     57 
     58     /**
     59      * Quality level corresponding to the qcif (176 x 144) resolution.
     60      */
     61     public static final int QUALITY_QCIF = 2;
     62 
     63     /**
     64      * Quality level corresponding to the cif (352 x 288) resolution.
     65      */
     66     public static final int QUALITY_CIF = 3;
     67 
     68     /**
     69      * Quality level corresponding to the 480p (720 x 480) resolution.
     70      */
     71     public static final int QUALITY_480P = 4;
     72 
     73     /**
     74      * Quality level corresponding to the 720p (1280 x 720) resolution.
     75      */
     76     public static final int QUALITY_720P = 5;
     77 
     78     /**
     79      * Quality level corresponding to the 1080p (1920 x 1088) resolution.
     80      */
     81     public static final int QUALITY_1080P = 6;
     82 
     83     /**
     84      * Quality level corresponding to the QVGA (320x240) resolution.
     85      * {@hide}
     86      */
     87     public static final int QUALITY_QVGA = 7;
     88 
     89     // Start and end of quality list
     90     private static final int QUALITY_LIST_START = QUALITY_LOW;
     91     private static final int QUALITY_LIST_END = QUALITY_QVGA;
     92 
     93     /**
     94      * Time lapse quality level corresponding to the lowest available resolution.
     95      */
     96     public static final int QUALITY_TIME_LAPSE_LOW  = 1000;
     97 
     98     /**
     99      * Time lapse quality level corresponding to the highest available resolution.
    100      */
    101     public static final int QUALITY_TIME_LAPSE_HIGH = 1001;
    102 
    103     /**
    104      * Time lapse quality level corresponding to the qcif (176 x 144) resolution.
    105      */
    106     public static final int QUALITY_TIME_LAPSE_QCIF = 1002;
    107 
    108     /**
    109      * Time lapse quality level corresponding to the cif (352 x 288) resolution.
    110      */
    111     public static final int QUALITY_TIME_LAPSE_CIF = 1003;
    112 
    113     /**
    114      * Time lapse quality level corresponding to the 480p (720 x 480) resolution.
    115      */
    116     public static final int QUALITY_TIME_LAPSE_480P = 1004;
    117 
    118     /**
    119      * Time lapse quality level corresponding to the 720p (1280 x 720) resolution.
    120      */
    121     public static final int QUALITY_TIME_LAPSE_720P = 1005;
    122 
    123     /**
    124      * Time lapse quality level corresponding to the 1080p (1920 x 1088) resolution.
    125      */
    126     public static final int QUALITY_TIME_LAPSE_1080P = 1006;
    127 
    128     /**
    129      * Time lapse quality level corresponding to the QVGA (320 x 240) resolution.
    130      * {@hide}
    131      */
    132     public static final int QUALITY_TIME_LAPSE_QVGA = 1007;
    133 
    134     // Start and end of timelapse quality list
    135     private static final int QUALITY_TIME_LAPSE_LIST_START = QUALITY_TIME_LAPSE_LOW;
    136     private static final int QUALITY_TIME_LAPSE_LIST_END = QUALITY_TIME_LAPSE_QVGA;
    137 
    138     /**
    139      * Default recording duration in seconds before the session is terminated.
    140      * This is useful for applications like MMS has limited file size requirement.
    141      */
    142     public int duration;
    143 
    144     /**
    145      * The quality level of the camcorder profile
    146      */
    147     public int quality;
    148 
    149     /**
    150      * The file output format of the camcorder profile
    151      * @see android.media.MediaRecorder.OutputFormat
    152      */
    153     public int fileFormat;
    154 
    155     /**
    156      * The video encoder being used for the video track
    157      * @see android.media.MediaRecorder.VideoEncoder
    158      */
    159     public int videoCodec;
    160 
    161     /**
    162      * The target video output bit rate in bits per second
    163      */
    164     public int videoBitRate;
    165 
    166     /**
    167      * The target video frame rate in frames per second
    168      */
    169     public int videoFrameRate;
    170 
    171     /**
    172      * The target video frame width in pixels
    173      */
    174     public int videoFrameWidth;
    175 
    176     /**
    177      * The target video frame height in pixels
    178      */
    179     public int videoFrameHeight;
    180 
    181     /**
    182      * The audio encoder being used for the audio track.
    183      * @see android.media.MediaRecorder.AudioEncoder
    184      */
    185     public int audioCodec;
    186 
    187     /**
    188      * The target audio output bit rate in bits per second
    189      */
    190     public int audioBitRate;
    191 
    192     /**
    193      * The audio sampling rate used for the audio track
    194      */
    195     public int audioSampleRate;
    196 
    197     /**
    198      * The number of audio channels used for the audio track
    199      */
    200     public int audioChannels;
    201 
    202     /**
    203      * Returns the camcorder profile for the first back-facing camera on the
    204      * device at the given quality level. If the device has no back-facing
    205      * camera, this returns null.
    206      * @param quality the target quality level for the camcorder profile
    207      * @see #get(int, int)
    208      */
    209     public static CamcorderProfile get(int quality) {
    210         int numberOfCameras = Camera.getNumberOfCameras();
    211         CameraInfo cameraInfo = new CameraInfo();
    212         for (int i = 0; i < numberOfCameras; i++) {
    213             Camera.getCameraInfo(i, cameraInfo);
    214             if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
    215                 return get(i, quality);
    216             }
    217         }
    218         return null;
    219     }
    220 
    221     /**
    222      * Returns the camcorder profile for the given camera at the given
    223      * quality level.
    224      *
    225      * Quality levels QUALITY_LOW, QUALITY_HIGH are guaranteed to be supported, while
    226      * other levels may or may not be supported. The supported levels can be checked using
    227      * {@link #hasProfile(int, int)}.
    228      * QUALITY_LOW refers to the lowest quality available, while QUALITY_HIGH refers to
    229      * the highest quality available.
    230      * QUALITY_LOW/QUALITY_HIGH have to match one of qcif, cif, 480p, 720p, or 1080p.
    231      * E.g. if the device supports 480p, 720p, and 1080p, then low is 480p and high is
    232      * 1080p.
    233      *
    234      * The same is true for time lapse quality levels, i.e. QUALITY_TIME_LAPSE_LOW,
    235      * QUALITY_TIME_LAPSE_HIGH are guaranteed to be supported and have to match one of
    236      * qcif, cif, 480p, 720p, or 1080p.
    237      *
    238      * A camcorder recording session with higher quality level usually has higher output
    239      * bit rate, better video and/or audio recording quality, larger video frame
    240      * resolution and higher audio sampling rate, etc, than those with lower quality
    241      * level.
    242      *
    243      * @param cameraId the id for the camera
    244      * @param quality the target quality level for the camcorder profile.
    245      * @see #QUALITY_LOW
    246      * @see #QUALITY_HIGH
    247      * @see #QUALITY_QCIF
    248      * @see #QUALITY_CIF
    249      * @see #QUALITY_480P
    250      * @see #QUALITY_720P
    251      * @see #QUALITY_1080P
    252      * @see #QUALITY_TIME_LAPSE_LOW
    253      * @see #QUALITY_TIME_LAPSE_HIGH
    254      * @see #QUALITY_TIME_LAPSE_QCIF
    255      * @see #QUALITY_TIME_LAPSE_CIF
    256      * @see #QUALITY_TIME_LAPSE_480P
    257      * @see #QUALITY_TIME_LAPSE_720P
    258      * @see #QUALITY_TIME_LAPSE_1080P
    259      */
    260     public static CamcorderProfile get(int cameraId, int quality) {
    261         if (!((quality >= QUALITY_LIST_START &&
    262                quality <= QUALITY_LIST_END) ||
    263               (quality >= QUALITY_TIME_LAPSE_LIST_START &&
    264                quality <= QUALITY_TIME_LAPSE_LIST_END))) {
    265             String errMessage = "Unsupported quality level: " + quality;
    266             throw new IllegalArgumentException(errMessage);
    267         }
    268         return native_get_camcorder_profile(cameraId, quality);
    269     }
    270 
    271     /**
    272      * Returns true if camcorder profile exists for the first back-facing
    273      * camera at the given quality level.
    274      * @param quality the target quality level for the camcorder profile
    275      */
    276     public static boolean hasProfile(int quality) {
    277         int numberOfCameras = Camera.getNumberOfCameras();
    278         CameraInfo cameraInfo = new CameraInfo();
    279         for (int i = 0; i < numberOfCameras; i++) {
    280             Camera.getCameraInfo(i, cameraInfo);
    281             if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
    282                 return hasProfile(i, quality);
    283             }
    284         }
    285         return false;
    286     }
    287 
    288     /**
    289      * Returns true if camcorder profile exists for the given camera at
    290      * the given quality level.
    291      * @param cameraId the id for the camera
    292      * @param quality the target quality level for the camcorder profile
    293      */
    294     public static boolean hasProfile(int cameraId, int quality) {
    295         return native_has_camcorder_profile(cameraId, quality);
    296     }
    297 
    298     static {
    299         System.loadLibrary("media_jni");
    300         native_init();
    301     }
    302 
    303     // Private constructor called by JNI
    304     private CamcorderProfile(int duration,
    305                              int quality,
    306                              int fileFormat,
    307                              int videoCodec,
    308                              int videoBitRate,
    309                              int videoFrameRate,
    310                              int videoWidth,
    311                              int videoHeight,
    312                              int audioCodec,
    313                              int audioBitRate,
    314                              int audioSampleRate,
    315                              int audioChannels) {
    316 
    317         this.duration         = duration;
    318         this.quality          = quality;
    319         this.fileFormat       = fileFormat;
    320         this.videoCodec       = videoCodec;
    321         this.videoBitRate     = videoBitRate;
    322         this.videoFrameRate   = videoFrameRate;
    323         this.videoFrameWidth  = videoWidth;
    324         this.videoFrameHeight = videoHeight;
    325         this.audioCodec       = audioCodec;
    326         this.audioBitRate     = audioBitRate;
    327         this.audioSampleRate  = audioSampleRate;
    328         this.audioChannels    = audioChannels;
    329     }
    330 
    331     // Methods implemented by JNI
    332     private static native final void native_init();
    333     private static native final CamcorderProfile native_get_camcorder_profile(
    334             int cameraId, int quality);
    335     private static native final boolean native_has_camcorder_profile(
    336             int cameraId, int quality);
    337 }
    338