/*
|
* Copyright (c) 2021 by Allwinnertech Co., Ltd.
|
*
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* you may not use this file except in compliance with the License.
|
* You may obtain a copy of the License at
|
*
|
* http://www.apache.org/licenses/LICENSE-2.0
|
*
|
* Unless required by applicable law or agreed to in writing, software
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* See the License for the specific language governing permissions and
|
* limitations under the License.
|
*/
|
|
#ifndef V4L2_CAMERA_HAL_COMMON_H_
|
#define V4L2_CAMERA_HAL_COMMON_H_
|
|
#ifndef LOG_TAG
|
#define LOG_TAG "CameraHALv3_4"
|
#endif
|
|
#include <sys/time.h>
|
#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
|
#include <utils/Trace.h>
|
#include <linux/videodev2.h>
|
#include <system/graphics.h>
|
#include <hardware/gralloc.h>
|
#include <map>
|
#include <string>
|
|
#define ALIGN_4K(x) (((x) + (4095)) & ~(4095))
|
#define ALIGN_32B(x) (((x) + (31)) & ~(31))
|
#define ALIGN_16B(x) (((x) + (15)) & ~(15))
|
#define ALIGN_8B(x) (((x) + (7)) & ~(7))
|
|
#define DBG_CAMERA 0
|
#define DBG_CAMERA_CONFIG 0
|
#define DBG_CAMERA_HAL 0
|
#define DBG_CAMERA_STREAM 0
|
#define DBG_STREAM_MANAGER 0
|
#define DBG_V4L2_CAMERA 0
|
#define DBG_V4L2_GRALLOC 0
|
#define DBG_V4L2_STREAM 0
|
#define DBG_V4L2_WRAPPER 0
|
// Debug setting.
|
#define DBG_PERFORMANCE 0
|
#define DBG_SAVE_OUTPUT 0
|
|
// Fix confliction in case it's defined elsewhere.
|
#ifndef DISALLOW_COPY_AND_ASSIGN
|
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
TypeName(const TypeName&); \
|
void operator=(const TypeName&);
|
#endif
|
|
// Common setting.
|
|
#define DEVICE_FACING_FRONT 1
|
#define DEVICE_FACING_BACK 0
|
#define TIMEOUT_COUNT 0
|
#define MAX_STREAM_NUM 3
|
#define DROP_BUFFERS_NUM 3
|
#define MAX_FRAME_NUM 128
|
// ms delay between stream on and off.
|
#define DELAY_BETWEEN_STREAM 500
|
#define DELAY_BETWEEN_ON_OFF 0
|
|
#define MAIN_STREAM_PATH "/dev/video0"
|
#define SUB_0_STREAM_PATH "/dev/video1"
|
#define MAIN_MERGE_STREAM_PATH "/dev/video1"
|
#define SUB_0_MERGE_STREAM_PATH "dev/video3"
|
#if defined __A100__ || defined __T509__
|
#define MAIN_FRONT_STREAM_PATH "/dev/video2"
|
#define SUB_0_FRONT_STREAM_PATH "/dev/video3"
|
#else
|
#define MAIN_FRONT_STREAM_PATH "/dev/video0"
|
#define SUB_0_FRONT_STREAM_PATH "/dev/video1"
|
#endif
|
|
enum STREAM_SERIAL {
|
MAIN_STREAM = 0,
|
MAIN_STREAM_BLOB,
|
SUB_0_STREAM,
|
SUB_0_STREAM_BLOB,
|
MAIN_MIRROR_STREAM,
|
MAIN_MIRROR_STREAM_BLOB,
|
SUB_0_MIRROR_STREAM,
|
SUB_0_MIRROR_STREAM_BLOB,
|
MAX_STREAM,
|
ERROR_STREAM
|
};
|
|
|
// Platform setting.
|
#if defined __A50__
|
#define MAX_NUM_OF_STREAMS 1
|
|
#define USE_CSI_VIN_DRIVER
|
#define USE_ISP
|
|
#define MAX_BUFFER_NUM 3
|
#define MAX_BUFFER_CSI_RESERVE 2
|
#define PICTURE_BUFFER_NUM 1
|
|
#define V4L2_PIX_FMT_DEFAULT V4L2_PIX_FMT_NV21
|
|
// Platform setting.
|
#elif defined __A100__
|
#define MAX_NUM_OF_STREAMS 1
|
|
#define USE_CSI_VIN_DRIVER
|
#define USE_ISP
|
|
#define MAX_BUFFER_NUM 3
|
#define MAX_BUFFER_CSI_RESERVE 2
|
#define PICTURE_BUFFER_NUM 1
|
|
#define V4L2_PIX_FMT_DEFAULT V4L2_PIX_FMT_NV21
|
|
// Platform setting.
|
#elif defined __T3__
|
#define MAX_NUM_OF_STREAMS 1
|
|
#define USE_CSI_VIN_DRIVER
|
#define USE_ISP
|
|
#define MAX_BUFFER_NUM 3
|
#define MAX_BUFFER_CSI_RESERVE 2
|
#define PICTURE_BUFFER_NUM 1
|
|
#define V4L2_PIX_FMT_DEFAULT V4L2_PIX_FMT_NV21
|
|
#elif defined __A63__
|
#define MAX_NUM_OF_STREAMS 1
|
|
#define USE_CSI_VIN_DRIVER
|
|
#define MAX_BUFFER_NUM 3
|
#define MAX_BUFFER_CSI_RESERVE 2
|
#define PICTURE_BUFFER_NUM 1
|
|
#define V4L2_PIX_FMT_DEFAULT V4L2_PIX_FMT_NV21
|
|
// universal implement.
|
#else
|
#define MAX_NUM_OF_STREAMS 1
|
|
#define USE_CSI_VIN_DRIVER
|
#define USE_ISP
|
|
#define MAX_BUFFER_NUM 3
|
#define MAX_BUFFER_CSI_RESERVE 2
|
#define PICTURE_BUFFER_NUM 1
|
|
#define V4L2_PIX_FMT_DEFAULT V4L2_PIX_FMT_NV21
|
|
#endif
|
|
#ifdef USE_CSI_VIN_DRIVER
|
#define V4L2_CAPTURE_TYPE V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
|
#else
|
#define V4L2_CAPTURE_TYPE V4L2_BUF_TYPE_VIDEO_CAPTURE
|
#endif
|
|
// Tools for save buffers.
|
#define DBG_BUFFER_SAVE 0
|
#define DBG_BUFFER_SAVE_ONE_FRAME 1
|
#define DBG_BUFFER_SAVE_MORE_FRAME 0
|
|
#define PATH "/data/camera/"
|
extern void * buffers_addr[MAX_BUFFER_NUM];
|
extern bool saveBuffers(char *str,
|
void *p,
|
unsigned int length,
|
bool is_oneframe);
|
|
extern bool saveBuffers(const char *path,
|
void *y_addr,
|
void *cr_addr,
|
unsigned int y_size,
|
unsigned int cr_size,
|
bool is_oneframe);
|
|
extern bool saveSizes(int width, int height);
|
extern int getSingleCameraId();
|
extern int getSupportCameraId(int cameraId);
|
|
typedef uint8_t byte;
|
typedef int32_t int32;
|
typedef int64_t int64;
|
|
#define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
|
#define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
|
|
extern std::map<int, std::string> v4l2_ioctl_map;
|
extern std::map<int, std::string> hal_pixel_format_map;
|
extern std::map<int, std::string> v4l2_pixel_format_map;
|
extern std::map<int, std::string> gralloc_usage_map;
|
|
extern std::string getV4l2IoctlString(int v4l2_ioctl_request);
|
extern std::string getHalPixelFormatString(int hal_pixel_format);
|
extern std::string getV4l2PixelFormatString(int v4l2_pixel_format);
|
extern std::string getGrallocUsageString(int usage);
|
#endif // V4L2_CAMERA_HAL_COMMON_H_
|