165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/*
265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Copyright (C) 2008, The Android Open Source Project
465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License");
665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** you may not use this file except in compliance with the License.
765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** You may obtain a copy of the License at
865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**     http://www.apache.org/licenses/LICENSE-2.0
1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Unless required by applicable law or agreed to in writing, software
1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS,
1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** See the License for the specific language governing permissions and
1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** limitations under the License.
1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian*/
1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
2065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
215462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian#include <binder/BinderService.h>
2265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <camera/ICameraService.h>
238951a97b1f8462c37e740ea5082eea0445d2c501Iliyan Malchev#include <hardware/camera.h>
2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/* This needs to be increased if we can have more cameras */
2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define MAX_CAMERAS 2
2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android {
2965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass MemoryHeapBase;
3165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass MediaPlayer;
328951a97b1f8462c37e740ea5082eea0445d2c501Iliyan Malchevclass CameraHardwareInterface;
3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
345462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopianclass CameraService :
355462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    public BinderService<CameraService>,
365462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    public BnCameraService
3765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
3865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class Client;
395462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    friend class BinderService<CameraService>;
4065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianpublic:
415462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    static char const* getServiceName() { return "media.camera"; }
4265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        CameraService();
4465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual             ~CameraService();
4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual int32_t     getNumberOfCameras();
4765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t    getCameraInfo(int cameraId,
4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                      struct CameraInfo* cameraInfo);
4908ad5efcef90e24db2863c0f85972ed05fe848a2Wu-cheng Li    virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId);
5065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual void        removeClient(const sp<ICameraClient>& cameraClient);
51d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park    // returns plain pointer of client. Note that mClientLock should be acquired to
52d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park    // prevent the client from destruction. The result can be NULL.
53d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park    virtual Client*     getClientByIdUnsafe(int cameraId);
54d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park    virtual Mutex*      getClientLockById(int cameraId);
5565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t    dump(int fd, const Vector<String16>& args);
5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t    onTransact(uint32_t code, const Parcel& data,
5865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                   Parcel* reply, uint32_t flags);
598951a97b1f8462c37e740ea5082eea0445d2c501Iliyan Malchev    virtual void onFirstRef();
6065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
6165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    enum sound_kind {
6265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        SOUND_SHUTTER = 0,
6365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        SOUND_RECORDING = 1,
6465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        NUM_SOUNDS
6565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
6665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
6765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    void                loadSound();
6865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    void                playSound(sound_kind kind);
6965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    void                releaseSound();
7065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
7165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianprivate:
7265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex               mServiceLock;
7365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    wp<Client>          mClient[MAX_CAMERAS];  // protected by mServiceLock
74d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park    Mutex               mClientLock[MAX_CAMERAS]; // prevent Client destruction inside callbacks
7565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    int                 mNumberOfCameras;
7665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
7765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // atomics to record whether the hardware is allocated to some client.
7865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    volatile int32_t    mBusy[MAX_CAMERAS];
7965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    void                setCameraBusy(int cameraId);
8065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    void                setCameraFree(int cameraId);
8165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
8265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // sounds
83ff4f55c8d77e276dbcceedb4e560ca1d91ba38baChih-Chung Chang    MediaPlayer*        newMediaPlayer(const char *file);
84ff4f55c8d77e276dbcceedb4e560ca1d91ba38baChih-Chung Chang
8565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    Mutex               mSoundLock;
8665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    sp<MediaPlayer>     mSoundPlayer[NUM_SOUNDS];
8765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    int                 mSoundRef;  // reference count (release all MediaPlayer when 0)
8865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
8965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class Client : public BnCamera
9065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    {
9165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
9265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // ICamera interface (see ICamera for details)
9365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void            disconnect();
9465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        connect(const sp<ICameraClient>& client);
9565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        lock();
9665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        unlock();
974b79168835965cf0fc41ebe2a367e22b4cb20d08Jamie Gennis        virtual status_t        setPreviewDisplay(const sp<Surface>& surface);
98bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        virtual status_t        setPreviewTexture(const sp<ISurfaceTexture>& surfaceTexture);
9965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void            setPreviewCallbackFlag(int flag);
10065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        startPreview();
10165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void            stopPreview();
10265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual bool            previewEnabled();
103e2ad6734eccc4b9ea7857c747ff9469a9c11ba09James Dong        virtual status_t        storeMetaDataInBuffers(bool enabled);
10465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        startRecording();
10565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void            stopRecording();
10665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual bool            recordingEnabled();
10765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void            releaseRecordingFrame(const sp<IMemory>& mem);
10865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        autoFocus();
10965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        cancelAutoFocus();
110e468ac57f6e8afc6078c76d4eb1ac327112a3de0James Dong        virtual status_t        takePicture(int msgType);
11165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        setParameters(const String8& params);
11265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual String8         getParameters() const;
11365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t        sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
11465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
11565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class CameraService;
11665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Client(const sp<CameraService>& cameraService,
11765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                       const sp<ICameraClient>& cameraClient,
118b7a67942823e8339eb298238f117aaa6d7b63111Wu-cheng Li                                       const sp<CameraHardwareInterface>& hardware,
11965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                       int cameraId,
120e09591eff55fdff1868b32c3e046c62f800330fcWu-cheng Li                                       int cameraFacing,
12108ad5efcef90e24db2863c0f85972ed05fe848a2Wu-cheng Li                                       int clientPid);
12265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                ~Client();
12365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // return our camera client
12565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        const sp<ICameraClient>&    getCameraClient() { return mCameraClient; }
12665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // check whether the calling process matches mClientPid.
12865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t                checkPid() const;
12965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t                checkPidAndHardware() const;  // also check mHardware != 0
13065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // these are internal functions used to set up preview buffers
13265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t                registerPreviewBuffers();
13365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // camera operation mode
13565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        enum camera_mode {
13665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            CAMERA_PREVIEW_MODE   = 0,  // frame automatically released
13765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            CAMERA_RECORDING_MODE = 1,  // frame has to be explicitly released by releaseRecordingFrame()
13865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
13965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // these are internal functions used for preview/recording
14065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t                startCameraMode(camera_mode mode);
14165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t                startPreviewMode();
14265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t                startRecordingMode();
14365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
144b5ca4618a722a21f084fe8bfc1c2992749ccd3f0Nipun Kwatra        // internal function used by sendCommand to enable/disable shutter sound.
145b5ca4618a722a21f084fe8bfc1c2992749ccd3f0Nipun Kwatra        status_t                enableShutterSound(bool enable);
146b5ca4618a722a21f084fe8bfc1c2992749ccd3f0Nipun Kwatra
14765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // these are static callback functions
14865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        static void             notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2, void* user);
149ff09ef8f18eed29bce50c7817df2fd52d2b50cf6Wu-cheng Li        static void             dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
150ff09ef8f18eed29bce50c7817df2fd52d2b50cf6Wu-cheng Li                                             camera_frame_metadata_t *metadata, void* user);
15165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        static void             dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr, void* user);
152d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        static Mutex*        getClientLockFromCookie(void* user);
153d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        // convert client from cookie. Client lock should be acquired before getting Client.
154d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        static Client*       getClientFromCookie(void* user);
15565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // handlers for messages
156108dddf924d714c811dd565b8f4c7a0178cca2f2Iliyan Malchev        void                    handleShutter(void);
15757c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li        void                    handlePreviewData(int32_t msgType, const sp<IMemory>& mem,
15857c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li                                                  camera_frame_metadata_t *metadata);
15965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    handlePostview(const sp<IMemory>& mem);
16065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    handleRawPicture(const sp<IMemory>& mem);
16165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    handleCompressedPicture(const sp<IMemory>& mem);
16265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    handleGenericNotify(int32_t msgType, int32_t ext1, int32_t ext2);
16357c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li        void                    handleGenericData(int32_t msgType, const sp<IMemory>& dataPtr,
16457c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li                                                  camera_frame_metadata_t *metadata);
16565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    handleGenericDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
16665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    copyFrameAndPostCopiedFrame(
16857c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li                                    int32_t msgType,
16965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    const sp<ICameraClient>& client,
17065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    const sp<IMemoryHeap>& heap,
17157c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li                                    size_t offset, size_t size,
17257c86189bc07d9ccb0fd044e66df736d0bf19639Wu-cheng Li                                    camera_frame_metadata_t *metadata);
17365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
174e09591eff55fdff1868b32c3e046c62f800330fcWu-cheng Li        int                     getOrientation(int orientation, bool mirror);
175e09591eff55fdff1868b32c3e046c62f800330fcWu-cheng Li
1760ed3ec00d0242c9dc77532fe0cf0082645b6662cJamie Gennis        status_t                setPreviewWindow(
1770ed3ec00d0242c9dc77532fe0cf0082645b6662cJamie Gennis                                    const sp<IBinder>& binder,
1780ed3ec00d0242c9dc77532fe0cf0082645b6662cJamie Gennis                                    const sp<ANativeWindow>& window);
1790ed3ec00d0242c9dc77532fe0cf0082645b6662cJamie Gennis
18065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // these are initialized in the constructor.
18165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<CameraService>               mCameraService;  // immutable after constructor
18265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<ICameraClient>               mCameraClient;
18365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                             mCameraId;       // immutable after constructor
184012716a857641a977afd16ff6be4bf66fc403884Wu-cheng Li        int                             mCameraFacing;   // immutable after constructor
18565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        pid_t                           mClientPid;
18665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<CameraHardwareInterface>     mHardware;       // cleared after disconnect()
18765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                             mPreviewCallbackFlag;
1884a73f3da3501db6e95473a4a653d6319c6d618e2Wu-cheng Li        int                             mOrientation;     // Current display orientation
189b5ca4618a722a21f084fe8bfc1c2992749ccd3f0Nipun Kwatra        bool                            mPlayShutterSound;
19065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Ensures atomicity among the public methods
19265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        mutable Mutex                   mLock;
19309cf462a265c3e9bc84c518cc75d77a5b1d69012Eino-Ville Talvala        // A lock to synchronize access through the ICamera binder
19409cf462a265c3e9bc84c518cc75d77a5b1d69012Eino-Ville Talvala        // interface. The entire binder call should be done with mICameraLock
19509cf462a265c3e9bc84c518cc75d77a5b1d69012Eino-Ville Talvala        // locked, to serialize ICamera access, even when mLock is disabled for
19609cf462a265c3e9bc84c518cc75d77a5b1d69012Eino-Ville Talvala        // calls to the HAL.
19709cf462a265c3e9bc84c518cc75d77a5b1d69012Eino-Ville Talvala        mutable Mutex                   mICameraLock;
198bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        // This is a binder of Surface or SurfaceTexture.
199bfa33aae4f54c0020a0568b16a3acb7b30b6ca3dJamie Gennis        sp<IBinder>                     mSurface;
2004b79168835965cf0fc41ebe2a367e22b4cb20d08Jamie Gennis        sp<ANativeWindow>               mPreviewWindow;
20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
20265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // If the user want us to return a copy of the preview frame (instead
20365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // of the original one), we allocate mPreviewBuffer and reuse it if possible.
20465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<MemoryHeapBase>              mPreviewBuffer;
20565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
206d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        // the instance is in the middle of destruction. When this is set,
207d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        // the instance should not be accessed from callback.
208d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        // CameraService's mClientLock should be acquired to access this.
209d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park        bool                            mDestructionStarted;
210d8973a71a3d1dd670e5dcdf6e94ec0cd45444eecKeun young Park
21165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // We need to avoid the deadlock when the incoming command thread and
21265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // the CameraHardwareInterface callback thread both want to grab mLock.
21365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // An extra flag is used to tell the callback thread that it should stop
21465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // trying to deliver the callback messages if the client is not
21565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // interested in it anymore. For example, if the client is calling
21665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // stopPreview(), the preview frame messages do not need to be delivered
21765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // anymore.
21865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
21965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // This function takes the same parameter as the enableMsgType() and
22065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // disableMsgType() functions in CameraHardwareInterface.
22165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    enableMsgType(int32_t msgType);
22265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void                    disableMsgType(int32_t msgType);
22365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        volatile int32_t        mMsgEnabled;
22465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
22565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // This function keeps trying to grab mLock, or give up if the message
22665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // is found to be disabled. It returns true if mLock is grabbed.
22765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool                    lockIfMessageWanted(int32_t msgType);
22865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
2298951a97b1f8462c37e740ea5082eea0445d2c501Iliyan Malchev
2308951a97b1f8462c37e740ea5082eea0445d2c501Iliyan Malchev    camera_module_t *mModule;
23165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian};
23265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
23365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} // namespace android
23465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
23565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#endif
236