IMediaRecorder.cpp revision 7b5eb023f8d87cca6d830ae6c11c6aadbe02aca8
1/* 2 ** 3 ** Copyright 2008, HTC Inc. 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18//#define LOG_NDEBUG 0 19#define LOG_TAG "IMediaRecorder" 20#include <utils/Log.h> 21#include <utils/Parcel.h> 22#include <ui/ISurface.h> 23#include <ui/ICamera.h> 24#include <media/IMediaRecorder.h> 25 26namespace android { 27 28enum { 29 RELEASE = IBinder::FIRST_CALL_TRANSACTION, 30 INIT, 31 CLOSE, 32 RESET, 33 STOP, 34 START, 35 PREPARE, 36 GET_MAX_AMPLITUDE, 37 SET_VIDEO_SOURCE, 38 SET_AUDIO_SOURCE, 39 SET_OUTPUT_FORMAT, 40 SET_VIDEO_ENCODER, 41 SET_AUDIO_ENCODER, 42 SET_OUTPUT_FILE, 43 SET_VIDEO_SIZE, 44 SET_VIDEO_FRAMERATE, 45 SET_PREVIEW_SURFACE, 46 SET_CAMERA 47}; 48 49class BpMediaRecorder: public BpInterface<IMediaRecorder> 50{ 51public: 52 BpMediaRecorder(const sp<IBinder>& impl) 53 : BpInterface<IMediaRecorder>(impl) 54 { 55 } 56 57 status_t setCamera(const sp<ICamera>& camera) 58 { 59 LOGV("setCamera(%p)", camera.get()); 60 Parcel data, reply; 61 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 62 data.writeStrongBinder(camera->asBinder()); 63 remote()->transact(SET_CAMERA, data, &reply); 64 return reply.readInt32(); 65 } 66 67 status_t setPreviewSurface(const sp<ISurface>& surface) 68 { 69 LOGV("setPreviewSurface(%p)", surface.get()); 70 Parcel data, reply; 71 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 72 data.writeStrongBinder(surface->asBinder()); 73 remote()->transact(SET_PREVIEW_SURFACE, data, &reply); 74 return reply.readInt32(); 75 } 76 77 status_t init() 78 { 79 LOGV("init"); 80 Parcel data, reply; 81 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 82 remote()->transact(INIT, data, &reply); 83 return reply.readInt32(); 84 } 85 86 status_t setVideoSource(int vs) 87 { 88 LOGV("setVideoSource(%d)", vs); 89 Parcel data, reply; 90 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 91 data.writeInt32(vs); 92 remote()->transact(SET_VIDEO_SOURCE, data, &reply); 93 return reply.readInt32(); 94 } 95 96 status_t setAudioSource(int as) 97 { 98 LOGV("setAudioSource(%d)", as); 99 Parcel data, reply; 100 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 101 data.writeInt32(as); 102 remote()->transact(SET_AUDIO_SOURCE, data, &reply); 103 return reply.readInt32(); 104 } 105 106 status_t setOutputFormat(int of) 107 { 108 LOGV("setOutputFormat(%d)", of); 109 Parcel data, reply; 110 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 111 data.writeInt32(of); 112 remote()->transact(SET_OUTPUT_FORMAT, data, &reply); 113 return reply.readInt32(); 114 } 115 116 status_t setVideoEncoder(int ve) 117 { 118 LOGV("setVideoEncoder(%d)", ve); 119 Parcel data, reply; 120 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 121 data.writeInt32(ve); 122 remote()->transact(SET_VIDEO_ENCODER, data, &reply); 123 return reply.readInt32(); 124 } 125 126 status_t setAudioEncoder(int ae) 127 { 128 LOGV("setAudioEncoder(%d)", ae); 129 Parcel data, reply; 130 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 131 data.writeInt32(ae); 132 remote()->transact(SET_AUDIO_ENCODER, data, &reply); 133 return reply.readInt32(); 134 } 135 136 status_t setOutputFile(const char* path) 137 { 138 LOGV("setOutputFile(%s)", path); 139 Parcel data, reply; 140 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 141 data.writeCString(path); 142 remote()->transact(SET_OUTPUT_FILE, data, &reply); 143 return reply.readInt32(); 144 } 145 146 status_t setVideoSize(int width, int height) 147 { 148 LOGV("setVideoSize(%dx%d)", width, height); 149 Parcel data, reply; 150 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 151 data.writeInt32(width); 152 data.writeInt32(height); 153 remote()->transact(SET_VIDEO_SIZE, data, &reply); 154 return reply.readInt32(); 155 } 156 157 status_t setVideoFrameRate(int frames_per_second) 158 { 159 LOGV("setVideoFrameRate(%d)", frames_per_second); 160 Parcel data, reply; 161 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 162 data.writeInt32(frames_per_second); 163 remote()->transact(SET_VIDEO_FRAMERATE, data, &reply); 164 return reply.readInt32(); 165 } 166 167 status_t prepare() 168 { 169 LOGV("prepare"); 170 Parcel data, reply; 171 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 172 remote()->transact(PREPARE, data, &reply); 173 return reply.readInt32(); 174 } 175 176 status_t getMaxAmplitude(int* max) 177 { 178 LOGV("getMaxAmplitude"); 179 Parcel data, reply; 180 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 181 remote()->transact(GET_MAX_AMPLITUDE, data, &reply); 182 *max = reply.readInt32(); 183 return reply.readInt32(); 184 } 185 186 status_t start() 187 { 188 LOGV("start"); 189 Parcel data, reply; 190 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 191 remote()->transact(START, data, &reply); 192 return reply.readInt32(); 193 } 194 195 status_t stop() 196 { 197 LOGV("stop"); 198 Parcel data, reply; 199 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 200 remote()->transact(STOP, data, &reply); 201 return reply.readInt32(); 202 } 203 204 status_t reset() 205 { 206 LOGV("reset"); 207 Parcel data, reply; 208 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 209 remote()->transact(RESET, data, &reply); 210 return reply.readInt32(); 211 } 212 213 status_t close() 214 { 215 LOGV("close"); 216 Parcel data, reply; 217 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 218 remote()->transact(CLOSE, data, &reply); 219 return reply.readInt32(); 220 } 221 222 status_t release() 223 { 224 LOGV("release"); 225 Parcel data, reply; 226 data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); 227 remote()->transact(RELEASE, data, &reply); 228 return reply.readInt32(); 229 } 230}; 231 232IMPLEMENT_META_INTERFACE(MediaRecorder, "android.hardware.IMediaRecorder"); 233 234// ---------------------------------------------------------------------- 235 236#define CHECK_INTERFACE(interface, data, reply) \ 237 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \ 238 LOGW("Call incorrectly routed to " #interface); \ 239 return PERMISSION_DENIED; \ 240 } } while (0) 241 242status_t BnMediaRecorder::onTransact( 243 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 244{ 245 switch(code) { 246 case RELEASE: { 247 LOGV("RELEASE"); 248 CHECK_INTERFACE(IMediaRecorder, data, reply); 249 reply->writeInt32(release()); 250 return NO_ERROR; 251 } break; 252 case INIT: { 253 LOGV("INIT"); 254 CHECK_INTERFACE(IMediaRecorder, data, reply); 255 reply->writeInt32(init()); 256 return NO_ERROR; 257 } break; 258 case CLOSE: { 259 LOGV("CLOSE"); 260 CHECK_INTERFACE(IMediaRecorder, data, reply); 261 reply->writeInt32(close()); 262 return NO_ERROR; 263 } break; 264 case RESET: { 265 LOGV("RESET"); 266 CHECK_INTERFACE(IMediaRecorder, data, reply); 267 reply->writeInt32(reset()); 268 return NO_ERROR; 269 } break; 270 case STOP: { 271 LOGV("STOP"); 272 CHECK_INTERFACE(IMediaRecorder, data, reply); 273 reply->writeInt32(stop()); 274 return NO_ERROR; 275 } break; 276 case START: { 277 LOGV("START"); 278 CHECK_INTERFACE(IMediaRecorder, data, reply); 279 reply->writeInt32(start()); 280 return NO_ERROR; 281 } break; 282 case PREPARE: { 283 LOGV("PREPARE"); 284 CHECK_INTERFACE(IMediaRecorder, data, reply); 285 reply->writeInt32(prepare()); 286 return NO_ERROR; 287 } break; 288 case GET_MAX_AMPLITUDE: { 289 LOGV("GET_MAX_AMPLITUDE"); 290 CHECK_INTERFACE(IMediaRecorder, data, reply); 291 int max = 0; 292 status_t ret = getMaxAmplitude(&max); 293 reply->writeInt32(max); 294 reply->writeInt32(ret); 295 return NO_ERROR; 296 } break; 297 case SET_VIDEO_SOURCE: { 298 LOGV("SET_VIDEO_SOURCE"); 299 CHECK_INTERFACE(IMediaRecorder, data, reply); 300 int vs = data.readInt32(); 301 reply->writeInt32(setVideoSource(vs)); 302 return NO_ERROR; 303 } break; 304 case SET_AUDIO_SOURCE: { 305 LOGV("SET_AUDIO_SOURCE"); 306 CHECK_INTERFACE(IMediaRecorder, data, reply); 307 int as = data.readInt32(); 308 reply->writeInt32(setAudioSource(as)); 309 return NO_ERROR; 310 } break; 311 case SET_OUTPUT_FORMAT: { 312 LOGV("SET_OUTPUT_FORMAT"); 313 CHECK_INTERFACE(IMediaRecorder, data, reply); 314 int of = data.readInt32(); 315 reply->writeInt32(setOutputFormat(of)); 316 return NO_ERROR; 317 } break; 318 case SET_VIDEO_ENCODER: { 319 LOGV("SET_VIDEO_ENCODER"); 320 CHECK_INTERFACE(IMediaRecorder, data, reply); 321 int ve = data.readInt32(); 322 reply->writeInt32(setVideoEncoder(ve)); 323 return NO_ERROR; 324 } break; 325 case SET_AUDIO_ENCODER: { 326 LOGV("SET_AUDIO_ENCODER"); 327 CHECK_INTERFACE(IMediaRecorder, data, reply); 328 int ae = data.readInt32(); 329 reply->writeInt32(setAudioEncoder(ae)); 330 return NO_ERROR; 331 332 } break; 333 case SET_OUTPUT_FILE: { 334 LOGV("SET_OUTPUT_FILE"); 335 CHECK_INTERFACE(IMediaRecorder, data, reply); 336 const char* path = data.readCString(); 337 reply->writeInt32(setOutputFile(path)); 338 return NO_ERROR; 339 } break; 340 case SET_VIDEO_SIZE: { 341 LOGV("SET_VIDEO_SIZE"); 342 CHECK_INTERFACE(IMediaRecorder, data, reply); 343 int width = data.readInt32(); 344 int height = data.readInt32(); 345 reply->writeInt32(setVideoSize(width, height)); 346 return NO_ERROR; 347 } break; 348 case SET_VIDEO_FRAMERATE: { 349 LOGV("SET_VIDEO_FRAMERATE"); 350 CHECK_INTERFACE(IMediaRecorder, data, reply); 351 int frames_per_second = data.readInt32(); 352 reply->writeInt32(setVideoFrameRate(frames_per_second)); 353 return NO_ERROR; 354 } break; 355 case SET_PREVIEW_SURFACE: { 356 LOGV("SET_PREVIEW_SURFACE"); 357 CHECK_INTERFACE(IMediaRecorder, data, reply); 358 sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder()); 359 reply->writeInt32(setPreviewSurface(surface)); 360 return NO_ERROR; 361 } break; 362 case SET_CAMERA: { 363 LOGV("SET_CAMERA"); 364 CHECK_INTERFACE(IMediaRecorder, data, reply); 365 sp<ICamera> camera = interface_cast<ICamera>(data.readStrongBinder()); 366 reply->writeInt32(setCamera(camera)); 367 return NO_ERROR; 368 } break; 369 default: 370 return BBinder::onTransact(code, data, reply, flags); 371 } 372} 373 374// ---------------------------------------------------------------------------- 375 376}; // namespace android 377