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"
57 #define NODE_PREFIX "/dev/video"
59 #define NUM_MAX_STREAM_THREAD (5)
60 #define NUM_MAX_DEQUEUED_REQUEST (8)
61 /* #define NUM_MAX_REQUEST_MGR_ENTRY NUM_MAX_DEQUEUED_REQUEST */
62 #define NUM_MAX_REQUEST_MGR_ENTRY (10)
63 #define MAX_CAMERA_MEMORY_PLANE_NUM (4)
64 #define NUM_MAX_CAMERA_BUFFERS (16)
65 #define NUM_BAYER_BUFFERS (8)
66 #define NUM_SENSOR_QBUF (4)
68 #define PREVIEW_GSC_NODE_NUM (1)
69 #define PICTURE_GSC_NODE_NUM (2)
71 #define SIGNAL_MAIN_REQ_Q_NOT_EMPTY (SIGNAL_THREAD_COMMON_LAST<<1)
72 #define SIGNAL_MAIN_REPROCESS_Q_NOT_EMPTY (SIGNAL_THREAD_COMMON_LAST<<2)
73 #define SIGNAL_MAIN_STREAM_OUTPUT_DONE (SIGNAL_THREAD_COMMON_LAST<<3)
74 #define SIGNAL_SENSOR_START_REQ_PROCESSING (SIGNAL_THREAD_COMMON_LAST<<4)
75 #define SIGNAL_STREAM_GET_BUFFER (SIGNAL_THREAD_COMMON_LAST<<5)
76 #define SIGNAL_STREAM_PUT_BUFFER (SIGNAL_THREAD_COMMON_LAST<<6)
77 #define SIGNAL_STREAM_CHANGE_PARAMETER (SIGNAL_THREAD_COMMON_LAST<<7)
78 #define SIGNAL_THREAD_RELEASE (SIGNAL_THREAD_COMMON_LAST<<8)
79 #define SIGNAL_ISP_START_BAYER_INPUT (SIGNAL_THREAD_COMMON_LAST<<9)
80 #define SIGNAL_ISP_START_BAYER_DEQUEUE (SIGNAL_THREAD_COMMON_LAST<<10)
82 #define SIGNAL_STREAM_DATA_COMING (SIGNAL_THREAD_COMMON_LAST<<15)
87 SENSOR_NAME_S5K3H2
= 1,
88 SENSOR_NAME_S5K6A3
= 2,
89 SENSOR_NAME_S5K4E5
= 3,
90 SENSOR_NAME_S5K3H7
= 4,
91 SENSOR_NAME_CUSTOM
= 5,
96 typedef struct node_info
{
103 enum v4l2_memory memory
;
104 enum v4l2_buf_type type
;
105 ion_client ionClient
;
106 ExynosBuffer buffer
[NUM_MAX_CAMERA_BUFFERS
];
111 typedef struct camera_hw_info
{
119 struct camera2_shot_ext dummy_shot
;
123 typedef enum request_entry_status
{
128 } request_entry_status_t
;
130 typedef struct request_manager_entry
{
131 request_entry_status_t status
;
132 camera_metadata_t
*original_request
;
133 struct camera2_shot_ext internal_shot
;
134 int output_stream_count
;
135 bool dynamic_meta_vaild
;
136 } request_manager_entry_t
;
138 class RequestManager
{
140 RequestManager(SignalDrivenThread
* main_thread
);
143 bool IsRequestQueueFull();
145 void RegisterRequest(camera_metadata_t
*new_request
);
146 void DeregisterRequest(camera_metadata_t
**deregistered_request
);
147 bool PrepareFrame(size_t *num_entries
, size_t *frame_size
,
148 camera_metadata_t
**prepared_frame
);
149 int MarkProcessingRequest(ExynosBuffer
*buf
);
150 void NotifyStreamOutput(int frameCnt
, int stream_id
);
151 void DumpInfoWithIndex(int index
);
152 void ApplyDynamicMetadata(struct camera2_shot_ext
*shot_ext
, int frameCnt
);
153 void CheckCompleted(int index
);
154 void UpdateOutputStreamInfo(struct camera2_shot_ext
*shot_ext
, int frameCnt
);
155 void RegisterTimestamp(int frameCnt
, nsecs_t
*frameTime
);
156 uint64_t GetTimestamp(int frameCnt
);
157 int FindFrameCnt(struct camera2_shot_ext
* shot_ext
);
158 int FindEntryIndexByFrameCnt(int frameCnt
);
160 int GetNextIndex(int index
);
161 void SetDefaultParameters(int cropX
);
162 void SetInitialSkip(int count
);
165 MetadataConverter
*m_metadataConverter
;
166 SignalDrivenThread
*m_mainThread
;
168 int m_entryInsertionIndex
;
169 int m_entryProcessingIndex
;
170 int m_entryFrameOutputIndex
;
171 request_manager_entry_t entries
[NUM_MAX_REQUEST_MGR_ENTRY
];
172 int m_completedIndex
;
174 Mutex m_requestMutex
;
176 //TODO : alloc dynamically
177 char m_tempFrameMetadataBuf
[2000];
178 camera_metadata_t
*m_tempFrameMetadata
;
180 int m_sensorPipelineSkipCnt
;
186 typedef struct bayer_buf_entry
{
193 class BayerBufManager
{
197 int GetIndexForSensorEnqueue();
198 int MarkSensorEnqueue(int index
);
199 int MarkSensorDequeue(int index
, int reqFrameCnt
, nsecs_t
*timeStamp
);
200 int GetIndexForIspEnqueue(int *reqFrameCnt
);
201 int GetIndexForIspDequeue(int *reqFrameCnt
);
202 int MarkIspEnqueue(int index
);
203 int MarkIspDequeue(int index
);
204 int GetNumOnSensor();
205 int GetNumOnHalFilled();
209 int GetNextIndex(int index
);
211 int sensorEnqueueHead
;
212 int sensorDequeueHead
;
220 bayer_buf_entry_t entries
[NUM_BAYER_BUFFERS
];
224 #define NOT_AVAILABLE (0)
225 #define REQUIRES_DQ_FROM_SVC (1)
226 #define ON_DRIVER (2)
228 #define ON_SERVICE (4)
230 #define BAYER_NOT_AVAILABLE (0)
231 #define BAYER_ON_SENSOR (1)
232 #define BAYER_ON_HAL_FILLED (2)
233 #define BAYER_ON_ISP (3)
234 #define BAYER_ON_SERVICE (4)
235 #define BAYER_ON_HAL_EMPTY (5)
237 typedef struct stream_parameters
{
239 uint32_t outputWidth
;
240 uint32_t outputHeight
;
245 const camera2_stream_ops_t
* streamOps
;
249 int numOwnSvcBuffers
;
253 enum v4l2_memory memory
;
254 enum v4l2_buf_type halBuftype
;
256 buffer_handle_t svcBufHandle
[NUM_MAX_CAMERA_BUFFERS
];
257 ExynosBuffer svcBuffers
[NUM_MAX_CAMERA_BUFFERS
];
258 int svcBufStatus
[NUM_MAX_CAMERA_BUFFERS
];
260 ion_client ionClient
;
262 } stream_parameters_t
;
264 typedef struct record_parameters
{
265 uint32_t outputWidth
;
266 uint32_t outputHeight
;
268 const camera2_stream_ops_t
* streamOps
;
271 int numOwnSvcBuffers
;
273 buffer_handle_t svcBufHandle
[NUM_MAX_CAMERA_BUFFERS
];
274 ExynosBuffer svcBuffers
[NUM_MAX_CAMERA_BUFFERS
];
275 int svcBufStatus
[NUM_MAX_CAMERA_BUFFERS
];
278 } record_parameters_t
;
280 class ExynosCameraHWInterface2
: public virtual RefBase
{
282 ExynosCameraHWInterface2(int cameraId
, camera2_device_t
*dev
);
283 virtual ~ExynosCameraHWInterface2();
285 virtual void release();
287 inline int getCameraId() const;
289 virtual int setRequestQueueSrcOps(const camera2_request_queue_src_ops_t
*request_src_ops
);
290 virtual int notifyRequestQueueNotEmpty();
291 virtual int setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t
*frame_dst_ops
);
292 virtual int getInProgressCount();
293 virtual int flushCapturesInProgress();
294 virtual int constructDefaultRequest(int request_template
, camera_metadata_t
**request
);
295 virtual int allocateStream(uint32_t width
, uint32_t height
,
296 int format
, const camera2_stream_ops_t
*stream_ops
,
297 uint32_t *stream_id
, uint32_t *format_actual
, uint32_t *usage
, uint32_t *max_buffers
);
298 virtual int registerStreamBuffers(uint32_t stream_id
, int num_buffers
, buffer_handle_t
*buffers
);
299 virtual int releaseStream(uint32_t stream_id
);
300 virtual int allocateReprocessStream(uint32_t width
, uint32_t height
,
301 uint32_t format
, const camera2_stream_in_ops_t
*reprocess_stream_ops
,
302 uint32_t *stream_id
, uint32_t *consumer_usage
, uint32_t *max_buffers
);
303 virtual int releaseReprocessStream(uint32_t stream_id
);
304 virtual int triggerAction(uint32_t trigger_id
, int ext1
, int ext2
);
305 virtual int setNotifyCallback(camera2_notify_callback notify_cb
, void *user
);
306 virtual int getMetadataVendorTagOps(vendor_tag_query_ops_t
**ops
);
307 virtual int dump(int fd
);
309 class MainThread
: public SignalDrivenThread
{
310 ExynosCameraHWInterface2
*mHardware
;
312 MainThread(ExynosCameraHWInterface2
*hw
):
313 SignalDrivenThread(),
315 // Start("MainThread", PRIORITY_DEFAULT, 0);
318 status_t
readyToRunInternal()
322 void threadFunctionInternal()
324 mHardware
->m_mainThreadFunc(this);
330 class SensorThread
: public SignalDrivenThread
{
331 ExynosCameraHWInterface2
*mHardware
;
333 SensorThread(ExynosCameraHWInterface2
*hw
):
334 SignalDrivenThread("SensorThread", PRIORITY_DEFAULT
, 0),
336 m_isBayerOutputEnabled(false) { }
338 status_t
readyToRunInternal() {
339 mHardware
->m_sensorThreadInitialize(this);
342 void threadFunctionInternal() {
343 mHardware
->m_sensorThreadFunc(this);
348 bool m_isBayerOutputEnabled
;
352 class IspThread
: public SignalDrivenThread
{
353 ExynosCameraHWInterface2
*mHardware
;
355 IspThread(ExynosCameraHWInterface2
*hw
):
356 SignalDrivenThread("IspThread", PRIORITY_DEFAULT
, 0),
359 status_t
readyToRunInternal() {
360 mHardware
->m_ispThreadInitialize(this);
363 void threadFunctionInternal() {
364 mHardware
->m_ispThreadFunc(this);
372 class StreamThread
: public SignalDrivenThread
{
373 ExynosCameraHWInterface2
*mHardware
;
375 StreamThread(ExynosCameraHWInterface2
*hw
, uint8_t new_index
):
376 SignalDrivenThread("StreamThread", PRIORITY_DEFAULT
, 0),
378 m_index(new_index
) { }
380 status_t
readyToRunInternal() {
381 mHardware
->m_streamThreadInitialize(this);
384 void threadFunctionInternal() {
385 mHardware
->m_streamThreadFunc(this);
388 void setRecordingParameter(record_parameters_t
* recordParm
);
389 void setParameter(stream_parameters_t
* new_parameters
);
390 void applyChange(void);
392 int findBufferIndex(void * bufAddr
);
398 stream_parameters_t m_parameters
;
399 stream_parameters_t
*m_tempParameters
;
400 record_parameters_t m_recordParameters
;
405 sp
<MainThread
> m_mainThread
;
406 sp
<SensorThread
> m_sensorThread
;
407 sp
<IspThread
> m_ispThread
;
408 sp
<StreamThread
> m_streamThreads
[NUM_MAX_STREAM_THREAD
];
412 RequestManager
*m_requestManager
;
413 BayerBufManager
*m_BayerManager
;
415 void m_mainThreadFunc(SignalDrivenThread
* self
);
416 void m_sensorThreadFunc(SignalDrivenThread
* self
);
417 void m_sensorThreadInitialize(SignalDrivenThread
* self
);
418 void m_ispThreadFunc(SignalDrivenThread
* self
);
419 void m_ispThreadInitialize(SignalDrivenThread
* self
);
420 void m_streamThreadFunc(SignalDrivenThread
* self
);
421 void m_streamThreadInitialize(SignalDrivenThread
* self
);
423 void m_getAlignedYUVSize(int colorFormat
, int w
, int h
,
425 bool m_getRatioSize(int src_w
, int src_h
,
426 int dst_w
, int dst_h
,
427 int *crop_x
, int *crop_y
,
428 int *crop_w
, int *crop_h
,
430 int createIonClient(ion_client ionClient
);
431 int deleteIonClient(ion_client ionClient
);
433 int allocCameraMemory(ion_client ionClient
, ExynosBuffer
*buf
, int iMemoryNum
);
434 void freeCameraMemory(ExynosBuffer
*buf
, int iMemoryNum
);
435 void initCameraMemory(ExynosBuffer
*buf
, int iMemoryNum
);
437 void DumpInfoWithShot(struct camera2_shot_ext
* shot_ext
);
438 bool yuv2Jpeg(ExynosBuffer
*yuvBuf
,
439 ExynosBuffer
*jpegBuf
,
441 exif_attribute_t mExifInfo
;
442 void *m_exynosPictureCSC
;
443 void *m_exynosVideoCSC
;
445 int m_jpegEncodingFrameCnt
;
447 camera2_request_queue_src_ops_t
*m_requestQueueOps
;
448 camera2_frame_queue_dst_ops_t
*m_frameQueueOps
;
449 camera2_notify_callback m_notifyCb
;
450 void *m_callbackCookie
;
452 int m_numOfRemainingReqInSvc
;
453 bool m_isRequestQueuePending
;
454 bool m_isRequestQueueNull
;
455 camera2_device_t
*m_halDevice
;
456 static gralloc_module_t
const* m_grallocHal
;
459 camera_hw_info_t m_camera_info
;
461 ion_client m_ionCameraClient
;
463 bool m_isSensorThreadOn
;
464 bool m_isSensorStarted
;
470 int m_ispProcessingFrameCnt
;
472 int indexToQueue
[3+1];
477 ExynosBuffer m_resizeBuf
;
478 ExynosBuffer m_resizeBuf2
;
479 bool m_recordingEnabled
;
482 bool m_needsRecordBufferInit
;
490 }; // namespace android