• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "CameraService.h"
21 #include "common/CameraDeviceBase.h"
22 #include "common/Camera2ClientBase.h"
23 #include "api1/client2/Parameters.h"
24 #include "api1/client2/FrameProcessor.h"
25 //#include "api1/client2/StreamingProcessor.h"
26 //#include "api1/client2/JpegProcessor.h"
27 //#include "api1/client2/ZslProcessorInterface.h"
28 //#include "api1/client2/CaptureSequencer.h"
29 //#include "api1/client2/CallbackProcessor.h"
30 
31 namespace android {
32 
33 namespace camera2 {
34 
35 class StreamingProcessor;
36 class JpegProcessor;
37 class ZslProcessorInterface;
38 class CaptureSequencer;
39 class CallbackProcessor;
40 
41 }
42 
43 class IMemory;
44 /**
45  * Interface between android.hardware.Camera API and Camera HAL device for versions
46  * CAMERA_DEVICE_API_VERSION_2_0 and 3_0.
47  */
48 class Camera2Client :
49         public Camera2ClientBase<CameraService::Client>
50 {
51 public:
52     /**
53      * ICamera interface (see ICamera for details)
54      */
55 
56     virtual void            disconnect();
57     virtual status_t        connect(const sp<ICameraClient>& client);
58     virtual status_t        lock();
59     virtual status_t        unlock();
60     virtual status_t        setPreviewTarget(
61         const sp<IGraphicBufferProducer>& bufferProducer);
62     virtual void            setPreviewCallbackFlag(int flag);
63     virtual status_t        setPreviewCallbackTarget(
64         const sp<IGraphicBufferProducer>& callbackProducer);
65 
66     virtual status_t        startPreview();
67     virtual void            stopPreview();
68     virtual bool            previewEnabled();
69     virtual status_t        storeMetaDataInBuffers(bool enabled);
70     virtual status_t        startRecording();
71     virtual void            stopRecording();
72     virtual bool            recordingEnabled();
73     virtual void            releaseRecordingFrame(const sp<IMemory>& mem);
74     virtual status_t        autoFocus();
75     virtual status_t        cancelAutoFocus();
76     virtual status_t        takePicture(int msgType);
77     virtual status_t        setParameters(const String8& params);
78     virtual String8         getParameters() const;
79     virtual status_t        sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
80     virtual void            notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
81                                         const CaptureResultExtras& resultExtras);
82 
83     /**
84      * Interface used by CameraService
85      */
86 
87     Camera2Client(const sp<CameraService>& cameraService,
88             const sp<ICameraClient>& cameraClient,
89             const String16& clientPackageName,
90             int cameraId,
91             int cameraFacing,
92             int clientPid,
93             uid_t clientUid,
94             int servicePid,
95             bool legacyMode);
96 
97     virtual ~Camera2Client();
98 
99     status_t initialize(CameraModule *module);
100 
101     virtual status_t dump(int fd, const Vector<String16>& args);
102 
103     virtual status_t dumpClient(int fd, const Vector<String16>& args);
104 
105     /**
106      * Interface used by CameraDeviceBase
107      */
108 
109     virtual void notifyAutoFocus(uint8_t newState, int triggerId);
110     virtual void notifyAutoExposure(uint8_t newState, int triggerId);
111     virtual void notifyShutter(const CaptureResultExtras& resultExtras,
112                                nsecs_t timestamp);
113 
114     /**
115      * Interface used by independent components of Camera2Client.
116      */
117 
118     camera2::SharedParameters& getParameters();
119 
120     int getPreviewStreamId() const;
121     int getCaptureStreamId() const;
122     int getCallbackStreamId() const;
123     int getRecordingStreamId() const;
124     int getZslStreamId() const;
125 
126     status_t registerFrameListener(int32_t minId, int32_t maxId,
127             wp<camera2::FrameProcessor::FilteredListener> listener,
128             bool sendPartials = true);
129     status_t removeFrameListener(int32_t minId, int32_t maxId,
130             wp<camera2::FrameProcessor::FilteredListener> listener);
131 
132     status_t stopStream();
133 
134     // For the slowJpegMode to create jpeg stream when precapture sequence is done
135     status_t createJpegStreamL(camera2::Parameters &params);
136 
137     static size_t calculateBufferSize(int width, int height,
138             int format, int stride);
139 
140     static const int32_t kPreviewRequestIdStart = 10000000;
141     static const int32_t kPreviewRequestIdEnd   = 20000000;
142 
143     static const int32_t kRecordingRequestIdStart  = 20000000;
144     static const int32_t kRecordingRequestIdEnd    = 30000000;
145 
146     static const int32_t kCaptureRequestIdStart = 30000000;
147     static const int32_t kCaptureRequestIdEnd   = 40000000;
148 
149     // Constant strings for ATRACE logging
150     static const char* kAutofocusLabel;
151     static const char* kTakepictureLabel;
152 
153     // Used with stream IDs
154     static const int NO_STREAM = -1;
155 
156 private:
157     /** ICamera interface-related private members */
158     typedef camera2::Parameters Parameters;
159 
160     status_t setPreviewWindowL(const sp<IBinder>& binder,
161             sp<Surface> window);
162     status_t startPreviewL(Parameters &params, bool restart);
163     void     stopPreviewL();
164     status_t startRecordingL(Parameters &params, bool restart);
165     bool     recordingEnabledL();
166 
167     // Individual commands for sendCommand()
168     status_t commandStartSmoothZoomL();
169     status_t commandStopSmoothZoomL();
170     status_t commandSetDisplayOrientationL(int degrees);
171     status_t commandEnableShutterSoundL(bool enable);
172     status_t commandPlayRecordingSoundL();
173     status_t commandStartFaceDetectionL(int type);
174     status_t commandStopFaceDetectionL(Parameters &params);
175     status_t commandEnableFocusMoveMsgL(bool enable);
176     status_t commandPingL();
177     status_t commandSetVideoBufferCountL(size_t count);
178     status_t commandSetVideoFormatL(int format, android_dataspace dataSpace);
179 
180     // Current camera device configuration
181     camera2::SharedParameters mParameters;
182 
183     /** Camera device-related private members */
184 
185     void     setPreviewCallbackFlagL(Parameters &params, int flag);
186     status_t updateRequests(Parameters &params);
187 
188     template <typename ProcessorT>
189     status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params);
190     template <typename ProcessorT,
191               status_t (ProcessorT::*updateStreamF)(const Parameters &)>
192     status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params);
193 
194     sp<camera2::FrameProcessor> mFrameProcessor;
195 
196     /* Preview/Recording related members */
197 
198     sp<IBinder> mPreviewSurface;
199     sp<camera2::StreamingProcessor> mStreamingProcessor;
200 
201     /** Preview callback related members */
202 
203     sp<camera2::CallbackProcessor> mCallbackProcessor;
204 
205     /* Still image capture related members */
206 
207     sp<camera2::CaptureSequencer> mCaptureSequencer;
208     sp<camera2::JpegProcessor> mJpegProcessor;
209     sp<camera2::ZslProcessorInterface> mZslProcessor;
210     sp<Thread> mZslProcessorThread;
211 
212     /** Notification-related members */
213 
214     bool mAfInMotion;
215 
216     /** Utility members */
217     bool mLegacyMode;
218 
219     // Wait until the camera device has received the latest control settings
220     status_t syncWithDevice();
221 
222     // Video snapshot jpeg size overriding helper function
223     status_t overrideVideoSnapshotSize(Parameters &params);
224 };
225 
226 }; // namespace android
227 
228 #endif
229