The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
Jean-Baptiste Queru | 83407b9 | 2010-07-29 17:35:37 -0700 | [diff] [blame] | 3 | ** Copyright 2008, The Android Open Source Project |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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> |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 22 | #include <surfaceflinger/ISurface.h> |
| 23 | #include <camera/ICamera.h> |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 24 | #include <media/IMediaRecorderClient.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <media/IMediaRecorder.h> |
James Dong | c6280bc | 2010-08-11 17:12:39 -0700 | [diff] [blame] | 26 | #include <unistd.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | enum { |
| 31 | RELEASE = IBinder::FIRST_CALL_TRANSACTION, |
| 32 | INIT, |
| 33 | CLOSE, |
| 34 | RESET, |
| 35 | STOP, |
| 36 | START, |
| 37 | PREPARE, |
| 38 | GET_MAX_AMPLITUDE, |
| 39 | SET_VIDEO_SOURCE, |
| 40 | SET_AUDIO_SOURCE, |
| 41 | SET_OUTPUT_FORMAT, |
| 42 | SET_VIDEO_ENCODER, |
| 43 | SET_AUDIO_ENCODER, |
| 44 | SET_OUTPUT_FILE_PATH, |
| 45 | SET_OUTPUT_FILE_FD, |
| 46 | SET_VIDEO_SIZE, |
| 47 | SET_VIDEO_FRAMERATE, |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 48 | SET_PARAMETERS, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | SET_PREVIEW_SURFACE, |
| 50 | SET_CAMERA, |
| 51 | SET_LISTENER |
| 52 | }; |
| 53 | |
| 54 | class BpMediaRecorder: public BpInterface<IMediaRecorder> |
| 55 | { |
| 56 | public: |
| 57 | BpMediaRecorder(const sp<IBinder>& impl) |
| 58 | : BpInterface<IMediaRecorder>(impl) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | status_t setCamera(const sp<ICamera>& camera) |
| 63 | { |
| 64 | LOGV("setCamera(%p)", camera.get()); |
| 65 | Parcel data, reply; |
| 66 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 67 | data.writeStrongBinder(camera->asBinder()); |
| 68 | remote()->transact(SET_CAMERA, data, &reply); |
| 69 | return reply.readInt32(); |
| 70 | } |
| 71 | |
| 72 | status_t setPreviewSurface(const sp<ISurface>& surface) |
| 73 | { |
| 74 | LOGV("setPreviewSurface(%p)", surface.get()); |
| 75 | Parcel data, reply; |
| 76 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 77 | data.writeStrongBinder(surface->asBinder()); |
| 78 | remote()->transact(SET_PREVIEW_SURFACE, data, &reply); |
| 79 | return reply.readInt32(); |
| 80 | } |
| 81 | |
| 82 | status_t init() |
| 83 | { |
| 84 | LOGV("init"); |
| 85 | Parcel data, reply; |
| 86 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 87 | remote()->transact(INIT, data, &reply); |
| 88 | return reply.readInt32(); |
| 89 | } |
| 90 | |
| 91 | status_t setVideoSource(int vs) |
| 92 | { |
| 93 | LOGV("setVideoSource(%d)", vs); |
| 94 | Parcel data, reply; |
| 95 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 96 | data.writeInt32(vs); |
| 97 | remote()->transact(SET_VIDEO_SOURCE, data, &reply); |
| 98 | return reply.readInt32(); |
| 99 | } |
| 100 | |
| 101 | status_t setAudioSource(int as) |
| 102 | { |
| 103 | LOGV("setAudioSource(%d)", as); |
| 104 | Parcel data, reply; |
| 105 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 106 | data.writeInt32(as); |
| 107 | remote()->transact(SET_AUDIO_SOURCE, data, &reply); |
| 108 | return reply.readInt32(); |
| 109 | } |
| 110 | |
| 111 | status_t setOutputFormat(int of) |
| 112 | { |
| 113 | LOGV("setOutputFormat(%d)", of); |
| 114 | Parcel data, reply; |
| 115 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 116 | data.writeInt32(of); |
| 117 | remote()->transact(SET_OUTPUT_FORMAT, data, &reply); |
| 118 | return reply.readInt32(); |
| 119 | } |
| 120 | |
| 121 | status_t setVideoEncoder(int ve) |
| 122 | { |
| 123 | LOGV("setVideoEncoder(%d)", ve); |
| 124 | Parcel data, reply; |
| 125 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 126 | data.writeInt32(ve); |
| 127 | remote()->transact(SET_VIDEO_ENCODER, data, &reply); |
| 128 | return reply.readInt32(); |
| 129 | } |
| 130 | |
| 131 | status_t setAudioEncoder(int ae) |
| 132 | { |
| 133 | LOGV("setAudioEncoder(%d)", ae); |
| 134 | Parcel data, reply; |
| 135 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 136 | data.writeInt32(ae); |
| 137 | remote()->transact(SET_AUDIO_ENCODER, data, &reply); |
| 138 | return reply.readInt32(); |
| 139 | } |
| 140 | |
| 141 | status_t setOutputFile(const char* path) |
| 142 | { |
| 143 | LOGV("setOutputFile(%s)", path); |
| 144 | Parcel data, reply; |
| 145 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 146 | data.writeCString(path); |
| 147 | remote()->transact(SET_OUTPUT_FILE_PATH, data, &reply); |
| 148 | return reply.readInt32(); |
| 149 | } |
| 150 | |
| 151 | status_t setOutputFile(int fd, int64_t offset, int64_t length) { |
| 152 | LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length); |
| 153 | Parcel data, reply; |
| 154 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 155 | data.writeFileDescriptor(fd); |
| 156 | data.writeInt64(offset); |
| 157 | data.writeInt64(length); |
| 158 | remote()->transact(SET_OUTPUT_FILE_FD, data, &reply); |
| 159 | return reply.readInt32(); |
| 160 | } |
| 161 | |
| 162 | status_t setVideoSize(int width, int height) |
| 163 | { |
| 164 | LOGV("setVideoSize(%dx%d)", width, height); |
| 165 | Parcel data, reply; |
| 166 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 167 | data.writeInt32(width); |
| 168 | data.writeInt32(height); |
| 169 | remote()->transact(SET_VIDEO_SIZE, data, &reply); |
| 170 | return reply.readInt32(); |
| 171 | } |
| 172 | |
| 173 | status_t setVideoFrameRate(int frames_per_second) |
| 174 | { |
| 175 | LOGV("setVideoFrameRate(%d)", frames_per_second); |
| 176 | Parcel data, reply; |
| 177 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 178 | data.writeInt32(frames_per_second); |
| 179 | remote()->transact(SET_VIDEO_FRAMERATE, data, &reply); |
| 180 | return reply.readInt32(); |
| 181 | } |
| 182 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 183 | status_t setParameters(const String8& params) |
| 184 | { |
| 185 | LOGV("setParameter(%s)", params.string()); |
| 186 | Parcel data, reply; |
| 187 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 188 | data.writeString8(params); |
| 189 | remote()->transact(SET_PARAMETERS, data, &reply); |
| 190 | return reply.readInt32(); |
| 191 | } |
| 192 | |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 193 | status_t setListener(const sp<IMediaRecorderClient>& listener) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | { |
| 195 | LOGV("setListener(%p)", listener.get()); |
| 196 | Parcel data, reply; |
| 197 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 198 | data.writeStrongBinder(listener->asBinder()); |
| 199 | remote()->transact(SET_LISTENER, data, &reply); |
| 200 | return reply.readInt32(); |
| 201 | } |
| 202 | |
| 203 | status_t prepare() |
| 204 | { |
| 205 | LOGV("prepare"); |
| 206 | Parcel data, reply; |
| 207 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 208 | remote()->transact(PREPARE, data, &reply); |
| 209 | return reply.readInt32(); |
| 210 | } |
| 211 | |
| 212 | status_t getMaxAmplitude(int* max) |
| 213 | { |
| 214 | LOGV("getMaxAmplitude"); |
| 215 | Parcel data, reply; |
| 216 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 217 | remote()->transact(GET_MAX_AMPLITUDE, data, &reply); |
| 218 | *max = reply.readInt32(); |
| 219 | return reply.readInt32(); |
| 220 | } |
| 221 | |
| 222 | status_t start() |
| 223 | { |
| 224 | LOGV("start"); |
| 225 | Parcel data, reply; |
| 226 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 227 | remote()->transact(START, data, &reply); |
| 228 | return reply.readInt32(); |
| 229 | } |
| 230 | |
| 231 | status_t stop() |
| 232 | { |
| 233 | LOGV("stop"); |
| 234 | Parcel data, reply; |
| 235 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 236 | remote()->transact(STOP, data, &reply); |
| 237 | return reply.readInt32(); |
| 238 | } |
| 239 | |
| 240 | status_t reset() |
| 241 | { |
| 242 | LOGV("reset"); |
| 243 | Parcel data, reply; |
| 244 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 245 | remote()->transact(RESET, data, &reply); |
| 246 | return reply.readInt32(); |
| 247 | } |
| 248 | |
| 249 | status_t close() |
| 250 | { |
| 251 | LOGV("close"); |
| 252 | Parcel data, reply; |
| 253 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 254 | remote()->transact(CLOSE, data, &reply); |
| 255 | return reply.readInt32(); |
| 256 | } |
| 257 | |
| 258 | status_t release() |
| 259 | { |
| 260 | LOGV("release"); |
| 261 | Parcel data, reply; |
| 262 | data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor()); |
| 263 | remote()->transact(RELEASE, data, &reply); |
| 264 | return reply.readInt32(); |
| 265 | } |
| 266 | }; |
| 267 | |
niko | dcd810d | 2009-06-22 08:49:52 -0700 | [diff] [blame] | 268 | IMPLEMENT_META_INTERFACE(MediaRecorder, "android.media.IMediaRecorder"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | |
| 270 | // ---------------------------------------------------------------------- |
| 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | status_t BnMediaRecorder::onTransact( |
| 273 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 274 | { |
| 275 | switch(code) { |
| 276 | case RELEASE: { |
| 277 | LOGV("RELEASE"); |
| 278 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 279 | reply->writeInt32(release()); |
| 280 | return NO_ERROR; |
| 281 | } break; |
| 282 | case INIT: { |
| 283 | LOGV("INIT"); |
| 284 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 285 | reply->writeInt32(init()); |
| 286 | return NO_ERROR; |
| 287 | } break; |
| 288 | case CLOSE: { |
| 289 | LOGV("CLOSE"); |
| 290 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 291 | reply->writeInt32(close()); |
| 292 | return NO_ERROR; |
| 293 | } break; |
| 294 | case RESET: { |
| 295 | LOGV("RESET"); |
| 296 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 297 | reply->writeInt32(reset()); |
| 298 | return NO_ERROR; |
| 299 | } break; |
| 300 | case STOP: { |
| 301 | LOGV("STOP"); |
| 302 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 303 | reply->writeInt32(stop()); |
| 304 | return NO_ERROR; |
| 305 | } break; |
| 306 | case START: { |
| 307 | LOGV("START"); |
| 308 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 309 | reply->writeInt32(start()); |
| 310 | return NO_ERROR; |
| 311 | } break; |
| 312 | case PREPARE: { |
| 313 | LOGV("PREPARE"); |
| 314 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 315 | reply->writeInt32(prepare()); |
| 316 | return NO_ERROR; |
| 317 | } break; |
| 318 | case GET_MAX_AMPLITUDE: { |
| 319 | LOGV("GET_MAX_AMPLITUDE"); |
| 320 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 321 | int max = 0; |
| 322 | status_t ret = getMaxAmplitude(&max); |
| 323 | reply->writeInt32(max); |
| 324 | reply->writeInt32(ret); |
| 325 | return NO_ERROR; |
| 326 | } break; |
| 327 | case SET_VIDEO_SOURCE: { |
| 328 | LOGV("SET_VIDEO_SOURCE"); |
| 329 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 330 | int vs = data.readInt32(); |
| 331 | reply->writeInt32(setVideoSource(vs)); |
| 332 | return NO_ERROR; |
| 333 | } break; |
| 334 | case SET_AUDIO_SOURCE: { |
| 335 | LOGV("SET_AUDIO_SOURCE"); |
| 336 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 337 | int as = data.readInt32(); |
| 338 | reply->writeInt32(setAudioSource(as)); |
| 339 | return NO_ERROR; |
| 340 | } break; |
| 341 | case SET_OUTPUT_FORMAT: { |
| 342 | LOGV("SET_OUTPUT_FORMAT"); |
| 343 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 344 | int of = data.readInt32(); |
| 345 | reply->writeInt32(setOutputFormat(of)); |
| 346 | return NO_ERROR; |
| 347 | } break; |
| 348 | case SET_VIDEO_ENCODER: { |
| 349 | LOGV("SET_VIDEO_ENCODER"); |
| 350 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 351 | int ve = data.readInt32(); |
| 352 | reply->writeInt32(setVideoEncoder(ve)); |
| 353 | return NO_ERROR; |
| 354 | } break; |
| 355 | case SET_AUDIO_ENCODER: { |
| 356 | LOGV("SET_AUDIO_ENCODER"); |
| 357 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 358 | int ae = data.readInt32(); |
| 359 | reply->writeInt32(setAudioEncoder(ae)); |
| 360 | return NO_ERROR; |
| 361 | |
| 362 | } break; |
| 363 | case SET_OUTPUT_FILE_PATH: { |
| 364 | LOGV("SET_OUTPUT_FILE_PATH"); |
| 365 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 366 | const char* path = data.readCString(); |
| 367 | reply->writeInt32(setOutputFile(path)); |
| 368 | return NO_ERROR; |
| 369 | } break; |
| 370 | case SET_OUTPUT_FILE_FD: { |
| 371 | LOGV("SET_OUTPUT_FILE_FD"); |
| 372 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 373 | int fd = dup(data.readFileDescriptor()); |
| 374 | int64_t offset = data.readInt64(); |
| 375 | int64_t length = data.readInt64(); |
| 376 | reply->writeInt32(setOutputFile(fd, offset, length)); |
James Dong | c6280bc | 2010-08-11 17:12:39 -0700 | [diff] [blame] | 377 | ::close(fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | return NO_ERROR; |
| 379 | } break; |
| 380 | case SET_VIDEO_SIZE: { |
| 381 | LOGV("SET_VIDEO_SIZE"); |
| 382 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 383 | int width = data.readInt32(); |
| 384 | int height = data.readInt32(); |
| 385 | reply->writeInt32(setVideoSize(width, height)); |
| 386 | return NO_ERROR; |
| 387 | } break; |
| 388 | case SET_VIDEO_FRAMERATE: { |
| 389 | LOGV("SET_VIDEO_FRAMERATE"); |
| 390 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 391 | int frames_per_second = data.readInt32(); |
| 392 | reply->writeInt32(setVideoFrameRate(frames_per_second)); |
| 393 | return NO_ERROR; |
| 394 | } break; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 395 | case SET_PARAMETERS: { |
| 396 | LOGV("SET_PARAMETER"); |
| 397 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 398 | reply->writeInt32(setParameters(data.readString8())); |
| 399 | return NO_ERROR; |
| 400 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | case SET_LISTENER: { |
| 402 | LOGV("SET_LISTENER"); |
| 403 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 404 | sp<IMediaRecorderClient> listener = |
| 405 | interface_cast<IMediaRecorderClient>(data.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | reply->writeInt32(setListener(listener)); |
| 407 | return NO_ERROR; |
| 408 | } break; |
| 409 | case SET_PREVIEW_SURFACE: { |
| 410 | LOGV("SET_PREVIEW_SURFACE"); |
| 411 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 412 | sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder()); |
| 413 | reply->writeInt32(setPreviewSurface(surface)); |
| 414 | return NO_ERROR; |
| 415 | } break; |
| 416 | case SET_CAMERA: { |
| 417 | LOGV("SET_CAMERA"); |
| 418 | CHECK_INTERFACE(IMediaRecorder, data, reply); |
| 419 | sp<ICamera> camera = interface_cast<ICamera>(data.readStrongBinder()); |
| 420 | reply->writeInt32(setCamera(camera)); |
| 421 | return NO_ERROR; |
| 422 | } break; |
| 423 | default: |
| 424 | return BBinder::onTransact(code, data, reply, flags); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // ---------------------------------------------------------------------------- |
| 429 | |
| 430 | }; // namespace android |