Home | History | Annotate | Download | only in media
      1 /*
      2  ** Copyright (C) 2008 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  **
     15  ** limitations under the License.
     16  */
     17 
     18 #ifndef ANDROID_MEDIARECORDER_H
     19 #define ANDROID_MEDIARECORDER_H
     20 
     21 #include <utils/Log.h>
     22 #include <utils/threads.h>
     23 #include <utils/List.h>
     24 #include <utils/Errors.h>
     25 #include <media/IMediaPlayerClient.h>
     26 #include <media/IMediaDeathNotifier.h>
     27 
     28 namespace android {
     29 
     30 class Surface;
     31 class IMediaRecorder;
     32 class ICamera;
     33 
     34 typedef void (*media_completion_f)(status_t status, void *cookie);
     35 
     36 /* Do not change these values without updating their counterparts
     37  * in media/java/android/media/MediaRecorder.java!
     38  */
     39 enum audio_source {
     40     AUDIO_SOURCE_DEFAULT = 0,
     41     AUDIO_SOURCE_MIC = 1,
     42     AUDIO_SOURCE_VOICE_UPLINK = 2,
     43     AUDIO_SOURCE_VOICE_DOWNLINK = 3,
     44     AUDIO_SOURCE_VOICE_CALL = 4,
     45     AUDIO_SOURCE_CAMCORDER = 5,
     46     AUDIO_SOURCE_VOICE_RECOGNITION = 6,
     47     AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_RECOGNITION,
     48 
     49     AUDIO_SOURCE_LIST_END  // must be last - used to validate audio source type
     50 };
     51 
     52 enum video_source {
     53     VIDEO_SOURCE_DEFAULT = 0,
     54     VIDEO_SOURCE_CAMERA = 1,
     55 
     56     VIDEO_SOURCE_LIST_END  // must be last - used to validate audio source type
     57 };
     58 
     59 //Please update media/java/android/media/MediaRecorder.java if the following is updated.
     60 enum output_format {
     61     OUTPUT_FORMAT_DEFAULT = 0,
     62     OUTPUT_FORMAT_THREE_GPP = 1,
     63     OUTPUT_FORMAT_MPEG_4 = 2,
     64 
     65 
     66     OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format.  Should be the
     67                                         //  at the start of the audio only output formats.
     68 
     69     /* These are audio only file formats */
     70     OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
     71     OUTPUT_FORMAT_AMR_NB = 3,
     72     OUTPUT_FORMAT_AMR_WB = 4,
     73     OUTPUT_FORMAT_AAC_ADIF = 5,
     74     OUTPUT_FORMAT_AAC_ADTS = 6,
     75 
     76     OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
     77 };
     78 
     79 enum audio_encoder {
     80     AUDIO_ENCODER_DEFAULT = 0,
     81     AUDIO_ENCODER_AMR_NB = 1,
     82     AUDIO_ENCODER_AMR_WB = 2,
     83     AUDIO_ENCODER_AAC = 3,
     84     AUDIO_ENCODER_AAC_PLUS = 4,
     85     AUDIO_ENCODER_EAAC_PLUS = 5,
     86 
     87     AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type
     88 };
     89 
     90 enum video_encoder {
     91     VIDEO_ENCODER_DEFAULT = 0,
     92     VIDEO_ENCODER_H263 = 1,
     93     VIDEO_ENCODER_H264 = 2,
     94     VIDEO_ENCODER_MPEG_4_SP = 3,
     95 
     96     VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type
     97 };
     98 
     99 /*
    100  * The state machine of the media_recorder uses a set of different state names.
    101  * The mapping between the media_recorder and the pvauthorengine is shown below:
    102  *
    103  *    mediarecorder                        pvauthorengine
    104  * ----------------------------------------------------------------
    105  *    MEDIA_RECORDER_ERROR                 ERROR
    106  *    MEDIA_RECORDER_IDLE                  IDLE
    107  *    MEDIA_RECORDER_INITIALIZED           OPENED
    108  *    MEDIA_RECORDER_DATASOURCE_CONFIGURED
    109  *    MEDIA_RECORDER_PREPARED              INITIALIZED
    110  *    MEDIA_RECORDER_RECORDING             RECORDING
    111  */
    112 enum media_recorder_states {
    113     MEDIA_RECORDER_ERROR                 =      0,
    114     MEDIA_RECORDER_IDLE                  = 1 << 0,
    115     MEDIA_RECORDER_INITIALIZED           = 1 << 1,
    116     MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
    117     MEDIA_RECORDER_PREPARED              = 1 << 3,
    118     MEDIA_RECORDER_RECORDING             = 1 << 4,
    119 };
    120 
    121 // The "msg" code passed to the listener in notify.
    122 enum media_recorder_event_type {
    123     MEDIA_RECORDER_EVENT_ERROR                    = 1,
    124     MEDIA_RECORDER_EVENT_INFO                     = 2
    125 };
    126 
    127 enum media_recorder_error_type {
    128     MEDIA_RECORDER_ERROR_UNKNOWN                  = 1
    129 };
    130 
    131 // The codes are distributed as follow:
    132 //   0xx: Reserved
    133 //   8xx: General info/warning
    134 //
    135 enum media_recorder_info_type {
    136     MEDIA_RECORDER_INFO_UNKNOWN                   = 1,
    137     MEDIA_RECORDER_INFO_MAX_DURATION_REACHED      = 800,
    138     MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED      = 801
    139 };
    140 
    141 // ----------------------------------------------------------------------------
    142 // ref-counted object for callbacks
    143 class MediaRecorderListener: virtual public RefBase
    144 {
    145 public:
    146     virtual void notify(int msg, int ext1, int ext2) = 0;
    147 };
    148 
    149 class MediaRecorder : public BnMediaPlayerClient,
    150                       public virtual IMediaDeathNotifier
    151 {
    152 public:
    153     MediaRecorder();
    154     ~MediaRecorder();
    155 
    156     void        died();
    157     status_t    initCheck();
    158     status_t    setCamera(const sp<ICamera>& camera);
    159     status_t    setPreviewSurface(const sp<Surface>& surface);
    160     status_t    setVideoSource(int vs);
    161     status_t    setAudioSource(int as);
    162     status_t    setOutputFormat(int of);
    163     status_t    setVideoEncoder(int ve);
    164     status_t    setAudioEncoder(int ae);
    165     status_t    setOutputFile(const char* path);
    166     status_t    setOutputFile(int fd, int64_t offset, int64_t length);
    167     status_t    setVideoSize(int width, int height);
    168     status_t    setVideoFrameRate(int frames_per_second);
    169     status_t    setParameters(const String8& params);
    170     status_t    setListener(const sp<MediaRecorderListener>& listener);
    171     status_t    prepare();
    172     status_t    getMaxAmplitude(int* max);
    173     status_t    start();
    174     status_t    stop();
    175     status_t    reset();
    176     status_t    init();
    177     status_t    close();
    178     status_t    release();
    179     void        notify(int msg, int ext1, int ext2);
    180 
    181 private:
    182     void                    doCleanUp();
    183     status_t                doReset();
    184 
    185     sp<IMediaRecorder>          mMediaRecorder;
    186     sp<MediaRecorderListener>   mListener;
    187     media_recorder_states       mCurrentState;
    188     bool                        mIsAudioSourceSet;
    189     bool                        mIsVideoSourceSet;
    190     bool                        mIsAudioEncoderSet;
    191     bool                        mIsVideoEncoderSet;
    192     bool                        mIsOutputFileSet;
    193     Mutex                       mLock;
    194     Mutex                       mNotifyLock;
    195 };
    196 
    197 };  // namespace android
    198 
    199 #endif // ANDROID_MEDIARECORDER_H
    200