13cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian/*
23cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian**
33cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Copyright 2008, The Android Open Source Project
43cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian**
53cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License");
63cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** you may not use this file except in compliance with the License.
73cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** You may obtain a copy of the License at
83cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian**
93cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian**     http://www.apache.org/licenses/LICENSE-2.0
103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian**
113cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** Unless required by applicable law or agreed to in writing, software
123cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS,
133cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** See the License for the specific language governing permissions and
153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian** limitations under the License.
163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian*/
173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
183cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian//#define LOG_NDEBUG 0
193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#define LOG_TAG "ICamera"
203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <utils/Log.h>
213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <stdint.h>
223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <sys/types.h>
233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian#include <binder/Parcel.h>
246773d4777f4ccbbe6377e4ae1b42c117066ae6baPraveen Chavan#include <camera/CameraUtils.h>
25d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala#include <android/hardware/ICamera.h>
26d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala#include <android/hardware/ICameraClient.h>
278ba01021b573889802e67e029225a96f0dfa471aAndy McFadden#include <gui/IGraphicBufferProducer.h>
28df712ea86e6350f7005a02ab0e1c60c28a343ed0Mathias Agopian#include <gui/Surface.h>
296773d4777f4ccbbe6377e4ae1b42c117066ae6baPraveen Chavan#include <media/hardware/HardwareAPI.h>
303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopiannamespace android {
32d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvalanamespace hardware {
333cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianenum {
353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
361ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala    SET_PREVIEW_TARGET,
373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    SET_PREVIEW_CALLBACK_FLAG,
383ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    SET_PREVIEW_CALLBACK_TARGET,
393cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    START_PREVIEW,
403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    STOP_PREVIEW,
413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    AUTO_FOCUS,
423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    CANCEL_AUTO_FOCUS,
433cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    TAKE_PICTURE,
443cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    SET_PARAMETERS,
453cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    GET_PARAMETERS,
463cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    SEND_COMMAND,
473cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    CONNECT,
483cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    LOCK,
493cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    UNLOCK,
503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    PREVIEW_ENABLED,
513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    START_RECORDING,
523cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    STOP_RECORDING,
533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    RECORDING_ENABLED,
543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    RELEASE_RECORDING_FRAME,
558cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    SET_VIDEO_BUFFER_MODE,
568cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    SET_VIDEO_BUFFER_TARGET,
572d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen    RELEASE_RECORDING_FRAME_HANDLE,
58b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh    RELEASE_RECORDING_FRAME_HANDLE_BATCH,
593cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian};
603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
613cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianclass BpCamera: public BpInterface<ICamera>
623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{
633cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianpublic:
64090ef604f81447eab4aa0a5b45d6307482573560Chih-Hung Hsieh    explicit BpCamera(const sp<IBinder>& impl)
653cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        : BpInterface<ICamera>(impl)
663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
673cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
683cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
693cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // disconnect from camera service
70d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala    binder::Status disconnect()
713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("disconnect");
733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(DISCONNECT, data, &reply);
76bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin        reply.readExceptionCode();
77d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala        return binder::Status::ok();
783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
808ba01021b573889802e67e029225a96f0dfa471aAndy McFadden    // pass the buffered IGraphicBufferProducer to the camera service
811ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala    status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
82bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis    {
831ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        ALOGV("setPreviewTarget");
84bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        Parcel data, reply;
85bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
8606b46062d2f8bc82ca3061a23d197734ae51918bMarco Nelissen        sp<IBinder> b(IInterface::asBinder(bufferProducer));
87bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        data.writeStrongBinder(b);
881ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        remote()->transact(SET_PREVIEW_TARGET, data, &reply);
89bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        return reply.readInt32();
90bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis    }
91bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis
923cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // set the preview callback flag to affect how the received frames from
933cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // preview are handled. See Camera.h for details.
943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    void setPreviewCallbackFlag(int flag)
953cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("setPreviewCallbackFlag(%d)", flag);
973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
983cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
993cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInt32(flag);
1003cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(SET_PREVIEW_CALLBACK_FLAG, data, &reply);
1013cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1023cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1033ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    status_t setPreviewCallbackTarget(
1043ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            const sp<IGraphicBufferProducer>& callbackProducer)
1053ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    {
1063ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        ALOGV("setPreviewCallbackTarget");
1073ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        Parcel data, reply;
1083ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
10906b46062d2f8bc82ca3061a23d197734ae51918bMarco Nelissen        sp<IBinder> b(IInterface::asBinder(callbackProducer));
1103ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        data.writeStrongBinder(b);
1113ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        remote()->transact(SET_PREVIEW_CALLBACK_TARGET, data, &reply);
1123ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        return reply.readInt32();
1133ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala    }
1143ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala
1151ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala    // start preview mode, must call setPreviewTarget first
1163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    status_t startPreview()
1173cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
1183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("startPreview");
1193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
1203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
1213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(START_PREVIEW, data, &reply);
1223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
1233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1251ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala    // start recording mode, must call setPreviewTarget first
1263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    status_t startRecording()
1273cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
1283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("startRecording");
1293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
1303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
1313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(START_RECORDING, data, &reply);
1323cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
1333cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // stop preview mode
1363cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    void stopPreview()
1373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
1383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("stopPreview");
1393cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
1403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
1413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(STOP_PREVIEW, data, &reply);
1423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1433cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1443cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // stop recording mode
1453cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    void stopRecording()
1463cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
1473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("stopRecording");
1483cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
1493cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
1503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(STOP_RECORDING, data, &reply);
1513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1523cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
1533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    void releaseRecordingFrame(const sp<IMemory>& mem)
1543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
1553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("releaseRecordingFrame");
1563cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
1573cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
15806b46062d2f8bc82ca3061a23d197734ae51918bMarco Nelissen        data.writeStrongBinder(IInterface::asBinder(mem));
1596773d4777f4ccbbe6377e4ae1b42c117066ae6baPraveen Chavan
1603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(RELEASE_RECORDING_FRAME, data, &reply);
1612d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen    }
1626773d4777f4ccbbe6377e4ae1b42c117066ae6baPraveen Chavan
1632d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen    void releaseRecordingFrameHandle(native_handle_t *handle) {
1642d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        ALOGV("releaseRecordingFrameHandle");
1652d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        Parcel data, reply;
1662d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
1672d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        data.writeNativeHandle(handle);
1682d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen
1692d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        remote()->transact(RELEASE_RECORDING_FRAME_HANDLE, data, &reply);
1702d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen
1712d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        // Close the native handle because camera received a dup copy.
1722d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        native_handle_close(handle);
1732d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        native_handle_delete(handle);
1743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
1753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
176b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh    void releaseRecordingFrameHandleBatch(const std::vector<native_handle_t*>& handles) {
177b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        ALOGV("releaseRecordingFrameHandleBatch");
178b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        Parcel data, reply;
179b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
180b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        uint32_t n = handles.size();
181b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        data.writeUint32(n);
182b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        for (auto& handle : handles) {
183b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            data.writeNativeHandle(handle);
184b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        }
185b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        remote()->transact(RELEASE_RECORDING_FRAME_HANDLE_BATCH, data, &reply);
186b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh
187b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        // Close the native handle because camera received a dup copy.
188b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        for (auto& handle : handles) {
189b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            native_handle_close(handle);
190b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            native_handle_delete(handle);
191b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        }
192b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh    }
193b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh
1948cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    status_t setVideoBufferMode(int32_t videoBufferMode)
195e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong    {
1968cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGV("setVideoBufferMode: %d", videoBufferMode);
197e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong        Parcel data, reply;
198e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
1998cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        data.writeInt32(videoBufferMode);
2008cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        remote()->transact(SET_VIDEO_BUFFER_MODE, data, &reply);
201e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong        return reply.readInt32();
202e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong    }
203e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong
2043cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // check preview state
2053cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    bool previewEnabled()
2063cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("previewEnabled");
2083cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2093cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(PREVIEW_ENABLED, data, &reply);
2113cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
2123cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2133cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
2143cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // check recording state
2153cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    bool recordingEnabled()
2163cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("recordingEnabled");
2183cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2193cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(RECORDING_ENABLED, data, &reply);
2213cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
2223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
2243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // auto focus
2253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    status_t autoFocus()
2263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("autoFocus");
2283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(AUTO_FOCUS, data, &reply);
2313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        status_t ret = reply.readInt32();
2323cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return ret;
2333cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
2353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // cancel focus
2363cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    status_t cancelAutoFocus()
2373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("cancelAutoFocus");
2393cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(CANCEL_AUTO_FOCUS, data, &reply);
2423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        status_t ret = reply.readInt32();
2433cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return ret;
2443cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2453cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
2463cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // take a picture - returns an IMemory (ref-counted mmap)
247e468ac57f6e8afc6078c76d4eb1ac327112a3de0James Dong    status_t takePicture(int msgType)
2483cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("takePicture: 0x%x", msgType);
2503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
252e468ac57f6e8afc6078c76d4eb1ac327112a3de0James Dong        data.writeInt32(msgType);
2533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(TAKE_PICTURE, data, &reply);
2543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        status_t ret = reply.readInt32();
2553cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return ret;
2563cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2573cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
2583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // set preview/capture parameters - key/value pairs
2593cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    status_t setParameters(const String8& params)
2603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("setParameters");
2623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2633cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2643cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeString8(params);
2653cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(SET_PARAMETERS, data, &reply);
2663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
2673cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2683cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
2693cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    // get preview/capture parameters - key/value pairs
2703cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    String8 getParameters() const
2713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("getParameters");
2733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(GET_PARAMETERS, data, &reply);
2763cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readString8();
2773cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
2793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("sendCommand");
2813cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2823cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
2833cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInt32(cmd);
2843cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInt32(arg1);
2853cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInt32(arg2);
2863cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(SEND_COMMAND, data, &reply);
2873cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
2883cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2893cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    virtual status_t connect(const sp<ICameraClient>& cameraClient)
2903cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2913cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
2923cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
29306b46062d2f8bc82ca3061a23d197734ae51918bMarco Nelissen        data.writeStrongBinder(IInterface::asBinder(cameraClient));
2943cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(CONNECT, data, &reply);
2953cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
2963cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
2973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    virtual status_t lock()
2983cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
2993cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
3003cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
3013cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(LOCK, data, &reply);
3023cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
3033cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
3043cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    virtual status_t unlock()
3053cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    {
3063cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        Parcel data, reply;
3073cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
3083cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        remote()->transact(UNLOCK, data, &reply);
3093cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        return reply.readInt32();
3103cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
3118cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen
3128cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    status_t setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer)
3138cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    {
3148cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        ALOGV("setVideoTarget");
3158cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        Parcel data, reply;
3168cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
3178cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        sp<IBinder> b(IInterface::asBinder(bufferProducer));
3188cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        data.writeStrongBinder(b);
3198cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        remote()->transact(SET_VIDEO_BUFFER_TARGET, data, &reply);
3208cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        return reply.readInt32();
3218cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen    }
3223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian};
3233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
3243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias AgopianIMPLEMENT_META_INTERFACE(Camera, "android.hardware.ICamera");
3253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
3263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ----------------------------------------------------------------------
3273cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
3283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopianstatus_t BnCamera::onTransact(
3293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
3303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian{
3313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    switch(code) {
3323cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case DISCONNECT: {
3333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("DISCONNECT");
3343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            disconnect();
336bef3f23f16f2fc575b3f425febcfcc436a7db70fIgor Murashkin            reply->writeNoException();
3373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3383cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
3391ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala        case SET_PREVIEW_TARGET: {
3401ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala            ALOGV("SET_PREVIEW_TARGET");
341bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis            CHECK_INTERFACE(ICamera, data, reply);
3428ba01021b573889802e67e029225a96f0dfa471aAndy McFadden            sp<IGraphicBufferProducer> st =
3438ba01021b573889802e67e029225a96f0dfa471aAndy McFadden                interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
3441ce7c34e67c2cf58dd88c31f36f4bd62e375f7f0Eino-Ville Talvala            reply->writeInt32(setPreviewTarget(st));
345bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis            return NO_ERROR;
346bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        } break;
3473cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case SET_PREVIEW_CALLBACK_FLAG: {
3483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("SET_PREVIEW_CALLBACK_TYPE");
3493cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            int callback_flag = data.readInt32();
3513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            setPreviewCallbackFlag(callback_flag);
3523cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
3543ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        case SET_PREVIEW_CALLBACK_TARGET: {
3553ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            ALOGV("SET_PREVIEW_CALLBACK_TARGET");
3563ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            CHECK_INTERFACE(ICamera, data, reply);
3573ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            sp<IGraphicBufferProducer> cp =
3583ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala                interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
3593ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            reply->writeInt32(setPreviewCallbackTarget(cp));
3603ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala            return NO_ERROR;
3613ee3550a2f529cbf56d87d8503f59a8f45dccf32Eino-Ville Talvala        }
3623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case START_PREVIEW: {
3633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("START_PREVIEW");
3643cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3653cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(startPreview());
3663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3673cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
3683cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case START_RECORDING: {
3693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("START_RECORDING");
3703cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(startRecording());
3723cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
3743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case STOP_PREVIEW: {
3753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("STOP_PREVIEW");
3763cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3773cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            stopPreview();
3783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
3803cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case STOP_RECORDING: {
3813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("STOP_RECORDING");
3823cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3833cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            stopRecording();
3843cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
3853cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
3863cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case RELEASE_RECORDING_FRAME: {
3873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("RELEASE_RECORDING_FRAME");
3883cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
3893cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            sp<IMemory> mem = interface_cast<IMemory>(data.readStrongBinder());
3903cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            releaseRecordingFrame(mem);
3913cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
392e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong        } break;
3932d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        case RELEASE_RECORDING_FRAME_HANDLE: {
3942d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen            ALOGV("RELEASE_RECORDING_FRAME_HANDLE");
3952d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen            CHECK_INTERFACE(ICamera, data, reply);
3962d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen            // releaseRecordingFrameHandle will be responsble to close the native handle.
3972d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen            releaseRecordingFrameHandle(data.readNativeHandle());
3982d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen            return NO_ERROR;
3992d13b1d3eeaba31d8c15acc6037fd68b150a9a66Chien-Yu Chen        } break;
400b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        case RELEASE_RECORDING_FRAME_HANDLE_BATCH: {
401b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            ALOGV("RELEASE_RECORDING_FRAME_HANDLE_BATCH");
402b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            CHECK_INTERFACE(ICamera, data, reply);
403b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            // releaseRecordingFrameHandle will be responsble to close the native handle.
404b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            uint32_t n = data.readUint32();
405b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            std::vector<native_handle_t*> handles;
406b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            handles.reserve(n);
407b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            for (uint32_t i = 0; i < n; i++) {
408b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh                handles.push_back(data.readNativeHandle());
409b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            }
410b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            releaseRecordingFrameHandleBatch(handles);
411b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh            return NO_ERROR;
412b5df547bce900fa5764d735bee304e79c001d60dYin-Chia Yeh        } break;
4138cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        case SET_VIDEO_BUFFER_MODE: {
4148cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            ALOGV("SET_VIDEO_BUFFER_MODE");
415e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong            CHECK_INTERFACE(ICamera, data, reply);
4168cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            int32_t mode = data.readInt32();
4178cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            reply->writeInt32(setVideoBufferMode(mode));
418e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong            return NO_ERROR;
419e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong        } break;
4203cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case PREVIEW_ENABLED: {
4213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("PREVIEW_ENABLED");
4223cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4233cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(previewEnabled());
4243cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4253cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4263cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case RECORDING_ENABLED: {
4273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("RECORDING_ENABLED");
4283cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4293cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(recordingEnabled());
4303cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4313cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4323cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case AUTO_FOCUS: {
4333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("AUTO_FOCUS");
4343cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4353cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(autoFocus());
4363cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4373cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4383cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case CANCEL_AUTO_FOCUS: {
4393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("CANCEL_AUTO_FOCUS");
4403cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4413cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(cancelAutoFocus());
4423cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4433cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4443cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case TAKE_PICTURE: {
4453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("TAKE_PICTURE");
4463cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
447e468ac57f6e8afc6078c76d4eb1ac327112a3de0James Dong            int msgType = data.readInt32();
448e468ac57f6e8afc6078c76d4eb1ac327112a3de0James Dong            reply->writeInt32(takePicture(msgType));
4493cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4503cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4513cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case SET_PARAMETERS: {
4523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("SET_PARAMETERS");
4533cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4543cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            String8 params(data.readString8());
4553cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(setParameters(params));
4563cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4573cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian         } break;
4583cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case GET_PARAMETERS: {
4593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("GET_PARAMETERS");
4603cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4613cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian             reply->writeString8(getParameters());
4623cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4633cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian         } break;
4643cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case SEND_COMMAND: {
4653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("SEND_COMMAND");
4663cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4673cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            int command = data.readInt32();
4683cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            int arg1 = data.readInt32();
4693cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            int arg2 = data.readInt32();
4703cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(sendCommand(command, arg1, arg2));
4713cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4723cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian         } break;
4733cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case CONNECT: {
4743cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4753cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
4763cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(connect(cameraClient));
4773cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4783cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4793cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case LOCK: {
4803cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4813cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(lock());
4823cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4833cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4843cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        case UNLOCK: {
4853cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            CHECK_INTERFACE(ICamera, data, reply);
4863cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            reply->writeInt32(unlock());
4873cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return NO_ERROR;
4883cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        } break;
4898cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        case SET_VIDEO_BUFFER_TARGET: {
4908cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            ALOGV("SET_VIDEO_BUFFER_TARGET");
4918cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            CHECK_INTERFACE(ICamera, data, reply);
4928cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            sp<IGraphicBufferProducer> st =
4938cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen                interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
4948cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            reply->writeInt32(setVideoTarget(st));
4958cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen            return NO_ERROR;
4968cca0750a84c2d97224c0cfef7cf255308ee80b3Chien-Yu Chen        } break;
4973cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian        default:
4983cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian            return BBinder::onTransact(code, data, reply, flags);
4993cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian    }
5003cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian}
5013cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
5023cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian// ----------------------------------------------------------------------------
5033cf613507f1e2f7bd932d921a6e222e426fd3be4Mathias Agopian
504d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala} // namespace hardware
505d56db1d2bee182d1851097a9c712712fc094d117Eino-Ville Talvala} // namespace android
506