Home | History | Annotate | Download | only in libcameraservice
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_H
     18 #define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_H
     19 
     20 #include "CameraDeviceBase.h"
     21 #include "CameraService.h"
     22 #include "camera2/Parameters.h"
     23 #include "camera2/FrameProcessor.h"
     24 #include "camera2/StreamingProcessor.h"
     25 #include "camera2/JpegProcessor.h"
     26 #include "camera2/ZslProcessorInterface.h"
     27 #include "camera2/CaptureSequencer.h"
     28 #include "camera2/CallbackProcessor.h"
     29 #include "Camera2ClientBase.h"
     30 
     31 namespace android {
     32 
     33 class IMemory;
     34 /**
     35  * Interface between android.hardware.Camera API and Camera HAL device for versions
     36  * CAMERA_DEVICE_API_VERSION_2_0 and 3_0.
     37  */
     38 class Camera2Client :
     39         public Camera2ClientBase<CameraService::Client>
     40 {
     41 public:
     42     /**
     43      * ICamera interface (see ICamera for details)
     44      */
     45 
     46     virtual void            disconnect();
     47     virtual status_t        connect(const sp<ICameraClient>& client);
     48     virtual status_t        lock();
     49     virtual status_t        unlock();
     50     virtual status_t        setPreviewDisplay(const sp<Surface>& surface);
     51     virtual status_t        setPreviewTexture(
     52         const sp<IGraphicBufferProducer>& bufferProducer);
     53     virtual void            setPreviewCallbackFlag(int flag);
     54     virtual status_t        startPreview();
     55     virtual void            stopPreview();
     56     virtual bool            previewEnabled();
     57     virtual status_t        storeMetaDataInBuffers(bool enabled);
     58     virtual status_t        startRecording();
     59     virtual void            stopRecording();
     60     virtual bool            recordingEnabled();
     61     virtual void            releaseRecordingFrame(const sp<IMemory>& mem);
     62     virtual status_t        autoFocus();
     63     virtual status_t        cancelAutoFocus();
     64     virtual status_t        takePicture(int msgType);
     65     virtual status_t        setParameters(const String8& params);
     66     virtual String8         getParameters() const;
     67     virtual status_t        sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
     68 
     69     /**
     70      * Interface used by CameraService
     71      */
     72 
     73     Camera2Client(const sp<CameraService>& cameraService,
     74             const sp<ICameraClient>& cameraClient,
     75             const String16& clientPackageName,
     76             int cameraId,
     77             int cameraFacing,
     78             int clientPid,
     79             uid_t clientUid,
     80             int servicePid,
     81             int deviceVersion);
     82 
     83     virtual ~Camera2Client();
     84 
     85     status_t initialize(camera_module_t *module);
     86 
     87     virtual status_t dump(int fd, const Vector<String16>& args);
     88 
     89     /**
     90      * Interface used by CameraDeviceBase
     91      */
     92 
     93     virtual void notifyAutoFocus(uint8_t newState, int triggerId);
     94     virtual void notifyAutoExposure(uint8_t newState, int triggerId);
     95 
     96     /**
     97      * Interface used by independent components of Camera2Client.
     98      */
     99 
    100     camera2::SharedParameters& getParameters();
    101 
    102     int getPreviewStreamId() const;
    103     int getCaptureStreamId() const;
    104     int getCallbackStreamId() const;
    105     int getRecordingStreamId() const;
    106     int getZslStreamId() const;
    107 
    108     status_t registerFrameListener(int32_t minId, int32_t maxId,
    109             wp<camera2::FrameProcessor::FilteredListener> listener);
    110     status_t removeFrameListener(int32_t minId, int32_t maxId,
    111             wp<camera2::FrameProcessor::FilteredListener> listener);
    112 
    113     status_t stopStream();
    114 
    115     static size_t calculateBufferSize(int width, int height,
    116             int format, int stride);
    117 
    118     static const int32_t kPreviewRequestIdStart = 10000000;
    119     static const int32_t kPreviewRequestIdEnd   = 20000000;
    120 
    121     static const int32_t kRecordingRequestIdStart  = 20000000;
    122     static const int32_t kRecordingRequestIdEnd    = 30000000;
    123 
    124     static const int32_t kCaptureRequestIdStart = 30000000;
    125     static const int32_t kCaptureRequestIdEnd   = 40000000;
    126 
    127 private:
    128     /** ICamera interface-related private members */
    129     typedef camera2::Parameters Parameters;
    130 
    131     status_t setPreviewWindowL(const sp<IBinder>& binder,
    132             sp<ANativeWindow> window);
    133     status_t startPreviewL(Parameters &params, bool restart);
    134     void     stopPreviewL();
    135     status_t startRecordingL(Parameters &params, bool restart);
    136     bool     recordingEnabledL();
    137 
    138     // Individual commands for sendCommand()
    139     status_t commandStartSmoothZoomL();
    140     status_t commandStopSmoothZoomL();
    141     status_t commandSetDisplayOrientationL(int degrees);
    142     status_t commandEnableShutterSoundL(bool enable);
    143     status_t commandPlayRecordingSoundL();
    144     status_t commandStartFaceDetectionL(int type);
    145     status_t commandStopFaceDetectionL(Parameters &params);
    146     status_t commandEnableFocusMoveMsgL(bool enable);
    147     status_t commandPingL();
    148     status_t commandSetVideoBufferCountL(size_t count);
    149 
    150     // Current camera device configuration
    151     camera2::SharedParameters mParameters;
    152 
    153     /** Camera device-related private members */
    154 
    155     void     setPreviewCallbackFlagL(Parameters &params, int flag);
    156     status_t updateRequests(Parameters &params);
    157     int mDeviceVersion;
    158 
    159     // Used with stream IDs
    160     static const int NO_STREAM = -1;
    161 
    162     template <typename ProcessorT>
    163     status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params);
    164     template <typename ProcessorT,
    165               status_t (ProcessorT::*updateStreamF)(const Parameters &)>
    166     status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params);
    167 
    168     sp<camera2::FrameProcessor> mFrameProcessor;
    169 
    170     /* Preview/Recording related members */
    171 
    172     sp<IBinder> mPreviewSurface;
    173     sp<camera2::StreamingProcessor> mStreamingProcessor;
    174 
    175     /** Preview callback related members */
    176 
    177     sp<camera2::CallbackProcessor> mCallbackProcessor;
    178 
    179     /* Still image capture related members */
    180 
    181     sp<camera2::CaptureSequencer> mCaptureSequencer;
    182     sp<camera2::JpegProcessor> mJpegProcessor;
    183     sp<camera2::ZslProcessorInterface> mZslProcessor;
    184     sp<Thread> mZslProcessorThread;
    185 
    186     /** Notification-related members */
    187 
    188     bool mAfInMotion;
    189 
    190     /** Utility members */
    191 
    192     // Wait until the camera device has received the latest control settings
    193     status_t syncWithDevice();
    194 };
    195 
    196 }; // namespace android
    197 
    198 #endif
    199