3 ** Copyright 2008, The Android Open Source Project
4 ** Copyright 2012, Samsung Electronics Co. LTD
6 ** Licensed under the Apache License, Version 2.0 (the "License");
7 ** you may not use this file except in compliance with the License.
8 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
20 * \file ExynosCameraHWInterface2.h
21 * \brief header file for Android Camera API 2.0 HAL
22 * \author Sungjoong Kang(sj3.kang@samsung.com)
25 * <b>Revision History: </b>
26 * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n
29 * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n
34 #ifndef EXYNOS_CAMERA_HW_INTERFACE_2_H
35 #define EXYNOS_CAMERA_HW_INTERFACE_2_H
37 #include <hardware/camera2.h>
38 #include <camera/Camera.h>
39 #include <camera/CameraParameters.h>
40 #include "SignalDrivenThread.h"
41 #include "MetadataConverter.h"
42 #include "exynos_v4l2.h"
43 #include "ExynosRect.h"
44 #include "ExynosBuffer.h"
45 #include "videodev2_exynos_camera.h"
46 #include "gralloc_priv.h"
47 #include "ExynosJpegEncoderForCamera.h"
49 #include "fimc-is-metadata.h"
51 #include "ExynosExif.h"
53 #include "ExynosCamera2.h"
58 #define NODE_PREFIX "/dev/video"
60 #define NUM_MAX_STREAM_THREAD (5)
61 #define NUM_MAX_DEQUEUED_REQUEST (6)
62 /* #define NUM_MAX_REQUEST_MGR_ENTRY NUM_MAX_DEQUEUED_REQUEST */
63 #define NUM_MAX_REQUEST_MGR_ENTRY (10)
64 #define MAX_CAMERA_MEMORY_PLANE_NUM (4)
65 #define NUM_MAX_CAMERA_BUFFERS (16)
66 #define NUM_BAYER_BUFFERS (8)
67 #define NUM_SENSOR_QBUF (3)
69 #define PREVIEW_GSC_NODE_NUM (1)
70 #define PICTURE_GSC_NODE_NUM (2)
72 #define SIGNAL_MAIN_REQ_Q_NOT_EMPTY (SIGNAL_THREAD_COMMON_LAST<<1)
73 #define SIGNAL_MAIN_REPROCESS_Q_NOT_EMPTY (SIGNAL_THREAD_COMMON_LAST<<2)
74 #define SIGNAL_MAIN_STREAM_OUTPUT_DONE (SIGNAL_THREAD_COMMON_LAST<<3)
75 #define SIGNAL_SENSOR_START_REQ_PROCESSING (SIGNAL_THREAD_COMMON_LAST<<4)
76 #define SIGNAL_STREAM_GET_BUFFER (SIGNAL_THREAD_COMMON_LAST<<5)
77 #define SIGNAL_STREAM_PUT_BUFFER (SIGNAL_THREAD_COMMON_LAST<<6)
78 #define SIGNAL_STREAM_CHANGE_PARAMETER (SIGNAL_THREAD_COMMON_LAST<<7)
79 #define SIGNAL_THREAD_RELEASE (SIGNAL_THREAD_COMMON_LAST<<8)
80 #define SIGNAL_ISP_START_BAYER_INPUT (SIGNAL_THREAD_COMMON_LAST<<9)
81 #define SIGNAL_ISP_START_BAYER_DEQUEUE (SIGNAL_THREAD_COMMON_LAST<<10)
83 #define SIGNAL_STREAM_DATA_COMING (SIGNAL_THREAD_COMMON_LAST<<15)
88 SENSOR_NAME_S5K3H2
= 1,
89 SENSOR_NAME_S5K6A3
= 2,
90 SENSOR_NAME_S5K4E5
= 3,
91 SENSOR_NAME_S5K3H7
= 4,
92 SENSOR_NAME_CUSTOM
= 5,
97 typedef struct node_info
{
104 enum v4l2_memory memory
;
105 enum v4l2_buf_type type
;
106 ion_client ionClient
;
107 ExynosBuffer buffer
[NUM_MAX_CAMERA_BUFFERS
];
112 typedef struct camera_hw_info
{
120 struct camera2_shot_ext dummy_shot
;
124 typedef enum request_entry_status
{
129 } request_entry_status_t
;
131 typedef struct request_manager_entry
{
132 request_entry_status_t status
;
133 camera_metadata_t
*original_request
;
134 struct camera2_shot_ext internal_shot
;
135 int output_stream_count
;
136 bool dynamic_meta_vaild
;
137 } request_manager_entry_t
;
139 class RequestManager
{
141 RequestManager(SignalDrivenThread
* main_thread
);
144 bool IsRequestQueueFull();
146 void RegisterRequest(camera_metadata_t
*new_request
);
147 void DeregisterRequest(camera_metadata_t
**deregistered_request
);
148 bool PrepareFrame(size_t *num_entries
, size_t *frame_size
,
149 camera_metadata_t
**prepared_frame
);
150 int MarkProcessingRequest(ExynosBuffer
*buf
);
151 void NotifyStreamOutput(int frameCnt
, int stream_id
);
152 void DumpInfoWithIndex(int index
);
153 void ApplyDynamicMetadata(struct camera2_shot_ext
*shot_ext
, int frameCnt
);
154 void CheckCompleted(int index
);
155 void UpdateIspParameters(struct camera2_shot_ext
*shot_ext
, int frameCnt
);
156 void RegisterTimestamp(int frameCnt
, nsecs_t
*frameTime
);
157 uint64_t GetTimestamp(int frameCnt
);
158 int FindFrameCnt(struct camera2_shot_ext
* shot_ext
);
159 int FindEntryIndexByFrameCnt(int frameCnt
);
161 int GetNextIndex(int index
);
162 void SetDefaultParameters(int cropX
);
163 void SetInitialSkip(int count
);
166 MetadataConverter
*m_metadataConverter
;
167 SignalDrivenThread
*m_mainThread
;
169 int m_entryInsertionIndex
;
170 int m_entryProcessingIndex
;
171 int m_entryFrameOutputIndex
;
172 request_manager_entry_t entries
[NUM_MAX_REQUEST_MGR_ENTRY
];
173 int m_completedIndex
;
175 Mutex m_requestMutex
;
177 //TODO : alloc dynamically
178 char m_tempFrameMetadataBuf
[2000];
179 camera_metadata_t
*m_tempFrameMetadata
;
181 int m_sensorPipelineSkipCnt
;
187 typedef struct bayer_buf_entry
{
194 class BayerBufManager
{
198 int GetIndexForSensorEnqueue();
199 int MarkSensorEnqueue(int index
);
200 int MarkSensorDequeue(int index
, int reqFrameCnt
, nsecs_t
*timeStamp
);
201 int GetIndexForIspEnqueue(int *reqFrameCnt
);
202 int GetIndexForIspDequeue(int *reqFrameCnt
);
203 int MarkIspEnqueue(int index
);
204 int MarkIspDequeue(int index
);
205 int GetNumOnSensor();
206 int GetNumOnHalFilled();
210 int GetNextIndex(int index
);
212 int sensorEnqueueHead
;
213 int sensorDequeueHead
;
221 bayer_buf_entry_t entries
[NUM_BAYER_BUFFERS
];
225 #define NOT_AVAILABLE (0)
226 #define REQUIRES_DQ_FROM_SVC (1)
227 #define ON_DRIVER (2)
229 #define ON_SERVICE (4)
231 #define BAYER_NOT_AVAILABLE (0)
232 #define BAYER_ON_SENSOR (1)
233 #define BAYER_ON_HAL_FILLED (2)
234 #define BAYER_ON_ISP (3)
235 #define BAYER_ON_SERVICE (4)
236 #define BAYER_ON_HAL_EMPTY (5)
238 typedef struct stream_parameters
{
240 uint32_t outputWidth
;
241 uint32_t outputHeight
;
246 const camera2_stream_ops_t
* streamOps
;
250 int numOwnSvcBuffers
;
254 enum v4l2_memory memory
;
255 enum v4l2_buf_type halBuftype
;
257 buffer_handle_t svcBufHandle
[NUM_MAX_CAMERA_BUFFERS
];
258 ExynosBuffer svcBuffers
[NUM_MAX_CAMERA_BUFFERS
];
259 int svcBufStatus
[NUM_MAX_CAMERA_BUFFERS
];
261 ion_client ionClient
;
263 } stream_parameters_t
;
265 typedef struct record_parameters
{
266 uint32_t outputWidth
;
267 uint32_t outputHeight
;
269 const camera2_stream_ops_t
* streamOps
;
272 int numOwnSvcBuffers
;
274 buffer_handle_t svcBufHandle
[NUM_MAX_CAMERA_BUFFERS
];
275 ExynosBuffer svcBuffers
[NUM_MAX_CAMERA_BUFFERS
];
276 int svcBufStatus
[NUM_MAX_CAMERA_BUFFERS
];
279 } record_parameters_t
;
281 class ExynosCameraHWInterface2
: public virtual RefBase
{
283 ExynosCameraHWInterface2(int cameraId
, camera2_device_t
*dev
, ExynosCamera2
* camera
);
284 virtual ~ExynosCameraHWInterface2();
286 virtual void release();
288 inline int getCameraId() const;
290 virtual int setRequestQueueSrcOps(const camera2_request_queue_src_ops_t
*request_src_ops
);
291 virtual int notifyRequestQueueNotEmpty();
292 virtual int setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t
*frame_dst_ops
);
293 virtual int getInProgressCount();
294 virtual int flushCapturesInProgress();
295 virtual int constructDefaultRequest(int request_template
, camera_metadata_t
**request
);
296 virtual int allocateStream(uint32_t width
, uint32_t height
,
297 int format
, const camera2_stream_ops_t
*stream_ops
,
298 uint32_t *stream_id
, uint32_t *format_actual
, uint32_t *usage
, uint32_t *max_buffers
);
299 virtual int registerStreamBuffers(uint32_t stream_id
, int num_buffers
, buffer_handle_t
*buffers
);
300 virtual int releaseStream(uint32_t stream_id
);
301 virtual int allocateReprocessStream(uint32_t width
, uint32_t height
,
302 uint32_t format
, const camera2_stream_in_ops_t
*reprocess_stream_ops
,
303 uint32_t *stream_id
, uint32_t *consumer_usage
, uint32_t *max_buffers
);
304 virtual int releaseReprocessStream(uint32_t stream_id
);
305 virtual int triggerAction(uint32_t trigger_id
, int ext1
, int ext2
);
306 virtual int setNotifyCallback(camera2_notify_callback notify_cb
, void *user
);
307 virtual int getMetadataVendorTagOps(vendor_tag_query_ops_t
**ops
);
308 virtual int dump(int fd
);
310 class MainThread
: public SignalDrivenThread
{
311 ExynosCameraHWInterface2
*mHardware
;
313 MainThread(ExynosCameraHWInterface2
*hw
):
314 SignalDrivenThread(),
316 // Start("MainThread", PRIORITY_DEFAULT, 0);
319 status_t
readyToRunInternal()
323 void threadFunctionInternal()
325 mHardware
->m_mainThreadFunc(this);
331 class SensorThread
: public SignalDrivenThread
{
332 ExynosCameraHWInterface2
*mHardware
;
334 SensorThread(ExynosCameraHWInterface2
*hw
):
335 SignalDrivenThread("SensorThread", PRIORITY_DEFAULT
, 0),
337 m_isBayerOutputEnabled(false) { }
339 status_t
readyToRunInternal() {
340 mHardware
->m_sensorThreadInitialize(this);
343 void threadFunctionInternal() {
344 mHardware
->m_sensorThreadFunc(this);
349 bool m_isBayerOutputEnabled
;
353 class IspThread
: public SignalDrivenThread
{
354 ExynosCameraHWInterface2
*mHardware
;
356 IspThread(ExynosCameraHWInterface2
*hw
):
357 SignalDrivenThread("IspThread", PRIORITY_DEFAULT
, 0),
360 status_t
readyToRunInternal() {
361 mHardware
->m_ispThreadInitialize(this);
364 void threadFunctionInternal() {
365 mHardware
->m_ispThreadFunc(this);
373 class StreamThread
: public SignalDrivenThread
{
374 ExynosCameraHWInterface2
*mHardware
;
376 StreamThread(ExynosCameraHWInterface2
*hw
, uint8_t new_index
):
377 SignalDrivenThread("StreamThread", PRIORITY_DEFAULT
, 0),
379 m_index(new_index
) { }
381 status_t
readyToRunInternal() {
382 mHardware
->m_streamThreadInitialize(this);
385 void threadFunctionInternal() {
386 mHardware
->m_streamThreadFunc(this);
389 void setRecordingParameter(record_parameters_t
* recordParm
);
390 void setParameter(stream_parameters_t
* new_parameters
);
391 void applyChange(void);
393 int findBufferIndex(void * bufAddr
);
399 stream_parameters_t m_parameters
;
400 stream_parameters_t
*m_tempParameters
;
401 record_parameters_t m_recordParameters
;
406 sp
<MainThread
> m_mainThread
;
407 sp
<SensorThread
> m_sensorThread
;
408 sp
<IspThread
> m_ispThread
;
409 sp
<StreamThread
> m_streamThreads
[NUM_MAX_STREAM_THREAD
];
413 RequestManager
*m_requestManager
;
414 BayerBufManager
*m_BayerManager
;
415 ExynosCamera2
*m_camera2
;
417 void m_mainThreadFunc(SignalDrivenThread
* self
);
418 void m_sensorThreadFunc(SignalDrivenThread
* self
);
419 void m_sensorThreadInitialize(SignalDrivenThread
* self
);
420 void m_ispThreadFunc(SignalDrivenThread
* self
);
421 void m_ispThreadInitialize(SignalDrivenThread
* self
);
422 void m_streamThreadFunc(SignalDrivenThread
* self
);
423 void m_streamThreadInitialize(SignalDrivenThread
* self
);
425 void m_getAlignedYUVSize(int colorFormat
, int w
, int h
,
427 bool m_getRatioSize(int src_w
, int src_h
,
428 int dst_w
, int dst_h
,
429 int *crop_x
, int *crop_y
,
430 int *crop_w
, int *crop_h
,
432 int createIonClient(ion_client ionClient
);
433 int deleteIonClient(ion_client ionClient
);
435 int allocCameraMemory(ion_client ionClient
, ExynosBuffer
*buf
, int iMemoryNum
);
436 void freeCameraMemory(ExynosBuffer
*buf
, int iMemoryNum
);
437 void initCameraMemory(ExynosBuffer
*buf
, int iMemoryNum
);
439 void DumpInfoWithShot(struct camera2_shot_ext
* shot_ext
);
440 bool yuv2Jpeg(ExynosBuffer
*yuvBuf
,
441 ExynosBuffer
*jpegBuf
,
443 exif_attribute_t mExifInfo
;
444 void *m_exynosPictureCSC
;
445 void *m_exynosVideoCSC
;
447 int m_jpegEncodingFrameCnt
;
449 camera2_request_queue_src_ops_t
*m_requestQueueOps
;
450 camera2_frame_queue_dst_ops_t
*m_frameQueueOps
;
451 camera2_notify_callback m_notifyCb
;
452 void *m_callbackCookie
;
454 int m_numOfRemainingReqInSvc
;
455 bool m_isRequestQueuePending
;
456 bool m_isRequestQueueNull
;
457 camera2_device_t
*m_halDevice
;
458 static gralloc_module_t
const* m_grallocHal
;
461 camera_hw_info_t m_camera_info
;
463 ion_client m_ionCameraClient
;
465 bool m_isSensorThreadOn
;
466 bool m_isSensorStarted
;
472 int m_ispProcessingFrameCnt
;
474 int indexToQueue
[3+1];
479 ExynosBuffer m_resizeBuf
;
480 bool m_recordingEnabled
;
483 bool m_needsRecordBufferInit
;
491 }; // namespace android