1 /*
2  **
3  ** Copyright 2008, The Android Open Source Project
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 
21 #include <inttypes.h>
22 #include <unistd.h>
23 
24 #include <utils/Log.h>
25 #include <binder/Parcel.h>
26 #include <camera/android/hardware/ICamera.h>
27 #include <camera/ICameraRecordingProxy.h>
28 #include <media/IMediaRecorderClient.h>
29 #include <media/IMediaRecorder.h>
30 #include <gui/Surface.h>
31 #include <gui/IGraphicBufferProducer.h>
32 #include <media/stagefright/PersistentSurface.h>
33 
34 namespace android {
35 
36 enum {
37     RELEASE = IBinder::FIRST_CALL_TRANSACTION,
38     INIT,
39     CLOSE,
40     SET_INPUT_SURFACE,
41     QUERY_SURFACE_MEDIASOURCE,
42     RESET,
43     STOP,
44     START,
45     PREPARE,
46     GET_MAX_AMPLITUDE,
47     SET_VIDEO_SOURCE,
48     SET_AUDIO_SOURCE,
49     SET_OUTPUT_FORMAT,
50     SET_VIDEO_ENCODER,
51     SET_AUDIO_ENCODER,
52     SET_OUTPUT_FILE_FD,
53     SET_NEXT_OUTPUT_FILE_FD,
54     SET_VIDEO_SIZE,
55     SET_VIDEO_FRAMERATE,
56     SET_PARAMETERS,
57     SET_PREVIEW_SURFACE,
58     SET_CAMERA,
59     SET_LISTENER,
60     SET_CLIENT_NAME,
61     PAUSE,
62     RESUME,
63     GET_METRICS,
64     SET_INPUT_DEVICE,
65     GET_ROUTED_DEVICE_ID,
66     ENABLE_AUDIO_DEVICE_CALLBACK,
67     GET_ACTIVE_MICROPHONES,
68     GET_PORT_ID,
69     SET_PREFERRED_MICROPHONE_DIRECTION,
70     SET_PREFERRED_MICROPHONE_FIELD_DIMENSION
71 };
72 
73 class BpMediaRecorder: public BpInterface<IMediaRecorder>
74 {
75 public:
BpMediaRecorder(const sp<IBinder> & impl)76     explicit BpMediaRecorder(const sp<IBinder>& impl)
77     : BpInterface<IMediaRecorder>(impl)
78     {
79     }
80 
setCamera(const sp<hardware::ICamera> & camera,const sp<ICameraRecordingProxy> & proxy)81     status_t setCamera(const sp<hardware::ICamera>& camera, const sp<ICameraRecordingProxy>& proxy)
82     {
83         ALOGV("setCamera(%p,%p)", camera.get(), proxy.get());
84         Parcel data, reply;
85         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
86         data.writeStrongBinder(IInterface::asBinder(camera));
87         data.writeStrongBinder(IInterface::asBinder(proxy));
88         remote()->transact(SET_CAMERA, data, &reply);
89         return reply.readInt32();
90     }
91 
setInputSurface(const sp<PersistentSurface> & surface)92     status_t setInputSurface(const sp<PersistentSurface>& surface)
93     {
94         ALOGV("setInputSurface(%p)", surface.get());
95         Parcel data, reply;
96         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
97         surface->writeToParcel(&data);
98         remote()->transact(SET_INPUT_SURFACE, data, &reply);
99         return reply.readInt32();
100     }
101 
querySurfaceMediaSource()102     sp<IGraphicBufferProducer> querySurfaceMediaSource()
103     {
104         ALOGV("Query SurfaceMediaSource");
105         Parcel data, reply;
106         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
107         remote()->transact(QUERY_SURFACE_MEDIASOURCE, data, &reply);
108         int returnedNull = reply.readInt32();
109         if (returnedNull) {
110             return NULL;
111         }
112         return interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
113     }
114 
setPreviewSurface(const sp<IGraphicBufferProducer> & surface)115     status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface)
116     {
117         ALOGV("setPreviewSurface(%p)", surface.get());
118         Parcel data, reply;
119         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
120         data.writeStrongBinder(IInterface::asBinder(surface));
121         remote()->transact(SET_PREVIEW_SURFACE, data, &reply);
122         return reply.readInt32();
123     }
124 
init()125     status_t init()
126     {
127         ALOGV("init");
128         Parcel data, reply;
129         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
130         remote()->transact(INIT, data, &reply);
131         return reply.readInt32();
132     }
133 
setVideoSource(int vs)134     status_t setVideoSource(int vs)
135     {
136         ALOGV("setVideoSource(%d)", vs);
137         Parcel data, reply;
138         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
139         data.writeInt32(vs);
140         remote()->transact(SET_VIDEO_SOURCE, data, &reply);
141         return reply.readInt32();
142     }
143 
setAudioSource(int as)144     status_t setAudioSource(int as)
145     {
146         ALOGV("setAudioSource(%d)", as);
147         Parcel data, reply;
148         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
149         data.writeInt32(as);
150         remote()->transact(SET_AUDIO_SOURCE, data, &reply);
151         return reply.readInt32();
152     }
153 
setOutputFormat(int of)154     status_t setOutputFormat(int of)
155     {
156         ALOGV("setOutputFormat(%d)", of);
157         Parcel data, reply;
158         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
159         data.writeInt32(of);
160         remote()->transact(SET_OUTPUT_FORMAT, data, &reply);
161         return reply.readInt32();
162     }
163 
setVideoEncoder(int ve)164     status_t setVideoEncoder(int ve)
165     {
166         ALOGV("setVideoEncoder(%d)", ve);
167         Parcel data, reply;
168         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
169         data.writeInt32(ve);
170         remote()->transact(SET_VIDEO_ENCODER, data, &reply);
171         return reply.readInt32();
172     }
173 
setAudioEncoder(int ae)174     status_t setAudioEncoder(int ae)
175     {
176         ALOGV("setAudioEncoder(%d)", ae);
177         Parcel data, reply;
178         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
179         data.writeInt32(ae);
180         remote()->transact(SET_AUDIO_ENCODER, data, &reply);
181         return reply.readInt32();
182     }
183 
setOutputFile(int fd)184     status_t setOutputFile(int fd) {
185         ALOGV("setOutputFile(%d)", fd);
186         Parcel data, reply;
187         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
188         data.writeFileDescriptor(fd);
189         remote()->transact(SET_OUTPUT_FILE_FD, data, &reply);
190         return reply.readInt32();
191     }
192 
setNextOutputFile(int fd)193     status_t setNextOutputFile(int fd) {
194         ALOGV("setNextOutputFile(%d)", fd);
195         Parcel data, reply;
196         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
197         data.writeFileDescriptor(fd);
198         remote()->transact(SET_NEXT_OUTPUT_FILE_FD, data, &reply);
199         return reply.readInt32();
200     }
201 
setVideoSize(int width,int height)202     status_t setVideoSize(int width, int height)
203     {
204         ALOGV("setVideoSize(%dx%d)", width, height);
205         Parcel data, reply;
206         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
207         data.writeInt32(width);
208         data.writeInt32(height);
209         remote()->transact(SET_VIDEO_SIZE, data, &reply);
210         return reply.readInt32();
211     }
212 
setVideoFrameRate(int frames_per_second)213     status_t setVideoFrameRate(int frames_per_second)
214     {
215         ALOGV("setVideoFrameRate(%d)", frames_per_second);
216         Parcel data, reply;
217         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
218         data.writeInt32(frames_per_second);
219         remote()->transact(SET_VIDEO_FRAMERATE, data, &reply);
220         return reply.readInt32();
221     }
222 
setParameters(const String8 & params)223     status_t setParameters(const String8& params)
224     {
225         ALOGV("setParameter(%s)", params.string());
226         Parcel data, reply;
227         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
228         data.writeString8(params);
229         remote()->transact(SET_PARAMETERS, data, &reply);
230         return reply.readInt32();
231     }
232 
setListener(const sp<IMediaRecorderClient> & listener)233     status_t setListener(const sp<IMediaRecorderClient>& listener)
234     {
235         ALOGV("setListener(%p)", listener.get());
236         Parcel data, reply;
237         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
238         data.writeStrongBinder(IInterface::asBinder(listener));
239         remote()->transact(SET_LISTENER, data, &reply);
240         return reply.readInt32();
241     }
242 
setClientName(const String16 & clientName)243     status_t setClientName(const String16& clientName)
244     {
245         ALOGV("setClientName(%s)", String8(clientName).string());
246         Parcel data, reply;
247         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
248         data.writeString16(clientName);
249         remote()->transact(SET_CLIENT_NAME, data, &reply);
250         return reply.readInt32();
251     }
252 
prepare()253     status_t prepare()
254     {
255         ALOGV("prepare");
256         Parcel data, reply;
257         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
258         remote()->transact(PREPARE, data, &reply);
259         return reply.readInt32();
260     }
261 
getMaxAmplitude(int * max)262     status_t getMaxAmplitude(int* max)
263     {
264         ALOGV("getMaxAmplitude");
265         Parcel data, reply;
266         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
267         remote()->transact(GET_MAX_AMPLITUDE, data, &reply);
268         *max = reply.readInt32();
269         return reply.readInt32();
270     }
271 
getMetrics(Parcel * reply)272     status_t getMetrics(Parcel* reply)
273     {
274         ALOGV("getMetrics");
275         Parcel data;
276         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
277         status_t ret = remote()->transact(GET_METRICS, data, reply);
278         if (ret == NO_ERROR) {
279             return OK;
280         }
281         return UNKNOWN_ERROR;
282     }
283 
start()284     status_t start()
285     {
286         ALOGV("start");
287         Parcel data, reply;
288         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
289         remote()->transact(START, data, &reply);
290         return reply.readInt32();
291     }
292 
stop()293     status_t stop()
294     {
295         ALOGV("stop");
296         Parcel data, reply;
297         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
298         remote()->transact(STOP, data, &reply);
299         return reply.readInt32();
300     }
301 
reset()302     status_t reset()
303     {
304         ALOGV("reset");
305         Parcel data, reply;
306         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
307         remote()->transact(RESET, data, &reply);
308         return reply.readInt32();
309     }
310 
pause()311     status_t pause()
312     {
313         ALOGV("pause");
314         Parcel data, reply;
315         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
316         remote()->transact(PAUSE, data, &reply);
317         return reply.readInt32();
318     }
319 
resume()320     status_t resume()
321     {
322         ALOGV("resume");
323         Parcel data, reply;
324         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
325         remote()->transact(RESUME, data, &reply);
326         return reply.readInt32();
327     }
328 
close()329     status_t close()
330     {
331         ALOGV("close");
332         Parcel data, reply;
333         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
334         remote()->transact(CLOSE, data, &reply);
335         return reply.readInt32();
336     }
337 
release()338     status_t release()
339     {
340         ALOGV("release");
341         Parcel data, reply;
342         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
343         remote()->transact(RELEASE, data, &reply);
344         return reply.readInt32();
345     }
346 
setInputDevice(audio_port_handle_t deviceId)347     status_t setInputDevice(audio_port_handle_t deviceId)
348     {
349         ALOGV("setInputDevice");
350         Parcel data, reply;
351         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
352         data.writeInt32(deviceId);
353 
354         status_t status = remote()->transact(SET_INPUT_DEVICE, data, &reply);
355         if (status != OK) {
356             ALOGE("setInputDevice binder call failed: %d", status);
357             return status;
358         }
359         return reply.readInt32();;
360     }
361 
getRoutedDeviceId(audio_port_handle_t * deviceId)362     audio_port_handle_t getRoutedDeviceId(audio_port_handle_t *deviceId)
363     {
364         ALOGV("getRoutedDeviceId");
365         Parcel data, reply;
366         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
367 
368         status_t status = remote()->transact(GET_ROUTED_DEVICE_ID, data, &reply);
369         if (status != OK) {
370             ALOGE("getRoutedDeviceid binder call failed: %d", status);
371             *deviceId = AUDIO_PORT_HANDLE_NONE;
372             return status;
373         }
374 
375         status = reply.readInt32();
376         if (status != NO_ERROR) {
377             *deviceId = AUDIO_PORT_HANDLE_NONE;
378         } else {
379             *deviceId = reply.readInt32();
380         }
381         return status;
382     }
383 
enableAudioDeviceCallback(bool enabled)384     status_t enableAudioDeviceCallback(bool enabled)
385     {
386         ALOGV("enableAudioDeviceCallback");
387         Parcel data, reply;
388         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
389         data.writeBool(enabled);
390         status_t status = remote()->transact(ENABLE_AUDIO_DEVICE_CALLBACK, data, &reply);
391         if (status != OK) {
392             ALOGE("enableAudioDeviceCallback binder call failed: %d, %d", enabled, status);
393             return status;
394         }
395         return reply.readInt32();
396     }
397 
getActiveMicrophones(std::vector<media::MicrophoneInfo> * activeMicrophones)398     status_t getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones)
399     {
400         ALOGV("getActiveMicrophones");
401         Parcel data, reply;
402         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
403         status_t status = remote()->transact(GET_ACTIVE_MICROPHONES, data, &reply);
404         if (status != OK
405                 || (status = (status_t)reply.readInt32()) != NO_ERROR) {
406             return status;
407         }
408         status = reply.readParcelableVector(activeMicrophones);
409         return status;
410     }
411 
setPreferredMicrophoneDirection(audio_microphone_direction_t direction)412     status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction) {
413         ALOGV("setPreferredMicrophoneDirection(%d)", direction);
414         Parcel data, reply;
415         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
416         data.writeInt32(direction);
417         status_t status = remote()->transact(SET_PREFERRED_MICROPHONE_DIRECTION, data, &reply);
418         return status == NO_ERROR ? (status_t)reply.readInt32() : status;
419     }
420 
setPreferredMicrophoneFieldDimension(float zoom)421     status_t setPreferredMicrophoneFieldDimension(float zoom) {
422         ALOGV("setPreferredMicrophoneFieldDimension(%f)", zoom);
423         Parcel data, reply;
424         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
425         data.writeFloat(zoom);
426         status_t status = remote()->transact(SET_PREFERRED_MICROPHONE_FIELD_DIMENSION, data, &reply);
427         return status == NO_ERROR ? (status_t)reply.readInt32() : status;
428     }
429 
getPortId(audio_port_handle_t * portId)430     status_t getPortId(audio_port_handle_t *portId)
431     {
432         ALOGV("getPortId");
433         if (portId == nullptr) {
434             return BAD_VALUE;
435         }
436         Parcel data, reply;
437         data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
438         status_t status = remote()->transact(GET_PORT_ID, data, &reply);
439         if (status != OK
440                 || (status = (status_t)reply.readInt32()) != NO_ERROR) {
441             *portId = AUDIO_PORT_HANDLE_NONE;
442             return status;
443         }
444         *portId = (audio_port_handle_t)reply.readInt32();
445         return NO_ERROR;
446     }
447 };
448 
449 IMPLEMENT_META_INTERFACE(MediaRecorder, "android.media.IMediaRecorder");
450 
451 // ----------------------------------------------------------------------
452 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)453 status_t BnMediaRecorder::onTransact(
454                                      uint32_t code, const Parcel& data, Parcel* reply,
455                                      uint32_t flags)
456 {
457     switch (code) {
458         case RELEASE: {
459             ALOGV("RELEASE");
460             CHECK_INTERFACE(IMediaRecorder, data, reply);
461             reply->writeInt32(release());
462             return NO_ERROR;
463         } break;
464         case INIT: {
465             ALOGV("INIT");
466             CHECK_INTERFACE(IMediaRecorder, data, reply);
467             reply->writeInt32(init());
468             return NO_ERROR;
469         } break;
470         case CLOSE: {
471             ALOGV("CLOSE");
472             CHECK_INTERFACE(IMediaRecorder, data, reply);
473             reply->writeInt32(close());
474             return NO_ERROR;
475         } break;
476         case RESET: {
477             ALOGV("RESET");
478             CHECK_INTERFACE(IMediaRecorder, data, reply);
479             reply->writeInt32(reset());
480             return NO_ERROR;
481         } break;
482         case STOP: {
483             ALOGV("STOP");
484             CHECK_INTERFACE(IMediaRecorder, data, reply);
485             reply->writeInt32(stop());
486             return NO_ERROR;
487         } break;
488         case START: {
489             ALOGV("START");
490             CHECK_INTERFACE(IMediaRecorder, data, reply);
491             reply->writeInt32(start());
492             return NO_ERROR;
493         } break;
494         case PAUSE: {
495             ALOGV("PAUSE");
496             CHECK_INTERFACE(IMediaRecorder, data, reply);
497             reply->writeInt32(pause());
498             return NO_ERROR;
499         } break;
500         case RESUME: {
501             ALOGV("RESUME");
502             CHECK_INTERFACE(IMediaRecorder, data, reply);
503             reply->writeInt32(resume());
504             return NO_ERROR;
505         } break;
506         case PREPARE: {
507             ALOGV("PREPARE");
508             CHECK_INTERFACE(IMediaRecorder, data, reply);
509             reply->writeInt32(prepare());
510             return NO_ERROR;
511         } break;
512         case GET_MAX_AMPLITUDE: {
513             ALOGV("GET_MAX_AMPLITUDE");
514             CHECK_INTERFACE(IMediaRecorder, data, reply);
515             int max = 0;
516             status_t ret = getMaxAmplitude(&max);
517             reply->writeInt32(max);
518             reply->writeInt32(ret);
519             return NO_ERROR;
520         } break;
521         case GET_METRICS: {
522             ALOGV("GET_METRICS");
523             status_t ret = getMetrics(reply);
524             return ret;
525         } break;
526         case SET_VIDEO_SOURCE: {
527             ALOGV("SET_VIDEO_SOURCE");
528             CHECK_INTERFACE(IMediaRecorder, data, reply);
529             int vs = data.readInt32();
530             reply->writeInt32(setVideoSource(vs));
531             return NO_ERROR;
532         } break;
533         case SET_AUDIO_SOURCE: {
534             ALOGV("SET_AUDIO_SOURCE");
535             CHECK_INTERFACE(IMediaRecorder, data, reply);
536             int as = data.readInt32();
537             reply->writeInt32(setAudioSource(as));
538             return NO_ERROR;
539         } break;
540         case SET_OUTPUT_FORMAT: {
541             ALOGV("SET_OUTPUT_FORMAT");
542             CHECK_INTERFACE(IMediaRecorder, data, reply);
543             int of = data.readInt32();
544             reply->writeInt32(setOutputFormat(of));
545             return NO_ERROR;
546         } break;
547         case SET_VIDEO_ENCODER: {
548             ALOGV("SET_VIDEO_ENCODER");
549             CHECK_INTERFACE(IMediaRecorder, data, reply);
550             int ve = data.readInt32();
551             reply->writeInt32(setVideoEncoder(ve));
552             return NO_ERROR;
553         } break;
554         case SET_AUDIO_ENCODER: {
555             ALOGV("SET_AUDIO_ENCODER");
556             CHECK_INTERFACE(IMediaRecorder, data, reply);
557             int ae = data.readInt32();
558             reply->writeInt32(setAudioEncoder(ae));
559             return NO_ERROR;
560 
561         } break;
562         case SET_OUTPUT_FILE_FD: {
563             ALOGV("SET_OUTPUT_FILE_FD");
564             CHECK_INTERFACE(IMediaRecorder, data, reply);
565             int fd = dup(data.readFileDescriptor());
566             reply->writeInt32(setOutputFile(fd));
567             ::close(fd);
568             return NO_ERROR;
569         } break;
570         case SET_NEXT_OUTPUT_FILE_FD: {
571             ALOGV("SET_NEXT_OUTPUT_FILE_FD");
572             CHECK_INTERFACE(IMediaRecorder, data, reply);
573             int fd = dup(data.readFileDescriptor());
574             reply->writeInt32(setNextOutputFile(fd));
575             ::close(fd);
576             return NO_ERROR;
577         } break;
578         case SET_VIDEO_SIZE: {
579             ALOGV("SET_VIDEO_SIZE");
580             CHECK_INTERFACE(IMediaRecorder, data, reply);
581             int width = data.readInt32();
582             int height = data.readInt32();
583             reply->writeInt32(setVideoSize(width, height));
584             return NO_ERROR;
585         } break;
586         case SET_VIDEO_FRAMERATE: {
587             ALOGV("SET_VIDEO_FRAMERATE");
588             CHECK_INTERFACE(IMediaRecorder, data, reply);
589             int frames_per_second = data.readInt32();
590             reply->writeInt32(setVideoFrameRate(frames_per_second));
591             return NO_ERROR;
592         } break;
593         case SET_PARAMETERS: {
594             ALOGV("SET_PARAMETER");
595             CHECK_INTERFACE(IMediaRecorder, data, reply);
596             reply->writeInt32(setParameters(data.readString8()));
597             return NO_ERROR;
598         } break;
599         case SET_LISTENER: {
600             ALOGV("SET_LISTENER");
601             CHECK_INTERFACE(IMediaRecorder, data, reply);
602             sp<IMediaRecorderClient> listener =
603                 interface_cast<IMediaRecorderClient>(data.readStrongBinder());
604             reply->writeInt32(setListener(listener));
605             return NO_ERROR;
606         } break;
607         case SET_CLIENT_NAME: {
608             ALOGV("SET_CLIENT_NAME");
609             CHECK_INTERFACE(IMediaRecorder, data, reply);
610             reply->writeInt32(setClientName(data.readString16()));
611             return NO_ERROR;
612         }
613         case SET_PREVIEW_SURFACE: {
614             ALOGV("SET_PREVIEW_SURFACE");
615             CHECK_INTERFACE(IMediaRecorder, data, reply);
616             sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(
617                     data.readStrongBinder());
618             reply->writeInt32(setPreviewSurface(surface));
619             return NO_ERROR;
620         } break;
621         case SET_CAMERA: {
622             ALOGV("SET_CAMERA");
623             CHECK_INTERFACE(IMediaRecorder, data, reply);
624             sp<hardware::ICamera> camera =
625                     interface_cast<hardware::ICamera>(data.readStrongBinder());
626             sp<ICameraRecordingProxy> proxy =
627                     interface_cast<ICameraRecordingProxy>(data.readStrongBinder());
628             reply->writeInt32(setCamera(camera, proxy));
629             return NO_ERROR;
630         } break;
631         case SET_INPUT_SURFACE: {
632             ALOGV("SET_INPUT_SURFACE");
633             CHECK_INTERFACE(IMediaRecorder, data, reply);
634             sp<PersistentSurface> surface = new PersistentSurface();
635             surface->readFromParcel(&data);
636             reply->writeInt32(setInputSurface(surface));
637             return NO_ERROR;
638         } break;
639         case QUERY_SURFACE_MEDIASOURCE: {
640             ALOGV("QUERY_SURFACE_MEDIASOURCE");
641             CHECK_INTERFACE(IMediaRecorder, data, reply);
642             // call the mediaserver side to create
643             // a surfacemediasource
644             sp<IGraphicBufferProducer> surfaceMediaSource = querySurfaceMediaSource();
645             // The mediaserver might have failed to create a source
646             int returnedNull= (surfaceMediaSource == NULL) ? 1 : 0 ;
647             reply->writeInt32(returnedNull);
648             if (!returnedNull) {
649                 reply->writeStrongBinder(IInterface::asBinder(surfaceMediaSource));
650             }
651             return NO_ERROR;
652         } break;
653         case SET_INPUT_DEVICE: {
654             ALOGV("SET_INPUT_DEVICE");
655             CHECK_INTERFACE(IMediaRecorder, data, reply);
656             audio_port_handle_t deviceId;
657             status_t status = data.readInt32(&deviceId);
658             if (status == NO_ERROR) {
659                 reply->writeInt32(setInputDevice(deviceId));
660             } else {
661                 reply->writeInt32(BAD_VALUE);
662             }
663             return NO_ERROR;
664         } break;
665         case GET_ROUTED_DEVICE_ID: {
666             ALOGV("GET_ROUTED_DEVICE_ID");
667             CHECK_INTERFACE(IMediaRecorder, data, reply);
668             audio_port_handle_t deviceId;
669             status_t status = getRoutedDeviceId(&deviceId);
670             reply->writeInt32(status);
671             if (status == NO_ERROR) {
672                 reply->writeInt32(deviceId);
673             }
674             return NO_ERROR;
675         } break;
676         case ENABLE_AUDIO_DEVICE_CALLBACK: {
677             ALOGV("ENABLE_AUDIO_DEVICE_CALLBACK");
678             CHECK_INTERFACE(IMediaRecorder, data, reply);
679             bool enabled;
680             status_t status = data.readBool(&enabled);
681             if (status == NO_ERROR) {
682                 reply->writeInt32(enableAudioDeviceCallback(enabled));
683             } else {
684                 reply->writeInt32(BAD_VALUE);
685             }
686             return NO_ERROR;
687         } break;
688         case GET_ACTIVE_MICROPHONES: {
689             ALOGV("GET_ACTIVE_MICROPHONES");
690             CHECK_INTERFACE(IMediaRecorder, data, reply);
691             std::vector<media::MicrophoneInfo> activeMicrophones;
692             status_t status = getActiveMicrophones(&activeMicrophones);
693             reply->writeInt32(status);
694             if (status != NO_ERROR) {
695                 return NO_ERROR;
696             }
697             reply->writeParcelableVector(activeMicrophones);
698             return NO_ERROR;
699 
700         }
701         case GET_PORT_ID: {
702             ALOGV("GET_PORT_ID");
703             CHECK_INTERFACE(IMediaRecorder, data, reply);
704             audio_port_handle_t portId;
705             status_t status = getPortId(&portId);
706             reply->writeInt32(status);
707             if (status == NO_ERROR) {
708                 reply->writeInt32(portId);
709             }
710             return NO_ERROR;
711         }
712         case SET_PREFERRED_MICROPHONE_DIRECTION: {
713             ALOGV("SET_PREFERRED_MICROPHONE_DIRECTION");
714             CHECK_INTERFACE(IMediaRecorder, data, reply);
715             int direction = data.readInt32();
716             status_t status = setPreferredMicrophoneDirection(
717                     static_cast<audio_microphone_direction_t>(direction));
718             reply->writeInt32(status);
719             return NO_ERROR;
720         }
721         case SET_PREFERRED_MICROPHONE_FIELD_DIMENSION: {
722             ALOGV("SET_MICROPHONE_FIELD_DIMENSION");
723             CHECK_INTERFACE(IMediaRecorder, data, reply);
724             float zoom = data.readFloat();
725             status_t status = setPreferredMicrophoneFieldDimension(zoom);
726             reply->writeInt32(status);
727             return NO_ERROR;
728         }
729         default:
730             return BBinder::onTransact(code, data, reply, flags);
731     }
732 }
733 
734 // ----------------------------------------------------------------------------
735 
736 } // namespace android
737