MediaRecorderClient.cpp revision 99ffda877980468a9ae31e013cd10fb3645df1b0
1/* 2 ** Copyright 2008, HTC Inc. 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//#define LOG_NDEBUG 0 18#define LOG_TAG "MediaRecorderService" 19#include <utils/Log.h> 20 21#include <sys/types.h> 22#include <sys/stat.h> 23#include <dirent.h> 24#include <unistd.h> 25#include <string.h> 26#include <cutils/atomic.h> 27#include <android_runtime/ActivityManager.h> 28#include <utils/IPCThreadState.h> 29#include <utils/IServiceManager.h> 30#include <utils/MemoryHeapBase.h> 31#include <utils/MemoryBase.h> 32#include <media/PVMediaRecorder.h> 33 34#include "MediaRecorderClient.h" 35 36namespace android { 37 38status_t MediaRecorderClient::setCamera(const sp<ICamera>& camera) 39{ 40 LOGV("setCamera"); 41 Mutex::Autolock lock(mLock); 42 if (mRecorder == NULL) { 43 LOGE("recorder is not initialized"); 44 return NO_INIT; 45 } 46 return mRecorder->setCamera(camera); 47} 48 49status_t MediaRecorderClient::setPreviewSurface(const sp<ISurface>& surface) 50{ 51 LOGV("setPreviewSurface"); 52 Mutex::Autolock lock(mLock); 53 if (mRecorder == NULL) { 54 LOGE("recorder is not initialized"); 55 return NO_INIT; 56 } 57 return mRecorder->setPreviewSurface(surface); 58} 59 60status_t MediaRecorderClient::setVideoSource(int vs) 61{ 62 LOGV("setVideoSource(%d)", vs); 63 Mutex::Autolock lock(mLock); 64 if (mRecorder == NULL) { 65 LOGE("recorder is not initialized"); 66 } 67 return mRecorder->setVideoSource((video_source)vs); 68} 69 70status_t MediaRecorderClient::setAudioSource(int as) 71{ 72 LOGV("setAudioSource(%d)", as); 73 Mutex::Autolock lock(mLock); 74 if (mRecorder == NULL) { 75 LOGE("recorder is not initialized"); 76 } 77 return mRecorder->setAudioSource((audio_source)as); 78} 79 80status_t MediaRecorderClient::setOutputFormat(int of) 81{ 82 LOGV("setOutputFormat(%d)", of); 83 Mutex::Autolock lock(mLock); 84 if (mRecorder == NULL) { 85 LOGE("recorder is not initialized"); 86 return NO_INIT; 87 } 88 return mRecorder->setOutputFormat((output_format)of); 89} 90 91status_t MediaRecorderClient::setVideoEncoder(int ve) 92{ 93 LOGV("setVideoEncoder(%d)", ve); 94 Mutex::Autolock lock(mLock); 95 if (mRecorder == NULL) { 96 LOGE("recorder is not initialized"); 97 return NO_INIT; 98 } 99 return mRecorder->setVideoEncoder((video_encoder)ve); 100} 101 102status_t MediaRecorderClient::setAudioEncoder(int ae) 103{ 104 LOGV("setAudioEncoder(%d)", ae); 105 Mutex::Autolock lock(mLock); 106 if (mRecorder == NULL) { 107 LOGE("recorder is not initialized"); 108 return NO_INIT; 109 } 110 return mRecorder->setAudioEncoder((audio_encoder)ae); 111} 112 113status_t MediaRecorderClient::setOutputFile(const char* path) 114{ 115 LOGV("setOutputFile(%s)", path); 116 Mutex::Autolock lock(mLock); 117 if (mRecorder == NULL) { 118 LOGE("recorder is not initialized"); 119 return NO_INIT; 120 } 121 return mRecorder->setOutputFile(path); 122} 123 124status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t length) 125{ 126 LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length); 127 Mutex::Autolock lock(mLock); 128 if (mRecorder == NULL) { 129 LOGE("recorder is not initialized"); 130 return NO_INIT; 131 } 132 return mRecorder->setOutputFile(fd, offset, length); 133} 134 135status_t MediaRecorderClient::setVideoSize(int width, int height) 136{ 137 LOGV("setVideoSize(%dx%d)", width, height); 138 Mutex::Autolock lock(mLock); 139 if (mRecorder == NULL) { 140 LOGE("recorder is not initialized"); 141 return NO_INIT; 142 } 143 return mRecorder->setVideoSize(width, height); 144} 145 146status_t MediaRecorderClient::setVideoFrameRate(int frames_per_second) 147{ 148 LOGV("setVideoFrameRate(%d)", frames_per_second); 149 Mutex::Autolock lock(mLock); 150 if (mRecorder == NULL) { 151 LOGE("recorder is not initialized"); 152 return NO_INIT; 153 } 154 return mRecorder->setVideoFrameRate(frames_per_second); 155} 156 157status_t MediaRecorderClient::prepare() 158{ 159 LOGV("prepare"); 160 Mutex::Autolock lock(mLock); 161 if (mRecorder == NULL) { 162 LOGE("recorder is not initialized"); 163 return NO_INIT; 164 } 165 return mRecorder->prepare(); 166} 167 168 169status_t MediaRecorderClient::getMaxAmplitude(int* max) 170{ 171 LOGV("getMaxAmplitude"); 172 Mutex::Autolock lock(mLock); 173 if (mRecorder == NULL) { 174 LOGE("recorder is not initialized"); 175 return NO_INIT; 176 } 177 return mRecorder->getMaxAmplitude(max); 178} 179 180status_t MediaRecorderClient::start() 181{ 182 LOGV("start"); 183 Mutex::Autolock lock(mLock); 184 if (mRecorder == NULL) { 185 LOGE("recorder is not initialized"); 186 return NO_INIT; 187 } 188 return mRecorder->start(); 189 190} 191 192status_t MediaRecorderClient::stop() 193{ 194 LOGV("stop"); 195 Mutex::Autolock lock(mLock); 196 if (mRecorder == NULL) { 197 LOGE("recorder is not initialized"); 198 return NO_INIT; 199 } 200 return mRecorder->stop(); 201} 202 203status_t MediaRecorderClient::init() 204{ 205 LOGV("init"); 206 Mutex::Autolock lock(mLock); 207 if (mRecorder == NULL) { 208 LOGE("recorder is not initialized"); 209 return NO_INIT; 210 } 211 return mRecorder->init(); 212} 213 214status_t MediaRecorderClient::close() 215{ 216 LOGV("close"); 217 Mutex::Autolock lock(mLock); 218 if (mRecorder == NULL) { 219 LOGE("recorder is not initialized"); 220 return NO_INIT; 221 } 222 return mRecorder->close(); 223} 224 225 226status_t MediaRecorderClient::reset() 227{ 228 LOGV("reset"); 229 Mutex::Autolock lock(mLock); 230 if (mRecorder == NULL) { 231 LOGE("recorder is not initialized"); 232 return NO_INIT; 233 } 234 return mRecorder->reset(); 235} 236 237status_t MediaRecorderClient::release() 238{ 239 LOGV("release"); 240 Mutex::Autolock lock(mLock); 241 if (mRecorder != NULL) { 242 delete mRecorder; 243 mRecorder = NULL; 244 } 245 return NO_ERROR; 246} 247 248MediaRecorderClient::MediaRecorderClient(pid_t pid) 249{ 250 LOGV("Client constructor"); 251 mPid = pid; 252 mRecorder = new PVMediaRecorder(); 253} 254 255MediaRecorderClient::~MediaRecorderClient() 256{ 257 LOGV("Client destructor"); 258 release(); 259} 260 261status_t MediaRecorderClient::setListener(const sp<IMediaPlayerClient>& listener) 262{ 263 LOGV("setListener"); 264 Mutex::Autolock lock(mLock); 265 if (mRecorder == NULL) { 266 LOGE("recorder is not initialized"); 267 return NO_INIT; 268 } 269 return mRecorder->setListener(listener); 270} 271 272}; // namespace android 273 274