mediarecorder.h revision 7a2146d5807030b2629f347736be5301b61e8811
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.h> 22 23namespace android { 24 25class Surface; 26class IMediaRecorder; 27class ICamera; 28 29typedef void (*media_completion_f)(status_t status, void *cookie); 30 31/* Do not change these values without updating their counterparts 32 * in java/android/android/media/MediaRecorder.java! 33 */ 34enum audio_source { 35 AUDIO_SOURCE_DEFAULT = 0, 36 AUDIO_SOURCE_MIC = 1, 37}; 38 39enum video_source { 40 VIDEO_SOURCE_DEFAULT = 0, 41 VIDEO_SOURCE_CAMERA = 1, 42}; 43 44//Please update java/android/android/media/MediaRecorder.java if the following is updated. 45enum output_format { 46 OUTPUT_FORMAT_DEFAULT = 0, 47 OUTPUT_FORMAT_THREE_GPP, 48 OUTPUT_FORMAT_MPEG_4, 49 OUTPUT_FORMAT_RAW_AMR, 50 OUTPUT_FORMAT_LIST_END // must be last - used to validate format type 51}; 52 53enum audio_encoder { 54 AUDIO_ENCODER_DEFAULT = 0, 55 AUDIO_ENCODER_AMR_NB = 1, 56}; 57 58enum video_encoder { 59 VIDEO_ENCODER_DEFAULT = 0, 60 VIDEO_ENCODER_H263 = 1, 61 VIDEO_ENCODER_H264 = 2, 62 VIDEO_ENCODER_MPEG_4_SP = 3, 63}; 64 65// Maximum frames per second is 24 66#define MEDIA_RECORDER_MAX_FRAME_RATE 24 67 68/* 69 * The state machine of the media_recorder uses a set of different state names. 70 * The mapping between the media_recorder and the pvauthorengine is shown below: 71 * 72 * mediarecorder pvauthorengine 73 * ---------------------------------------------------------------- 74 * MEDIA_RECORDER_ERROR ERROR 75 * MEDIA_RECORDER_IDLE IDLE 76 * MEDIA_RECORDER_INITIALIZED OPENED 77 * MEDIA_RECORDER_DATASOURCE_CONFIGURED 78 * MEDIA_RECORDER_PREPARED INITIALIZED 79 * MEDIA_RECORDER_RECORDING RECORDING 80 */ 81enum media_recorder_states { 82 MEDIA_RECORDER_ERROR = 0, 83 MEDIA_RECORDER_IDLE = 1 << 0, 84 MEDIA_RECORDER_INITIALIZED = 1 << 1, 85 MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2, 86 MEDIA_RECORDER_PREPARED = 1 << 3, 87 MEDIA_RECORDER_RECORDING = 1 << 4, 88}; 89 90class MediaRecorder 91{ 92public: 93 MediaRecorder(); 94 ~MediaRecorder(); 95 96 status_t initCheck(); 97 status_t setCamera(const sp<ICamera>& camera); 98 status_t setPreviewSurface(const sp<Surface>& surface); 99 status_t setVideoSource(int vs); 100 status_t setAudioSource(int as); 101 status_t setOutputFormat(int of); 102 status_t setVideoEncoder(int ve); 103 status_t setAudioEncoder(int ae); 104 status_t setOutputFile(const char* path); 105 status_t setOutputFile(int fd, int64_t offset, int64_t length); 106 status_t setVideoSize(int width, int height); 107 status_t setVideoFrameRate(int frames_per_second); 108 status_t prepare(); 109 status_t getMaxAmplitude(int* max); 110 status_t start(); 111 status_t stop(); 112 status_t reset(); 113 status_t init(); 114 status_t close(); 115 status_t release(); 116 117private: 118 void doCleanUp(); 119 status_t doReset(); 120 121 sp<IMediaRecorder> mMediaRecorder; 122 media_recorder_states mCurrentState; 123 bool mIsAudioSourceSet; 124 bool mIsVideoSourceSet; 125 bool mIsAudioEncoderSet; 126 bool mIsVideoEncoderSet; 127 bool mIsOutputFileSet; 128}; 129 130}; // namespace android 131 132#endif // ANDROID_MEDIARECORDER_H 133