Squashed 'camera/' content from commit 4d6400170

git-subtree-dir: camera
git-subtree-split: 4d64001700fe361fa152f23b310991c1079f6a87
This commit is contained in:
pix106 2023-11-30 06:21:25 +01:00
commit 1462c4955c
162 changed files with 158348 additions and 0 deletions

31
Android.mk Normal file
View file

@ -0,0 +1,31 @@
ifeq ($(call my-dir),$(call project-path-for,qcom-camera))
MM_V4L2_DRIVER_LIST += msm8960
MM_V4L2_DRIVER_LIST += msm8974
MM_V4L2_DRIVER_LIST += msm8916
MM_V4L2_DRIVER_LIST += msm8226
MM_V4L2_DRIVER_LIST += msm8610
MM_V4L2_DRIVER_LIST += apq8084
MM_V4L2_DRIVER_LIST += mpq8092
MM_V4L2_DRIVER_LIST += msm_bronze
MM_V4L2_DRIVER_LIST += msm8916
MM_V4L2_DRIVER_LIST += msm8994
MM_V4L2_DRIVER_LIST += msm8084
MM_V4L2_DRIVER_LIST += msm8909
MM_V4L2_DRIVER_LIST += msm8952
MM_V4L2_DRIVER_LIST += msm8996
MM_V4L2_DRIVER_LIST += msm8992
MM_V4L2_DRIVER_LIST += msm8937
MM_V4L2_DRIVER_LIST += msm8953
MM_V4L2_DRIVER_LIST += apq8098_latv
MM_V4L2_DRIVER_LIST += msm8998
MM_V4L2_DRIVER_LIST += sdm660
MM_V4L2_DRIVER_LIST += $(TRINKET)
ifneq (,$(filter $(MM_V4L2_DRIVER_LIST),$(TARGET_BOARD_PLATFORM)))
ifneq ($(strip $(USE_CAMERA_STUB)),true)
ifneq ($(BUILD_TINY_ANDROID),true)
include $(call all-subdir-makefiles)
endif
endif
endif
endif

47
CleanSpec.mk Normal file
View file

@ -0,0 +1,47 @@
# Copyright (C) 2007 The Android Open Source Project
#
# 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.
#
# If you don't need to do a full clean build but would like to touch
# a file or delete some intermediate files, add a clean step to the end
# of the list. These steps will only be run once, if they haven't been
# run before.
#
# E.g.:
# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
#
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
# files that are missing or have been moved.
#
# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
# Use $(OUT_DIR) to refer to the "out" directory.
#
# If you need to re-do something that's already mentioned, just copy
# the command and add it to the bottom of the list. E.g., if a change
# that you made last week required touching a file and a change you
# made today requires touching the same file, just copy the old
# touch step and add it to the end of the list.
#
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
# For example:
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
$(call add-clean-step, find $(OUT_DIR) -name "camera.sdm660*" -print0 | xargs -0 rm -rf)

0
MODULE_LICENSE_BSD Normal file
View file

247
QCamera2/Android.mk Normal file
View file

@ -0,0 +1,247 @@
ifneq (,$(filter $(TARGET_ARCH), arm arm64))
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
SDCLANG_COMMON_DEFS := $(LOCAL_PATH)/sdllvm-common-defs.mk
SDCLANG_FLAG_DEFS := $(LOCAL_PATH)/sdllvm-flag-defs.mk
ifneq ($(call is-platform-sdk-version-at-least,28),true)
IS_QC_BOKEH_SUPPORTED := true
else
IS_QC_BOKEH_SUPPORTED := false
endif
ifeq ($(call is-platform-sdk-version-at-least,28),true)
ENABLE_MULTICAM_SUPPORT := true
endif
LOCAL_SRC_FILES := \
util/QCameraBufferMaps.cpp \
util/QCameraCmdThread.cpp \
util/QCameraFlash.cpp \
util/QCameraPerf.cpp \
util/QCameraQueue.cpp \
util/QCameraDisplay.cpp \
util/QCameraCommon.cpp \
util/QCameraTrace.cpp \
util/camscope_packet_type.cpp \
util/QCameraPerfTranslator.cpp \
QCamera2Hal.cpp \
QCamera2Factory.cpp
#HAL 3.0 source
LOCAL_SRC_FILES += \
HAL3/QCamera3HWI.cpp \
HAL3/QCamera3Mem.cpp \
HAL3/QCamera3Stream.cpp \
HAL3/QCamera3Channel.cpp \
HAL3/QCamera3VendorTags.cpp \
HAL3/QCamera3PostProc.cpp \
HAL3/QCamera3CropRegionMapper.cpp \
HAL3/QCamera3StreamMem.cpp
ifeq (1,$(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) >= 31 ))" )))
LOCAL_CFLAGS := -Wall -Wextra -Werror -Wno-compound-token-split-by-macro
else
LOCAL_CFLAGS := -Wall -Wextra -Werror
endif
LOCAL_CFLAGS += -DFDLEAK_FLAG
LOCAL_CFLAGS += -DMEMLEAK_FLAG
#HAL 1.0 source
ifeq ($(TARGET_SUPPORT_HAL1),false)
LOCAL_CFLAGS += -DQCAMERA_HAL3_SUPPORT
else
LOCAL_CFLAGS += -DQCAMERA_HAL1_SUPPORT
LOCAL_SRC_FILES += \
HAL/QCamera2HWI.cpp \
HAL/QCameraMuxer.cpp \
HAL/QCameraMem.cpp \
HAL/QCameraStateMachine.cpp \
HAL/QCameraChannel.cpp \
HAL/QCameraStream.cpp \
HAL/QCameraPostProc.cpp \
HAL/QCamera2HWICallbacks.cpp \
HAL/QCameraParameters.cpp \
HAL/CameraParameters.cpp \
HAL/QCameraParametersIntf.cpp \
HAL/QCameraThermalAdapter.cpp \
util/QCameraFOVControl.cpp \
util/QCameraHALPP.cpp \
util/QCameraDualFOVPP.cpp \
util/QCameraExtZoomTranslator.cpp \
util/QCameraPprocManager.cpp \
util/QCameraBokeh.cpp \
util/QCameraClearSight.cpp
endif
# System header file path prefix
LOCAL_CFLAGS += -DSYSTEM_HEADER_PREFIX=sys
LOCAL_CFLAGS += -DHAS_MULTIMEDIA_HINTS -D_ANDROID
ifeq ($(ENABLE_MULTICAM_SUPPORT), true)
LOCAL_CFLAGS += -DUSE_HAL_3_5
else
ifeq (1,$(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) <= 23 ))" )))
LOCAL_CFLAGS += -DUSE_HAL_3_3
endif
endif
#use media extension
ifeq ($(TARGET_USES_MEDIA_EXTENSIONS), true)
LOCAL_CFLAGS += -DUSE_MEDIA_EXTENSIONS
endif
#USE_DISPLAY_SERVICE from Android O onwards
#to receive vsync event from display
ifeq ($(call is-platform-sdk-version-at-least,26),true)
USE_DISPLAY_SERVICE := true
LOCAL_CFLAGS += -DUSE_DISPLAY_SERVICE
LOCAL_CFLAGS += -std=c++14 -std=gnu++1z
else
LOCAL_CFLAGS += -std=c++14 -std=gnu++1z
endif
#Android P onwards we use vendor prefix
ifeq ($(call is-platform-sdk-version-at-least,28),true)
LOCAL_CFLAGS += -DUSE_VENDOR_PROP
endif
#HAL 1.0 Flags
LOCAL_CFLAGS += -DDEFAULT_DENOISE_MODE_ON -DHAL3 -DQCAMERA_REDEFINE_LOG
LOCAL_LDFLAGS += -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=socket -Wl,--wrap=pipe -Wl,--wrap=mmap -Wl,--wrap=__open_2
LOCAL_LDFLAGS += -Wl,--wrap=malloc -Wl,--wrap=free -Wl,--wrap=realloc -Wl,--wrap=calloc
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../mm-image-codec/qexif \
$(LOCAL_PATH)/../mm-image-codec/qomx_core \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/stack/common/leak \
$(LOCAL_PATH)/stack/mm-camera-interface/inc \
$(LOCAL_PATH)/util \
$(LOCAL_PATH)/HAL3 \
$(call project-path-for,qcom-media)/libstagefrighthw \
$(call project-path-for,qcom-media)/mm-core/inc \
$(TARGET_OUT_HEADERS)/mm-camera-lib/cp/prebuilt
ifneq (,$(filter $(TRINKET),$(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DTARGET_TRINKET
endif
ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),3.18 4.4 4.9))
ifneq ($(LIBION_HEADER_PATH_WRAPPER), )
include $(LIBION_HEADER_PATH_WRAPPER)
LOCAL_C_INCLUDES += $(LIBION_HEADER_PATHS)
else
LOCAL_C_INCLUDES += \
system/core/libion/kernel-headers \
system/core/libion/include
endif
endif
LOCAL_HEADER_LIBRARIES := camera_common_headers
LOCAL_HEADER_LIBRARIES += media_plugin_headers
LOCAL_HEADER_LIBRARIES += libandroid_sensor_headers
LOCAL_HEADER_LIBRARIES += libcutils_headers
LOCAL_HEADER_LIBRARIES += libsystem_headers
LOCAL_HEADER_LIBRARIES += libhardware_headers
LOCAL_HEADER_LIBRARIES += display_headers
#HAL 1.0 Include paths
LOCAL_C_INCLUDES += \
$(call project-path-for,qcom-camera)/QCamera2/HAL
ifeq ($(TARGET_COMPILE_WITH_MSM_KERNEL),true)
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include/media
LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
endif
ifeq ($(TARGET_TS_MAKEUP),true)
LOCAL_CFLAGS += -DTARGET_TS_MAKEUP
LOCAL_C_INCLUDES += $(LOCAL_PATH)/HAL/tsMakeuplib/include
endif
ifneq (,$(filter msm8974 msm8916 msm8226 msm8610 msm8916 apq8084 msm8084 msm8994 msm8992 msm8952 msm8937 msm8953 msm8996 sdm660 msm8998 apq8098_latv $(TRINKET), $(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DVENUS_PRESENT
endif
ifneq (,$(filter msm8996 sdm660 msm8998 apq8098_latv $(TRINKET),$(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DUBWC_PRESENT
endif
ifneq (,$(filter msm8996,$(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DTARGET_MSM8996
endif
LOCAL_CFLAGS += -DUSE_CAMERA_METABUFFER_UTILS
#LOCAL_STATIC_LIBRARIES := libqcamera2_util
LOCAL_C_INCLUDES += \
$(call project-path-for,qcom-display)/libqservice
LOCAL_SHARED_LIBRARIES := liblog libhardware libutils libcutils libdl libsync
LOCAL_SHARED_LIBRARIES += libmmcamera_interface libmmjpeg_interface libui libcamera_metadata
LOCAL_SHARED_LIBRARIES += libqdMetaData libqservice libbinder
LOCAL_SHARED_LIBRARIES += libbase libcutils libdl libhal_dbg
ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),3.18 4.4 4.9))
LOCAL_SHARED_LIBRARIES += libion
LOCAL_CFLAGS += -DVIDEO_EXPLICIT_UBWC
endif
ifeq ($(IS_QC_BOKEH_SUPPORTED),true)
LOCAL_SHARED_LIBRARIES += libdualcameraddm
LOCAL_CFLAGS += -DENABLE_QC_BOKEH
endif
ifeq ($(USE_DISPLAY_SERVICE),true)
LOCAL_SHARED_LIBRARIES += android.frameworks.displayservice@1.0 libhidltransport libhidlbase
ifneq ($(filter P% p% Q% q%,$(TARGET_PLATFORM_VERSION)),)
LOCAL_SHARED_LIBRARIES += libhidltransport
endif
else
LOCAL_SHARED_LIBRARIES += libgui
endif
ifeq ($(TARGET_TS_MAKEUP),true)
LOCAL_SHARED_LIBRARIES += libts_face_beautify_hal libts_detected_face_hal
endif
ifeq ($(TARGET_HAS_LOW_RAM), true)
LOCAL_CFLAGS += -DHAS_LOW_RAM
endif
ifneq (,$(filter $(TRINKET) msm8937_32go-userdebug, $(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DSUPPORT_ONLY_HAL3
endif
ifneq (,$(filter $(strip $(TARGET_KERNEL_VERSION)),4.14 4.19))
ifneq (,$(filter sdm660 msm8937 msm8953, $(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DSUPPORT_ONLY_HAL3
endif
endif
ifneq (,$(filter $(strip $(TARGET_KERNEL_VERSION)),4.14 4.19))
ifneq (,$(filter $(TRINKET) sdm660 msm8937 msm8953, $(TARGET_BOARD_PLATFORM)))
ifeq (,$(filter P% p% Q% q% ,$(TARGET_PLATFORM_VERSION)))
LOCAL_CFLAGS += -DSUPPORT_POWER_HINT_XML
endif
endif
endif
LOCAL_STATIC_LIBRARIES := android.hardware.camera.common@1.0-helper
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_MODULE := camera.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib
LOCAL_MODULE_TAGS := optional
LOCAL_32_BIT_ONLY := $(BOARD_QTI_CAMERA_32BIT_ONLY)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := camera_common_headers
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/stack/common
include $(BUILD_HEADER_LIBRARY)
include $(call first-makefiles-under,$(LOCAL_PATH))
endif
# Clear SDCLANG_FLAG_DEFS after use
SDCLANG_FLAG_DEFS :=

View file

@ -0,0 +1,537 @@
/*
**
** Copyright 2008, The Android Open Source Project
**
** 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.
*/
#define LOG_TAG "CameraParams"
#include <utils/Log.h>
#include <string.h>
#include <stdlib.h>
#include "CameraParameters.h"
#include <system/graphics.h>
namespace android {
// Parameter keys to communicate between camera application and driver.
const char CameraParameters::KEY_PREVIEW_SIZE[] = "preview-size";
const char CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES[] = "preview-size-values";
const char CameraParameters::KEY_PREVIEW_FORMAT[] = "preview-format";
const char CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS[] = "preview-format-values";
const char CameraParameters::KEY_PREVIEW_FRAME_RATE[] = "preview-frame-rate";
const char CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES[] = "preview-frame-rate-values";
const char CameraParameters::KEY_PREVIEW_FPS_RANGE[] = "preview-fps-range";
const char CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE[] = "preview-fps-range-values";
const char CameraParameters::KEY_PICTURE_SIZE[] = "picture-size";
const char CameraParameters::KEY_SUPPORTED_PICTURE_SIZES[] = "picture-size-values";
const char CameraParameters::KEY_PICTURE_FORMAT[] = "picture-format";
const char CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS[] = "picture-format-values";
const char CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH[] = "jpeg-thumbnail-width";
const char CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT[] = "jpeg-thumbnail-height";
const char CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[] = "jpeg-thumbnail-size-values";
const char CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY[] = "jpeg-thumbnail-quality";
const char CameraParameters::KEY_JPEG_QUALITY[] = "jpeg-quality";
const char CameraParameters::KEY_ROTATION[] = "rotation";
const char CameraParameters::KEY_GPS_LATITUDE[] = "gps-latitude";
const char CameraParameters::KEY_GPS_LONGITUDE[] = "gps-longitude";
const char CameraParameters::KEY_GPS_ALTITUDE[] = "gps-altitude";
const char CameraParameters::KEY_GPS_TIMESTAMP[] = "gps-timestamp";
const char CameraParameters::KEY_GPS_PROCESSING_METHOD[] = "gps-processing-method";
const char CameraParameters::KEY_WHITE_BALANCE[] = "whitebalance";
const char CameraParameters::KEY_SUPPORTED_WHITE_BALANCE[] = "whitebalance-values";
const char CameraParameters::KEY_EFFECT[] = "effect";
const char CameraParameters::KEY_SUPPORTED_EFFECTS[] = "effect-values";
const char CameraParameters::KEY_ANTIBANDING[] = "antibanding";
const char CameraParameters::KEY_SUPPORTED_ANTIBANDING[] = "antibanding-values";
const char CameraParameters::KEY_SCENE_MODE[] = "scene-mode";
const char CameraParameters::KEY_SUPPORTED_SCENE_MODES[] = "scene-mode-values";
const char CameraParameters::KEY_FLASH_MODE[] = "flash-mode";
const char CameraParameters::KEY_SUPPORTED_FLASH_MODES[] = "flash-mode-values";
const char CameraParameters::KEY_FOCUS_MODE[] = "focus-mode";
const char CameraParameters::KEY_SUPPORTED_FOCUS_MODES[] = "focus-mode-values";
const char CameraParameters::KEY_MAX_NUM_FOCUS_AREAS[] = "max-num-focus-areas";
const char CameraParameters::KEY_FOCUS_AREAS[] = "focus-areas";
const char CameraParameters::KEY_FOCAL_LENGTH[] = "focal-length";
const char CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE[] = "horizontal-view-angle";
const char CameraParameters::KEY_VERTICAL_VIEW_ANGLE[] = "vertical-view-angle";
const char CameraParameters::KEY_EXPOSURE_COMPENSATION[] = "exposure-compensation";
const char CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION[] = "max-exposure-compensation";
const char CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION[] = "min-exposure-compensation";
const char CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP[] = "exposure-compensation-step";
const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK[] = "auto-exposure-lock";
const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[] = "auto-exposure-lock-supported";
const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK[] = "auto-whitebalance-lock";
const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[] = "auto-whitebalance-lock-supported";
const char CameraParameters::KEY_MAX_NUM_METERING_AREAS[] = "max-num-metering-areas";
const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas";
const char CameraParameters::KEY_ZOOM[] = "zoom";
const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom";
const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios";
const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported";
const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported";
const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances";
const char CameraParameters::KEY_VIDEO_FRAME_FORMAT[] = "video-frame-format";
const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size";
const char CameraParameters::KEY_SUPPORTED_VIDEO_SIZES[] = "video-size-values";
const char CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = "preferred-preview-size-for-video";
const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW[] = "max-num-detected-faces-hw";
const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW[] = "max-num-detected-faces-sw";
const char CameraParameters::KEY_RECORDING_HINT[] = "recording-hint";
const char CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED[] = "video-snapshot-supported";
const char CameraParameters::KEY_VIDEO_STABILIZATION[] = "video-stabilization";
const char CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED[] = "video-stabilization-supported";
const char CameraParameters::KEY_LIGHTFX[] = "light-fx";
const char CameraParameters::TRUE[] = "true";
const char CameraParameters::FALSE[] = "false";
const char CameraParameters::FOCUS_DISTANCE_INFINITY[] = "Infinity";
// Values for white balance settings.
const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto";
const char CameraParameters::WHITE_BALANCE_INCANDESCENT[] = "incandescent";
const char CameraParameters::WHITE_BALANCE_FLUORESCENT[] = "fluorescent";
const char CameraParameters::WHITE_BALANCE_WARM_FLUORESCENT[] = "warm-fluorescent";
const char CameraParameters::WHITE_BALANCE_DAYLIGHT[] = "daylight";
const char CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT[] = "cloudy-daylight";
const char CameraParameters::WHITE_BALANCE_TWILIGHT[] = "twilight";
const char CameraParameters::WHITE_BALANCE_SHADE[] = "shade";
// Values for effect settings.
const char CameraParameters::EFFECT_NONE[] = "none";
const char CameraParameters::EFFECT_MONO[] = "mono";
const char CameraParameters::EFFECT_NEGATIVE[] = "negative";
const char CameraParameters::EFFECT_SOLARIZE[] = "solarize";
const char CameraParameters::EFFECT_SEPIA[] = "sepia";
const char CameraParameters::EFFECT_POSTERIZE[] = "posterize";
const char CameraParameters::EFFECT_WHITEBOARD[] = "whiteboard";
const char CameraParameters::EFFECT_BLACKBOARD[] = "blackboard";
const char CameraParameters::EFFECT_AQUA[] = "aqua";
// Values for antibanding settings.
const char CameraParameters::ANTIBANDING_AUTO[] = "auto";
const char CameraParameters::ANTIBANDING_50HZ[] = "50hz";
const char CameraParameters::ANTIBANDING_60HZ[] = "60hz";
const char CameraParameters::ANTIBANDING_OFF[] = "off";
// Values for flash mode settings.
const char CameraParameters::FLASH_MODE_OFF[] = "off";
const char CameraParameters::FLASH_MODE_AUTO[] = "auto";
const char CameraParameters::FLASH_MODE_ON[] = "on";
const char CameraParameters::FLASH_MODE_RED_EYE[] = "red-eye";
const char CameraParameters::FLASH_MODE_TORCH[] = "torch";
// Values for scene mode settings.
const char CameraParameters::SCENE_MODE_AUTO[] = "auto";
const char CameraParameters::SCENE_MODE_ACTION[] = "action";
const char CameraParameters::SCENE_MODE_PORTRAIT[] = "portrait";
const char CameraParameters::SCENE_MODE_LANDSCAPE[] = "landscape";
const char CameraParameters::SCENE_MODE_NIGHT[] = "night";
const char CameraParameters::SCENE_MODE_NIGHT_PORTRAIT[] = "night-portrait";
const char CameraParameters::SCENE_MODE_THEATRE[] = "theatre";
const char CameraParameters::SCENE_MODE_BEACH[] = "beach";
const char CameraParameters::SCENE_MODE_SNOW[] = "snow";
const char CameraParameters::SCENE_MODE_SUNSET[] = "sunset";
const char CameraParameters::SCENE_MODE_STEADYPHOTO[] = "steadyphoto";
const char CameraParameters::SCENE_MODE_FIREWORKS[] = "fireworks";
const char CameraParameters::SCENE_MODE_SPORTS[] = "sports";
const char CameraParameters::SCENE_MODE_PARTY[] = "party";
const char CameraParameters::SCENE_MODE_CANDLELIGHT[] = "candlelight";
const char CameraParameters::SCENE_MODE_BARCODE[] = "barcode";
const char CameraParameters::SCENE_MODE_HDR[] = "hdr";
const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp";
const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp";
const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv";
const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p";
const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565";
const char CameraParameters::PIXEL_FORMAT_RGBA8888[] = "rgba8888";
const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg";
const char CameraParameters::PIXEL_FORMAT_BAYER_RGGB[] = "bayer-rggb";
const char CameraParameters::PIXEL_FORMAT_ANDROID_OPAQUE[] = "android-opaque";
// Values for focus mode settings.
const char CameraParameters::FOCUS_MODE_AUTO[] = "auto";
const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity";
const char CameraParameters::FOCUS_MODE_MACRO[] = "macro";
const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed";
const char CameraParameters::FOCUS_MODE_EDOF[] = "edof";
const char CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO[] = "continuous-video";
const char CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE[] = "continuous-picture";
// Values for light fx settings
const char CameraParameters::LIGHTFX_LOWLIGHT[] = "low-light";
const char CameraParameters::LIGHTFX_HDR[] = "high-dynamic-range";
CameraParameters::CameraParameters()
: mMap()
{
}
CameraParameters::~CameraParameters()
{
}
String8 CameraParameters::flatten() const
{
String8 flattened("");
size_t size = mMap.size();
for (size_t i = 0; i < size; i++) {
String8 k, v;
k = mMap.keyAt(i);
v = mMap.valueAt(i);
flattened += k;
flattened += "=";
flattened += v;
if (i != size-1)
flattened += ";";
}
return flattened;
}
void CameraParameters::unflatten(const String8 &params)
{
const char *a = params.string();
const char *b;
mMap.clear();
for (;;) {
// Find the bounds of the key name.
b = strchr(a, '=');
if (b == 0)
break;
// Create the key string.
String8 k(a, (size_t)(b-a));
// Find the value.
a = b+1;
b = strchr(a, ';');
if (b == 0) {
// If there's no semicolon, this is the last item.
String8 v(a);
mMap.add(k, v);
break;
}
String8 v(a, (size_t)(b-a));
mMap.add(k, v);
a = b+1;
}
}
void CameraParameters::set(const char *key, const char *value)
{
// XXX i think i can do this with strspn()
if (strchr(key, '=') || strchr(key, ';')) {
//XXX ALOGE("Key \"%s\"contains invalid character (= or ;)", key);
return;
}
if (strchr(value, '=') || strchr(value, ';')) {
//XXX ALOGE("Value \"%s\"contains invalid character (= or ;)", value);
return;
}
mMap.replaceValueFor(String8(key), String8(value));
}
void CameraParameters::set(const char *key, int value)
{
char str[16];
snprintf(str, sizeof(str), "%d", value);
set(key, str);
}
void CameraParameters::setFloat(const char *key, float value)
{
char str[16]; // 14 should be enough. We overestimate to be safe.
snprintf(str, sizeof(str), "%g", value);
set(key, str);
}
const char *CameraParameters::get(const char *key) const
{
String8 v = mMap.valueFor(String8(key));
if (v.length() == 0)
return 0;
return v.string();
}
int CameraParameters::getInt(const char *key) const
{
const char *v = get(key);
if (v == 0)
return -1;
return strtol(v, 0, 0);
}
float CameraParameters::getFloat(const char *key) const
{
const char *v = get(key);
if (v == 0) return -1;
return strtof(v, 0);
}
void CameraParameters::remove(const char *key)
{
mMap.removeItem(String8(key));
}
// Parse string like "640x480" or "10000,20000"
static int parse_pair(const char *str, int *first, int *second, char delim,
char **endptr = NULL)
{
// Find the first integer.
char *end;
int w = (int)strtol(str, &end, 10);
// If a delimeter does not immediately follow, give up.
if (*end != delim) {
ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
return -1;
}
// Find the second integer, immediately after the delimeter.
int h = (int)strtol(end+1, &end, 10);
*first = w;
*second = h;
if (endptr) {
*endptr = end;
}
return 0;
}
static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
{
if (sizesStr == 0) {
return;
}
char *sizeStartPtr = (char *)sizesStr;
while (true) {
int width, height;
int success = parse_pair(sizeStartPtr, &width, &height, 'x',
&sizeStartPtr);
if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
return;
}
sizes.push(Size(width, height));
if (*sizeStartPtr == '\0') {
return;
}
sizeStartPtr++;
}
}
void CameraParameters::setPreviewSize(int width, int height)
{
char str[32];
snprintf(str, sizeof(str), "%dx%d", width, height);
set(KEY_PREVIEW_SIZE, str);
}
void CameraParameters::getPreviewSize(int *width, int *height) const
{
*width = *height = -1;
// Get the current string, if it doesn't exist, leave the -1x-1
const char *p = get(KEY_PREVIEW_SIZE);
if (p == 0) return;
parse_pair(p, width, height, 'x');
}
void CameraParameters::getPreferredPreviewSizeForVideo(int *width, int *height) const
{
*width = *height = -1;
const char *p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
if (p == 0) return;
parse_pair(p, width, height, 'x');
}
void CameraParameters::getSupportedPreviewSizes(Vector<Size> &sizes) const
{
const char *previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES);
parseSizesList(previewSizesStr, sizes);
}
void CameraParameters::setVideoSize(int width, int height)
{
char str[32];
snprintf(str, sizeof(str), "%dx%d", width, height);
set(KEY_VIDEO_SIZE, str);
}
void CameraParameters::getVideoSize(int *width, int *height) const
{
*width = *height = -1;
const char *p = get(KEY_VIDEO_SIZE);
if (p == 0) return;
parse_pair(p, width, height, 'x');
}
void CameraParameters::getSupportedVideoSizes(Vector<Size> &sizes) const
{
const char *videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES);
parseSizesList(videoSizesStr, sizes);
}
void CameraParameters::setPreviewFrameRate(int fps)
{
set(KEY_PREVIEW_FRAME_RATE, fps);
}
int CameraParameters::getPreviewFrameRate() const
{
return getInt(KEY_PREVIEW_FRAME_RATE);
}
void CameraParameters::getPreviewFpsRange(int *min_fps, int *max_fps) const
{
*min_fps = *max_fps = -1;
const char *p = get(KEY_PREVIEW_FPS_RANGE);
if (p == 0) return;
parse_pair(p, min_fps, max_fps, ',');
}
void CameraParameters::setPreviewFormat(const char *format)
{
set(KEY_PREVIEW_FORMAT, format);
}
const char *CameraParameters::getPreviewFormat() const
{
return get(KEY_PREVIEW_FORMAT);
}
void CameraParameters::setPictureSize(int width, int height)
{
char str[32];
snprintf(str, sizeof(str), "%dx%d", width, height);
set(KEY_PICTURE_SIZE, str);
}
void CameraParameters::getPictureSize(int *width, int *height) const
{
*width = *height = -1;
// Get the current string, if it doesn't exist, leave the -1x-1
const char *p = get(KEY_PICTURE_SIZE);
if (p == 0) return;
parse_pair(p, width, height, 'x');
}
void CameraParameters::getSupportedPictureSizes(Vector<Size> &sizes) const
{
const char *pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES);
parseSizesList(pictureSizesStr, sizes);
}
void CameraParameters::setPictureFormat(const char *format)
{
set(KEY_PICTURE_FORMAT, format);
}
const char *CameraParameters::getPictureFormat() const
{
return get(KEY_PICTURE_FORMAT);
}
void CameraParameters::dump() const
{
ALOGD("dump: mMap.size = %zu", mMap.size());
for (size_t i = 0; i < mMap.size(); i++) {
String8 k, v;
k = mMap.keyAt(i);
v = mMap.valueAt(i);
ALOGD("%s: %s\n", k.string(), v.string());
}
}
status_t CameraParameters::dump(int fd, const Vector<String16>& /*args*/) const
{
const size_t SIZE = 256;
char buffer[SIZE];
String8 result;
snprintf(buffer, 255, "CameraParameters::dump: mMap.size = %zu\n", mMap.size());
result.append(buffer);
for (size_t i = 0; i < mMap.size(); i++) {
String8 k, v;
k = mMap.keyAt(i);
v = mMap.valueAt(i);
snprintf(buffer, 255, "\t%s: %s\n", k.string(), v.string());
result.append(buffer);
}
write(fd, result.string(), result.size());
return NO_ERROR;
}
void CameraParameters::getSupportedPreviewFormats(Vector<int>& formats) const {
const char* supportedPreviewFormats =
get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS);
if (supportedPreviewFormats == NULL) {
ALOGW("%s: No supported preview formats.", __FUNCTION__);
return;
}
String8 fmtStr(supportedPreviewFormats);
char* prevFmts = fmtStr.lockBuffer(fmtStr.size());
char* savePtr;
char* fmt = strtok_r(prevFmts, ",", &savePtr);
while (fmt) {
int actual = previewFormatToEnum(fmt);
if (actual != -1) {
formats.add(actual);
}
fmt = strtok_r(NULL, ",", &savePtr);
}
fmtStr.unlockBuffer(fmtStr.size());
}
int CameraParameters::previewFormatToEnum(const char* format) {
return
!format ?
HAL_PIXEL_FORMAT_YCrCb_420_SP :
!strcmp(format, PIXEL_FORMAT_YUV422SP) ?
HAL_PIXEL_FORMAT_YCbCr_422_SP : // NV16
!strcmp(format, PIXEL_FORMAT_YUV420SP) ?
HAL_PIXEL_FORMAT_YCrCb_420_SP : // NV21
!strcmp(format, PIXEL_FORMAT_YUV422I) ?
HAL_PIXEL_FORMAT_YCbCr_422_I : // YUY2
!strcmp(format, PIXEL_FORMAT_YUV420P) ?
HAL_PIXEL_FORMAT_YV12 : // YV12
!strcmp(format, PIXEL_FORMAT_RGB565) ?
HAL_PIXEL_FORMAT_RGB_565 : // RGB565
!strcmp(format, PIXEL_FORMAT_RGBA8888) ?
HAL_PIXEL_FORMAT_RGBA_8888 : // RGB8888
!strcmp(format, PIXEL_FORMAT_BAYER_RGGB) ?
HAL_PIXEL_FORMAT_RAW16 : // Raw sensor data
-1;
}
bool CameraParameters::isEmpty() const {
return mMap.isEmpty();
}
}; // namespace android

View file

@ -0,0 +1,700 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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 ANDROID_HARDWARE_CAMERA_PARAMETERS_H
#define ANDROID_HARDWARE_CAMERA_PARAMETERS_H
#include <utils/KeyedVector.h>
#include <utils/String8.h>
#include <unistd.h>
namespace android {
struct Size {
int width;
int height;
Size() {
width = 0;
height = 0;
}
Size(int w, int h) {
width = w;
height = h;
}
};
class CameraParameters
{
public:
CameraParameters();
CameraParameters(const String8 &params) { unflatten(params); }
~CameraParameters();
String8 flatten() const;
void unflatten(const String8 &params);
void set(const char *key, const char *value);
void set(const char *key, int value);
void setFloat(const char *key, float value);
const char *get(const char *key) const;
int getInt(const char *key) const;
float getFloat(const char *key) const;
void remove(const char *key);
void setPreviewSize(int width, int height);
void getPreviewSize(int *width, int *height) const;
void getSupportedPreviewSizes(Vector<Size> &sizes) const;
// Set the dimensions in pixels to the given width and height
// for video frames. The given width and height must be one
// of the supported dimensions returned from
// getSupportedVideoSizes(). Must not be called if
// getSupportedVideoSizes() returns an empty Vector of Size.
void setVideoSize(int width, int height);
// Retrieve the current dimensions (width and height)
// in pixels for video frames, which must be one of the
// supported dimensions returned from getSupportedVideoSizes().
// Must not be called if getSupportedVideoSizes() returns an
// empty Vector of Size.
void getVideoSize(int *width, int *height) const;
// Retrieve a Vector of supported dimensions (width and height)
// in pixels for video frames. If sizes returned from the method
// is empty, the camera does not support calls to setVideoSize()
// or getVideoSize(). In adddition, it also indicates that
// the camera only has a single output, and does not have
// separate output for video frames and preview frame.
void getSupportedVideoSizes(Vector<Size> &sizes) const;
// Retrieve the preferred preview size (width and height) in pixels
// for video recording. The given width and height must be one of
// supported preview sizes returned from getSupportedPreviewSizes().
// Must not be called if getSupportedVideoSizes() returns an empty
// Vector of Size. If getSupportedVideoSizes() returns an empty
// Vector of Size, the width and height returned from this method
// is invalid, and is "-1x-1".
void getPreferredPreviewSizeForVideo(int *width, int *height) const;
void setPreviewFrameRate(int fps);
int getPreviewFrameRate() const;
void getPreviewFpsRange(int *min_fps, int *max_fps) const;
void setPreviewFormat(const char *format);
const char *getPreviewFormat() const;
void setPictureSize(int width, int height);
void getPictureSize(int *width, int *height) const;
void getSupportedPictureSizes(Vector<Size> &sizes) const;
void setPictureFormat(const char *format);
const char *getPictureFormat() const;
void dump() const;
status_t dump(int fd, const Vector<String16>& args) const;
/**
* Returns a Vector containing the supported preview formats
* as enums given in graphics.h.
*/
void getSupportedPreviewFormats(Vector<int>& formats) const;
// Returns true if no keys are present
bool isEmpty() const;
// Parameter keys to communicate between camera application and driver.
// The access (read/write, read only, or write only) is viewed from the
// perspective of applications, not driver.
// Preview frame size in pixels (width x height).
// Example value: "480x320". Read/Write.
static const char KEY_PREVIEW_SIZE[];
// Supported preview frame sizes in pixels.
// Example value: "800x600,480x320". Read only.
static const char KEY_SUPPORTED_PREVIEW_SIZES[];
// The current minimum and maximum preview fps. This controls the rate of
// preview frames received (CAMERA_MSG_PREVIEW_FRAME). The minimum and
// maximum fps must be one of the elements from
// KEY_SUPPORTED_PREVIEW_FPS_RANGE parameter.
// Example value: "10500,26623"
static const char KEY_PREVIEW_FPS_RANGE[];
// The supported preview fps (frame-per-second) ranges. Each range contains
// a minimum fps and maximum fps. If minimum fps equals to maximum fps, the
// camera outputs frames in fixed frame rate. If not, the camera outputs
// frames in auto frame rate. The actual frame rate fluctuates between the
// minimum and the maximum. The list has at least one element. The list is
// sorted from small to large (first by maximum fps and then minimum fps).
// Example value: "(10500,26623),(15000,26623),(30000,30000)"
static const char KEY_SUPPORTED_PREVIEW_FPS_RANGE[];
// The image format for preview frames. See CAMERA_MSG_PREVIEW_FRAME in
// frameworks/av/include/camera/Camera.h. The default is
// PIXEL_FORMAT_YUV420SP. Example value: "yuv420sp" or PIXEL_FORMAT_XXX
// constants. Read/write.
static const char KEY_PREVIEW_FORMAT[];
// Supported image formats for preview frames.
// Example value: "yuv420sp,yuv422i-yuyv". Read only.
static const char KEY_SUPPORTED_PREVIEW_FORMATS[];
// Number of preview frames per second. This is the target frame rate. The
// actual frame rate depends on the driver.
// Example value: "15". Read/write.
static const char KEY_PREVIEW_FRAME_RATE[];
// Supported number of preview frames per second.
// Example value: "24,15,10". Read.
static const char KEY_SUPPORTED_PREVIEW_FRAME_RATES[];
// The dimensions for captured pictures in pixels (width x height).
// Example value: "1024x768". Read/write.
static const char KEY_PICTURE_SIZE[];
// Supported dimensions for captured pictures in pixels.
// Example value: "2048x1536,1024x768". Read only.
static const char KEY_SUPPORTED_PICTURE_SIZES[];
// The image format for captured pictures. See CAMERA_MSG_COMPRESSED_IMAGE
// in frameworks/base/include/camera/Camera.h.
// Example value: "jpeg" or PIXEL_FORMAT_XXX constants. Read/write.
static const char KEY_PICTURE_FORMAT[];
// Supported image formats for captured pictures.
// Example value: "jpeg,rgb565". Read only.
static const char KEY_SUPPORTED_PICTURE_FORMATS[];
// The width (in pixels) of EXIF thumbnail in Jpeg picture.
// Example value: "512". Read/write.
static const char KEY_JPEG_THUMBNAIL_WIDTH[];
// The height (in pixels) of EXIF thumbnail in Jpeg picture.
// Example value: "384". Read/write.
static const char KEY_JPEG_THUMBNAIL_HEIGHT[];
// Supported EXIF thumbnail sizes (width x height). 0x0 means not thumbnail
// in EXIF.
// Example value: "512x384,320x240,0x0". Read only.
static const char KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[];
// The quality of the EXIF thumbnail in Jpeg picture. The range is 1 to 100,
// with 100 being the best.
// Example value: "90". Read/write.
static const char KEY_JPEG_THUMBNAIL_QUALITY[];
// Jpeg quality of captured picture. The range is 1 to 100, with 100 being
// the best.
// Example value: "90". Read/write.
static const char KEY_JPEG_QUALITY[];
// The rotation angle in degrees relative to the orientation of the camera.
// This affects the pictures returned from CAMERA_MSG_COMPRESSED_IMAGE. The
// camera driver may set orientation in the EXIF header without rotating the
// picture. Or the driver may rotate the picture and the EXIF thumbnail. If
// the Jpeg picture is rotated, the orientation in the EXIF header will be
// missing or 1 (row #0 is top and column #0 is left side).
//
// Note that the JPEG pictures of front-facing cameras are not mirrored
// as in preview display.
//
// For example, suppose the natural orientation of the device is portrait.
// The device is rotated 270 degrees clockwise, so the device orientation is
// 270. Suppose a back-facing camera sensor is mounted in landscape and the
// top side of the camera sensor is aligned with the right edge of the
// display in natural orientation. So the camera orientation is 90. The
// rotation should be set to 0 (270 + 90).
//
// Example value: "0" or "90" or "180" or "270". Write only.
static const char KEY_ROTATION[];
// GPS latitude coordinate. GPSLatitude and GPSLatitudeRef will be stored in
// JPEG EXIF header.
// Example value: "25.032146" or "-33.462809". Write only.
static const char KEY_GPS_LATITUDE[];
// GPS longitude coordinate. GPSLongitude and GPSLongitudeRef will be stored
// in JPEG EXIF header.
// Example value: "121.564448" or "-70.660286". Write only.
static const char KEY_GPS_LONGITUDE[];
// GPS altitude. GPSAltitude and GPSAltitudeRef will be stored in JPEG EXIF
// header.
// Example value: "21.0" or "-5". Write only.
static const char KEY_GPS_ALTITUDE[];
// GPS timestamp (UTC in seconds since January 1, 1970). This should be
// stored in JPEG EXIF header.
// Example value: "1251192757". Write only.
static const char KEY_GPS_TIMESTAMP[];
// GPS Processing Method
// Example value: "GPS" or "NETWORK". Write only.
static const char KEY_GPS_PROCESSING_METHOD[];
// Current white balance setting.
// Example value: "auto" or WHITE_BALANCE_XXX constants. Read/write.
static const char KEY_WHITE_BALANCE[];
// Supported white balance settings.
// Example value: "auto,incandescent,daylight". Read only.
static const char KEY_SUPPORTED_WHITE_BALANCE[];
// Current color effect setting.
// Example value: "none" or EFFECT_XXX constants. Read/write.
static const char KEY_EFFECT[];
// Supported color effect settings.
// Example value: "none,mono,sepia". Read only.
static const char KEY_SUPPORTED_EFFECTS[];
// Current antibanding setting.
// Example value: "auto" or ANTIBANDING_XXX constants. Read/write.
static const char KEY_ANTIBANDING[];
// Supported antibanding settings.
// Example value: "auto,50hz,60hz,off". Read only.
static const char KEY_SUPPORTED_ANTIBANDING[];
// Current scene mode.
// Example value: "auto" or SCENE_MODE_XXX constants. Read/write.
static const char KEY_SCENE_MODE[];
// Supported scene mode settings.
// Example value: "auto,night,fireworks". Read only.
static const char KEY_SUPPORTED_SCENE_MODES[];
// Current flash mode.
// Example value: "auto" or FLASH_MODE_XXX constants. Read/write.
static const char KEY_FLASH_MODE[];
// Supported flash modes.
// Example value: "auto,on,off". Read only.
static const char KEY_SUPPORTED_FLASH_MODES[];
// Current focus mode. This will not be empty. Applications should call
// CameraHardwareInterface.autoFocus to start the focus if focus mode is
// FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
// Example value: "auto" or FOCUS_MODE_XXX constants. Read/write.
static const char KEY_FOCUS_MODE[];
// Supported focus modes.
// Example value: "auto,macro,fixed". Read only.
static const char KEY_SUPPORTED_FOCUS_MODES[];
// The maximum number of focus areas supported. This is the maximum length
// of KEY_FOCUS_AREAS.
// Example value: "0" or "2". Read only.
static const char KEY_MAX_NUM_FOCUS_AREAS[];
// Current focus areas.
//
// Before accessing this parameter, apps should check
// KEY_MAX_NUM_FOCUS_AREAS first to know the maximum number of focus areas
// first. If the value is 0, focus area is not supported.
//
// Each focus area is a five-element int array. The first four elements are
// the rectangle of the area (left, top, right, bottom). The direction is
// relative to the sensor orientation, that is, what the sensor sees. The
// direction is not affected by the rotation or mirroring of
// CAMERA_CMD_SET_DISPLAY_ORIENTATION. Coordinates range from -1000 to 1000.
// (-1000,-1000) is the upper left point. (1000, 1000) is the lower right
// point. The width and height of focus areas cannot be 0 or negative.
//
// The fifth element is the weight. Values for weight must range from 1 to
// 1000. The weight should be interpreted as a per-pixel weight - all
// pixels in the area have the specified weight. This means a small area
// with the same weight as a larger area will have less influence on the
// focusing than the larger area. Focus areas can partially overlap and the
// driver will add the weights in the overlap region.
//
// A special case of single focus area (0,0,0,0,0) means driver to decide
// the focus area. For example, the driver may use more signals to decide
// focus areas and change them dynamically. Apps can set (0,0,0,0,0) if they
// want the driver to decide focus areas.
//
// Focus areas are relative to the current field of view (KEY_ZOOM). No
// matter what the zoom level is, (-1000,-1000) represents the top of the
// currently visible camera frame. The focus area cannot be set to be
// outside the current field of view, even when using zoom.
//
// Focus area only has effect if the current focus mode is FOCUS_MODE_AUTO,
// FOCUS_MODE_MACRO, FOCUS_MODE_CONTINUOUS_VIDEO, or
// FOCUS_MODE_CONTINUOUS_PICTURE.
// Example value: "(-10,-10,0,0,300),(0,0,10,10,700)". Read/write.
static const char KEY_FOCUS_AREAS[];
// Focal length in millimeter.
// Example value: "4.31". Read only.
static const char KEY_FOCAL_LENGTH[];
// Horizontal angle of view in degrees.
// Example value: "54.8". Read only.
static const char KEY_HORIZONTAL_VIEW_ANGLE[];
// Vertical angle of view in degrees.
// Example value: "42.5". Read only.
static const char KEY_VERTICAL_VIEW_ANGLE[];
// Exposure compensation index. 0 means exposure is not adjusted.
// Example value: "-5" or "5". Read/write.
static const char KEY_EXPOSURE_COMPENSATION[];
// The maximum exposure compensation index (>=0).
// Example value: "6". Read only.
static const char KEY_MAX_EXPOSURE_COMPENSATION[];
// The minimum exposure compensation index (<=0).
// Example value: "-6". Read only.
static const char KEY_MIN_EXPOSURE_COMPENSATION[];
// The exposure compensation step. Exposure compensation index multiply by
// step eqals to EV. Ex: if exposure compensation index is -6 and step is
// 0.3333, EV is -2.
// Example value: "0.333333333" or "0.5". Read only.
static const char KEY_EXPOSURE_COMPENSATION_STEP[];
// The state of the auto-exposure lock. "true" means that
// auto-exposure is locked to its current value and will not
// change. "false" means the auto-exposure routine is free to
// change exposure values. If auto-exposure is already locked,
// setting this to true again has no effect (the driver will not
// recalculate exposure values). Changing exposure compensation
// settings will still affect the exposure settings while
// auto-exposure is locked. Stopping preview or taking a still
// image will not change the lock. In conjunction with
// exposure compensation, this allows for capturing multi-exposure
// brackets with known relative exposure values. Locking
// auto-exposure after open but before the first call to
// startPreview may result in severely over- or under-exposed
// images. The driver will not change the AE lock after
// auto-focus completes.
static const char KEY_AUTO_EXPOSURE_LOCK[];
// Whether locking the auto-exposure is supported. "true" means it is, and
// "false" or this key not existing means it is not supported.
static const char KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[];
// The state of the auto-white balance lock. "true" means that
// auto-white balance is locked to its current value and will not
// change. "false" means the auto-white balance routine is free to
// change white balance values. If auto-white balance is already
// locked, setting this to true again has no effect (the driver
// will not recalculate white balance values). Stopping preview or
// taking a still image will not change the lock. In conjunction
// with exposure compensation, this allows for capturing
// multi-exposure brackets with fixed white balance. Locking
// auto-white balance after open but before the first call to
// startPreview may result in severely incorrect color. The
// driver will not change the AWB lock after auto-focus
// completes.
static const char KEY_AUTO_WHITEBALANCE_LOCK[];
// Whether locking the auto-white balance is supported. "true"
// means it is, and "false" or this key not existing means it is
// not supported.
static const char KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[];
// The maximum number of metering areas supported. This is the maximum
// length of KEY_METERING_AREAS.
// Example value: "0" or "2". Read only.
static const char KEY_MAX_NUM_METERING_AREAS[];
// Current metering areas. Camera driver uses these areas to decide
// exposure.
//
// Before accessing this parameter, apps should check
// KEY_MAX_NUM_METERING_AREAS first to know the maximum number of metering
// areas first. If the value is 0, metering area is not supported.
//
// Each metering area is a rectangle with specified weight. The direction is
// relative to the sensor orientation, that is, what the sensor sees. The
// direction is not affected by the rotation or mirroring of
// CAMERA_CMD_SET_DISPLAY_ORIENTATION. Coordinates of the rectangle range
// from -1000 to 1000. (-1000, -1000) is the upper left point. (1000, 1000)
// is the lower right point. The width and height of metering areas cannot
// be 0 or negative.
//
// The fifth element is the weight. Values for weight must range from 1 to
// 1000. The weight should be interpreted as a per-pixel weight - all
// pixels in the area have the specified weight. This means a small area
// with the same weight as a larger area will have less influence on the
// metering than the larger area. Metering areas can partially overlap and
// the driver will add the weights in the overlap region.
//
// A special case of all-zero single metering area means driver to decide
// the metering area. For example, the driver may use more signals to decide
// metering areas and change them dynamically. Apps can set all-zero if they
// want the driver to decide metering areas.
//
// Metering areas are relative to the current field of view (KEY_ZOOM).
// No matter what the zoom level is, (-1000,-1000) represents the top of the
// currently visible camera frame. The metering area cannot be set to be
// outside the current field of view, even when using zoom.
//
// No matter what metering areas are, the final exposure are compensated
// by KEY_EXPOSURE_COMPENSATION.
// Example value: "(-10,-10,0,0,300),(0,0,10,10,700)". Read/write.
static const char KEY_METERING_AREAS[];
// Current zoom value.
// Example value: "0" or "6". Read/write.
static const char KEY_ZOOM[];
// Maximum zoom value.
// Example value: "6". Read only.
static const char KEY_MAX_ZOOM[];
// The zoom ratios of all zoom values. The zoom ratio is in 1/100
// increments. Ex: a zoom of 3.2x is returned as 320. The number of list
// elements is KEY_MAX_ZOOM + 1. The first element is always 100. The last
// element is the zoom ratio of zoom value KEY_MAX_ZOOM.
// Example value: "100,150,200,250,300,350,400". Read only.
static const char KEY_ZOOM_RATIOS[];
// Whether zoom is supported. Zoom is supported if the value is "true". Zoom
// is not supported if the value is not "true" or the key does not exist.
// Example value: "true". Read only.
static const char KEY_ZOOM_SUPPORTED[];
// Whether if smooth zoom is supported. Smooth zoom is supported if the
// value is "true". It is not supported if the value is not "true" or the
// key does not exist.
// See CAMERA_CMD_START_SMOOTH_ZOOM, CAMERA_CMD_STOP_SMOOTH_ZOOM, and
// CAMERA_MSG_ZOOM in frameworks/base/include/camera/Camera.h.
// Example value: "true". Read only.
static const char KEY_SMOOTH_ZOOM_SUPPORTED[];
// The distances (in meters) from the camera to where an object appears to
// be in focus. The object is sharpest at the optimal focus distance. The
// depth of field is the far focus distance minus near focus distance.
//
// Focus distances may change after starting auto focus, canceling auto
// focus, or starting the preview. Applications can read this anytime to get
// the latest focus distances. If the focus mode is FOCUS_MODE_CONTINUOUS,
// focus distances may change from time to time.
//
// This is intended to estimate the distance between the camera and the
// subject. After autofocus, the subject distance may be within near and far
// focus distance. However, the precision depends on the camera hardware,
// autofocus algorithm, the focus area, and the scene. The error can be
// large and it should be only used as a reference.
//
// Far focus distance > optimal focus distance > near focus distance. If
// the far focus distance is infinity, the value should be "Infinity" (case
// sensitive). The format is three float values separated by commas. The
// first is near focus distance. The second is optimal focus distance. The
// third is far focus distance.
// Example value: "0.95,1.9,Infinity" or "0.049,0.05,0.051". Read only.
static const char KEY_FOCUS_DISTANCES[];
// The current dimensions in pixels (width x height) for video frames.
// The width and height must be one of the supported sizes retrieved
// via KEY_SUPPORTED_VIDEO_SIZES.
// Example value: "1280x720". Read/write.
static const char KEY_VIDEO_SIZE[];
// A list of the supported dimensions in pixels (width x height)
// for video frames. See CAMERA_MSG_VIDEO_FRAME for details in
// frameworks/base/include/camera/Camera.h.
// Example: "176x144,1280x720". Read only.
static const char KEY_SUPPORTED_VIDEO_SIZES[];
// The maximum number of detected faces supported by hardware face
// detection. If the value is 0, hardware face detection is not supported.
// Example: "5". Read only
static const char KEY_MAX_NUM_DETECTED_FACES_HW[];
// The maximum number of detected faces supported by software face
// detection. If the value is 0, software face detection is not supported.
// Example: "5". Read only
static const char KEY_MAX_NUM_DETECTED_FACES_SW[];
// Preferred preview frame size in pixels for video recording.
// The width and height must be one of the supported sizes retrieved
// via KEY_SUPPORTED_PREVIEW_SIZES. This key can be used only when
// getSupportedVideoSizes() does not return an empty Vector of Size.
// Camcorder applications are recommended to set the preview size
// to a value that is not larger than the preferred preview size.
// In other words, the product of the width and height of the
// preview size should not be larger than that of the preferred
// preview size. In addition, we recommend to choos a preview size
// that has the same aspect ratio as the resolution of video to be
// recorded.
// Example value: "800x600". Read only.
static const char KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[];
// The image format for video frames. See CAMERA_MSG_VIDEO_FRAME in
// frameworks/base/include/camera/Camera.h.
// Example value: "yuv420sp" or PIXEL_FORMAT_XXX constants. Read only.
static const char KEY_VIDEO_FRAME_FORMAT[];
// Sets the hint of the recording mode. If this is true, MediaRecorder.start
// may be faster or has less glitches. This should be called before starting
// the preview for the best result. But it is allowed to change the hint
// while the preview is active. The default value is false.
//
// The apps can still call Camera.takePicture when the hint is true. The
// apps can call MediaRecorder.start when the hint is false. But the
// performance may be worse.
// Example value: "true" or "false". Read/write.
static const char KEY_RECORDING_HINT[];
// Returns true if video snapshot is supported. That is, applications
// can call Camera.takePicture during recording. Applications do not need to
// call Camera.startPreview after taking a picture. The preview will be
// still active. Other than that, taking a picture during recording is
// identical to taking a picture normally. All settings and methods related
// to takePicture work identically. Ex: KEY_PICTURE_SIZE,
// KEY_SUPPORTED_PICTURE_SIZES, KEY_JPEG_QUALITY, KEY_ROTATION, and etc.
// The picture will have an EXIF header. FLASH_MODE_AUTO and FLASH_MODE_ON
// also still work, but the video will record the flash.
//
// Applications can set shutter callback as null to avoid the shutter
// sound. It is also recommended to set raw picture and post view callbacks
// to null to avoid the interrupt of preview display.
//
// Field-of-view of the recorded video may be different from that of the
// captured pictures.
// Example value: "true" or "false". Read only.
static const char KEY_VIDEO_SNAPSHOT_SUPPORTED[];
// The state of the video stabilization. If set to true, both the
// preview stream and the recorded video stream are stabilized by
// the camera. Only valid to set if KEY_VIDEO_STABILIZATION_SUPPORTED is
// set to true.
//
// The value of this key can be changed any time the camera is
// open. If preview or recording is active, it is acceptable for
// there to be a slight video glitch when video stabilization is
// toggled on and off.
//
// This only stabilizes video streams (between-frames stabilization), and
// has no effect on still image capture.
static const char KEY_VIDEO_STABILIZATION[];
// Returns true if video stabilization is supported. That is, applications
// can set KEY_VIDEO_STABILIZATION to true and have a stabilized preview
// stream and record stabilized videos.
static const char KEY_VIDEO_STABILIZATION_SUPPORTED[];
// Supported modes for special effects with light.
// Example values: "lowlight,hdr".
static const char KEY_LIGHTFX[];
// Value for KEY_ZOOM_SUPPORTED or KEY_SMOOTH_ZOOM_SUPPORTED.
static const char TRUE[];
static const char FALSE[];
// Value for KEY_FOCUS_DISTANCES.
static const char FOCUS_DISTANCE_INFINITY[];
// Values for white balance settings.
static const char WHITE_BALANCE_AUTO[];
static const char WHITE_BALANCE_INCANDESCENT[];
static const char WHITE_BALANCE_FLUORESCENT[];
static const char WHITE_BALANCE_WARM_FLUORESCENT[];
static const char WHITE_BALANCE_DAYLIGHT[];
static const char WHITE_BALANCE_CLOUDY_DAYLIGHT[];
static const char WHITE_BALANCE_TWILIGHT[];
static const char WHITE_BALANCE_SHADE[];
// Values for effect settings.
static const char EFFECT_NONE[];
static const char EFFECT_MONO[];
static const char EFFECT_NEGATIVE[];
static const char EFFECT_SOLARIZE[];
static const char EFFECT_SEPIA[];
static const char EFFECT_POSTERIZE[];
static const char EFFECT_WHITEBOARD[];
static const char EFFECT_BLACKBOARD[];
static const char EFFECT_AQUA[];
// Values for antibanding settings.
static const char ANTIBANDING_AUTO[];
static const char ANTIBANDING_50HZ[];
static const char ANTIBANDING_60HZ[];
static const char ANTIBANDING_OFF[];
// Values for flash mode settings.
// Flash will not be fired.
static const char FLASH_MODE_OFF[];
// Flash will be fired automatically when required. The flash may be fired
// during preview, auto-focus, or snapshot depending on the driver.
static const char FLASH_MODE_AUTO[];
// Flash will always be fired during snapshot. The flash may also be
// fired during preview or auto-focus depending on the driver.
static const char FLASH_MODE_ON[];
// Flash will be fired in red-eye reduction mode.
static const char FLASH_MODE_RED_EYE[];
// Constant emission of light during preview, auto-focus and snapshot.
// This can also be used for video recording.
static const char FLASH_MODE_TORCH[];
// Values for scene mode settings.
static const char SCENE_MODE_AUTO[];
static const char SCENE_MODE_ACTION[];
static const char SCENE_MODE_PORTRAIT[];
static const char SCENE_MODE_LANDSCAPE[];
static const char SCENE_MODE_NIGHT[];
static const char SCENE_MODE_NIGHT_PORTRAIT[];
static const char SCENE_MODE_THEATRE[];
static const char SCENE_MODE_BEACH[];
static const char SCENE_MODE_SNOW[];
static const char SCENE_MODE_SUNSET[];
static const char SCENE_MODE_STEADYPHOTO[];
static const char SCENE_MODE_FIREWORKS[];
static const char SCENE_MODE_SPORTS[];
static const char SCENE_MODE_PARTY[];
static const char SCENE_MODE_CANDLELIGHT[];
// Applications are looking for a barcode. Camera driver will be optimized
// for barcode reading.
static const char SCENE_MODE_BARCODE[];
// A high-dynamic range mode. In this mode, the HAL module will use a
// capture strategy that extends the dynamic range of the captured
// image in some fashion. Only the final image is returned.
static const char SCENE_MODE_HDR[];
// Pixel color formats for KEY_PREVIEW_FORMAT, KEY_PICTURE_FORMAT,
// and KEY_VIDEO_FRAME_FORMAT
static const char PIXEL_FORMAT_YUV422SP[];
static const char PIXEL_FORMAT_YUV420SP[]; // NV21
static const char PIXEL_FORMAT_YUV422I[]; // YUY2
static const char PIXEL_FORMAT_YUV420P[]; // YV12
static const char PIXEL_FORMAT_RGB565[];
static const char PIXEL_FORMAT_RGBA8888[];
static const char PIXEL_FORMAT_JPEG[];
// Raw bayer format used for images, which is 10 bit precision samples
// stored in 16 bit words. The filter pattern is RGGB.
static const char PIXEL_FORMAT_BAYER_RGGB[];
// Pixel format is not known to the framework
static const char PIXEL_FORMAT_ANDROID_OPAQUE[];
// Values for focus mode settings.
// Auto-focus mode. Applications should call
// CameraHardwareInterface.autoFocus to start the focus in this mode.
static const char FOCUS_MODE_AUTO[];
// Focus is set at infinity. Applications should not call
// CameraHardwareInterface.autoFocus in this mode.
static const char FOCUS_MODE_INFINITY[];
// Macro (close-up) focus mode. Applications should call
// CameraHardwareInterface.autoFocus to start the focus in this mode.
static const char FOCUS_MODE_MACRO[];
// Focus is fixed. The camera is always in this mode if the focus is not
// adjustable. If the camera has auto-focus, this mode can fix the
// focus, which is usually at hyperfocal distance. Applications should
// not call CameraHardwareInterface.autoFocus in this mode.
static const char FOCUS_MODE_FIXED[];
// Extended depth of field (EDOF). Focusing is done digitally and
// continuously. Applications should not call
// CameraHardwareInterface.autoFocus in this mode.
static const char FOCUS_MODE_EDOF[];
// Continuous auto focus mode intended for video recording. The camera
// continuously tries to focus. This is the best choice for video
// recording because the focus changes smoothly . Applications still can
// call CameraHardwareInterface.takePicture in this mode but the subject may
// not be in focus. Auto focus starts when the parameter is set.
//
// Applications can call CameraHardwareInterface.autoFocus in this mode. The
// focus callback will immediately return with a boolean that indicates
// whether the focus is sharp or not. The focus position is locked after
// autoFocus call. If applications want to resume the continuous focus,
// cancelAutoFocus must be called. Restarting the preview will not resume
// the continuous autofocus. To stop continuous focus, applications should
// change the focus mode to other modes.
static const char FOCUS_MODE_CONTINUOUS_VIDEO[];
// Continuous auto focus mode intended for taking pictures. The camera
// continuously tries to focus. The speed of focus change is more aggressive
// than FOCUS_MODE_CONTINUOUS_VIDEO. Auto focus starts when the parameter is
// set.
//
// Applications can call CameraHardwareInterface.autoFocus in this mode. If
// the autofocus is in the middle of scanning, the focus callback will
// return when it completes. If the autofocus is not scanning, focus
// callback will immediately return with a boolean that indicates whether
// the focus is sharp or not. The apps can then decide if they want to take
// a picture immediately or to change the focus mode to auto, and run a full
// autofocus cycle. The focus position is locked after autoFocus call. If
// applications want to resume the continuous focus, cancelAutoFocus must be
// called. Restarting the preview will not resume the continuous autofocus.
// To stop continuous focus, applications should change the focus mode to
// other modes.
static const char FOCUS_MODE_CONTINUOUS_PICTURE[];
// Values for light special effects
// Low-light enhancement mode
static const char LIGHTFX_LOWLIGHT[];
// High-dynamic range mode
static const char LIGHTFX_HDR[];
/**
* Returns the the supported preview formats as an enum given in graphics.h
* corrsponding to the format given in the input string or -1 if no such
* conversion exists.
*/
static int previewFormatToEnum(const char* format);
private:
DefaultKeyedVector<String8,String8> mMap;
};
}; // namespace android
#endif

11997
QCamera2/HAL/QCamera2HWI.cpp Normal file

File diff suppressed because it is too large Load diff

870
QCamera2/HAL/QCamera2HWI.h Normal file
View file

@ -0,0 +1,870 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA2HARDWAREINTERFACE_H__
#define __QCAMERA2HARDWAREINTERFACE_H__
// System dependencies
#include <utils/Mutex.h>
#include <utils/Condition.h>
// Camera dependencies
#include "hardware/camera.h"
#include "QCameraAllocator.h"
#include "QCameraChannel.h"
#include "QCameraCmdThread.h"
#include "QCameraMem.h"
#include "QCameraParameters.h"
#include "QCameraParametersIntf.h"
#include "QCameraPerf.h"
#include "QCameraPostProc.h"
#include "QCameraQueue.h"
#include "QCameraStream.h"
#include "QCameraStateMachine.h"
#include "QCameraThermalAdapter.h"
#include "QCameraFOVControl.h"
#include "QCameraDualCamSettings.h"
#ifdef TARGET_TS_MAKEUP
#include "ts_makeup_engine.h"
#include "ts_detectface_engine.h"
#endif
extern "C" {
#include "mm_camera_interface.h"
#include "mm_jpeg_interface.h"
}
#include "QCameraTrace.h"
namespace qcamera {
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef enum {
QCAMERA_CH_TYPE_ZSL,
QCAMERA_CH_TYPE_CAPTURE,
QCAMERA_CH_TYPE_PREVIEW,
QCAMERA_CH_TYPE_VIDEO,
QCAMERA_CH_TYPE_SNAPSHOT,
QCAMERA_CH_TYPE_RAW,
QCAMERA_CH_TYPE_METADATA,
QCAMERA_CH_TYPE_ANALYSIS,
QCAMERA_CH_TYPE_CALLBACK,
QCAMERA_CH_TYPE_REPROCESSING,
QCAMERA_CH_TYPE_MAX
} qcamera_ch_type_enum_t;
typedef struct {
int32_t msg_type;
int32_t ext1;
int32_t ext2;
} qcamera_evt_argm_t;
#define QCAMERA_DUMP_FRM_PREVIEW 1
#define QCAMERA_DUMP_FRM_VIDEO (1<<1)
#define QCAMERA_DUMP_FRM_INPUT_JPEG (1<<2)
#define QCAMERA_DUMP_FRM_THUMBNAIL (1<<3)
#define QCAMERA_DUMP_FRM_RAW (1<<4)
#define QCAMERA_DUMP_FRM_OUTPUT_JPEG (1<<5)
#define QCAMERA_DUMP_FRM_INPUT_REPROCESS (1<<6)
#define QCAMERA_DUMP_FRM_MASK_ALL 0x000000ff
#define QCAMERA_ION_USE_CACHE true
#define QCAMERA_ION_USE_NOCACHE false
#define MAX_ONGOING_JOBS 25
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define EXIF_ASCII_PREFIX_SIZE 8 //(sizeof(ExifAsciiPrefix))
//Min buffer requirement for B+M Clearsight fusion
#define MIN_CLEARSIGHT_BUFS 3
#define NUM_BOKEH_OUTPUT 3 //Bokeh image, main image and depth map
/*For noraml recording usecase the number of video buffers
are 9 and preivew buffers are 5. In the special case
same buffer will be used for both preview and video, therefore
keeping the buffer count to 15.*/
#define VIDEO_FB_BUF_COUNT 15 //Number of buffers for video face beautification.
typedef enum {
QCAMERA_NOTIFY_CALLBACK,
QCAMERA_DATA_CALLBACK,
QCAMERA_DATA_TIMESTAMP_CALLBACK,
QCAMERA_DATA_SNAPSHOT_CALLBACK
} qcamera_callback_type_m;
/* meta data type and value in CameraMetaDataCallback */
typedef enum {
QCAMERA_METADATA_ASD = 0x001,
QCAMERA_METADATA_FD,
QCAMERA_METADATA_HDR,
QCAMERA_METADATA_LED_CALIB,
QCAMERA_METADATA_RTB
} cam_manual_capture_type;
typedef void (*camera_release_callback)(void *user_data,
void *cookie,
int32_t cb_status);
typedef void (*jpeg_data_callback)(int32_t msg_type,
const camera_memory_t *data, unsigned int index,
camera_frame_metadata_t *metadata, void *user,
uint32_t frame_idx, camera_release_callback release_cb,
void *release_cookie, void *release_data);
typedef struct {
qcamera_callback_type_m cb_type; // event type
int32_t msg_type; // msg type
int32_t ext1; // extended parameter
int32_t ext2; // extended parameter
camera_memory_t * data; // ptr to data memory struct
unsigned int index; // index of the buf in the whole buffer
int64_t timestamp; // buffer timestamp
camera_frame_metadata_t *metadata; // meta data
void *user_data; // any data needs to be released after callback
void *cookie; // release callback cookie
camera_release_callback release_cb; // release callback
uint32_t frame_index; // frame index for the buffer
} qcamera_callback_argm_t;
class QCameraCbNotifier {
public:
QCameraCbNotifier(QCamera2HardwareInterface *parent) :
mNotifyCb (NULL),
mDataCb (NULL),
mDataCbTimestamp (NULL),
mCallbackCookie (NULL),
mJpegCb(NULL),
mJpegCallbackCookie(NULL),
mParent (parent),
mDataQ(releaseNotifications, this),
mActive(false){}
virtual ~QCameraCbNotifier();
virtual int32_t notifyCallback(qcamera_callback_argm_t &cbArgs);
virtual void setCallbacks(camera_notify_callback notifyCb,
camera_data_callback dataCb,
camera_data_timestamp_callback dataCbTimestamp,
void *callbackCookie);
virtual void setJpegCallBacks(
jpeg_data_callback jpegCb, void *callbackCookie);
virtual int32_t startSnapshots();
virtual void stopSnapshots();
virtual void exit();
static void * cbNotifyRoutine(void * data);
static void releaseNotifications(void *data, void *user_data);
static bool matchSnapshotNotifications(void *data, void *user_data);
static bool matchPreviewNotifications(void *data, void *user_data);
static bool matchTimestampNotifications(void *data, void *user_data);
virtual int32_t flushPreviewNotifications();
virtual int32_t flushVideoNotifications();
private:
camera_notify_callback mNotifyCb;
camera_data_callback mDataCb;
camera_data_timestamp_callback mDataCbTimestamp;
void *mCallbackCookie;
jpeg_data_callback mJpegCb;
void *mJpegCallbackCookie;
QCamera2HardwareInterface *mParent;
QCameraQueue mDataQ;
QCameraCmdThread mProcTh;
bool mActive;
};
class QCameraDisplay;
class QCamera2HardwareInterface : public QCameraAllocator,
public QCameraThermalCallback, public QCameraAdjustFPS
{
public:
/* static variable and functions accessed by camera service */
static camera_device_ops_t mCameraOps;
static int set_preview_window(struct camera_device *,
struct preview_stream_ops *window);
static void set_CallBacks(struct camera_device *,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user);
static void enable_msg_type(struct camera_device *, int32_t msg_type);
static void disable_msg_type(struct camera_device *, int32_t msg_type);
static int msg_type_enabled(struct camera_device *, int32_t msg_type);
static int start_preview(struct camera_device *);
static void stop_preview(struct camera_device *);
static int preview_enabled(struct camera_device *);
static int store_meta_data_in_buffers(struct camera_device *, int enable);
static int restart_start_preview(struct camera_device *);
static int restart_stop_preview(struct camera_device *);
static int pre_start_recording(struct camera_device *);
static int start_recording(struct camera_device *);
static void stop_recording(struct camera_device *);
static int recording_enabled(struct camera_device *);
static void release_recording_frame(struct camera_device *, const void *opaque);
static int auto_focus(struct camera_device *);
static int cancel_auto_focus(struct camera_device *);
static int pre_take_picture(struct camera_device *);
static int take_picture(struct camera_device *);
int takeLiveSnapshot_internal();
int cancelLiveSnapshot_internal();
int takeBackendPic_internal(bool *JpegMemOpt, char *raw_format);
void clearIntPendingEvents();
void checkIntPicPending(bool JpegMemOpt, char *raw_format);
static int cancel_picture(struct camera_device *);
static int set_parameters(struct camera_device *, const char *parms);
static int stop_after_set_params(struct camera_device *);
static int commit_params(struct camera_device *);
static int restart_after_set_params(struct camera_device *);
static char* get_parameters(struct camera_device *);
static void put_parameters(struct camera_device *, char *);
static int send_command(struct camera_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
static int send_command_restart(struct camera_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
static void release(struct camera_device *);
static int dump(struct camera_device *, int fd);
static int close_camera_device(hw_device_t *);
static int register_face_image(struct camera_device *,
void *img_ptr,
cam_pp_offline_src_config_t *config);
static int prepare_preview(struct camera_device *);
static int prepare_snapshot(struct camera_device *device);
public:
QCamera2HardwareInterface(uint32_t cameraId);
virtual ~QCamera2HardwareInterface();
int openCamera(struct hw_device_t **hw_device);
// Dual camera specific oprations
int bundleRelatedCameras(bool syncOn);
int getCameraSessionId(uint32_t* session_id);
const cam_sync_related_sensors_event_info_t* getRelatedCamSyncInfo(
void);
int32_t setRelatedCamSyncInfo(
cam_sync_related_sensors_event_info_t* info);
bool isFrameSyncEnabled(void);
int32_t setFrameSyncEnabled(bool enable);
int32_t setMpoComposition(bool enable);
bool getMpoComposition(void);
bool getRecordingHintValue(void);
int32_t setRecordingHintValue(int32_t value);
bool isPreviewRestartNeeded(void) { return mPreviewRestartNeeded; };
static int getCapabilities(uint32_t cameraId,
struct camera_info *info, cam_sync_type_t *cam_type);
static int initCapabilities(uint32_t cameraId, mm_camera_vtbl_t *cameraHandle);
static cam_capability_t *getCapabilities(mm_camera_ops_t *ops,
uint32_t cam_handle);
cam_capability_t *getCamHalCapabilities();
// Implementation of QCameraAllocator
virtual QCameraMemory *allocateStreamBuf(cam_stream_type_t stream_type,
size_t size, int stride, int scanline, uint8_t &bufferCnt,
uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
virtual int32_t allocateMoreStreamBuf(QCameraMemory *mem_obj,
size_t size, uint8_t &bufferCnt);
virtual QCameraHeapMemory *allocateStreamInfoBuf(
cam_stream_type_t stream_type, uint8_t bufCount = 1,
uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
virtual QCameraHeapMemory *allocateMiscBuf(cam_stream_info_t *streamInfo);
virtual QCameraMemory *allocateStreamUserBuf(cam_stream_info_t *streamInfo);
virtual void waitForDeferredAlloc(cam_stream_type_t stream_type);
// Implementation of QCameraThermalCallback
virtual int thermalEvtHandle(qcamera_thermal_level_enum_t *level,
void *userdata, void *data);
virtual int recalcFPSRange(int &minFPS, int &maxFPS,
const float &minVideoFPS, const float &maxVideoFPS,
cam_fps_range_t &adjustedRange, bool bRecordingHint);
friend class QCameraStateMachine;
friend class QCameraPostProcessor;
friend class QCameraCbNotifier;
friend class QCameraMuxer;
int32_t initStreamInfoBuf(cam_stream_type_t stream_type,
cam_stream_info_t *streamInfo, uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
void setJpegCallBacks(jpeg_data_callback jpegCb,
void *callbackCookie);
int32_t initJpegHandle();
int32_t deinitJpegHandle();
int32_t setJpegHandleInfo(mm_jpeg_ops_t *ops,
mm_jpeg_mpo_ops_t *mpo_ops, uint32_t pJpegClientHandle);
int32_t getJpegHandleInfo(mm_jpeg_ops_t *ops,
mm_jpeg_mpo_ops_t *mpo_ops, uint32_t *pJpegClientHandle);
uint32_t getCameraId() { return mCameraId; };
bool bLiveSnapshot;
private:
int setPreviewWindow(struct preview_stream_ops *window);
int setCallBacks(
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user);
int enableMsgType(int32_t msg_type);
int disableMsgType(int32_t msg_type);
int msgTypeEnabled(int32_t msg_type);
int msgTypeEnabledWithLock(int32_t msg_type);
int startPreview();
int stopPreview();
int storeMetaDataInBuffers(int enable);
int preStartRecording();
int startRecording();
int stopRecording();
int releaseRecordingFrame(const void *opaque);
int autoFocus();
int cancelAutoFocus();
int preTakePicture();
int takePicture();
int stopCaptureChannel(bool destroy);
int cancelPicture();
int takeLiveSnapshot();
int takePictureInternal();
int cancelLiveSnapshot();
char* getParameters() {return mParameters.getParameters(); }
int putParameters(char *);
int sendCommand(int32_t cmd, int32_t &arg1, int32_t &arg2);
int release();
int dump(int fd);
int registerFaceImage(void *img_ptr,
cam_pp_offline_src_config_t *config,
int32_t &faceID);
int32_t longShot();
uint32_t deferPPInit();
int openCamera();
int closeCamera();
int processAPI(qcamera_sm_evt_enum_t api, void *api_payload);
int processEvt(qcamera_sm_evt_enum_t evt, void *evt_payload);
int processSyncEvt(qcamera_sm_evt_enum_t evt, void *evt_payload);
void lockAPI();
void waitAPIResult(qcamera_sm_evt_enum_t api_evt,
qcamera_api_result_t *apiResult, int timeoutSec = -1);
void unlockAPI();
void signalAPIResult(qcamera_api_result_t *result);
void signalEvtResult(qcamera_api_result_t *result);
int calcThermalLevel(qcamera_thermal_level_enum_t level,
const int minFPSi, const int maxFPSi,
const float &minVideoFPS, const float &maxVideoFPS,
cam_fps_range_t &adjustedRange,
enum msm_vfe_frame_skip_pattern &skipPattern,
bool bRecordingHint);
int updateThermalLevel(void *level);
// update entris to set parameters and check if restart is needed
int updateParameters(const char *parms, bool &needRestart);
// send request to server to set parameters
int commitParameterChanges();
bool isCaptureShutterEnabled();
bool needDebugFps();
bool isRegularCapture();
bool needOfflineReprocessing();
bool isCACEnabled();
bool is4k2kResolution(cam_dimension_t* resolution);
bool isPreviewRestartEnabled();
bool needReprocess();
bool needHALPP() {return m_bNeedHalPP;}
bool needRotationReprocess();
void debugShowVideoFPS();
void debugShowPreviewFPS();
void dumpJpegToFile(const void *data, size_t size, uint32_t index);
void dumpFrameToFile(QCameraStream *stream,
mm_camera_buf_def_t *frame, uint32_t dump_type, const char *misc = NULL);
void dumpMetadataToFile(QCameraStream *stream,
mm_camera_buf_def_t *frame,char *type);
void releaseSuperBuf(mm_camera_super_buf_t *super_buf);
void playShutter();
void getThumbnailSize(cam_dimension_t &dim);
uint32_t getJpegQuality();
QCameraExif *getExifData();
cam_sensor_t getSensorType();
bool isLowPowerMode();
nsecs_t getBootToMonoTimeOffset();
int32_t processAutoFocusEvent(cam_auto_focus_data_t &focus_data);
int32_t processZoomEvent(cam_crop_data_t &crop_info);
int32_t processPrepSnapshotDoneEvent(cam_prep_snapshot_state_t prep_snapshot_state);
int32_t processASDUpdate(cam_asd_decision_t asd_decision);
int32_t processJpegNotify(qcamera_jpeg_evt_payload_t *jpeg_job);
int32_t processHDRData(cam_asd_hdr_scene_data_t hdr_scene);
int32_t processLEDCalibration(int32_t value);
int32_t processRTBData(cam_rtb_msg_type_t rtbData);
int32_t processRetroAECUnlock();
int32_t processZSLCaptureDone();
int32_t processSceneData(cam_scene_mode_type scene);
int32_t transAwbMetaToParams(cam_awb_params_t &awb_params);
int32_t processFocusPositionInfo(cam_focus_pos_info_t &cur_pos_info);
int32_t processAEInfo(cam_3a_params_t &ae_params);
void processDualCamFovControl();
int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2);
int32_t sendDataNotify(int32_t msg_type,
camera_memory_t *data,
uint8_t index,
camera_frame_metadata_t *metadata,
uint32_t frame_idx);
int32_t sendPreviewCallback(QCameraStream *stream,
QCameraMemory *memory, uint32_t idx);
int32_t selectScene(QCameraChannel *pChannel,
mm_camera_super_buf_t *recvd_frame);
int32_t addChannel(qcamera_ch_type_enum_t ch_type);
int32_t startChannel(qcamera_ch_type_enum_t ch_type);
int32_t stopChannel(qcamera_ch_type_enum_t ch_type);
int32_t delChannel(qcamera_ch_type_enum_t ch_type, bool destroy = true);
int32_t addPreviewChannel();
int32_t addSnapshotChannel();
int32_t addVideoChannel();
int32_t addZSLChannel();
int32_t addCaptureChannel();
int32_t addRawChannel();
int32_t addMetaDataChannel();
int32_t addAnalysisChannel();
QCameraReprocessChannel *addReprocChannel(QCameraChannel *pInputChannel,
int8_t cur_channel_index = 0);
QCameraReprocessChannel *addOfflineReprocChannel(
cam_pp_offline_src_config_t &img_config,
cam_pp_feature_config_t &pp_feature,
stream_cb_routine stream_cb,
void *userdata);
int32_t addCallbackChannel();
int32_t addStreamToChannel(QCameraChannel *pChannel,
cam_stream_type_t streamType,
stream_cb_routine streamCB,
void *userData);
int32_t preparePreview();
void unpreparePreview();
int32_t prepareRawStream(QCameraChannel *pChannel);
QCameraChannel *getChannelByHandle(uint32_t channelHandle);
mm_camera_buf_def_t *getSnapshotFrame(mm_camera_super_buf_t *recvd_frame);
int32_t processFaceDetectionResult(cam_faces_data_t *fd_data);
bool needPreviewFDCallback(uint8_t num_faces);
int32_t processHistogramStats(cam_hist_stats_t &stats_data);
int32_t setHistogram(bool histogram_en);
int32_t setFaceDetection(bool enabled);
int32_t prepareHardwareForSnapshot(int32_t afNeeded);
bool needProcessPreviewFrame(uint32_t frameID);
bool needSendPreviewCallback();
bool isNoDisplayMode(uint32_t cam_type) {
return mParameters.isNoDisplayMode(cam_type); };
bool isZSLMode() {return mParameters.isZSLMode();};
bool isRdiMode() {return mParameters.isRdiMode();};
uint8_t numOfSnapshotsExpected() {
return mParameters.getNumOfSnapshots();};
bool isSecureMode() {return mParameters.isSecureMode();};
bool isLongshotEnabled() { return mLongshotEnabled; };
bool isHFRMode() {return mParameters.isHfrMode();};
bool isLiveSnapshot() {return m_stateMachine.isRecording();};
void setRetroPicture(bool enable) { bRetroPicture = enable; };
bool isRetroPicture() {return bRetroPicture; };
bool isHDRMode() {return mParameters.isHDREnabled();};
uint8_t getBufNumRequired(cam_stream_type_t stream_type,
uint32_t cam_type = CAM_TYPE_MAIN);
uint8_t getBufNumForAux(cam_stream_type_t stream_type);
bool needFDMetadata(qcamera_ch_type_enum_t channel_type);
int32_t getPaddingInfo(cam_stream_type_t streamType,
cam_padding_info_t *padding_info);
int32_t configureOnlineRotation(QCameraChannel &ch);
int32_t declareSnapshotStreams();
int32_t unconfigureAdvancedCapture();
int32_t configureAdvancedCapture();
int32_t configureAFBracketing(bool enable = true);
int32_t configureHDRBracketing();
int32_t configureHalPostProcess();
int32_t stopAdvancedCapture(QCameraPicChannel *pChannel);
int32_t startAdvancedCapture(QCameraPicChannel *pChannel);
int32_t configureOptiZoom();
int32_t configureStillMore();
int32_t configureAEBracketing();
int32_t updatePostPreviewParameters();
inline void setOutputImageCount(uint32_t aCount) {mOutputCount = aCount;}
inline uint32_t getOutputImageCount() {return mOutputCount;}
bool processUFDumps(qcamera_jpeg_evt_payload_t *evt);
void captureDone();
int32_t updateMetadata(metadata_buffer_t *pMetaData);
void fillFacesData(cam_faces_data_t &faces_data, metadata_buffer_t *metadata);
int32_t getPPConfig(cam_pp_feature_config_t &pp_config,
int8_t curIndex = 0, bool multipass = FALSE);
virtual uint32_t scheduleBackgroundTask(BackgroundTask* bgTask);
virtual int32_t waitForBackgroundTask(uint32_t &taskId);
bool needDeferred(cam_stream_type_t stream_type);
static void camEvtHandle(uint32_t camera_handle,
mm_camera_event_t *evt,
void *user_data);
static void jpegEvtHandle(jpeg_job_status_t status,
uint32_t client_hdl,
uint32_t jobId,
mm_jpeg_output_t *p_buf,
void *userdata);
static void *evtNotifyRoutine(void *data);
// functions for different data notify cb
static void zsl_channel_cb(mm_camera_super_buf_t *recvd_frame, void *userdata);
static void capture_channel_cb_routine(mm_camera_super_buf_t *recvd_frame,
void *userdata);
static void postproc_channel_cb_routine(mm_camera_super_buf_t *recvd_frame,
void *userdata);
static void rdi_mode_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void nodisplay_preview_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void preview_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void synchronous_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream, void *userdata);
static void postview_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void video_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void snapshot_channel_cb_routine(mm_camera_super_buf_t *frame,
void *userdata);
static void raw_channel_cb_routine(mm_camera_super_buf_t *frame,
void *userdata);
static void raw_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void preview_raw_stream_cb_routine(mm_camera_super_buf_t * super_frame,
QCameraStream * stream,
void * userdata);
static void snapshot_raw_stream_cb_routine(mm_camera_super_buf_t * super_frame,
QCameraStream * stream,
void * userdata);
static void metadata_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void callback_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream, void *userdata);
static void reprocess_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
static void secure_stream_cb_routine(mm_camera_super_buf_t *frame,
QCameraStream *stream, void *userdata);
static void releaseCameraMemory(void *data,
void *cookie,
int32_t cbStatus);
static void returnStreamBuffer(void *data,
void *cookie,
int32_t cbStatus);
static void getLogLevel();
int32_t startRAWChannel(QCameraChannel *pChannel);
int32_t stopRAWChannel();
inline bool getNeedRestart() {return m_bNeedRestart;}
inline void setNeedRestart(bool needRestart) {m_bNeedRestart = needRestart;}
/*Start display skip. Skip starts after
skipCnt number of frames from current frame*/
void setDisplaySkip(bool enabled, uint8_t skipCnt = 0);
/*Caller can specify range frameID to skip.
if end is 0, all the frames after start will be skipped*/
void setDisplayFrameSkip(uint32_t start = 0, uint32_t end = 0);
/*Verifies if frameId is valid to skip*/
bool isDisplayFrameToSkip(uint32_t frameId);
bool isDualCamera() { return mDualCamera; };
void fillDualCameraFOVControl();
uint8_t getStreamRefCount(cam_stream_type_t stream_type,
uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
uint32_t getCamHandleForChannel(qcamera_ch_type_enum_t ch_type);
int32_t switchCameraCb(uint32_t camMaster);
void forceCameraWakeup();
int32_t processCameraControl(uint32_t camState, bool bundledSnapshot,
cam_fallback_mode_t fallbackMode);
bool needSyncCB(cam_stream_type_t stream_type);
uint32_t getSnapshotHandle();
void initDCSettings();
void updateDCSettings();
void configureSnapshotSkip(bool skip);
private:
camera_device_t mCameraDevice;
uint32_t mCameraId;
mm_camera_vtbl_t *mCameraHandle;
uint32_t mActiveCameras;
uint32_t mMasterCamera;
bool mBundledSnapshot;
cam_fallback_mode_t mFallbackMode;
bool mCameraOpened;
bool mDualCamera;
QCameraFOVControl *m_pFovControl;
cam_jpeg_metadata_t mJpegMetadata;
bool m_bRelCamCalibValid;
preview_stream_ops_t *mPreviewWindow;
QCameraParametersIntf mParameters;
int32_t mMsgEnabled;
int mStoreMetaDataInFrame;
camera_notify_callback mNotifyCb;
camera_data_callback mDataCb;
camera_data_timestamp_callback mDataCbTimestamp;
camera_request_memory mGetMemory;
jpeg_data_callback mJpegCb;
void *mCallbackCookie;
void *mJpegCallbackCookie;
bool m_bMpoEnabled;
QCameraStateMachine m_stateMachine; // state machine
bool m_smThreadActive;
QCameraPostProcessor m_postprocessor; // post processor
QCameraThermalAdapter &m_thermalAdapter;
QCameraCbNotifier m_cbNotifier;
QCameraPerfLockMgr m_perfLockMgr;
pthread_mutex_t m_lock;
pthread_cond_t m_cond;
api_result_list *m_apiResultList;
QCameraMemoryPool m_memoryPool;
pthread_mutex_t m_evtLock;
pthread_cond_t m_evtCond;
qcamera_api_result_t m_evtResult;
QCameraChannel *m_channels[QCAMERA_CH_TYPE_MAX]; // array holding channel ptr
bool m_bPreviewStarted; //flag indicates first preview frame callback is received
bool m_bFirstPreviewFrameReceived;
bool m_bRecordStarted; //flag indicates Recording is started for first time
bool m_bPreparingHardware; //flag indicates take picture initiated
bool m_bNeedVideoCb; //flag indicates video face beautifications is enabled
QCameraVideoMemory *videoMemFb;
// Signifies if ZSL Retro Snapshots are enabled
bool bRetroPicture;
// Signifies AEC locked during zsl snapshots
bool m_bLedAfAecLock;
cam_af_state_t m_currentFocusState;
uint32_t mDumpFrmCnt; // frame dump count
uint32_t mDumpSkipCnt; // frame skip count
mm_jpeg_exif_params_t mExifParams;
qcamera_thermal_level_enum_t mThermalLevel;
bool mActiveAF;
bool m_HDRSceneEnabled;
bool mLongshotEnabled;
pthread_t mLiveSnapshotThread;
pthread_t mIntPicThread;
bool mFlashNeeded;
bool mFlashConfigured;
uint32_t mDeviceRotation;
uint32_t mCaptureRotation;
uint32_t mJpegExifRotation;
bool mUseJpegExifRotation;
bool mIs3ALocked;
bool mPrepSnapRun;
int32_t mZoomLevel;
// Flag to indicate whether preview restart needed (for dual camera mode)
bool mPreviewRestartNeeded;
int mVFrameCount;
int mVLastFrameCount;
nsecs_t mVLastFpsTime;
double mVFps;
int mPFrameCount;
int mPLastFrameCount;
nsecs_t mPLastFpsTime;
double mPFps;
bool mLowLightConfigured;
uint8_t mInstantAecFrameCount;
//eztune variables for communication with eztune server at backend
bool m_bIntJpegEvtPending;
bool m_bIntRawEvtPending;
char m_BackendFileName[QCAMERA_MAX_FILEPATH_LENGTH];
size_t mBackendFileSize;
pthread_mutex_t m_int_lock;
pthread_cond_t m_int_cond;
enum DeferredWorkCmd {
CMD_DEF_ALLOCATE_BUFF,
CMD_DEF_PPROC_START,
CMD_DEF_PPROC_INIT,
CMD_DEF_METADATA_ALLOC,
CMD_DEF_CREATE_JPEG_SESSION,
CMD_DEF_PARAM_ALLOC,
CMD_DEF_PARAM_INIT,
CMD_DEF_GENERIC,
CMD_DEF_MAX
};
typedef struct {
QCameraChannel *ch;
cam_stream_type_t type;
} DeferAllocBuffArgs;
typedef struct {
uint8_t bufferCnt;
size_t size;
} DeferMetadataAllocArgs;
typedef struct {
jpeg_encode_callback_t jpeg_cb;
void *user_data;
} DeferPProcInitArgs;
typedef union {
DeferAllocBuffArgs allocArgs;
QCameraChannel *pprocArgs;
DeferMetadataAllocArgs metadataAllocArgs;
DeferPProcInitArgs pprocInitArgs;
BackgroundTask *genericArgs;
} DeferWorkArgs;
typedef struct {
uint32_t mDefJobId;
//Job status is needed to check job was successful or failed
//Error code when job was not sucessful and there is error
//0 when is initialized.
//for sucessfull job, do not need to maintain job status
int32_t mDefJobStatus;
} DefOngoingJob;
DefOngoingJob mDefOngoingJobs[MAX_ONGOING_JOBS];
struct DefWork
{
DefWork(DeferredWorkCmd cmd_,
uint32_t id_,
DeferWorkArgs args_)
: cmd(cmd_),
id(id_),
args(args_){};
DeferredWorkCmd cmd;
uint32_t id;
DeferWorkArgs args;
};
QCameraCmdThread mDeferredWorkThread;
QCameraQueue mCmdQueue;
Mutex mDefLock;
Condition mDefCond;
uint32_t queueDeferredWork(DeferredWorkCmd cmd,
DeferWorkArgs args);
uint32_t dequeueDeferredWork(DefWork* dw, int32_t jobStatus);
int32_t waitDeferredWork(uint32_t &job_id);
static void *deferredWorkRoutine(void *obj);
bool checkDeferredWork(uint32_t &job_id);
int32_t getDefJobStatus(uint32_t &job_id);
uint32_t mReprocJob;
uint32_t mJpegJob;
uint32_t mMetadataAllocJob;
uint32_t mInitPProcJob;
uint32_t mParamAllocJob;
uint32_t mParamInitJob;
uint32_t mOutputCount;
uint32_t mInputCount;
bool mAdvancedCaptureConfigured;
bool mHDRBracketingEnabled;
int32_t mNumPreviewFaces;
// Jpeg Handle shared between HWI instances
mm_jpeg_ops_t mJpegHandle;
// MPO handle shared between HWI instances
// this is needed for MPO composition of related
// cam images
mm_jpeg_mpo_ops_t mJpegMpoHandle;
uint32_t mJpegClientHandle;
bool mJpegHandleOwner;
//ts add for makeup
#ifdef TARGET_TS_MAKEUP
TSRect mFaceRect;
bool TsMakeupProcess_Preview(mm_camera_buf_def_t *pFrame,QCameraStream * pStream);
bool TsMakeupProcess_Snapshot(mm_camera_buf_def_t *pFrame,QCameraStream * pStream);
bool TsMakeupProcess(mm_camera_buf_def_t *frame,QCameraStream * stream,TSRect& faceRect);
#endif
QCameraMemory *mMetadataMem;
uint32_t mNextJobId;
//Gralloc memory details
pthread_mutex_t mGrallocLock;
uint8_t mEnqueuedBuffers;
bool mCACDoneReceived;
//GPU library to read buffer padding details.
void *lib_surface_utils;
int (*LINK_get_surface_pixel_alignment)();
uint32_t mSurfaceStridePadding;
//QCamera Display Object
QCameraDisplay* mCameraDisplay;
bool m_bNeedRestart;
Mutex mMapLock;
Condition mMapCond;
//Used to decide the next frameID to be skipped
uint32_t mLastPreviewFrameID;
//FrameID to start frame skip.
uint32_t mFrameSkipStart;
/*FrameID to stop frameskip. If this is not set,
all frames are skipped till we set this*/
uint32_t mFrameSkipEnd;
//The offset between BOOTTIME and MONOTONIC timestamps
nsecs_t mBootToMonoTimestampOffset;
bool bDepthAFCallbacks;
bool m_bOptimizeCacheOps;
bool m_bNeedHalPP;
};
}; // namespace qcamera
#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,66 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_ALLOCATOR__
#define __QCAMERA_ALLOCATOR__
extern "C" {
#include "mm_camera_interface.h"
}
namespace qcamera {
class QCameraMemory;
class QCameraHeapMemory;
typedef struct {
int32_t (*bgFunction) (void *);
void* bgArgs;
} BackgroundTask;
class QCameraAllocator {
public:
virtual QCameraMemory *allocateStreamBuf(cam_stream_type_t stream_type,
size_t size, int stride, int scanline, uint8_t &bufferCnt,
uint32_t cam_type = MM_CAMERA_TYPE_MAIN) = 0;
virtual int32_t allocateMoreStreamBuf(QCameraMemory *mem_obj,
size_t size, uint8_t &bufferCnt) = 0;
virtual QCameraHeapMemory *allocateStreamInfoBuf(
cam_stream_type_t stream_type, uint8_t bufCount = 1,
uint32_t cam_type = MM_CAMERA_TYPE_MAIN) = 0;
virtual QCameraHeapMemory *allocateMiscBuf(cam_stream_info_t *streamInfo) = 0;
virtual QCameraMemory *allocateStreamUserBuf(cam_stream_info_t *streamInfo) = 0;
virtual void waitForDeferredAlloc(cam_stream_type_t stream_type) = 0;
virtual uint32_t scheduleBackgroundTask(BackgroundTask* bgTask) = 0;
virtual int32_t waitForBackgroundTask(uint32_t &taskId) = 0;
virtual ~QCameraAllocator() {}
};
}; /* namespace qcamera */
#endif /* __QCAMERA_ALLOCATOR__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,185 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_CHANNEL_H__
#define __QCAMERA_CHANNEL_H__
#include "hardware/camera.h"
#include "QCameraMem.h"
#include "QCameraParameters.h"
#include "QCameraStream.h"
extern "C" {
#include "mm_camera_interface.h"
}
namespace qcamera {
class QCameraChannel
{
public:
QCameraChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops);
QCameraChannel();
virtual ~QCameraChannel();
virtual int32_t init(mm_camera_channel_attr_t *attr,
mm_camera_buf_notify_t dataCB, // data CB for channel data
void *userData);
// Owner of memory is transferred from the caller to the caller with this call.
virtual int32_t addStream(QCameraAllocator& allocator,
QCameraHeapMemory *streamInfoBuf, QCameraHeapMemory *miscBuf,
cam_padding_info_t *paddingInfo,
stream_cb_routine stream_cb, void *userdata, bool bDynAllocBuf,
bool bDeffAlloc = false, cam_rotation_t online_rotation = ROTATE_0,
uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
virtual int32_t linkStream(QCameraChannel *ch, QCameraStream *stream);
virtual int32_t start();
virtual int32_t stop();
virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame);
virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame, uint32_t stream_id);
virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow,
cam_crop_data_t &crop_info);
QCameraStream *getStreamByHandle(uint32_t streamHandle);
uint32_t getMyHandle() const {return m_handle;};
uint32_t getNumOfStreams() const {return (uint32_t) mStreams.size();};
QCameraStream *getStreamByIndex(uint32_t index);
QCameraStream *getStreamByServerID(uint32_t serverID);
int32_t UpdateStreamBasedParameters(QCameraParametersIntf &param);
void deleteChannel();
int32_t setStreamSyncCB (cam_stream_type_t stream_type,
stream_cb_routine stream_cb);
bool isActive() { return m_bIsActive; }
int32_t releaseFrame(const void *opaque, bool isMetaData, QCameraVideoMemory *videoMem);
uint32_t getChHandleForStream(cam_stream_type_t stream_type);
int32_t switchChannelCb(uint32_t camMaster);
int32_t processCameraControl(uint32_t camState, bool bundledSnapshot);
bool isDualChannel(){return mDualChannel;};
uint32_t getSnapshotHandle();
void initDCSettings(int32_t camState, uint32_t camMaster,
bool bundledSnapshot);
protected:
uint32_t m_camHandle;
mm_camera_ops_t *m_camOps;
bool m_bIsActive;
bool m_bAllowDynBufAlloc; // if buf allocation can be in two steps
uint32_t m_handle;
uint32_t mActiveCameras;
uint32_t mMasterCamera;
bool mBundledSnapshot;
Vector<QCameraStream *> mStreams;
mm_camera_buf_notify_t mDataCB;
void *mUserData;
Mutex mStreamLock;
bool mDualChannel;
};
// burst pic channel: i.e. zsl burst mode
class QCameraPicChannel : public QCameraChannel
{
public:
QCameraPicChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops);
QCameraPicChannel();
virtual ~QCameraPicChannel();
int32_t takePicture(mm_camera_req_buf_t *buf);
int32_t cancelPicture();
int32_t stopAdvancedCapture(mm_camera_advanced_capture_t type);
int32_t startAdvancedCapture(mm_camera_advanced_capture_t type,
cam_capture_frame_config_t *config = NULL);
int32_t flushSuperbuffer(uint32_t cam, uint32_t frame_idx);
};
// video channel class
class QCameraVideoChannel : public QCameraChannel
{
public:
QCameraVideoChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops);
QCameraVideoChannel();
virtual ~QCameraVideoChannel();
int32_t takePicture(mm_camera_req_buf_t *buf);
int32_t cancelPicture();
int32_t releaseFrame(const void *opaque, bool isMetaData);
};
// reprocess channel class
class QCameraReprocessChannel : public QCameraChannel
{
public:
QCameraReprocessChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops);
QCameraReprocessChannel();
virtual ~QCameraReprocessChannel();
int32_t addReprocStreamsFromSource(QCameraAllocator& allocator,
cam_pp_feature_config_t &config,
QCameraChannel *pSrcChannel,
uint8_t minStreamBufNum,
uint8_t burstNum,
cam_padding_info_t *paddingInfo,
QCameraParametersIntf &param,
bool contStream,
bool offline);
// online reprocess
int32_t doReprocess(mm_camera_super_buf_t *frame,
QCameraParametersIntf &param, QCameraStream *pMetaStream,
uint8_t meta_buf_index);
// offline reprocess
int32_t doReprocess(int buf_fd, void *buffer, size_t buf_length, int32_t &ret_val);
int32_t doReprocessOffline(mm_camera_super_buf_t *frame,
mm_camera_buf_def_t *meta_buf, QCameraParametersIntf &param);
int32_t doReprocessOffline(mm_camera_buf_def_t *frame,
mm_camera_buf_def_t *meta_buf, QCameraStream *pStream = NULL);
int32_t stop();
QCameraChannel *getSrcChannel(){return m_pSrcChannel;};
int8_t getReprocCount(){return mPassCount;};
void setReprocCount(int8_t count) {mPassCount = count;};
private:
QCameraStream *getStreamBySrouceHandle(uint32_t srcHandle);
typedef struct {
QCameraStream *stream;
cam_mapping_buf_type type;
uint32_t index;
} OfflineBuffer;
uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE];
QCameraChannel *m_pSrcChannel; // ptr to source channel for reprocess
android::List<OfflineBuffer> mOfflineBuffers;
int8_t mPassCount;
};
}; // namespace qcamera
#endif /* __QCAMERA_CHANNEL_H__ */

2857
QCamera2/HAL/QCameraMem.cpp Normal file

File diff suppressed because it is too large Load diff

356
QCamera2/HAL/QCameraMem.h Normal file
View file

@ -0,0 +1,356 @@
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA2HWI_MEM_H__
#define __QCAMERA2HWI_MEM_H__
// System dependencies
#include <linux/msm_ion.h>
#if TARGET_ION_ABI_VERSION >= 2
#include <ion/ion.h>
#include <linux/dma-buf.h>
#endif //TARGET_ION_ABI_VERSION
#include <utils/Mutex.h>
#include <utils/List.h>
//Media depedancies
#include "OMX_QCOMExtns.h"
// Display dependencies
#include "qdMetaData.h"
// Camera dependencies
#include "hardware/camera.h"
extern "C" {
#include "mm_camera_interface.h"
}
#if TARGET_ION_ABI_VERSION >= 2
#ifndef CAM_CACHE_OPS
#define CAM_CACHE_OPS
enum {
CAM_CLEAN_CACHE,
CAM_INV_CACHE,
CAM_CLEAN_INV_CACHE
};
#define ION_IOC_CLEAN_CACHES CAM_CLEAN_CACHE
#define ION_IOC_INV_CACHES CAM_INV_CACHE
#define ION_IOC_CLEAN_INV_CACHES CAM_CLEAN_INV_CACHE
#endif //CAM_CACHE_OPS
#endif //TARGET_ION_ABI_VERSION
namespace qcamera {
using namespace android;
class QCameraMemoryPool;
//Buffer identity
//Note that this macro might have already been
//defined in OMX_QCOMExtns.h, in which case
//the local value below will not be used.
#ifndef VIDEO_METADATA_NUM_COMMON_INTS
#define VIDEO_METADATA_NUM_COMMON_INTS 1
#endif
enum QCameraMemType {
QCAMERA_MEM_TYPE_DEFAULT = 0,
QCAMERA_MEM_TYPE_SECURE = 1,
QCAMERA_MEM_TYPE_BATCH = (1 << 1),
QCAMERA_MEM_TYPE_COMPRESSED = (1 << 2),
};
enum QCameraVideoMetaBufInts {
VIDEO_META_OFFSET = MetaBufferUtil::INT_OFFSET,
VIDEO_META_SIZE = MetaBufferUtil::INT_SIZE,
VIDEO_META_USAGE = MetaBufferUtil::INT_USAGE,
VIDEO_META_TIMESTAMP = MetaBufferUtil::INT_TIMESTAMP,
VIDEO_META_FORMAT = MetaBufferUtil::INT_COLORFORMAT,
VIDEO_META_BUFIDX = MetaBufferUtil::INT_BUFINDEX,
VIDEO_META_EVENT = MetaBufferUtil::INT_BUFEVENT,
//Add per frame Ints before this
VIDEO_METADATA_NUM_INTS = MetaBufferUtil::INT_TOTAL,
};
typedef enum {
STATUS_IDLE,
STATUS_SKIPPED,
STATUS_ACTIVE
} BufferStatus;
// Base class for all memory types. Abstract.
class QCameraMemory {
public:
int cleanCache(uint32_t index)
{
return cacheOps(index, ION_IOC_CLEAN_CACHES);
}
int invalidateCache(uint32_t index)
{
return cacheOps(index, ION_IOC_INV_CACHES);
}
int cleanInvalidateCache(uint32_t index)
{
return cacheOps(index, ION_IOC_CLEAN_INV_CACHES);
}
int getFd(uint32_t index) const;
ssize_t getSize(uint32_t index) const;
uint8_t getCnt() const;
virtual uint8_t getMappable() const;
virtual uint8_t checkIfAllBuffersMapped() const;
virtual int allocate(uint8_t count, size_t size) = 0;
virtual void deallocate() = 0;
virtual int allocateMore(uint8_t count, size_t size) = 0;
virtual int cacheOps(uint32_t index, unsigned int cmd) = 0;
virtual int getRegFlags(uint8_t *regFlags) const = 0;
virtual camera_memory_t *getMemory(uint32_t index,
bool metadata) const = 0;
virtual int getMatchBufIndex(const void *opaque, bool metadata) const = 0;
virtual void *getPtr(uint32_t index) const= 0;
QCameraMemory(bool cached,
QCameraMemoryPool *pool = NULL,
cam_stream_type_t streamType = CAM_STREAM_TYPE_DEFAULT,
QCameraMemType buf_Type = QCAMERA_MEM_TYPE_DEFAULT);
virtual ~QCameraMemory();
virtual void reset();
void getBufDef(const cam_frame_len_offset_t &offset,
mm_camera_buf_def_t &bufDef, uint32_t index) const;
int32_t getUserBufDef(const cam_stream_user_buf_info_t &buf_info,
mm_camera_buf_def_t &bufDef, uint32_t index,
const cam_frame_len_offset_t &plane_offset,
mm_camera_buf_def_t *planebufDef, QCameraMemory *bufs) const;
protected:
friend class QCameraMemoryPool;
struct QCameraMemInfo {
int fd;
int main_ion_fd;
ion_user_handle_t handle;
size_t size;
bool cached;
unsigned int heap_id;
};
int alloc(int count, size_t size, unsigned int heap_id);
void dealloc();
static int allocOneBuffer(struct QCameraMemInfo &memInfo,
unsigned int heap_id, size_t size, bool cached, bool is_secure);
static void deallocOneBuffer(struct QCameraMemInfo &memInfo);
int cacheOpsInternal(uint32_t index, unsigned int cmd, void *vaddr);
bool m_bCached;
uint8_t mBufferCount;
struct QCameraMemInfo mMemInfo[MM_CAMERA_MAX_NUM_FRAMES];
QCameraMemoryPool *mMemoryPool;
cam_stream_type_t mStreamType;
QCameraMemType mBufType;
};
class QCameraMemoryPool {
public:
QCameraMemoryPool();
virtual ~QCameraMemoryPool();
int allocateBuffer(struct QCameraMemory::QCameraMemInfo &memInfo,
unsigned int heap_id, size_t size, bool cached,
cam_stream_type_t streamType, bool is_secure);
void releaseBuffer(struct QCameraMemory::QCameraMemInfo &memInfo,
cam_stream_type_t streamType);
void clear();
protected:
int findBufferLocked(struct QCameraMemory::QCameraMemInfo &memInfo,
unsigned int heap_id, size_t size, bool cached,
cam_stream_type_t streamType);
android::List<QCameraMemory::QCameraMemInfo> mPools[CAM_STREAM_TYPE_MAX];
pthread_mutex_t mLock;
};
// Internal heap memory is used for memories used internally
// They are allocated from /dev/ion.
class QCameraHeapMemory : public QCameraMemory {
public:
QCameraHeapMemory(bool cached);
virtual ~QCameraHeapMemory();
virtual int allocate(uint8_t count, size_t size);
virtual int allocateMore(uint8_t count, size_t size);
virtual void deallocate();
virtual int cacheOps(uint32_t index, unsigned int cmd);
virtual int getRegFlags(uint8_t *regFlags) const;
virtual camera_memory_t *getMemory(uint32_t index, bool metadata) const;
virtual int getMatchBufIndex(const void *opaque, bool metadata) const;
virtual void *getPtr(uint32_t index) const;
private:
void *mPtr[MM_CAMERA_MAX_NUM_FRAMES];
};
class QCameraMetadataStreamMemory : public QCameraHeapMemory {
public:
QCameraMetadataStreamMemory(bool cached);
virtual ~QCameraMetadataStreamMemory();
virtual int getRegFlags(uint8_t *regFlags) const;
};
// Externel heap memory is used for memories shared with
// framework. They are allocated from /dev/ion or gralloc.
class QCameraStreamMemory : public QCameraMemory {
public:
QCameraStreamMemory(camera_request_memory getMemory,
void* cbCookie,
bool cached,
QCameraMemoryPool *pool = NULL,
cam_stream_type_t streamType = CAM_STREAM_TYPE_DEFAULT,
QCameraMemType buf_Type = QCAMERA_MEM_TYPE_DEFAULT);
virtual ~QCameraStreamMemory();
virtual int allocate(uint8_t count, size_t size);
virtual int allocateMore(uint8_t count, size_t size);
virtual void deallocate();
virtual int cacheOps(uint32_t index, unsigned int cmd);
virtual int getRegFlags(uint8_t *regFlags) const;
virtual camera_memory_t *getMemory(uint32_t index, bool metadata) const;
virtual int getMatchBufIndex(const void *opaque, bool metadata) const;
virtual void *getPtr(uint32_t index) const;
protected:
camera_request_memory mGetMemory;
camera_memory_t *mCameraMemory[MM_CAMERA_MAX_NUM_FRAMES];
void* mCallbackCookie;
};
// Externel heap memory is used for memories shared with
// framework. They are allocated from /dev/ion or gralloc.
class QCameraVideoMemory : public QCameraStreamMemory {
public:
QCameraVideoMemory(camera_request_memory getMemory, void* cbCookie, bool cached,
QCameraMemType bufType = QCAMERA_MEM_TYPE_DEFAULT);
virtual ~QCameraVideoMemory();
virtual int allocate(uint8_t count, size_t size);
virtual int allocateMetaBufs(uint8_t count, QCameraMemory *previewmem);
virtual int allocateMore(uint8_t count, size_t size);
virtual void deallocate();
virtual camera_memory_t *getMemory(uint32_t index, bool metadata) const;
virtual int getMatchBufIndex(const void *opaque, bool metadata) const;
int allocateMeta(uint8_t buf_cnt, int numFDs);
void deallocateMeta();
void setVideoInfo(int usage, cam_format_t format);
int getUsage(){return mUsage;};
int getFormat(){return mFormat;};
int convCamtoOMXFormat(cam_format_t format);
int closeNativeHandle(const void *data, bool metadata = true);
native_handle_t *getNativeHandle(uint32_t index, bool metadata = true);
static int closeNativeHandle(const void *data);
int32_t updateNativeHandle(native_handle_t *nh,
int batch_idx, int fd, int size, int ts = 0);
bool needPerfEvent(const void *data, bool metadata = true);
private:
camera_memory_t *mMetadata[MM_CAMERA_MAX_NUM_FRAMES];
uint8_t mMetaBufCount;
int mUsage, mFormat;
native_handle_t *mNativeHandle[MM_CAMERA_MAX_NUM_FRAMES];
};
// Gralloc Memory is acquired from preview window
class QCameraGrallocMemory : public QCameraMemory {
enum {
BUFFER_NOT_OWNED,
BUFFER_OWNED,
};
public:
QCameraGrallocMemory(camera_request_memory getMemory, void* cbCookie,
QCameraMemType buf_Type = QCAMERA_MEM_TYPE_DEFAULT);
void setNativeWindow(preview_stream_ops_t *anw);
virtual ~QCameraGrallocMemory();
virtual int allocate(uint8_t count, size_t size);
virtual int allocateMore(uint8_t count, size_t size);
virtual void deallocate();
virtual int cacheOps(uint32_t index, unsigned int cmd);
virtual int getRegFlags(uint8_t *regFlags) const;
virtual camera_memory_t *getMemory(uint32_t index, bool metadata) const;
virtual int getMatchBufIndex(const void *opaque, bool metadata) const;
virtual void *getPtr(uint32_t index) const;
virtual void setMappable(uint8_t mappable);
virtual uint8_t getMappable() const;
virtual uint8_t checkIfAllBuffersMapped() const;
void setWindowInfo(preview_stream_ops_t *window, int width, int height,
int stride, int scanline, int format, int maxFPS, int usage = 0);
// Enqueue/display buffer[index] onto the native window,
// and dequeue one buffer from it.
// Returns the buffer index of the dequeued buffer.
int displayBuffer(uint32_t index);
void setMaxFPS(int maxFPS);
int32_t enqueueBuffer(uint32_t index, nsecs_t timeStamp = 0);
int32_t dequeueBuffer();
inline bool isBufActive(uint32_t index){return (mBufferStatus[index] == STATUS_ACTIVE);};
inline bool isBufSkipped(uint32_t index){return (mBufferStatus[index] == STATUS_SKIPPED);};
inline bool hasPendingRef(uint32_t index){return (mRefCount[index]);};
void setBufferStatus(uint32_t index, BufferStatus status);
void setRefCount(uint32_t index,uint8_t count);
pthread_mutex_t mStatusLock;
private:
buffer_handle_t *mBufferHandle[MM_CAMERA_MAX_NUM_FRAMES];
int mLocalFlag[MM_CAMERA_MAX_NUM_FRAMES];
int mBufferStatus[MM_CAMERA_MAX_NUM_FRAMES];
uint8_t mRefCount[MM_CAMERA_MAX_NUM_FRAMES];
struct private_handle_t *mPrivateHandle[MM_CAMERA_MAX_NUM_FRAMES];
preview_stream_ops_t *mWindow;
int mWidth, mHeight, mFormat, mStride, mScanline, mUsage;
typeof (MetaData_t::refreshrate) mMaxFPS;
camera_request_memory mGetMemory;
void* mCallbackCookie;
camera_memory_t *mCameraMemory[MM_CAMERA_MAX_NUM_FRAMES];
int mMinUndequeuedBuffers;
enum ColorSpace_t mColorSpace;
uint8_t mMappableBuffers;
pthread_mutex_t mLock;
uint8_t mEnqueuedBuffers;
};
}; // namespace qcamera
#endif /* __QCAMERA2HWI_MEM_H__ */

File diff suppressed because it is too large Load diff

286
QCamera2/HAL/QCameraMuxer.h Normal file
View file

@ -0,0 +1,286 @@
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __QCAMERAMUXER_H__
#define __QCAMERAMUXER_H__
#include "hardware/camera.h"
#include "QCamera2HWI.h"
#include "QCamera3HWI.h"
namespace qcamera {
/* Struct@ qcamera_physical_descriptor_t
*
* Description@ This structure specifies various attributes
* physical cameras enumerated on the device
*/
typedef struct {
// Userspace Physical Camera ID
uint32_t id;
// Server Camera ID
uint32_t camera_server_id;
// Device version
uint32_t device_version;
// Specifies type of camera
cam_sync_type_t type;
// Specifies mode of Camera
cam_sync_mode_t mode;
// Camera Info
camera_info cam_info;
// Reference to HWI
QCamera2HardwareInterface *hwi;
// Reference to camera device structure
camera_device_t* dev;
} qcamera_physical_descriptor_t;
/* Struct@ qcamera_logical_descriptor_t
*
* Description@ This structure stores information about logical cameras
* and corresponding data of the physical camera that are part of
* this logical camera
*/
typedef struct {
// Camera Device to be shared to Frameworks
camera_device_t dev;
// Device version
uint32_t device_version;
// Logical Camera ID
uint32_t id;
// Logical Camera Facing
int32_t facing;
// Number of Physical camera present in this logical camera
uint32_t numCameras;
// To signify if the LINK/UNLINK established between physical cameras
bool bSyncOn;
// index of the primary physical camera session in the bundle
uint8_t nPrimaryPhyCamIndex;
// Signifies Physical Camera ID of each camera
uint32_t pId[MAX_NUM_CAMERA_PER_BUNDLE];
// Signifies server camera ID of each camera
uint32_t sId[MAX_NUM_CAMERA_PER_BUNDLE];
// Signifies type of each camera
cam_sync_type_t type[MAX_NUM_CAMERA_PER_BUNDLE];
// Signifies mode of each camera
cam_sync_mode_t mode[MAX_NUM_CAMERA_PER_BUNDLE];
// Signifies mode of each 3a used by the camera
cam_3a_sync_mode_t sync_3a[MAX_NUM_CAMERA_PER_BUNDLE];
} qcamera_logical_descriptor_t;
/* Struct@ cam_compose_jpeg_info_t
*
* Description@ This structure stores information about individual Jpeg images
* received from multiple related physical camera instances. These images would then be
* composed together into a single MPO image later.
*/
typedef struct {
// msg_type is same as data callback msg_type
int32_t msg_type;
// ptr to actual data buffer
camera_memory_t *buffer;
// index of the buffer same as received in data callback
unsigned int index;
// metadata associated with the buffer
camera_frame_metadata_t *metadata;
// user contains the caller's identity
// this contains a reference to the physical cam structure
// of the HWI instance which had requested for this data buffer
void *user;
// this indicates validity of the buffer
// this flag is used by multiple threads to check validity of
// Jpegs received by other threads
bool valid;
// frame id of the Jpeg. this is needed for frame sync between aux
// and main camera sessions
uint32_t frame_idx;
// release callback function to release this Jpeg memory later after
// composition is completed
camera_release_callback release_cb;
// cookie for the release callback function
void *release_cookie;
// release data info for what needs to be released
void *release_data;
}cam_compose_jpeg_info_t;
/* Class@ QCameraMuxer
*
* Description@ Muxer interface
* a) Manages the grouping of the physical cameras into a logical camera
* b) Muxes the operational calls from Frameworks to HWI
* c) Composes MPO from JPEG
*/
class QCameraMuxer {
public:
/* Public Methods */
QCameraMuxer(uint32_t num_of_cameras);
virtual ~QCameraMuxer();
static void getCameraMuxer(QCameraMuxer** pCamMuxer,
uint32_t num_of_cameras);
static int get_number_of_cameras();
static int get_camera_info(int camera_id, struct camera_info *info);
static int set_callbacks(const camera_module_callbacks_t *callbacks);
static int open_legacy(const struct hw_module_t* module,
const char* id, uint32_t halVersion, struct hw_device_t** device);
static int camera_device_open(const struct hw_module_t* module,
const char* id,
struct hw_device_t** device);
static int close_camera_device( hw_device_t *);
/* Operation methods directly accessed by Camera Service */
static camera_device_ops_t mCameraMuxerOps;
/* Start of operational methods */
static int set_preview_window(struct camera_device *,
struct preview_stream_ops *window);
static void set_callBacks(struct camera_device *,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user);
static void enable_msg_type(struct camera_device *, int32_t msg_type);
static void disable_msg_type(struct camera_device *, int32_t msg_type);
static int msg_type_enabled(struct camera_device *, int32_t msg_type);
static int start_preview(struct camera_device *);
static void stop_preview(struct camera_device *);
static int preview_enabled(struct camera_device *);
static int store_meta_data_in_buffers(struct camera_device *,
int enable);
static int start_recording(struct camera_device *);
static void stop_recording(struct camera_device *);
static int recording_enabled(struct camera_device *);
static void release_recording_frame(struct camera_device *,
const void *opaque);
static int auto_focus(struct camera_device *);
static int cancel_auto_focus(struct camera_device *);
static int take_picture(struct camera_device *);
static int cancel_picture(struct camera_device *);
static int set_parameters(struct camera_device *, const char *parms);
static char* get_parameters(struct camera_device *);
static void put_parameters(struct camera_device *, char *);
static int send_command(struct camera_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
static void release(struct camera_device *);
static int dump(struct camera_device *, int fd);
/* End of operational methods */
static void jpeg_data_callback(int32_t msg_type,
const camera_memory_t *data, unsigned int index,
camera_frame_metadata_t *metadata, void *user,
uint32_t frame_idx, camera_release_callback release_cb,
void *release_cookie, void *release_data);
// add notify error msgs to the notifer queue of the primary related cam instance
static int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2);
// function to compose all JPEG images from all physical related camera instances
void composeMpo(cam_compose_jpeg_info_t* main_Jpeg,
cam_compose_jpeg_info_t* aux_Jpeg);
static void* composeMpoRoutine(void* data);
static bool matchFrameId(void *data, void *user_data, void *match_data);
static bool findPreviousJpegs(void *data, void *user_data, void *match_data);
static void releaseJpegInfo(void *data, void *user_data);
public:
/* Public Members Variables */
// Jpeg and Mpo ops need to be shared between 2 HWI instances
// hence these are cached in the muxer alongwith Jpeg handle
mm_jpeg_ops_t mJpegOps;
mm_jpeg_mpo_ops_t mJpegMpoOps;
uint32_t mJpegClientHandle;
// Stores Camera Data Callback function
camera_data_callback mDataCb;
// Stores Camera GetMemory Callback function
camera_request_memory mGetMemoryCb;
private:
/* Private Member Variables */
qcamera_physical_descriptor_t *m_pPhyCamera;
qcamera_logical_descriptor_t *m_pLogicalCamera;
const camera_module_callbacks_t *m_pCallbacks;
bool m_bAuxCameraExposed;
uint8_t m_nPhyCameras;
uint8_t m_nLogicalCameras;
// Main Camera session Jpeg Queue
QCameraQueue m_MainJpegQ;
// Aux Camera session Jpeg Queue
QCameraQueue m_AuxJpegQ;
// thread for mpo composition
QCameraCmdThread m_ComposeMpoTh;
// Final Mpo Jpeg Buffer
camera_memory_t *m_pRelCamMpoJpeg;
// Lock needed to synchronize between multiple composition requests
pthread_mutex_t m_JpegLock;
// this callback cookie would be used for sending Final mpo Jpeg to the framework
void *m_pMpoCallbackCookie;
// this callback cookie would be used for caching main related cam phy instance
// this is needed for error scenarios
// incase of error, we use this cookie to get HWI instance and send errors in notify cb
void *m_pJpegCallbackCookie;
// flag to indicate whether we need to dump dual camera snapshots
bool m_bDumpImages;
// flag to indicate whether MPO is enabled or not
bool m_bMpoEnabled;
// Signifies if frame sync is enabled
bool m_bFrameSyncEnabled;
// flag to indicate whether recording hint is internally set.
bool m_bRecordingHintInternallySet;
/* Private Member Methods */
int setupLogicalCameras();
int cameraDeviceOpen(int camera_id, struct hw_device_t **hw_device);
int getNumberOfCameras();
int getCameraInfo(int camera_id, struct camera_info *info,
cam_sync_type_t *p_cam_type);
int32_t setCallbacks(const camera_module_callbacks_t *callbacks);
int32_t setDataCallback(camera_data_callback data_cb);
int32_t setMemoryCallback(camera_request_memory get_memory);
qcamera_logical_descriptor_t* getLogicalCamera(
struct camera_device * device);
qcamera_physical_descriptor_t* getPhysicalCamera(
qcamera_logical_descriptor_t* log_cam, uint32_t index);
int32_t getActiveNumOfPhyCam(
qcamera_logical_descriptor_t* log_cam, int& numOfAcitvePhyCam);
int32_t setMpoCallbackCookie(void* mpoCbCookie);
void* getMpoCallbackCookie();
int32_t setMainJpegCallbackCookie(void* jpegCbCookie);
void* getMainJpegCallbackCookie();
void setJpegHandle(uint32_t handle) { mJpegClientHandle = handle;};
// function to store single JPEG from 1 related physical camera instance
int32_t storeJpeg(cam_sync_type_t cam_type, int32_t msg_type,
const camera_memory_t *data, unsigned int index,
camera_frame_metadata_t *metadata, void *user,
uint32_t frame_idx, camera_release_callback release_cb,
void *release_cookie, void *release_data);
};// End namespace qcamera
}
#endif /* __QCAMERAMUXER_H__ */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,350 @@
/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANDROID_HARDWARE_QCAMERA_PARAMETERS_INTF_H
#define ANDROID_HARDWARE_QCAMERA_PARAMETERS_INTF_H
#include <utils/String8.h>
#include <utils/Mutex.h>
#include "cam_intf.h"
#include "cam_types.h"
#include "QCameraThermalAdapter.h"
#include "QCameraFOVControl.h"
extern "C" {
#include <mm_camera_interface.h>
#include <mm_jpeg_interface.h>
}
using namespace android;
namespace qcamera {
typedef cam_manual_capture_type QCameraManualCaptureModes;
class QCameraAdjustFPS
{
public:
virtual int recalcFPSRange(int &minFPS, int &maxFPS,
const float &minVideoFPS, const float &maxVideoFPs,
cam_fps_range_t &adjustedRange, bool bRecordingHint) = 0;
virtual ~QCameraAdjustFPS() {}
};
class QCameraParameters;
class QCameraParametersIntf
{
public:
// member variables
QCameraParametersIntf();
~QCameraParametersIntf();
int32_t allocate(uint8_t bufCount = 1);
int32_t init(cam_capability_t *capabilities,
mm_camera_vtbl_t *mmOps,
QCameraAdjustFPS *adjustFPS,
QCameraFOVControl *fovControl);
void deinit();
int32_t updateParameters(const String8& params, bool &needRestart);
int32_t commitParameters();
char* getParameters();
void getPreviewFpsRange(int *min_fps, int *max_fps) const;
#ifdef TARGET_TS_MAKEUP
bool getTsMakeupInfo(int &whiteLevel, int &cleanLevel) const;
#endif
int getPreviewHalPixelFormat();
int32_t getStreamRotation(cam_stream_type_t streamType,
cam_pp_feature_config_t &featureConfig,
cam_dimension_t &dim);
int32_t getStreamFormat(cam_stream_type_t streamType,
cam_format_t &format);
int32_t getStreamSubFormat(
cam_stream_type_t streamType, cam_sub_format_type_t &sub_format);
int32_t getStreamDimension(cam_stream_type_t streamType,
cam_dimension_t &dim, uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
void getThumbnailSize(int *width, int *height) const;
uint8_t getSecureQueueDepth();
uint8_t getZSLBurstInterval();
uint8_t getZSLQueueDepth();
uint8_t getZSLBackLookCount();
uint8_t getMaxUnmatchedFramesInQueue();
bool isZSLMode();
bool isRdiMode();
bool isSecureMode();
cam_stream_secure_mode_t getSecureSessionType();
cam_stream_type_t getSecureStreamType();
bool isNoDisplayMode(uint32_t cam_type = CAM_TYPE_MAIN);
bool isWNREnabled();
bool isTNRSnapshotEnabled();
int32_t getCDSMode();
bool isLTMForSeeMoreEnabled();
bool isVideoFaceBeautification();
bool isHfrMode();
void getHfrFps(cam_fps_range_t &pFpsRange);
uint8_t getNumOfSnapshots();
uint8_t getNumOfRetroSnapshots();
uint8_t getNumOfExtraHDRInBufsIfNeeded();
uint8_t getNumOfExtraHDROutBufsIfNeeded();
uint8_t getNumOfExtraEISBufsIfNeeded();
bool getRecordingHintValue();
uint32_t getJpegQuality();
uint32_t getRotation();
uint32_t getDeviceRotation();
uint32_t getJpegExifRotation();
bool useJpegExifRotation();
int32_t getEffectValue();
bool isInstantAECEnabled();
bool isInstantCaptureEnabled();
uint8_t getAecFrameBoundValue();
uint8_t getAecSkipDisplayFrameBound();
int32_t getExifDateTime(String8 &dateTime, String8 &subsecTime);
int32_t getExifFocalLength(rat_t *focalLenght);
uint16_t getExifIsoSpeed();
int32_t getExifGpsProcessingMethod(char *gpsProcessingMethod,
uint32_t &count);
int32_t getExifLatitude(rat_t *latitude, char *latRef);
int32_t getExifLongitude(rat_t *longitude, char *lonRef);
int32_t getExifAltitude(rat_t *altitude, char *altRef);
int32_t getExifGpsDateTimeStamp(char *gpsDateStamp,
uint32_t bufLen, rat_t *gpsTimeStamp);
bool isVideoBuffersCached();
int32_t updateFocusDistances(cam_focus_distances_info_t *focusDistances);
bool isAEBracketEnabled();
int32_t setAEBracketing();
bool isFpsDebugEnabled();
bool isHistogramEnabled();
bool isSceneSelectionEnabled();
bool isSmallJpegSizeEnabled();
int32_t setSelectedScene(cam_scene_mode_type scene);
cam_scene_mode_type getSelectedScene();
bool isFaceDetectionEnabled();
int32_t setFaceDetectionOption(bool enabled);
int32_t setHistogram(bool enabled);
int32_t setFaceDetection(bool enabled, bool initCommit);
int32_t setFrameSkip(enum msm_vfe_frame_skip_pattern pattern);
qcamera_thermal_mode getThermalMode();
int32_t updateRecordingHintValue(int32_t value);
int32_t updateCaptureRequest(uint8_t value);
int32_t setHDRAEBracket(cam_exp_bracketing_t hdrBracket);
bool isHDREnabled();
bool isAutoHDREnabled();
int32_t stopAEBracket();
int32_t updateRAW(cam_dimension_t max_dim);
bool isDISEnabled();
bool isAVTimerEnabled();
int32_t setISType();
cam_is_type_t getVideoISType();
cam_is_type_t getPreviewISType();
uint8_t getMobicatMask();
cam_focus_mode_type getFocusMode() const;
int32_t setNumOfSnapshot();
int32_t adjustPreviewFpsRange(cam_fps_range_t *fpsRange);
bool isJpegPictureFormat();
bool isNV16PictureFormat();
bool isNV21PictureFormat();
cam_denoise_process_type_t getDenoiseProcessPlate(cam_intf_parm_type_t type);
int32_t getMaxPicSize(cam_dimension_t &dim);
int getFlipMode(cam_stream_type_t streamType);
bool isSnapshotFDNeeded();
bool isHDR1xFrameEnabled();
bool isYUVFrameInfoNeeded();
const char*getFrameFmtString(cam_format_t fmt);
bool isHDR1xExtraBufferNeeded();
bool isHDROutputCropEnabled();
bool isPreviewFlipChanged();
bool isVideoFlipChanged();
bool isSnapshotFlipChanged();
bool isZoomChanged();
void setHDRSceneEnable(bool bflag);
int32_t updateAWBParams(cam_awb_params_t &awb_params);
const char *getASDStateString(cam_auto_scene_t scene);
bool isHDRThumbnailProcessNeeded();
void setMinPpMask(cam_feature_mask_t min_pp_mask);
bool setStreamConfigure(bool isCapture,
bool previewAsPostview, bool resetConfig);
int32_t addOnlineRotation(uint32_t rotation, uint32_t streamId,
int32_t device_rotation);
uint8_t getNumOfExtraBuffersForImageProc();
uint8_t getNumOfExtraBuffersForVideo();
uint8_t getNumOfExtraBuffersForPreview();
uint32_t getExifBufIndex(uint32_t captureIndex);
bool needThumbnailReprocess(cam_feature_mask_t *pFeatureMask);
bool isUbiFocusEnabled();
bool isChromaFlashEnabled();
bool isHighQualityNoiseReductionMode();
bool isTruePortraitEnabled();
size_t getTPMaxMetaSize();
bool isSeeMoreEnabled();
bool isStillMoreEnabled();
bool isOptiZoomEnabled();
int32_t commitAFBracket(cam_af_bracketing_t afBracket);
int32_t set3ALock(bool lock3A);
int32_t setAndCommitZoom(int zoom_level);
uint8_t getBurstCountForAdvancedCapture();
uint32_t getNumberInBufsForSingleShot();
uint32_t getNumberOutBufsForSingleShot();
int32_t setLongshotEnable(bool enable);
String8 dump();
bool isUbiRefocus();
uint32_t getRefocusMaxMetaSize();
uint8_t getRefocusOutputCount();
bool generateThumbFromMain();
void updateCurrentFocusPosition(cam_focus_pos_info_t &cur_pos_info);
void updateAEInfo(cam_3a_params_t &ae_params);
bool isDisplayFrameNeeded();
bool isAdvCamFeaturesEnabled();
int32_t setAecLock(const char *aecStr);
int32_t updateDebugLevel();
bool is4k2kVideoResolution();
bool isUBWCEnabled();
int getBrightness();
int32_t updateOisMode(cam_ois_mode_t oisMode);
int32_t setIntEvent(cam_int_evt_params_t params);
bool getofflineRAW();
bool getQuadraCfa();
int32_t updatePpFeatureMask(cam_stream_type_t stream_type);
int32_t getStreamPpMask(cam_stream_type_t stream_type, cam_feature_mask_t &pp_mask);
int32_t getSharpness();
int32_t getEffect();
int32_t updateFlashMode(cam_flash_mode_t flash_mode);
int32_t configureAEBracketing(cam_capture_frame_config_t &frame_config);
int32_t configureHDRBracketing(cam_capture_frame_config_t &frame_config);
int32_t configFrameCapture(bool commitSettings);
int32_t resetFrameCapture(bool commitSettings, bool lowLightEnabled);
cam_still_more_t getStillMoreSettings();
void setStillMoreSettings(cam_still_more_t stillmore_config);
cam_still_more_t getStillMoreCapability();
cam_dyn_img_data_t getDynamicImgData();
void setDynamicImgData(cam_dyn_img_data_t d);
int32_t getParmZoomLevel();
int8_t getReprocCount();
int8_t getCurPPCount();
void setReprocCount();
bool isPostProcScaling();
bool isLLNoiseEnabled();
void setCurPPCount(int8_t count);
int32_t setQuadraCfaMode(uint32_t value, bool initCommit);
int32_t setRawCaptureMode(uint32_t value);
bool getRawZsl();
bool getRawZslCapture();
int32_t setToneMapMode(uint32_t value, bool initCommit);
void setTintless(bool enable);
uint8_t getLongshotStages();
int8_t getBufBatchCount();
int8_t getVideoBatchSize();
int32_t setManualCaptureMode(
QCameraManualCaptureModes value = CAM_MANUAL_CAPTURE_TYPE_OFF);
QCameraManualCaptureModes getManualCaptureMode();
int64_t getExposureTime();
cam_capture_frame_config_t getCaptureFrameConfig();
void setJpegRotation(int rotation);
uint32_t getJpegRotation();
void setLowLightLevel(cam_low_light_mode_t value);
cam_low_light_mode_t getLowLightLevel();
bool getLowLightCapture();
bool isLinkPreviewForLiveShot();
/* Dual camera specific */
bool getDcrf();
int32_t setRelatedCamSyncInfo(
cam_sync_related_sensors_event_info_t* info);
const cam_sync_related_sensors_event_info_t*
getRelatedCamSyncInfo(void);
int32_t setFrameSyncEnabled(bool enable);
bool isFrameSyncEnabled(void);
int32_t getRelatedCamCalibration(
cam_related_system_calibration_data_t* calib);
int32_t bundleRelatedCameras(bool sync);
uint8_t fdModeInVideo();
bool isOEMFeatEnabled();
uint8_t isOEMFeatFrameSkipEnabled();
int32_t setZslMode(bool value);
int32_t updateZSLModeValue(bool value);
bool isReprocScaleEnabled();
bool isUnderReprocScaling();
int32_t getPicSizeFromAPK(int &width, int &height);
int32_t checkFeatureConcurrency();
int32_t setInstantAEC(uint8_t enable, bool initCommit);
int32_t getAnalysisInfo(
bool fdVideoEnabled,
cam_feature_mask_t featureMask,
cam_analysis_info_t *pAnalysisInfo);
int32_t updateDtVc(int32_t *dt, int32_t *vc);
bool needSnapshotPP();
int32_t SetDualCamera(bool value);
cam_hal_pp_type_t getHalPPType();
int32_t setCameraControls(uint32_t controls, bool bundleSnap, cam_fallback_mode_t fallbackMode);
int32_t setSwitchCamera(uint32_t camMaster);
int32_t setDCDeferCamera(cam_dual_camera_defer_cmd_t type);
int32_t getDualLedCalibration();
bool isDCmAsymmetricSnapMode();
bool isDCAsymmetricPrevMode ();
int32_t setDCLowPowerMode(uint32_t state);
void initDCSettings(int32_t state, uint32_t camMaster,
bool bundleSnapshot, cam_fallback_mode_t fallbackMode);
bool needAnalysisStream();
void setLowPower(bool value);
uint32_t getBlurLevel();
void setBokehSnaphot(bool enable);
void getDepthMapSize(int &width, int &height);
bool isAutoFocusSupported(uint32_t cam_type);
private:
QCameraParameters *mImpl;
mutable Mutex mLock;
};
}; // namespace qcamera
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,272 @@
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_POSTPROC_H__
#define __QCAMERA_POSTPROC_H__
// Camera dependencies
#include "QCamera2HWI.h"
#include "QCameraPprocManager.h"
extern "C" {
#include "mm_camera_interface.h"
#include "mm_jpeg_interface.h"
}
#define MAX_JPEG_BURST 2
#define HAL_PP_NUM_BUFS 2
#define CAM_PP_CHANNEL_MAX 8
namespace qcamera {
class QCameraExif;
class QCamera2HardwareInterface;
class QCameraHALPPManager;
typedef struct {
uint32_t jobId; // job ID
uint32_t client_hdl; // handle of jpeg client (obtained when open jpeg)
mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel
//after done)
mm_camera_super_buf_t *src_reproc_frame; // original source
//frame for reproc if not NULL
metadata_buffer_t *metadata; // source frame metadata
bool reproc_frame_release; // false release original buffer, true don't release it
mm_camera_buf_def_t *src_reproc_bufs;
QCameraExif *pJpegExifObj;
uint8_t offline_buffer;
mm_camera_buf_def_t *offline_reproc_buf; //HAL processed buffer
bool halPPAllocatedBuf; // true if src frame buffer is allocated by HAL PP block
mm_camera_buf_def_t *hal_pp_bufs; // bufs allocates for HAL PP
QCameraHeapMemory *snapshot_heap; // heap memory of snapshot buffer
QCameraHeapMemory *metadata_heap; // heap memory of metadata buffer
} qcamera_jpeg_data_t;
typedef struct {
int8_t reprocCount;
mm_camera_super_buf_t *src_frame; // source frame that needs post process
mm_camera_super_buf_t *src_reproc_frame;// source frame (need to be
//returned back to kernel after done)
}qcamera_pp_request_t;
typedef struct {
uint32_t jobId; // job ID
int8_t reprocCount; //Current pass count
int8_t ppChannelIndex; //Reprocess channel object index
mm_camera_super_buf_t *src_frame;// source frame
bool reproc_frame_release; // false release original buffer
// true don't release it
mm_camera_buf_def_t *src_reproc_bufs;
mm_camera_super_buf_t *src_reproc_frame;// source frame (need to be
//returned back to kernel after done)
uint8_t offline_buffer;
mm_camera_buf_def_t *offline_reproc_buf; //HAL processed buffer
} qcamera_pp_data_t;
typedef struct {
uint32_t jobId; // job ID (obtained when start_jpeg_job)
jpeg_job_status_t status; // jpeg encoding status
mm_jpeg_output_t out_data; // ptr to jpeg output buf
} qcamera_jpeg_evt_payload_t;
typedef struct {
camera_memory_t * data; // ptr to data memory struct
mm_camera_super_buf_t * frame; // ptr to frame
QCameraMemory * streamBufs; //ptr to stream buffers
bool unlinkFile; // unlink any stored buffers on error
} qcamera_release_data_t;
typedef struct {
int32_t msg_type; // msg type of data notify
camera_memory_t * data; // ptr to data memory struct
unsigned int index; // index of the buf in the whole buffer
camera_frame_metadata_t *metadata; // ptr to meta data
qcamera_release_data_t release_data; // any data needs to be release after notify
} qcamera_data_argm_t;
#define MAX_EXIF_TABLE_ENTRIES 50
class QCameraExif
{
public:
QCameraExif();
virtual ~QCameraExif();
int32_t addEntry(exif_tag_id_t tagid,
exif_tag_type_t type,
uint32_t count,
void *data);
uint32_t getNumOfEntries() {return m_nNumEntries;};
QEXIF_INFO_DATA *getEntries() {return m_Entries;};
private:
QEXIF_INFO_DATA m_Entries[MAX_EXIF_TABLE_ENTRIES]; // exif tags for JPEG encoder
uint32_t m_nNumEntries; // number of valid entries
};
class QCameraPostProcessor
{
public:
QCameraPostProcessor(QCamera2HardwareInterface *cam_ctrl);
virtual ~QCameraPostProcessor();
int32_t init(jpeg_encode_callback_t jpeg_cb, void *user_data);
int32_t deinit();
int32_t start(QCameraChannel *pSrcChannel);
int32_t stop();
bool validatePostProcess(mm_camera_super_buf_t *frame);
int32_t processData(mm_camera_super_buf_t *frame);
int32_t processRawData(mm_camera_super_buf_t *frame);
int32_t processPPData(mm_camera_super_buf_t *frame);
int32_t processJpegEvt(qcamera_jpeg_evt_payload_t *evt);
int32_t getJpegPaddingReq(cam_padding_info_t &padding_info);
QCameraReprocessChannel * getReprocChannel(uint8_t index);
inline bool getJpegMemOpt() {return mJpegMemOpt;}
inline void setJpegMemOpt(bool val) {mJpegMemOpt = val;}
int32_t setJpegHandle(mm_jpeg_ops_t *pJpegHandle,
mm_jpeg_mpo_ops_t* pJpegMpoHandle, uint32_t clientHandle);
int32_t createJpegSession(QCameraChannel *pSrcChannel);
int8_t getPPChannelCount() {return mPPChannelCount;};
mm_camera_buf_def_t *getOfflinePPInputBuffer(
mm_camera_super_buf_t *src_frame);
static void processHalPPDataCB(qcamera_hal_pp_data_t *pOutput, void* pUserData);
static void getHalPPOutputBufferCB(uint32_t frameIndex, void* pUserData);
static void releaseSuperBuf(mm_camera_super_buf_t *super_buf, void* pUserData);
QCameraMemory *mOfflineDataBufs;
QCameraChannel *getChannelByHandle(uint32_t channelHandle);
bool isHalPPEnabled() { return (m_pHalPPManager != NULL);}
void releaseSuperBuf(mm_camera_super_buf_t *super_buf);
QCamera2HardwareInterface *m_parent;
private:
int32_t sendDataNotify(int32_t msg_type,
camera_memory_t *data,
uint8_t index,
camera_frame_metadata_t *metadata,
qcamera_release_data_t *release_data,
uint32_t super_buf_frame_idx = 0);
int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2);
qcamera_jpeg_data_t *findJpegJobByJobId(uint32_t jobId);
mm_jpeg_color_format getColorfmtFromImgFmt(cam_format_t img_fmt);
mm_jpeg_format_t getJpegImgTypeFromImgFmt(cam_format_t img_fmt);
int32_t getJpegEncodingConfig(mm_jpeg_encode_params_t& encode_parm,
QCameraStream *main_stream,
QCameraStream *thumb_stream,
const mm_camera_super_buf_t *halpp_out_buf = NULL);
int32_t encodeData(qcamera_jpeg_data_t *jpeg_job_data,
uint8_t &needNewSess);
int32_t queryStreams(QCameraStream **main,
QCameraStream **thumb,
QCameraStream **reproc,
mm_camera_buf_def_t **main_image,
mm_camera_buf_def_t **thumb_image,
mm_camera_super_buf_t *main_frame,
mm_camera_super_buf_t *reproc_frame);
int32_t syncStreamParams(mm_camera_super_buf_t *frame,
mm_camera_super_buf_t *reproc_frame);
void releaseSuperBuf(mm_camera_super_buf_t *super_buf,
cam_stream_type_t stream_type);
static void releaseNotifyData(void *user_data,
void *cookie,
int32_t cb_status);
void releaseJpegJobData(qcamera_jpeg_data_t *job);
static void releaseSaveJobData(void *data, void *user_data);
static void releaseRawData(void *data, void *user_data);
int32_t processRawImageImpl(mm_camera_super_buf_t *recvd_frame);
static void releaseJpegData(void *data, void *user_data);
static void releasePPInputData(void *data, void *user_data);
static void releaseOngoingPPData(void *data, void *user_data);
static void *dataProcessRoutine(void *data);
static void *dataSaveRoutine(void *data);
int32_t setYUVFrameInfo(mm_camera_super_buf_t *recvd_frame);
static bool matchJobId(void *data, void *user_data, void *match_data);
static int getJpegMemory(omx_jpeg_ouput_buf_t *out_buf);
static int releaseJpegMemory(omx_jpeg_ouput_buf_t *out_buf);
int32_t processHalPPData(qcamera_hal_pp_data_t *pData);
void getHalPPOutputBuffer(uint32_t frameIndex);
int32_t doReprocess();
int32_t stopCapture();
void createHalPPManager();
int32_t initHalPPManager();
private:
jpeg_encode_callback_t mJpegCB;
void * mJpegUserData;
mm_jpeg_ops_t mJpegHandle;
mm_jpeg_mpo_ops_t mJpegMpoHandle; // handle for mpo composition for dualcam
uint32_t mJpegClientHandle;
uint32_t mJpegSessionId;
uint32_t mJpegSessionIdHalPP;
void * m_pJpegOutputMem[MM_JPEG_MAX_BUF];
void * m_pJpegOutputMemHalPP[MM_JPEG_MAX_BUF];
QCameraExif * m_pJpegExifObj;
uint32_t m_bThumbnailNeeded;
int8_t mPPChannelCount;
QCameraReprocessChannel *mPPChannels[CAM_PP_CHANNEL_MAX];
camera_memory_t * m_DataMem; // save frame mem pointer
int8_t m_bInited; // if postproc is inited
QCameraQueue m_inputPPQ; // input queue for postproc
QCameraQueue m_ongoingPPQ; // ongoing postproc queue
QCameraQueue m_inputJpegQ; // input jpeg job queue
QCameraQueue m_ongoingJpegQ; // ongoing jpeg job queue
QCameraQueue m_inputRawQ; // input raw job queue
QCameraQueue m_inputSaveQ; // input save job queue
QCameraCmdThread m_dataProcTh; // thread for data processing
QCameraCmdThread m_saveProcTh; // thread for storing buffers
uint32_t mSaveFrmCnt; // save frame counter
static const char *STORE_LOCATION; // path for storing buffers
bool mUseSaveProc; // use store thread
bool mUseJpegBurst; // use jpeg burst encoding mode
bool mUseJpegBurstHalPP;
bool mJpegMemOpt;
uint32_t m_JpegOutputMemCount;
uint32_t m_JpegOutputMemCountHALPP;
QCameraStream *pJpegSrcStream;
uint8_t mNewJpegSessionNeeded;
uint8_t mNewJpegSessionNeededHalPP;
int32_t m_bufCountPPQ;
Vector<mm_camera_buf_def_t *> m_InputMetadata; // store input metadata buffers for AOST cases
size_t m_PPindex; // counter for each incoming AOST buffer
pthread_mutex_t m_reprocess_lock; // lock to ensure reprocess job is not freed early.
QCameraHALPPManager *m_pHalPPManager; // HAL Post process block
public:
cam_dimension_t m_dst_dim;
};
}; // namespace qcamera
#endif /* __QCAMERA_POSTPROC_H__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,269 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_STATEMACHINE_H__
#define __QCAMERA_STATEMACHINE_H__
// System dependencies
#include <pthread.h>
// Camera dependencies
#include "QCameraQueue.h"
#include "QCameraChannel.h"
#include "cam_semaphore.h"
extern "C" {
#include "mm_camera_interface.h"
}
namespace qcamera {
class QCamera2HardwareInterface;
typedef enum {
/*******BEGIN OF: API EVT*********/
QCAMERA_SM_EVT_SET_PREVIEW_WINDOW = 1, // set preview window
QCAMERA_SM_EVT_SET_CALLBACKS, // set callbacks
QCAMERA_SM_EVT_ENABLE_MSG_TYPE, // enable msg type
QCAMERA_SM_EVT_DISABLE_MSG_TYPE, // disable msg type
QCAMERA_SM_EVT_MSG_TYPE_ENABLED, // query certain msg type is enabled
QCAMERA_SM_EVT_SET_PARAMS, // set parameters
QCAMERA_SM_EVT_SET_PARAMS_STOP, // stop camera after set params, if necessary
QCAMERA_SM_EVT_SET_PARAMS_COMMIT, // commit set params
QCAMERA_SM_EVT_SET_PARAMS_RESTART, // restart after set params, if necessary
QCAMERA_SM_EVT_GET_PARAMS, // get parameters
QCAMERA_SM_EVT_PUT_PARAMS, // put parameters, release param buf
QCAMERA_SM_EVT_PREPARE_PREVIEW, // prepare preview (zsl, camera mode, camcorder mode)
QCAMERA_SM_EVT_START_PREVIEW, // start preview (zsl, camera mode, camcorder mode)
QCAMERA_SM_EVT_START_NODISPLAY_PREVIEW, // start no display preview (zsl, camera mode, camcorder mode)
QCAMERA_SM_EVT_STOP_PREVIEW, // stop preview (zsl, camera mode, camcorder mode)
QCAMERA_SM_EVT_PREVIEW_ENABLED, // query if preview is running
QCAMERA_SM_EVT_STORE_METADATA_IN_BUFS, // request to store meta data in video buffers
QCAMERA_SM_EVT_PRE_START_RECORDING, // pre start recording, to prepare for recording
QCAMERA_SM_EVT_START_RECORDING, // start recording
QCAMERA_SM_EVT_STOP_RECORDING, // stop recording
QCAMERA_SM_EVT_RECORDING_ENABLED, // query if recording is running
QCAMERA_SM_EVT_RELEASE_RECORIDNG_FRAME, // release recording frame
QCAMERA_SM_EVT_PREPARE_SNAPSHOT, // prepare snapshot in case LED needs to be flashed
QCAMERA_SM_EVT_PRE_TAKE_PICTURE, // pre take picutre (to restart preview if necessary)
QCAMERA_SM_EVT_TAKE_PICTURE, // take picutre (zsl, regualr capture, live snapshot
QCAMERA_SM_EVT_CANCEL_PICTURE, // cancel picture
QCAMERA_SM_EVT_START_AUTO_FOCUS, // start auto focus
QCAMERA_SM_EVT_STOP_AUTO_FOCUS, // stop auto focus
QCAMERA_SM_EVT_SEND_COMMAND, // send command
QCAMERA_SM_EVT_RELEASE, // release camera resource
QCAMERA_SM_EVT_DUMP, // dump
QCAMERA_SM_EVT_REG_FACE_IMAGE, // register a face image in imaging lib
/*******END OF: API EVT*********/
QCAMERA_SM_EVT_EVT_INTERNAL, // internal evt notify
QCAMERA_SM_EVT_EVT_NOTIFY, // evt notify from server
QCAMERA_SM_EVT_JPEG_EVT_NOTIFY, // evt notify from jpeg
QCAMERA_SM_EVT_SNAPSHOT_DONE, // internal evt that snapshot is done
QCAMERA_SM_EVT_THERMAL_NOTIFY, // evt notify from thermal daemon
QCAMERA_SM_EVT_STOP_CAPTURE_CHANNEL, // stop capture channel
QCAMERA_SM_EVT_RESTART_PERVIEW, // internal preview restart
QCAMERA_SM_EVT_DELAYED_RESTART, // preview restart needs delay (dual camera mode)
QCAMERA_SM_EVT_SEND_COMMAND_RESTART, // restart after send command (if necessary)
QCAMERA_SM_EVT_RESTART_START_PREVIEW, // preview start as part of restart (dual camera mode)
QCAMERA_SM_EVT_RESTART_STOP_PREVIEW, // preview stop as part of restart (dual camera mode)
QCAMERA_SM_EVT_MAX
} qcamera_sm_evt_enum_t;
typedef enum {
QCAMERA_API_RESULT_TYPE_DEF, // default type, no additional info
QCAMERA_API_RESULT_TYPE_ENABLE_FLAG, // msg_enabled, preview_enabled, recording_enabled
QCAMERA_API_RESULT_TYPE_PARAMS, // returned parameters in string
QCAMERA_API_RESULT_TYPE_HANDLE, // returned handle in int
QCAMERA_API_RESULT_TYPE_MAX
} qcamera_api_result_type_t;
typedef struct {
int32_t status; // api call status
qcamera_sm_evt_enum_t request_api; // api evt requested
qcamera_api_result_type_t result_type; // result type
union {
int enabled; // result_type == QCAMERA_API_RESULT_TYPE_ENABLE_FLAG
char *params; // result_type == QCAMERA_API_RESULT_TYPE_PARAMS
int handle; // result_type ==QCAMERA_API_RESULT_TYPE_HANDLE
};
} qcamera_api_result_t;
typedef struct api_result_list {
qcamera_api_result_t result;
struct api_result_list *next;
}api_result_list;
// definition for payload type of setting callback
typedef struct {
camera_notify_callback notify_cb;
camera_data_callback data_cb;
camera_data_timestamp_callback data_cb_timestamp;
camera_request_memory get_memory;
void *user;
} qcamera_sm_evt_setcb_payload_t;
// definition for payload type of sending command
typedef struct {
int32_t cmd;
int32_t arg1;
int32_t arg2;
} qcamera_sm_evt_command_payload_t;
// definition for payload type of sending command
typedef struct {
void *img_ptr;
cam_pp_offline_src_config_t *config;
} qcamera_sm_evt_reg_face_payload_t;
typedef enum {
QCAMERA_INTERNAL_EVT_FOCUS_UPDATE, // focus updating result
QCAMERA_INTERNAL_EVT_PREP_SNAPSHOT_DONE, // prepare snapshot done
QCAMERA_INTERNAL_EVT_FACE_DETECT_RESULT, // face detection result
QCAMERA_INTERNAL_EVT_HISTOGRAM_STATS, // histogram
QCAMERA_INTERNAL_EVT_CROP_INFO, // crop info
QCAMERA_INTERNAL_EVT_ASD_UPDATE, // asd update result
QCAMERA_INTERNAL_EVT_READY_FOR_SNAPSHOT, // Ready for Prepare Snapshot
QCAMERA_INTERNAL_EVT_LED_MODE_OVERRIDE, // Led mode override
QCAMERA_INTERNAL_EVT_AWB_UPDATE, // awb update result
QCAMERA_INTERNAL_EVT_AE_UPDATE, // ae update result
QCAMERA_INTERNAL_EVT_FOCUS_POS_UPDATE, // focus position update result
QCAMERA_INTERNAL_EVT_HDR_UPDATE, // HDR scene update
QCAMERA_INTERNAL_EVT_RETRO_AEC_UNLOCK, // retro burst AEC unlock event
QCAMERA_INTERNAL_EVT_ZSL_CAPTURE_DONE, // ZSL capture done event
QCAMERA_INTERNAL_EVT_DUAL_CAMERA_FOV_CONTROL, // FOV Control event
QCAMERA_INTERNAL_EVT_LED_CALIB_UPDATE, //LED calibration result update
QCAMERA_INTERNAL_EVT_RTB_METADATA, //RTB Metadata
QCAMERA_INTERNAL_EVT_MAX
} qcamera_internal_evt_type_t;
typedef struct {
qcamera_internal_evt_type_t evt_type;
union {
cam_auto_focus_data_t focus_data;
cam_prep_snapshot_state_t prep_snapshot_state;
cam_faces_data_t faces_data;
cam_hist_stats_t stats_data;
cam_crop_data_t crop_data;
cam_asd_decision_t asd_data;
cam_flash_mode_t led_data;
cam_awb_params_t awb_data;
cam_3a_params_t ae_data;
cam_focus_pos_info_t focus_pos;
cam_asd_hdr_scene_data_t hdr_data;
int32_t led_calib_result;
cam_rtb_msg_type_t rtb_data;
};
} qcamera_sm_internal_evt_payload_t;
class QCameraStateMachine
{
public:
QCameraStateMachine(QCamera2HardwareInterface *ctrl);
virtual ~QCameraStateMachine();
int32_t procAPI(qcamera_sm_evt_enum_t evt, void *api_payload);
int32_t procEvt(qcamera_sm_evt_enum_t evt, void *evt_payload);
bool isPreviewRunning(); // check if preview is running
bool isPreviewReady(); // check if preview is ready
bool isCaptureRunning(); // check if image capture is running
bool isNonZSLCaptureRunning(); // check if image capture is running in non ZSL mode
String8 dump(); //returns the state information in a string
bool isPrepSnapStateRunning();
bool isRecording();
void releaseThread();
bool isPreviewCallbackNeeded() { return m_bPreviewCallbackNeeded; };
int32_t setPreviewCallbackNeeded(bool enabled) {m_bPreviewCallbackNeeded=enabled; return 0;};
private:
typedef enum {
QCAMERA_SM_STATE_PREVIEW_STOPPED, // preview is stopped
QCAMERA_SM_STATE_PREVIEW_READY, // preview started but preview window is not set yet
QCAMERA_SM_STATE_PREVIEWING, // previewing
QCAMERA_SM_STATE_PREPARE_SNAPSHOT, // prepare snapshot in case aec estimation is
// needed for LED flash
QCAMERA_SM_STATE_PIC_TAKING, // taking picture (preview stopped)
QCAMERA_SM_STATE_RECORDING, // recording (preview running)
QCAMERA_SM_STATE_VIDEO_PIC_TAKING, // taking live snapshot during recording (preview running)
QCAMERA_SM_STATE_PREVIEW_PIC_TAKING // taking ZSL/live snapshot (recording stopped but preview running)
} qcamera_state_enum_t;
typedef enum
{
QCAMERA_SM_CMD_TYPE_API, // cmd from API
QCAMERA_SM_CMD_TYPE_EVT, // cmd from mm-camera-interface/mm-jpeg-interface event
QCAMERA_SM_CMD_TYPE_EXIT, // cmd for exiting statemachine cmdThread
QCAMERA_SM_CMD_TYPE_MAX
} qcamera_sm_cmd_type_t;
typedef struct {
qcamera_sm_cmd_type_t cmd; // cmd type (where it comes from)
qcamera_sm_evt_enum_t evt; // event type
void *evt_payload; // ptr to payload
} qcamera_sm_cmd_t;
int32_t stateMachine(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtPreviewStoppedState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtPreviewReadyState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtPreviewingState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtPrepareSnapshotState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtPicTakingState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtRecordingState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtVideoPicTakingState(qcamera_sm_evt_enum_t evt, void *payload);
int32_t procEvtPreviewPicTakingState(qcamera_sm_evt_enum_t evt, void *payload);
// main statemachine process routine
static void *smEvtProcRoutine(void *data);
int32_t applyDelayedMsgs();
QCamera2HardwareInterface *m_parent; // ptr to HWI
qcamera_state_enum_t m_state; // statemachine state
QCameraQueue api_queue; // cmd queue for APIs
QCameraQueue evt_queue; // cmd queue for evt from mm-camera-intf/mm-jpeg-intf
pthread_t cmd_pid; // cmd thread ID
cam_semaphore_t cmd_sem; // semaphore for cmd thread
bool m_bDelayPreviewMsgs; // Delay preview callback enable during ZSL snapshot
bool m_bPreviewNeedsRestart; // Preview needs restart
bool m_bPreviewDelayedRestart; // Preview delayed restart
int32_t m_DelayedMsgs;
bool m_RestoreZSL;
bool m_bPreviewCallbackNeeded;
bool m_bPreviewRestartedInternal;
};
}; // namespace qcamera
#endif /* __QCAMERA_STATEMACHINE_H__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,291 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_STREAM_H__
#define __QCAMERA_STREAM_H__
// Camera dependencies
#include "hardware/camera.h"
#include "QCameraCmdThread.h"
#include "QCameraMem.h"
#include "QCameraAllocator.h"
extern "C" {
#include "mm_camera_interface.h"
}
namespace qcamera {
class QCameraStream;
typedef void (*stream_cb_routine)(mm_camera_super_buf_t *frame,
QCameraStream *stream,
void *userdata);
#define CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE 16
#define CAMERA_MIN_VIDEO_BATCH_BUFFERS 3
class QCameraStream
{
public:
QCameraStream(QCameraAllocator &allocator,
uint32_t camHandle, uint32_t chId,
mm_camera_ops_t *camOps, cam_padding_info_t *paddingInfo,
bool deffered = false, cam_rotation_t online_rotation = ROTATE_0);
virtual ~QCameraStream();
virtual int32_t init(QCameraHeapMemory *streamInfoBuf,
QCameraHeapMemory *miscBuf,
stream_cb_routine stream_cb,
void *userdata,
bool bDynallocBuf);
virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow,
cam_crop_data_t &crop_info);
virtual int32_t bufDone(uint32_t index);
virtual int32_t bufDone(const void *opaque, bool isMetaData);
virtual int32_t bufDone(const void *opaque, bool isMetaData, QCameraVideoMemory *videoMem);
virtual int32_t bufDone(mm_camera_super_buf_t *super_buf);
virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs);
virtual int32_t start();
virtual int32_t stop();
/* Used for deffered allocation of buffers */
virtual int32_t allocateBuffers();
virtual int32_t mapBuffers();
virtual int32_t releaseBuffs();
static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata);
static void dataNotifySYNCCB(mm_camera_super_buf_t *recvd_frame,
void *userdata);
static void *dataProcRoutine(void *data);
static void *BufAllocRoutine(void *data);
uint32_t getMyHandle() const {return mHandle;}
bool isTypeOf(cam_stream_type_t type);
bool isOrignalTypeOf(cam_stream_type_t type);
int32_t getFrameOffset(cam_frame_len_offset_t &offset);
int32_t getCropInfo(cam_rect_t &crop);
int32_t setCropInfo(cam_rect_t crop);
int32_t getFrameDimension(cam_dimension_t &dim);
int32_t getFormat(cam_format_t &fmt);
QCameraMemory *getStreamBufs() {return mStreamBufs;};
QCameraHeapMemory *getStreamInfoBuf() {return mStreamInfoBuf;};
QCameraHeapMemory *getMiscBuf() {return mMiscBuf;};
uint32_t getMyServerID();
cam_stream_type_t getMyType();
bool isStreamSyncCbNeeded();
cam_stream_type_t getMyOriginalType();
int32_t acquireStreamBufs();
int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx,
int32_t plane_idx, int fd, void *buffer, size_t size,
mm_camera_map_unmap_ops_tbl_t *ops_tbl = NULL);
int32_t mapBufs(cam_buf_map_type_list bufMapList,
mm_camera_map_unmap_ops_tbl_t *ops_tbl = NULL);
int32_t mapNewBuffer(uint32_t index);
int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx,
mm_camera_map_unmap_ops_tbl_t *ops_tbl = NULL);
int32_t setParameter(cam_stream_parm_buffer_t &param);
int32_t getParameter(cam_stream_parm_buffer_t &param);
int32_t syncRuntimeParams();
cam_stream_parm_buffer_t getOutputCrop() { return m_OutputCrop;};
cam_stream_parm_buffer_t getImgProp() { return m_ImgProp;};
static void releaseFrameData(void *data, void *user_data);
int32_t configStream();
bool isDeffered() const { return mDefferedAllocation; }
bool isSyncCBEnabled() {return mSyncCBEnabled;};
void deleteStream();
uint8_t getBufferCount() { return mNumBufs; }
uint32_t getChannelHandle() { return mChannelHandle; }
int32_t getNumQueuedBuf();
mm_camera_buf_def_t *getBuffer(int32_t index);
uint32_t mDumpFrame;
uint32_t mDumpMetaFrame;
uint32_t mDumpSkipCnt;
void cond_wait();
void cond_signal(bool forceExit = false);
void initDCSettings(int32_t state, uint32_t camMaster);
int32_t setSyncDataCB(stream_cb_routine data_cb);
int32_t setBundleInfo();
int32_t switchStreamCb(uint32_t camMaster);
int32_t processCameraControl(uint32_t camState);
bool isDualStream(){return mDualStream;};
bool needCbSwitch();
bool needFrameSync();
uint32_t getMyCamType() { return mCamType; }
//Stream time stamp. We need this for preview stream to update display
nsecs_t mStreamTimestamp;
//Frame Buffer will be stored here in case framework batch mode.
camera_memory_t *mCurMetaMemory; // Current metadata buffer ptr
int8_t mCurBufIndex; // Buffer count filled in current metadata
int8_t mCurMetaIndex; // Active metadata buffer index
nsecs_t mFirstTimeStamp; // Timestamp of first frame in Metadata.
// Buffer storage structure.
typedef struct {
bool consumerOwned; // Metadata is with Consumer if TRUE
uint8_t numBuffers; // Num of buffer need to released
uint8_t buf_index[CAMERA_MAX_CONSUMER_BATCH_BUFFER_SIZE];
} MetaMemory;
MetaMemory mStreamMetaMemory[CAMERA_MIN_VIDEO_BATCH_BUFFERS];
int32_t handleCacheOps(mm_camera_buf_def_t* buf);
void setFrameDimension(cam_dimension_t dim) {mStreamInfo->dim = dim;}
void setFrameOffset(cam_frame_len_offset_t offset) {mFrameLenOffset = offset;}
void setFormat(cam_format_t fmt) {mStreamInfo->fmt = fmt;}
private:
uint32_t mCamHandle;
uint32_t mChannelHandle;
uint32_t mHandle; // stream handle from mm-camera-interface
uint32_t mActiveCameras;
uint32_t mMasterCamera;
mm_camera_ops_t *mCamOps;
cam_stream_info_t *mStreamInfo; // ptr to stream info buf
mm_camera_stream_mem_vtbl_t mMemVtbl;
uint8_t mNumBufs;
uint8_t mNumPlaneBufs;
uint8_t mNumBufsNeedAlloc;
uint8_t *mRegFlags;
stream_cb_routine mDataCB;
stream_cb_routine mSYNCDataCB;
void *mUserData;
QCameraQueue mDataQ;
QCameraCmdThread mProcTh; // thread for dataCB
QCameraHeapMemory *mStreamInfoBuf;
QCameraHeapMemory *mMiscBuf;
QCameraMemory *mStreamBufs;
QCameraMemory *mStreamBatchBufs;
QCameraAllocator &mAllocator;
mm_camera_buf_def_t *mBufDefs;
mm_camera_buf_def_t *mPlaneBufDefs;
cam_frame_len_offset_t mFrameLenOffset;
cam_padding_info_t mPaddingInfo;
cam_rect_t mCropInfo;
cam_rotation_t mOnlineRotation;
pthread_mutex_t mCropLock; // lock to protect crop info
pthread_mutex_t mParameterLock; // lock to sync access to parameters
bool mStreamBufsAcquired;
bool m_bActive; // if stream mProcTh is active
bool mDynBufAlloc; // allow buf allocation in 2 steps
pthread_t mBufAllocPid;
mm_camera_map_unmap_ops_tbl_t m_MemOpsTbl;
cam_stream_parm_buffer_t m_OutputCrop;
cam_stream_parm_buffer_t m_ImgProp;
static int32_t get_bufs(
cam_frame_len_offset_t *offset,
uint8_t *num_bufs,
uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t get_bufs_deffered(
cam_frame_len_offset_t *offset,
uint8_t *num_bufs,
uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t put_bufs(
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t put_bufs_deffered(
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t set_config_ops(
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t invalidate_buf(uint32_t index, void *user_data);
static int32_t clean_invalidate_buf(uint32_t index, void *user_data);
static int32_t clean_buf(uint32_t index, void *user_data);
static int32_t backgroundAllocate(void* data);
static int32_t backgroundMap(void* data);
int32_t getBufs(cam_frame_len_offset_t *offset,
uint8_t *num_bufs,
uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t getBufsDeferred(cam_frame_len_offset_t *offset,
uint8_t *num_bufs,
uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t putBufsDeffered();
/* Used for deffered allocation of buffers */
int32_t allocateBatchBufs(cam_frame_len_offset_t *offset,
uint8_t *num_bufs, uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs, mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t releaseBatchBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t invalidateBuf(uint32_t index);
int32_t cleanInvalidateBuf(uint32_t index);
int32_t cleanBuf(uint32_t index);
int32_t calcOffset(cam_stream_info_t *streamInfo);
int32_t unmapStreamInfoBuf();
int32_t releaseStreamInfoBuf();
int32_t releaseMiscBuf();
int32_t mapBufs(QCameraMemory *heapBuf, cam_mapping_buf_type bufType,
mm_camera_map_unmap_ops_tbl_t *ops_tbl = NULL);
int32_t unMapBuf(QCameraMemory *heapBuf, cam_mapping_buf_type bufType,
mm_camera_map_unmap_ops_tbl_t *ops_tbl = NULL);
bool mDefferedAllocation;
bool wait_for_cond;
pthread_mutex_t m_lock;
pthread_cond_t m_cond;
BackgroundTask mAllocTask;
uint32_t mAllocTaskId;
BackgroundTask mMapTask;
uint32_t mMapTaskId;
bool mSyncCBEnabled;
bool mDualStream;
uint32_t mCamType;
};
}; // namespace qcamera
#endif /* __QCAMERA_STREAM_H__ */

View file

@ -0,0 +1,260 @@
/* Copyright (c) 2013-2016,2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCameraThermalAdapter"
// System dependencies
#include <dlfcn.h>
#include <utils/Errors.h>
// Camera dependencies
#include "QCamera2HWI.h"
#include "QCameraThermalAdapter.h"
extern "C" {
#include "mm_camera_dbg.h"
}
#define CLIENT_NAME "camera_bw"
using namespace android;
namespace qcamera {
QCameraThermalAdapter& QCameraThermalAdapter::getInstance()
{
static QCameraThermalAdapter instance;
return instance;
}
QCameraThermalAdapter::QCameraThermalAdapter() :
mCallback(NULL),
mHandle(NULL),
mRegister(NULL),
mUnregister(NULL),
mCameraHandle(0),
mCamcorderHandle(0),
mInstanceCount(0)
{
}
int QCameraThermalAdapter::init(QCameraThermalCallback *thermalCb)
{
int rc = UNKNOWN_ERROR;
LOGE("Skip loading libthermalclient \n");
(void)thermalCb;
goto error;
#if 0
const char *error = NULL;
int rc = NO_ERROR;
LOGD("E");
{
Mutex::Autolock l(mInstanceLock);
mInstanceCount++;
if (mInstanceCount > 1) {
LOGD("Thermal adapter already initialized, skip this");
return NO_ERROR;
}
}
mHandle = dlopen("/vendor/lib/libthermalclient.so", RTLD_NOW);
if (!mHandle) {
error = dlerror();
LOGE("dlopen failed with error %s",
error ? error : "");
rc = UNKNOWN_ERROR;
goto error;
}
*(void **)&mRegister = dlsym(mHandle, "thermal_client_register_callback");
if (!mRegister) {
error = dlerror();
LOGE("dlsym failed with error code %s",
error ? error: "");
rc = UNKNOWN_ERROR;
goto error2;
}
*(void **)&mUnregister = dlsym(mHandle, "thermal_client_unregister_callback");
if (!mUnregister) {
error = dlerror();
LOGE("dlsym failed with error code %s",
error ? error: "");
rc = UNKNOWN_ERROR;
goto error2;
}
*(void **)&mSetPerfLevel = dlsym(mHandle, "thermal_bandwidth_client_request");
if (!mSetPerfLevel) {
error = dlerror();
LOGE("dlsym failed with error code %s",
error ? error: "");
rc = UNKNOWN_ERROR;
goto error2;
}
*(void **)&mReset = dlsym(mHandle, "thermal_bandwidth_client_cancel_request");
if (!mReset) {
error = dlerror();
LOGE("dlsym failed with error code %s",
error ? error: "");
rc = UNKNOWN_ERROR;
goto error2;
}
mCallback = thermalCb;
// Register camera and camcorder callbacks
mCameraHandle = mRegister(mStrCamera, thermalCallback, NULL);
if (mCameraHandle < 0) {
LOGE("thermal_client_register_callback failed %d",
mCameraHandle);
rc = UNKNOWN_ERROR;
goto error2;
}
mCamcorderHandle = mRegister(mStrCamcorder, thermalCallback, NULL);
if (mCamcorderHandle < 0) {
LOGE("thermal_client_register_callback failed %d",
mCamcorderHandle);
rc = UNKNOWN_ERROR;
goto error3;
}
LOGD("X");
return rc;
error3:
mCamcorderHandle = 0;
mUnregister(mCameraHandle);
error2:
mCameraHandle = 0;
dlclose(mHandle);
mHandle = NULL;
#endif
error:
LOGD("X");
return rc;
}
void QCameraThermalAdapter::deinit()
{
LOGD("E");
{
Mutex::Autolock l(mInstanceLock);
mInstanceCount--;
if (mInstanceCount > 0) {
LOGD("Still active clients, skip this");
return;
}
}
Reset();
if (mUnregister) {
if (mCameraHandle) {
mUnregister(mCameraHandle);
mCameraHandle = 0;
}
if (mCamcorderHandle) {
mUnregister(mCamcorderHandle);
mCamcorderHandle = 0;
}
}
if (mHandle)
dlclose(mHandle);
mHandle = NULL;
mRegister = NULL;
mUnregister = NULL;
mCallback = NULL;
LOGD("X");
}
char QCameraThermalAdapter::mStrCamera[] = "camera";
char QCameraThermalAdapter::mStrCamcorder[] = "camcorder";
// initializing prevPerfLevel to -1, to ensure 0 is send to thermal
// module.
int QCameraThermalAdapter::prevPerfLevel = -1;
int QCameraThermalAdapter::thermalCallback(int level,
void *userdata, void *data)
{
int rc = 0;
LOGD("E");
QCameraThermalCallback *mcb = getInstance().mCallback;
if (mcb) {
mcb->setThermalLevel((qcamera_thermal_level_enum_t) level);
rc = mcb->thermalEvtHandle(mcb->getThermalLevel(), userdata, data);
}
LOGD("X");
return rc;
}
int QCameraThermalAdapter::SetPerfLevel(int level) {
// Change has been done to handle the use case
// When modem changes from say level 2 to level 1
// It has to send level 0 then level 1.
int result=0;
if (prevPerfLevel > level) {
// First send 0 then lower perf Level
result=mSetPerfLevel((char*)CLIENT_NAME, 0);
LOGE("Prev Level greater than New Level\n");
result=mSetPerfLevel((char*)CLIENT_NAME, level);
} else if (prevPerfLevel == level) {
// no need to send
result=mSetPerfLevel((char*)CLIENT_NAME, level);
// But sending, because sometimes modem might not
// have received the previous level based on its
// state.
// To be removed - once modem state handling is
// incorporated.
LOGE("Prev Level same as New Level\n");
} else {
// send the new level
result=mSetPerfLevel((char*)CLIENT_NAME, level);
LOGE("Prev Level smaller than New Level\n");
}
prevPerfLevel=level;
return result;
}
void QCameraThermalAdapter::Reset() {
return mReset((char*)CLIENT_NAME);
}
qcamera_thermal_level_enum_t *QCameraThermalCallback::getThermalLevel() {
return &mLevel;
}
void QCameraThermalCallback::setThermalLevel(qcamera_thermal_level_enum_t level) {
mLevel = level;
}
}; //namespace qcamera

View file

@ -0,0 +1,97 @@
/* Copyright (c) 2013,2016,2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_THERMAL_ADAPTER__
#define __QCAMERA_THERMAL_ADAPTER__
namespace qcamera {
typedef enum {
QCAMERA_THERMAL_NO_ADJUSTMENT = 0,
QCAMERA_THERMAL_SLIGHT_ADJUSTMENT,
QCAMERA_THERMAL_BIG_ADJUSTMENT,
QCAMERA_THERMAL_MAX_ADJUSTMENT,
QCAMERA_THERMAL_SHUTDOWN = 10
} qcamera_thermal_level_enum_t;
typedef enum {
QCAMERA_THERMAL_ADJUST_FPS,
QCAMERA_THERMAL_ADJUST_FRAMESKIP,
} qcamera_thermal_mode;
class QCameraThermalCallback
{
public:
virtual int thermalEvtHandle(qcamera_thermal_level_enum_t *level,
void *userdata, void *data) = 0;
virtual ~QCameraThermalCallback() {}
qcamera_thermal_level_enum_t *getThermalLevel();
void setThermalLevel(qcamera_thermal_level_enum_t level);
private:
qcamera_thermal_level_enum_t mLevel;
};
class QCameraThermalAdapter
{
public:
static QCameraThermalAdapter& getInstance();
int init(QCameraThermalCallback *thermalCb);
void deinit();
int SetPerfLevel(int level);
void Reset();
private:
static char mStrCamera[];
static char mStrCamcorder[];
static int prevPerfLevel;
static int thermalCallback(int level, void *userdata, void *data);
QCameraThermalCallback *mCallback;
void *mHandle;
int (*mRegister)(char *name,
int (*callback)(int, void *userdata, void *data), void *data);
int (*mUnregister)(int handle);
int (*mSetPerfLevel)(char *client_name, int req_data);
void (*mReset)(char *client_name);
int mCameraHandle;
int mCamcorderHandle;
uint8_t mInstanceCount;
Mutex mInstanceLock;
QCameraThermalAdapter();
QCameraThermalAdapter(QCameraThermalAdapter const& copy); // not implemented
QCameraThermalAdapter& operator=(QCameraThermalAdapter const& copy); // not implemented
};
}; // namespace qcamera
#endif /* __QCAMERA_THERMAL_ADAPTER__ */

View file

@ -0,0 +1,47 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA2EXTERNAL_H__
#define __QCAMERA2EXTERNAL_H__
// System dependencies
#include <utils/Errors.h>
// Display dependencies
#include "QServiceUtils.h"
namespace qcamera {
inline android::status_t setCameraLaunchStatus(uint32_t on __attribute__ ((unused))) {
return android::OK;
}
}; // namespace qcamera
#endif /* __QCAMERA2EXTERNAL_H__ */

View file

@ -0,0 +1,100 @@
/*
* Copyright (C) 2014,2015 Thundersoft Corporation
* All rights Reserved
*
* 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 __TS_DETECTFACE_ENGINE_H__
#define __TS_DETECTFACE_ENGINE_H__
#include "ts_makeup_data.h"
#include "ts_makeup_image.h"
typedef void* TSHandle;
/*===========================================================================
* FUNCTION : ts_detectface_create_context
*
* DESCRIPTION: create context.The method MUST call at first time.
*
*
* RETURN : TSHandle as the context handle
*
*==========================================================================*/
TSHandle ts_detectface_create_context();
/*===========================================================================
* FUNCTION : ts_detectface_destroy_context
*
* DESCRIPTION: destroy context. The method MUST call at last time.
* Before you MUST call ts_detectface_create_context method
* to create context and get context handle.
*
* PARAMETERS :
* @param[in] contexTSHandle : The context handle pointer.
*
*
*==========================================================================*/
void ts_detectface_destroy_context(TSHandle* contexTSHandle);
/*===========================================================================
* FUNCTION : ts_detectface_detect
*
* DESCRIPTION: start detect.Before you MUST call ts_detectface_create_context method
* to create context and get context handle.
*
* PARAMETERS :
* @param[in] contexTSHandle : The context handle.
* @param[in] pInData : The TSMakeupData pointer.MUST not NULL.
*
* RETURN : int If less than zero failed, otherwise the number of the detected faces.
*
*==========================================================================*/
int ts_detectface_detect(TSHandle contexTSHandle, TSMakeupData *pInData);
/*===========================================================================
* FUNCTION : ts_detectface_detectEx
*
* DESCRIPTION: start detect.Before you MUST call ts_detectface_create_context method
* to create context and get context handle.
*
* PARAMETERS :
* @param[in] contexTSHandle : The context handle.
* @param[in] pInData : The TSMakeupDataEx pointer.MUST not NULL.
*
* RETURN : int If less than zero failed, otherwise the number of the detected faces.
*
*==========================================================================*/
int ts_detectface_detectEx(TSHandle contexTSHandle, TSMakeupDataEx *pInData);
/*===========================================================================
* FUNCTION : ts_detectface_get_face_info
*
* DESCRIPTION: get detected face information.Before you MUST call ts_detectface_detect method
* to detect face.
*
* PARAMETERS :
* @param[in] contexTSHandle : The context handle.
* @param[in] index : The face index.MUST > 0.
* @param[out] pFaceRect : The face rects.MUST not NULL.
* @param[out] leftEye : The left eye rect.
* @param[out] rightEye : The right eye rect.
* @param[out] pMouth : The mount rect.
*
* RETURN : TS_OK if success, otherwise failed.
*
*==========================================================================*/
int ts_detectface_get_face_info(TSHandle contexTSHandle, int index, TSRect *pFaceRect, TSRect *leftEye, TSRect *rightEye, TSRect *pMouth);
#endif // __TS_DETECTFACE_ENGINE_H__

View file

@ -0,0 +1,49 @@
/*
* Copyright (C) 2014,2015 Thundersoft Corporation
* All rights Reserved
*
* 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 __TS_MAKEUP_DATA_H__
#define __TS_MAKEUP_DATA_H__
#define TS_OK (0x00000000) //Successful
#define TS_ERROR_PARAM (0x00000001) //Parameters error
#define TS_ERROR_IO (0x00000002) //Input or output error
#define TS_ERROR_INTERNAL (0x00000003) //Internal error
#define TS_NO_MEMORY (0x00000004) //No memory error
/*
* Data struct : rectangle
*/
typedef struct __tag_tsrect
{
long left;
long top;
long right;
long bottom;
} TSRect;
/*
* Data struct : point
*/
typedef struct __tag_tsmakeuppoint
{
long x;
long y;
} TSPoint;
#endif // __TS_MAKEUP_DATA_H__

View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 2014,2015 Thundersoft Corporation
* All rights Reserved
*
* 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 __TS_MAKEUP_ENGINI_H__
#define __TS_MAKEUP_ENGINI_H__
#include "ts_makeup_data.h"
#include "ts_makeup_image.h"
/*
* FUNCTION : ts_makeup_get_supported_face_num
*
* DESCRIPTION: get supported face number
*
* RETURN : The supported face number
*
*/
int ts_makeup_get_supported_face_num();
/*
* FUNCTION : ts_makeup_skin_beauty
*
* DESCRIPTION: skin beauty method.
*
* PARAMETERS :
* @param[in] pInData : The TSMakeupData pointer.MUST not NULL.
* @param[out] pOutData : The TSMakeupData pointer.MUST not NULL.
* @param[in] pFaceRect : The face rect.MUST not NULL.
* @param[in] cleanLevel : Skin clean level, value range [0,100].
* @param[in] whiteLevel : Skin white level, value range [0,100].
* RETURN : TS_OK if success, otherwise failed.
*
*/
int ts_makeup_skin_beauty(TSMakeupData *pInData, TSMakeupData *pOutData, const TSRect *pFaceRect, int cleanLevel,int whiteLevel);
/*
* FUNCTION : ts_makeup_skin_beautyEx
*
* DESCRIPTION: skin beauty method.
*
* PARAMETERS :
* @param[in] pInData : The TSMakeupDataEx pointer.MUST not NULL.
* @param[out] pOutData : The TSMakeupDataEx pointer.MUST not NULL.
* @param[in] pFaceRect : The face rect.MUST not NULL.
* @param[in] cleanLevel : Skin clean level, value range [0,100].
* @param[in] whiteLevel : Skin white level, value range [0,100].
* RETURN : TS_OK if success, otherwise failed.
*
*/
int ts_makeup_skin_beautyEx(TSMakeupDataEx *pInData, TSMakeupDataEx *pOutData, const TSRect *pFaceRect, int cleanLevel, int whiteLevel);
/*
* FUNCTION : ts_makeup_finish
*
* DESCRIPTION: Finish makeup,call this method at last time.
* This method MUST be called After ts_makeup_skin_clean and ts_makeup_skin_whiten
*
*/
void ts_makeup_finish();
/*
* FUNCTION : ts_makeup_warp_face
*
* DESCRIPTION: do warp face.
*
* PARAMETERS :
* @param[in] pInData : The TSMakeupData pointer.MUST not NULL.
* @param[out] pOutData : The TSMakeupData pointer.MUST not NULL.
* @param[in] pLeftEye : The left eye rect pointer.MUST not NULL.
* @param[in] pRightEye : The right eye rect pointer.MUST not NULL.
* @param[in] pMouth : The mouth rect pointer.MUST not NULL.
* @param[in] bigEyeLevel : The big eye level, value range [0,100].
* @param[in] trimFaceLevel : The trim face level, value range [0,100].
*
* RETURN : TS_OK if success, otherwise failed.
*
*/
int ts_makeup_warp_face(TSMakeupData *pInData, TSMakeupData *pOutData,
const TSRect *pLeftEye, const TSRect *pRightEye, const TSRect *pMouth, int bigEyeLevel, int trimFaceLevel);
#endif // __TS_MAKEUP_ENGINI_H__

View file

@ -0,0 +1,46 @@
/*
* Copyright (C) 2014,2015 Thundersoft Corporation
* All rights Reserved
*
* 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 __TS_MAKEUP_IMGAGE_H__
#define __TS_MAKEUP_IMGAGE_H__
/*
* Data struct : TSMakeupData
*/
typedef struct __tag_tsmakeupdata
{
int frameWidth; //NV21 Frame width.MUST > 0.
int frameHeight; //NV21 Frame height. MUST > 0.
unsigned char *yBuf; //NV21 Y buffer pointer.MUST not null.
unsigned char *uvBuf; //NV21 UV buffer pointer.MUST not null.
}TSMakeupData;
/*
* Data struct : TSMakeupDataEx
*/
typedef struct __tag_tsmakeupdataEx
{
int frameWidth; //NV21 Frame width.MUST > 0.
int frameHeight; //NV21 Frame height. MUST > 0.
unsigned char *yBuf; //NV21 Y buffer pointer.MUST not null.
unsigned char *uvBuf; //NV21 UV buffer pointer.MUST not null.
int yStride; //NV21 Y buffer stride len
int uvStride; //NV21 uv buffer stride len
}TSMakeupDataEx;
#endif // __TS_MAKEUP_IMGAGE_H__

View file

@ -0,0 +1,450 @@
/* Copyright (c) 2011-2014, 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define ALOG_NIDEBUG 0
#define LOG_TAG "QualcommCamera"
// System dependencies
#include <utils/threads.h>
#include <binder/IMemory.h>
#include <binder/MemoryBase.h>
#include <binder/MemoryHeapBase.h>
#include <utils/RefBase.h>
extern "C" {
#define TIME_H <SYSTEM_HEADER_PREFIX/time.h>
#include TIME_H
}
// Camera dependencies
#include "QualcommCamera.h"
#include "QCamera2Factory.h"
#include "QCamera2HWI.h"
/* HAL function implementation goes here*/
/**
* The functions need to be provided by the camera HAL.
*
* If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
* and openCameraHardware() is 0 to N-1.
*/
static hw_module_methods_t camera_module_methods = {
open: camera_device_open,
};
static hw_module_t camera_common = {
tag: HARDWARE_MODULE_TAG,
module_api_version: CAMERA_MODULE_API_VERSION_1_0,
hal_api_version: HARDWARE_HAL_API_VERSION,
id: CAMERA_HARDWARE_MODULE_ID,
name: "QCamera Module",
author: "Quic on behalf of CAF",
methods: &camera_module_methods,
dso: NULL,
reserved: {0},
};
using namespace qcamera;
namespace android {
typedef struct {
camera_device hw_dev;
QCamera2HardwareInterface *hardware;
int camera_released;
int cameraId;
} camera_hardware_t;
typedef struct {
camera_memory_t mem;
int32_t msgType;
sp<IMemory> dataPtr;
void* user;
unsigned int index;
} q_cam_memory_t;
QCamera2HardwareInterface *util_get_Hal_obj( struct camera_device * device)
{
QCamera2HardwareInterface *hardware = NULL;
if(device && device->priv){
camera_hardware_t *camHal = (camera_hardware_t *)device->priv;
hardware = camHal->hardware;
}
return hardware;
}
extern "C" int get_number_of_cameras()
{
/* try to query every time we get the call!*/
ALOGE("Q%s: E");
return QCamera2Factory::get_number_of_cameras();
}
extern "C" int get_camera_info(int camera_id, struct camera_info *info)
{
int rc = -1;
ALOGE("Q%s: E");
if(info) {
QCamera2Factory::get_camera_info(camera_id, info);
}
LOGD("Q%s: X");
return rc;
}
/* HAL should return NULL if it fails to open camera hardware. */
extern "C" int camera_device_open(
const struct hw_module_t* module, const char* id,
struct hw_device_t** hw_device)
{
int rc = -1;
camera_device *device = NULL;
if(module && id && hw_device) {
if (!strcmp(module->name, camera_common.name)) {
int cameraId = atoi(id);
camera_hardware_t *camHal =
(camera_hardware_t *) malloc(sizeof (camera_hardware_t));
if(!camHal) {
*hw_device = NULL;
ALOGE(" end in no mem");
return rc;
}
/* we have the camera_hardware obj malloced */
memset(camHal, 0, sizeof (camera_hardware_t));
camHal->hardware = new QCamera2HardwareInterface((uint32_t)cameraId);
if (camHal->hardware) {
camHal->cameraId = cameraId;
device = &camHal->hw_dev;
device->common.close = close_camera_device;
device->ops = &QCamera2HardwareInterface::mCameraOps;
device->priv = (void *)camHal;
rc = 0;
} else {
if (camHal->hardware) {
delete camHal->hardware;
camHal->hardware = NULL;
}
free(camHal);
device = NULL;
goto EXIT;
}
}
}
/* pass actual hw_device ptr to framework. This amkes that we actally be use memberof() macro */
*hw_device = (hw_device_t*)&device->common;
EXIT:
ALOGE(" end rc %d", rc);
return rc;
}
extern "C" int close_camera_device( hw_device_t *hw_dev)
{
ALOGE("Q%s: device =%p E", hw_dev);
int rc = -1;
camera_device_t *device = (camera_device_t *)hw_dev;
if(device) {
camera_hardware_t *camHal = (camera_hardware_t *)device->priv;
if(camHal ) {
QCamera2HardwareInterface *hardware = util_get_Hal_obj( device);
if(!camHal->camera_released) {
if(hardware != NULL) {
hardware->release(device);
}
}
if(hardware != NULL)
delete hardware;
free(camHal);
}
rc = 0;
}
return rc;
}
int set_preview_window(struct camera_device * device,
struct preview_stream_ops *window)
{
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL) {
rc = hardware->set_preview_window(device, window);
}
return rc;
}
void set_CallBacks(struct camera_device * device,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user)
{
ALOGE("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
hardware->set_CallBacks(device, notify_cb,data_cb, data_cb_timestamp, get_memory, user);
}
}
void enable_msg_type(struct camera_device * device, int32_t msg_type)
{
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
hardware->enable_msg_type(device, msg_type);
}
}
void disable_msg_type(struct camera_device * device, int32_t msg_type)
{
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
ALOGE("Q%s: E");
if(hardware != NULL){
hardware->disable_msg_type(device, msg_type);
}
}
int msg_type_enabled(struct camera_device * device, int32_t msg_type)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->msg_type_enabled(device, msg_type);
}
return rc;
}
int start_preview(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->start_preview(device);
}
ALOGE("Q%s: X");
return rc;
}
void stop_preview(struct camera_device * device)
{
ALOGE("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
hardware->stop_preview(device);
}
}
int preview_enabled(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->preview_enabled(device);
}
return rc;
}
int store_meta_data_in_buffers(struct camera_device * device, int enable)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->store_meta_data_in_buffers(device, enable);
}
return rc;
}
int start_recording(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->start_recording(device);
}
return rc;
}
void stop_recording(struct camera_device * device)
{
ALOGE("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
hardware->stop_recording(device);
}
}
int recording_enabled(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->recording_enabled(device);
}
return rc;
}
void release_recording_frame(struct camera_device * device,
const void *opaque)
{
LOGD("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
hardware->release_recording_frame(device, opaque);
}
}
int auto_focus(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->auto_focus(device);
}
return rc;
}
int cancel_auto_focus(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->cancel_auto_focus(device);
}
return rc;
}
int take_picture(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->take_picture(device);
}
return rc;
}
int cancel_picture(struct camera_device * device)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->cancel_picture(device);
}
return rc;
}
int set_parameters(struct camera_device * device, const char *parms)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL && parms){
rc = hardware->set_parameters(device, parms);
}
return rc;
}
char* get_parameters(struct camera_device * device)
{
ALOGE("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
char *parms = NULL;
parms = hardware->get_parameters(device);
return parms;
}
return NULL;
}
void put_parameters(struct camera_device * device, char *parm)
{
ALOGE("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
hardware->put_parameters(device, parm);
}
}
int send_command(struct camera_device * device,
int32_t cmd, int32_t arg1, int32_t arg2)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->send_command(device, cmd, arg1, arg2);
}
return rc;
}
void release(struct camera_device * device)
{
ALOGE("Q%s: E");
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
camera_hardware_t *camHal = (camera_hardware_t *)device->priv;
hardware->release(device);
camHal->camera_released = true;
}
}
int dump(struct camera_device * device, int fd)
{
ALOGE("Q%s: E");
int rc = -1;
QCamera2HardwareInterface *hardware = util_get_Hal_obj(device);
if(hardware != NULL){
rc = hardware->dump(device, fd);
}
return rc;
}
}; // namespace android

View file

@ -0,0 +1,107 @@
/* Copyright (c) 2011-2013, 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef ANDROID_HARDWARE_QUALCOMM_CAMERA_H
#define ANDROID_HARDWARE_QUALCOMM_CAMERA_H
// Camera dependencies
#include "QCamera2HWI.h"
extern "C" {
int get_number_of_cameras();
int get_camera_info(int camera_id, struct camera_info *info);
int camera_device_open(const struct hw_module_t* module, const char* id,
struct hw_device_t** device);
hw_device_t * open_camera_device(int cameraId);
int close_camera_device( hw_device_t *);
namespace android {
int set_preview_window(struct camera_device *,
struct preview_stream_ops *window);
void set_CallBacks(struct camera_device *,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user);
void enable_msg_type(struct camera_device *, int32_t msg_type);
void disable_msg_type(struct camera_device *, int32_t msg_type);
int msg_type_enabled(struct camera_device *, int32_t msg_type);
int start_preview(struct camera_device *);
void stop_preview(struct camera_device *);
int preview_enabled(struct camera_device *);
int store_meta_data_in_buffers(struct camera_device *, int enable);
int start_recording(struct camera_device *);
void stop_recording(struct camera_device *);
int recording_enabled(struct camera_device *);
void release_recording_frame(struct camera_device *,
const void *opaque);
int auto_focus(struct camera_device *);
int cancel_auto_focus(struct camera_device *);
int take_picture(struct camera_device *);
int cancel_picture(struct camera_device *);
int set_parameters(struct camera_device *, const char *parms);
char* get_parameters(struct camera_device *);
void put_parameters(struct camera_device *, char *);
int send_command(struct camera_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
void release(struct camera_device *);
int dump(struct camera_device *, int fd);
}; // namespace android
} //extern "C"
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,319 @@
/* Copyright (c) 2015-2016, 2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define ATRACE_TAG ATRACE_TAG_CAMERA
#define LOG_TAG "QCamera3CropRegionMapper"
// Camera dependencies
#include "QCamera3CropRegionMapper.h"
#include "QCamera3HWI.h"
#include "math.h"
extern "C" {
#include "mm_camera_dbg.h"
}
using namespace android;
namespace qcamera {
/*===========================================================================
* FUNCTION : QCamera3CropRegionMapper
*
* DESCRIPTION: Constructor
*
* PARAMETERS : None
*
* RETURN : None
*==========================================================================*/
QCamera3CropRegionMapper::QCamera3CropRegionMapper()
: mSensorW(0),
mSensorH(0),
mActiveArrayW(0),
mActiveArrayH(0)
{
}
/*===========================================================================
* FUNCTION : ~QCamera3CropRegionMapper
*
* DESCRIPTION: destructor
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCamera3CropRegionMapper::~QCamera3CropRegionMapper()
{
}
/*===========================================================================
* FUNCTION : update
*
* DESCRIPTION: update sensor active array size and sensor output size
*
* PARAMETERS :
* @active_array_w : active array width
* @active_array_h : active array height
* @sensor_w : sensor output width
* @sensor_h : sensor output height
*
* RETURN : none
*==========================================================================*/
void QCamera3CropRegionMapper::update(uint32_t active_array_w,
uint32_t active_array_h, uint32_t sensor_w,
uint32_t sensor_h)
{
// Sanity check
if (active_array_w == 0 || active_array_h == 0 ||
sensor_w == 0 || sensor_h == 0) {
LOGE("active_array size and sensor output size must be non zero");
return;
}
if (active_array_w < sensor_w || active_array_h < sensor_h) {
LOGE("invalid input: active_array [%d, %d], sensor size [%d, %d]",
active_array_w, active_array_h, sensor_w, sensor_h);
return;
}
mSensorW = sensor_w;
mSensorH = sensor_h;
mActiveArrayW = active_array_w;
mActiveArrayH = active_array_h;
LOGH("active_array: %d x %d, sensor size %d x %d",
mActiveArrayW, mActiveArrayH, mSensorW, mSensorH);
}
/*===========================================================================
* FUNCTION : toActiveArray
*
* DESCRIPTION: Map crop rectangle from sensor output space to active array space
*
* PARAMETERS :
* @crop_left : x coordinate of top left corner of rectangle
* @crop_top : y coordinate of top left corner of rectangle
* @crop_width : width of rectangle
* @crop_height : height of rectangle
*
* RETURN : none
*==========================================================================*/
void QCamera3CropRegionMapper::toActiveArray(int32_t& crop_left, int32_t& crop_top,
int32_t& crop_width, int32_t& crop_height)
{
if (mSensorW == 0 || mSensorH == 0 ||
mActiveArrayW == 0 || mActiveArrayH == 0) {
LOGE("sensor/active array sizes are not initialized!");
return;
}
crop_left = crop_left * mActiveArrayW / mSensorW;
crop_top = crop_top * mActiveArrayH / mSensorH;
crop_width = crop_width * mActiveArrayW / mSensorW;
crop_height = crop_height * mActiveArrayH / mSensorH;
boundToSize(crop_left, crop_top, crop_width, crop_height,
mActiveArrayW, mActiveArrayH);
}
/*===========================================================================
* FUNCTION : toSensor
*
* DESCRIPTION: Map crop rectangle from active array space to sensor output space
*
* PARAMETERS :
* @crop_left : x coordinate of top left corner of rectangle
* @crop_top : y coordinate of top left corner of rectangle
* @crop_width : width of rectangle
* @crop_height : height of rectangle
*
* RETURN : none
*==========================================================================*/
void QCamera3CropRegionMapper::toSensor(int32_t& crop_left, int32_t& crop_top,
int32_t& crop_width, int32_t& crop_height)
{
float tmpLeft, tmpTop, tmpWidth, tmpHeight;
if (mSensorW == 0 || mSensorH == 0 ||
mActiveArrayW == 0 || mActiveArrayH == 0) {
LOGE("sensor/active array sizes are not initialized!");
return;
}
tmpLeft = (float)crop_left * mSensorW / mActiveArrayW;
tmpTop = (float)crop_top * mSensorH / mActiveArrayH;
tmpWidth = (float)crop_width * mSensorW / mActiveArrayW;
tmpHeight = (float)crop_height * mSensorH / mActiveArrayH;
crop_left = ceil(tmpLeft);
crop_top = ceil(tmpTop);
crop_width = ceil(tmpWidth);
crop_height = ceil(tmpHeight);
LOGD("before bounding left %d, top %d, width %d, height %d",
crop_left, crop_top, crop_width, crop_height);
boundToSize(crop_left, crop_top, crop_width, crop_height,
mSensorW, mSensorH);
LOGD("after bounding left %d, top %d, width %d, height %d",
crop_left, crop_top, crop_width, crop_height);
}
/*===========================================================================
* FUNCTION : boundToSize
*
* DESCRIPTION: Bound a particular rectangle inside a bounding box
*
* PARAMETERS :
* @left : x coordinate of top left corner of rectangle
* @top : y coordinate of top left corner of rectangle
* @width : width of rectangle
* @height : height of rectangle
* @bound_w : width of bounding box
* @bound_y : height of bounding box
*
* RETURN : none
*==========================================================================*/
void QCamera3CropRegionMapper::boundToSize(int32_t& left, int32_t& top,
int32_t& width, int32_t& height, int32_t bound_w, int32_t bound_h)
{
if (left < 0) {
left = 0;
}
if (top < 0) {
top = 0;
}
if ((left + width) > bound_w) {
width = bound_w - left;
}
if ((top + height) > bound_h) {
height = bound_h - top;
}
}
/*===========================================================================
* FUNCTION : toActiveArray
*
* DESCRIPTION: Map co-ordinate from sensor output space to active array space
*
* PARAMETERS :
* @x : x coordinate
* @y : y coordinate
*
* RETURN : none
*==========================================================================*/
void QCamera3CropRegionMapper::toActiveArray(uint32_t& x, uint32_t& y)
{
if (mSensorW == 0 || mSensorH == 0 ||
mActiveArrayW == 0 || mActiveArrayH == 0) {
LOGE("sensor/active array sizes are not initialized!");
return;
}
if ((x > static_cast<uint32_t>(mSensorW)) ||
(y > static_cast<uint32_t>(mSensorH))) {
LOGE("invalid co-ordinate (%d, %d) in (0, 0, %d, %d) space",
x, y, mSensorW, mSensorH);
return;
}
x = x * mActiveArrayW / mSensorW;
y = y * mActiveArrayH / mSensorH;
}
/*===========================================================================
* FUNCTION : toSensor
*
* DESCRIPTION: Map co-ordinate from active array space to sensor output space
*
* PARAMETERS :
* @x : x coordinate
* @y : y coordinate
*
* RETURN : none
*==========================================================================*/
void QCamera3CropRegionMapper::toSensor(uint32_t& x, uint32_t& y)
{
if (mSensorW == 0 || mSensorH == 0 ||
mActiveArrayW == 0 || mActiveArrayH == 0) {
LOGE("sensor/active array sizes are not initialized!");
return;
}
if ((x > static_cast<uint32_t>(mActiveArrayW)) ||
(y > static_cast<uint32_t>(mActiveArrayH))) {
LOGE("invalid co-ordinate (%d, %d) in (0, 0, %d, %d) space",
x, y, mSensorW, mSensorH);
return;
}
x = x * mSensorW / mActiveArrayW;
y = y * mSensorH / mActiveArrayH;
}
void QCamera3CropRegionMapper::convertFDROI(int32_t& crop_left, int32_t& crop_top,
int32_t& crop_width, int32_t& crop_height)
{
float width_ratio, height_ratio, upscale_ratio;
int new_width, new_height, new_left, new_top;
if (mSensorW == 0 || mSensorH == 0 ||
mActiveArrayW == 0 || mActiveArrayH == 0) {
LOGE("sensor/active array sizes are not initialized!");
return;
}
width_ratio = (float)mActiveArrayW / mSensorW;
height_ratio = (float)mActiveArrayH / mSensorH;
if(width_ratio > height_ratio)
upscale_ratio = height_ratio;
else
upscale_ratio = width_ratio;
new_width = mSensorW * upscale_ratio;
new_height = mSensorH * upscale_ratio;
new_left = (mActiveArrayW - new_width) / 2;
new_top = (mActiveArrayH - new_height) / 2;
width_ratio = (float)new_width / mSensorW;
height_ratio = (float)new_height / mSensorH;
crop_left = crop_left * width_ratio + new_left;
crop_top = crop_top * height_ratio + new_top;
crop_width = crop_width * width_ratio;
crop_height = crop_height * height_ratio;
boundToSize(crop_left, crop_top, crop_width, crop_height,
mActiveArrayW, mActiveArrayH);
}
}; //end namespace android

View file

@ -0,0 +1,67 @@
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3CROPREGIONMAPPER_H__
#define __QCAMERA3CROPREGIONMAPPER_H__
// System dependencies
#include <utils/Errors.h>
using namespace android;
namespace qcamera {
class QCamera3CropRegionMapper {
public:
QCamera3CropRegionMapper();
virtual ~QCamera3CropRegionMapper();
void update(uint32_t active_array_w, uint32_t active_array_h,
uint32_t sensor_w, uint32_t sensor_h);
void toActiveArray(int32_t& crop_left, int32_t& crop_top,
int32_t& crop_width, int32_t& crop_height);
void toSensor(int32_t& crop_left, int32_t& crop_top,
int32_t& crop_width, int32_t& crop_height);
void toActiveArray(uint32_t& x, uint32_t& y);
void toSensor(uint32_t& x, uint32_t& y);
void convertFDROI(int32_t& crop_left, int32_t& crop_top,
int32_t& crop_width, int32_t& crop_height);
private:
/* sensor output size */
int32_t mSensorW, mSensorH;
int32_t mActiveArrayW, mActiveArrayH;
void boundToSize(int32_t& left, int32_t& top, int32_t& width,
int32_t& height, int32_t bound_w, int32_t bound_h);
};
}; // namespace qcamera
#endif /* __QCAMERA3CROPREGIONMAPPER_H__ */

View file

@ -0,0 +1,122 @@
/* Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_HALHEADER_H__
#define __QCAMERA_HALHEADER_H__
// System dependencies
#include "hardware/gralloc.h"
// Camera dependencies
#include "cam_types.h"
extern "C" {
#include "mm_jpeg_interface.h"
}
namespace qcamera {
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define IS_USAGE_ZSL(usage) (((usage) & (GRALLOC_USAGE_HW_CAMERA_ZSL)) \
== (GRALLOC_USAGE_HW_CAMERA_ZSL))
#define IS_USAGE_SECURE(usage) (((usage) & (GRALLOC_USAGE_PROTECTED)) \
== (GRALLOC_USAGE_PROTECTED))
#define IS_USAGE_UBWC(usage) (((usage) & (GRALLOC_USAGE_PRIVATE_ALLOC_UBWC)) \
== (GRALLOC_USAGE_PRIVATE_ALLOC_UBWC))
class QCamera3Channel;
class QCamera3ProcessingChannel;
typedef enum {
INVALID,
VALID,
} stream_status_t;
typedef enum {
REPROCESS_TYPE_NONE,
REPROCESS_TYPE_JPEG,
REPROCESS_TYPE_YUV,
REPROCESS_TYPE_PRIVATE,
REPROCESS_TYPE_RAW
} reprocess_type_t;
typedef struct {
uint32_t out_buf_index;
int32_t jpeg_orientation;
uint8_t jpeg_quality;
uint8_t jpeg_thumb_quality;
cam_dimension_t thumbnail_size;
uint8_t gps_timestamp_valid;
int64_t gps_timestamp;
uint8_t gps_coordinates_valid;
double gps_coordinates[3];
char gps_processing_method[GPS_PROCESSING_METHOD_SIZE];
uint8_t image_desc_valid;
char image_desc[EXIF_IMAGE_DESCRIPTION_SIZE];
bool hdr_snapshot;
bool multiframe_snapshot;
cam_hal3_JPEG_type_t image_type;
bool is_dim_valid;
cam_dimension_t output_dim;
bool is_offset_valid;
cam_frame_len_offset_t offset;
bool is_format_valid;
cam_format_t format;
bool is_crop_valid;
cam_rect_t crop;
mm_jpeg_image_type_t encode_type;
bool zsl_snapshot;
uint32_t frame_number;
bool raw_mfc_snapshot;
} jpeg_settings_t;
typedef struct {
int32_t iso_speed;
int64_t exposure_time;
} metadata_response_t;
typedef struct {
cam_stream_type_t stream_type;
cam_format_t stream_format;
cam_format_t output_stream_format;
cam_dimension_t input_stream_dim;
cam_stream_buf_plane_info_t input_stream_plane_info;
cam_dimension_t output_stream_dim;
cam_padding_info_t *padding;
reprocess_type_t reprocess_type;
cam_hdr_param_t hdr_param;
QCamera3Channel *src_channel;
} reprocess_config_t;
};//namespace qcamera
#endif

18364
QCamera2/HAL3/QCamera3HWI.cpp Normal file

File diff suppressed because it is too large Load diff

893
QCamera2/HAL3/QCamera3HWI.h Normal file
View file

@ -0,0 +1,893 @@
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3HARDWAREINTERFACE_H__
#define __QCAMERA3HARDWAREINTERFACE_H__
// System dependencies
#include <pthread.h>
#include <utils/KeyedVector.h>
#include <utils/List.h>
#include <map>
#include "CameraMetadata.h"
// Camera dependencies
#include "hardware/camera3.h"
#include "QCamera3Channel.h"
#include "QCamera3CropRegionMapper.h"
#include "QCamera3HALHeader.h"
#include "QCamera3Mem.h"
#include "QCameraPerf.h"
#include "QCameraCommon.h"
#include "QCamera3VendorTags.h"
#include "QCameraDualCamSettings.h"
#include "QCameraFOVControl.h"
#include "QCameraThermalAdapter.h"
#include "QCameraPerfTranslator.h"
extern "C" {
#include "mm_camera_interface.h"
#include "mm_jpeg_interface.h"
}
using namespace android;
namespace qcamera {
using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* Time related macros */
typedef int64_t nsecs_t;
#define NSEC_PER_SEC 1000000000LLU
#define NSEC_PER_USEC 1000LLU
#define NSEC_PER_33MSEC 33000000LLU
/*Orchestrate Macros */
#define EV_COMP_SETTLE_DELAY 2
#define GB_HDR_HALF_STEP_EV -6
#define GB_HDR_2X_STEP_EV 6
#define FRAME_REGISTER_LRU_SIZE 256
#define INTERNAL_FRAME_STARTING_NUMBER 800
#define EMPTY_FRAMEWORK_FRAME_NUMBER 0xFFFFFFFF
//blur range
#define MIN_BLUR 0
#define MAX_BLUR 100
#define BLUR_STEP 1
#define MAX_MFPROC_FRAMECOUNT 5
//ZSL queue attributes
#define ZSL_WATER_MARK 2
#define ZSL_UNMATCH_COUNT 3
#define ZSL_LOOK_BACK 2
#define ZSL_POST_FRAME_SKIP 1
typedef enum {
SET_ENABLE,
SET_CONTROLENABLE,
SET_RELOAD_CHROMATIX,
SET_STATUS,
} optype_t;
typedef enum {
QCFA_INACTIVE,
QCFA_RAW_OUTPUT,
QCFA_RAW_REPROCESS
} quadra_cfa_state_t;
typedef enum {
CONFIG_INDEX_MAIN = 0,
CONFIG_INDEX_AUX,
CONFIG_INDEX_MAX
}stream_config_index_t;
#define MODULE_ALL 0
#define IS_PP_TYPE_NONE (getHalPPType() == CAM_HAL_PP_TYPE_NONE)
#define IS_MULTI_CAMERA (isDualCamera() && IS_PP_TYPE_NONE)
#define IS_HAL_PP_TYPE_BOKEH (getHalPPType() == CAM_HAL_PP_TYPE_BOKEH)
#define IS_HAL_PP_TYPE_SAT (getHalPPType() == CAM_HAL_PP_TYPE_SAT)
#define IS_YUV_ZSL (mHALZSL == CAM_HAL3_ZSL_TYPE_CALLBACK)
#define IS_SNAP_ZSL (mHALZSL == CAM_HAL3_ZSL_TYPE_SNAPSHOT)
#define HW_RECOVERY_PROP "persist.vendor.camera.internal.restart"
#define DEFAULT_VALUE_HW_RECOVERY_PROP "1"
extern volatile uint32_t gCamHal3LogLevel;
class QCamera3MetadataChannel;
class QCamera3PicChannel;
class QCamera3HeapMemory;
class QCamera3Exif;
enum {
NONE,
INITIATE_HW_RECOVERY,
}deferred_task_type_t;
typedef struct {
uint32_t msg_type;
void *data;
void *owner;
} DeferredTask;
typedef struct {
camera3_stream_t *stream;
camera3_stream_buffer_set_t buffer_set;
stream_status_t status;
int registered;
QCamera3ProcessingChannel *channel;
} stream_info_t;
typedef struct {
// Stream handle
camera3_stream_t *stream;
// Buffer handle
buffer_handle_t *buffer;
// Buffer status
camera3_buffer_status_t bufStatus = CAMERA3_BUFFER_STATUS_OK;
} PendingBufferInfo;
typedef struct {
// Frame number corresponding to request
uint32_t frame_number;
// Time when request queued into system
nsecs_t timestamp;
List<PendingBufferInfo> mPendingBufferList;
} PendingBuffersInRequest;
class PendingBuffersMap {
public:
// Number of outstanding buffers at flush
uint32_t numPendingBufsAtFlush;
// List of pending buffers per request
List<PendingBuffersInRequest> mPendingBuffersInRequest;
uint32_t get_num_overall_buffers();
void removeBuf(buffer_handle_t *buffer);
int32_t getBufErrStatus(buffer_handle_t *buffer);
};
class FrameNumberRegistry {
public:
FrameNumberRegistry();
~FrameNumberRegistry();
int32_t allocStoreInternalFrameNumber(uint32_t frameworkFrameNumber,
uint32_t &internalFrameNumber);
int32_t generateStoreInternalFrameNumber(uint32_t &internalFrameNumber);
int32_t freeInternalFrameNumber(uint32_t internalFrameNumber);
int32_t getFrameworkFrameNumber(uint32_t internalFrameNumber, uint32_t &frameworkFrameNumber);
void purgeOldEntriesLocked();
private:
std::map<uint32_t, uint32_t> _register;
uint32_t _nextFreeInternalNumber;
Mutex mRegistryLock;
};
class QCamera3HardwareInterface : public QCameraThermalCallback {
public:
/* static variable and functions accessed by camera service */
static camera3_device_ops_t mCameraOps;
//Id of each session in bundle/link
static uint32_t sessionId[MM_CAMERA_MAX_NUM_SENSORS];
static int initialize(const struct camera3_device *,
const camera3_callback_ops_t *callback_ops);
static int configure_streams(const struct camera3_device *,
camera3_stream_configuration_t *stream_list);
static const camera_metadata_t* construct_default_request_settings(
const struct camera3_device *, int type);
static int process_capture_request(const struct camera3_device *,
camera3_capture_request_t *request);
static void dump(const struct camera3_device *, int fd);
static int flush(const struct camera3_device *);
static int close_camera_device(struct hw_device_t* device);
public:
QCamera3HardwareInterface(uint32_t cameraId,
const camera_module_callbacks_t *callbacks);
virtual ~QCamera3HardwareInterface();
static void camEvtHandle(uint32_t camera_handle, mm_camera_event_t *evt,
void *user_data);
int openCamera(struct hw_device_t **hw_device);
camera_metadata_t* translateCapabilityToMetadata(int type);
typedef struct {
camera3_stream_t *stream;
bool need_metadata;
bool meteringOnly;
bool needPastFrame;
} InternalRequest;
static int getCamInfo(uint32_t cameraId, struct camera_info *info);
static cam_capability_t *getCapabilities(mm_camera_ops_t *ops,
uint32_t cam_handle);
static int initCapabilities(uint32_t cameraId);
static int initStaticMetadata(uint32_t cameraId);
static uint8_t convertIdToUTF8(uint32_t id);
static void makeTable(cam_dimension_t *dimTable, size_t size,
size_t max_size, int32_t *sizeTable);
static void makeFPSTable(cam_fps_range_t *fpsTable, size_t size,
size_t max_size, int32_t *fpsRangesTable);
static void makeOverridesList(cam_scene_mode_overrides_t *overridesTable,
size_t size, size_t max_size, uint8_t *overridesList,
uint8_t *supported_indexes, uint32_t camera_id);
static size_t filterJpegSizes(int32_t *jpegSizes, int32_t *processedSizes,
size_t processedSizesCnt, size_t maxCount, cam_rect_t active_array_size,
uint8_t downscale_factor);
static void convertToRegions(cam_rect_t rect, int32_t* region, int weight);
static void convertFromRegions(cam_area_t &roi, const camera_metadata_t *settings,
uint32_t tag);
static bool resetIfNeededROI(cam_area_t* roi, const cam_crop_region_t* scalerCropRegion);
static int32_t getSensorSensitivity(int32_t iso_mode);
static uint8_t getIsoMode(int32_t sensitivity);
double computeNoiseModelEntryS(int32_t sensitivity);
double computeNoiseModelEntryO(int32_t sensitivity);
static void captureResultCb(mm_camera_super_buf_t *metadata,
camera3_stream_buffer_t *buffer, uint32_t frame_number,
bool isInputBuffer, void *userdata);
static void internalMetaCb(mm_camera_super_buf_t *metadata,
camera3_stream_buffer_t *buffer, uint32_t frame_number,
bool isInputBuffer, void *userdata);
static void* deferredWork(void* data);
int initialize(const camera3_callback_ops_t *callback_ops);
int configureStreams(camera3_stream_configuration_t *stream_list);
int configureStreamsPerfLocked(camera3_stream_configuration_t *stream_list);
int processCaptureRequest(camera3_capture_request_t *request,
List<InternalRequest> &internalReqs);
int orchestrateRequest(camera3_capture_request_t *request);
void orchestrateResult(camera3_capture_result_t *result);
void orchestrateNotify(camera3_notify_msg_t *notify_msg);
int32_t orchestrateHDRCapture(camera3_capture_request_t *request);
int32_t orchestrateMultiFrameCapture(camera3_capture_request_t *request);
int32_t orchestrateMFCRawCapture(camera3_capture_request_t *request);
int32_t orchestrateAdvancedCapture(camera3_capture_request_t *request, bool &isAdvancedCapture);
int32_t createDeferredWork(DeferredTask task);
void dump(int fd);
int flushPerf();
int setFrameParameters(const camera_metadata_t *settings,
cam_stream_ID_t streamID, int blob_request, uint32_t snapshotStreamId,
metadata_buffer_t *mParams, const camera3_capture_request_t *request);
int32_t setReprocParameters(camera3_capture_request_t *request,
metadata_buffer_t *reprocParam, uint32_t snapshotStreamId);
int8_t getReprocChannelCnt() {return m_ppChannelCnt;};
int translateToHalMetadata(const camera_metadata_t *settings,
metadata_buffer_t *parm, uint32_t snapshotStreamId,
const camera3_capture_request_t *request);
camera_metadata_t* translateCbUrgentMetadataToResultMetadata (
metadata_buffer_t *metadata);
camera_metadata_t* translateFromHalMetadata(metadata_buffer_t *metadata,
nsecs_t timestamp, int32_t request_id,
const CameraMetadata& jpegMetadata, uint8_t pipeline_depth,
uint8_t capture_intent, bool pprocDone, uint8_t fwk_cacMode,
bool firstMetadataInBatch, bool enableZSL, uint8_t fwkFlashMode);
camera_metadata_t* saveRequestSettings(const CameraMetadata& jpegMetadata,
camera3_capture_request_t *request);
int initParameters();
void deinitParameters();
QCamera3ReprocessChannel *addOfflineReprocChannel(const reprocess_config_t &config,
QCamera3ProcessingChannel *inputChHandle, int8_t pp_channel_idx = 0);
bool needRotationReprocess();
bool needJpegExifRotation();
bool useExifRotation();
bool needReprocess(cam_feature_mask_t postprocess_mask);
bool needJpegRotation();
cam_denoise_process_type_t getWaveletDenoiseProcessPlate();
cam_denoise_process_type_t getTemporalDenoiseProcessPlate();
void captureResultCb(mm_camera_super_buf_t *metadata,
camera3_stream_buffer_t *buffer, uint32_t frame_number,
bool isInputBuffer);
void internalMetaCb(mm_camera_super_buf_t *metadata);
cam_dimension_t getQuadraCfaDim();
cam_dimension_t calcMaxJpegDim();
bool needOnlineRotation();
uint32_t getJpegQuality();
QCamera3Exif *getExifData();
mm_jpeg_exif_params_t get3AExifParams();
uint8_t getMobicatMask();
static void getFlashInfo(const int cameraId,
bool& hasFlash,
char (&flashNode)[QCAMERA_MAX_FILEPATH_LENGTH]);
const char *getEepromVersionInfo();
const uint32_t *getLdafCalib();
void get3AVersion(cam_q3a_version_t &swVersion);
static void setBufferErrorStatus(QCamera3Channel*, uint32_t frameNumber,
camera3_buffer_status_t err, void *userdata);
void setBufferErrorStatus(QCamera3Channel*, uint32_t frameNumber,
camera3_buffer_status_t err);
// Implementation of QCameraThermalCallback
virtual int thermalEvtHandle(qcamera_thermal_level_enum_t *level,
void *userdata, void *data);
// Get dual camera related info
bool isDeviceLinked() {return mIsDeviceLinked;}
bool isMainCamera() {return mIsMainCamera;}
uint32_t getSensorMountAngle();
const cam_related_system_calibration_data_t *getRelatedCalibrationData();
int getCameraId() {return mCameraId;}
bool isQuadCfaSensor() {return m_bQuadraCfaSensor;}
int32_t deleteQCFACaptureChannel();
cam_dimension_t getQCFAComapitbleDim(const uint32_t& width,
const uint32_t& height);
template <typename fwkType, typename halType> struct QCameraMap {
fwkType fwk_name;
halType hal_name;
};
typedef struct {
const char *const desc;
cam_cds_mode_type_t val;
} QCameraPropMap;
uint32_t getCameraID() {return mCameraId;}
bool isDualCamera() { return mDualCamera; };
int32_t bundleRelatedCameras(bool enable_sync);
cam_hal_pp_type_t getHalPPType() {return m_halPPType;}
bool isDimSupportedbyCamType(const cam_dimension_t &dim, const cam_sync_type_t &type);
cam_dimension_t getOptimalSupportedDim(const cam_dimension_t &dim, const cam_sync_type_t &type);
cam_dimension_t getMaxSingleIspRes();
bool isAsymetricDim(const cam_dimension_t &dim);
bool isPPUpscaleNeededForDim(const cam_dimension_t &dim);
void rectifyStreamDimIfNeeded(
cam_dimension_t &dim, const cam_sync_type_t &type, bool &needUpScale);
uint32_t getBlurLevel() {return mBlurLevel;}
cam_dual_camera_perf_mode_t getLowPowerMode(cam_sync_type_t cam);
bool needHALPP() {return m_bNeedHalPP;}
cam_capability_t *getCamHalCapabilities();
bool isPPMaskSetForScaling(cam_feature_mask_t pp_mask);
bool isHALZSLEnabled() {return mHALZSL;}
bool isQuadraSizedDimension(cam_dimension_t &dim);
QCamera3PicChannel* getPicChannel() {return mPictureChannel;};
cam_dimension_t getMaxRawSize(uint32_t camera_id);
int32_t updateFrameMetaWithParams(metadata_buffer_t *frameMeta);
private:
// State transition conditions:
// "\" means not applicable
// "x" means not valid
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | | CLOSED | OPENED | INITIALIZED | CONFIGURED | STARTED | ERROR | DEINIT |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | CLOSED | \ | open | x | x | x | x | x |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | OPENED | close | \ | initialize | x | x | error | x |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// |INITIALIZED | close | x | \ | configure | x | error | x |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | CONFIGURED | close | x | x | configure | request | error | x |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | STARTED | close | x | x | configure | \ | error | x |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | ERROR | close | x | x | x | x | \ | any |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
// | DEINIT | close | x | x | x | x | x | \ |
// +------------+----------+----------+-------------+------------+---------+-------+--------+
typedef enum {
CLOSED,
OPENED,
INITIALIZED,
CONFIGURED,
STARTED,
ERROR,
DEINIT
} State;
FSMDB_t *FSM;
int openCamera();
int closeCamera();
int flush(bool restartChannels);
static size_t calcMaxJpegSize(uint32_t camera_id);
static void addStreamConfig(Vector<int32_t> &available_stream_configs,
int32_t scalar_format, const cam_dimension_t &dim,
int32_t config_type);
int validateCaptureRequest(camera3_capture_request_t *request,
List<InternalRequest> &internallyRequestedStreams);
int validateStreamDimensions(camera3_stream_configuration_t *streamList);
int validateStreamRotations(camera3_stream_configuration_t *streamList);
void deriveMinFrameDuration();
void handleBuffersDuringFlushLock(camera3_stream_buffer_t *buffer);
int32_t handlePendingReprocResults(uint32_t frame_number);
int64_t getMinFrameDuration(const camera3_capture_request_t *request);
void handleMetadataWithLock(mm_camera_super_buf_t *metadata_buf,
bool free_and_bufdone_meta_buf,
bool firstMetadataInBatch,
bool *p_is_metabuf_queued);
void handleBatchMetadata(mm_camera_super_buf_t *metadata_buf,
bool free_and_bufdone_meta_buf);
void handleBufferWithLock(camera3_stream_buffer_t *buffer,
uint32_t frame_number);
void handleInputBufferWithLock(uint32_t frame_number);
void unblockRequestIfNecessary();
void dumpMetadataToFile(tuning_params_t &meta, uint32_t &dumpFrameCount,
bool enabled, const char *type, uint32_t frameNumber);
static void getLogLevel();
void cleanAndSortStreamInfo();
void extractJpegMetadata(CameraMetadata& jpegMetadata,
const camera3_capture_request_t *request);
bool isSupportChannelNeeded(camera3_stream_configuration_t *streamList,
cam_stream_size_info_t stream_config_info);
bool IsQCFASelected(camera3_capture_request *request);
bool isHdrSnapshotRequest(camera3_capture_request *request);
bool isMultiFrameSnapshotRequest(camera3_capture_request *request);
bool isMFCRaw(camera3_capture_request *request);
bool isSWMFNRSnapshotRequest(camera3_capture_request *request);
int32_t setMobicat();
int32_t getSensorOutputSize(cam_dimension_t &sensor_dim, uint32_t cam_type = CAM_TYPE_MAIN);
int32_t setHalFpsRange(const CameraMetadata &settings,
metadata_buffer_t *hal_metadata);
int32_t extractSceneMode(const CameraMetadata &frame_settings, uint8_t metaMode,
metadata_buffer_t *hal_metadata);
int32_t setVideoHdrMode(metadata_buffer_t *hal_metadata,
cam_video_hdr_mode_t vhdr);
int32_t numOfSizesOnEncoder(const camera3_stream_configuration_t *streamList,
const cam_dimension_t &maxViewfinderSize);
void addToPPFeatureMask(int stream_format, uint32_t stream_idx,
cam_stream_size_info_t *mStreamConfigInfo);
int cacheFwConfiguredStreams(camera3_stream_configuration_t *streams_configuration);
Vector<uint32_t> getPhyIdListForCameraId(uint32_t cameraId);
int validateStreamsPhyIds(camera3_stream_configuration_t *streamList);
void setDCFeature(cam_feature_mask_t& feature_mask,
cam_stream_type_t stream_type, cam_dimension_t stream_dim);
void updateFpsInPreviewBuffer(metadata_buffer_t *metadata, uint32_t frame_number);
void updateTimeStampInPendingBuffers(uint32_t frameNumber, nsecs_t timestamp);
void enablePowerHint();
void disablePowerHint();
int32_t dynamicUpdateMetaStreamInfo();
int32_t startAllChannels();
int32_t stopAllChannels();
int32_t notifyErrorForPendingRequests();
void notifyError(uint32_t frameNumber,
camera3_error_msg_code_t errorCode);
int32_t getReprocessibleOutputStreamId(uint32_t &id);
int32_t handleCameraDeviceError();
bool checkFrameInPendingList(const uint32_t frame_number);
bool isOnEncoder(const cam_dimension_t max_viewfinder_size,
uint32_t width, uint32_t height);
camera_metadata_t* restoreHdrScene(uint8_t sceneMode, const camera_metadata_t *result);
void hdrPlusPerfLock(mm_camera_super_buf_t *metadata_buf);
static bool supportBurstCapture(uint32_t cameraId);
int32_t setBundleInfo();
int32_t setAuxBundleInfo();
int32_t setInstantAEC(const CameraMetadata &meta);
void setChannelQuadraMode(camera3_capture_request_t *req, bool mode);
static void convertLandmarks(cam_face_landmarks_info_t face, int32_t* landmarks);
static void setInvalidLandmarks(int32_t* landmarks);
static void setPAAFSupport(cam_feature_mask_t& feature_mask,
cam_stream_type_t stream_type,
cam_color_filter_arrangement_t filter_arrangement);
int32_t setSensorHDR(metadata_buffer_t *hal_metadata, bool enable,
bool isVideoHdrEnable = false);
int32_t captureQuadraCfaFrameInternal(camera3_capture_request_t *request);
int32_t switchStreamConfigInternal(uint32_t frame_number);
uint8_t mDualCamType;
inline bool isBayerMono() { return (mDualCamType == DUAL_CAM_BAYER_MONO); };
int32_t sendDualCamCmd(cam_dual_camera_cmd_type type,
uint8_t num_cam, void *info);
int32_t setDualCamBundleInfo(bool enable_sync,
uint8_t bundle_cam_idx);
int32_t configureHalPostProcess(bool bIsInput);
void switchMaster(uint32_t masterCam);
int32_t setDCMasterInfo(uint32_t camMaster);
int32_t setDCControls(uint32_t camMaster, uint32_t state,
bool bundleSnap, cam_fallback_mode_t fallbackMode);
int32_t setDCLowPowerMode(uint32_t state);
int32_t setDCFallbackMode(cam_fallback_mode_t fallback);
int32_t setDCDeferCamera(cam_dual_camera_defer_cmd_t type);
//dual camera api's
void rectifyStreamSizesByCamType(
cam_stream_size_info_t* streamsInfo, const cam_sync_type_t &type);
void initDCSettings();
void fillUBWCStats(camera3_stream_buffer_t *buffer);
void setColorMetadata(camera3_stream_buffer_t *buffer);
bool needZSLCapture(const camera3_capture_request_t *request);
int32_t addZSLChannel();
static void zsl_channel_cb(mm_camera_super_buf_t *recvd_frame, void *userdata);
int getConfiguredSATStreamDim(cam_dimension_t &dim);
bool isPreviewSATEnabled();
bool isHWRecoveryEnabled();
int doInternalRestart();
int initiateRecovery(bool defered = true);
camera3_device_t mCameraDevice;
uint32_t mCameraId;
uint32_t mBlurLevel;
cam_hal_pp_type_t m_halPPType;
mm_camera_vtbl_t *mCameraHandle;
bool mCameraInitialized;
camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT];
const camera3_callback_ops_t *mCallbackOps;
QCamera3MetadataChannel *mMetadataChannel;
QCamera3PicChannel *mPictureChannel;
QCamera3RawChannel *mRawChannel;
QCamera3SupportChannel *mSupportChannel;
QCamera3SupportChannel *mAnalysisChannel;
QCamera3RawDumpChannel *mRawDumpChannel;
QCamera3RegularChannel *mDummyBatchChannel;
QCamera3DepthChannel *mDepthChannel;
QCameraPerfLockMgr mPerfLockMgr;
QCameraThermalAdapter &m_thermalAdapter;
uint32_t mChannelHandle;
void saveExifParams(metadata_buffer_t *metadata);
mm_jpeg_exif_params_t mExifParams;
//First request yet to be processed after configureStreams
bool mFirstConfiguration;
bool mFlush;
bool mStreamOnPending;
bool mFlushPerf;
bool mEnableRawDump;
bool mForceHdrSnapshot;
uint32_t mHdrFrameNum;
uint32_t mMultiFrameCaptureNumber;
bool mHdrSnapshotRunning;
bool mMultiFrameSnapshotRunning;
bool mShouldSetSensorHdr;
QCamera3HeapMemory *mParamHeap;
metadata_buffer_t* mParameters;
metadata_buffer_t* mAuxParameters;
metadata_buffer_t* mPrevParameters;
CameraMetadata mCurJpegMeta;
bool m_bIsVideo;
bool m_bIs4KVideo;
bool m_bEisSupportedSize;
bool m_bEisEnable;
bool m_bEis3PropertyEnabled;
bool m_bEisSupported;
bool m_bLPMEnabled;
typedef struct {
cam_dimension_t dim;
int format;
uint32_t usage;
} InputStreamInfo;
InputStreamInfo mInputStreamInfo;
uint8_t m_MobicatMask;
uint8_t m_bTnrEnabled;
int8_t mSupportedFaceDetectMode;
uint8_t m_bTnrPreview;
uint8_t m_bSwTnrPreview;
uint8_t m_bTnrVideo;
uint8_t m_debug_avtimer;
uint8_t m_cacModeDisabled;
/* Data structure to store pending request */
typedef struct {
camera3_stream_t *stream;
camera3_stream_buffer_t *buffer;
// metadata needs to be consumed by the corresponding stream
// in order to generate the buffer.
bool need_metadata;
bool isZSL;
} RequestedBufferInfo;
typedef struct {
uint32_t frame_number;
uint32_t num_buffers;
int32_t request_id;
int32_t aux_request_id;
List<RequestedBufferInfo> buffers;
List<InternalRequest> internalRequestList;
int blob_request;
uint8_t bUrgentReceived;
nsecs_t timestamp;
camera3_stream_buffer_t *input_buffer;
const camera_metadata_t *settings;
CameraMetadata jpegMetadata;
uint8_t pipeline_depth;
uint32_t partial_result_cnt;
uint8_t capture_intent;
uint8_t aux_capture_intent;
uint8_t fwkCacMode;
uint8_t fwkAuxCacMode;
bool shutter_notified;
uint8_t scene_mode;
bool requested_on_aux;
bool requested_on_main;
bool received_main_meta;
bool requested_logical;
bool received_aux_meta;
mm_camera_super_buf_t *main_meta;
mm_camera_super_buf_t*aux_meta;
bool enableZSL;
uint8_t fwkFlashMode;
} PendingRequestInfo;
typedef struct {
uint32_t frame_number;
uint32_t stream_ID;
} PendingFrameDropInfo;
typedef struct {
camera3_notify_msg_t notify_msg;
camera3_stream_buffer_t buffer;
uint32_t frame_number;
} PendingReprocessResult;
class FrameNumberRegistry _orchestrationDb;
typedef KeyedVector<uint32_t, Vector<PendingBufferInfo> > FlushMap;
typedef List<QCamera3HardwareInterface::PendingRequestInfo>::iterator
pendingRequestIterator;
typedef List<QCamera3HardwareInterface::RequestedBufferInfo>::iterator
pendingBufferIterator;
List<PendingReprocessResult> mPendingReprocessResultList;
List<PendingRequestInfo> mPendingRequestsList;
List<PendingFrameDropInfo> mPendingFrameDropList;
/* Use last frame number of the batch as key and first frame number of the
* batch as value for that key */
KeyedVector<uint32_t, uint32_t> mPendingBatchMap;
cam_stream_ID_t mBatchedStreamsArray;
pthread_cond_t mRequestCond;
pthread_cond_t mHdrRequestCond;
uint32_t mPendingLiveRequest;
int32_t mCurrentRequestId;
int32_t mAuxCurrentRequestId;
cam_stream_size_info_t mStreamConfigInfo[CONFIG_INDEX_MAX];
cam_stream_size_info_t mAuxStreamConfigInfo;
//mutex for serialized access to camera3_device_ops_t functions
pthread_mutex_t mMutex;
Mutex mMultiFrameReqLock;
//condition used to signal flush after buffers have returned
pthread_cond_t mBuffersCond;
List<stream_info_t*> mStreamInfo;
int64_t mMinProcessedFrameDuration;
int64_t mMinJpegFrameDuration;
int64_t mMinRawFrameDuration;
uint32_t mMetaFrameCount;
bool mUpdateDebugLevel;
const camera_module_callbacks_t *mCallbacks;
uint8_t mCaptureIntent;
uint8_t mAuxCaptureIntent;
uint8_t mCacMode;
uint8_t mAuxCacMode;
metadata_buffer_t mReprocMeta; //scratch meta buffer
/* 0: Not batch, non-zero: Number of image buffers in a batch */
uint8_t mBatchSize;
// Used only in batch mode
uint8_t mToBeQueuedVidBufs;
// Fixed video fps
float mHFRVideoFps;
public:
uint32_t mOpMode;
bool mStreamConfig;
QCameraCommon mCommon;
cam_format_t mRdiModeFmt;
QCamera3QCfaCaptureChannel *mQCFACaptureChannel;
bool m_bQuadraCfaRequest;
bool m_bPreSnapQuadraCfaRequest;
QCameraFOVControl *m_pFovControl;
PendingBuffersMap mPendingBuffersMap;
bool m_bInSensorQCFA;
bool mbIsSWMFNRCapture;
bool isSecureMode() {return m_bIsSecureMode;}
QCamera3ProcessingChannel *mZSLChannel; //Interface ptr for actual ZSL channel.
QCamera3MultiRawChannel *mMultiRawChannel;
bool m_bMultiRawRequest;
private:
uint32_t mFirstFrameNumberInBatch;
camera3_stream_t mDummyBatchStream;
bool mNeedSensorRestart;
bool mPreviewStarted;
uint32_t mMinInFlightRequests;
uint32_t mMaxInFlightRequests;
// Param to trigger instant AEC.
bool mInstantAEC;
// Param to know when to reset AEC
bool mResetInstantAEC;
// Frame number, untill which we need to drop the frames.
uint32_t mInstantAECSettledFrameNumber;
// Max number of frames, that HAL will hold without displaying, for instant AEC mode.
uint8_t mAecSkipDisplayFrameBound;
// Counter to keep track of number of frames that took for AEC convergence.
uint8_t mInstantAecFrameIdxCount;
/* sensor output size with current stream configuration */
QCamera3CropRegionMapper mCropRegionMapper;
cam_feature_mask_t mCurrFeatureState;
/* Ldaf calibration data */
bool mLdafCalibExist;
uint32_t mLdafCalib[2];
int32_t mLastCustIntentFrmNum;
CameraMetadata mCachedMetadata;
bool cacheMetaIfNeeded(
mm_camera_super_buf_t *metadata_buf, uint32_t frame_number);
bool isTotalMetaReceivedForFrame(
uint32_t frame_number, PendingRequestInfo *request);
char *getUINT8Ptr(uint32_t cameraId);
void releasePhysicalId(const char **physicalId, uint32_t size);
camera_metadata_t *getPhysicalMeta(const mm_camera_super_buf_t *metadata,
PendingRequestInfo *request, bool dummyMeta,
cam_sync_type_t sync_type = CAM_TYPE_MAIN);
void allocateAndinitializeMetadata(camera3_capture_result *result,
PendingRequestInfo *request);
void releasePhysicalMetadata(const camera_metadata_t **meta, uint32_t num_of_meta);
void releaseCachedMeta(
PendingRequestInfo *request, QCamera3Channel *meta_channel);
bool shouldWaitForFrame(
PendingRequestInfo *request, mm_camera_super_buf_t *cur_meta,
uint32_t cur_frame_number, uint32_t &pendingFor);
bool checkIfMetaDropped(PendingRequestInfo *request);
static const QCameraMap<camera_metadata_enum_android_control_effect_mode_t,
cam_effect_mode_type> EFFECT_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_control_awb_mode_t,
cam_wb_mode_type> WHITE_BALANCE_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_control_scene_mode_t,
cam_scene_mode_type> SCENE_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_control_af_mode_t,
cam_focus_mode_type> FOCUS_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_color_correction_aberration_mode_t,
cam_aberration_mode_t> COLOR_ABERRATION_MAP[];
static const QCameraMap<camera_metadata_enum_android_control_ae_antibanding_mode_t,
cam_antibanding_mode_type> ANTIBANDING_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_lens_state_t,
cam_af_lens_state_t> LENS_STATE_MAP[];
static const QCameraMap<camera_metadata_enum_android_control_ae_mode_t,
cam_flash_mode_t> AE_FLASH_MODE_MAP[];
static const QCameraMap<camera_metadata_enum_android_flash_mode_t,
cam_flash_mode_t> FLASH_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_statistics_face_detect_mode_t,
cam_face_detect_mode_t> FACEDETECT_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_lens_info_focus_distance_calibration_t,
cam_focus_calibration_t> FOCUS_CALIBRATION_MAP[];
static const QCameraMap<camera_metadata_enum_android_sensor_test_pattern_mode_t,
cam_test_pattern_mode_t> TEST_PATTERN_MAP[];
static const QCameraMap<camera_metadata_enum_android_video_hdr_mode_t,
cam_video_hdr_mode_t> VIDEO_HDR_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_sensor_reference_illuminant1_t,
cam_illuminat_t> REFERENCE_ILLUMINANT_MAP[];
static const QCameraMap<int32_t,
cam_hfr_mode_t> HFR_MODE_MAP[];
static const QCameraMap<camera_metadata_enum_android_ir_mode_t,
cam_ir_mode_type_t> IR_MODES_MAP[];
static const QCameraMap<qcamera3_ext_instant_aec_mode_t,
cam_aec_convergence_type> INSTANT_AEC_MODES_MAP[];
static const QCameraMap<camera_metadata_enum_android_binning_correction_mode_t,
cam_binning_correction_mode_t> BINNING_CORRECTION_MODES_MAP[];
static const QCameraMap<qcamera3_ext_exposure_meter_mode_t,
cam_auto_exposure_mode_type> AEC_MODES_MAP[];
static const QCameraMap<qcamera3_ext_iso_mode_t,
cam_iso_mode_type> ISO_MODES_MAP[];
static const QCameraPropMap CDS_MAP[];
pendingRequestIterator erasePendingRequest(pendingRequestIterator i);
//GPU library to read buffer padding details.
void *lib_surface_utils;
int (*LINK_get_surface_pixel_alignment)();
uint32_t mSurfaceStridePadding;
State mState;
//Dual camera related params
bool mIsDeviceLinked;
bool mIsMainCamera;
uint8_t mLinkedCameraId;
QCamera3HeapMemory *m_pDualCamCmdHeap;
cam_dual_camera_cmd_info_t *m_pDualCamCmdPtr[MM_CAMERA_MAX_CAM_CNT];
cam_sync_related_sensors_event_info_t m_relCamSyncInfo;
Mutex mFlushLock;
bool m_bSensorHDREnabled;
uint8_t mCurrentSceneMode;
bool m_bOfflineIsp;
//for multiframe process capture
bool mbIsMultiFrameCapture;
uint8_t mMultiFrameCaptureCount;
// for quad cfa
bool m_bQuadraCfaSensor;
uint8_t mQuadraCfaStage;
bool m_bQuadraSizeConfigured;
int8_t m_ppChannelCnt;
typedef struct {
camera3_stream_configuration_t streamList;
uint32_t *usage;
}stream_configuration_t;
stream_configuration_t mStreamList;
pthread_mutex_t mRemosaicLock;
pthread_mutex_t mRecoveryLock;
//UDCF
bool mDualCamera;
bool m_bNeedHalPP;
bool mBundledSnapshot;
uint32_t mActiveCameras;
uint32_t mMasterCamera;
cam_fallback_mode_t mFallbackMode;
bool mLPMEnable;
cam_rtb_msg_type_t mRTBStatus;
bool m_bIsSecureMode;
bool m_bStopPicChannel;
bool is_aux_configured = false; //only for dualcamera usecase
bool is_main_configured = false; //only for dual camera usecase
bool is_logical_configured = false; //only for dual camera usecase
zsl_stream_type_t mHALZSL;
bool mFlashNeeded;
cam_perf_info_t mSettingInfo[CONFIG_INDEX_MAX];
uint8_t mSessionId;
cam_hfr_mode_t mHFRMode;
//for multi frame raw capture
uint8_t mMultiFrameRAWCaptureCount;
//quadra
camera3_capture_request_t **quad_req;
bool m_bRecoveryDone;
CameraMetadata mSavedParams;
uint32_t sync_counter;
};
}; // namespace qcamera
#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */

File diff suppressed because it is too large Load diff

182
QCamera2/HAL3/QCamera3Mem.h Normal file
View file

@ -0,0 +1,182 @@
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3HWI_MEM_H__
#define __QCAMERA3HWI_MEM_H__
// System dependencies
#include <linux/msm_ion.h>
#if TARGET_ION_ABI_VERSION >= 2
#include <ion/ion.h>
#include <linux/dma-buf.h>
#endif //TARGET_ION_ABI_VERSION
#include <utils/Mutex.h>
// Camera dependencies
#include "hardware/camera3.h"
extern "C" {
#include "mm_camera_interface.h"
}
#if TARGET_ION_ABI_VERSION >= 2
#ifndef CAM_CACHE_OPS
#define CAM_CACHE_OPS
enum {
CAM_CLEAN_CACHE,
CAM_INV_CACHE,
CAM_CLEAN_INV_CACHE
};
#define ION_IOC_CLEAN_CACHES CAM_CLEAN_CACHE
#define ION_IOC_INV_CACHES CAM_INV_CACHE
#define ION_IOC_CLEAN_INV_CACHES CAM_CLEAN_INV_CACHE
#endif //CAM_CACHE_OPS
#endif //TARGET_ION_ABI_VERSION
using namespace android;
namespace qcamera {
// Base class for all memory types. Abstract.
class QCamera3Memory {
public:
int cleanCache(uint32_t index)
{
return cacheOps(index, ION_IOC_CLEAN_CACHES);
}
int invalidateCache(uint32_t index)
{
return cacheOps(index, ION_IOC_INV_CACHES);
}
int cleanInvalidateCache(uint32_t index)
{
return cacheOps(index, ION_IOC_CLEAN_INV_CACHES);
}
int getFd(uint32_t index);
ssize_t getSize(uint32_t index);
uint32_t getCnt();
virtual int cacheOps(uint32_t index, unsigned int cmd) = 0;
virtual int getMatchBufIndex(void *object) = 0;
virtual void *getPtr(uint32_t index) = 0;
virtual int32_t markFrameNumber(uint32_t index, uint32_t frameNumber) = 0;
virtual int32_t getFrameNumber(uint32_t index) = 0;
virtual int32_t getBufferIndex(uint32_t frameNumber) = 0;
virtual int32_t getOldestFrameNumber(uint32_t &index) = 0;
QCamera3Memory();
virtual ~QCamera3Memory();
int32_t getBufDef(const cam_frame_len_offset_t &offset,
mm_camera_buf_def_t &bufDef, uint32_t index);
protected:
struct QCamera3MemInfo {
int fd;
int main_ion_fd;
ion_user_handle_t handle;
size_t size;
};
int cacheOpsInternal(uint32_t index, unsigned int cmd, void *vaddr);
virtual void *getPtrLocked(uint32_t index) = 0;
uint32_t mBufferCount;
struct QCamera3MemInfo mMemInfo[MM_CAMERA_MAX_NUM_FRAMES];
void *mPtr[MM_CAMERA_MAX_NUM_FRAMES];
int32_t mCurrentFrameNumbers[MM_CAMERA_MAX_NUM_FRAMES];
Mutex mLock;
};
// Internal heap memory is used for memories used internally
// They are allocated from /dev/ion. Examples are: capabilities,
// parameters, metadata, and internal YUV data for jpeg encoding.
class QCamera3HeapMemory : public QCamera3Memory {
public:
QCamera3HeapMemory(uint32_t maxCnt, bool isSecure = false);
virtual ~QCamera3HeapMemory();
int allocate(size_t size);
int allocateOne(size_t size);
void deallocate();
virtual int cacheOps(uint32_t index, unsigned int cmd);
virtual int getMatchBufIndex(void *object);
virtual void *getPtr(uint32_t index);
virtual int32_t markFrameNumber(uint32_t index, uint32_t frameNumber);
virtual int32_t getFrameNumber(uint32_t index);
virtual int32_t getBufferIndex(uint32_t frameNumber);
virtual int32_t getOldestFrameNumber(uint32_t &index);
protected:
virtual void *getPtrLocked(uint32_t index);
private:
int allocOneBuffer(struct QCamera3MemInfo &memInfo,
unsigned int heap_id, size_t size);
void deallocOneBuffer(struct QCamera3MemInfo &memInfo);
uint32_t mMaxCnt;
bool m_bIsSecureMode;
};
// Gralloc Memory shared with frameworks
class QCamera3GrallocMemory : public QCamera3Memory {
public:
QCamera3GrallocMemory(uint32_t startIdx, bool isSecure);
virtual ~QCamera3GrallocMemory();
int registerBuffer(buffer_handle_t *buffer, cam_stream_type_t type);
int32_t unregisterBuffer(size_t idx);
void unregisterBuffers();
virtual int cacheOps(uint32_t index, unsigned int cmd);
virtual int getMatchBufIndex(void *object);
virtual void *getPtr(uint32_t index);
virtual int32_t markFrameNumber(uint32_t index, uint32_t frameNumber);
virtual int32_t getFrameNumber(uint32_t index);
virtual int32_t getBufferIndex(uint32_t frameNumber);
virtual int32_t getOldestFrameNumber(uint32_t &index);
void *getBufferHandle(uint32_t index);
void switchMaster(uint32_t masterCam);
protected:
virtual void *getPtrLocked(uint32_t index);
private:
int32_t unregisterBufferLocked(size_t idx);
int32_t getFreeIndexLocked();
buffer_handle_t *mBufferHandle[MM_CAMERA_MAX_NUM_FRAMES];
struct private_handle_t *mPrivateHandle[MM_CAMERA_MAX_NUM_FRAMES];
uint32_t mStartIdx;
uint32_t mMasterCam;
bool m_bIsSecureMode;
};
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,269 @@
/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCamera3_POSTPROC_H__
#define __QCamera3_POSTPROC_H__
// Camera dependencies
#include "hardware/camera3.h"
#include "QCamera3HALHeader.h"
#include "QCameraCmdThread.h"
#include "QCameraQueue.h"
#include "QCameraPerf.h"
#include "QCameraPprocManager.h"
extern "C" {
#include "mm_camera_interface.h"
#include "mm_jpeg_interface.h"
}
namespace qcamera {
class QCamera3Exif;
class QCamera3ProcessingChannel;
class QCamera3ReprocessChannel;
class QCamera3Stream;
class QCamera3StreamMem;
typedef struct {
camera3_stream_buffer_t src_frame;// source frame
mm_camera_buf_def_t metadata_buffer;
mm_camera_buf_def_t input_buffer;
reprocess_config_t reproc_config;
buffer_handle_t *output_buffer;
uint32_t frameNumber;
} qcamera_fwk_input_pp_data_t;
typedef struct {
uint32_t jobId; // job ID
uint32_t client_hdl; // handle of jpeg client (obtained when open jpeg)
mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done)
mm_camera_super_buf_t *src_reproc_frame; // original source frame for reproc if not NULL
qcamera_fwk_input_pp_data_t *fwk_frame; // source framework buffer
qcamera_fwk_input_pp_data_t *fwk_src_buffer; // original framework source frame for reproc
QCamera3Exif *pJpegExifObj;
metadata_buffer_t *metadata;
mm_camera_super_buf_t *src_metadata;
jpeg_settings_t *jpeg_settings;
bool halPPAllocatedBuf;
mm_camera_buf_def_t *hal_pp_bufs; // bufs allocates for HAL PP
QCameraHeapMemory *snapshot_heap; // heap memory of snapshot buffer
QCameraHeapMemory *metadata_heap; // heap memory of metadata buffer
} qcamera_hal3_jpeg_data_t;
typedef struct {
uint32_t jobId; // job ID
mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done)
qcamera_fwk_input_pp_data_t *fwk_src_frame;// source frame
metadata_buffer_t *metadata;
jpeg_settings_t *jpeg_settings;
jpeg_settings_t *ppOutput_jpeg_settings;
mm_camera_super_buf_t *src_metadata;
mm_camera_super_buf_t *reprocessed_src_frame; // reprocessed output, valid in multi reprocess pass case
int8_t pp_ch_idx;
uint32_t frameNumber;
} qcamera_hal3_pp_data_t;
typedef struct {
mm_camera_super_buf_t *input;
buffer_handle_t *output;
uint32_t frameNumber;
} qcamera_hal3_pp_buffer_t;
#define MAX_HAL3_EXIF_TABLE_ENTRIES 50
typedef struct {
mm_camera_super_buf_t *metabuf;
uint32_t metaFrameNumber;
bool dropFrame;
}qcamera_hal3_meta_pp_buffer_t;
typedef struct {
qcamera_hal3_pp_buffer_t *reprocBuf;
qcamera_hal3_meta_pp_buffer_t *metaBuffer;
}ReprocessBuffer;
typedef struct {
qcamera_hal3_jpeg_data_t *jpeg_job;
mm_jpeg_output_t jpeg_image;
void * user_data;
}qcamera_hal3_mpo_data_t;
typedef struct {
mm_jpeg_output_t main_image;
mm_jpeg_output_t aux_images[MM_JPEG_MAX_MPO_IMAGES -1];
mm_jpeg_output_t output;
uint32_t num_of_aux_image;
}qcamera_hal3_mpo_compose_info_t;
class QCamera3Exif
{
public:
QCamera3Exif();
virtual ~QCamera3Exif();
int32_t addEntry(exif_tag_id_t tagid,
exif_tag_type_t type,
uint32_t count,
void *data);
uint32_t getNumOfEntries() {return m_nNumEntries;};
QEXIF_INFO_DATA *getEntries() {return m_Entries;};
private:
QEXIF_INFO_DATA m_Entries[MAX_HAL3_EXIF_TABLE_ENTRIES]; // exif tags for JPEG encoder
uint32_t m_nNumEntries; // number of valid entries
};
class QCamera3PostProcessor
{
public:
QCamera3PostProcessor(QCamera3ProcessingChannel *ch_ctrl);
virtual ~QCamera3PostProcessor();
int32_t init(QCamera3StreamMem *mMemory);
int32_t initJpeg(jpeg_encode_callback_t jpeg_cb,
mpo_encode_callback_t mpo_cb,
cam_dimension_t *m_max_pic_dim,
void *user_data);
int32_t deinit();
int32_t start(const reprocess_config_t &config);
int32_t stop(bool isHDR = false);
int32_t flush();
int32_t processData(qcamera_fwk_input_pp_data_t *frame);
int32_t processData(mm_camera_super_buf_t *input,
buffer_handle_t *output, uint32_t frameNumber);
int32_t processData(mm_camera_super_buf_t *input);
int32_t cancelFramePProc(uint32_t framenum);
int32_t processPPData(mm_camera_super_buf_t *frame, const metadata_buffer_t *p_metadata = NULL);
int32_t processPPMetadata(mm_camera_super_buf_t *reproc_meta,uint32_t framenum, bool dropFrame);
int32_t processJpegSettingData(jpeg_settings_t *jpeg_settings);
static void processJpegData(jpeg_job_status_t status,
uint32_t /*client_hdl*/,
uint32_t jobId,
mm_jpeg_output_t *p_output,
void *userdata);
int32_t composeMpo(qcamera_hal3_mpo_compose_info_t &mpo_info, void *userdata);
void doNextJob();
qcamera_hal3_pp_data_t *dequeuePPJob(uint32_t frameNumber);
qcamera_hal3_jpeg_data_t *findJpegJobByJobId(uint32_t jobId);
void releaseJpegJobData(qcamera_hal3_jpeg_data_t *job);
int32_t releaseOfflineBuffers(bool all);
void releasePPJobData(qcamera_hal3_pp_data_t *job);
int32_t timeoutFrame(uint32_t frameNumber);
bool releaseReprocMetaBuffer(uint32_t);
static void processHalPPDataCB(qcamera_hal_pp_data_t *pOutput, void* pUserData);
static void releaseSuperBufCb(mm_camera_super_buf_t *super_buf, void* pUserData);
void setMpoMode(bool enable) {m_bMpoEnabled = enable;}
bool isMpoEnabled() { return m_bMpoEnabled; }
int releaseFreeJpegSessions();
void eraseJpegSetting(uint32_t resultFrameNumber);
private:
int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2);
mm_jpeg_color_format getColorfmtFromImgFmt(cam_format_t img_fmt);
mm_jpeg_format_t getJpegImgTypeFromImgFmt(cam_format_t img_fmt);
int32_t getJpegEncodeConfig(mm_jpeg_encode_params_t& encode_parm,
QCamera3Stream *main_stream,
jpeg_settings_t *jpeg_settings,
mm_camera_buf_def_t *input_buf = NULL);
int32_t getFWKJpegEncodeConfig(mm_jpeg_encode_params_t& encode_parm,
qcamera_fwk_input_pp_data_t *frame,
jpeg_settings_t *jpeg_settings);
QCamera3Exif * getExifData(metadata_buffer_t *metadata,
jpeg_settings_t *jpeg_settings, bool needJpegExifRotation);
int32_t encodeData(qcamera_hal3_jpeg_data_t *jpeg_job_data,
uint8_t &needNewSess);
int32_t encodeFWKData(qcamera_hal3_jpeg_data_t *jpeg_job_data,
uint8_t &needNewSess);
void releaseSuperBuf(mm_camera_super_buf_t *super_buf);
static void releaseNotifyData(void *user_data, void *cookie);
int32_t processRawImageImpl(mm_camera_super_buf_t *recvd_frame);
static void releaseJpegData(void *data, void *user_data);
static void releasePPInputData(void *data, void *user_data);
static void releaseMetadata(void *data, void *user_data);
static void releaseOngoingPPData(void *data, void *user_data);
static bool matchMetaFrameNum(void *data, void *user_data, void *match_data);
static bool matchReprocessFrameNum(void *data, void *user_data, void *match_data);
static bool matchJpegSetting(void *data, void *user_data, void *match_data);
static void *dataProcessRoutine(void *data);
qcamera_hal3_meta_pp_buffer_t * isMetaMatched(uint32_t resultFrameNumber);
qcamera_hal3_pp_buffer_t * isFrameMatched(uint32_t resultFrameNumber);
bool needsReprocess(qcamera_fwk_input_pp_data_t *frame);
int32_t processHalPPData(qcamera_hal_pp_data_t *pData);
void createHalPPManager();
int32_t initHalPPManager();
bool isHalPPEnabled() { return (m_pHalPPManager != NULL);}
QCamera3Channel *getChannelByHandle(uint32_t channelHandle);
private:
QCamera3ProcessingChannel *m_parent;
jpeg_encode_callback_t mJpegCB;
mpo_encode_callback_t mMpoCB;
void * mJpegUserData;
mm_jpeg_ops_t mJpegHandle;
mm_jpeg_mpo_ops_t mMpoHandle;
uint32_t mJpegClientHandle;
uint32_t mJpegSessionId;
cam_jpeg_metadata_t mJpegMetadata;
uint32_t m_bThumbnailNeeded;
QCamera3StreamMem *mOutputMem;
int8_t m_ppChannelCnt;
QCamera3ReprocessChannel * m_pReprocChannel[2];
bool m_bMpoEnabled;
uint32_t mReprocessFrameNum;
List<ReprocessBuffer> mReprocessNode;
QCameraQueue m_inputPPQ; // input queue for postproc
QCameraQueue m_inputFWKPPQ; // framework input queue for postproc
QCameraQueue m_inputMultiReprocQ;
QCameraQueue m_ongoingPPQ; // ongoing postproc queue
QCameraQueue m_inputJpegQ; // input jpeg job queue
QCameraQueue m_ongoingJpegQ; // ongoing jpeg job queue
QCameraQueue m_inputRawQ; // input raw job queue
QCameraQueue m_inputMetaQ; // input meta queue
QCameraQueue m_jpegSettingsQ; // input jpeg setting queue
QCameraCmdThread m_dataProcTh; // thread for data processing
QCameraPerfLockMgr mPerfLockMgr;
pthread_mutex_t mReprocJobLock;
pthread_mutex_t mHDRJobLock;
pthread_cond_t mProcChStopCond;
QCameraHALPPManager *m_pHalPPManager; // HAL Post process block
mm_dimension max_pic_size;
public:
bool mChannelStop;
static List<qcamera_hal3_mpo_data_t> mMpoInputData;
List<uint32_t> mFreeJpegSessions;
List<uint32_t> mCancelpprocReqFrameList;
};
}; // namespace qcamera
#endif /* __QCamera3_POSTPROC_H__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,190 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3_STREAM_H__
#define __QCAMERA3_STREAM_H__
// System dependencies
#include <utils/Mutex.h>
// Camera dependencies
#include "QCamera3Mem.h"
#include "QCamera3StreamMem.h"
#include "QCameraCmdThread.h"
#include "QCameraQueue.h"
extern "C" {
#include "mm_camera_interface.h"
}
namespace qcamera {
class QCamera3Channel;
class QCamera3Stream;
typedef void (*hal3_stream_cb_routine)(mm_camera_super_buf_t *frame,
QCamera3Stream *stream,
void *userdata);
class QCamera3Stream
{
public:
QCamera3Stream(uint32_t camHandle,
uint32_t chId,
mm_camera_ops_t *camOps,
cam_padding_info_t *paddingInfo,
QCamera3Channel *channel);
virtual ~QCamera3Stream();
virtual int32_t init(cam_stream_type_t streamType,
cam_format_t streamFormat,
cam_dimension_t streamDim,
cam_rotation_t streamRotation,
cam_stream_reproc_config_t* reprocess_config,
uint8_t minStreamBufNum,
cam_feature_mask_t postprocess_mask,
cam_is_type_t is_type,
uint32_t batchSize,
hal3_stream_cb_routine stream_cb,
void *userdata,
bool isSecureMode,
bool bNeedBundling = false);
virtual int32_t bufDone(uint32_t index);
virtual int32_t cancelBuffer(uint32_t index);
virtual int32_t bufRelease(int32_t index);
virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs);
virtual int32_t start();
virtual int32_t stop();
virtual int32_t queueBatchBuf();
static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata);
static void *dataProcRoutine(void *data);
uint32_t getMyHandle() const {return mHandle;}
cam_stream_type_t getMyType() const;
int32_t getFrameOffset(cam_frame_len_offset_t &offset);
int32_t getFrameDimension(cam_dimension_t &dim);
int32_t getFormat(cam_format_t &fmt);
int32_t setCropInfo(cam_rect_t crop);
int32_t getParameter(cam_stream_parm_buffer_t &param);
QCamera3StreamMem *getStreamBufs() {return mStreamBufs;};
uint32_t getMyServerID();
int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx,
int32_t plane_idx, int fd, void *buffer, size_t size);
int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx);
int32_t setParameter(cam_stream_parm_buffer_t &param,
uint32_t cam_type = CAM_TYPE_MAIN);
cam_stream_info_t* getStreamInfo() const {return mStreamInfo; };
static void releaseFrameData(void *data, void *user_data);
int32_t timeoutFrame(int32_t bufIdx);
bool isDualStream(){return mDualStream;};
void initDCSettings();
void switchMaster(uint32_t masterCam);
private:
uint32_t mCamHandle;
uint32_t mChannelHandle;
uint32_t mHandle; // stream handle from mm-camera-interface
mm_camera_ops_t *mCamOps;
cam_stream_info_t *mStreamInfo; // ptr to stream info buf
mm_camera_stream_mem_vtbl_t mMemVtbl;
mm_camera_map_unmap_ops_tbl_t *mMemOps;
uint8_t mNumBufs;
hal3_stream_cb_routine mDataCB;
void *mUserData;
QCameraQueue mDataQ;
List<int32_t> mTimeoutFrameQ;
Mutex mTimeoutFrameQLock;
QCameraCmdThread mProcTh; // thread for dataCB
QCamera3HeapMemory *mStreamInfoBuf;
QCamera3StreamMem *mStreamBufs;
mm_camera_buf_def_t *mBufDefs;
cam_frame_len_offset_t mFrameLenOffset;
cam_rect_t mCropInfo;
cam_padding_info_t mPaddingInfo;
QCamera3Channel *mChannel;
Mutex mLock; //Lock controlling access to 'mBufDefs'
Mutex mParamLock; //Lock setparam
uint32_t mBatchSize; // 0: No batch, non-0: Number of imaage bufs in a batch
uint8_t mNumBatchBufs; //Number of batch buffers which can hold image bufs
QCamera3HeapMemory *mStreamBatchBufs; //Pointer to batch buffers memory
mm_camera_buf_def_t *mBatchBufDefs; //Pointer to array of batch bufDefs
mm_camera_buf_def_t *mCurrentBatchBufDef; //batch buffer in progress during
//aggregation
uint32_t mBufsStaged; //Number of image buffers aggregated into
//currentBatchBufDef
QCameraQueue mFreeBatchBufQ; //Buffer queue containing empty batch buffers
static int32_t get_bufs(
cam_frame_len_offset_t *offset,
uint8_t *num_bufs,
uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t put_bufs(
mm_camera_map_unmap_ops_tbl_t *ops_tbl,
void *user_data);
static int32_t invalidate_buf(uint32_t index, void *user_data);
static int32_t clean_invalidate_buf(uint32_t index, void *user_data);
static int32_t clean_buf(uint32_t index, void *user_data);
int32_t getBufs(cam_frame_len_offset_t *offset,
uint8_t *num_bufs,
uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t invalidateBuf(uint32_t index);
int32_t cleanInvalidateBuf(uint32_t index);
int32_t cleanBuf(uint32_t index);
int32_t getBatchBufs(
uint8_t *num_bufs, uint8_t **initial_reg_flag,
mm_camera_buf_def_t **bufs,
mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t putBatchBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
int32_t getBatchBufDef(mm_camera_buf_def_t& batchBufDef,
int32_t index);
int32_t aggregateBufToBatch(mm_camera_buf_def_t& bufDef);
int32_t handleBatchBuffer(mm_camera_super_buf_t *superBuf);
static const char* mStreamNames[CAM_STREAM_TYPE_MAX];
void flushFreeBatchBufQ();
bool mDualStream;
uint32_t mMasterCam;
};
}; // namespace qcamera
#endif /* __QCAMERA3_STREAM_H__ */

View file

@ -0,0 +1,570 @@
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCamera3StreamMem"
// System dependencies
#include "gralloc_priv.h"
// Camera dependencies
#include "QCamera3StreamMem.h"
using namespace android;
namespace qcamera {
/*===========================================================================
* FUNCTION : QCamera3StreamMem
*
* DESCRIPTION: default constructor of QCamera3StreamMem
*
* PARAMETERS : none
*
* RETURN : None
*==========================================================================*/
QCamera3StreamMem::QCamera3StreamMem(uint32_t maxHeapBuffer, bool queueHeapBuffers, bool isSecure) :
mHeapMem(maxHeapBuffer, isSecure),
mGrallocMem(maxHeapBuffer, isSecure),
mMaxHeapBuffers(maxHeapBuffer),
mQueueHeapBuffers(queueHeapBuffers)
{
}
/*===========================================================================
* FUNCTION : QCamera3StreamMem
*
* DESCRIPTION: destructor of QCamera3StreamMem
*
* PARAMETERS : none
*
* RETURN : None
*==========================================================================*/
QCamera3StreamMem::~QCamera3StreamMem()
{
clear();
}
/*===========================================================================
* FUNCTION : getCnt
*
* DESCRIPTION: query number of buffers allocated/registered
*
* PARAMETERS : none
*
* RETURN : number of buffers allocated
*==========================================================================*/
uint32_t QCamera3StreamMem::getCnt()
{
Mutex::Autolock lock(mLock);
return (mHeapMem.getCnt() + mGrallocMem.getCnt());
}
/*===========================================================================
* FUNCTION : getRegFlags
*
* DESCRIPTION: query initial reg flags
*
* PARAMETERS :
* @regFlags: initial reg flags of the allocated/registered buffers
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3StreamMem::getRegFlags(uint8_t * regFlags)
{
// Assume that all buffers allocated can be queued.
for (uint32_t i = 0; i < mHeapMem.getCnt(); i ++)
regFlags[i] = (mQueueHeapBuffers ? 1 : 0);
return NO_ERROR;
}
/*===========================================================================
* FUNCTION : getFd
*
* DESCRIPTION: return file descriptor of the indexed buffer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : file descriptor
*==========================================================================*/
int QCamera3StreamMem::getFd(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.getFd(index);
else
return mGrallocMem.getFd(index);
}
/*===========================================================================
* FUNCTION : getSize
*
* DESCRIPTION: return buffer size of the indexed buffer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : buffer size
*==========================================================================*/
ssize_t QCamera3StreamMem::getSize(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.getSize(index);
else
return mGrallocMem.getSize(index);
}
/*===========================================================================
* FUNCTION : invalidateCache
*
* DESCRIPTION: invalidate the cache of the indexed buffer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3StreamMem::invalidateCache(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.invalidateCache(index);
else
return mGrallocMem.invalidateCache(index);
}
/*===========================================================================
* FUNCTION : cleanInvalidateCache
*
* DESCRIPTION: clean and invalidate the cache of the indexed buffer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3StreamMem::cleanInvalidateCache(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.cleanInvalidateCache(index);
else
return mGrallocMem.cleanInvalidateCache(index);
}
/*===========================================================================
* FUNCTION : cleanCache
*
* DESCRIPTION: clean the cache of the indexed buffer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3StreamMem::cleanCache(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.cleanCache(index);
else
return mGrallocMem.cleanCache(index);
}
/*===========================================================================
* FUNCTION : getBufDef
*
* DESCRIPTION: query detailed buffer information
*
* PARAMETERS :
* @offset : [input] frame buffer offset
* @bufDef : [output] reference to struct to store buffer definition
* @index : [input] index of the buffer
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCamera3StreamMem::getBufDef(const cam_frame_len_offset_t &offset,
mm_camera_buf_def_t &bufDef, uint32_t index)
{
int32_t ret = NO_ERROR;
if (index < mMaxHeapBuffers)
ret = mHeapMem.getBufDef(offset, bufDef, index);
else
ret = mGrallocMem.getBufDef(offset, bufDef, index);
bufDef.mem_info = (void *)this;
return ret;
}
/*===========================================================================
* FUNCTION : getPtr
*
* DESCRIPTION: return virtual address of the indexed buffer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : virtual address
*==========================================================================*/
void* QCamera3StreamMem::getPtr(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.getPtr(index);
else
return mGrallocMem.getPtr(index);
}
/*===========================================================================
* FUNCTION : valid
*
* DESCRIPTION: return whether there is a valid buffer at the current index
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : true if there is a buffer, false otherwise
*==========================================================================*/
bool QCamera3StreamMem::valid(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return (mHeapMem.getSize(index) > 0);
else
return (mGrallocMem.getSize(index) > 0);
}
/*===========================================================================
* FUNCTION : registerBuffer
*
* DESCRIPTION: registers frameworks-allocated gralloc buffer_handle_t
*
* PARAMETERS :
* @buffers : buffer_handle_t pointer
* @type : cam_stream_type_t
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3StreamMem::registerBuffer(buffer_handle_t *buffer,
cam_stream_type_t type)
{
Mutex::Autolock lock(mLock);
return mGrallocMem.registerBuffer(buffer, type);
}
/*===========================================================================
* FUNCTION : unregisterBuffer
*
* DESCRIPTION: unregister buffer
*
* PARAMETERS :
* @idx : unregister buffer at index 'idx'
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCamera3StreamMem::unregisterBuffer(size_t idx)
{
Mutex::Autolock lock(mLock);
return mGrallocMem.unregisterBuffer(idx);
}
/*===========================================================================
* FUNCTION : getMatchBufIndex
*
* DESCRIPTION: query buffer index by object ptr
*
* PARAMETERS :
* @opaque : opaque ptr
*
* RETURN : buffer index if match found,
* -1 if failed
*==========================================================================*/
int QCamera3StreamMem::getMatchBufIndex(void *object)
{
Mutex::Autolock lock(mLock);
return mGrallocMem.getMatchBufIndex(object);
}
/*===========================================================================
* FUNCTION : getBufferHandle
*
* DESCRIPTION: return framework pointer
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : buffer ptr if match found
NULL if failed
*==========================================================================*/
void *QCamera3StreamMem::getBufferHandle(uint32_t index)
{
Mutex::Autolock lock(mLock);
return mGrallocMem.getBufferHandle(index);
}
/*===========================================================================
* FUNCTION : unregisterBuffers
*
* DESCRIPTION: unregister buffers
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
void QCamera3StreamMem::unregisterBuffers()
{
Mutex::Autolock lock(mLock);
mGrallocMem.unregisterBuffers();
}
/*===========================================================================
* FUNCTION : allocate
*
* DESCRIPTION: allocate requested number of buffers of certain size
*
* PARAMETERS :
* @count : number of buffers to be allocated
* @size : lenght of the buffer to be allocated
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera3StreamMem::allocateAll(size_t size)
{
Mutex::Autolock lock(mLock);
return mHeapMem.allocate(size);
}
int QCamera3StreamMem::allocateOne(size_t size)
{
Mutex::Autolock lock(mLock);
return mHeapMem.allocateOne(size);
}
/*===========================================================================
* FUNCTION : deallocate
*
* DESCRIPTION: deallocate heap buffers
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
void QCamera3StreamMem::deallocate()
{
Mutex::Autolock lock(mLock);
mHeapMem.deallocate();
}
/*===========================================================================
* FUNCTION : markFrameNumber
*
* DESCRIPTION: We use this function from the request call path to mark the
* buffers with the frame number they are intended for this info
* is used later when giving out callback & it is duty of PP to
* ensure that data for that particular frameNumber/Request is
* written to this buffer.
* PARAMETERS :
* @index : index of the buffer
* @frame# : Frame number from the framework
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCamera3StreamMem::markFrameNumber(uint32_t index, uint32_t frameNumber)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.markFrameNumber(index, frameNumber);
else
return mGrallocMem.markFrameNumber(index, frameNumber);
}
/*===========================================================================
* FUNCTION : getOldestFrameNumber
*
* DESCRIPTION: We use this to fetch the frameNumber expected as per FIFO
*
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : int32_t frameNumber
* positive/zero -- success
* negative failure
*==========================================================================*/
int32_t QCamera3StreamMem::getOldestFrameNumber(uint32_t &bufIdx)
{
Mutex::Autolock lock(mLock);
int32_t oldest = INT_MAX;
bool empty = true;
if (mHeapMem.getCnt()){
empty = false;
oldest = mHeapMem.getOldestFrameNumber(bufIdx);
}
if (mGrallocMem.getCnt()) {
uint32_t grallocBufIdx;
int32_t oldestGrallocFrameNumber = mGrallocMem.getOldestFrameNumber(grallocBufIdx);
if (empty || (!empty && (oldestGrallocFrameNumber < oldest))){
oldest = oldestGrallocFrameNumber;
bufIdx = grallocBufIdx;
}
empty = false;
}
if (empty )
return -1;
else
return oldest;
}
/*===========================================================================
* FUNCTION : getFrameNumber
*
* DESCRIPTION: We use this to fetch the frameNumber for the request with which
* this buffer was given to HAL
*
*
* PARAMETERS :
* @index : index of the buffer
*
* RETURN : int32_t frameNumber
* positive/zero -- success
* negative failure
*==========================================================================*/
int32_t QCamera3StreamMem::getFrameNumber(uint32_t index)
{
Mutex::Autolock lock(mLock);
if (index < mMaxHeapBuffers)
return mHeapMem.getFrameNumber(index);
else
return mGrallocMem.getFrameNumber(index);
}
/*===========================================================================
* FUNCTION : getGrallocBufferIndex
*
* DESCRIPTION: We use this to fetch the gralloc buffer index based on frameNumber
*
* PARAMETERS :
* @frameNumber : frame Number
*
* RETURN : int32_t buffer index
* positive/zero -- success
* negative failure
*==========================================================================*/
int32_t QCamera3StreamMem::getGrallocBufferIndex(uint32_t frameNumber)
{
Mutex::Autolock lock(mLock);
int32_t index = mGrallocMem.getBufferIndex(frameNumber);
return index;
}
/*===========================================================================
* FUNCTION : getHeapBufferIndex
*
* DESCRIPTION: We use this to fetch the heap buffer index based on frameNumber
*
* PARAMETERS :
* @frameNumber : frame Number
*
* RETURN : int32_t buffer index
* positive/zero -- success
* negative failure
*==========================================================================*/
int32_t QCamera3StreamMem::getHeapBufferIndex(uint32_t frameNumber)
{
Mutex::Autolock lock(mLock);
int32_t index = mHeapMem.getBufferIndex(frameNumber);
return index;
}
/*===========================================================================
* FUNCTION : getBufferIndex
*
* DESCRIPTION: We use this to fetch the buffer index based on frameNumber
*
* PARAMETERS :
* @frameNumber : frame Number
*
* RETURN : int32_t buffer index
* positive/zero -- success
* negative failure
*==========================================================================*/
int32_t QCamera3StreamMem::getBufferIndex(uint32_t frameNumber)
{
Mutex::Autolock lock(mLock);
int32_t index = mGrallocMem.getBufferIndex(frameNumber);
if (index < 0)
return mHeapMem.getBufferIndex(frameNumber);
else
return index;
}
void QCamera3StreamMem::switchMaster(uint32_t masterCam)
{
mGrallocMem.switchMaster(masterCam);
}
}; //namespace qcamera

View file

@ -0,0 +1,101 @@
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3_STREAMMEM_H__
#define __QCAMERA3_STREAMMEM_H__
// System dependencies
#include <utils/Mutex.h>
// Camera dependencies
#include "QCamera3Mem.h"
extern "C" {
#include "mm_camera_interface.h"
}
using namespace android;
namespace qcamera {
class QCamera3StreamMem {
public:
QCamera3StreamMem(uint32_t maxHeapBuffer, bool queueAll = true, bool isSecure = false);
virtual ~QCamera3StreamMem();
uint32_t getCnt();
int getRegFlags(uint8_t *regFlags);
// Helper function to access individual QCamera3Buffer object
int getFd(uint32_t index);
ssize_t getSize(uint32_t index);
int invalidateCache(uint32_t index);
int cleanInvalidateCache(uint32_t index);
int cleanCache(uint32_t index);
int32_t getBufDef(const cam_frame_len_offset_t &offset,
mm_camera_buf_def_t &bufDef, uint32_t index);
void *getPtr(uint32_t index);
bool valid(uint32_t index);
// Gralloc buffer related functions
int registerBuffer(buffer_handle_t *buffer, cam_stream_type_t type);
int unregisterBuffer(uint32_t index);
int getMatchBufIndex(void *object);
void *getBufferHandle(uint32_t index);
void unregisterBuffers(); //TODO: relace with unififed clear() function?
// Heap buffer related functions
int allocateAll(size_t size);
int allocateOne(size_t size);
void deallocate(); //TODO: replace with unified clear() function?
// Clear function: unregister for gralloc buffer, and deallocate for heap buffer
void clear() {unregisterBuffers(); deallocate(); }
// Frame number getter and setter
int32_t markFrameNumber(uint32_t index, uint32_t frameNumber);
int32_t getFrameNumber(uint32_t index);
int32_t getOldestFrameNumber(uint32_t &index);
int32_t getGrallocBufferIndex(uint32_t frameNumber);
int32_t getHeapBufferIndex(uint32_t frameNumber);
int32_t getBufferIndex(uint32_t frameNumber);
void switchMaster(uint32_t masterCam);
private:
//variables
QCamera3HeapMemory mHeapMem;
QCamera3GrallocMemory mGrallocMem;
uint32_t mMaxHeapBuffers;
Mutex mLock;
bool mQueueHeapBuffers;
};
};
#endif // __QCAMERA3_STREAMMEM_H__

View file

@ -0,0 +1,717 @@
/* Copyright (c) 2014-2016,2019 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCamera3VendorTags"
// Camera dependencies
#include "QCamera3HWI.h"
#include "QCamera3VendorTags.h"
extern "C" {
#include "mm_camera_dbg.h"
}
using namespace android;
namespace qcamera {
enum qcamera3_ext_tags qcamera3_ext3_section_bounds[QCAMERA3_SECTIONS_END -
VENDOR_SECTION] = {
QCAMERA3_PRIVATEDATA_END,
QCAMERA3_CDS_END,
QCAMERA3_OPAQUE_RAW_END,
QCAMERA3_CROP_END,
QCAMERA3_TUNING_META_DATA_END,
QCAMERA3_TEMPORAL_DENOISE_END,
QCAMERA3_ISO_EXP_PRIORITY_END,
QCAMERA3_SATURATION_END,
QCAMERA3_EXPOSURE_METER_END,
QCAMERA3_AV_TIMER_END,
QCAMERA3_SENSOR_META_DATA_END,
QCAMERA3_DUALCAM_LINK_META_DATA_END,
QCAMERA3_DUALCAM_CALIB_META_DATA_END,
QCAMERA3_HAL_PRIVATEDATA_END,
QCAMERA3_JPEG_ENCODE_CROP_END,
QCAMERA3_VIDEO_HDR_END,
QCAMERA3_IR_END,
QCAMERA3_AEC_CONVERGENCE_SPEED_END,
QCAMERA3_AWB_CONVERGENCE_SPEED_END,
QCAMERA3_INSTANT_AEC_END,
QCAMERA3_SHARPNESS_END,
QCAMERA3_HISTOGRAM_END,
QCAMERA3_BINNING_CORRECTION_END,
QCAMERA3_STATS_END,
QCAMERA3_SIMULTANEOUS_CAMERA_END,
QCAMERA3_QUADRA_CFA_DATA_END,
QCAMERA3_HFR_END,
QCAMERA3_BOKEH_END,
QCAMERA3_FUSION_END,
QCAMERA3_LOGICAL_CAM_END,
QCAMERA3_MANUAL_WB_END,
QCAMERA3_SAT_MODE_END,
QCAMERA3_EIS_FLUSH_END,
QCAMERA3_SWMFNR_END,
};
typedef struct vendor_tag_info {
const char *tag_name;
uint8_t tag_type;
} vendor_tag_info_t;
const char *qcamera3_ext_section_names[QCAMERA3_SECTIONS_END -
VENDOR_SECTION] = {
"org.codeaurora.qcamera3.privatedata",
"org.codeaurora.qcamera3.CDS",
"org.codeaurora.qcamera3.opaque_raw",
"org.codeaurora.qcamera3.crop",
"org.codeaurora.qcamera3.tuning_meta_data",
"org.codeaurora.qcamera3.temporal_denoise",
"org.codeaurora.qcamera3.iso_exp_priority",
"org.codeaurora.qcamera3.saturation",
"org.codeaurora.qcamera3.exposure_metering",
"org.codeaurora.qcamera3.av_timer",
"org.codeaurora.qcamera3.sensor_meta_data",
"org.codeaurora.qcamera3.dualcam_link_meta_data",
"org.codeaurora.qcamera3.dualcam_calib_meta_data",
"org.codeaurora.qcamera3.hal_private_data",
"org.codeaurora.qcamera3.jpeg_encode_crop",
"org.codeaurora.qcamera3.video_hdr_mode",
"org.codeaurora.qcamera3.ir",
"org.codeaurora.qcamera3.aec_convergence_speed",
"org.codeaurora.qcamera3.awb_convergence_speed",
"org.codeaurora.qcamera3.instant_aec",
"org.codeaurora.qcamera3.sharpness",
"org.codeaurora.qcamera3.histogram",
"org.codeaurora.qcamera3.binning_correction",
"org.codeaurora.qcamera3.stats",
"org.codeaurora.qcamera3.simultaneous_camera",
"org.codeaurora.qcamera3.quadra_cfa",
"org.codeaurora.qcamera3.hfr",
"org.codeaurora.qcamera3.bokeh",
"org.codeaurora.qcamera3.fusion",
"org.codeaurora.qcamera3.logical",
"org.codeaurora.qcamera3.manualWB",
"org.codeaurora.qcamera3.sat",
"org.quic.camera.recording",
"org.codeaurora.qcamera3.swmfnr"
};
vendor_tag_info_t qcamera3_privatedata[QCAMERA3_PRIVATEDATA_END - QCAMERA3_PRIVATEDATA_START] = {
{ "privatedata_reprocess", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_cds[QCAMERA3_CDS_END - QCAMERA3_CDS_START] = {
{ "cds_mode", TYPE_INT32 },
{ "cds_info", TYPE_BYTE }
};
vendor_tag_info_t qcamera3_opaque_raw[QCAMERA3_OPAQUE_RAW_END -
QCAMERA3_OPAQUE_RAW_START] = {
{ "opaque_raw_strides", TYPE_INT32 },
{ "opaque_raw_format", TYPE_BYTE }
};
vendor_tag_info_t qcamera3_crop[QCAMERA3_CROP_END- QCAMERA3_CROP_START] = {
{ "count", TYPE_INT32 },
{ "data", TYPE_INT32},
{ "roimap", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_tuning_meta_data[QCAMERA3_TUNING_META_DATA_END -
QCAMERA3_TUNING_META_DATA_START] = {
{ "tuning_meta_data_blob", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_temporal_denoise[QCAMERA3_TEMPORAL_DENOISE_END -
QCAMERA3_TEMPORAL_DENOISE_START] = {
{ "enable", TYPE_BYTE },
{ "process_type", TYPE_INT32 }
};
vendor_tag_info qcamera3_iso_exp_priority[QCAMERA3_ISO_EXP_PRIORITY_END -
QCAMERA3_ISO_EXP_PRIORITY_START] = {
{ "use_iso_exp_priority", TYPE_INT64 },
{ "select_priority", TYPE_INT32 },
{ "iso_available_modes", TYPE_INT32 },
{ "exposure_time_range", TYPE_INT64 }
};
vendor_tag_info qcamera3_saturation[QCAMERA3_SATURATION_END -
QCAMERA3_SATURATION_START] = {
{ "use_saturation", TYPE_INT32 },
{ "range", TYPE_INT32 }
};
vendor_tag_info qcamera3_exposure_metering[QCAMERA3_EXPOSURE_METER_END -
QCAMERA3_EXPOSURE_METER_START] = {
{ "exposure_metering_mode", TYPE_INT32},
{ "available_modes", TYPE_INT32 }
};
vendor_tag_info qcamera3_av_timer[QCAMERA3_AV_TIMER_END -
QCAMERA3_AV_TIMER_START] = {
{"use_av_timer", TYPE_BYTE }
};
vendor_tag_info qcamera3_sensor_meta_data[QCAMERA3_SENSOR_META_DATA_END -
QCAMERA3_SENSOR_META_DATA_START] = {
{"dynamic_black_level_pattern", TYPE_FLOAT },
{"is_mono_only", TYPE_BYTE }
};
vendor_tag_info_t
qcamera3_dualcam_link_meta_data[QCAMERA3_DUALCAM_LINK_META_DATA_END -
QCAMERA3_DUALCAM_LINK_META_DATA_START] = {
{ "enable", TYPE_BYTE },
{ "is_main", TYPE_BYTE },
{ "related_camera_id", TYPE_INT32 }
};
vendor_tag_info_t
qcamera3_dualcam_calib_meta_data[QCAMERA3_DUALCAM_CALIB_META_DATA_END -
QCAMERA3_DUALCAM_CALIB_META_DATA_START] = {
{ "dualcam_calib_meta_data_blob", TYPE_BYTE }
};
vendor_tag_info_t
qcamera3_hal_privatedata[QCAMERA3_HAL_PRIVATEDATA_END -
QCAMERA3_HAL_PRIVATEDATA_START] = {
{ "reprocess_flags", TYPE_BYTE },
{ "reprocess_data_blob", TYPE_BYTE },
{ "exif_debug_data_blob", TYPE_BYTE }
};
vendor_tag_info_t
qcamera3_jpep_encode_crop[QCAMERA3_JPEG_ENCODE_CROP_END -
QCAMERA3_JPEG_ENCODE_CROP_START] = {
{ "enable", TYPE_BYTE },
{ "rect", TYPE_INT32 },
{ "roi", TYPE_INT32}
};
vendor_tag_info_t qcamera3_video_hdr[QCAMERA3_VIDEO_HDR_END -
QCAMERA3_VIDEO_HDR_START] = {
{ "vhdr_mode", TYPE_INT32 },
{ "vhdr_supported_modes", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_ir[QCAMERA3_IR_END -
QCAMERA3_IR_START] = {
{ "ir_mode", TYPE_INT32 },
{ "ir_supported_modes", TYPE_INT32}
};
vendor_tag_info_t qcamera3_aec_speed[QCAMERA3_AEC_CONVERGENCE_SPEED_END -
QCAMERA3_AEC_CONVERGENCE_SPEED_START] = {
{"aec_speed", TYPE_FLOAT }
};
vendor_tag_info_t qcamera3_awb_speed[QCAMERA3_AWB_CONVERGENCE_SPEED_END -
QCAMERA3_AWB_CONVERGENCE_SPEED_START] = {
{"awb_speed", TYPE_FLOAT }
};
vendor_tag_info_t
qcamera3_instant_aec[QCAMERA3_INSTANT_AEC_END -
QCAMERA3_INSTANT_AEC_START] = {
{ "instant_aec_mode", TYPE_INT32 },
{ "instant_aec_available_modes", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_sharpness[QCAMERA3_SHARPNESS_END -
QCAMERA3_SHARPNESS_START] = {
{"strength", TYPE_INT32 },
{"range", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_histogram[QCAMERA3_HISTOGRAM_END -
QCAMERA3_HISTOGRAM_START] = {
{ "enable", TYPE_BYTE },
{ "buckets", TYPE_INT32 },
{ "max_count", TYPE_INT32 },
{ "stats", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_binning_correction[QCAMERA3_BINNING_CORRECTION_END -
QCAMERA3_BINNING_CORRECTION_START] = {
{ "binning_correction_mode", TYPE_INT32 },
{ "binning_correction_available_modes", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_stats[QCAMERA3_STATS_END -
QCAMERA3_STATS_START] = {
{ "is_hdr_scene", TYPE_BYTE },
{ "is_hdr_scene_values", TYPE_BYTE },
{ "is_hdr_scene_confidence", TYPE_FLOAT },
{ "is_hdr_scene_confidence_range", TYPE_FLOAT },
{ "bsgc_available", TYPE_BYTE },
{ "blink_detected", TYPE_BYTE },
{ "blink_degree", TYPE_BYTE },
{ "smile_degree", TYPE_BYTE },
{ "smile_confidence", TYPE_BYTE },
{ "gaze_angle", TYPE_BYTE },
{ "gaze_direction", TYPE_INT32 },
{ "gaze_degree", TYPE_BYTE }
};
vendor_tag_info_t qcamera3_simultaneous_camera[QCAMERA3_SIMULTANEOUS_CAMERA_END-
QCAMERA3_SIMULTANEOUS_CAMERA_START] = {
{ "vfe1_reserved_rdi", TYPE_INT32 },
};
vendor_tag_info_t qcamera3_quadra_cfa[QCAMERA3_QUADRA_CFA_DATA_END -
QCAMERA3_QUADRA_CFA_DATA_START] = {
{ "is_qcfa_sensor", TYPE_BYTE },
{ "qcfa_dimension", TYPE_INT32 },
};
vendor_tag_info_t qcamera3_hfr[QCAMERA3_HFR_END -
QCAMERA3_HFR_START] = {
{ "sizes", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_bokeh[QCAMERA3_BOKEH_END -
QCAMERA3_BOKEH_START] = {
{ "enable", TYPE_BYTE },
{ "blurLevel", TYPE_INT32 },
{ "status", TYPE_INT32 }
};
vendor_tag_info_t qcamera3_fusion[QCAMERA3_FUSION_END -
QCAMERA3_FUSION_START] = {
{ "status", TYPE_BYTE }
};
vendor_tag_info_t qcamera3_logical_cam[QCAMERA3_LOGICAL_CAM_END -
QCAMERA3_LOGICAL_CAM_START] = {
{ "mode", TYPE_BYTE }
};
vendor_tag_info qcamera3_manual_wb[QCAMERA3_MANUAL_WB_END -
QCAMERA3_MANUAL_WB_START] = {
{ "partial_mwb_mode", TYPE_INT32 },
{ "color_temperature_range", TYPE_INT32 },
{ "gains_range", TYPE_FLOAT },
{ "color_temperature", TYPE_INT32 },
{ "gains", TYPE_FLOAT }
};
vendor_tag_info qcamera3_swmfnr[QCAMERA3_SWMFNR_END -
QCAMERA3_SWMFNR_START] = {
{ "enable", TYPE_BYTE }
};
vendor_tag_info_t qcamera3_sat_cam[QCAMERA3_SAT_MODE_END -
QCAMERA3_SAT_MODE_START] = {
{ "on", TYPE_BYTE }
};
vendor_tag_info_t qcamera3_eis_flush[QCAMERA3_EIS_FLUSH_END -
QCAMERA3_EIS_FLUSH_START] = {
{ "endOfStream", TYPE_BYTE }
};
vendor_tag_info_t *qcamera3_tag_info[QCAMERA3_SECTIONS_END -
VENDOR_SECTION] = {
qcamera3_privatedata,
qcamera3_cds,
qcamera3_opaque_raw,
qcamera3_crop,
qcamera3_tuning_meta_data,
qcamera3_temporal_denoise,
qcamera3_iso_exp_priority,
qcamera3_saturation,
qcamera3_exposure_metering,
qcamera3_av_timer,
qcamera3_sensor_meta_data,
qcamera3_dualcam_link_meta_data,
qcamera3_dualcam_calib_meta_data,
qcamera3_hal_privatedata,
qcamera3_jpep_encode_crop,
qcamera3_video_hdr,
qcamera3_ir,
qcamera3_aec_speed,
qcamera3_awb_speed,
qcamera3_instant_aec,
qcamera3_sharpness,
qcamera3_histogram,
qcamera3_binning_correction,
qcamera3_stats,
qcamera3_simultaneous_camera,
qcamera3_quadra_cfa,
qcamera3_hfr,
qcamera3_bokeh,
qcamera3_fusion,
qcamera3_logical_cam,
qcamera3_manual_wb,
qcamera3_sat_cam,
qcamera3_eis_flush,
qcamera3_swmfnr,
};
uint32_t qcamera3_all_tags[] = {
// QCAMERA3_PRIVATEDATA
(uint32_t)QCAMERA3_PRIVATEDATA_REPROCESS,
// QCAMERA3_CDS
(uint32_t)QCAMERA3_CDS_MODE,
(uint32_t)QCAMERA3_CDS_INFO,
// QCAMERA3_OPAQUE_RAW
(uint32_t)QCAMERA3_OPAQUE_RAW_STRIDES,
(uint32_t)QCAMERA3_OPAQUE_RAW_FORMAT,
// QCAMERA3_CROP
(uint32_t)QCAMERA3_CROP_COUNT_REPROCESS,
(uint32_t)QCAMERA3_CROP_REPROCESS,
(uint32_t)QCAMERA3_CROP_ROI_MAP_REPROCESS,
// QCAMERA3_TUNING_META_DATA
(uint32_t)QCAMERA3_TUNING_META_DATA_BLOB,
// QCAMERA3_TEMPORAL_DENOISE
(uint32_t)QCAMERA3_TEMPORAL_DENOISE_ENABLE,
(uint32_t)QCAMERA3_TEMPORAL_DENOISE_PROCESS_TYPE,
// QCAMERA3_ISO_EXP_PRIORITY
(uint32_t)QCAMERA3_USE_ISO_EXP_PRIORITY,
(uint32_t)QCAMERA3_SELECT_PRIORITY,
(uint32_t)QCAMERA3_ISO_AVAILABLE_MODES,
(uint32_t)QCAMERA3_EXP_TIME_RANGE,
// QCAMERA3_SATURATION
(uint32_t)QCAMERA3_USE_SATURATION,
(uint32_t)QCAMERA3_SATURATION_RANGE,
// QCAMERA3_EXPOSURE_METERING
(uint32_t)QCAMERA3_EXPOSURE_METER,
(uint32_t)QCAMERA3_EXPOSURE_METER_AVAILABLE_MODES,
//QCAMERA3_AVTIMER
(uint32_t)QCAMERA3_USE_AV_TIMER,
//QCAMERA3_SENSOR_META_DATA
(uint32_t)QCAMERA3_SENSOR_DYNAMIC_BLACK_LEVEL_PATTERN,
(uint32_t)QCAMERA3_SENSOR_IS_MONO_ONLY,
// QCAMERA3_DUALCAM_LINK_META_DATA
(uint32_t)QCAMERA3_DUALCAM_LINK_ENABLE,
(uint32_t)QCAMERA3_DUALCAM_LINK_IS_MAIN,
(uint32_t)QCAMERA3_DUALCAM_LINK_RELATED_CAMERA_ID,
// QCAMERA3_DUALCAM_CALIB_META_DATA
(uint32_t)QCAMERA3_DUALCAM_CALIB_META_DATA_BLOB,
// QCAMERA3_HAL_PRIVATEDATA
(uint32_t)QCAMERA3_HAL_PRIVATEDATA_REPROCESS_FLAGS,
(uint32_t)QCAMERA3_HAL_PRIVATEDATA_REPROCESS_DATA_BLOB,
(uint32_t)QCAMERA3_HAL_PRIVATEDATA_EXIF_DEBUG_DATA_BLOB,
// QCAMERA3_JPEG_ENCODE_CROP
(uint32_t)QCAMERA3_JPEG_ENCODE_CROP_ENABLE,
(uint32_t)QCAMERA3_JPEG_ENCODE_CROP_RECT,
(uint32_t)QCAMERA3_JPEG_ENCODE_CROP_ROI,
// QCAMERA3_VIDEO_HDR
(uint32_t)QCAMERA3_VIDEO_HDR_MODE,
(uint32_t)QCAMERA3_AVAILABLE_VIDEO_HDR_MODES,
// QCAMERA3_IR_MODE_ENABLE
(uint32_t)QCAMERA3_IR_MODE,
(uint32_t)QCAMERA3_IR_AVAILABLE_MODES,
//QCAMERA3_AEC_CONVERGENCE_SPEED
(uint32_t)QCAMERA3_AEC_CONVERGENCE_SPEED,
//QCAMERA3_AWB_CONVERGENCE_SPEED
(uint32_t)QCAMERA3_AWB_CONVERGENCE_SPEED,
// QCAMERA3_INSTANT_AEC
(uint32_t)QCAMERA3_INSTANT_AEC_MODE,
(uint32_t)QCAMERA3_INSTANT_AEC_AVAILABLE_MODES,
//QCAMERA3_SHARPNESS
(uint32_t)QCAMERA3_SHARPNESS_STRENGTH,
(uint32_t)QCAMERA3_SHARPNESS_RANGE,
//QCAMERA3_HISTOGRAM
(uint32_t)QCAMERA3_HISTOGRAM_MODE,
(uint32_t)QCAMERA3_HISTOGRAM_BUCKETS,
(uint32_t)QCAMERA3_HISTOGRAM_MAX_COUNT,
(uint32_t)QCAMERA3_HISTOGRAM_STATS,
// QCAMERA3_BINNING_CORRECTION_END
(uint32_t)QCAMERA3_BINNING_CORRECTION_MODE,
(uint32_t)QCAMERA3_AVAILABLE_BINNING_CORRECTION_MODES,
// QCAMERA3_STATS
(uint32_t)QCAMERA3_STATS_IS_HDR_SCENE,
(uint32_t)QCAMERA3_STATS_IS_HDR_SCENE_CONFIDENCE,
(uint32_t)QCAMERA3_STATS_BSGC_AVAILABLE,
(uint32_t)QCAMERA3_STATS_BLINK_DETECTED,
(uint32_t)QCAMERA3_STATS_BLINK_DEGREE,
(uint32_t)QCAMERA3_STATS_SMILE_DEGREE,
(uint32_t)QCAMERA3_STATS_SMILE_CONFIDENCE,
(uint32_t)QCAMERA3_STATS_GAZE_ANGLE,
(uint32_t)QCAMERA3_STATS_GAZE_DIRECTION,
(uint32_t)QCAMERA3_STATS_GAZE_DEGREE,
// QCAMERA3_SIMULTANEOUS_CAMERA
(uint32_t)QCAMERA3_SIMULTANEOUS_CAMERA_VFE1_RESERVED_RDI,
// QCAMERA3_QUADRA_CFA_DATA
(uint32_t)QCAMERA3_IS_QUADRA_CFA_SENSOR,
(uint32_t)QCAMERA3_SUPPORT_QUADRA_CFA_DIM,
//QCAMERA3_HFR
(uint32_t)QCAMERA3_HFR_SIZES,
//QCAMERA3_BOKEH
(uint32_t)QCAMERA3_BOKEH_ENABLE,
(uint32_t)QCAMERA3_BOKEH_BLURLEVEL,
(uint32_t)QCAMERA3_BOKEH_STATUS,
//QCAMERA3_FUSION
(uint32_t)QCAMERA3_FUSION_STATUS,
//QCAMERA3_LOGICAL_CAM
(uint32_t)QCAMERA3_LOGICAL_CAM_MODE,
//QCAMERA3_MANUAL_WB
(uint32_t)QCAMERA3_MANUAL_WB_MODE,
(uint32_t)QCAMERA3_MANUAL_WB_CCT_RANGE,
(uint32_t)QCAMERA3_MANUAL_WB_GAINS_RANGE,
(uint32_t)QCAMERA3_MANUAL_WB_CCT,
(uint32_t)QCAMERA3_MANUAL_WB_GAINS,
//QCAMERA3_SAT
(uint32_t)QCAMERA3_SAT_MODE_ON,
(uint32_t)QCAMERA3_EIS_FLUSH_ON,
//QCAMERA3 SWMFNR
(uint32_t)QCAMERA3_SWMFNR_ENABLE
};
const vendor_tag_ops_t* QCamera3VendorTags::Ops = NULL;
/*===========================================================================
* FUNCTION : get_vendor_tag_ops
*
* DESCRIPTION: Get the metadata vendor tag function pointers
*
* PARAMETERS :
* @ops : function pointer table to be filled by HAL
*
*
* RETURN : NONE
*==========================================================================*/
void QCamera3VendorTags::get_vendor_tag_ops(
vendor_tag_ops_t* ops)
{
LOGL("E");
Ops = ops;
ops->get_tag_count = get_tag_count;
ops->get_all_tags = get_all_tags;
ops->get_section_name = get_section_name;
ops->get_tag_name = get_tag_name;
ops->get_tag_type = get_tag_type;
ops->reserved[0] = NULL;
LOGL("X");
return;
}
/*===========================================================================
* FUNCTION : get_tag_count
*
* DESCRIPTION: Get number of vendor tags supported
*
* PARAMETERS :
* @ops : Vendor tag ops data structure
*
*
* RETURN : Number of vendor tags supported
*==========================================================================*/
int QCamera3VendorTags::get_tag_count(
const vendor_tag_ops_t * ops)
{
size_t count = 0;
if (ops == Ops)
count = sizeof(qcamera3_all_tags)/sizeof(qcamera3_all_tags[0]);
LOGL("count is %d", count);
return (int)count;
}
/*===========================================================================
* FUNCTION : get_all_tags
*
* DESCRIPTION: Fill array with all supported vendor tags
*
* PARAMETERS :
* @ops : Vendor tag ops data structure
* @tag_array: array of metadata tags
*
* RETURN : Success: the section name of the specific tag
* Failure: NULL
*==========================================================================*/
void QCamera3VendorTags::get_all_tags(
const vendor_tag_ops_t * ops,
uint32_t *g_array)
{
if (ops != Ops)
return;
for (size_t i = 0;
i < sizeof(qcamera3_all_tags)/sizeof(qcamera3_all_tags[0]);
i++) {
g_array[i] = qcamera3_all_tags[i];
LOGD("g_array[%d] is %d", i, g_array[i]);
}
}
/*===========================================================================
* FUNCTION : get_section_name
*
* DESCRIPTION: Get section name for vendor tag
*
* PARAMETERS :
* @ops : Vendor tag ops structure
* @tag : Vendor specific tag
*
*
* RETURN : Success: the section name of the specific tag
* Failure: NULL
*==========================================================================*/
const char* QCamera3VendorTags::get_section_name(
const vendor_tag_ops_t * ops,
uint32_t tag)
{
LOGL("E");
if (ops != Ops)
return NULL;
const char *ret;
uint32_t section = tag >> 16;
if (section < VENDOR_SECTION || section >= QCAMERA3_SECTIONS_END)
ret = NULL;
else
ret = qcamera3_ext_section_names[section - VENDOR_SECTION];
if (ret)
LOGL("section_name[%d] is %s", tag, ret);
LOGL("X");
return ret;
}
/*===========================================================================
* FUNCTION : get_tag_name
*
* DESCRIPTION: Get name of a vendor specific tag
*
* PARAMETERS :
* @tag : Vendor specific tag
*
*
* RETURN : Success: the name of the specific tag
* Failure: NULL
*==========================================================================*/
const char* QCamera3VendorTags::get_tag_name(
const vendor_tag_ops_t * ops,
uint32_t tag)
{
LOGL("E");
const char *ret;
uint32_t section = tag >> 16;
uint32_t section_index = section - VENDOR_SECTION;
uint32_t tag_index = tag & 0xFFFF;
if (ops != Ops) {
ret = NULL;
goto done;
}
if (section < VENDOR_SECTION || section >= QCAMERA3_SECTIONS_END)
ret = NULL;
else if (tag >= (uint32_t)qcamera3_ext3_section_bounds[section_index])
ret = NULL;
else
ret = qcamera3_tag_info[section_index][tag_index].tag_name;
if (ret)
LOGL("tag name for tag %d is %s", tag, ret);
LOGL("X");
done:
return ret;
}
/*===========================================================================
* FUNCTION : get_tag_type
*
* DESCRIPTION: Get type of a vendor specific tag
*
* PARAMETERS :
* @tag : Vendor specific tag
*
*
* RETURN : Success: the type of the specific tag
* Failure: -1
*==========================================================================*/
int QCamera3VendorTags::get_tag_type(
const vendor_tag_ops_t *ops,
uint32_t tag)
{
LOGL("E");
int ret;
uint32_t section = tag >> 16;
uint32_t section_index = section - VENDOR_SECTION;
uint32_t tag_index = tag & 0xFFFF;
if (ops != Ops) {
ret = -1;
goto done;
}
if (section < VENDOR_SECTION || section >= QCAMERA3_SECTIONS_END)
ret = -1;
else if (tag >= (uint32_t )qcamera3_ext3_section_bounds[section_index])
ret = -1;
else
ret = qcamera3_tag_info[section_index][tag_index].tag_type;
LOGL("tag type for tag %d is %d", tag, ret);
LOGL("X");
done:
return ret;
}
}; //end namespace qcamera

View file

@ -0,0 +1,521 @@
/* Copyright (c) 2014-2016,2019 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3VENDORTAGS_H__
#define __QCAMERA3VENDORTAGS_H__
// Camera dependencies
#include "system/camera_metadata.h"
namespace qcamera {
enum qcamera3_ext_section {
QCAMERA3_PRIVATEDATA = VENDOR_SECTION,
QCAMERA3_CDS,
QCAMERA3_OPAQUE_RAW,
QCAMERA3_CROP,
QCAMERA3_TUNING_META_DATA,
QCAMERA3_TEMPORAL_DENOISE,
QCAMERA3_ISO_EXP_PRIORITY,
QCAMERA3_SATURATION,
QCAMERA3_EXPOSURE_METERING_MODE,
QCAMERA3_AV_TIMER,
QCAMERA3_SENSOR_META_DATA,
QCAMERA3_DUALCAM_LINK_META_DATA,
QCAMERA3_DUALCAM_CALIB_META_DATA,
QCAMERA3_HAL_PRIVATEDATA,
QCAMERA3_JPEG_ENCODE_CROP,
QCAMERA3_VIDEO_HDR,
QCAMERA3_IR,
QCAMERA3_AEC_CONVERGENCE,
QCAMERA3_AWB_CONVERGENCE,
QCAMERA3_INSTANT_AEC,
QCAMERA3_SHARPNESS_DATA,
QCAMERA3_HISTOGRAM,
QCAMERA3_BINNING_CORRECTION,
QCAMERA3_STATS,
QCAMERA3_SIMULTANEOUS_CAMERA,
QCAMERA3_QUADRA_CFA_DATA,
QCAMERA3_HFR,
QCAMERA3_BOKEH,
QCAMERA3_FUSION,
QCAMERA3_LOGICAL_CAM,
QCAMERA3_MANUAL_WB,
QCAMERA3_SAT_MODE,
QCAMERA3_EIS_FLUSH,
QCAMERA3_SWMFNR,
QCAMERA3_SECTIONS_END,
};
enum qcamera3_ext_section_ranges {
QCAMERA3_PRIVATEDATA_START = QCAMERA3_PRIVATEDATA << 16,
QCAMERA3_CDS_START = QCAMERA3_CDS << 16,
QCAMERA3_OPAQUE_RAW_START = QCAMERA3_OPAQUE_RAW << 16,
QCAMERA3_CROP_START = QCAMERA3_CROP << 16,
QCAMERA3_TUNING_META_DATA_START = QCAMERA3_TUNING_META_DATA << 16,
QCAMERA3_TEMPORAL_DENOISE_START = QCAMERA3_TEMPORAL_DENOISE << 16,
QCAMERA3_ISO_EXP_PRIORITY_START = QCAMERA3_ISO_EXP_PRIORITY << 16,
QCAMERA3_SATURATION_START = QCAMERA3_SATURATION << 16,
QCAMERA3_EXPOSURE_METER_START = QCAMERA3_EXPOSURE_METERING_MODE << 16,
QCAMERA3_AV_TIMER_START = QCAMERA3_AV_TIMER << 16,
QCAMERA3_SENSOR_META_DATA_START = QCAMERA3_SENSOR_META_DATA << 16,
QCAMERA3_DUALCAM_LINK_META_DATA_START = QCAMERA3_DUALCAM_LINK_META_DATA << 16,
QCAMERA3_DUALCAM_CALIB_META_DATA_START = QCAMERA3_DUALCAM_CALIB_META_DATA << 16,
QCAMERA3_HAL_PRIVATEDATA_START = QCAMERA3_HAL_PRIVATEDATA << 16,
QCAMERA3_JPEG_ENCODE_CROP_START = QCAMERA3_JPEG_ENCODE_CROP << 16,
QCAMERA3_VIDEO_HDR_START = QCAMERA3_VIDEO_HDR << 16,
QCAMERA3_IR_START = QCAMERA3_IR << 16,
QCAMERA3_AEC_CONVERGENCE_SPEED_START = QCAMERA3_AEC_CONVERGENCE << 16,
QCAMERA3_AWB_CONVERGENCE_SPEED_START = QCAMERA3_AWB_CONVERGENCE << 16,
QCAMERA3_INSTANT_AEC_START = QCAMERA3_INSTANT_AEC << 16,
QCAMERA3_SHARPNESS_START = QCAMERA3_SHARPNESS_DATA << 16,
QCAMERA3_HISTOGRAM_START = QCAMERA3_HISTOGRAM << 16,
QCAMERA3_BINNING_CORRECTION_START = QCAMERA3_BINNING_CORRECTION << 16,
QCAMERA3_STATS_START = QCAMERA3_STATS << 16,
QCAMERA3_SIMULTANEOUS_CAMERA_START = QCAMERA3_SIMULTANEOUS_CAMERA << 16,
QCAMERA3_QUADRA_CFA_DATA_START = QCAMERA3_QUADRA_CFA_DATA << 16,
QCAMERA3_HFR_START = QCAMERA3_HFR << 16,
QCAMERA3_BOKEH_START = QCAMERA3_BOKEH << 16,
QCAMERA3_FUSION_START = QCAMERA3_FUSION << 16,
QCAMERA3_LOGICAL_CAM_START = QCAMERA3_LOGICAL_CAM << 16,
QCAMERA3_MANUAL_WB_START = QCAMERA3_MANUAL_WB << 16,
QCAMERA3_SAT_MODE_START = QCAMERA3_SAT_MODE << 16,
QCAMERA3_EIS_FLUSH_START = QCAMERA3_EIS_FLUSH << 16,
QCAMERA3_SWMFNR_START = QCAMERA3_SWMFNR << 16,
};
enum qcamera3_ext_tags {
QCAMERA3_PRIVATEDATA_REPROCESS = QCAMERA3_PRIVATEDATA_START,
QCAMERA3_PRIVATEDATA_END,
QCAMERA3_CDS_MODE = QCAMERA3_CDS_START,
QCAMERA3_CDS_INFO,
QCAMERA3_CDS_END,
//Property Name: org.codeaurora.qcamera3.opaque_raw.opaque_raw_strides
//
//Type: int32 * n * 3 [public]
//
//Description: Distance in bytes from the beginning of one row of opaque
//raw image data to the beginning of next row.
//
//Details: The strides are listed as (raw_width, raw_height, stride)
//triplets. For each supported raw size, there will be a stride associated
//with it.
QCAMERA3_OPAQUE_RAW_STRIDES = QCAMERA3_OPAQUE_RAW_START,
//Property Name: org.codeaurora.qcamera3.opaque_raw.opaque_raw_format
//
//Type: byte(enum) [public]
// * LEGACY - The legacy raw format where 8, 10, or 12-bit
// raw data is packed into a 64-bit word.
// * MIPI - raw format matching the data packing described
// in MIPI CSI-2 specification. In memory, the data
// is constructed by packing sequentially received pixels
// into least significant parts of the words first.
// Within each pixel, the least significant bits are also
// placed towards the least significant part of the word.
//
//Details: Lay out of opaque raw data in memory is decided by two factors:
// opaque_raw_format and bit depth (implied by whiteLevel). Below
// list illustrates their relationship:
// LEGACY8: P7(7:0) P6(7:0) P5(7:0) P4(7:0) P3(7:0) P2(7:0) P1(7:0) P0(7:0)
// 8 pixels occupy 8 bytes, no padding needed
// min_stride = CEILING8(raw_width)
// LEGACY10: 0000 P5(9:0) P4(9:0) P3(9:0) P2(9:0) P1(9:0) P0(9:0)
// 6 pixels occupy 8 bytes, 4 bits padding at MSB
// min_stride = (raw_width+5)/6 * 8
// LEGACY12: 0000 P4(11:0) P3(11:0) P2(11:0) P1(11:0) P0(11:0)
// 5 pixels occupy 8 bytes, 4 bits padding at MSB
// min_stride = (raw_width+4)/5 * 8
// MIPI8: P0(7:0)
// 1 pixel occupy 1 byte
// min_stride = raw_width
// MIPI10: P3(1:0) P2(1:0) P1(1:0) P0(1:0) P3(9:2) P2(9:2) P1(9:2) P0(9:2)
// 4 pixels occupy 5 bytes
// min_stride = (raw_width+3)/4 * 5
// MIPI12: P1(3:0) P0(3:0) P1(11:4) P0(11:4)
// 2 pixels occupy 3 bytes
// min_stride = (raw_width+1)/2 * 3
//Note that opaque_raw_stride needs to be at least the required minimum
//stride from the table above. ISP hardware may need more generous stride
//setting. For example, for LEGACY8, the actual stride may be
//CEILING16(raw_width) due to bus burst length requirement.
QCAMERA3_OPAQUE_RAW_FORMAT,
QCAMERA3_OPAQUE_RAW_END,
QCAMERA3_CROP_COUNT_REPROCESS = QCAMERA3_CROP_START,
QCAMERA3_CROP_REPROCESS,
QCAMERA3_CROP_ROI_MAP_REPROCESS,
QCAMERA3_CROP_END,
QCAMERA3_TUNING_META_DATA_BLOB = QCAMERA3_TUNING_META_DATA_START,
QCAMERA3_TUNING_META_DATA_END,
QCAMERA3_TEMPORAL_DENOISE_ENABLE = QCAMERA3_TEMPORAL_DENOISE_START,
QCAMERA3_TEMPORAL_DENOISE_PROCESS_TYPE,
QCAMERA3_TEMPORAL_DENOISE_END,
QCAMERA3_USE_ISO_EXP_PRIORITY = QCAMERA3_ISO_EXP_PRIORITY_START,
QCAMERA3_SELECT_PRIORITY,
/* Property Name: org.codeaurora.qcamera3.iso_exp_priority.iso_available_modes
Type: int32[8]
Description: Available iso mode values
iso_available_modes[0] = 0 (auto)
iso_available_modes[1] = 1 (deblur)
iso_available_modes[2] = 2 (100)
iso_available_modes[3] = 3 (200)
iso_available_modes[4] = 4 (400)
iso_available_modes[5] = 5 (800)
iso_available_modes[6] = 6 (1600)
iso_available_modes[7] = 7 (3200)
*/
QCAMERA3_ISO_AVAILABLE_MODES,
/* Property Name: org.codeaurora.qcamera3.iso_exp_priority.exposure_time_range
Type: int64[2]
Description: Min/max exposure time values (ns)
exposure_time_range[0] = min
exposure_time_range[1] = max
*/
QCAMERA3_EXP_TIME_RANGE,
QCAMERA3_ISO_EXP_PRIORITY_END,
QCAMERA3_USE_SATURATION = QCAMERA3_SATURATION_START,
/* Property Name: org.codeaurora.qcamera3.saturation.range
Type: int32[4]
Description: Range of possible saturation values
range[0] = min
range[1] = max
range[2] = default
range[3] = step
*/
QCAMERA3_SATURATION_RANGE,
QCAMERA3_SATURATION_END,
QCAMERA3_EXPOSURE_METER = QCAMERA3_EXPOSURE_METER_START,
/* Property Name: org.codeaurora.qcamera3.exposure_metering.available_modes
Type: int32[7]
Description: Available exposure metering mode values
available_modes[0] = 0 (FRAME_AVERAGE)
available_modes[1] = 1 (CENTER_WEIGHTED)
available_modes[2] = 2 (SPOT_METERING)
available_modes[3] = 3 (SMART_METERING)
available_modes[4] = 4 (USER_METERING)
available_modes[5] = 5 (SPOT_METERING_ADV)
available_modes[6] = 6 (CENTER_WEIGHTED_ADV)
*/
QCAMERA3_EXPOSURE_METER_AVAILABLE_MODES,
QCAMERA3_EXPOSURE_METER_END,
QCAMERA3_USE_AV_TIMER = QCAMERA3_AV_TIMER_START,
QCAMERA3_AV_TIMER_END,
QCAMERA3_SENSOR_DYNAMIC_BLACK_LEVEL_PATTERN = QCAMERA3_SENSOR_META_DATA_START,
QCAMERA3_SENSOR_IS_MONO_ONLY,
QCAMERA3_SENSOR_META_DATA_END,
QCAMERA3_DUALCAM_LINK_ENABLE = QCAMERA3_DUALCAM_LINK_META_DATA_START,
QCAMERA3_DUALCAM_LINK_IS_MAIN,
QCAMERA3_DUALCAM_LINK_RELATED_CAMERA_ID,
QCAMERA3_DUALCAM_LINK_META_DATA_END,
QCAMERA3_DUALCAM_CALIB_META_DATA_BLOB = QCAMERA3_DUALCAM_CALIB_META_DATA_START,
QCAMERA3_DUALCAM_CALIB_META_DATA_END,
QCAMERA3_HAL_PRIVATEDATA_REPROCESS_FLAGS = QCAMERA3_HAL_PRIVATEDATA_START,
QCAMERA3_HAL_PRIVATEDATA_REPROCESS_DATA_BLOB,
QCAMERA3_HAL_PRIVATEDATA_EXIF_DEBUG_DATA_BLOB,
QCAMERA3_HAL_PRIVATEDATA_END,
/* Property Name: org.codeaurora.qcamera3.jpeg_encode_crop.enable
Type: byte
Description: If JPEG crop is enable
*/
QCAMERA3_JPEG_ENCODE_CROP_ENABLE = QCAMERA3_JPEG_ENCODE_CROP_START,
/* Property Name: org.codeaurora.qcamera3.jpeg_encode_crop.rect
Type: int32[4]
Description: Crop image into size width x height
from [left, top] coordinate
rect[0] = left
rect[1] = top
rect[2] = width
rect[3] = height
*/
QCAMERA3_JPEG_ENCODE_CROP_RECT,
/* Property Name: org.codeaurora.qcamera3.jpeg_encode_crop.roi
Type: int32[4]
Description: Scale the crop image into size width x height
from [left, top] coordinate.
roi[0] = left
roi[1] = top
roi[2] = width
roi[3] = height
*/
QCAMERA3_JPEG_ENCODE_CROP_ROI,
QCAMERA3_JPEG_ENCODE_CROP_END,
QCAMERA3_VIDEO_HDR_MODE = QCAMERA3_VIDEO_HDR_START,
QCAMERA3_AVAILABLE_VIDEO_HDR_MODES,
QCAMERA3_VIDEO_HDR_END,
QCAMERA3_IR_MODE = QCAMERA3_IR_START,
QCAMERA3_IR_AVAILABLE_MODES,
QCAMERA3_IR_END,
QCAMERA3_AEC_CONVERGENCE_SPEED = QCAMERA3_AEC_CONVERGENCE_SPEED_START,
QCAMERA3_AEC_CONVERGENCE_SPEED_END,
QCAMERA3_AWB_CONVERGENCE_SPEED = QCAMERA3_AWB_CONVERGENCE_SPEED_START,
QCAMERA3_AWB_CONVERGENCE_SPEED_END,
QCAMERA3_INSTANT_AEC_MODE = QCAMERA3_INSTANT_AEC_START,
QCAMERA3_INSTANT_AEC_AVAILABLE_MODES,
QCAMERA3_INSTANT_AEC_END,
QCAMERA3_SHARPNESS_STRENGTH = QCAMERA3_SHARPNESS_START,
QCAMERA3_SHARPNESS_RANGE,
QCAMERA3_SHARPNESS_END,
QCAMERA3_HISTOGRAM_MODE = QCAMERA3_HISTOGRAM_START,
QCAMERA3_HISTOGRAM_BUCKETS,
QCAMERA3_HISTOGRAM_MAX_COUNT,
QCAMERA3_HISTOGRAM_STATS,
QCAMERA3_HISTOGRAM_END,
QCAMERA3_BINNING_CORRECTION_MODE = QCAMERA3_BINNING_CORRECTION_START,
QCAMERA3_AVAILABLE_BINNING_CORRECTION_MODES,
QCAMERA3_BINNING_CORRECTION_END,
QCAMERA3_STATS_IS_HDR_SCENE = QCAMERA3_STATS_START,
/* Property Name: org.codeaurora.qcamera3.stats.is_hdr_scene_values
Type: byte[2]
Description: Possible values for is_hdr_scene
roi[0] = 0 (false)
roi[1] = 1 (true)
*/
QCAMERA3_STATS_IS_HDR_SCENE_VALUES,
QCAMERA3_STATS_IS_HDR_SCENE_CONFIDENCE,
/* Property Name: org.codeaurora.qcamera3.stats.is_hdr_scene_confidence_range
Type: float[2]
Description: Range of values for is_hdr_scene_confidence
roi[0] = 0.0 (min)
roi[1] = 1.0 (max)
*/
QCAMERA3_STATS_IS_HDR_SCENE_CONFIDENCE_RANGE,
QCAMERA3_STATS_BSGC_AVAILABLE,
QCAMERA3_STATS_BLINK_DETECTED,
/* Property Name: org.codeaurora.qcamera3.stats.blink_degree
Type: int8[2]
Description: Blink degree
blink_degree[0] = left
blink_degree[1] = right
*/
QCAMERA3_STATS_BLINK_DEGREE,
QCAMERA3_STATS_SMILE_DEGREE,
QCAMERA3_STATS_SMILE_CONFIDENCE,
QCAMERA3_STATS_GAZE_ANGLE,
/* Property Name: org.codeaurora.qcamera3.stats.gaze_direction
Type: int32[3]
Description: Gaze direction
gaze_direction[0] = up-down
gaze_direction[1] = left-right
gaze_direction[2] = roll
*/
QCAMERA3_STATS_GAZE_DIRECTION,
/* Property Name: org.codeaurora.qcamera3.stats.gaze_degree
Type: int8[2]
Description: Gaze degree
gaze_degree[0] = left-right
gaze_degree[1] = top-bottom
*/
QCAMERA3_STATS_GAZE_DEGREE,
QCAMERA3_STATS_END,
QCAMERA3_SIMULTANEOUS_CAMERA_VFE1_RESERVED_RDI = QCAMERA3_SIMULTANEOUS_CAMERA_START,
/* Property Name: org.codeaurora.qcamera3.simultaneous_camera.vfe1_reserved_rdi
Type: int32
Description: number of RDI interface reserved on VFE1(the smaller VFE)
Details: It will guarantee the available RDI interfaces for RDI streams,
and any RDI stream requests that exceed the reserved number will
be allocated to the other VFE.
Range from -1 to 3, -1 means the feature is disabled.
*/
QCAMERA3_SIMULTANEOUS_CAMERA_END,
QCAMERA3_IS_QUADRA_CFA_SENSOR = QCAMERA3_QUADRA_CFA_DATA_START,
QCAMERA3_SUPPORT_QUADRA_CFA_DIM,
QCAMERA3_QUADRA_CFA_DATA_END,
QCAMERA3_HFR_SIZES = QCAMERA3_HFR_START,
QCAMERA3_HFR_END,
QCAMERA3_BOKEH_ENABLE = QCAMERA3_BOKEH_START,
QCAMERA3_BOKEH_BLURLEVEL,
QCAMERA3_BOKEH_STATUS,
QCAMERA3_BOKEH_END,
QCAMERA3_FUSION_STATUS = QCAMERA3_FUSION_START,
QCAMERA3_FUSION_END,
QCAMERA3_LOGICAL_CAM_MODE = QCAMERA3_LOGICAL_CAM_START,
QCAMERA3_LOGICAL_CAM_END,
QCAMERA3_MANUAL_WB_MODE = QCAMERA3_MANUAL_WB_START,
QCAMERA3_MANUAL_WB_CCT_RANGE,
QCAMERA3_MANUAL_WB_GAINS_RANGE,
QCAMERA3_MANUAL_WB_CCT,
QCAMERA3_MANUAL_WB_GAINS,
QCAMERA3_MANUAL_WB_END,
QCAMERA3_SAT_MODE_ON = QCAMERA3_SAT_MODE_START,
QCAMERA3_SAT_MODE_END,
QCAMERA3_EIS_FLUSH_ON = QCAMERA3_EIS_FLUSH_START,
QCAMERA3_EIS_FLUSH_END,
QCAMERA3_SWMFNR_ENABLE = QCAMERA3_SWMFNR_START,
QCAMERA3_SWMFNR_END
};
// QCAMERA3_OPAQUE_RAW_FORMAT
typedef enum qcamera3_ext_opaque_raw_format {
QCAMERA3_OPAQUE_RAW_FORMAT_LEGACY,
QCAMERA3_OPAQUE_RAW_FORMAT_MIPI
} qcamera3_ext_opaque_raw_format_t;
// QCAMERA3_VIDEO_HDR_MODE
typedef enum camera_metadata_enum_android_video_hdr_mode {
QCAMERA3_VIDEO_HDR_MODE_OFF,
QCAMERA3_VIDEO_HDR_MODE_ON
} camera_metadata_enum_android_video_hdr_mode_t;
// QCAMERA3_IR_MODE
typedef enum camera_metadata_enum_android_ir_mode {
QCAMERA3_IR_MODE_OFF,
QCAMERA3_IR_MODE_ON,
QCAMERA3_IR_MODE_AUTO
} camera_metadata_enum_android_ir_mode_t;
// QCAMERA3_INSTANCE_AEC_MODE
typedef enum qcamera3_ext_instant_aec_mode {
QCAMERA3_INSTANT_AEC_NORMAL_CONVERGENCE,
QCAMERA3_INSTANT_AEC_AGGRESSIVE_CONVERGENCE,
QCAMERA3_INSTANT_AEC_FAST_CONVERGENCE
} qcamera3_ext_instant_aec_mode_t;
// QCAMERA3_HISTOGRAM_MODE
typedef enum qcamera3_histogram_mode {
QCAMERA3_HISTOGRAM_MODE_OFF,
QCAMERA3_HISTOGRAM_MODE_ON
} histogram_mode;
// QCAMERA3_BINNING_CORRECTION_MODE
typedef enum camera_metadata_enum_android_binning_correction_mode {
QCAMERA3_BINNING_CORRECTION_MODE_OFF,
QCAMERA3_BINNING_CORRECTION_MODE_ON
} camera_metadata_enum_android_binning_correction_mode_t;
// QCAMERA3_EXPOSURE_METER
typedef enum qcamera3_ext_exposure_meter_mode {
QCAMERA3_EXP_METER_MODE_FRAME_AVERAGE,
QCAMERA3_EXP_METER_MODE_CENTER_WEIGHTED,
QCAMERA3_EXP_METER_MODE_SPOT_METERING,
QCAMERA3_EXP_METER_MODE_SMART_METERING,
QCAMERA3_EXP_METER_MODE_USER_METERING,
QCAMERA3_EXP_METER_MODE_SPOT_METERING_ADV,
QCAMERA3_EXP_METER_MODE_CENTER_WEIGHTED_ADV
} qcamera3_ext_exposure_meter_mode_t;
// QCAMERA3_ISO_EXP_PRIORITY
typedef enum qcamera3_ext_iso_mode {
QCAMERA3_ISO_MODE_AUTO,
QCAMERA3_ISO_MODE_DEBLUR,
QCAMERA3_ISO_MODE_100,
QCAMERA3_ISO_MODE_200,
QCAMERA3_ISO_MODE_400,
QCAMERA3_ISO_MODE_800,
QCAMERA3_ISO_MODE_1600,
QCAMERA3_ISO_MODE_3200,
} qcamera3_ext_iso_mode_t;
typedef enum {
/* RAW only mode for devices that will simultaneously use more than two
* cameras. This is required because by default the HAL will start support
* stream along with RAW stream. This will allocate resources which
* otherwise can be used for another camera. Using this mode indicates HAL
* that the additional functionality provided by support stream is not
* needed.
* This mode has following limitations:
* - Back end 3A, Face Detect or any additional functionality depending
* on image/sensor statistics and YUV streams will be disabled.
*/
QCAMERA3_VENDOR_STREAM_CONFIGURATION_RAW_ONLY_MODE = 0x8000,
/* Disables all support streams for non raw mode configurations. */
QCAMERA3_VENDOR_STREAM_CONFIGURATION_DISABLE_SUPPORT_STREAMS = 0x8001,
/*YUV ZSL*/
QCAMERA3_VENDOR_STREAM_CONFIGURATION_YUV_ZSL_MODE = 0x8002,
/* Controlling Postprocessing of YUV stream from App. This is required to
* reduce the performance overhead while multiple callback streams are running
* by disabling postprocessing which improves power, performance.
* When App notifies this mode to HAL, HAL doesnt link CPP with any stream
* This mode has following limitations:
* - All YUV stream under this mode wont be connecting CPP
* - Postprocessing cant be done.
*/
QCAMERA3_VENDOR_STREAM_CONFIGURATION_PP_DISABLED_MODE = 0x8004
} QCamera3VendorStreamConfiguration;
class QCamera3VendorTags {
public:
static void get_vendor_tag_ops(vendor_tag_ops_t* ops);
static int get_tag_count(
const vendor_tag_ops_t *ops);
static void get_all_tags(
const vendor_tag_ops_t *ops,
uint32_t *tag_array);
static const char* get_section_name(
const vendor_tag_ops_t *ops,
uint32_t tag);
static const char* get_tag_name(
const vendor_tag_ops_t *ops,
uint32_t tag);
static int get_tag_type(
const vendor_tag_ops_t *ops,
uint32_t tag);
static const vendor_tag_ops_t *Ops;
};
}; // namespace qcamera
#endif /* __QCAMERA3VENDORTAGS_H__ */

View file

@ -0,0 +1,47 @@
/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA3EXTERNAL_H__
#define __QCAMERA3EXTERNAL_H__
// System dependencies
#include <utils/Errors.h>
// Display dependencies
#include "QServiceUtils.h"
namespace qcamera {
inline android::status_t setCameraLaunchStatus(uint32_t on __attribute__ ((unused))) {
return android::OK;
}
}; // namespace qcamera
#endif /* __QCAMERA3EXTERNAL_H__ */

View file

@ -0,0 +1,68 @@
LOCAL_PATH:=$(call my-dir)
# Build command line test app: mm-hal3-app
include $(CLEAR_VARS)
ifeq ($(TARGET_SUPPORT_HAL1),false)
LOCAL_CFLAGS += -DQCAMERA_HAL3_SUPPORT
endif
ifeq ($(TARGET_BOARD_PLATFORM),msm8953)
LOCAL_CFLAGS += -DCAMERA_CHIPSET_8953
else
LOCAL_CFLAGS += -DCAMERA_CHIPSET_8937
endif
ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),3.18 4.4 4.9))
ifneq ($(LIBION_HEADER_PATH_WRAPPER), )
include $(LIBION_HEADER_PATH_WRAPPER)
LOCAL_C_INCLUDES += $(LIBION_HEADER_PATHS)
else
LOCAL_C_INCLUDES += \
system/core/libion/kernel-headers \
system/core/libion/include
endif
endif
LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_C_INCLUDES+= $(kernel_includes)
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../../stack/mm-camera-interface/inc \
$(call project-path-for,qcom-media)/libstagefrighthw \
$(call project-path-for,qcom-media)/mm-core/inc
LOCAL_HEADER_LIBRARIES := libhardware_headers
LOCAL_HEADER_LIBRARIES += libbinder_headers
LOCAL_HEADER_LIBRARIES += libandroid_sensor_headers
LOCAL_SRC_FILES := \
QCameraHAL3Base.cpp \
QCameraHAL3MainTestContext.cpp \
QCameraHAL3VideoTest.cpp \
QCameraHAL3PreviewTest.cpp \
QCameraHAL3SnapshotTest.cpp \
QCameraHAL3RawSnapshotTest.cpp \
QCameraHAL3Test.cpp
LOCAL_SHARED_LIBRARIES:= libutils liblog libcamera_metadata libcutils
ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),3.18 4.4 4.9))
LOCAL_SHARED_LIBRARIES += libion
endif
LOCAL_STATIC_LIBRARIES := android.hardware.camera.common@1.0-helper
LOCAL_32_BIT_ONLY := $(BOARD_QTI_CAMERA_32BIT_ONLY)
LOCAL_MODULE:= hal3-test-app
LOCAL_VENDOR_MODULE := true
include $(SDCLANG_COMMON_DEFS)
LOCAL_CFLAGS += -Wall -Wextra -Werror
LOCAL_CFLAGS += -std=c++14 -std=gnu++1z
include $(BUILD_EXECUTABLE)

View file

@ -0,0 +1,477 @@
/*Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3MainTestContext.h"
#include "QCameraHAL3SnapshotTest.h"
#include "QCameraHAL3RawSnapshotTest.h"
#include "QCameraHAL3PreviewTest.h"
#ifdef QCAMERA_HAL3_SUPPORT
#define LIB_PATH /usr/lib/hw/camera.msm8953.so
#else
#define LIB_PATH /system/lib/hw/camera.msm8953.so
#endif
extern "C" {
extern int set_camera_metadata_vendor_ops(const vendor_tag_ops_t *query_ops);
}
/*#ifdef CAMERA_CHIPSET_8953
#define CHIPSET_LIB lib/hw/camera.msm8953.so
#else
#define CHIPSET_LIB lib/hw/camera.msm8937.so
#endif*/
#define CAM_LIB(s) STR_LIB_PATH(s)
#define STR_LIB_PATH(s) #s
namespace qcamera {
QCameraHAL3PreviewTest *mPreviewtestCase = NULL;
QCameraHAL3VideoTest *mVideotestCase = NULL;
QCameraHAL3SnapshotTest *mSnapshottestCase = NULL;
QCameraHAL3RawSnapshotTest *mRawSnapshottestCase = NULL;
struct timeval start_time;
int capture_received;
int pfd[2];
extern int test_case_end;
extern int snapshot_buffer;
pthread_cond_t mRequestAppCond;
std::list<uint32_t> PreviewQueue;
std::list<uint32_t> VideoQueue;
pthread_mutex_t TestAppLock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mCaptureRequestLock = PTHREAD_MUTEX_INITIALIZER;
static void camera_device_status_change(
const struct camera_module_callbacks* callbacks,
int camera_id, int new_status)
{
/* Stub function */
if (callbacks == NULL) {
LOGD("Parameters are NULL %d %d", camera_id, new_status);
}
}
static void torch_mode_status_change(
const struct camera_module_callbacks* callbacks,
const char* camera_id, int new_status)
{
/* Stub function */
if((callbacks == NULL) || (camera_id == NULL)) {
LOGD("Parameters are NULL %d", new_status);
}
}
static void Notify(
const camera3_callback_ops *cb,
const camera3_notify_msg *msg)
{
/* Stub function */
if((cb == NULL) || (msg == NULL)) {
LOGD("Parameters are NULL ");
}
}
static void ProcessCaptureResult(
const camera3_callback_ops *cb,
const camera3_capture_result *result)
{
buffer_thread_msg_t msg;
extern CameraHAL3Base *mCamHal3Base;
int frame_num;
extern int req_sent;
extern int preview_buffer_allocated;
extern int video_buffer_allocated;
int num;
if(cb == NULL) {
LOGD("callback returned is NULL");
}
LOGD("Cam Capture Result Callback %d and %d",
result->num_output_buffers, mCamHal3Base->mFrameCount);
if (mCamHal3Base->mTestCaseSelected == MENU_START_PREVIEW ||
mCamHal3Base->mTestCaseSelected == MENU_START_VIDEO) {
if (result->num_output_buffers == 1) {
frame_num = result->frame_number;
LOGD("Frame width:%d and height:%d and format:%d",
result->output_buffers->stream->width,
result->output_buffers->stream->height,
result->output_buffers->stream->format);
(mCamHal3Base->mFrameCount)++;
LOGD("Preview/Video Capture Result %d and fcount: %d and req_Sent:%d and %d ",
result->num_output_buffers, mCamHal3Base->mFrameCount, req_sent, result->frame_number);
if (test_case_end == 0) {
if (mCamHal3Base->mTestCaseSelected == MENU_START_PREVIEW) {
num = (result->frame_number)%preview_buffer_allocated;
PreviewQueue.push_back(num);
}
else {
num = (result->frame_number)%video_buffer_allocated;
VideoQueue.push_back(num);
}
pthread_cond_signal(&mRequestAppCond);
memset(&msg, 0, sizeof(buffer_thread_msg_t));
}
}
}
else {
extern int fcount_captured;
if (result->num_output_buffers == 1) {
LOGD("snapshot/Raw Capture1 Result Callback %d and %d",
result->num_output_buffers, fcount_captured);
(mCamHal3Base->mFrameCount)++;
fcount_captured++;
LOGD("\n Capture %d done preparing for capture ", fcount_captured);
memset(&msg, 0, sizeof(buffer_thread_msg_t));
write(pfd[1], &msg, sizeof(buffer_thread_msg_t));
}
}
}
CameraHAL3Base::CameraHAL3Base(int cameraIndex) :
mCameraIndex(cameraIndex),
mLibHandle(NULL),
mFrameCount(0),
mSecElapsed(1),
mTestCaseSelected(0),
mPreviewRunning(0),
mVideoRunning(0),
mSnapShotRunning(0),
binning_mode(0)
{
}
int CameraHAL3Base::hal3appCameraTestLoad()
{
int rc = HAL3_CAM_OK;
int numCam;
int32_t res = 0;
hal3_camera_test_obj_t *my_test_obj;
mLibHandle = new hal3_camera_lib_test;
memset(mLibHandle, 0, sizeof(hal3_camera_lib_handle));
rc = hal3appTestLoad(&mLibHandle->app_obj);
camera_module_t *my_if_handle = mLibHandle->app_obj.hal3_lib.halModule_t;
if (HAL3_CAM_OK != rc) {
LOGE("hal3 err\n");
goto EXIT;
}
numCam = my_if_handle->get_number_of_cameras();
printf("\n Number of Cameras are : %d ", numCam);
if (my_if_handle->get_vendor_tag_ops) {
mLibHandle->app_obj.mVendorTagOps = vendor_tag_ops_t();
my_if_handle->get_vendor_tag_ops(&(mLibHandle->app_obj.mVendorTagOps));
res = set_camera_metadata_vendor_ops(&(mLibHandle->app_obj.mVendorTagOps));
if (0 != res) {
printf("%s: Could not set vendor tag descriptor, "
"received error %s (%d). \n", __func__,
strerror(-res), res);
goto EXIT;
}
}
my_test_obj = &(mLibHandle->test_obj);
my_test_obj->module_cb.torch_mode_status_change = &torch_mode_status_change;
my_test_obj->module_cb.camera_device_status_change = &camera_device_status_change;
my_if_handle->set_callbacks(&(my_test_obj->module_cb));
my_if_handle->get_camera_info(0, &(mLibHandle->test_obj.cam_info));
camcap_info = mLibHandle->test_obj.cam_info;
hal3app_cam_settings = (camcap_info.static_camera_characteristics);
display_capability();
return numCam;
EXIT:
return rc;
}
void CameraHAL3Base::display_capability()
{
ALOGE("Camera Here");
int i;
int *available_ir_modes = NULL;
if(hal3app_cam_settings.exists(QCAMERA3_IR_AVAILABLE_MODES)) {
ALOGE("\n mrad check1 ");
entry_hal3app = hal3app_cam_settings.find(QCAMERA3_IR_AVAILABLE_MODES);
available_ir_modes = (int *) malloc((entry_hal3app.count)*sizeof(int ));
for(i =0;i < (int)entry_hal3app.count; i++){
available_ir_modes[i] = entry_hal3app.data.i32[i];
ALOGE("\n mrad cap %d ", available_ir_modes[i]);
}
}
}
int CameraHAL3Base::hal3appCameraLibOpen(int camid)
{
int rc;
rc = hal3appCamOpen(&mLibHandle->app_obj, (int)camid, &(mLibHandle->test_obj));
if (rc != HAL3_CAM_OK) {
LOGE("hal3appCamOpen() camidx=%d, err=%d\n",
camid, rc);
goto EXIT;
}
rc = hal3appCamInitialize((int)camid, &mLibHandle->test_obj);
EXIT:
return rc;
}
int CameraHAL3Base::hal3appTestLoad(hal3_camera_app_t *my_hal3_app)
{
memset(&my_hal3_app->hal3_lib, 0, sizeof(hal3_interface_lib_t));
printf("\nLibrary path is :%s", CAM_LIB(LIB_PATH));
my_hal3_app->hal3_lib.ptr = dlopen(CAM_LIB(LIB_PATH), RTLD_NOW);
if (!my_hal3_app->hal3_lib.ptr) {
LOGE("Error opening HAL libraries %s\n",
dlerror());
return -HAL3_CAM_E_GENERAL;
}
my_hal3_app->hal3_lib.halModule_t =
(camera_module_t*)dlsym(my_hal3_app->hal3_lib.ptr, HAL_MODULE_INFO_SYM_AS_STR);
if (my_hal3_app->hal3_lib.halModule_t == NULL) {
LOGE("Error opening HAL library %s\n",
dlerror());
return -HAL3_CAM_E_GENERAL;
}
return HAL3_CAM_OK;
}
int CameraHAL3Base::hal3appCamOpen(
hal3_camera_app_t *my_hal3_app,
int camid,
hal3_camera_test_obj_t *my_test_obj)
{
camera_module_t *my_if_handle = my_hal3_app->hal3_lib.halModule_t;
my_if_handle->common.methods->open(&(my_if_handle->common), "0",
reinterpret_cast<hw_device_t**>(&(my_test_obj->device)));
printf("\n Camera ID %d Opened \n", camid);
return HAL3_CAM_OK;
}
int CameraHAL3Base::hal3appCamInitialize(int camid, hal3_camera_test_obj_t *my_test_obj)
{
int rc = 0;
camera3_device_t *device_handle = my_test_obj->device;
my_test_obj->callback_ops.notify = &Notify;
my_test_obj->callback_ops.process_capture_result = &ProcessCaptureResult;
rc = device_handle->ops->initialize(my_test_obj->device, &(my_test_obj->callback_ops));
if (rc != HAL3_CAM_OK) {
LOGE("hal3appCamInitialize() camidx=%d, err=%d\n",
camid, rc);
goto EXIT;
}
EXIT:
return rc;
}
void CameraHAL3Base::hal3appCheckStream(int testcase, int camid)
{
if (testcase != MENU_START_PREVIEW) {
if (mPreviewtestCase != NULL) {
mPreviewtestCase->previewTestEnd(mLibHandle, camid);
delete mPreviewtestCase;
mPreviewtestCase = NULL;
}
}
if (testcase != MENU_START_VIDEO){
if (mVideotestCase != NULL) {
mVideotestCase->videoTestEnd(mLibHandle, camid);
delete mVideotestCase;
mVideotestCase = NULL;
}
}
if (testcase != MENU_START_CAPTURE){
if (mSnapshottestCase != NULL) {
delete mSnapshottestCase;
mSnapshottestCase = NULL;
}
}
if (testcase != MENU_START_RAW_CAPTURE) {
if (mRawSnapshottestCase != NULL) {
delete mRawSnapshottestCase;
mRawSnapshottestCase = NULL;
}
}
}
int CameraHAL3Base::hal3appCameraPreviewInit(int testcase, int camid, int w, int h)
{
extern int req_sent;
int testCaseEndComplete = 0;
if (w == 0 || h == 0) {
printf("\n Frame dimension is wrong");
return -1;
}
if ( mPreviewtestCase != NULL) {
if(testcase == MENU_TOGGLE_IR_MODE) {
ALOGE("\n IR mode requested is :%d", ir_mode);
mPreviewtestCase->ir_mode = ir_mode;
}
if(testcase == MENU_TOGGLE_SVHDR_MODE) {
ALOGE("\n SVHDR mode requested is :%d", svhdr_mode);
mPreviewtestCase->svhdr_mode = svhdr_mode;
}
return 0;
}
else {
testCaseEndComplete = 0;
do {
if (mVideoRunning == 1) {
hal3appCheckStream(MENU_START_PREVIEW, camid);
}
pthread_mutex_lock(&TestAppLock);
mTestCaseSelected = MENU_START_PREVIEW;
if (mVideoRunning != 1) {
hal3appCheckStream(MENU_START_PREVIEW, camid);
}
mPreviewtestCase = new QCameraHAL3PreviewTest(0);
printf("\n\n Testing the Resolution : %d X %d", w, h);
req_sent = 0;
PreviewQueue.clear();
capture_received = 0; mSecElapsed = 1;
snapshot_buffer = -1; mFrameCount = 0;
mPreviewtestCase->width = w; mPreviewtestCase->height = h;
mPreviewtestCase->ir_mode = 0; mPreviewtestCase->svhdr_mode = 0;
mPreviewtestCase->initTest(mLibHandle,
(int) MENU_START_PREVIEW, camid, w, h);
testCaseEndComplete = 1;
}while(testCaseEndComplete != 1);
}
return 0;
}
int CameraHAL3Base::hal3appCameraVideoInit(int testcase, int camid, int w, int h)
{
extern int req_sent;
int testCaseEndComplete = 0;
if (w == 0 || h == 0) {
printf("\n Frame dimension is wrong");
return -1;
}
if (mVideotestCase != NULL) {
if(testcase == MENU_TOGGLE_BINNING_CORRECTION) {
ALOGE("\n Binning Mode Requested is :%d", binning_mode);
mVideotestCase->binning_mode = binning_mode;
}
return 0;
}
else {
testCaseEndComplete = 0;
do {
if (mPreviewRunning == 1) {
hal3appCheckStream(MENU_START_VIDEO, camid);
}
pthread_mutex_lock(&TestAppLock);
mTestCaseSelected = MENU_START_VIDEO;
if (mPreviewRunning != 1) {
hal3appCheckStream(MENU_START_VIDEO, camid);
}
mVideotestCase = new QCameraHAL3VideoTest(0);
VideoQueue.clear();
printf("\n\nTesting the Resolution : %d X %d", w, h);
req_sent = 0;
capture_received =0; mSecElapsed = 1; test_case_end = 0;
mVideotestCase->width = w; mVideotestCase->height = h;
snapshot_buffer = -1; mFrameCount = 0;
mVideotestCase->initTest(mLibHandle,
(int) MENU_START_VIDEO, camid, w, h);
testCaseEndComplete = 1;
}while(testCaseEndComplete !=1);
}
return 0;
}
int CameraHAL3Base::hal3appRawCaptureInit(hal3_camera_lib_test *handle, int camid, int req_cap)
{
int testCaseEndComplete = 0;
if(handle == NULL) {
LOGE("Camera Handle is NULL");
}
if (mSnapShotRunning != 1) {
hal3appCheckStream(MENU_START_RAW_CAPTURE, camid);
}
testCaseEndComplete = 0;
do {
pthread_mutex_lock(&TestAppLock);
if (mSnapShotRunning == 1) {
hal3appCheckStream(MENU_START_RAW_CAPTURE, camid);
}
printf("\n capture:%d", req_cap);
mTestCaseSelected = MENU_START_RAW_CAPTURE;
mRawSnapshottestCase = new QCameraHAL3RawSnapshotTest(req_cap);
mRawSnapshottestCase->mRequestedCapture = req_cap;
mRawSnapshottestCase->initTest(mLibHandle,
(int) MENU_START_RAW_CAPTURE, camid, RAWSNAPSHOT_CAPTURE_WIDTH,
RAWSNAPSHOT_CAPTURE_HEIGHT);
testCaseEndComplete = 1;
}while(testCaseEndComplete !=1);
return 0;
}
int CameraHAL3Base::hal3appCameraCaptureInit(hal3_camera_lib_test *handle,
int camid, int req_cap)
{
int testCaseEndComplete = 0;
if(handle == NULL) {
LOGE("Camera Handle is NULL");
}
if (mSnapShotRunning != 1) {
hal3appCheckStream(MENU_START_CAPTURE, camid);
}
testCaseEndComplete = 0;
do {
pthread_mutex_lock(&TestAppLock);
if (mSnapShotRunning == 1) {
hal3appCheckStream(MENU_START_CAPTURE, camid);
}
printf("\n capture:%d", req_cap);
mTestCaseSelected = MENU_START_CAPTURE;
mSnapshottestCase = new QCameraHAL3SnapshotTest(req_cap);
mSnapshottestCase->mRequestedCapture = req_cap;
mSnapshottestCase->initTest(mLibHandle,
(int) MENU_START_CAPTURE, camid, SNAPSHOT_CAPTURE_WIDTH, SNAPSHOT_CAPTURE_HEIGHT);
testCaseEndComplete = 1;
}while(testCaseEndComplete != 1);
return 0;
}
}

View file

@ -0,0 +1,186 @@
/*Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3APP_H__
#define __HAL3APP_H__
#include <hardware/hardware.h>
#include <dlfcn.h>
#include <hardware/camera3.h>
#include <sys/stat.h>
#include <ctype.h>
#include <list>
#include "CameraMetadata.h"
#include <linux/msm_ion.h>
#if TARGET_ION_ABI_VERSION >= 2
#include <ion/ion.h>
#include <linux/dma-buf.h>
#endif //TARGET_ION_ABI_VERSION
#include <errno.h>
#include <fcntl.h>
//#include <system/window.h>
#include <stdio.h>
#include <pthread.h>
#include <poll.h>
#include "QCamera3VendorTags.h"
#include "../stack/common/cam_types.h"
extern "C" {
#include "mm_camera_dbg.h"
}
#define HAL3_DATASPACE_UNKNOWN 0x0
#define HAL3_DATASPACE_ARBITRARY 0x1
#define HAL3_DATASPACE_JFIF 0x101
#define FLAGS_VIDEO_ENCODER 0x00010000
#define PREVIEW_WIDTH 1440
#define PREVIEW_HEIGHT 1080
#define VIDEO_WIDTH 1920
#define VIDEO_HEIGHT 1080
#define SNAPSHOT_CAPTURE_WIDTH 5344
#define SNAPSHOT_CAPTURE_HEIGHT 4008
#define RAWSNAPSHOT_CAPTURE_WIDTH 5344
#define RAWSNAPSHOT_CAPTURE_HEIGHT 4016
using namespace android;
namespace qcamera {
using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
typedef enum {
HAL3_CAM_OK,
HAL3_CAM_E_GENERAL,
HAL3_CAM_E_NO_MEMORY,
HAL3_CAM_E_NOT_SUPPORTED,
HAL3_CAM_E_INVALID_INPUT,
HAL3_CAM_E_INVALID_OPERATION,
HAL3_CAM_E_ENCODE,
HAL3_CAM_E_BUFFER_REG,
HAL3_CAM_E_PMEM_ALLOC,
HAL3_CAM_E_CAPTURE_FAILED,
HAL3_CAM_E_CAPTURE_TIMEOUT,
} hal3_camera_status_type_t;
typedef enum {
PROCESS_BUFFER,
} buffer_thread_msg_type_t;
typedef struct {
camera3_device_t *device;
camera3_callback_ops callback_ops;
struct camera_info cam_info;
camera_module_callbacks_t module_cb;
} hal3_camera_test_obj_t;
typedef struct {
int fd;
int ion_fd;
ion_user_handle_t ion_handle;
size_t size;
} hal3_camtest_meminfo_t;
typedef struct {
buffer_thread_msg_type_t msg;
bool stop_thread;
} buffer_thread_msg_t;
typedef struct {
void *ptr;
camera_module_t* halModule_t;
} hal3_interface_lib_t;
typedef struct {
uint8_t num_cameras;
vendor_tag_ops_t mVendorTagOps;
hal3_interface_lib_t hal3_lib;
} hal3_camera_app_t;
typedef struct {
hal3_camera_app_t app_obj;
hal3_camera_test_obj_t test_obj;
} hal3_camera_lib_test;
typedef struct {
pthread_t td;
pthread_mutex_t mutex;
pthread_cond_t cond;
int32_t readfd;
int32_t writefd;
void *data_obj;
bool is_thread_started;
int testcase;
} buffer_thread_t;
extern int32_t pfd[2];
typedef hal3_camera_lib_test hal3_camera_lib_handle;
class CameraHAL3Base
{
friend class MainTestContext;
protected:
int mCameraIndex;
public:
CameraHAL3Base();
CameraHAL3Base(int cameraIndex);
hal3_camera_lib_test *mLibHandle;
int mFrameCount;
int fps;
int mSecElapsed;
int mTestCaseSelected;
int mPreviewRunning;
int mVideoRunning;
int mSnapShotRunning;
bool ir_mode;
bool svhdr_mode;
uint8_t binning_mode;
camera_info camcap_info;
camera_metadata_entry entry_hal3app;
CameraMetadata hal3app_cam_settings;
int hal3appCamInitialize(int camid, hal3_camera_test_obj_t *my_test_obj);
void hal3appCamCapabilityGet(hal3_camera_lib_test *handle,int camid);
int hal3appCameraLibOpen(int );
int hal3appTestLoad(hal3_camera_app_t *);
int hal3appCamOpen(hal3_camera_app_t *,
int,
hal3_camera_test_obj_t *);
int hal3appCameraPreviewInit(int, int, int, int);
int hal3appCameraVideoInit(int, int camid, int w, int h);
void display_capability();
int hal3appCameraCaptureInit(hal3_camera_lib_test *, int, int);
int hal3appRawCaptureInit(hal3_camera_lib_test *handle, int camid, int );
int hal3appCameraTestLoad();
void hal3appCheckStream(int testcase, int camid);
};
}
#endif

View file

@ -0,0 +1,316 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3MainTestContext.h"
#include "QCameraHAL3Base.h"
namespace qcamera {
#define MAX_CAMERA_SUPPORTED 20
const CAMERA_BASE_MENU_TBL_T camera_main_menu_tbl[] = {
{MENU_START_PREVIEW, "To Start Preview"},
{MENU_START_VIDEO, "To Start Video"},
{MENU_START_CAPTURE, "To Capture(Non-ZSL)"},
{MENU_START_RAW_CAPTURE, "To Raw Capture"},
{MENU_TOGGLE_IR_MODE, "Toggle IR Mode"},
{MENU_TOGGLE_SVHDR_MODE, "Toggle SVHDR Mode"},
{MENU_TOGGLE_BINNING_CORRECTION, "Toggle Binning Correction"},
{MENU_EXIT, "EXIT"},
};
const HAL3TEST_SENSOR_MENU_TBL_T sensor_tbl[] = {
{"Rear Camera"},
{"Front Camera"},
};
CameraHAL3Base *mCamHal3Base = NULL;
pthread_mutex_t gCamLock = PTHREAD_MUTEX_INITIALIZER;
MainTestContext::MainTestContext()
{
mTestRunning = false;
mCamHal3Base = NULL;
irmode = 0;
svhdrmode = 0;
}
int MainTestContext::hal3appGetUserEvent()
{
int choice;
int rc = 0, req_capture = 0;
int preview_restart;
uint8_t num_of_cameras;
if (mCamHal3Base != NULL) {
delete mCamHal3Base;
}
mCamHal3Base = new CameraHAL3Base(0);
num_of_cameras = mCamHal3Base->hal3appCameraTestLoad();
if ((num_of_cameras <= 0) && (num_of_cameras >= MAX_CAMERA_SUPPORTED)) {
LOGE("\n Supported Camera Value is wrong : %d", num_of_cameras);
printf("\n Invalid Number Of Cameras");
goto exit;
}
else {
choice = hal3appDisplaySensorMenu(num_of_cameras);
if (choice >= num_of_cameras || choice < 0) {
printf("\n Unsupported Parameter");
goto exit;
}
else {
mCamHal3Base->mCameraIndex = choice;
rc = mCamHal3Base->hal3appCameraLibOpen(choice);
}
}
do {
choice = hal3appPrintMenu();
switch(choice) {
case MENU_START_PREVIEW:
mCamHal3Base->hal3appCameraPreviewInit(MENU_START_PREVIEW,
mCamHal3Base->mCameraIndex, PREVIEW_WIDTH, PREVIEW_HEIGHT);
mCamHal3Base->mPreviewRunning = 1; mCamHal3Base->mVideoRunning = 0;
mCamHal3Base->mSnapShotRunning = 0;
break;
case MENU_START_VIDEO:
mCamHal3Base->hal3appCameraVideoInit(MENU_START_VIDEO,
mCamHal3Base->mCameraIndex, VIDEO_WIDTH, VIDEO_HEIGHT);
mCamHal3Base->mPreviewRunning = 0; mCamHal3Base->mVideoRunning = 1;
mCamHal3Base->mSnapShotRunning = 0;
break;
case MENU_START_CAPTURE:
hal3appDisplaySnapshotMenu();
req_capture = 1; preview_restart = 0;
if (mCamHal3Base->mPreviewRunning == 1) {
preview_restart = 1;
}
mCamHal3Base->hal3appCameraCaptureInit(0, 0, req_capture);
mCamHal3Base->mPreviewRunning = 0; mCamHal3Base->mVideoRunning = 0;
mCamHal3Base->mSnapShotRunning = 1;
if (preview_restart == 1) {
mCamHal3Base->hal3appCameraPreviewInit(MENU_START_PREVIEW,
mCamHal3Base->mCameraIndex, PREVIEW_WIDTH, PREVIEW_HEIGHT);
mCamHal3Base->mPreviewRunning = 1; mCamHal3Base->mVideoRunning = 0;
mCamHal3Base->mSnapShotRunning = 0;
}
break;
case MENU_START_RAW_CAPTURE:
hal3appDisplayRawCaptureMenu();
req_capture = 3;
mCamHal3Base->hal3appRawCaptureInit(0, 0, req_capture);
mCamHal3Base->mPreviewRunning = 0; mCamHal3Base->mVideoRunning = 0;
mCamHal3Base->mSnapShotRunning = 1;
break;
case MENU_TOGGLE_IR_MODE:
if(mCamHal3Base->mPreviewRunning == 0)
printf(" Cant set IR/SVHDR mode in preview mode only");
else {
irmode = !irmode;
printf("\n Switching IR/SVHDR mode to %s",(irmode ? "On" : "Off"));
ALOGE("\n Switching IR/SVHDR mode to %s and %d",
(irmode ? "On" : "Off"),irmode);
mCamHal3Base->ir_mode = irmode;
mCamHal3Base->hal3appCameraPreviewInit(MENU_TOGGLE_IR_MODE,
mCamHal3Base->mCameraIndex, PREVIEW_WIDTH, PREVIEW_HEIGHT);
}
break;
case MENU_TOGGLE_SVHDR_MODE:
if(mCamHal3Base->mPreviewRunning == 0)
printf(" Cant set IR/SVHDR mode in preview mode only");
else {
svhdrmode = !svhdrmode;
printf("\n Switching IR/SVHDR mode to %s",(svhdrmode ? "On" : "Off"));
ALOGE("\n Switching IR/SVHDR mode to %s and %d",
(svhdrmode ? "On" : "Off"),svhdrmode);
mCamHal3Base->svhdr_mode = svhdrmode;
mCamHal3Base->hal3appCameraPreviewInit(MENU_TOGGLE_SVHDR_MODE,
mCamHal3Base->mCameraIndex, PREVIEW_WIDTH, PREVIEW_HEIGHT);
}
break;
case MENU_TOGGLE_BINNING_CORRECTION:
if (mCamHal3Base->binning_mode == 0)
mCamHal3Base->binning_mode = 1;
else
mCamHal3Base->binning_mode = 0;
LOGE(" Toggling Binning mode to :%d",mCamHal3Base->binning_mode);
printf(" Toggling to Binning mode :%d",mCamHal3Base->binning_mode );
if(mCamHal3Base->mPreviewRunning == 1)
mCamHal3Base->hal3appCameraPreviewInit(MENU_TOGGLE_BINNING_CORRECTION,
mCamHal3Base->mCameraIndex, PREVIEW_WIDTH, PREVIEW_HEIGHT);
if(mCamHal3Base->mVideoRunning == 1)
mCamHal3Base->hal3appCameraVideoInit(MENU_TOGGLE_BINNING_CORRECTION,
mCamHal3Base->mCameraIndex, VIDEO_WIDTH, VIDEO_HEIGHT);
break;
case MENU_EXIT:
hal3appDisplayExitMenu();
break;
default:
printf("\n Option not in Menu\n");
}
}while(choice != MENU_EXIT);
exit:
return 0;
}
int MainTestContext::hal3appDisplaySensorMenu(uint8_t num_of_cameras)
{
int i, choice;
printf("\n");
printf("===========================================\n");
printf(" Camera Sensor to be used: \n");
printf("===========================================\n\n");
for ( i=0;i < num_of_cameras; i++) {
if (i <= 1) {
printf("\n Press %d to select %s", (i), sensor_tbl[i].menu_name);
}
else {
printf("\n Press %d to select Camera%d", (i), i);
}
}
printf("\n Enter your Choice:");
fscanf(stdin, "%d", &choice);
return choice;
}
void MainTestContext::hal3appDisplayCapabilityMenu()
{
printf("\n");
printf("===========================================\n");
printf(" Sensor Capabilty are dumped at location:\n");
printf("===========================================\n\n");
}
int MainTestContext::hal3appDisplayPreviewMenu()
{
int choice;
printf("\n");
printf("===========================================\n");
printf("Select Camera Preview Resolution:\n");
printf("===========================================\n\n");
printf("========Select Preview Resolutions================\n");
printf("\nPress 1 .Aspect Ratio(4:3) Resolution 1440 X 1080");
printf("\nPress 2 .Aspect Ratio(16:9) Resolution 1920 X 1080");
printf("\n Enter your Choice:");
fscanf(stdin, "%d", &choice);
return choice;
}
int MainTestContext::hal3appDisplayVideoMenu()
{
int choice1;
printf("\n");
printf("===========================================\n");
printf("Testing Camera Recording on Different Resolution:\n");
printf("===========================================\n\n");
printf("========Select Video Resolutions================\n");
printf("\nPress 1 .Aspect Ratio(4:3) Resolution 640 X 480");
printf("\nPress 2 .Aspect Ratio(16:9) Resolution 1920 X 1080");
printf("\nPress 3 .To select both");
printf("\n Enter your Choice:");
fscanf(stdin, "%d", &choice1);
return choice1;
}
void MainTestContext::hal3appDisplayRawCaptureMenu()
{
printf("\n");
printf("===========================================\n");
printf("Testing RAW Camera Capture on Different Resolution::\n");
printf("===========================================\n\n");
}
void MainTestContext::hal3appDisplaySnapshotMenu()
{
printf("\n");
printf("===========================================\n");
printf("Testing Normal Camera Capture on Resolution 5344 X 4008\n");
printf("===========================================\n\n");
}
void MainTestContext::hal3appDisplayExitMenu()
{
printf("\n");
printf("===========================================\n");
printf(" Exiting HAL3 APP test \n");
printf("===========================================\n\n");
}
int MainTestContext::hal3appPrintMenu()
{
int i, choice = 0;
char ch = '0';
printf("\n");
printf("===========================================\n");
printf(" HAL3 MENU \n");
printf("===========================================\n\n");
for ( i = 0; i < (int)(sizeof(camera_main_menu_tbl)/sizeof(camera_main_menu_tbl[0])); i++) {
printf("\n Press %d to select %s", (i+1), camera_main_menu_tbl[i].menu_name);
}
printf("\n Enter your Choice:");
do {
std::cin >> ch;
} while(!(ch >= '1' && ch <= '9'));
choice = ch -'0';
return choice;
}
}
int main()
{
char tc_buf[3];
int mode = 0;
int rc = 0;
qcamera::MainTestContext main_ctx;
printf("Please Select Execution Mode:\n");
printf("0: Menu Based 1: Regression\n");
printf("\n Enter your choice:");
fgets(tc_buf, 3, stdin);
mode = tc_buf[0] - '0';
if (mode == 0) {
printf("\nStarting Menu based!!\n");
} else {
printf("\nPlease Enter 0 or 1\n");
printf("\nExisting the App!!\n");
exit(1);
}
rc = main_ctx.hal3appGetUserEvent();
printf("Exiting application\n");
return rc;
}

View file

@ -0,0 +1,87 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3TEST_H__
#define __HAL3TEST_H__
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <unistd.h>
namespace qcamera {
typedef enum
{
MENU_BASE = 0,
MENU_START_PREVIEW,
MENU_START_VIDEO,
MENU_START_CAPTURE,
MENU_START_RAW_CAPTURE,
MENU_TOGGLE_IR_MODE,
MENU_TOGGLE_SVHDR_MODE,
MENU_TOGGLE_BINNING_CORRECTION,
MENU_EXIT
} menu_id;
typedef struct {
menu_id base_menu;
char * basemenu_name;
} HAL3TEST_BASE_MENU_TBL_T;
typedef struct {
const char * menu_name;
} HAL3TEST_SENSOR_MENU_TBL_T;
typedef struct {
menu_id main_menu;
const char * menu_name;
} CAMERA_BASE_MENU_TBL_T;
class CameraHAL3Base;
class MainTestContext
{
bool mTestRunning;
bool irmode;
bool svhdrmode;
public:
MainTestContext();
int hal3appGetUserEvent();
int hal3appDisplaySensorMenu(uint8_t );
void hal3appDisplayCapabilityMenu();
int hal3appDisplayPreviewMenu();
int hal3appDisplayVideoMenu();
void hal3appDisplayRawCaptureMenu();
void hal3appDisplaySnapshotMenu();
void hal3appDisplayExitMenu();
int hal3appPrintMenu();
};
}
#endif

View file

@ -0,0 +1,266 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3PreviewTest.h"
#include "QCameraHAL3MainTestContext.h"
namespace qcamera {
extern hal3_camera_lib_test *CamObj_handle;
int req_sent;
extern pthread_cond_t mRequestAppCond;
int test_case_end;
bool thread_exit;
extern std::list<uint32_t> PreviewQueue;
int preview_buffer_allocated;
extern pthread_mutex_t TestAppLock, mCaptureRequestLock;
int snapshot_buffer = -1;
QCameraHAL3PreviewTest::QCameraHAL3PreviewTest(int camid) :
QCameraHAL3Test(0),
mPreviewHandle(NULL),
mCaptureHandle(NULL),
mPreviewStream(NULL),
nobuffer(0),
mCamId(camid),
ir_mode(0),
svhdr_mode(0)
{
}
void QCameraHAL3PreviewTest::initTest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h)
{
int i;
CamObj_handle = handle; thread_exit = 0; test_case_end = 0;
LOGD("\n buffer thread created for testcase %d %d and %d ",testcase, w, h);
configurePreviewStream(&(handle->test_obj) , camid, w, h);
LOGD("\n preview stream configured");
constructDefaultRequest(&(handle->test_obj), camid);
LOGD("Default stream setting read ");
printf("\npipeline_depth is %d", mPipelineDepthPreview);
mPreviewHandle = new native_handle_t *[mPipelineDepthPreview];
for (i = 0; i < mPipelineDepthPreview; i++)
mPreviewHandle[i] = new native_handle_t;
for (i = 0, req_sent = 1; i < mPipelineDepthPreview; i++, req_sent++) {
previewAllocateBuffers(width, height, i);
PreviewQueue.push_back(i);
}
LOGD(" Request Number is preview : %d ",mRequest.frame_number);
mRequest.frame_number = 0;
previewProcessThreadCreate(handle);
}
void QCameraHAL3PreviewTest::snapshotCaptureRequest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h)
{
LOGD("Requested Capture Sizes for testcase:%d are :%d X %d",testcase, w, h);
captureRequestRepeat(handle, camid, MENU_START_CAPTURE);
pthread_mutex_unlock(&mCaptureRequestLock);
}
void QCameraHAL3PreviewTest::configurePreviewStream(hal3_camera_test_obj_t *my_test_obj,
int camid, int w, int h)
{
camera3_device_t *device_handle = my_test_obj->device;
mPreviewStream = new camera3_stream_t;
memset(mPreviewStream, 0, sizeof(camera3_stream_t));
mPreviewStream = initStream(CAMERA3_STREAM_OUTPUT, camid, w, h, 0,
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, HAL3_DATASPACE_UNKNOWN);
mPreviewConfig = configureStream(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, 1);
mPreviewConfig.streams[0] = mPreviewStream;
device_handle->ops->configure_streams(my_test_obj->device, &(mPreviewConfig));
mPipelineDepthPreview = mPreviewConfig.streams[0]->max_buffers;
preview_buffer_allocated = mPipelineDepthPreview;
}
void QCameraHAL3PreviewTest::constructDefaultRequest(
hal3_camera_test_obj_t *my_test_obj, int camid)
{
camera3_device_t *device_handle = my_test_obj->device;
LOGD("Camera ID : %d",camid);
mMetaDataPtr[0]= device_handle->ops->construct_default_request_settings(my_test_obj->device,
CAMERA3_TEMPLATE_PREVIEW);
mMetaDataPtr[1] = device_handle->ops->construct_default_request_settings(my_test_obj->device,
CAMERA3_TEMPLATE_STILL_CAPTURE);
}
void QCameraHAL3PreviewTest::captureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase)
{
int num1, num2;
int ir_mode_changed;
int svhdr_mode_changed;
int32_t set_svhdr_mode;
int32_t set_ir_mode;
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
camera3_device_t *device_handle = my_test_obj->device;
if (testcase == MENU_START_PREVIEW) {
if (PreviewQueue.empty()) {
LOGE("no preview buffer for CamID : %d", camid);
}
else {
if (test_case_end == 0) {
LOGD(" Request Number is preview : %d ",mRequest.frame_number);
pthread_mutex_lock(&mCaptureRequestLock);
num2 = PreviewQueue.front();
PreviewQueue.pop_front();
num1 = mRequest.frame_number;
ir_mode_changed = get_ir_mode(ir_mode);
svhdr_mode_changed = get_svhdr_mode(svhdr_mode);
ALOGE("setting IR mode :%d",ir_mode_changed);
ALOGE("setting SVHDR mode :%d",svhdr_mode_changed);
if (num1 < 1) {
(mRequest).settings = mMetaDataPtr[0];
}
else if(ir_mode_changed == 1) {
hal3app_preview_settings = mMetaDataPtr[0];
if(ir_mode == 0) {
ALOGE("setting IR mode off");
set_ir_mode = (int32_t)QCAMERA3_IR_MODE_OFF;
}
else {
ALOGE("setting IR mode On");
set_ir_mode = (int32_t)QCAMERA3_IR_MODE_ON;
}
hal3app_preview_settings.update(QCAMERA3_IR_MODE, &set_ir_mode, 1);
(mRequest).settings = hal3app_preview_settings.release();
}
else if(svhdr_mode_changed == 1) {
hal3app_preview_settings = mMetaDataPtr[0];
if(svhdr_mode == 0) {
ALOGE("setting HDR mode off");
set_svhdr_mode = (int32_t)QCAMERA3_VIDEO_HDR_MODE_OFF;
}
else {
ALOGE("setting HDR mode On");
set_svhdr_mode = (int32_t)QCAMERA3_VIDEO_HDR_MODE_ON;
}
hal3app_preview_settings.update(QCAMERA3_VIDEO_HDR_MODE, &set_svhdr_mode, 1);
(mRequest).settings = hal3app_preview_settings.release();
}
else {
(mRequest).settings = NULL;
}
(mRequest).input_buffer = NULL;
(mRequest).num_output_buffers = 1;
mPreviewStreamBuffs.stream = mPreviewStream;
mPreviewStreamBuffs.status = 0;
mPreviewStreamBuffs.buffer =
(const native_handle_t**)&mPreviewHandle[num2];
mPreviewStreamBuffs.release_fence = -1;
mPreviewStreamBuffs.acquire_fence = -1;
(mRequest).output_buffers = &(mPreviewStreamBuffs);
LOGD("Calling HAL3APP repeat capture request %d and %d and free buffer :%d "
, num1, num2, PreviewQueue.size());
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
(mRequest.frame_number)++;
pthread_mutex_unlock(&mCaptureRequestLock);
}
}
}
else {
snapshot_buffer = mRequest.frame_number;
(mRequest).settings = mMetaDataPtr[1];
mSnapshotStreamBuffs = hal3appGetStreamBuffs(mSnapshotStream);
mSnapshotStreamBuffs.buffer = (const native_handle_t**)&mCaptureHandle;
mRequest = hal3appGetRequestSettings(&mSnapshotStreamBuffs, 1);
LOGD("Calling snap HAL3APP repeat capture request repeat %d ", snapshot_buffer);
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
(mRequest.frame_number)++;
}
}
void QCameraHAL3PreviewTest::previewTestEnd(
hal3_camera_lib_test *my_hal3test_obj, int camid)
{
test_case_end = 1;
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
camera3_device_t *device_handle = my_test_obj->device;
device_handle->ops->flush(my_test_obj->device);
LOGD("%s Closing Camera %d", __func__, camid);
ioctl(mPreviewMeminfo.ion_fd, ION_IOC_FREE, &mPreviewMeminfo.ion_handle);
close(mPreviewMeminfo.ion_fd);
mPreviewMeminfo.ion_fd = -1;
LOGD("%s Closing thread", __func__);
thread_exit = 1;
}
void QCameraHAL3PreviewTest::previewAllocateBuffers(int width, int height, int num)
{
mPreviewHandle[num] = allocateBuffers(width, height, &mPreviewMeminfo);
}
void QCameraHAL3PreviewTest::snapshotAllocateBuffers(int width, int height)
{
mCaptureHandle = allocateBuffers(width, height, &mCaptureMemInfo);
}
bool QCameraHAL3PreviewTest::previewProcessThreadCreate(
hal3_camera_lib_test *handle)
{
if(handle == NULL) {
LOGD("Camera Hanle is NULL");
}
processThreadCreate(this, MENU_START_PREVIEW);
return 1;
}
int QCameraHAL3PreviewTest::get_ir_mode(int ir_mode)
{
static int prev_irmode;
if(ir_mode == prev_irmode)
return 0;
else {
prev_irmode = ir_mode;
return 1;
}
}
int QCameraHAL3PreviewTest::get_svhdr_mode(int hdr_mode)
{
static int prev_hdrmode;
if(hdr_mode == prev_hdrmode)
return 0;
else {
prev_hdrmode = hdr_mode;
return 1;
}
}
QCameraHAL3PreviewTest::~QCameraHAL3PreviewTest()
{
}
}

View file

@ -0,0 +1,87 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3APPPREVIEWTEST_H__
#define __HAL3APPPREVIEWTEST_H__
#include "QCameraHAL3Base.h"
#include "QCameraHAL3Test.h"
using namespace android;
namespace qcamera {
using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
class QCameraHAL3PreviewTest : public QCameraHAL3Test
{
private:
hal3_camtest_meminfo_t mPreviewMeminfo;
native_handle_t **mPreviewHandle;
hal3_camtest_meminfo_t mCaptureMemInfo;
native_handle_t *mCaptureHandle;
const camera_metadata_t *mMetaDataPtr[3];
camera3_stream_t *mPreviewStream;
camera3_stream_t *mSnapshotStream;
camera3_capture_request mRequest;
CameraMetadata hal3app_preview_settings;
camera3_stream_buffer_t mPreviewStreamBuffs;
camera3_stream_buffer_t mSnapshotStreamBuffs;
camera3_stream_configuration mPreviewConfig;
public:
int width;
int height;
int nobuffer;
int mPipelineDepthPreview;
int mCamId;
bool ir_mode;
bool svhdr_mode;
QCameraHAL3PreviewTest(int cameraIndex);
void configurePreviewStream(hal3_camera_test_obj_t *my_test_obj, int camid,
int w, int h);
void snapshotCaptureRequest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h);
void constructDefaultRequest(hal3_camera_test_obj_t *, int);
void initTest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h);
void captureRequestRepeat(hal3_camera_lib_test *, int, int);
void previewAllocateBuffers(int,
int, int);
bool previewProcessThreadCreate(hal3_camera_lib_test *);
void previewTestEnd(hal3_camera_lib_test *my_hal3test_obj, int camid);
void snapshotAllocateBuffers(int, int );
virtual ~QCameraHAL3PreviewTest();
int get_ir_mode(int ir_mode);
int get_svhdr_mode(int hdr_mode);
};
void * hal3appPreviewProcessBuffers(void *);
}
#endif

View file

@ -0,0 +1,265 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3RawSnapshotTest.h"
#include "QCameraHAL3MainTestContext.h"
namespace qcamera {
hal3_camera_lib_test *RawSnapshot_CamObj_handle;
extern int fcount_captured;
extern pthread_mutex_t TestAppLock;
QCameraHAL3RawSnapshotTest::QCameraHAL3RawSnapshotTest(int req_cap) :
QCameraHAL3Test(0),
mRawCaptureHandle(NULL),
mRawSnapshotStream(NULL),
mRequestedCapture(req_cap)
{
}
void QCameraHAL3RawSnapshotTest::initTest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h)
{
RawSnapshot_CamObj_handle = handle;
LOGD("\n Raw buffer thread created for testcase : %d", testcase);
configureRawSnapshotStream(&(handle->test_obj), camid, w, h);
constructDefaultRequest(&(handle->test_obj), 0);
LOGD("\n Raw Snapshot Default stream setting read");
rawProcessThreadCreate(MENU_START_RAW_CAPTURE,
rawProcessBuffers);
mRequest.frame_number = 0;
LOGD("\nRaw Snapshot stream configured");
rawProcessCaptureRequest(&(handle->test_obj), 0);
LOGD("\nRaw Snapshot Process Capture Request Sent");
}
void QCameraHAL3RawSnapshotTest::constructDefaultRequest(
hal3_camera_test_obj_t *my_test_obj, int camid)
{
camera3_device_t *device_handle = my_test_obj->device;
LOGD("Camera ID : %d",camid);
mMetaDataPtr[0] = device_handle->ops->construct_default_request_settings(
my_test_obj->device, CAMERA3_TEMPLATE_PREVIEW);
mMetaDataPtr[1] = device_handle->ops->construct_default_request_settings(
my_test_obj->device, CAMERA3_TEMPLATE_STILL_CAPTURE);
}
void QCameraHAL3RawSnapshotTest::configureRawSnapshotStream(hal3_camera_test_obj_t *my_test_obj,
int camid, int w, int h)
{
camera3_device_t *device_handle = my_test_obj->device;
LOGD(" configureSnapshotStream testcase dim :%d X %d", w, h);
mPreviewStream = new camera3_stream_t;
mRawSnapshotStream = new camera3_stream_t;
memset(mPreviewStream, 0, sizeof(camera3_stream_t));
memset(mRawSnapshotStream, 0, sizeof(camera3_stream_t));
mPreviewStream = initStream(CAMERA3_STREAM_OUTPUT, camid, PREVIEW_WIDTH, PREVIEW_HEIGHT, 0,
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, HAL3_DATASPACE_UNKNOWN);
mRawSnapshotStream = initStream(CAMERA3_STREAM_OUTPUT, camid, RAWSNAPSHOT_CAPTURE_WIDTH,
RAWSNAPSHOT_CAPTURE_HEIGHT, 0, HAL_PIXEL_FORMAT_RAW16, HAL3_DATASPACE_ARBITRARY);
mRawSnapshotConfig = configureStream(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, 2);
mRawSnapshotConfig.streams[0] = mPreviewStream;
mRawSnapshotConfig.streams[1] = mRawSnapshotStream;
device_handle->ops->configure_streams(my_test_obj->device, &(mRawSnapshotConfig));
}
void QCameraHAL3RawSnapshotTest::rawProcessCaptureRequest(
hal3_camera_test_obj_t *my_test_obj, int camid)
{
int width, height;
camera3_device_t *device_handle = my_test_obj->device;
width = mRawSnapshotStream->width;
height = mRawSnapshotStream->height;
rawAllocateBuffers(width, height);
mRequest.frame_number = 0;
mRequest.settings = mMetaDataPtr[1];
mRequest.input_buffer = NULL;
mRequest.num_output_buffers = 1;
mRawSnapshotStreamBuffs.stream = mRawSnapshotStream;
mRawSnapshotStreamBuffs.status = 0;
mRawSnapshotStreamBuffs.buffer = (const native_handle_t**)&mRawCaptureHandle;
mRawSnapshotStreamBuffs.release_fence = -1;
mRawSnapshotStreamBuffs.acquire_fence = -1;
mRequest.output_buffers = &(mRawSnapshotStreamBuffs);
LOGD("Calling HAL3APP capture request for camid : %d", camid);
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
}
void QCameraHAL3RawSnapshotTest::rawProcessCaptureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid)
{
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
LOGD("\nRaw Requested Capture : %d and Received Capture : %d",
mRequestedCapture, fcount_captured);
if (mRequestedCapture == fcount_captured) {
LOGD("\n Raw Snapshot is running successfully Ending test");
fflush(stdout);
LOGD("\n Capture Done , Recieved Frame : %d", fcount_captured);
rawTestEnd(my_hal3test_obj, camid);
}
else {
camera3_device_t *device_handle = my_test_obj->device;
(mRequest.frame_number)++;
mRequest.settings = mMetaDataPtr[1];
mRequest.input_buffer = NULL;
mRequest.num_output_buffers = 1;
mRawSnapshotStreamBuffs.stream = mRawSnapshotStream;
mRawSnapshotStreamBuffs.buffer = (const native_handle_t**)&mRawCaptureHandle;
mRawSnapshotStreamBuffs.release_fence = -1;
mRawSnapshotStreamBuffs.acquire_fence = -1;
mRequest.output_buffers = &(mRawSnapshotStreamBuffs);
LOGD("Calling HAL3APP repeat capture request repeat ");
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
}
}
void QCameraHAL3RawSnapshotTest::rawTestEnd(
hal3_camera_lib_test *my_hal3test_obj, int camid)
{
buffer_thread_msg_t msg;
extern pthread_mutex_t gCamLock;
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
camera3_device_t *device_handle = my_test_obj->device;
device_handle->ops->flush(my_test_obj->device);
LOGD("%s Closing Camera %d", __func__, camid);
/* Free the Allocated ION Memory */
ioctl(mRawCaptureMemInfo.ion_fd, ION_IOC_FREE, &mRawCaptureMemInfo.ion_handle);
close(mRawCaptureMemInfo.ion_fd);
mRawCaptureMemInfo.ion_fd = -1;
/* Close the Thread */
memset(&msg, 0, sizeof(buffer_thread_msg_t));
msg.stop_thread = 1;
write(pfd[1], &msg, sizeof(buffer_thread_msg_t));
}
void QCameraHAL3RawSnapshotTest::rawAllocateBuffers(int width, int height)
{
mRawCaptureHandle = allocateBuffers(width, height, &mRawCaptureMemInfo);
}
bool QCameraHAL3RawSnapshotTest::rawProcessThreadCreate(int testcase_id,
void *(*hal3_thread_ops)(void *))
{
int32_t ret = 0;
buffer_thread_t thread;
pthread_attr_t attr;
if (pipe(pfd) < 0) {
LOGE("%s:Test:%d Error in creating the pipe", __func__, testcase_id);
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_mutex_init(&thread.mutex, NULL);
pthread_cond_init(&thread.cond, NULL);
thread.is_thread_started = 0;
thread.readfd = pfd[0];
thread.writefd = pfd[1];
thread.data_obj = this;
ret = pthread_create(&thread.td, &attr, hal3_thread_ops, &thread );
pthread_setname_np(thread.td, "TestApp_Thread");
if (ret < 0) {
LOGE("Failed to create status thread");
return 0;
}
pthread_mutex_lock(&thread.mutex);
while(thread.is_thread_started == 0) {
pthread_cond_wait(&thread.cond, &thread.mutex);
}
pthread_mutex_unlock(&thread.mutex);
return 1;
}
void QCameraHAL3RawSnapshotTest::captureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase)
{
if(my_hal3test_obj == NULL) {
LOGD("camid :%d and testcase : %d handle is NULL", camid, testcase);
}
}
void * rawProcessBuffers(void *data) {
buffer_thread_t *thread = (buffer_thread_t*)data;
int32_t readfd, writefd;
hal3_camera_lib_test *hal3_test_handle;
pthread_mutex_lock(&thread->mutex);
thread->is_thread_started = 1;
readfd = thread->readfd;
writefd = thread->writefd;
QCameraHAL3RawSnapshotTest *obj;
obj = (QCameraHAL3RawSnapshotTest *)thread->data_obj;
pthread_cond_signal(&thread->cond);
pthread_mutex_unlock(&thread->mutex);
struct pollfd pollfds;
int32_t num_of_fds = 1;
bool rthread_exit = 0;
int32_t ready = 0;
pollfds.fd = readfd;
pollfds.events = POLLIN | POLLPRI;
while(!rthread_exit) {
ready = poll(&pollfds, (nfds_t)num_of_fds, -1);
if (ready > 0) {
if (pollfds.revents & (POLLIN | POLLPRI)) {
ssize_t nread = 0;
buffer_thread_msg_t msg;
nread = read(pollfds.fd, &msg, sizeof(buffer_thread_msg_t));
if (nread < 0) {
LOGE("Unable to read the message");
}
if (msg.stop_thread) {
break;
}
hal3_test_handle = RawSnapshot_CamObj_handle;
obj->rawProcessCaptureRequestRepeat(hal3_test_handle, 0);
}
}
else {
LOGE("Unable to poll exiting the thread");
break;
}
}
LOGD("Sensor thread is exiting");
close(readfd);
close(writefd);
pthread_mutex_unlock(&TestAppLock);
pthread_exit(0);
return NULL;
}
QCameraHAL3RawSnapshotTest::~QCameraHAL3RawSnapshotTest()
{
}
}

View file

@ -0,0 +1,69 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3APPRAWSNAPSHOT_H__
#define __HAL3APPRAWSNAPSHOT_H__
#include "QCameraHAL3SnapshotTest.h"
namespace qcamera
{
class QCameraHAL3RawSnapshotTest : public QCameraHAL3Test
{
private:
hal3_camtest_meminfo_t mRawCaptureMemInfo;
native_handle_t *mRawCaptureHandle;
const camera_metadata_t *mMetaDataPtr[3];
camera3_stream_t *mPreviewStream;
camera3_stream_t *mRawSnapshotStream;
camera3_capture_request mRequest;
camera3_stream_buffer_t mRawSnapshotStreamBuffs;
camera3_stream_configuration mRawSnapshotConfig;
public:
int mRequestedCapture;
QCameraHAL3RawSnapshotTest(int req_cap);
void constructDefaultRequest(hal3_camera_test_obj_t *my_test_obj,
int camid);
void configureRawSnapshotStream(hal3_camera_test_obj_t *my_test_obj,
int camid, int, int );
void rawProcessCaptureRequest(hal3_camera_test_obj_t *my_test_obj,
int camid);
void rawProcessCaptureRequestRepeat(hal3_camera_lib_test *my_hal3test_obj,
int camid);
void initTest(hal3_camera_lib_test *handle, int testcase, int, int, int);
bool rawProcessThreadCreate(int testcase_id,
void *(*hal3_thread_ops)(void *));
void rawAllocateBuffers(int height, int width);
void rawTestEnd(hal3_camera_lib_test *my_hal3test_obj, int camid);
void captureRequestRepeat(hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase);
virtual ~QCameraHAL3RawSnapshotTest();
};
void * rawProcessBuffers(void *data);
}
#endif

View file

@ -0,0 +1,264 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3SnapshotTest.h"
#include "QCameraHAL3MainTestContext.h"
namespace qcamera {
hal3_camera_lib_test *Snapshot_CamObj_handle;
int fcount_captured;
extern pthread_mutex_t TestAppLock;
QCameraHAL3SnapshotTest::QCameraHAL3SnapshotTest(int req_cap) :
QCameraHAL3Test(0),
mCaptureHandle(NULL),
mSnapshotStream(NULL),
mRequestedCapture(req_cap)
{
}
void QCameraHAL3SnapshotTest::initTest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h)
{
fcount_captured = 0;
Snapshot_CamObj_handle = handle;
LOGD("\ntestcase %d %d and %d ",testcase, w, h);
configureSnapshotStream(&(handle->test_obj), camid, w, h);
constructDefaultRequest(&(handle->test_obj), 0);
LOGD("\n Snapshot Default stream setting read");
LOGD("\n Snapshot stream configured");
snapshotThreadCreate(MENU_START_CAPTURE, hal3appSnapshotProcessBuffers);
(mRequest.frame_number) = 0;
snapshotProcessCaptureRequest(&(handle->test_obj), 0);
LOGD("\n Snapshot Process Capture Request Sent");
}
void QCameraHAL3SnapshotTest::constructDefaultRequest(
hal3_camera_test_obj_t *my_test_obj, int camid)
{
camera3_device_t *device_handle = my_test_obj->device;
LOGD("Camera ID : %d",camid);
mMetaDataPtr[0]= device_handle->ops->construct_default_request_settings(my_test_obj->device,
CAMERA3_TEMPLATE_PREVIEW);
mMetaDataPtr[1] = device_handle->ops->construct_default_request_settings(my_test_obj->device,
CAMERA3_TEMPLATE_STILL_CAPTURE);
}
void QCameraHAL3SnapshotTest::configureSnapshotStream(hal3_camera_test_obj_t *my_test_obj,
int camid, int w, int h)
{
camera3_device_t *device_handle = my_test_obj->device;
LOGD(" configureSnapshotStream testcase dim :%d X %d", w, h);
mPreviewStream = new camera3_stream_t;
mSnapshotStream = new camera3_stream_t;
memset(mPreviewStream, 0, sizeof(camera3_stream_t));
memset(mSnapshotStream, 0, sizeof(camera3_stream_t));
mPreviewStream = initStream(CAMERA3_STREAM_OUTPUT, camid, PREVIEW_WIDTH, PREVIEW_HEIGHT, 0,
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, HAL3_DATASPACE_UNKNOWN);
mSnapshotStream = initStream(CAMERA3_STREAM_OUTPUT, camid, SNAPSHOT_CAPTURE_WIDTH,
SNAPSHOT_CAPTURE_HEIGHT, 0, HAL_PIXEL_FORMAT_BLOB, HAL3_DATASPACE_JFIF);
mSnapshotConfig = configureStream(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, 2);
mSnapshotConfig.streams[0] = mPreviewStream;
mSnapshotConfig.streams[1] = mSnapshotStream;
device_handle->ops->configure_streams(my_test_obj->device, &(mSnapshotConfig));
}
void QCameraHAL3SnapshotTest::snapshotProcessCaptureRequest(
hal3_camera_test_obj_t *my_test_obj, int camid)
{
int width, height;
camera3_device_t *device_handle = my_test_obj->device;
width = mSnapshotStream->width;
height = mSnapshotStream->height;
snapshotAllocateBuffers(width, height);
mRequest.settings = mMetaDataPtr[1];
mRequest.input_buffer = NULL;
mRequest.num_output_buffers = 1;
mSnapshotStreamBuffs.stream = mSnapshotStream;
mSnapshotStreamBuffs.status = 0;
mSnapshotStreamBuffs.buffer = (const native_handle_t**)&mCaptureHandle;
mSnapshotStreamBuffs.release_fence = -1;
mSnapshotStreamBuffs.acquire_fence = -1;
mRequest.output_buffers = &(mSnapshotStreamBuffs);
LOGD("Calling HAL3APP capture request for camid : %d", camid);
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
(mRequest.frame_number)++;
}
void QCameraHAL3SnapshotTest::snapshotProcessCaptureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid)
{
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
LOGD("\nSnapshot Requested Capture : %d and Received Capture : %d",
mRequestedCapture, fcount_captured);
if (mRequestedCapture == fcount_captured) {
LOGD("\n Snapshot is running successfully Ending test");
fflush(stdout);
LOGD("\n Capture Done , Recieved Frame : %d", fcount_captured);
snapshotTestEnd(my_hal3test_obj, camid);
}
else {
camera3_device_t *device_handle = my_test_obj->device;
mRequest.settings = mMetaDataPtr[1];
mRequest.input_buffer = NULL;
mRequest.num_output_buffers = 1;
mSnapshotStreamBuffs.stream = mSnapshotStream;
mSnapshotStreamBuffs.buffer = (const native_handle_t**)&mCaptureHandle;
mSnapshotStreamBuffs.release_fence = -1;
mSnapshotStreamBuffs.acquire_fence = -1;
mRequest.output_buffers = &(mSnapshotStreamBuffs);
LOGD("Calling HAL3APP repeat capture request repeat %d and %d",
mRequestedCapture, fcount_captured);
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
(mRequest.frame_number)++;
}
}
void QCameraHAL3SnapshotTest::snapshotTestEnd(
hal3_camera_lib_test *my_hal3test_obj, int camid)
{
buffer_thread_msg_t msg;
extern pthread_mutex_t gCamLock;
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
camera3_device_t *device_handle = my_test_obj->device;
device_handle->ops->flush(my_test_obj->device);
LOGD("%s Closing Camera %d", __func__, camid);
ioctl(mCaptureMemInfo.ion_fd, ION_IOC_FREE, &mCaptureMemInfo.ion_handle);
close(mCaptureMemInfo.ion_fd);
mCaptureMemInfo.ion_fd = -1;
memset(&msg, 0, sizeof(buffer_thread_msg_t));
msg.stop_thread = 1;
write(pfd[1], &msg, sizeof(buffer_thread_msg_t));
}
void QCameraHAL3SnapshotTest::snapshotAllocateBuffers(int width, int height)
{
mCaptureHandle= allocateBuffers(width, height, &mCaptureMemInfo);
}
bool QCameraHAL3SnapshotTest::snapshotThreadCreate(int testcase_id,
void *(*hal3_thread_ops)(void *))
{
int32_t ret = 0;
buffer_thread_t thread;
pthread_attr_t attr;
if (pipe(pfd) < 0) {
LOGE("%s:Test:%d Error in creating the pipe", __func__, testcase_id);
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_mutex_init(&thread.mutex, NULL);
pthread_cond_init(&thread.cond, NULL);
thread.is_thread_started = 0;
thread.readfd = pfd[0];
thread.writefd = pfd[1];
thread.data_obj = this;
ret = pthread_create(&thread.td, &attr, hal3_thread_ops, &thread );
pthread_setname_np(thread.td, "TestApp_Thread");
if (ret < 0) {
LOGE("Failed to create status thread");
return 0;
}
pthread_mutex_lock(&thread.mutex);
while(thread.is_thread_started == 0) {
pthread_cond_wait(&thread.cond, &thread.mutex);
}
pthread_mutex_unlock(&thread.mutex);
return 1;
}
void * hal3appSnapshotProcessBuffers(void *data)
{
buffer_thread_t *thread = (buffer_thread_t*)data;
int32_t readfd, writefd;
hal3_camera_lib_test *hal3_test_handle;
pthread_mutex_lock(&thread->mutex);
thread->is_thread_started = 1;
readfd = thread->readfd;
writefd = thread->writefd;
QCameraHAL3SnapshotTest *obj;
obj = (QCameraHAL3SnapshotTest *)thread->data_obj;
pthread_cond_signal(&thread->cond);
pthread_mutex_unlock(&thread->mutex);
struct pollfd pollfds;
int32_t num_of_fds = 1;
bool sthread_exit = 0;
int32_t ready = 0;
pollfds.fd = readfd;
pollfds.events = POLLIN | POLLPRI;
while(!sthread_exit) {
ready = poll(&pollfds, (nfds_t)num_of_fds, -1);
if (ready > 0) {
LOGD("Got some events");
if (pollfds.revents & (POLLIN | POLLPRI)) {
ssize_t nread = 0;
buffer_thread_msg_t msg;
nread = read(pollfds.fd, &msg, sizeof(buffer_thread_msg_t));
if (nread < 0) {
LOGE("Unable to read the message");
}
if (msg.stop_thread) {
break;
}
hal3_test_handle = Snapshot_CamObj_handle;
obj->snapshotProcessCaptureRequestRepeat(hal3_test_handle, 0);
}
}
else {
LOGE("Unable to poll exiting the thread");
break;
}
}
LOGD("Sensor thread is exiting");
close(readfd);
close(writefd);
pthread_mutex_unlock(&TestAppLock);
pthread_exit(0);
return NULL;
}
void QCameraHAL3SnapshotTest::captureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase)
{
if(my_hal3test_obj == NULL) {
LOGD("camid :%d and testcase : %d handle is NULL", camid, testcase);
}
}
QCameraHAL3SnapshotTest::~QCameraHAL3SnapshotTest()
{
}
}

View file

@ -0,0 +1,69 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3APPSNAPSHOT_H__
#define __HAL3APPSNAPSHOT_H__
#include "QCameraHAL3VideoTest.h"
namespace qcamera
{
class QCameraHAL3SnapshotTest : public QCameraHAL3Test
{
private:
hal3_camtest_meminfo_t mCaptureMemInfo;
native_handle_t *mCaptureHandle;
const camera_metadata_t *mMetaDataPtr[3];
camera3_stream_t *mPreviewStream;
camera3_stream_t *mSnapshotStream;
camera3_capture_request mRequest;
camera3_stream_buffer_t mSnapshotStreamBuffs;
camera3_stream_configuration mSnapshotConfig;
public:
int mRequestedCapture;
QCameraHAL3SnapshotTest(int req_cap);
void constructDefaultRequest(hal3_camera_test_obj_t *, int );
void configureSnapshotStream(hal3_camera_test_obj_t *, int,
int w, int h);
void snapshotProcessCaptureRequest(hal3_camera_test_obj_t *my_test_obj,
int camid);
void snapshotAllocateBuffers(int, int );
void initTest(hal3_camera_lib_test *my_test_obj,
int testcase, int camid, int w, int h);
bool snapshotThreadCreate(int testcase_id, void * (*hal3_thread_ops)(void *));
void snapshotProcessCaptureRequestRepeat(hal3_camera_lib_test *my_hal3test_obj,
int camid);
void captureRequestRepeat(hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase);
void snapshotTestEnd(hal3_camera_lib_test *my_hal3test_obj, int camid);
virtual ~QCameraHAL3SnapshotTest();
};
void * hal3appSnapshotProcessBuffers(void *data);
}
#endif

View file

@ -0,0 +1,227 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3Test.h"
#include "QCameraHAL3Base.h"
namespace qcamera {
hal3_camera_lib_test *CamObj_handle;
extern bool thread_exit;
extern int test_case_end;
buffer_thread_t thread;
extern pthread_cond_t mRequestAppCond;
extern pthread_mutex_t TestAppLock, mCaptureRequestLock;
camera3_stream_t *QCameraHAL3Test::initStream(int streamtype,
int camid, int w, int h, int usage, int format, int dataspace)
{
LOGD("Stream init for Camera : %d", camid);
requested_stream = new camera3_stream_t;
memset(requested_stream, 0, sizeof(camera3_stream_t));
requested_stream->stream_type = streamtype;
requested_stream->width = w;
requested_stream->height = h;
requested_stream->format = format;
requested_stream->usage = usage;
requested_stream->data_space = (android_dataspace_t)dataspace;
requested_stream->rotation = CAMERA3_STREAM_ROTATION_0;
return requested_stream;
}
QCameraHAL3Test::QCameraHAL3Test(int id)
{
mCamId = id;
}
camera3_stream_configuration QCameraHAL3Test::configureStream(
int opmode, int num_streams)
{
camera3_stream_configuration requested_config;
requested_config.operation_mode = opmode;
requested_config.num_streams = num_streams;
requested_config.streams = new camera3_stream_t *[num_streams];
return requested_config;
}
camera3_stream_buffer_t QCameraHAL3Test::hal3appGetStreamBuffs(camera3_stream_t *req_stream)
{
camera3_stream_buffer_t stream_buffs;
stream_buffs.stream = req_stream;
stream_buffs.release_fence = -1;
stream_buffs.acquire_fence = -1;
return stream_buffs;
}
camera3_capture_request QCameraHAL3Test::hal3appGetRequestSettings(
camera3_stream_buffer_t *stream_buffs, int num_buffer)
{
camera3_capture_request request_settings;
request_settings.input_buffer = NULL;
LOGD("Number of buffer sent : %d", num_buffer);
request_settings.num_output_buffers = 1;
request_settings.output_buffers = stream_buffs;
return request_settings;
}
native_handle_t *QCameraHAL3Test::allocateBuffers(int width, int height,
hal3_camtest_meminfo_t *req_meminfo)
{
struct ion_allocation_data alloc;
struct ion_fd_data ion_info_fd;
int main_ion_fd = -1, rc;
size_t buf_size;
native_handle_t *nh_test;
#ifndef TARGET_ION_ABI_VERSION
main_ion_fd = open("/dev/ion", O_RDONLY);
#else
main_ion_fd = ion_open();
#endif //TARGET_ION_ABI_VERSION
memset(&ion_info_fd, 0, sizeof(ion_info_fd));
if (main_ion_fd <= 0) {
LOGE("Ion dev open failed %s\n", strerror(errno));
return NULL;
}
memset(&alloc, 0, sizeof(alloc));
buf_size = (size_t)(width * height *2);
alloc.len = (size_t)(buf_size);
alloc.len = (alloc.len + 4095U) & (~4095U);
alloc.align = 4096;
alloc.heap_id_mask = ION_HEAP(ION_SYSTEM_HEAP_ID);
#ifndef TARGET_ION_ABI_VERSION
alloc.flags = ION_FLAG_CACHED;
rc = ioctl(main_ion_fd, ION_IOC_ALLOC, &alloc);
#else
rc = ion_alloc_fd(main_ion_fd, alloc.len, alloc.align, alloc.heap_id_mask,
alloc.flags, &ion_info_fd.fd);
#endif //TARGET_ION_ABI_VERSION
if (rc < 0) {
LOGE("ION allocation failed %s with rc = %d \n", strerror(errno), rc);
return NULL;
}
#ifndef TARGET_ION_ABI_VERSION
ion_info_fd.handle = alloc.handle;
rc = ioctl(main_ion_fd, ION_IOC_SHARE, &ion_info_fd);
#else
ion_info_fd.handle = ion_info_fd.fd;
#endif //TARGET_ION_ABI_VERSION
if (rc < 0) {
LOGE("ION map failed %s\n", strerror(errno));
return NULL;
}
req_meminfo->ion_fd = main_ion_fd;
req_meminfo->ion_handle = ion_info_fd.handle;
LOGD("%s ION FD %d len %d\n", __func__, ion_info_fd.fd, alloc.len);
nh_test = native_handle_create(2, 4);
nh_test->data[0] = ion_info_fd.fd;
nh_test->data[1] = 0;
nh_test->data[2] = 0;
nh_test->data[3] = 0;
nh_test->data[4] = alloc.len;
nh_test->data[5] = 0;
return nh_test;
}
void QCameraHAL3Test::captureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase)
{
if(my_hal3test_obj == NULL) {
LOGE("TestCase : %d Camera:%d Handle is NULL", testcase, camid);
}
}
bool QCameraHAL3Test::processThreadCreate(
void *obj, int testcase)
{
int32_t ret = 0;
pthread_attr_t attr;
if (pipe(pfd) < 0) {
LOGE("%s: Error in creating the pipe", __func__);
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_mutex_init(&thread.mutex, NULL);
pthread_cond_init(&thread.cond, NULL);
pthread_cond_init(&mRequestAppCond, NULL);
thread.is_thread_started = 0;
thread.readfd = pfd[0];
thread.writefd = pfd[1];
thread.data_obj = obj;
thread.testcase = testcase;
pthread_mutex_lock(&thread.mutex);
ret = pthread_create(&thread.td, &attr, processBuffers, &thread );
pthread_setname_np(thread.td, "TestApp_Thread");
if (ret < 0) {
LOGE("Failed to create status thread");
return 0;
}
pthread_mutex_unlock(&thread.mutex);
return 1;
}
void * processBuffers(void *data) {
buffer_thread_t *thread = (buffer_thread_t*)data;
int32_t readfd, writefd;
int testcase;
hal3_camera_lib_test *hal3_test_handle;
struct timespec ts1;
thread->is_thread_started = 1;
readfd = thread->readfd;
writefd = thread->writefd;
testcase = thread->testcase;
QCameraHAL3Test *obj;
obj = (QCameraHAL3Test *)thread->data_obj;
while(!thread_exit) {
pthread_mutex_lock(&thread->mutex);
clock_gettime(CLOCK_REALTIME, &ts1);
ts1.tv_nsec += 10000000L;
pthread_cond_timedwait(&mRequestAppCond, &thread->mutex, &ts1);
pthread_mutex_unlock(&thread->mutex);
hal3_test_handle = CamObj_handle;
if (test_case_end == 0) {
obj->captureRequestRepeat(hal3_test_handle, 0, testcase);
}
}
LOGD("Sensor thread is exiting");
close(readfd);
close(writefd);
pthread_cond_destroy(&mRequestAppCond);
pthread_mutex_unlock(&TestAppLock);
pthread_exit(0);
return NULL;
}
QCameraHAL3Test::~QCameraHAL3Test()
{
}
}

View file

@ -0,0 +1,63 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3APPTESTINIT_H__
#define __HAL3APPTESTINIT_H__
#include "QCameraHAL3MainTestContext.h"
#include "QCameraHAL3Base.h"
namespace qcamera {
class QCameraHAL3Test
{
int mCamId;
public:
QCameraHAL3Test(int cameraIndex);
camera3_stream_t *requested_stream;
camera3_stream_t *initStream(int streamtype,
int camid, int w, int h, int format,int usage,int dataspace);
camera3_stream_configuration configureStream(
int opmode, int num_streams);
virtual void captureRequestRepeat(hal3_camera_lib_test *, int, int);
camera_metadata_t* hal3appGetDefaultRequest(int type);
camera3_capture_request hal3appGetRequestSettings(
camera3_stream_buffer_t *stream_buffs, int num_buffer);
camera3_stream_buffer_t hal3appGetStreamBuffs(camera3_stream_t *req_stream);
native_handle_t *allocateBuffers(int width, int height,
hal3_camtest_meminfo_t *req_meminfo);
bool processThreadCreate(void *obj, int testcase);
virtual ~QCameraHAL3Test();
};
void * processBuffers(void *data);
}
#endif

View file

@ -0,0 +1,234 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "QCameraHAL3VideoTest.h"
#include "QCameraHAL3MainTestContext.h"
namespace qcamera {
extern hal3_camera_lib_test *CamObj_handle;
buffer_thread_t Video_thread;
int video_req_sent;
extern pthread_cond_t mRequestAppCond;
extern int test_case_end;
extern bool thread_exit;
extern std::list<uint32_t> VideoQueue;
int video_buffer_allocated;
extern pthread_mutex_t TestAppLock, mCaptureRequestLock;
extern int snapshot_buffer;
QCameraHAL3VideoTest::QCameraHAL3VideoTest(int camid) :
QCameraHAL3Test(0),
mVideoHandle(NULL),
mCaptureHandle(NULL),
mVideoStream(NULL),
mCameraId(camid),
binning_mode(0)
{
}
void QCameraHAL3VideoTest::initTest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h)
{
int i;
CamObj_handle = handle; thread_exit = 0;
test_case_end = 0;
LOGD("\n buffer thread created for testcase %d %d and %d ",testcase, w, h);
configureVideoStream(&(handle->test_obj), camid, w, h);
LOGD("\n video stream configured");
constructDefaultRequest(&(handle->test_obj), camid);
LOGD("pipeline_depth is %d", mPipelineDepthVideo);
mVideoHandle = new native_handle_t *[mPipelineDepthVideo];
for (i = 0; i < mPipelineDepthVideo; i++) {
mVideoHandle[i] = new native_handle_t;
}
for (i = 0, video_req_sent = 1; i < mPipelineDepthVideo; i++, video_req_sent++) {
vidoeAllocateBuffers(width, height, i);
VideoQueue.push_back(i);
}
LOGD(" Request Number is : %d ",mRequest.frame_number);
mRequest.frame_number = 0;
videoProcessThreadCreate(handle);
}
void QCameraHAL3VideoTest::snapshotCaptureRequest(hal3_camera_lib_test *handle,
int testcase, int camid, int w, int h)
{
LOGD("Requested Capture Sizes for testcase:%d are :%d X %d",testcase, w, h);
captureRequestRepeat(handle, camid, MENU_START_CAPTURE);
pthread_mutex_unlock(&mCaptureRequestLock);
}
void QCameraHAL3VideoTest::configureVideoStream(hal3_camera_test_obj_t *my_test_obj,
int camid, int w, int h)
{
camera3_device_t *device_handle = my_test_obj->device;
mVideoStream = new camera3_stream_t;
memset(mVideoStream, 0, sizeof(camera3_stream_t));
mVideoStream = initStream(CAMERA3_STREAM_OUTPUT, camid, w, h, FLAGS_VIDEO_ENCODER,
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, HAL3_DATASPACE_UNKNOWN);
mVideoConfig = configureStream(CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE, 1);
mVideoConfig.streams[0] = mVideoStream;
device_handle->ops->configure_streams(my_test_obj->device, &(mVideoConfig));
mPipelineDepthVideo = mVideoConfig.streams[0]->max_buffers;
video_buffer_allocated = mPipelineDepthVideo;
}
void QCameraHAL3VideoTest::constructDefaultRequest(
hal3_camera_test_obj_t *my_test_obj, int camid)
{
camera3_device_t *device_handle = my_test_obj->device;
LOGD("Camera ID : %d",camid);
mMetaDataPtr[0] = device_handle->ops->construct_default_request_settings(
my_test_obj->device, CAMERA3_TEMPLATE_VIDEO_RECORD);
mMetaDataPtr[1] = device_handle->ops->construct_default_request_settings(my_test_obj->device,
CAMERA3_TEMPLATE_STILL_CAPTURE);
}
void QCameraHAL3VideoTest::captureRequestRepeat(
hal3_camera_lib_test *my_hal3test_obj, int camid, int testcase)
{
int num1, num2;
int binning_mode_changed;
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
camera3_device_t *device_handle = my_test_obj->device;
if (testcase == MENU_START_VIDEO) {
if (VideoQueue.empty()) {
LOGE("no Video buffer for CamID : %d", camid);
}
else {
if (test_case_end == 0) {
LOGD(" Request Number is : %d ", mRequest.frame_number);
pthread_mutex_lock(&mCaptureRequestLock);
num2 = VideoQueue.front();
VideoQueue.pop_front();
num1 = mRequest.frame_number;
binning_mode_changed = get_binning_mode(binning_mode);
if (num1 < 1) {
(mRequest).settings = mMetaDataPtr[0];
}
else if(binning_mode_changed == 1) {
hal3app_video_settings = mMetaDataPtr[0];
hal3app_video_settings.update(QCAMERA3_BINNING_CORRECTION_MODE,
&binning_mode, 1);
(mRequest).settings = hal3app_video_settings.release();
}
else {
(mRequest).settings = NULL;
}
(mRequest).input_buffer = NULL;
(mRequest).num_output_buffers = 1;
mVideoStreamBuffs.stream = mVideoStream;
mVideoStreamBuffs.status = 0;
mVideoStreamBuffs.buffer =
(const native_handle_t**)&mVideoHandle[num2];
mVideoStreamBuffs.release_fence = -1;
mVideoStreamBuffs.acquire_fence = -1;
(mRequest).output_buffers = &(mVideoStreamBuffs);
LOGD("Calling HAL3APP repeat capture request %d and %d and free buffer :%d "
, num1, num2, VideoQueue.size());
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
(mRequest.frame_number)++;
pthread_mutex_unlock(&mCaptureRequestLock);
}
}
}
else {
snapshot_buffer = mRequest.frame_number;
(mRequest).settings = mMetaDataPtr[1];
mSnapshotStreamBuffs = hal3appGetStreamBuffs(mSnapshotStream);
mSnapshotStreamBuffs.buffer = (const native_handle_t**)&mCaptureHandle;
mRequest = hal3appGetRequestSettings(&mSnapshotStreamBuffs, 1);
LOGD("Calling snap HAL3APP repeat capture request repeat %d ", snapshot_buffer);
device_handle->ops->process_capture_request(my_test_obj->device, &(mRequest));
(mRequest.frame_number)++;
}
}
void QCameraHAL3VideoTest::videoTestEnd(
hal3_camera_lib_test *my_hal3test_obj, int camid)
{
test_case_end = 1;
hal3_camera_test_obj_t *my_test_obj = &(my_hal3test_obj->test_obj);
camera3_device_t *device_handle = my_test_obj->device;
device_handle->ops->flush(my_test_obj->device);
LOGD("%s Closing Camera %d", __func__, camid);
ioctl(mVideoMeminfo.ion_fd, ION_IOC_FREE, &mVideoMeminfo.ion_handle);
close(mVideoMeminfo.ion_fd);
mVideoMeminfo.ion_fd = -1;
LOGD("%s Closing thread", __func__);
thread_exit = 1;
}
void QCameraHAL3VideoTest::vidoeAllocateBuffers(int height, int width, int num)
{
mVideoHandle[num] = allocateBuffers(width, height, &mVideoMeminfo);
}
void QCameraHAL3VideoTest::snapshotAllocateBuffers(int width, int height)
{
mCaptureHandle = allocateBuffers(width, height, &mCaptureMemInfo);
}
int QCameraHAL3VideoTest::get_binning_mode(int32_t binning_mode)
{
static int prev_binning;
if(binning_mode == prev_binning)
return 0;
else {
ALOGE("setting binning mode in video:%d", binning_mode);
prev_binning = binning_mode;
return 1;
}
}
bool QCameraHAL3VideoTest::videoProcessThreadCreate(
hal3_camera_lib_test *handle) {
if(handle == NULL) {
LOGD("Camera Hanle is NULL");
}
processThreadCreate(this, MENU_START_VIDEO);
return 1;
}
QCameraHAL3VideoTest::~QCameraHAL3VideoTest()
{
}
}

View file

@ -0,0 +1,90 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __HAL3APPVIDEOTEST_H__
#define __HAL3APPVIDEOTEST_H__
#include "QCameraHAL3Base.h"
#include "QCameraHAL3Test.h"
using namespace android;
namespace qcamera {
using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
class QCameraHAL3VideoTest : public QCameraHAL3Test
{
private:
hal3_camtest_meminfo_t mVideoMeminfo;
native_handle_t **mVideoHandle;
hal3_camtest_meminfo_t mCaptureMemInfo;
native_handle_t *mCaptureHandle;
const camera_metadata_t *mMetaDataPtr[3];
camera3_stream_t *mVideoStream;
camera3_stream_t *mSnapshotStream;
camera3_capture_request mRequest;
camera3_stream_buffer_t mVideoStreamBuffs;
CameraMetadata hal3app_video_settings;
camera3_stream_buffer_t mSnapshotStreamBuffs;
camera3_stream_configuration mVideoConfig;
public:
int width;
int height;
int nobuffer;
int mPipelineDepthVideo;
int mCameraId;
int32_t binning_mode;
QCameraHAL3VideoTest(int cameraIndex);
void configureVideoStream(hal3_camera_test_obj_t *,
int, int, int);
void snapshotCaptureRequest(hal3_camera_lib_test *handle,int testcase,
int camid, int w, int h);
void constructDefaultRequest(hal3_camera_test_obj_t *,
int);
void captureRequestRepeat(hal3_camera_lib_test *, int, int);
void initTest(hal3_camera_lib_test *handle, int testcase, int camid,
int w, int h);
void vidoeAllocateBuffers(int, int, int);
bool videoProcessThreadCreate(hal3_camera_lib_test *);
void videoTestEnd(hal3_camera_lib_test *my_hal3test_obj, int camid);
void snapshotAllocateBuffers(int, int );
int get_binning_mode(int32_t binning_mode);
virtual ~QCameraHAL3VideoTest();
};
void * hal3appVideoProcessBuffers(void *);
}
#endif

View file

@ -0,0 +1,641 @@
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCamera2Factory"
// System dependencies
#include <stdlib.h>
#include <utils/Errors.h>
#include <cutils/properties.h>
// Camera dependencies
#ifdef QCAMERA_HAL1_SUPPORT
#include "hardware/camera.h"
#include "HAL/QCamera2HWI.h"
#include "QCameraMuxer.h"
#endif
#include "hardware/camera3.h"
#include "HAL3/QCamera3HWI.h"
#include "util/QCameraFlash.h"
#include "QCamera2Factory.h"
#include "QCameraTrace.h"
extern "C" {
#include "mm_camera_dbg.h"
}
using namespace android;
namespace qcamera {
QCamera2Factory *gQCamera2Factory = NULL;
pthread_mutex_t gCamLock = PTHREAD_MUTEX_INITIALIZER;
#ifdef QCAMERA_HAL1_SUPPORT
QCameraMuxer *gQCameraMuxer = NULL;
#endif
//Total number of cameras opened simultaneously.
//This variable updation is protected by gCamLock.
uint8_t gNumCameraSessions = 0;
volatile uint32_t gKpiDebugLevel = 1;
/*===========================================================================
* FUNCTION : QCamera2Factory
*
* DESCRIPTION: default constructor of QCamera2Factory
*
* PARAMETERS : none
*
* RETURN : None
*==========================================================================*/
QCamera2Factory::QCamera2Factory()
{
mHalDescriptors = NULL;
mCallbacks = NULL;
mNumOfCameras = get_num_of_cameras();
mNumOfCameras_expose = get_num_of_cameras_to_expose();
int bDualCamera = 0;
char propDefault[PROPERTY_VALUE_MAX];
char prop[PROPERTY_VALUE_MAX];
property_get("persist.vendor.camera.HAL3.enabled", prop, "1");
int isHAL3Enabled = atoi(prop);
#ifndef QCAMERA_HAL1_SUPPORT
isHAL3Enabled = 1;
#endif
// Signifies whether system has to enable dual camera mode
snprintf(propDefault, PROPERTY_VALUE_MAX, "%d", isDualCamAvailable(isHAL3Enabled));
property_get("persist.vendor.camera.dual.camera", prop, propDefault);
bDualCamera = atoi(prop);
LOGH("dualCamera:%d ", bDualCamera);
#ifndef QCAMERA_HAL1_SUPPORT
bDualCamera = 0;
#endif
if(bDualCamera) {
LOGI("Enabling QCamera Muxer");
#ifdef QCAMERA_HAL1_SUPPORT
if (!gQCameraMuxer) {
QCameraMuxer::getCameraMuxer(&gQCameraMuxer, mNumOfCameras);
if (!gQCameraMuxer) {
LOGE("Error !! Failed to get QCameraMuxer");
}
}
#endif
}
#ifdef QCAMERA_HAL1_SUPPORT
if (!gQCameraMuxer && (mNumOfCameras > 0) &&(mNumOfCameras <= MM_CAMERA_MAX_NUM_SENSORS)) {
#else
if ((mNumOfCameras > 0) &&(mNumOfCameras <= MM_CAMERA_MAX_NUM_SENSORS)) {
#endif
mHalDescriptors = new hal_desc[mNumOfCameras];
if ( NULL != mHalDescriptors) {
uint32_t cameraId = 0;
for (int i = 0; i < mNumOfCameras ; i++, cameraId++) {
mHalDescriptors[i].cameraId = cameraId;
// Set Device version to 3.x when both HAL3 is enabled & its BAYER sensor
if (isHAL3Enabled && !(is_yuv_sensor(cameraId))) {
mHalDescriptors[i].device_version =
CAMERA_DEVICE_API_VERSION_3_0;
} else {
mHalDescriptors[i].device_version =
CAMERA_DEVICE_API_VERSION_1_0;
}
}
} else {
LOGE("Not enough resources to allocate HAL descriptor table!");
}
} else {
LOGI("%d camera devices detected!", mNumOfCameras);
}
}
/*===========================================================================
* FUNCTION : ~QCamera2Factory
*
* DESCRIPTION: deconstructor of QCamera2Factory
*
* PARAMETERS : none
*
* RETURN : None
*==========================================================================*/
QCamera2Factory::~QCamera2Factory()
{
if ( NULL != mHalDescriptors ) {
delete [] mHalDescriptors;
}
#ifdef QCAMERA_HAL1_SUPPORT
if (gQCameraMuxer) {
delete gQCameraMuxer;
gQCameraMuxer = NULL;
}
#endif
}
/*===========================================================================
* FUNCTION : get_number_of_cameras
*
* DESCRIPTION: static function to query number of cameras detected
*
* PARAMETERS : none
*
* RETURN : number of cameras detected
*==========================================================================*/
int QCamera2Factory::get_number_of_cameras()
{
int numCameras = 0;
if (!gQCamera2Factory) {
gQCamera2Factory = new QCamera2Factory();
if (!gQCamera2Factory) {
LOGE("Failed to allocate Camera2Factory object");
return 0;
}
}
#ifdef QCAMERA_HAL1_SUPPORT
if(gQCameraMuxer)
numCameras = gQCameraMuxer->get_number_of_cameras();
else
#endif
numCameras = gQCamera2Factory->getNumberOfCameras();
LOGH("num of cameras: %d", numCameras);
return numCameras;
}
/*===========================================================================
* FUNCTION : get_camera_info
*
* DESCRIPTION: static function to query camera information with its ID
*
* PARAMETERS :
* @camera_id : camera ID
* @info : ptr to camera info struct
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::get_camera_info(int camera_id, struct camera_info *info)
{
int rc = NO_ERROR;
#ifdef QCAMERA_HAL1_SUPPORT
if(gQCameraMuxer)
rc = gQCameraMuxer->get_camera_info(camera_id, info);
else
#endif
rc = gQCamera2Factory->getCameraInfo(camera_id, info);
return rc;
}
/*===========================================================================
* FUNCTION : set_callbacks
*
* DESCRIPTION: static function to set callbacks function to camera module
*
* PARAMETERS :
* @callbacks : ptr to callback functions
*
* RETURN : NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::set_callbacks(const camera_module_callbacks_t *callbacks)
{
int rc = NO_ERROR;
#ifdef QCAMERA_HAL1_SUPPORT
if(gQCameraMuxer)
rc = gQCameraMuxer->set_callbacks(callbacks);
else
#endif
rc = gQCamera2Factory->setCallbacks(callbacks);
return rc;
}
/*===========================================================================
* FUNCTION : open_legacy
*
* DESCRIPTION: Function to open older hal version implementation
*
* PARAMETERS :
* @hw_device : ptr to struct storing camera hardware device info
* @camera_id : camera ID
* @halVersion: Based on camera_module_t.common.module_api_version
*
* RETURN : 0 -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::open_legacy(const struct hw_module_t* module,
const char* id, uint32_t halVersion, struct hw_device_t** device)
{
int rc = NO_ERROR;
if (module != &HAL_MODULE_INFO_SYM.common) {
LOGE("Invalid module. Trying to open %p, expect %p",
module, &HAL_MODULE_INFO_SYM.common);
return INVALID_OPERATION;
}
if (!id) {
LOGE("Invalid camera id");
return BAD_VALUE;
}
#ifdef QCAMERA_HAL1_SUPPORT
if(gQCameraMuxer)
rc = gQCameraMuxer->open_legacy(module, id, halVersion, device);
else
#endif
rc = gQCamera2Factory->openLegacy(atoi(id), halVersion, device);
return rc;
}
/*===========================================================================
* FUNCTION : set_torch_mode
*
* DESCRIPTION: Attempt to turn on or off the torch mode of the flash unit.
*
* PARAMETERS :
* @camera_id : camera ID
* @on : Indicates whether to turn the flash on or off
*
* RETURN : 0 -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::set_torch_mode(const char* camera_id, bool on)
{
return gQCamera2Factory->setTorchMode(camera_id, on);
}
/*===========================================================================
* FUNCTION : getNumberOfCameras
*
* DESCRIPTION: query number of cameras detected
*
* PARAMETERS : none
*
* RETURN : number of cameras detected
*==========================================================================*/
int QCamera2Factory::getNumberOfCameras()
{
return mNumOfCameras_expose;
}
/*===========================================================================
* FUNCTION : getCameraInfo
*
* DESCRIPTION: query camera information with its ID
*
* PARAMETERS :
* @camera_id : camera ID
* @info : ptr to camera info struct
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::getCameraInfo(int camera_id, struct camera_info *info)
{
int rc;
if (!mNumOfCameras || camera_id >= mNumOfCameras || !info ||
(camera_id < 0)) {
LOGE("Error getting camera info!! mNumOfCameras = %d,"
"camera_id = %d, info = %p",
mNumOfCameras, camera_id, info);
return -ENODEV;
}
if ( NULL == mHalDescriptors ) {
LOGE("Hal descriptor table is not initialized!");
return NO_INIT;
}
LOGI("Camera id %d API version %d",
camera_id, mHalDescriptors[camera_id].device_version);
// Need ANDROID_FLASH_INFO_AVAILABLE property for flashlight widget to
// work and so get the static data regardless of HAL version
rc = QCamera3HardwareInterface::getCamInfo(
mHalDescriptors[camera_id].cameraId, info);
if (mHalDescriptors[camera_id].device_version ==
CAMERA_DEVICE_API_VERSION_1_0) {
info->device_version = CAMERA_DEVICE_API_VERSION_1_0;
}
return rc;
}
/*===========================================================================
* FUNCTION : setCallbacks
*
* DESCRIPTION: set callback functions to send asynchronous notifications to
* frameworks.
*
* PARAMETERS :
* @callbacks : callback function pointer
*
* RETURN :
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::setCallbacks(const camera_module_callbacks_t *callbacks)
{
int rc = NO_ERROR;
mCallbacks = callbacks;
rc = QCameraFlash::getInstance().registerCallbacks(callbacks);
if (rc != 0) {
LOGE("Failed to register callbacks with flash module!");
}
return rc;
}
/*===========================================================================
* FUNCTION : cameraDeviceOpen
*
* DESCRIPTION: open a camera device with its ID
*
* PARAMETERS :
* @camera_id : camera ID
* @hw_device : ptr to struct storing camera hardware device info
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::cameraDeviceOpen(int camera_id,
struct hw_device_t **hw_device)
{
int rc = NO_ERROR;
if (camera_id < 0 || camera_id >= mNumOfCameras)
return -ENODEV;
if ( NULL == mHalDescriptors ) {
LOGE("Hal descriptor table is not initialized!");
return NO_INIT;
}
LOGI("Open camera id %d API version %d",
camera_id, mHalDescriptors[camera_id].device_version);
if ( mHalDescriptors[camera_id].device_version == CAMERA_DEVICE_API_VERSION_3_0 ) {
CAMSCOPE_INIT(CAMSCOPE_SECTION_HAL);
QCamera3HardwareInterface *hw = new QCamera3HardwareInterface(mHalDescriptors[camera_id].cameraId,
mCallbacks);
if (!hw) {
LOGE("Allocation of hardware interface failed");
return NO_MEMORY;
}
rc = hw->openCamera(hw_device);
if (rc != 0) {
delete hw;
}
}
#ifdef QCAMERA_HAL1_SUPPORT
else if (mHalDescriptors[camera_id].device_version == CAMERA_DEVICE_API_VERSION_1_0) {
QCamera2HardwareInterface *hw = new QCamera2HardwareInterface((uint32_t)camera_id);
if (!hw) {
LOGE("Allocation of hardware interface failed");
return NO_MEMORY;
}
rc = hw->openCamera(hw_device);
if (rc != NO_ERROR) {
delete hw;
}
}
#endif
else {
LOGE("Device version for camera id %d invalid %d",
camera_id,
mHalDescriptors[camera_id].device_version);
return BAD_VALUE;
}
return rc;
}
/*===========================================================================
* FUNCTION : camera_device_open
*
* DESCRIPTION: static function to open a camera device by its ID
*
* PARAMETERS :
* @camera_id : camera ID
* @hw_device : ptr to struct storing camera hardware device info
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::camera_device_open(
const struct hw_module_t *module, const char *id,
struct hw_device_t **hw_device)
{
int rc = NO_ERROR;
if (module != &HAL_MODULE_INFO_SYM.common) {
LOGE("Invalid module. Trying to open %p, expect %p",
module, &HAL_MODULE_INFO_SYM.common);
return INVALID_OPERATION;
}
if (!id) {
LOGE("Invalid camera id");
return BAD_VALUE;
}
#ifdef QCAMERA_HAL1_SUPPORT
if(gQCameraMuxer)
rc = gQCameraMuxer->camera_device_open(module, id, hw_device);
else
#endif
rc = gQCamera2Factory->cameraDeviceOpen(atoi(id), hw_device);
return rc;
}
struct hw_module_methods_t QCamera2Factory::mModuleMethods = {
.open = QCamera2Factory::camera_device_open,
};
/*===========================================================================
* FUNCTION : openLegacy
*
* DESCRIPTION: Function to open older hal version implementation
*
* PARAMETERS :
* @camera_id : camera ID
* @halVersion: Based on camera_module_t.common.module_api_version
* @hw_device : ptr to struct storing camera hardware device info
*
* RETURN : 0 -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::openLegacy(
int32_t cameraId, uint32_t halVersion, struct hw_device_t** hw_device __unused)
{
int rc = NO_ERROR;
LOGI("openLegacy halVersion: %d cameraId = %d", halVersion, cameraId);
//Assumption: all cameras can support legacy API version
if (cameraId < 0 || cameraId >= gQCamera2Factory->getNumberOfCameras())
return -ENODEV;
switch(halVersion)
{
#ifdef QCAMERA_HAL1_SUPPORT
case CAMERA_DEVICE_API_VERSION_1_0:
{
CAMSCOPE_INIT(CAMSCOPE_SECTION_HAL);
QCamera2HardwareInterface *hw =
new QCamera2HardwareInterface((uint32_t)cameraId);
if (!hw) {
LOGE("Allocation of hardware interface failed");
return NO_MEMORY;
}
rc = hw->openCamera(hw_device);
if (rc != NO_ERROR) {
delete hw;
}
break;
}
#endif
default:
LOGE("Device API version: %d for camera id %d invalid",
halVersion, cameraId);
return BAD_VALUE;
}
return rc;
}
/*===========================================================================
* FUNCTION : setTorchMode
*
* DESCRIPTION: Attempt to turn on or off the torch mode of the flash unit.
*
* PARAMETERS :
* @camera_id : camera ID
* @on : Indicates whether to turn the flash on or off
*
* RETURN : 0 -- success
* none-zero failure code
*==========================================================================*/
int QCamera2Factory::setTorchMode(const char* camera_id, bool on)
{
int retVal(0);
long cameraIdLong(-1);
int cameraIdInt(-1);
char* endPointer = NULL;
errno = 0;
QCameraFlash& flash = QCameraFlash::getInstance();
cameraIdLong = strtol(camera_id, &endPointer, 10);
if ((errno == ERANGE) ||
(cameraIdLong < 0) ||
(cameraIdLong >= static_cast<long>(get_number_of_cameras())) ||
(endPointer == camera_id) ||
(*endPointer != '\0')) {
retVal = -EINVAL;
} else if (on) {
cameraIdInt = static_cast<int>(cameraIdLong);
retVal = flash.initFlash(cameraIdInt);
if (retVal == 0) {
retVal = flash.setFlashMode(cameraIdInt, on);
if ((retVal == 0) && (mCallbacks != NULL)) {
mCallbacks->torch_mode_status_change(mCallbacks,
camera_id,
TORCH_MODE_STATUS_AVAILABLE_ON);
} else if (retVal == -EALREADY) {
// Flash is already on, so treat this as a success.
retVal = 0;
}
}
} else {
cameraIdInt = static_cast<int>(cameraIdLong);
retVal = flash.setFlashMode(cameraIdInt, on);
if (retVal == 0) {
retVal = flash.deinitFlash(cameraIdInt);
if ((retVal == 0) && (mCallbacks != NULL)) {
mCallbacks->torch_mode_status_change(mCallbacks,
camera_id,
TORCH_MODE_STATUS_AVAILABLE_OFF);
}
} else if (retVal == -EALREADY) {
// Flash is already off, so treat this as a success.
retVal = 0;
}
}
return retVal;
}
/*===========================================================================
* FUNCTION : isDualCamAvailable
*
* DESCRIPTION: Function to check whether we have dual Camera HW available
*
* PARAMETERS :
* @hal3Enabled : HAL3 enable flag
*
* RETURN : bool - true : have Dual Camera HW available
* false : not have Dual Camera HW available
*==========================================================================*/
bool QCamera2Factory::isDualCamAvailable(int hal3Enabled)
{
bool rc = false;
int i = 0;
#ifdef QCAMERA_HAL1_SUPPORT
camera_info info;
#endif
cam_sync_type_t cam_type = CAM_TYPE_MAIN;
for (i = 0; i < mNumOfCameras; i++) {
if (!hal3Enabled) {
#ifdef QCAMERA_HAL1_SUPPORT
QCamera2HardwareInterface::getCapabilities(i, &info, &cam_type);
#endif
}
if(cam_type == CAM_TYPE_AUX) {
LOGH("Have Dual Camera HW Avaiable.");
rc = true;
break;
}
}
#ifdef QCAMERA_HAL1_SUPPORT
return rc;
#else
return false;
#endif
}
}; // namespace qcamera

View file

@ -0,0 +1,81 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA2FACTORY_H__
#define __QCAMERA2FACTORY_H__
// Camera dependencies
#include "hardware/camera_common.h"
namespace qcamera {
typedef struct {
uint32_t cameraId;
uint32_t device_version;
} hal_desc;
class QCamera2Factory
{
public:
QCamera2Factory();
virtual ~QCamera2Factory();
static int get_number_of_cameras();
static int get_camera_info(int camera_id, struct camera_info *info);
static int set_callbacks(const camera_module_callbacks_t *callbacks);
static int open_legacy(const struct hw_module_t* module,
const char* id, uint32_t halVersion, struct hw_device_t** device);
static int set_torch_mode(const char* camera_id, bool on);
bool isDualCamAvailable(int hal3Enabled);
private:
int getNumberOfCameras();
int getCameraInfo(int camera_id, struct camera_info *info);
int setCallbacks(const camera_module_callbacks_t *callbacks);
int cameraDeviceOpen(int camera_id, struct hw_device_t **hw_device);
static int camera_device_open(const struct hw_module_t *module, const char *id,
struct hw_device_t **hw_device);
static int openLegacy(
int32_t cameraId, uint32_t halVersion, struct hw_device_t** hw_device);
int setTorchMode(const char* camera_id, bool on);
public:
static struct hw_module_methods_t mModuleMethods;
private:
int mNumOfCameras;
int mNumOfCameras_expose;
hal_desc *mHalDescriptors;
const camera_module_callbacks_t *mCallbacks;
};
}; /*namespace qcamera*/
extern camera_module_t HAL_MODULE_INFO_SYM;
#endif /* __QCAMERA2FACTORY_H__ */

59
QCamera2/QCamera2Hal.cpp Normal file
View file

@ -0,0 +1,59 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// Camera dependencies
#include "QCamera2Factory.h"
#include "util/QCameraCommon.h"
#include "HAL3/QCamera3VendorTags.h"
#include "util/QCameraCommon.h"
static hw_module_t camera_common = {
.tag = HARDWARE_MODULE_TAG,
.module_api_version = CAMERA_MODULE_API_VERSION_2_4,
.hal_api_version = HARDWARE_HAL_API_VERSION,
.id = CAMERA_HARDWARE_MODULE_ID,
.name = "QCamera Module",
.author = "Qualcomm Innovation Center Inc",
.methods = &qcamera::QCamera2Factory::mModuleMethods,
.dso = NULL,
.reserved = {0}
};
camera_module_t HAL_MODULE_INFO_SYM = {
.common = camera_common,
.get_number_of_cameras = qcamera::QCamera2Factory::get_number_of_cameras,
.get_camera_info = qcamera::QCamera2Factory::get_camera_info,
.set_callbacks = qcamera::QCamera2Factory::set_callbacks,
.get_vendor_tag_ops = qcamera::QCamera3VendorTags::get_vendor_tag_ops,
.open_legacy = (qcamera::QCameraCommon::needHAL1Support()) ?
qcamera::QCamera2Factory::open_legacy : NULL,
.set_torch_mode = qcamera::QCamera2Factory::set_torch_mode,
.init = NULL,
.reserved = {0}
};

44
QCamera2/QCameraFormat.h Normal file
View file

@ -0,0 +1,44 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Macros exposed to gralloc to query camera HAL for gralloc format to be
used for vedor specific camera formats. */
#define PREFERRED_IMPLEMENTATION_DEFINED_CAMERA_FORMAT HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS
#define PREFERRED_YCBCR_420_888_CAMERA_FORMAT HAL_PIXEL_FORMAT_NV21_ZSL
/* Macros exposed to camera HAL to get the preview and callback stream
formats. Please ensure that if the macros below are changed then the
corresponding change should be done in the above macros and vice versa
to prevent format mismatch between Gralloc and Camera HAL for stream
buffers */
#define PREVIEW_STREAM_FORMAT CAM_FORMAT_YUV_420_NV12_VENUS
#define CALLBACK_STREAM_FORMAT CAM_FORMAT_YUV_420_NV21

View file

@ -0,0 +1,47 @@
# Use SDCLANG if its version is >= 4.
# Else use SDCLANG_2 if it exists and its version is >= 4.
# Else use SDCLANG.
ifeq ($(CAMERA_USE_SDCLANG),)
CAMERA_USE_SDCLANG := true
CAMERA_USE_SDCLANG_2 := false
# Append Android build top if path is not absolute.
ifneq ($(SDCLANG_PATH),$(filter /%,$(SDCLANG_PATH)))
CAMERA_SDCLANG_ABS_PATH := $(ANDROID_BUILD_TOP)/$(SDCLANG_PATH)
else
CAMERA_SDCLANG_ABS_PATH := $(SDCLANG_PATH)
endif
ifneq ($(wildcard $(CAMERA_SDCLANG_ABS_PATH)),)
CAMERA_SDCLANG_VERSION := $(shell $(CAMERA_SDCLANG_ABS_PATH)/llvm-config --version)
ifneq ($(shell expr $(CAMERA_SDCLANG_VERSION) \>= 4), 1)
# Append Android build top if path is not absolute.
ifneq ($(SDCLANG_PATH_2),$(filter /%,$(SDCLANG_PATH_2)))
CAMERA_SDCLANG_ABS_PATH_2 := $(ANDROID_BUILD_TOP)/$(SDCLANG_PATH_2)
else
CAMERA_SDCLANG_ABS_PATH_2 := $(SDCLANG_PATH_2)
endif
ifneq ($(wildcard $(CAMERA_SDCLANG_ABS_PATH_2)),)
CAMERA_SDCLANG_VERSION_2 := $(shell $(CAMERA_SDCLANG_ABS_PATH_2)/llvm-config --version)
ifeq ($(shell expr $(CAMERA_SDCLANG_VERSION_2) \>= 4), 1)
CAMERA_USE_SDCLANG := false
CAMERA_USE_SDCLANG_2 := true
endif
else
# CAMERA_SDCLANG_ABS_PATH_2 does not exist.
CAMERA_USE_SDCLANG_2 := false
endif
endif
else
# CAMERA_SDCLANG_ABS_PATH does not exist.
CAMERA_USE_SDCLANG := false
endif
endif
LOCAL_SDCLANG := $(CAMERA_USE_SDCLANG)
LOCAL_SDCLANG_2 := $(CAMERA_USE_SDCLANG_2)
LOCAL_SDCLANG_LTO := true

View file

@ -0,0 +1,19 @@
SDCLANG_FLAGS := -Ofast -ffp-contract=fast -mcpu=cortex-a53 -mfpu=crypto-neon-fp-armv8 -fno-fast-math -Wl,--no-fatal-warnings
SDCLANG_LINK := -fuse-ld=qcld
# Turn on LTO for libs which set LOCAL_SDCLANG_LTO := true.
ifeq ($(LOCAL_SDCLANG_LTO),true)
SDCLANG_LTO := -flto
endif
# Note: LOCAL_SDCLANG_EXTRA_FLAGS can be set in the individual module's .mk
# file in order to override the default SDCLANG_FLAGS.
SDCLANG_CFLAGS := $(SDCLANG_FLAGS) $(SDCLANG_LTO) $(SDCLANG_LINK)
SDCLANG_LDFLAGS := $(SDCLANG_FLAGS) $(SDCLANG_LTO)
LOCAL_CFLAGS += $(SDCLANG_CFLAGS)
LOCAL_CXX_FLAGS += $(SDCLANG_CFLAGS)
LOCAL_LDFLAGS += $(SDCLANG_LDFLAGS)
LOCAL_CFLAGS_32 += $(LOCAL_SDCLANG_EXTRA_FLAGS_32)
LOCAL_LDFLAGS_32 += $(LOCAL_SDCLANG_EXTRA_FLAGS_32)

View file

@ -0,0 +1,8 @@
LOCAL_PATH:= $(call my-dir)
include $(LOCAL_PATH)/mm-camera-interface/Android.mk
include $(LOCAL_PATH)/mm-jpeg-interface/Android.mk
include $(LOCAL_PATH)/common/leak/Android.mk
ifeq ($(LIB2D_ROTATION), true)
include $(LOCAL_PATH)/mm-lib2d-interface/Android.mk
endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,85 @@
/* Copyright (c) 2012, 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* This file is a slave copy from /vendor/qcom/propreitary/mm-cammera/common,
* Please do not modify it directly here. */
#ifndef __CAMLIST_H
#define __CAMLIST_H
#include <stddef.h>
// System dependency
#include <stdlib.h>
#define member_of(ptr, type, member) ({ \
const typeof(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type,member));})
struct cam_list {
struct cam_list *next, *prev;
};
static inline void cam_list_init(struct cam_list *ptr)
{
ptr->next = ptr;
ptr->prev = ptr;
}
static inline void cam_list_add_tail_node(struct cam_list *item,
struct cam_list *head)
{
struct cam_list *prev = head->prev;
head->prev = item;
item->next = head;
item->prev = prev;
prev->next = item;
}
static inline void cam_list_insert_before_node(struct cam_list *item,
struct cam_list *node)
{
item->next = node;
item->prev = node->prev;
item->prev->next = item;
node->prev = item;
}
static inline void cam_list_del_node(struct cam_list *ptr)
{
struct cam_list *prev = ptr->prev;
struct cam_list *next = ptr->next;
next->prev = ptr->prev;
prev->next = ptr->next;
ptr->next = ptr;
ptr->prev = ptr;
}
#endif /* __CAMLIST_H */

View file

@ -0,0 +1,140 @@
/* Copyright (c) 2012, 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// System dependencies
#include <pthread.h>
// Camera dependencies
#include "cam_list.h"
typedef struct {
struct cam_list list;
void *data;
} cam_node_t;
typedef struct {
cam_node_t head; /* dummy head */
uint32_t size;
pthread_mutex_t lock;
} cam_queue_t;
static inline int32_t cam_queue_init(cam_queue_t *queue)
{
pthread_mutex_init(&queue->lock, NULL);
cam_list_init(&queue->head.list);
queue->size = 0;
return 0;
}
static inline int32_t cam_queue_enq(cam_queue_t *queue, void *data)
{
cam_node_t *node =
(cam_node_t *)malloc(sizeof(cam_node_t));
if (NULL == node) {
return -1;
}
memset(node, 0, sizeof(cam_node_t));
node->data = data;
pthread_mutex_lock(&queue->lock);
cam_list_add_tail_node(&node->list, &queue->head.list);
queue->size++;
pthread_mutex_unlock(&queue->lock);
return 0;
}
static inline void *cam_queue_deq(cam_queue_t *queue)
{
cam_node_t *node = NULL;
void *data = NULL;
struct cam_list *head = NULL;
struct cam_list *pos = NULL;
pthread_mutex_lock(&queue->lock);
head = &queue->head.list;
pos = head->next;
if (pos != head) {
node = member_of(pos, cam_node_t, list);
cam_list_del_node(&node->list);
queue->size--;
}
pthread_mutex_unlock(&queue->lock);
if (NULL != node) {
data = node->data;
free(node);
}
return data;
}
static inline int32_t cam_queue_flush(cam_queue_t *queue)
{
cam_node_t *node = NULL;
struct cam_list *head = NULL;
struct cam_list *pos = NULL;
pthread_mutex_lock(&queue->lock);
if (queue->size == 0) {
pthread_mutex_unlock(&queue->lock);
return 0;
}
head = &queue->head.list;
pos = head->next;
while(pos != head) {
node = member_of(pos, cam_node_t, list);
pos = pos->next;
cam_list_del_node(&node->list);
queue->size--;
/* TODO later to consider ptr inside data */
/* for now we only assume there is no ptr inside data
* so we free data directly */
if (NULL != node->data) {
free(node->data);
}
free(node);
}
queue->size = 0;
pthread_mutex_unlock(&queue->lock);
return 0;
}
static inline int32_t cam_queue_deinit(cam_queue_t *queue)
{
cam_queue_flush(queue);
pthread_mutex_destroy(&queue->lock);
return 0;
}

View file

@ -0,0 +1,94 @@
/* Copyright (c) 2012, 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __QCAMERA_SEMAPHORE_H__
#define __QCAMERA_SEMAPHORE_H__
// System dependencies
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Implement semaphore with mutex and conditional variable.
* Reason being, POSIX semaphore on Android are not used or
* well tested.
*/
typedef struct {
int val;
pthread_mutex_t mutex;
pthread_cond_t cond;
} cam_semaphore_t;
static inline void cam_sem_init(cam_semaphore_t *s, int n)
{
pthread_condattr_t cond_attr;
pthread_condattr_init(&cond_attr);
pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
pthread_mutex_init(&(s->mutex), NULL);
pthread_cond_init(&(s->cond), &cond_attr);
pthread_condattr_destroy(&cond_attr);
s->val = n;
}
static inline void cam_sem_post(cam_semaphore_t *s)
{
pthread_mutex_lock(&(s->mutex));
s->val++;
pthread_cond_signal(&(s->cond));
pthread_mutex_unlock(&(s->mutex));
}
static inline int cam_sem_wait(cam_semaphore_t *s)
{
int rc = 0;
pthread_mutex_lock(&(s->mutex));
while (s->val == 0)
rc = pthread_cond_wait(&(s->cond), &(s->mutex));
s->val--;
pthread_mutex_unlock(&(s->mutex));
return rc;
}
static inline void cam_sem_destroy(cam_semaphore_t *s)
{
pthread_mutex_destroy(&(s->mutex));
pthread_cond_destroy(&(s->cond));
s->val = 0;
}
#ifdef __cplusplus
}
#endif
#endif /* __QCAMERA_SEMAPHORE_H__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,273 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __CAMSCOPE_PACKET_TYPE_H__
#define __CAMSCOPE_PACKET_TYPE_H__
#include <stdint.h>
#include <time.h>
#define CAMSCOPE_OFF_FLAG 0x00000000
#define CAMSCOPE_ON_FLAG 0xFFFFFFFF
#define CAMSCOPE_OFF_MASK 0x00000000
#define CAMSCOPE_KPI_MASK 0x00000001
#define CAMSCOPE_KPI_DBG_MASK 0x00000002
#define CAMSCOPE_ALWAYS_ON_MASK 0xFFFFFFFF
extern volatile uint32_t kpi_camscope_flags;
extern volatile uint32_t kpi_camscope_frame_count;
typedef enum {
CAMSCOPE_SECTION_MMCAMERA,
CAMSCOPE_SECTION_HAL,
CAMSCOPE_SECTION_JPEG,
CAMSCOPE_SECTION_SIZE,
} camscope_section_type;
typedef enum {
CAMSCOPE_BASE,
CAMSCOPE_SOFTWARE_BASE,
CAMSCOPE_SYNC_BEGIN,
CAMSCOPE_SYNC_END,
CAMSCOPE_ASYNC_BEGIN,
CAMSCOPE_ASYNC_END,
CAMSCOPE_SYNC_EVENT,
CAMSCOPE_ASYNC_EVENT,
CAMSCOPE_RESERVED = 0xFFFFFFFF
} camscope_packet_type;
typedef enum {
CAMSCOPE_MCT_SOF,
CAMSCOPE_MCT_SUP_PARAMS,
CAMSCOPE_MCT_SPEC_EVT,
CAMSCOPE_MCT_BUS_PROC,
CAMSCOPE_AFD,
CAMSCOPE_ASD,
CAMSCOPE_AEC,
CAMSCOPE_AWB,
CAMSCOPE_AF,
CAMSCOPE_CPP,
CAMSCOPE_CPP_CAPTURE,
CAMSCOPE_CPP_CLK_REQ,
CAMSCOPE_CPP_HOLDING,
CAMSCOPE_CPP_HW_ON,
CAMSCOPE_SNAPSHOT,
CAMSCOPE_ISP_HW_UPDATE,
CAMSCOPE_JPEG,
CAMSCOPE_FACEPROC,
CAMSCOPE_SENSOR_PROCESS,
CAMSCOPE_FD_NUM_DETECTED,
CAMSCOPE_CAM_ALLOC,
CAMSCOPE_IFACE_STREAMON_FWD,
CAMSCOPE_IFACE_STREAMON_THREAD,
CAMSCOPE_IFACE_STREAMOFF_FWD,
CAMSCOPE_IFACE_STREAMOFF_THREAD,
CAMSCOPE_IFACE_CFG_ISP,
CAMSCOPE_IFACE_HW_CFG,
CAMSCOPE_IFACE_CREATE_AXI_HW,
CAMSCOPE_IFACE_CFG_AXI_HW,
CAMSCOPE_IFACE_STREAMON,
CAMSCOPE_IFACE_STREAMOFF,
CAMSCOPE_AF_START,
CAMSCOPE_AF_SET,
CAMSCOPE_IS,
CAMSCOPE_ISP_STREAMON,
CAMSCOPE_ISP_STREAMOFF,
CAMSCOPE_ISP_SET_STRM_CFG,
CAMSCOPE_VFE_HW_UPDATE,
CAMSCOPE_ISP_STREAMON_FWD,
CAMSCOPE_SENSOR_SD_OPEN,
CAMSCOPE_SENSOR_START_SESSION,
CAMSCOPE_SENSOR_SET_RESOLUTION,
CAMSCOPE_SENSOR_SET_STRM_CFG,
CAMSCOPE_SENSOR_CFG_PDAF,
CAMSCOPE_SENSOR_LOAD_CHROMATIX,
CAMSCOPE_SENSOR_START_STREAM,
CAMSCOPE_SENSOR_SET_FPS,
CAMSCOPE_SENSOR_STREAMOFF,
CAMSCOPE_WNR,
CAMSCOPE_WNR_MEMCPY,
CAMSCOPE_PPROC_STREAMOFF,
CAMSCOPE_CPP_STREAMON,
CAMSCOPE_CAC,
CAMSCOPE_CPP_CREATE_HW_FRAME,
CAMSCOPE_CPP_SET_STRM_CFG,
CAMSCOPE_MCT_START_SESSION,
CAMSCOPE_MCT_STOP_SESSION,
CAMSCOPE_IMGLIB_STREAMON,
CAMSCOPE_MCT_CREATE_BUF,
CAMSCOPE_HAL1_START_PREVIEW,
CAMSCOPE_HAL1_STOP_PREVIEW,
CAMSCOPE_HAL1_TAKE_PICTURE,
CAMSCOPE_HAL1_CLOSECAMERA,
CAMSCOPE_HAL1_OPENCAMERA,
CAMSCOPE_HAL1_STARTPREVIEW,
CAMSCOPE_HAL1_STOPPREVIEW,
CAMSCOPE_HAL1_CAPTURE_CH_CB,
CAMSCOPE_HAL1_PREVIEW_STRM_CB,
CAMSCOPE_HAL3_SNAPSHOT,
CAMSCOPE_HAL3_GETSTREAMBUFS,
CAMSCOPE_HAL3_OPENCAMERA,
CAMSCOPE_HAL3_CLOSECAMERA,
CAMSCOPE_HAL3_FLUSH,
CAMSCOPE_HAL1_ZSL_CH_CB,
CAMSCOPE_HAL1_PP_CH_CB,
CAMSCOPE_HAL1_SYNC_STRM_CB,
CAMSCOPE_HAL1_NODIS_PREVIEW_STRMCB,
CAMSCOPE_HAL1_RDI_MODE_STRM_CB,
CAMSCOPE_HAL1_POSTVIEW_STRM_CB,
CAMSCOPE_HAL1_VIDEO_STRM_CB,
CAMSCOPE_HAL1_SNAPSHOT_CH_CB,
CAMSCOPE_HAL1_RAW_STRM_CB,
CAMSCOPE_HAL1_RAW_CH_CB,
CAMSCOPE_HAL1_PREVIEW_RAW_STRM_CB,
CAMSCOPE_HAL1_SNAPSHOT_RAW_STRM_CB,
CAMSCOPE_HAL1_METADATA_STRM_CB,
CAMSCOPE_HAL1_REPROC_STRM_CB,
CAMSCOPE_HAL1_CB_STRM_CB,
CAMSCOPE_HAL1_SET_PREVIEW_WINDOW,
CAMSCOPE_HAL1_SET_CALLBACKS,
CAMSCOPE_HAL1_ENABLE_MSG_TYPE,
CAMSCOPE_HAL1_DISABLE_MSG_TYPE,
CAMSCOPE_HAL1_MSG_TYPE_ENABLED,
CAMSCOPE_HAL1_PREPARE_PREVIEW,
CAMSCOPE_HAL1_PREVIEW_ENABLED,
CAMSCOPE_HAL1_RESTART_START_PREVIEW,
CAMSCOPE_HAL1_RESTART_STOP_PREVIEW,
CAMSCOPE_HAL1_PRE_START_RECORDING,
CAMSCOPE_HAL1_START_RECORDING,
CAMSCOPE_HAL1_STOP_RECORDING,
CAMSCOPE_HAL1_RECORDING_ENABLED,
CAMSCOPE_HAL1_REL_REC_FRAME,
CAMSCOPE_HAL1_CANCEL_AF,
CAMSCOPE_HAL1_PRE_TAKE_PICTURE,
CAMSCOPE_HAL1_CANCEL_PICTURE,
CAMSCOPE_HAL1_SET_PARAMETERS,
CAMSCOPE_HAL1_STOP_AFTER_SET_PARAMS,
CAMSCOPE_HAL1_COMMIT_PARAMS,
CAMSCOPE_HAL1_RESTART_AFTER_SET_PARAMS,
CAMSCOPE_HAL1_GET_PARAMETERS,
CAMSCOPE_HAL1_PUT_PARAMETERS,
CAMSCOPE_HAL1_SEND_COMMAND,
CAMSCOPE_HAL1_SEND_COMMAND_RESTART,
CAMSCOPE_HAL1_RELEASE,
CAMSCOPE_HAL1_REGISTER_FACE_IMAGE,
CAMSCOPE_HAL1_PREPARE_SNAPSHOT,
CAMSCOPE_HAL1_QCAMERA2HWI,
CAMSCOPE_HAL1_INIT_CAP,
CAMSCOPE_HAL1_GET_CAP,
CAMSCOPE_HAL1_PREPAREPREVIEW,
CAMSCOPE_HAL1_PREPARE_HW_FOR_SNAPSHOT,
CAMSCOPE_HAL3_INIT,
CAMSCOPE_HAL3_CFG_STRMS,
CAMSCOPE_HAL3_CFG_STRMS_PERF_LKD,
CAMSCOPE_HAL3_HANDLE_BATCH_METADATA,
CAMSCOPE_HAL3_HANDLE_METADATA_LKD,
CAMSCOPE_HAL3_HANDLE_IN_BUF_LKD,
CAMSCOPE_HAL3_HANDLE_BUF_LKD,
CAMSCOPE_HAL3_PROC_CAP_REQ,
CAMSCOPE_HAL3_FLUSH_PREF,
CAMSCOPE_HAL3_GET_CAM_INFO,
CAMSCOPE_HAL3_DYN_UPDATE_META_STRM_INFO,
CAMSCOPE_HAL3_CH_START,
CAMSCOPE_HAL3_CH_STOP,
CAMSCOPE_HAL3_CH_FLUSH,
CAMSCOPE_HAL3_PROC_CH_STRM_CB,
CAMSCOPE_HAL3_PROC_CH_REG_BUF,
CAMSCOPE_HAL3_PROC_CH_REPROC_CB,
CAMSCOPE_HAL3_REG_CH_INIT,
CAMSCOPE_HAL3_REG_CH_REQ,
CAMSCOPE_HAL3_METADATA_CH_INIT,
CAMSCOPE_HAL3_RAW_CH_STRM_CB,
CAMSCOPE_HAL3_YUV_CH_INIT,
CAMSCOPE_HAL3_YUV_CH_STRM_CB,
CAMSCOPE_HAL3_PIC_CH_JPEG_EVT_HANDLE,
CAMSCOPE_HAL3_PIC_CH_REQ,
CAMSCOPE_HAL3_PIC_CH_DATA_NOTIFY_CB,
CAMSCOPE_HAL3_PIC_CH_STRM_CB,
CAMSCOPE_HAL3_REPROC_CH_REG_BUF,
CAMSCOPE_HAL3_REPROC_CH_START,
CAMSCOPE_HAL3_REPROC_CH_STOP,
CAMSCOPE_HAL3_PPROC_INIT,
CAMSCOPE_HAL3_PPROC_INIT_JPEG,
CAMSCOPE_HAL3_PPROC_REL_JPEG_JOB_DATA,
CAMSCOPE_HAL3_PPROC_REL_PP_JOB_DATA,
CAMSCOPE_HAL3_PPROC_ENCODEDATA,
CAMSCOPE_HAL3_PREVIEW_STRM_CB,
CAMSCOPE_HAL3_STOP_PREVIEW,
CAMSCOPE_HAL3_CAPTURE_CH_CB,
CAMSCOPE_EVENT_NAME_SIZE
} camscope_event_name;
extern const char * camscope_atrace_names[CAMSCOPE_EVENT_NAME_SIZE];
typedef struct {
uint32_t packet_type;
uint32_t size;
} camscope_base;
typedef struct {
camscope_base base;
struct timeval timestamp;
int32_t thread_id;
uint32_t event_name;
} camscope_sw_base;
typedef struct {
camscope_sw_base sw_base;
uint32_t frame_id;
} camscope_timing;
typedef struct {
camscope_sw_base sw_base;
struct timeval in_timestamp;
struct timeval out_timestamp;
uint32_t frame_id;
} camscope_in_out_timing;
void camscope_base_log(uint32_t camscope_section,
uint32_t camscope_enable_mask,
uint32_t packet_type);
void camscope_sw_base_log(uint32_t camscope_section,
uint32_t camscope_enable_mask, uint32_t packet_type,
uint32_t event_name);
void camscope_timing_log(uint32_t camscope_section,
uint32_t camscope_enable_mask, uint32_t packet_type,
uint32_t event_name, uint32_t frame_id);
void camscope_in_out_timing_log(uint32_t camscope_section,
uint32_t camscope_enable_mask,
uint32_t packet_type, uint32_t event_name,
struct timeval in_timestamp,
struct timeval out_timestamp,
uint32_t frame_id);
#endif /* __CAMSCOPE_PACKET_TYPE_H__ */

View file

@ -0,0 +1,28 @@
LOCAL_PATH:= $(call my-dir)
# trace logging lib
include $(CLEAR_VARS)
LOCAL_CFLAGS := -D_ANDROID_
LOCAL_CFLAGS += -Werror -Wunused-parameter
ifneq (,$(filter address,$(SANITIZE_TARGET)))
LOCAL_CFLAGS += -D__BIONIC_FORTIFY
endif
#************* HAL headers ************#
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../mm-camera-interface/inc
LOCAL_HEADER_LIBRARIES := libutils_headers
#************* Kernel headers ************#
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
LOCAL_SRC_FILES := fdleak.cpp memleak.cpp
LOCAL_SHARED_LIBRARIES := libdl libcutils liblog
LOCAL_MODULE := libhal_dbg
LOCAL_MODULE_TAGS := optional
LOCAL_VENDOR_MODULE := true
include $(BUILD_SHARED_LIBRARY)

View file

@ -0,0 +1,322 @@
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCameraLeak"
#include <dlfcn.h>
#include <stdio.h>
#include <ctype.h>
#include <unwind.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <inttypes.h>
#include <cutils/properties.h>
// System dependencies
#include <log/log.h>
#include <iostream>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include "fdleak.h"
#include "memleak.h"
#include <errno.h>
#include "mm_camera_dbg.h"
#define MAX_BACKTRACE_DEPTH 15
#define MAGIC_ALLOC 0x7abc0fb5
#define MAGIC_FREE 0x087cbc8a
struct fdlist_t {
uintptr_t bt[MAX_BACKTRACE_DEPTH];
int bt_depth;
int fd;
struct fdlist_t *next;
int allocated;
} __attribute__((packed));
typedef struct fdlist_t fdlist_t;
struct map_info_holder {
char *name;
struct map_info_holder* next;
uintptr_t start;
uintptr_t end;
};
struct stack_crawl_state_t {
uintptr_t *addr;
int skip;
size_t stack_count;
size_t max_depth;
};
pthread_mutex_t hal_debug_fdleak_mut = PTHREAD_MUTEX_INITIALIZER;
static unsigned int fdleak_count = 0;
static fdlist_t *head = NULL;
typedef int (*real_open_type)(const char *, int, ...);
typedef int (*real_open2_type)(const char *, int);
typedef int (*real_pipe_type)(int *);
typedef int (*real_socket_type)(int, int, int);
typedef void* (*real_mmap_type)(void*, size_t, int, int, int, off_t);
typedef int (*real_close_type)(int);
static real_open_type __real_open = NULL;
static real_open2_type __real_open2 = NULL;
static real_pipe_type __real_pipe= NULL;
static real_socket_type __real_socket= NULL;
static real_mmap_type __real_mmap= NULL;
static real_close_type __real_close= NULL;
static inline void add(int fd_value)
{
fdlist_t *fdlist;
fdlist = (fdlist_t *) malloc(sizeof(fdlist_t));
if (!fdlist)
return;
fdlist->allocated = MAGIC_ALLOC;
fdlist->bt_depth = 0;
fdlist->fd = fd_value;
pthread_mutex_lock(&hal_debug_fdleak_mut);
fdlist->bt_depth = mmcamera_stacktrace(fdlist->bt, MAX_BACKTRACE_DEPTH);
fdlist->next = head;
head = fdlist;
fdleak_count++;
pthread_mutex_unlock(&hal_debug_fdleak_mut);
}
extern "C" void fdleak_dump_list()
{
struct map_info_holder *p_map_info;
struct fdlist_t *temp;
temp = head;
pthread_mutex_lock(&hal_debug_fdleak_mut);
p_map_info = lib_map_create(getpid());
while (temp != NULL) {
ALOGE("leaked fd %d\n",temp->fd);
print_backtrace(p_map_info, temp->bt, temp->bt_depth);
temp = temp->next;
}
lib_map_destroy(p_map_info);
pthread_mutex_unlock(&hal_debug_fdleak_mut);
fdleak_count = 0;
}
int __open(const char* dev_name, int flags, ...)
{
int fd_value;
mode_t mode = 0;
if ((flags & O_CREAT) != 0) {
va_list args;
va_start(args, flags);
mode = static_cast<mode_t>(va_arg(args, int));
va_end(args);
}
fd_value = open(dev_name, flags, mode);
if (errno == EMFILE) {
ALOGE("FATAL during open %s ",strerror(errno));
}
if (fd_value > 0) {
add( fd_value);
return fd_value;
}
return fd_value;
}
int __open2(const char* dev_name, int flags)
{
int fd_value;
fd_value = __open_2(dev_name, flags);
if (errno == EMFILE) {
ALOGE("FATAL during open %s ",strerror(errno));
}
if (fd_value > 0) {
add( fd_value);
return fd_value;
}
return fd_value;
}
int __pipe(int fd[])
{
int ret_value;
ret_value = pipe(fd);
if (errno == EMFILE) {
ALOGE("FATAL during pipe creation %s" ,strerror(errno));
}
if (ret_value >= 0) {
add( fd[0]);
add( fd[1]);
return ret_value;
}
return ret_value;
}
int __socket(int domain, int type, int protocol)
{
int ds_fd ;
ds_fd = socket(domain, type, protocol);
if (errno == EMFILE) {
ALOGE("FATAL during socket create %s",strerror(errno));
}
if (ds_fd > 0) {
add( ds_fd);
return ds_fd;
}
return ds_fd;
}
void* __mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset)
{
void* ret;
ret = mmap(addr, size, prot, flags, fd, offset);
if (errno == EMFILE) {
ALOGE("FATAL during mmap %s",strerror(errno));
}
if (fd > 0 && ret != MAP_FAILED) {
add( fd);
return ret;
}
return ret;
}
void delete_node(int fd_value)
{
static fdlist_t *temp,*prev;
temp = head;
prev = NULL;
while (temp != NULL) {
if (temp->fd != fd_value) {
prev = temp;
temp = temp->next;
} else {
fdleak_count--;
if (temp == head) {
head = temp->next;
free(temp);
return;
}else {
prev->next = temp->next;
free(temp);
return;
}
}
}
}
static int __close(int fd_value)
{
pthread_mutex_lock(&hal_debug_fdleak_mut);
delete_node(fd_value);
pthread_mutex_unlock(&hal_debug_fdleak_mut);
return (close(fd_value));
}
void remFdCheck(int fd_value)
{
pthread_mutex_lock(&hal_debug_fdleak_mut);
delete_node(fd_value);
pthread_mutex_unlock(&hal_debug_fdleak_mut);
}
extern "C" int __wrap_open(const char* dev_name, int flags, ...)
{
mode_t mode = 0;
if ((flags & O_CREAT) != 0) {
va_list args;
va_start(args, flags);
mode = static_cast<mode_t>(va_arg(args, int));
va_end(args);
}
return __real_open(dev_name, flags, mode);
}
extern "C" int __wrap_pipe(int *fd)
{
return __real_pipe(fd);
}
extern "C" int __wrap_socket(int domain, int type, int protocol)
{
return __real_socket(domain,type,protocol);
}
extern "C" void* __wrap_mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset)
{
return __real_mmap(addr, size, prot, flags, fd, offset);
}
extern "C" int __wrap_close(int fd_value)
{
return __real_close(fd_value);
}
extern "C" int __wrap___open_2(const char* dev_name, int flags)
{
return __real_open2(dev_name, flags);
}
static __attribute__((constructor)) void init(void)
{
__real_open = open;
__real_open2 = __open_2;
__real_pipe = pipe;
__real_socket = socket;
__real_mmap = mmap;
__real_close = close;
}
void hal_debug_enable_fdleak_trace()
{
__real_open = __open;
__real_open2 = __open2;
__real_pipe = __pipe;
__real_socket = __socket;
__real_mmap = __mmap;
__real_close = __close;
}
void hal_debug_dump_fdleak_trace()
{
if (fdleak_count) {
ALOGE("FATAL fdleak found in camera hal %d",
fdleak_count);
fdleak_dump_list();
}
}
static __attribute__((destructor)) void finish(void)
{
ALOGD("fdleak lib deinit.\n");
if (fdleak_count)
fdleak_dump_list();
}

View file

@ -0,0 +1,49 @@
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef FDLEAK_H
#define FDLEAK_H
#include <pthread.h>
#include <unistd.h>
extern pthread_mutex_t hal_debug_fdleak_mut;
#ifdef __cplusplus
extern "C" {
#endif
void hal_debug_enable_fdleak_trace();
void hal_debug_dump_fdleak_trace();
void remFdCheck(int);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,415 @@
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_TAG "QCameraLeak"
#include <dlfcn.h>
#include <stdio.h>
#include <ctype.h>
#include <unwind.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <inttypes.h>
#include <cutils/properties.h>
#include "mm_camera_dbg.h"
#include "memleak.h"
#define MAX_BACKTRACE_DEPTH 15
#define MAGIC_ALLOC 0x7abc0fb5
#define MAGIC_FREE 0x087cbc8a
struct hdr_t {
int alloc_traced;
unsigned int size;
struct hdr_t *prev;
struct hdr_t *next;
uintptr_t bt[MAX_BACKTRACE_DEPTH];
int bt_depth;
int allocated;
} __attribute__((packed));
typedef struct hdr_t hdr_t;
struct map_info_holder {
char *name;
struct map_info_holder* next;
uintptr_t start;
uintptr_t end;
};
struct stack_crawl_state_t {
uintptr_t *addr;
int skip;
size_t stack_count;
size_t max_depth;
};
static pthread_mutex_t memory_mutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned int leaks_bytes = 0;
static hdr_t *last = NULL;
#define ADDITIONAL_SIZE sizeof(hdr_t)
typedef void *(*real_malloc_type)(size_t);
typedef void (*real_free_type)(void *);
typedef void *(*real_realloc_type)(void *, size_t);
typedef void *(*real_calloc_type)(size_t, size_t);
static real_malloc_type __real_malloc = NULL;
static real_calloc_type __real_calloc = NULL;
static real_realloc_type __real_realloc = NULL;
static real_free_type __real_free = NULL;
static struct map_info_holder *lib_map_find_name(struct map_info_holder *mi,
uintptr_t pc, uintptr_t* rel_pc) {
for (; mi != NULL; mi = mi->next) {
if ((pc >= mi->start) && (pc < mi->end)) {
*rel_pc = pc - mi->start;
return mi;
}
}
*rel_pc = pc;
return NULL;
}
void print_backtrace(struct map_info_holder *p_map_info, uintptr_t* frames, int frame_count)
{
int i;
struct map_info_holder *p_map_find;
uintptr_t offset, rel_pc = 0;
for (i = 0 ; i < frame_count; ++i) {
const char* symbol = NULL;
offset = 0;
Dl_info info;
const char* soname = NULL;
if (dladdr((void*) frames[i], &info) != 0) {
offset = (uintptr_t)(info.dli_saddr);
symbol = info.dli_sname;
rel_pc = offset;
p_map_find = lib_map_find_name(p_map_info, frames[i], &rel_pc);
soname = p_map_find ? p_map_find->name : info.dli_fname;
}
if (soname == NULL) {
soname = "<unknown>";
}
ALOGI("#%02d pc %08x %s (%s) \n", i, (unsigned int)rel_pc, symbol, soname);
}
}
static _Unwind_Reason_Code unwind_func_call(struct _Unwind_Context *context, void *arg)
{
struct stack_crawl_state_t *p_state = (struct stack_crawl_state_t *)arg;
uintptr_t unwind_ip = _Unwind_GetIP(context);
if (p_state->skip && unwind_ip) {
p_state->skip--;
return _URC_NO_REASON;
}
if (unwind_ip) {
short* ptr = (short *)(unwind_ip);
if ((*(ptr-1) & 0xff80) == 0x4780) {
unwind_ip -= 2;
} else {
unwind_ip -= 4;
}
}
p_state->addr[p_state->stack_count++] = unwind_ip;
return (p_state->stack_count >= p_state->max_depth) ? _URC_END_OF_STACK : _URC_NO_REASON;
}
int mmcamera_stacktrace(uintptr_t *addrs,
size_t max_entries)
{
struct stack_crawl_state_t state;
state.max_depth = max_entries;
state.skip = 2;
state.addr = addrs;
state.stack_count = 0;
_Unwind_Backtrace(unwind_func_call, &state);
return state.stack_count;
}
static inline void add(hdr_t *hdr, size_t size)
{
hdr->allocated = MAGIC_ALLOC;
hdr->size = size;
hdr->bt_depth = 0;
hdr->prev = 0;
hdr->next = 0;
hdr->bt_depth = mmcamera_stacktrace(hdr->bt, MAX_BACKTRACE_DEPTH);
hdr->next = last;
if (last) {
last->prev = hdr;
}
last = hdr;
leaks_bytes += hdr->size;
}
static struct map_info_holder *lib_map_parse_line(char* line)
{
uintptr_t start;
uintptr_t end;
int name_pos;
int ret;
ret = sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %*4s %*x %*x:%*x %*d%n",
&start, &end, &name_pos);
if (ret < 2) {
return NULL;
}
while (isspace(line[name_pos])) {
name_pos += 1;
}
const char* name = line + name_pos;
size_t name_len = strlen(name);
if (name_len && name[name_len - 1] == '\n') {
name_len -= 1;
}
struct map_info_holder *p_map_info =
(struct map_info_holder *)calloc(1, sizeof(*p_map_info));
if (p_map_info) {
p_map_info ->name = (char *)calloc(1, name_len + 1);
p_map_info->start = start;
p_map_info->end = end;
if(p_map_info -> name){
memcpy(p_map_info->name, name, name_len);
p_map_info->name[name_len] = '\0';
}
}
return p_map_info;
}
struct map_info_holder *lib_map_create(pid_t pid) {
struct map_info_holder *map_list = NULL;
struct map_info_holder *map_holder;
char data[1024]; // Used to read lines as well as to construct the filename.
snprintf(data, sizeof(data), "/proc/%d/maps", pid);
FILE* fp = fopen(data, "r");
if (fp != NULL) {
while (fgets(data, sizeof(data), fp) != NULL) {
map_holder = lib_map_parse_line(data);
if (map_holder) {
map_holder->next = map_list;
map_list = map_holder;
}
}
fclose(fp);
}
return map_list;
}
void lib_map_destroy(struct map_info_holder *map_hold)
{
struct map_info_holder *del;
while (map_hold != NULL) {
del = map_hold;
map_hold = map_hold->next;
free(del->name);
free(del);
}
}
extern "C" void print_allocated_memory()
{
hdr_t *del; int cnt, cnt_all = 0;
struct map_info_holder *p_map_info;
ALOGI("%d bytes non freed memory.\n", leaks_bytes);
pthread_mutex_lock(&memory_mutex);
p_map_info = lib_map_create(getpid());
del = last;
while(del) {
cnt_all++;
ALOGI("%d ALLOCATED MEMORY AT %p %d bytes (%d bytes REMAINING)\n",
cnt_all, del + 1, del->size, leaks_bytes);
print_backtrace(p_map_info, del->bt, del->bt_depth);
del = del->next;
}
lib_map_destroy(p_map_info);
pthread_mutex_unlock(&memory_mutex);
}
static inline void remove_hdr(hdr_t *hdr)
{
if (hdr->prev)
hdr->prev->next = hdr->next;
else
last = hdr->next;
if (hdr->next)
hdr->next->prev = hdr->prev;
leaks_bytes -= hdr->size;
hdr->allocated = MAGIC_FREE;
}
void * __malloc(size_t size)
{
hdr_t *hdr;
pthread_mutex_lock(&memory_mutex);
hdr = (hdr_t *) malloc(size + ADDITIONAL_SIZE);
if (hdr){
add(hdr, size);
pthread_mutex_unlock(&memory_mutex);
return hdr + 1;
}
LOGI("not enough memory.\n");
pthread_mutex_unlock(&memory_mutex);
return NULL;
}
void * __calloc(size_t nmemb, size_t size)
{
hdr_t *hdr = NULL;
pthread_mutex_lock(&memory_mutex);
hdr = (hdr_t *)calloc(1, (nmemb * size) + ADDITIONAL_SIZE);
if (hdr) {
add(hdr, (nmemb * size));
pthread_mutex_unlock(&memory_mutex);
return hdr + 1;
}
pthread_mutex_unlock(&memory_mutex);
return NULL;
}
void * __realloc(void *ptr, size_t size)
{
hdr_t *hdr = (hdr_t *)ptr;
pthread_mutex_lock(&memory_mutex);
if (hdr) {
hdr--;
if (hdr->allocated == MAGIC_ALLOC) {
remove_hdr(hdr);
} else {
/* If is not our allocation just realloc */
pthread_mutex_unlock(&memory_mutex);
return realloc(ptr, size);
}
}
hdr = (hdr_t *)realloc(hdr, size + ADDITIONAL_SIZE);
if (hdr) {
add(hdr, size);
pthread_mutex_unlock(&memory_mutex);
return hdr + 1;
}
pthread_mutex_unlock(&memory_mutex);
return NULL;
}
void __free(void *ptr)
{
if (ptr){
hdr_t *hdr = (hdr_t *) ptr;
hdr--;
pthread_mutex_lock(&memory_mutex);
if(hdr->allocated == MAGIC_ALLOC) {
remove_hdr(hdr);
free(hdr);
}else {
free(ptr);
}
pthread_mutex_unlock(&memory_mutex);
}
}
extern "C" void * __wrap_malloc(size_t size)
{
return __real_malloc(size);
}
extern "C" void * __wrap_calloc(size_t nmemb, size_t size)
{
return __real_calloc(nmemb, size);
}
extern "C" void * __wrap_realloc(void *ptr, size_t size)
{
return __real_realloc(ptr, size);
}
extern "C" void __wrap_free(void *ptr)
{
__real_free(ptr);
}
static __attribute__((constructor)) void init(void)
{
__real_malloc = malloc;
__real_calloc = calloc;
__real_realloc = realloc;
__real_free = free;
}
void hal_debug_enable_memleak_trace()
{
__real_malloc = __malloc;
__real_calloc = __calloc;
__real_realloc = __realloc;
__real_free = __free;
}
void hal_debug_dump_memleak_trace()
{
print_allocated_memory();
}
static __attribute__((destructor)) void finish(void)
{
LOGI( "memleak lib deinit.\n");
print_allocated_memory();
}

View file

@ -0,0 +1,51 @@
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef MEMLEAK_H
#define MEMLEAK_H
#include <pthread.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
int mmcamera_stacktrace(uintptr_t *addrs,size_t max_entries);
struct map_info_holder *lib_map_create(pid_t pid);
void print_backtrace(struct map_info_holder *p_map_info, uintptr_t* frames, int frame_count);
void lib_map_destroy(struct map_info_holder *map_hold);
void hal_debug_enable_memleak_trace();
void hal_debug_dump_memleak_trace();
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,99 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __MM_CAMERA_SHIMLAYER_H_
#define __MM_CAMERA_SHIMLAYER_H_
#include "cam_intf.h"
/*
* MCT shim layer APIs
*/
#define SHIMLAYER_LIB "libmmcamera2_mct_shimlayer.so"
struct cam_shim_packet;
/*
* Bundled events structure.
*/
typedef struct {
uint8_t cmd_count; /* Total number of events in this packet */
struct cam_shim_packet *cmd; /*Events to process*/
} cam_shim_cmd_packet_t;
/*
* Bundled stream event structure
*/
typedef struct {
uint8_t stream_count; /*Number of streams in a bundle*/
cam_shim_cmd_packet_t stream_event[MAX_NUM_STREAMS]; /*Event for different streams*/
} cam_shim_stream_cmd_packet_t;
/*
* Command types to process in shim layer
*/
typedef enum {
CAM_SHIM_SET_PARM, /*v4l2 set parameter*/
CAM_SHIM_GET_PARM, /*v4l2 get parameter*/
CAM_SHIM_REG_BUF, /*Reg/unreg buffers with back-end*/
CAM_SHIM_BUNDLE_CMD, /*Bundled command for streams*/
} cam_shim_cmd_type;
typedef struct {
uint32_t command; /*V4L2 or private command*/
uint32_t stream_id; /*streamID*/
void *value; /*command value/data*/
} cam_shim_cmd_data;
/*
* Structure to communicate command with shim layer
*/
typedef struct cam_shim_packet {
uint32_t session_id;
cam_shim_cmd_type cmd_type; /*Command type to process*/
union {
cam_shim_cmd_data cmd_data; /*get/set parameter structure*/
cam_reg_buf_t reg_buf; /*Buffer register and unregister*/
cam_shim_stream_cmd_packet_t bundle_cmd;/*Bundled command*/
};
} cam_shim_packet_t;
typedef int32_t (*mm_camera_shim_event_handler_func)(uint32_t session_id,
cam_event_t *event);
typedef struct {
cam_status_t (*mm_camera_shim_open_session) (int session,
mm_camera_shim_event_handler_func evt_cb);
int32_t (*mm_camera_shim_close_session)(int session);
int32_t (*mm_camera_shim_send_cmd)(cam_shim_packet_t *event);
} mm_camera_shim_ops_t;
int32_t (*mm_camera_shim_module_init)(mm_camera_shim_ops_t *shim_ops);
#endif /*__MM_CAMERA_SHIMLAYER_H_*/

View file

@ -0,0 +1,439 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef MM_JPEG_INTERFACE_H_
#define MM_JPEG_INTERFACE_H_
// System dependencies
#include <stdbool.h>
// Camera dependencies
#include "QOMX_JpegExtensions.h"
#include "cam_intf.h"
#define MM_JPEG_MAX_PLANES 3
#define MM_JPEG_MAX_BUF CAM_MAX_NUM_BUFS_PER_STREAM
#define QUANT_SIZE 64
#define QTABLE_MAX 2
#define MM_JPEG_MAX_MPO_IMAGES 3
/* bit mask for buffer usage*/
#define MM_JPEG_HAS_READ_BUF CPU_HAS_READ
#define MM_JPEG_HAS_WRITTEN_BUF CPU_HAS_WRITTEN
typedef enum {
MM_JPEG_FMT_YUV,
MM_JPEG_FMT_BITSTREAM
} mm_jpeg_format_t;
typedef enum {
MM_JPEG_TYPE_JPEG,
MM_JPEG_TYPE_MPO
} mm_jpeg_image_type_t;
typedef struct {
cam_ae_exif_debug_t ae_debug_params;
cam_awb_exif_debug_t awb_debug_params;
cam_af_exif_debug_t af_debug_params;
cam_asd_exif_debug_t asd_debug_params;
cam_stats_buffer_exif_debug_t stats_debug_params;
cam_bestats_buffer_exif_debug_t bestats_debug_params;
cam_bhist_buffer_exif_debug_t bhist_debug_params;
cam_q3a_tuning_info_t q3a_tuning_debug_params;
uint8_t ae_debug_params_valid;
uint8_t awb_debug_params_valid;
uint8_t af_debug_params_valid;
uint8_t asd_debug_params_valid;
uint8_t stats_debug_params_valid;
uint8_t bestats_debug_params_valid;
uint8_t bhist_debug_params_valid;
uint8_t q3a_tuning_debug_params_valid;
} mm_jpeg_debug_exif_params_t;
typedef struct {
cam_3a_params_t cam_3a_params;
uint8_t cam_3a_params_valid;
cam_sensor_params_t sensor_params;
mm_jpeg_debug_exif_params_t *debug_params;
} mm_jpeg_exif_params_t;
typedef struct {
/* Indicates if it is a single jpeg or part of a multi picture sequence */
mm_jpeg_image_type_t type;
/* Indicates if image is the primary image in a sequence of images.
Applicable only to multi picture formats */
uint8_t is_primary;
/* Number of images in the sequence */
uint32_t num_of_images;
/* Flag to indicate if multi picture metadata need to be added to Exif */
uint8_t enable_metadata;
} mm_jpeg_multi_image_t;
typedef struct {
uint32_t sequence; /* for jpeg bit streams, assembling is based on sequence. sequence starts from 0 */
uint8_t *buf_vaddr; /* ptr to buf */
int fd; /* fd of buf */
size_t buf_size; /* total size of buf (header + image) */
mm_jpeg_format_t format; /* buffer format*/
cam_frame_len_offset_t offset; /* offset of all the planes */
uint32_t index; /* index used to identify the buffers */
} mm_jpeg_buf_t;
typedef struct {
uint8_t *buf_vaddr; /* ptr to buf */
int fd; /* fd of buf */
size_t buf_filled_len; /* used for output image. filled by the client */
} mm_jpeg_output_t;
typedef enum {
MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2,
MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2,
MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1,
MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1,
MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2,
MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2,
MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1,
MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1,
MM_JPEG_COLOR_FORMAT_MONOCHROME,
MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V2,
MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V1,
MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V2,
MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V1,
MM_JPEG_COLOR_FORMAT_MAX
} mm_jpeg_color_format;
typedef enum {
JPEG_JOB_STATUS_DONE = 0,
JPEG_JOB_STATUS_ERROR
} jpeg_job_status_t;
typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status,
uint32_t client_hdl,
uint32_t jobId,
mm_jpeg_output_t *p_output,
void *userData);
typedef void (*mpo_encode_callback_t)(jpeg_job_status_t status,
mm_jpeg_output_t *p_output,
void *userData);
typedef struct {
/* src img dimension */
cam_dimension_t src_dim;
/* jpeg output dimension */
cam_dimension_t dst_dim;
/* crop information */
cam_rect_t crop;
} mm_jpeg_dim_t;
typedef struct {
/* num of buf in src img */
uint32_t num_src_bufs;
/* num of src tmb bufs */
uint32_t num_tmb_bufs;
/* num of buf in src img */
uint32_t num_dst_bufs;
/* should create thumbnail from main image or not */
uint32_t encode_thumbnail;
/* src img bufs */
mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
/* this will be used only for bitstream */
mm_jpeg_buf_t src_thumb_buf[MM_JPEG_MAX_BUF];
/* this will be used only for bitstream */
mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
/* mainimage color format */
mm_jpeg_color_format color_format;
/* thumbnail color format */
mm_jpeg_color_format thumb_color_format;
/* jpeg quality: range 0~100 */
uint32_t quality;
/* jpeg thumbnail quality: range 0~100 */
uint32_t thumb_quality;
/* buf to exif entries, caller needs to
* take care of the memory manage with insider ptr */
QOMX_EXIF_INFO exif_info;
/*Callback registered to be called after encode*/
jpeg_encode_callback_t jpeg_cb;
/*Appdata passed by the user*/
void* userdata;
/* thumbnail dimension */
mm_jpeg_dim_t thumb_dim;
/* rotation informaiton */
uint32_t rotation;
/* thumb rotation informaiton */
uint32_t thumb_rotation;
/* main image dimension */
mm_jpeg_dim_t main_dim;
/* enable encoder burst mode */
uint32_t burst_mode;
/* get memory function ptr */
int (*get_memory)( omx_jpeg_ouput_buf_t *p_out_buf);
/* release memory function ptr */
int (*put_memory)( omx_jpeg_ouput_buf_t *p_out_buf);
/* Flag to indicate whether to generate thumbnail from postview */
bool thumb_from_postview;
} mm_jpeg_encode_params_t;
typedef struct {
/* num of buf in src img */
uint32_t num_src_bufs;
/* num of buf in src img */
uint32_t num_dst_bufs;
/* src img bufs */
mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
/* this will be used only for bitstream */
mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
/* color format */
mm_jpeg_color_format color_format;
jpeg_encode_callback_t jpeg_cb;
void* userdata;
} mm_jpeg_decode_params_t;
/* This structure is populated by HAL to notify buffer
usage like has read or has written. This info is then
used to perform cache ops in jpeg */
typedef struct {
/* main image source buff usage */
uint8_t main_src_buf;
/* thumbnail source buff usage */
uint8_t thumb_src_buf;
/* destination buff usage */
uint8_t dest_buf;
/* work buff usage */
uint8_t work_buf;
} mm_jpeg_buf_usage_t;
typedef struct {
/* active indices of the buffers for encoding */
int32_t src_index;
int32_t dst_index;
uint32_t thumb_index;
mm_jpeg_dim_t thumb_dim;
/* rotation informaiton */
uint32_t rotation;
/* main image dimension */
mm_jpeg_dim_t main_dim;
/*session id*/
uint32_t session_id;
/* jpeg output buffer ref count */
int32_t ref_count;
/* allocated jpeg output buffer */
void *alloc_out_buffer;
/*Metadata stream*/
metadata_buffer_t *p_metadata;
/*HAL version*/
cam_hal_version_t hal_version;
/* buf to exif entries, caller needs to
* take care of the memory manage with insider ptr */
QOMX_EXIF_INFO exif_info;
/* 3a parameters */
mm_jpeg_exif_params_t cam_exif_params;
/* jpeg encoder QTable */
uint8_t qtable_set[QTABLE_MAX];
OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE qtable[QTABLE_MAX];
/* flag to enable/disable mobicat */
uint8_t mobicat_mask;
/*Info associated with multiple image sequence*/
mm_jpeg_multi_image_t multi_image_info;
/* work buf */
mm_jpeg_buf_t work_buf;
/* Input from HAL notifing the prior usage of buffers,
this info will be used to perform cache ops*/
mm_jpeg_buf_usage_t buf_usage;
} mm_jpeg_encode_job_t;
typedef struct {
/* active indices of the buffers for encoding */
int32_t src_index;
int32_t dst_index;
uint32_t tmb_dst_index;
/* rotation informaiton */
uint32_t rotation;
/* main image */
mm_jpeg_dim_t main_dim;
/*session id*/
uint32_t session_id;
} mm_jpeg_decode_job_t;
typedef enum {
JPEG_JOB_TYPE_ENCODE,
JPEG_JOB_TYPE_DECODE,
JPEG_JOB_TYPE_MAX
} mm_jpeg_job_type_t;
typedef struct {
mm_jpeg_job_type_t job_type;
union {
mm_jpeg_encode_job_t encode_job;
mm_jpeg_decode_job_t decode_job;
};
} mm_jpeg_job_t;
typedef struct {
uint32_t w;
uint32_t h;
} mm_dimension;
typedef struct {
/*Primary image in the MPO sequence*/
mm_jpeg_output_t primary_image;
/*All auxillary images in the sequence*/
mm_jpeg_output_t aux_images[MM_JPEG_MAX_MPO_IMAGES - 1];
/*Total number of images in the MPO sequence*/
int num_of_images;
/*Output MPO buffer*/
mm_jpeg_output_t output_buff;
/*Size of the allocated output buffer*/
size_t output_buff_size;
} mm_jpeg_mpo_info_t;
typedef struct {
/* config a job -- async call */
int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
/* abort a job -- sync call */
int (*abort_job)(uint32_t job_id);
/* create a session */
int (*create_session)(uint32_t client_hdl,
mm_jpeg_encode_params_t *p_params, uint32_t *p_session_id);
/* destroy session */
int (*destroy_session)(uint32_t session_id);
/* close a jpeg client -- sync call */
int (*close) (uint32_t clientHdl);
} mm_jpeg_ops_t;
typedef struct {
/* config a job -- async call */
int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
/* abort a job -- sync call */
int (*abort_job)(uint32_t job_id);
/* create a session */
int (*create_session)(uint32_t client_hdl,
mm_jpeg_decode_params_t *p_params, uint32_t *p_session_id);
/* destroy session */
int (*destroy_session)(uint32_t session_id);
/* close a jpeg client -- sync call */
int (*close) (uint32_t clientHdl);
} mm_jpegdec_ops_t;
typedef struct {
/* Get Mpo size*/
int (*get_mpo_size)(mm_jpeg_output_t jpeg_buffer[MM_JPEG_MAX_MPO_IMAGES],
int num_of_images);
/* Compose MPO*/
int (*compose_mpo)(mm_jpeg_mpo_info_t *mpo_info);
} mm_jpeg_mpo_ops_t;
/* open a jpeg client -- sync call
* returns client_handle.
* failed if client_handle=0
* jpeg ops tbl and mpo ops tbl will be filled in if open succeeds
* and jpeg meta data will be cached */
uint32_t jpeg_open(mm_jpeg_ops_t *ops, mm_jpeg_mpo_ops_t *mpo_ops,
mm_dimension picture_size,
cam_jpeg_metadata_t *jpeg_metadata);
/* open a jpeg client -- sync call
* returns client_handle.
* failed if client_handle=0
* jpeg ops tbl will be filled in if open succeeds */
uint32_t jpegdec_open(mm_jpegdec_ops_t *ops);
#endif /* MM_JPEG_INTERFACE_H_ */

View file

@ -0,0 +1,79 @@
OLD_LOCAL_PATH := $(LOCAL_PATH)
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/../../../common.mk
include $(CLEAR_VARS)
LOCAL_HEADER_LIBRARIES := camera_common_headers
LOCAL_HEADER_LIBRARIES += libhardware_headers
LOCAL_HEADER_LIBRARIES += media_plugin_headers
MM_CAM_FILES := \
src/mm_camera_interface.c \
src/mm_camera.c \
src/mm_camera_muxer.c \
src/mm_camera_channel.c \
src/mm_camera_stream.c \
src/mm_camera_thread.c \
src/mm_camera_sock.c
# System header file path prefix
LOCAL_CFLAGS += -DSYSTEM_HEADER_PREFIX=sys
ifeq ($(strip $(TARGET_USES_ION)),true)
LOCAL_CFLAGS += -DUSE_ION
endif
ifeq ($(shell expr $(TARGET_KERNEL_VERSION) \>= 4.4), 1)
LOCAL_CFLAGS += -DUSE_KERNEL_VERSION_GE_4_4_DEFS
endif
ifneq (,$(filter msm8974 msm8916 msm8226 msm8610 msm8916 apq8084 msm8084 msm8994 msm8992 msm8952 msm8937 msm8953 msm8996 sdm660 msm8998 apq8098_latv $(TRINKET), $(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DVENUS_PRESENT
endif
ifneq (,$(filter msm8996 sdm660 msm8998 apq8098_latv $(TRINKET),$(TARGET_BOARD_PLATFORM)))
LOCAL_CFLAGS += -DUBWC_PRESENT
endif
LOCAL_CFLAGS += -D_ANDROID_ -DQCAMERA_REDEFINE_LOG
LOCAL_CFLAGS += -DFDLEAK_FLAG
LOCAL_CFLAGS += -DMEMLEAK_FLAG
LOCAL_LDFLAGS += -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=socket -Wl,--wrap=pipe -Wl,--wrap=mmap -Wl,--wrap=__open_2
LOCAL_LDFLAGS += -Wl,--wrap=malloc -Wl,--wrap=free -Wl,--wrap=realloc -Wl,--wrap=calloc
LOCAL_C_INCLUDES := \
system/media/camera/include \
$(LOCAL_PATH)/inc \
$(LOCAL_PATH)/../common \
$(LOCAL_PATH)/../common/leak \
LOCAL_CFLAGS += -DCAMERA_ION_HEAP_ID=ION_IOMMU_HEAP_ID
LOCAL_C_INCLUDES+= $(kernel_includes)
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
ifneq (1,$(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) >= 17 ))" )))
LOCAL_CFLAGS += -include bionic/libc/kernel/common/linux/socket.h
LOCAL_CFLAGS += -include bionic/libc/kernel/common/linux/un.h
endif
LOCAL_CFLAGS += -Wall -Wextra -Werror
ifneq (,$(filter $(strip $(TARGET_KERNEL_VERSION)),4.9 4.14))
LOCAL_CFLAGS += -DUSE_4_9_DEFS
endif
LOCAL_SRC_FILES := $(MM_CAM_FILES)
LOCAL_MODULE := libmmcamera_interface
include $(SDCLANG_COMMON_DEFS)
LOCAL_SHARED_LIBRARIES := libdl libcutils liblog \
libhal_dbg libutils
LOCAL_HEADER_LIBRARIES := libhardware_headers
LOCAL_MODULE_TAGS := optional
LOCAL_VENDOR_MODULE := true
LOCAL_32_BIT_ONLY := $(BOARD_QTI_CAMERA_32BIT_ONLY)
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH := $(OLD_LOCAL_PATH)

View file

@ -0,0 +1,907 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __MM_CAMERA_H__
#define __MM_CAMERA_H__
// System dependencies
#include <poll.h>
// Camera dependencies
#include "hardware/camera_common.h"
#include "cam_semaphore.h"
#include "mm_camera_interface.h"
#include "mm_camera_shim.h"
/**********************************************************************************
* Data structure declarations
***********************************************************************************/
/* num of callbacks allowed for an event type */
#define MM_CAMERA_EVT_ENTRY_MAX 4
/* num of data callbacks allowed in a stream obj */
#define MM_CAMERA_STREAM_BUF_CB_MAX 4
/* num of data poll threads allowed in a channel obj */
#define MM_CAMERA_CHANNEL_POLL_THREAD_MAX 1
#define MM_CAMERA_DEV_NAME_LEN 32
#define MM_CAMERA_DEV_OPEN_TRIES 20
#define MM_CAMERA_DEV_OPEN_RETRY_SLEEP 40
#define THREAD_NAME_SIZE 15
/* Future frame idx, large enough to make sure capture
* settings can be applied and small enough to still capture an image */
#define MM_CAMERA_MAX_FUTURE_FRAME_WAIT 100
#define WAIT_TIMEOUT 10
/*For frame sync */
#define MAX_OBJS_FOR_FRAME_SYNC 4
/* num of supporting camera*/
#define MM_CAMERA_MAX_AUX_CAMERA 1
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
struct mm_channel;
struct mm_stream;
struct mm_camera_obj;
typedef int64_t nsecs_t;
typedef enum
{
MM_CAMERA_CMD_TYPE_DATA_CB, /* dataB CMD */
MM_CAMERA_CMD_TYPE_EVT_CB, /* evtCB CMD */
MM_CAMERA_CMD_TYPE_EXIT, /* EXIT */
MM_CAMERA_CMD_TYPE_REQ_DATA_CB,/* request data */
MM_CAMERA_CMD_TYPE_SUPER_BUF_DATA_CB, /* superbuf dataB CMD */
MM_CAMERA_CMD_TYPE_CONFIG_NOTIFY, /* configure notify mode */
MM_CAMERA_CMD_TYPE_START_ZSL, /* start zsl snapshot for channel */
MM_CAMERA_CMD_TYPE_STOP_ZSL, /* stop zsl snapshot for channel */
MM_CAMERA_CMD_TYPE_FLUSH_QUEUE, /* flush queue */
MM_CAMERA_CMD_TYPE_GENERAL, /* general cmd */
MM_CAMERA_CMD_TYPE_MAX
} mm_camera_cmdcb_type_t;
typedef struct {
uint32_t stream_id;
uint32_t frame_idx;
uint32_t flags;
mm_camera_buf_def_t *buf; /* ref to buf */
} mm_camera_buf_info_t;
typedef enum {
MM_CAMERA_GENERIC_CMD_TYPE_AE_BRACKETING,
MM_CAMERA_GENERIC_CMD_TYPE_AF_BRACKETING,
MM_CAMERA_GENERIC_CMD_TYPE_FLASH_BRACKETING,
MM_CAMERA_GENERIC_CMD_TYPE_ZOOM_1X,
MM_CAMERA_GENERIC_CMD_TYPE_CAPTURE_SETTING,
} mm_camera_generic_cmd_type_t;
typedef struct {
mm_camera_generic_cmd_type_t type;
uint32_t payload[32];
union {
cam_capture_frame_config_t frame_config;
};
} mm_camera_generic_cmd_t;
typedef struct {
uint32_t frame_idx;
cam_stream_type_t stream_type;
} mm_camera_flush_cmd_t;
typedef struct {
mm_camera_cmdcb_type_t cmd_type;
union {
mm_camera_buf_info_t buf; /* frame buf if dataCB */
mm_camera_event_t evt; /* evt if evtCB */
mm_camera_super_buf_t superbuf; /* superbuf if superbuf dataCB*/
mm_camera_req_buf_t req_buf; /* num of buf requested */
mm_camera_flush_cmd_t flush_cmd; /* frame idx boundary for flush superbuf queue*/
mm_camera_super_buf_notify_mode_t notify_mode; /* notification mode */
mm_camera_generic_cmd_t gen_cmd;
} u;
} mm_camera_cmdcb_t;
typedef void (*mm_camera_cmd_cb_t)(mm_camera_cmdcb_t * cmd_cb, void* user_data);
typedef struct {
uint8_t is_active; /*indicates whether thread is active or not */
cam_queue_t cmd_queue; /* cmd queue (queuing dataCB, asyncCB, or exitCMD) */
pthread_t cmd_pid; /* cmd thread ID */
cam_semaphore_t cmd_sem; /* semaphore for cmd thread */
cam_semaphore_t sync_sem; /* semaphore for synchronization with cmd thread */
mm_camera_cmd_cb_t cb; /* cb for cmd */
void* user_data; /* user_data for cb */
char threadName[THREAD_NAME_SIZE];
} mm_camera_cmd_thread_t;
typedef enum {
MM_CAMERA_POLL_TYPE_EVT,
MM_CAMERA_POLL_TYPE_DATA,
MM_CAMERA_POLL_TYPE_MAX
} mm_camera_poll_thread_type_t;
/* function ptr defined for poll notify CB,
* registered at poll thread with poll fd */
typedef void (*mm_camera_poll_notify_t)(void *user_data);
typedef struct {
int32_t fd;
mm_camera_poll_notify_t notify_cb;
uint32_t handler;
void* user_data;
} mm_camera_poll_entry_t;
typedef struct {
mm_camera_poll_thread_type_t poll_type;
/* array to store poll fd and cb info
* for MM_CAMERA_POLL_TYPE_EVT, only index 0 is valid;
* for MM_CAMERA_POLL_TYPE_DATA, depends on valid stream fd */
mm_camera_poll_entry_t poll_entries[MAX_STREAM_NUM_IN_BUNDLE];
int32_t pfds[2];
pthread_t pid;
int32_t state;
int timeoutms;
uint32_t cmd;
struct pollfd poll_fds[MAX_STREAM_NUM_IN_BUNDLE + 1];
uint8_t num_fds;
pthread_mutex_t mutex;
pthread_cond_t cond_v;
int32_t status;
char threadName[THREAD_NAME_SIZE];
//void *my_obj;
} mm_camera_poll_thread_t;
/* mm_stream */
typedef enum {
MM_STREAM_STATE_NOTUSED = 0, /* not used */
MM_STREAM_STATE_INITED, /* inited */
MM_STREAM_STATE_ACQUIRED, /* acquired, fd opened */
MM_STREAM_STATE_CFG, /* fmt & dim configured */
MM_STREAM_STATE_BUFFED, /* buf allocated */
MM_STREAM_STATE_REG, /* buf regged, stream off */
MM_STREAM_STATE_ACTIVE, /* active */
MM_STREAM_STATE_MAX
} mm_stream_state_type_t;
typedef enum {
MM_STREAM_EVT_ACQUIRE,
MM_STREAM_EVT_RELEASE,
MM_STREAM_EVT_SET_FMT,
MM_STREAM_EVT_GET_BUF,
MM_STREAM_EVT_PUT_BUF,
MM_STREAM_EVT_REG_BUF,
MM_STREAM_EVT_UNREG_BUF,
MM_STREAM_EVT_START,
MM_STREAM_EVT_STOP,
MM_STREAM_EVT_QBUF,
MM_STREAM_EVT_SET_PARM,
MM_STREAM_EVT_GET_PARM,
MM_STREAM_EVT_DO_ACTION,
MM_STREAM_EVT_GET_QUEUED_BUF_COUNT,
MM_STREAM_EVT_REG_FRAME_SYNC,
MM_STREAM_EVT_TRIGGER_FRAME_SYNC,
MM_STREAM_EVT_CANCEL_BUF,
MM_STREAM_EVT_MAX
} mm_stream_evt_type_t;
typedef struct {
mm_camera_buf_notify_t cb;
void *user_data;
/* cb_count = -1: infinite
* cb_count > 0: register only for required times */
int8_t cb_count;
mm_camera_stream_cb_type cb_type;
} mm_stream_data_cb_t;
typedef struct {
/* buf reference count */
uint8_t buf_refcnt;
/* This flag is to indicate if after allocation,
* the corresponding buf needs to qbuf into kernel
* (e.g. for preview usecase, display needs to hold two bufs,
* so no need to qbuf these two bufs initially) */
uint8_t initial_reg_flag;
/* indicate if buf is in kernel(1) or client(0) */
uint8_t in_kernel;
/*indicate if this buffer is mapped to daemon*/
int8_t map_status;
} mm_stream_buf_status_t;
/*Structure definition to carry frame sync queue details*/
typedef struct {
/*Number of objects to be synced*/
uint8_t num_objs;
/*Object handle to be synced*/
uint32_t bundled_objs[MAX_OBJS_FOR_FRAME_SYNC];
/*Queue*/
cam_queue_t que;
/*queue attributed*/
mm_camera_channel_attr_t attr;
/*Expected frame for this queue*/
uint32_t expected_frame_id;
/*Total match count*/
uint32_t match_cnt;
} mm_frame_sync_queue_t;
/*Structure definition to carry frame sync details*/
typedef struct {
/* flag to indicate if frame sync is active*/
uint8_t is_active;
/*Frame sync lock. Shared between child and parent stream*/
pthread_mutex_t sync_lock;
/*Limited number of synced frame request*/
mm_camera_req_buf_t req_buf;
/*Queue to hold super buffers*/
mm_frame_sync_queue_t superbuf_queue;
/*Callback registered for synced frame*/
mm_camera_buf_notify_t super_buf_notify_cb;
/*Client data*/
void *user_data;
} mm_frame_sync_t;
struct mm_stream;
typedef struct mm_stream {
uint32_t my_hdl; /* local stream id */
uint32_t server_stream_id; /* stream id from server */
int32_t fd;
mm_stream_state_type_t state;
/* stream info*/
cam_stream_info_t *stream_info;
/* padding info */
cam_padding_info_t padding_info;
/* offset */
cam_frame_len_offset_t frame_offset;
pthread_mutex_t cmd_lock; /* lock to protect cmd_thread */
mm_camera_cmd_thread_t cmd_thread;
/* dataCB registered on this stream obj */
uint8_t is_cb_active;
pthread_mutex_t cb_lock; /* cb lock to protect buf_cb */
mm_stream_data_cb_t buf_cb[MM_CAMERA_STREAM_BUF_CB_MAX];
/* stream buffer management */
pthread_mutex_t buf_lock;
uint8_t total_buf_cnt; /*Total number of buffer including slave*/
uint8_t buf_num; /* num of buffers for this stream */
uint8_t buf_idx; /* starting buffer index */
mm_camera_buf_def_t* buf; /* ptr to buf array */
mm_stream_buf_status_t buf_status[CAM_MAX_NUM_BUFS_PER_STREAM]; /* ptr to buf status array */
uint8_t plane_buf_num; /* num of plane buffers allocated Used only in Batch mode*/
mm_camera_buf_def_t *plane_buf; /*Pointer to plane buffer array Used only in Batch mode */
int32_t cur_buf_idx; /* Current container buffer active filling. Used only in Batch mode*/
uint8_t cur_bufs_staged; /*Number of plane buf freed by HAL for this usr buf*/
/* reference to parent channel_obj */
struct mm_channel* ch_obj;
uint8_t is_bundled; /* flag if stream is bundled */
/* reference to linked channel_obj */
struct mm_channel* linked_obj;
struct mm_stream * linked_stream; /* original stream */
uint8_t is_linked; /* flag if stream is linked */
mm_camera_stream_mem_vtbl_t mem_vtbl; /* mem ops tbl */
mm_camera_map_unmap_ops_tbl_t map_ops;
int8_t queued_buffer_count;
/*latest timestamp of this stream frame received & last frameID*/
uint32_t prev_frameID;
nsecs_t prev_timestamp;
/* Need to wait for buffer mapping before stream-on*/
pthread_cond_t buf_cond;
struct mm_stream *master_str_obj; /*Master stream of this stream*/
uint8_t num_s_cnt;
struct mm_stream *aux_str_obj[MM_CAMERA_MAX_AUX_CAMERA]; /*aux stream of this stream*/
mm_frame_sync_t frame_sync;
uint8_t is_res_shared;
uint8_t is_deferred;
uint8_t is_frame_shared;
uint8_t is_stream_inited;
} mm_stream_t;
/* mm_channel */
typedef enum {
MM_CHANNEL_STATE_NOTUSED = 0, /* not used */
MM_CHANNEL_STATE_STOPPED, /* stopped */
MM_CHANNEL_STATE_ACTIVE, /* active, at least one stream active */
MM_CHANNEL_STATE_PAUSED, /* paused */
MM_CHANNEL_STATE_MAX
} mm_channel_state_type_t;
typedef enum {
MM_CHANNEL_EVT_ADD_STREAM,
MM_CHANNEL_EVT_DEL_STREAM,
MM_CHANNEL_EVT_LINK_STREAM,
MM_CHANNEL_EVT_CONFIG_STREAM,
MM_CHANNEL_EVT_GET_BUNDLE_INFO,
MM_CHANNEL_EVT_START,
MM_CHANNEL_EVT_STOP,
MM_CHANNEL_EVT_PAUSE,
MM_CHANNEL_EVT_RESUME,
MM_CHANNEL_EVT_REQUEST_SUPER_BUF,
MM_CHANNEL_EVT_CANCEL_REQUEST_SUPER_BUF,
MM_CHANNEL_EVT_FLUSH_SUPER_BUF_QUEUE,
MM_CHANNEL_EVT_CONFIG_NOTIFY_MODE,
MM_CHANNEL_EVT_START_ZSL_SNAPSHOT,
MM_CHANNEL_EVT_STOP_ZSL_SNAPSHOT,
MM_CHANNEL_EVT_MAP_STREAM_BUF,
MM_CHANNEL_EVT_UNMAP_STREAM_BUF,
MM_CHANNEL_EVT_SET_STREAM_PARM,
MM_CHANNEL_EVT_GET_STREAM_PARM,
MM_CHANNEL_EVT_DO_ACTION,
MM_CHANNEL_EVT_DELETE,
MM_CHANNEL_EVT_AF_BRACKETING,
MM_CHANNEL_EVT_AE_BRACKETING,
MM_CHANNEL_EVT_FLASH_BRACKETING,
MM_CHANNEL_EVT_ZOOM_1X,
MM_CAMERA_EVT_CAPTURE_SETTING,
MM_CHANNEL_EVT_GET_STREAM_QUEUED_BUF_COUNT,
MM_CHANNEL_EVT_MAP_STREAM_BUFS,
MM_CHANNEL_EVT_REG_STREAM_BUF_CB,
MM_CHANNEL_EVT_REG_FRAME_SYNC,
MM_CHANNEL_EVT_TRIGGER_FRAME_SYNC,
} mm_channel_evt_type_t;
typedef struct {
uint32_t stream_id;
mm_camera_stream_config_t *config;
} mm_evt_paylod_config_stream_t;
typedef struct {
uint32_t stream_id;
cam_stream_parm_buffer_t *parms;
} mm_evt_paylod_set_get_stream_parms_t;
typedef struct {
uint32_t stream_id;
void *actions;
} mm_evt_paylod_do_stream_action_t;
typedef struct {
uint32_t stream_id;
mm_stream_data_cb_t buf_cb;
} mm_evt_paylod_reg_stream_buf_cb;
typedef struct {
uint8_t num_of_bufs;
mm_camera_buf_info_t super_buf[MAX_STREAM_NUM_IN_BUNDLE];
uint8_t matched;
uint8_t expected_frame;
uint32_t frame_idx;
/* unmatched meta idx needed in case of low priority queue */
uint32_t unmatched_meta_idx;
uint32_t meta_frame_idx;
uint8_t is_drop_frame;
} mm_channel_queue_node_t;
typedef struct {
cam_queue_t que;
uint8_t num_streams;
/* container for bundled stream handlers */
uint32_t bundled_streams[MAX_STREAM_NUM_IN_BUNDLE];
mm_camera_channel_attr_t attr;
uint32_t expected_frame_id;
uint32_t match_cnt;
uint32_t expected_frame_id_without_led;
uint32_t led_on_start_frame_id;
uint32_t led_off_start_frame_id;
uint32_t led_on_num_frames;
uint32_t once;
uint32_t frame_skip_count;
uint32_t good_frame_id;
} mm_channel_queue_t;
typedef struct {
uint8_t is_active; /* flag to indicate if bundle is valid */
/* queue to store bundled super buffers */
uint8_t is_cb_active;
mm_channel_queue_t superbuf_queue;
mm_camera_buf_notify_t super_buf_notify_cb;
void *user_data;
} mm_channel_bundle_t;
/* Nodes used for frame sync */
typedef struct {
/* Frame idx */
uint32_t frame_idx;
/* Frame present for corresponding channel*/
uint32_t frame_valid[MAX_NUM_CAMERA_PER_BUNDLE];
/* Frame present in all channels*/
uint32_t matched;
} mm_channel_sync_node_t;
/* Frame sync information */
typedef struct {
/* Number of camera channels that need to be synced*/
uint8_t num_cam;
/* position of the next node to be updated */
uint8_t pos;
/* circular node array used to store frame information */
mm_channel_sync_node_t node[MM_CAMERA_FRAME_SYNC_NODES];
/* Channel corresponding to each camera */
struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE];
/* Cb corresponding to each camera */
mm_camera_buf_notify_t cb[MAX_NUM_CAMERA_PER_BUNDLE];
} mm_channel_frame_sync_info_t;
/* Node information for multiple superbuf callbacks
* This can be used to batch nodes before sending to upper layer */
typedef struct {
/* Number of nodes to be sent*/
uint8_t num_nodes;
/* queue node information*/
mm_channel_queue_node_t *node[MAX_NUM_CAMERA_PER_BUNDLE];
/* channel information*/
struct mm_channel *ch_obj[MAX_NUM_CAMERA_PER_BUNDLE];
} mm_channel_node_info_t;
typedef enum {
MM_CHANNEL_BRACKETING_STATE_OFF,
MM_CHANNEL_BRACKETING_STATE_WAIT_GOOD_FRAME_IDX,
MM_CHANNEL_BRACKETING_STATE_ACTIVE,
} mm_channel_bracketing_state_t;
struct mm_channel;
typedef struct mm_channel {
uint32_t my_hdl;
mm_channel_state_type_t state;
pthread_mutex_t ch_lock; /* channel lock */
/* stream bundle info in the channel */
mm_channel_bundle_t bundle;
/* num of pending suferbuffers */
uint32_t pending_cnt;
uint32_t pending_retro_cnt;
mm_camera_req_buf_type_t req_type;
uint32_t bWaitForPrepSnapshotDone;
uint32_t unLockAEC;
/* num of pending suferbuffers */
uint8_t stopZslSnapshot;
/* cmd thread for superbuffer dataCB and async stop*/
mm_camera_cmd_thread_t cmd_thread;
/* cb thread for sending data cb */
mm_camera_cmd_thread_t cb_thread;
/* data poll thread
* currently one data poll thread per channel
* could extended to support one data poll thread per stream in the channel */
mm_camera_poll_thread_t poll_thread[MM_CAMERA_CHANNEL_POLL_THREAD_MAX];
/* container for all streams in channel */
mm_stream_t streams[MAX_STREAM_NUM_IN_BUNDLE];
/* reference to parent cam_obj */
struct mm_camera_obj* cam_obj;
/* manual zsl snapshot control */
uint8_t manualZSLSnapshot;
/* control for zsl led */
uint8_t startZSlSnapshotCalled;
uint8_t needLEDFlash;
mm_channel_bracketing_state_t bracketingState;
uint8_t isFlashBracketingEnabled;
uint8_t isZoom1xFrameRequested;
uint32_t burstSnapNum;
char threadName[THREAD_NAME_SIZE];
/*Buffer diverted*/
uint8_t diverted_frame_id;
uint32_t sessionid;
/*Frame capture configaration*/
uint8_t isConfigCapture;
uint8_t cur_capture_idx;
uint32_t capture_frame_id[MAX_CAPTURE_BATCH_NUM];
cam_capture_frame_config_t frameConfig;
uint8_t needLowLightZSL;
/*Capture based on index*/
uint8_t cur_req_idx;
uint8_t frame_req_cnt;
uint32_t requested_frame_id[MAX_CAPTURE_BATCH_NUM];
/*For channel frame sync*/
mm_frame_sync_t frame_sync;
/*Multiple camera's*/
struct mm_channel *master_ch_obj; /*Master channel of this channel*/
uint8_t num_s_cnt;
struct mm_channel *aux_ch_obj[MM_CAMERA_MAX_AUX_CAMERA]; /*Slave channel of this channel*/
uint8_t match_meta;
uint32_t zsl_stream_id;
} mm_channel_t;
typedef struct {
mm_channel_t *ch;
uint32_t stream_id;
} mm_camera_stream_link_t;
/* struct to store information about pp cookie*/
typedef struct {
uint32_t cam_hdl;
uint32_t ch_hdl;
uint32_t stream_hdl;
mm_channel_queue_node_t *super_buf;
} mm_channel_pp_info_t;
/* mm_camera */
typedef struct {
mm_camera_event_notify_t evt_cb;
void *user_data;
} mm_camera_evt_entry_t;
typedef struct {
mm_camera_evt_entry_t evt[MM_CAMERA_EVT_ENTRY_MAX];
/* reg_count <=0: infinite
* reg_count > 0: register only for required times */
int reg_count;
} mm_camera_evt_obj_t;
struct mm_camera_obj;
typedef struct mm_camera_obj {
uint32_t my_hdl;
int ref_count;
int32_t ctrl_fd;
int32_t ds_fd; /* domain socket fd */
pthread_mutex_t cam_lock;
pthread_mutex_t cb_lock; /* lock for evt cb */
mm_channel_t ch[MM_CAMERA_CHANNEL_MAX];
mm_camera_evt_obj_t evt;
mm_camera_poll_thread_t evt_poll_thread; /* evt poll thread */
mm_camera_cmd_thread_t evt_thread; /* thread for evt CB */
mm_camera_vtbl_t vtbl;
pthread_mutex_t evt_lock;
pthread_cond_t evt_cond;
mm_camera_event_t evt_rcvd;
pthread_mutex_t msg_lock; /* lock for sending msg through socket */
uint32_t sessionid; /* Camera server session id */
uint8_t my_num; /*this camera position in multi mode*/
pthread_mutex_t muxer_lock;
struct mm_camera_obj *master_cam_obj; /*Master Camera of this camera*/
uint8_t num_s_cnt;
struct mm_camera_obj *aux_cam_obj[MM_CAMERA_MAX_AUX_CAMERA]; /*Slave Camera of this camera*/
} mm_camera_obj_t;
typedef struct {
int8_t num_cam;
mm_camera_shim_ops_t cam_shim_ops;
int8_t num_cam_to_expose;
char video_dev_name[MM_CAMERA_MAX_NUM_SENSORS][MM_CAMERA_DEV_NAME_LEN];
mm_camera_obj_t *cam_obj[MM_CAMERA_MAX_NUM_SENSORS];
struct camera_info info[MM_CAMERA_MAX_NUM_SENSORS];
cam_sync_type_t cam_type[MM_CAMERA_MAX_NUM_SENSORS];
cam_sync_mode_t cam_mode[MM_CAMERA_MAX_NUM_SENSORS];
uint8_t is_yuv[MM_CAMERA_MAX_NUM_SENSORS]; // 1=CAM_SENSOR_YUV, 0=CAM_SENSOR_RAW
uint32_t cam_index[MM_CAMERA_MAX_NUM_SENSORS]; //Actual cam index are stored in bits
} mm_camera_ctrl_t;
typedef enum {
mm_camera_async_call,
mm_camera_sync_call
} mm_camera_call_type_t;
/*internal structure for registring frame sync*/
typedef struct {
mm_camera_obj_t *a_cam_obj;
uint32_t a_ch_id;
uint32_t a_stream_id;
uint8_t is_active;
mm_camera_channel_attr_t attr;
mm_camera_buf_notify_t buf_cb;
uint8_t is_res_shared;
void *userdata;
} mm_camera_frame_sync_t;
/*Payload for reg frame sync event in MCI*/
typedef struct {
uint32_t stream_id;
mm_channel_t *a_ch_obj;
mm_stream_t *a_str_obj;
mm_camera_frame_sync_t *sync_attr;
} mm_evt_paylod_reg_frame_sync;
/*Payload to handle frame sync */
typedef struct {
uint32_t stream_id;
mm_camera_cb_req_type type;
} mm_evt_paylod_trigger_frame_sync;
/**********************************************************************************
* external function declare
***********************************************************************************/
/* utility functions */
/* set int32_t value */
extern int32_t mm_camera_util_s_ctrl(mm_camera_obj_t *my_obj,
int stream_id, int32_t fd, uint32_t id, int32_t *value);
/* get int32_t value */
extern int32_t mm_camera_util_g_ctrl(mm_camera_obj_t *my_obj,
int stream_id, int32_t fd, uint32_t id, int32_t *value);
/* send msg throught domain socket for fd mapping */
extern int32_t mm_camera_util_sendmsg(mm_camera_obj_t *my_obj,
void *msg,
size_t buf_size,
int sendfd);
/* send msg through domain socket for bundled fd mapping */
extern int32_t mm_camera_util_bundled_sendmsg(mm_camera_obj_t *my_obj,
void *msg,
size_t buf_size,
int sendfds[CAM_MAX_NUM_BUFS_PER_STREAM],
int numfds);
/* Check if hardware target is A family */
uint8_t mm_camera_util_chip_is_a_family(void);
/* mm-camera */
extern int32_t mm_camera_open(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_close(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_register_event_notify(mm_camera_obj_t *my_obj,
mm_camera_event_notify_t evt_cb,
void * user_data);
extern int32_t mm_camera_qbuf(mm_camera_obj_t *my_obj,
uint32_t ch_id,
mm_camera_buf_def_t *buf);
extern int32_t mm_camera_cancel_buf(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id,
uint32_t buf_idx);
extern int32_t mm_camera_get_queued_buf_count(mm_camera_obj_t *my_obj,
uint32_t ch_id, uint32_t stream_id);
extern int32_t mm_camera_query_capability(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_set_parms(mm_camera_obj_t *my_obj,
parm_buffer_t *parms);
extern int32_t mm_camera_get_parms(mm_camera_obj_t *my_obj,
parm_buffer_t *parms);
extern int32_t mm_camera_map_buf(mm_camera_obj_t *my_obj,
uint8_t buf_type,
int fd,
size_t size,
void *buffer);
extern int32_t mm_camera_map_bufs(mm_camera_obj_t *my_obj,
const cam_buf_map_type_list *buf_map_list);
extern int32_t mm_camera_unmap_buf(mm_camera_obj_t *my_obj,
uint8_t buf_type);
extern int32_t mm_camera_do_auto_focus(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_cancel_auto_focus(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_prepare_snapshot(mm_camera_obj_t *my_obj,
int32_t do_af_flag);
extern int32_t mm_camera_start_zsl_snapshot(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_stop_zsl_snapshot(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_flush(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_start_zsl_snapshot_ch(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern int32_t mm_camera_stop_zsl_snapshot_ch(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern uint32_t mm_camera_add_channel(mm_camera_obj_t *my_obj,
mm_camera_channel_attr_t *attr,
mm_camera_buf_notify_t channel_cb,
void *userdata);
extern int32_t mm_camera_del_channel(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern int32_t mm_camera_get_bundle_info(mm_camera_obj_t *my_obj,
uint32_t ch_id,
cam_bundle_config_t *bundle_info);
extern uint32_t mm_camera_add_stream(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern int32_t mm_camera_del_stream(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id);
extern uint32_t mm_camera_link_stream(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id,
uint32_t linked_ch_id);
extern int32_t mm_camera_reg_stream_buf_cb(mm_camera_obj_t *my_obj,
uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb,
mm_camera_stream_cb_type cb_type, void *userdata);
extern int32_t mm_camera_config_stream(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id,
mm_camera_stream_config_t *config);
extern int32_t mm_camera_start_channel(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern int32_t mm_camera_stop_channel(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern int32_t mm_camera_request_super_buf(mm_camera_obj_t *my_obj,
uint32_t ch_id, mm_camera_req_buf_t *buf);
extern int32_t mm_camera_cancel_super_buf_request(mm_camera_obj_t *my_obj,
uint32_t ch_id);
extern int32_t mm_camera_flush_super_buf_queue(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t frame_idx);
extern int32_t mm_camera_config_channel_notify(mm_camera_obj_t *my_obj,
uint32_t ch_id,
mm_camera_super_buf_notify_mode_t notify_mode);
extern int32_t mm_camera_set_stream_parms(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t s_id,
cam_stream_parm_buffer_t *parms);
extern int32_t mm_camera_get_stream_parms(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t s_id,
cam_stream_parm_buffer_t *parms);
extern int32_t mm_camera_register_event_notify_internal(mm_camera_obj_t *my_obj,
mm_camera_event_notify_t evt_cb,
void * user_data);
extern int32_t mm_camera_map_stream_buf(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id,
uint8_t buf_type,
uint32_t buf_idx,
int32_t plane_idx,
int fd,
size_t size,
void *buffer);
extern int32_t mm_camera_map_stream_bufs(mm_camera_obj_t *my_obj,
uint32_t ch_id,
const cam_buf_map_type_list *buf_map_list);
extern int32_t mm_camera_unmap_stream_buf(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id,
uint8_t buf_type,
uint32_t buf_idx,
int32_t plane_idx);
extern int32_t mm_camera_do_stream_action(mm_camera_obj_t *my_obj,
uint32_t ch_id,
uint32_t stream_id,
void *actions);
extern int32_t mm_camera_get_session_id(mm_camera_obj_t *my_obj,
uint32_t* sessionid);
extern int32_t mm_camera_set_dual_cam_cmd(mm_camera_obj_t *my_obj);
extern int32_t mm_camera_reg_frame_sync(mm_camera_obj_t *my_obj,
uint32_t ch_id, uint32_t stream_id,
mm_camera_frame_sync_t *sync_attr);
extern int32_t mm_camera_handle_frame_sync_cb(mm_camera_obj_t *my_obj,
uint32_t ch_id, uint32_t stream_id, mm_camera_cb_req_type req_type);
/* mm_channel */
extern int32_t mm_channel_fsm_fn(mm_channel_t *my_obj,
mm_channel_evt_type_t evt,
void * in_val,
void * out_val);
extern int32_t mm_channel_init(mm_channel_t *my_obj,
mm_camera_channel_attr_t *attr,
mm_camera_buf_notify_t channel_cb,
void *userdata);
/* qbuf is a special case that not going through state machine.
* This is to avoid deadlock when trying to aquire ch_lock,
* from the context of dataCB, but async stop is holding ch_lock */
extern int32_t mm_channel_qbuf(mm_channel_t *my_obj,
mm_camera_buf_def_t *buf);
extern int32_t mm_channel_cancel_buf(mm_channel_t *my_obj,
uint32_t stream_id, uint32_t buf_idx);
int32_t mm_camera_set_frame_sync(mm_camera_obj_t *my_obj, uint32_t channel_id,
uint32_t sync_value);
void mm_channel_set_frame_sync(mm_channel_t *my_obj, uint32_t sync_value);
/* mm_stream */
extern int32_t mm_stream_fsm_fn(mm_stream_t *my_obj,
mm_stream_evt_type_t evt,
void * in_val,
void * out_val);
/* Function to register special callback for stream buffer*/
extern int32_t mm_stream_reg_buf_cb(mm_stream_t *my_obj,
mm_stream_data_cb_t val);
extern int32_t mm_stream_map_buf(mm_stream_t *my_obj,
uint8_t buf_type,
uint32_t frame_idx,
int32_t plane_idx,
int fd,
size_t size,
void *buffer);
extern int32_t mm_stream_map_bufs(mm_stream_t *my_obj,
const cam_buf_map_type_list *buf_map_list);
extern int32_t mm_stream_unmap_buf(mm_stream_t *my_obj,
uint8_t buf_type,
uint32_t frame_idx,
int32_t plane_idx);
/* utiltity fucntion declared in mm-camera-inteface2.c
* and need be used by mm-camera and below*/
uint32_t mm_camera_util_generate_handler(uint8_t index);
const char *mm_camera_util_get_dev_name(uint32_t cam_handler);
uint8_t mm_camera_util_get_index_by_handler(uint32_t handler);
/* poll/cmd thread functions */
extern int32_t mm_camera_poll_thread_launch(
mm_camera_poll_thread_t * poll_cb,
mm_camera_poll_thread_type_t poll_type);
extern int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb);
extern int32_t mm_camera_poll_thread_add_poll_fd(
mm_camera_poll_thread_t * poll_cb, uint8_t idx, uint32_t handler,
int32_t fd, mm_camera_poll_notify_t nofity_cb,
void *userdata, mm_camera_call_type_t);
extern int32_t mm_camera_poll_thread_del_poll_fd(
mm_camera_poll_thread_t * poll_cb, uint8_t idx, uint32_t handler,
mm_camera_call_type_t);
extern int32_t mm_camera_poll_thread_commit_updates(
mm_camera_poll_thread_t * poll_cb);
extern int32_t mm_camera_cmd_thread_launch(
mm_camera_cmd_thread_t * cmd_thread,
mm_camera_cmd_cb_t cb,
void* user_data);
extern int32_t mm_camera_cmd_thread_name(const char* name);
extern int32_t mm_camera_cmd_thread_release(mm_camera_cmd_thread_t * cmd_thread);
extern int32_t mm_camera_channel_advanced_capture(mm_camera_obj_t *my_obj,
uint32_t ch_id, mm_camera_advanced_capture_t type,
uint32_t trigger, void *in_value);
int32_t mm_camera_enqueue_evt(mm_camera_obj_t *my_obj,
mm_camera_event_t *event);
int32_t mm_camera_load_shim_lib();
cam_shim_packet_t *mm_camera_create_shim_cmd_packet(cam_shim_cmd_type type,
uint32_t sessionID, void *data);
int32_t mm_camera_destroy_shim_cmd_packet(cam_shim_packet_t *cmd);
int32_t mm_camera_module_event_handler(
uint32_t session_id, cam_event_t *event);
cam_status_t mm_camera_module_open_session(int sessionid,
int (*event_cb)(uint32_t sessionid, cam_event_t *event));
int32_t mm_camera_module_close_session(int session);
int32_t mm_camera_module_send_cmd(cam_shim_packet_t *event);
#endif /* __MM_CAMERA_H__ */

View file

@ -0,0 +1,137 @@
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __MM_CAMERA_DBG_H__
#define __MM_CAMERA_DBG_H__
// System dependencies
#include <log/log.h>
#ifdef QCAMERA_REDEFINE_LOG
// Camera dependencies
#include "cam_types.h"
typedef enum {
CAM_NO_MODULE,
CAM_HAL_MODULE,
CAM_MCI_MODULE,
CAM_JPEG_MODULE,
CAM_LAST_MODULE
} cam_modules_t;
/* values that persist.vendor.camera.global.debug can be set to */
/* all camera modules need to map their internal debug levels to this range */
typedef enum {
CAM_GLBL_DBG_NONE = 0,
CAM_GLBL_DBG_ERR = 1,
CAM_GLBL_DBG_WARN = 2,
CAM_GLBL_DBG_HIGH = 3,
CAM_GLBL_DBG_DEBUG = 4,
CAM_GLBL_DBG_LOW = 5,
CAM_GLBL_DBG_INFO = 6
} cam_global_debug_level_t;
extern int g_cam_log[CAM_LAST_MODULE][CAM_GLBL_DBG_INFO + 1];
#define FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
#undef CLOGx
#define CLOGx(module, level, fmt, args...) \
{\
if (g_cam_log[module][level]) { \
mm_camera_debug_log(module, level, __func__, __LINE__, fmt, ##args); \
}\
}
#undef CLOGI
#define CLOGI(module, fmt, args...) \
CLOGx(module, CAM_GLBL_DBG_INFO, fmt, ##args)
#undef CLOGD
#define CLOGD(module, fmt, args...) \
CLOGx(module, CAM_GLBL_DBG_DEBUG, fmt, ##args)
#undef CLOGL
#define CLOGL(module, fmt, args...) \
CLOGx(module, CAM_GLBL_DBG_LOW, fmt, ##args)
#undef CLOGW
#define CLOGW(module, fmt, args...) \
CLOGx(module, CAM_GLBL_DBG_WARN, fmt, ##args)
#undef CLOGH
#define CLOGH(module, fmt, args...) \
CLOGx(module, CAM_GLBL_DBG_HIGH, fmt, ##args)
#undef CLOGE
#define CLOGE(module, fmt, args...) \
CLOGx(module, CAM_GLBL_DBG_ERR, fmt, ##args)
#ifndef CAM_MODULE
#define CAM_MODULE CAM_MCI_MODULE
#endif
#undef LOGD
#define LOGD(fmt, args...) CLOGD(CAM_MODULE, fmt, ##args)
#undef LOGL
#define LOGL(fmt, args...) CLOGL(CAM_MODULE, fmt, ##args)
#undef LOGW
#define LOGW(fmt, args...) CLOGW(CAM_MODULE, fmt, ##args)
#undef LOGH
#define LOGH(fmt, args...) CLOGH(CAM_MODULE, fmt, ##args)
#undef LOGE
#define LOGE(fmt, args...) CLOGE(CAM_MODULE, fmt, ##args)
#undef LOGI
#define LOGI(fmt, args...) CLOGI(CAM_MODULE, fmt, ##args)
/* reads and updates camera logging properties */
void mm_camera_set_dbg_log_properties(void);
/* generic logger function */
void mm_camera_debug_log(const cam_modules_t module,
const cam_global_debug_level_t level,
const char *func, const int line, const char *fmt, ...);
void mm_camera_debug_open(void);
void mm_camera_debug_close(void);
#else
#undef LOGD
#define LOGD(fmt, args...) ALOGD(fmt, ##args)
#undef LOGL
#define LOGL(fmt, args...) ALOGD(fmt, ##args)
#undef LOGW
#define LOGW(fmt, args...) ALOGW(fmt, ##args)
#undef LOGH
#define LOGH(fmt, args...) ALOGD(fmt, ##args)
#undef LOGE
#define LOGE(fmt, args...) ALOGE(fmt, ##args)
#undef LOGI
#define LOGI(fmt, args...) ALOGV(fmt, ##args)
#endif
#endif /* __MM_CAMERA_DBG_H__ */

View file

@ -0,0 +1,190 @@
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __MM_CAMERA_MUXER_H__
#define __MM_CAMERA_MUXER_H__
// System dependencies
#include <media/msmb_camera.h>
// Camera dependencies
#include "cam_intf.h"
#include "mm_camera.h"
/*Frame sync node structure*/
typedef struct mm_frame_sync_queue_node {
/*Number of objects*/
uint8_t num_objs;
/*Super buffer for different objects*/
mm_camera_super_buf_t super_buf[MAX_OBJS_FOR_FRAME_SYNC];
/*FrameID of these super buffers*/
uint32_t frame_idx;
/*Is this matched?*/
uint8_t matched;
} mm_frame_sync_queue_node_t;
/*Utility Functions for dual camera*/
uint8_t mm_camera_util_get_index_by_num(uint8_t cam_num, uint32_t handler);
uint32_t mm_camera_util_get_handle_by_num(uint8_t num1, uint32_t handle);
uint32_t mm_camera_util_generate_handler_by_num(uint8_t cam_num, uint8_t index);
const char *mm_camera_util_get_dev_name_by_num(uint8_t cam_num, uint32_t cam_handle);
/*Function to handle command from client for Auxillary Cameras*/
int32_t mm_camera_muxer_camera_open(uint8_t camera_idx,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_query_capability(uint32_t camera_handle,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_register_event_notify(uint32_t camera_handle,
mm_camera_event_notify_t evt_cb,
void *user_data, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_close_camera(uint32_t camera_handle,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_map_buf(uint32_t camera_handle, uint8_t buf_type,
int fd, size_t size, void *buffer, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_map_bufs(uint32_t camera_handle,
const cam_buf_map_type_list *buf_map_list,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_unmap_buf(uint32_t camera_handle,
uint8_t buf_type, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_set_parms(uint32_t camera_handle,
parm_buffer_t *parms, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_get_parms(uint32_t camera_handle,
parm_buffer_t *parms, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_do_auto_focus(uint32_t camera_handle,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_cancel_auto_focus(uint32_t camera_handle,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_prepare_snapshot(uint32_t camera_handle,
int32_t do_af_flag, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_start_zsl_snapshot(uint32_t camera_handle,
uint32_t ch_id, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_stop_zsl_snapshot(uint32_t camera_handle,
uint32_t ch_id, mm_camera_obj_t *cam_obj);
uint32_t mm_camera_muxer_add_channel(uint32_t camera_handle,
mm_camera_channel_attr_t *attr, mm_camera_buf_notify_t channel_cb,
void *userdata, uint32_t src_id, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_delete_channel(uint32_t camera_handle, uint32_t ch_id,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_get_bundle_info(uint32_t camera_handle, uint32_t ch_id,
cam_bundle_config_t *bundle_info, mm_camera_obj_t *cam_obj);
uint32_t mm_camera_muxer_add_stream(uint32_t camera_handle,
uint32_t ch_id, uint32_t src__ch_id, uint32_t src_stream_id,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_delete_stream(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_link_stream(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id, uint32_t linked_ch_id,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_config_stream(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id, mm_camera_stream_config_t *config,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_map_stream_buf(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id,
uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx, int fd,
size_t size, void *buffer, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_map_stream_bufs(uint32_t camera_handle,
uint32_t ch_id, const cam_buf_map_type_list *buf_map_list,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_unmap_stream_buf(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id,
uint8_t buf_type, uint32_t buf_idx,
int32_t plane_idx, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_set_stream_parms(uint32_t camera_handle,
uint32_t ch_id, uint32_t s_id, cam_stream_parm_buffer_t *parms,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_get_stream_parms(uint32_t camera_handle,
uint32_t ch_id, uint32_t s_id, cam_stream_parm_buffer_t *parms,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_start_channel(uint32_t camera_handle,
uint32_t ch_id, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_stop_channel(uint32_t camera_handle,
uint32_t ch_id, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_qbuf(uint32_t camera_handle, uint32_t ch_id,
mm_camera_buf_def_t *buf, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_get_queued_buf_count(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_request_super_buf(uint32_t ch_id,
mm_camera_req_buf_t *buf, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_cancel_super_buf_request(uint32_t camera_handle,
uint32_t ch_id,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_flush_super_buf_queue(uint32_t camera_handle,
uint32_t ch_id,
uint32_t frame_idx, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_configure_notify_mode(uint32_t camera_handle,
uint32_t ch_id, mm_camera_super_buf_notify_mode_t notify_mode,
mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_process_advanced_capture(uint32_t camera_handle,
uint32_t ch_id, mm_camera_advanced_capture_t type,
int8_t start_flag, void *in_value, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_get_session_id(uint32_t camera_handle,
uint32_t* sessionid, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_flush(uint32_t camera_handle, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_register_stream_buf_cb(uint32_t camera_handle,
uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb,
mm_camera_stream_cb_type cb_type, void *userdata, mm_camera_obj_t *cam_obj);
int32_t mm_camera_muxer_reg_frame_sync(mm_camera_obj_t *cam_obj,
uint32_t ch_id, uint32_t stream_id,
mm_camera_intf_frame_sync_t *sync_attr);
int32_t mm_camera_muxer_set_dual_cam_cmd(uint32_t camera_handle,
mm_camera_obj_t *cam_obj);
/*Muxer internal functions*/
void mm_camera_muxer_stream_frame_sync(mm_camera_super_buf_t *super_buf,
void *user_data);
void mm_camera_muxer_channel_frame_sync(mm_camera_super_buf_t *super_buf,
void *user_data);
int32_t mm_camera_muxer_do_frame_sync(
mm_frame_sync_queue_t *queue, mm_camera_super_buf_t *buffer,
mm_frame_sync_queue_node_t *dispatch_buf);
void mm_camera_muxer_buf_done(mm_camera_super_buf_t *buffer);
int32_t mm_muxer_frame_sync_queue_init(mm_frame_sync_queue_t *queue);
int32_t mm_muxer_frame_sync_queue_deinit(mm_frame_sync_queue_t *queue);
int32_t mm_camera_muxer_get_stream_bufs(mm_stream_t *my_obj);
int32_t mm_camera_muxer_put_stream_bufs(mm_stream_t *my_obj);
int32_t mm_camera_muxer_stream_frame_sync_flush(mm_stream_t *str_obj);
int32_t mm_camera_muxer_channel_frame_sync_flush(mm_channel_t *my_obj);
mm_frame_sync_queue_node_t *mm_camera_muxer_frame_sync_dequeue(
mm_frame_sync_queue_t *queue, uint8_t matched_only);
int32_t mm_camera_muxer_channel_req_data_cb(mm_camera_req_buf_t *req_buf,
mm_channel_t *ch_obj);
int32_t mm_camera_map_stream_buf_ops(uint32_t buf_idx,
int32_t plane_idx, int fd, size_t size,
void *buffer, cam_mapping_buf_type type,
void *userdata);
int32_t mm_camera_bundled_map_stream_buf_ops(
const cam_buf_map_type_list *buf_map_list,
void *userdata);
int32_t mm_camera_unmap_stream_buf_ops(uint32_t buf_idx,
int32_t plane_idx, cam_mapping_buf_type type, void *userdata);
#endif /*__MM_CAMERA_MUXER_H */

View file

@ -0,0 +1,76 @@
/* Copyright (c) 2012-2014, 2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __MM_CAMERA_SOCKET_H__
#define __MM_CAMERA_SOCKET_H__
// System dependencies
#define SOCKET_H <SYSTEM_HEADER_PREFIX/socket.h>
#include SOCKET_H
#define UN_H <SYSTEM_HEADER_PREFIX/un.h>
#include UN_H
// Camera dependencies
#include "cam_types.h"
typedef enum {
MM_CAMERA_SOCK_TYPE_UDP,
MM_CAMERA_SOCK_TYPE_TCP,
} mm_camera_sock_type_t;
typedef union {
struct sockaddr addr;
struct sockaddr_un addr_un;
} mm_camera_sock_addr_t;
int mm_camera_socket_create(int cam_id, mm_camera_sock_type_t sock_type);
int mm_camera_socket_sendmsg(
int fd,
void *msg,
size_t buf_size,
int sendfd);
int mm_camera_socket_bundle_sendmsg(
int fd,
void *msg,
size_t buf_size,
int sendfds[CAM_MAX_NUM_BUFS_PER_STREAM],
int num_fds);
int mm_camera_socket_recvmsg(
int fd,
void *msg,
uint32_t buf_size,
int *rcvdfd);
void mm_camera_socket_close(int fd);
#endif /*__MM_CAMERA_SOCKET_H__*/

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,295 @@
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// System dependencies
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
// Camera dependencies
#include "mm_camera_dbg.h"
#include "mm_camera_sock.h"
/*===========================================================================
* FUNCTION : mm_camera_socket_create
*
* DESCRIPTION: opens a domain socket tied to camera ID and socket type
* @cam_id : camera ID
* @sock_type: socket type, TCP/UDP
*
* RETURN : fd related to the domain socket
*==========================================================================*/
int mm_camera_socket_create(int cam_id, mm_camera_sock_type_t sock_type)
{
int socket_fd;
mm_camera_sock_addr_t sock_addr;
int sktype;
int rc;
switch (sock_type)
{
case MM_CAMERA_SOCK_TYPE_UDP:
sktype = SOCK_DGRAM;
break;
case MM_CAMERA_SOCK_TYPE_TCP:
sktype = SOCK_STREAM;
break;
default:
LOGE("unknown socket type =%d", sock_type);
return -1;
}
socket_fd = socket(AF_UNIX, sktype, 0);
if (socket_fd < 0) {
LOGE("error create socket fd =%d", socket_fd);
return socket_fd;
}
memset(&sock_addr, 0, sizeof(sock_addr));
sock_addr.addr_un.sun_family = AF_UNIX;
snprintf(sock_addr.addr_un.sun_path,
UNIX_PATH_MAX, QCAMERA_DUMP_FRM_LOCATION"cam_socket%d", cam_id);
rc = connect(socket_fd, &sock_addr.addr, sizeof(sock_addr.addr_un));
if (0 != rc) {
close(socket_fd);
socket_fd = -1;
LOGE("socket_fd=%d %s ", socket_fd, strerror(errno));
}
LOGD("socket_fd=%d %s", socket_fd,
sock_addr.addr_un.sun_path);
return socket_fd;
}
/*===========================================================================
* FUNCTION : mm_camera_socket_close
*
* DESCRIPTION: close domain socket by its fd
* @fd : file descriptor for the domain socket to be closed
*
* RETURN : none
*==========================================================================*/
void mm_camera_socket_close(int fd)
{
if (fd >= 0) {
close(fd);
}
}
/*===========================================================================
* FUNCTION : mm_camera_socket_sendmsg
*
* DESCRIPTION: send msg through domain socket
* @fd : socket fd
* @msg : pointer to msg to be sent over domain socket
* @sendfd : file descriptors to be sent
*
* RETURN : the total bytes of sent msg
*==========================================================================*/
int mm_camera_socket_sendmsg(
int fd,
void *msg,
size_t buf_size,
int sendfd)
{
struct msghdr msgh;
struct iovec iov[1];
struct cmsghdr * cmsghp = NULL;
char control[CMSG_SPACE(sizeof(int))];
if (msg == NULL) {
LOGD("msg is NULL");
return -1;
}
memset(&msgh, 0, sizeof(msgh));
msgh.msg_name = NULL;
msgh.msg_namelen = 0;
iov[0].iov_base = msg;
iov[0].iov_len = buf_size;
msgh.msg_iov = iov;
msgh.msg_iovlen = 1;
LOGD("iov_len=%llu",
(unsigned long long int)iov[0].iov_len);
msgh.msg_control = NULL;
msgh.msg_controllen = 0;
/* if sendfd is valid, we need to pass it through control msg */
if( sendfd >= 0) {
msgh.msg_control = control;
msgh.msg_controllen = sizeof(control);
cmsghp = CMSG_FIRSTHDR(&msgh);
if (cmsghp != NULL) {
LOGD("Got ctrl msg pointer");
cmsghp->cmsg_level = SOL_SOCKET;
cmsghp->cmsg_type = SCM_RIGHTS;
cmsghp->cmsg_len = CMSG_LEN(sizeof(int));
*((int *)CMSG_DATA(cmsghp)) = sendfd;
LOGD("cmsg data=%d", *((int *) CMSG_DATA(cmsghp)));
} else {
LOGD("ctrl msg NULL");
return -1;
}
}
return sendmsg(fd, &(msgh), 0);
}
/*===========================================================================
* FUNCTION : mm_camera_socket_bundle_sendmsg
*
* DESCRIPTION: send msg through domain socket
* @fd : socket fd
* @msg : pointer to msg to be sent over domain socket
* @sendfds : file descriptors to be sent
* @numfds : num of file descriptors to be sent
*
* RETURN : the total bytes of sent msg
*==========================================================================*/
int mm_camera_socket_bundle_sendmsg(
int fd,
void *msg,
size_t buf_size,
int sendfds[CAM_MAX_NUM_BUFS_PER_STREAM],
int numfds)
{
struct msghdr msgh;
struct iovec iov[1];
struct cmsghdr * cmsghp = NULL;
char control[CMSG_SPACE(sizeof(int) * numfds)];
int *fds_ptr = NULL;
if (msg == NULL) {
LOGD("msg is NULL");
return -1;
}
memset(&msgh, 0, sizeof(msgh));
msgh.msg_name = NULL;
msgh.msg_namelen = 0;
iov[0].iov_base = msg;
iov[0].iov_len = buf_size;
msgh.msg_iov = iov;
msgh.msg_iovlen = 1;
LOGD("iov_len=%llu",
(unsigned long long int)iov[0].iov_len);
msgh.msg_control = NULL;
msgh.msg_controllen = 0;
/* if numfds is valid, we need to pass it through control msg */
if (numfds > 0) {
msgh.msg_control = control;
msgh.msg_controllen = sizeof(control);
cmsghp = CMSG_FIRSTHDR(&msgh);
if (cmsghp != NULL) {
cmsghp->cmsg_level = SOL_SOCKET;
cmsghp->cmsg_type = SCM_RIGHTS;
cmsghp->cmsg_len = CMSG_LEN(sizeof(int) * numfds);
fds_ptr = (int*) CMSG_DATA(cmsghp);
memcpy(fds_ptr, sendfds, sizeof(int) * numfds);
} else {
LOGE("ctrl msg NULL");
return -1;
}
}
return sendmsg(fd, &(msgh), 0);
}
/*===========================================================================
* FUNCTION : mm_camera_socket_recvmsg
*
* DESCRIPTION: receive msg from domain socket.
* @fd : socket fd
* @msg : pointer to mm_camera_sock_msg_packet_t to hold incoming msg,
* need be allocated by the caller
* @buf_size: the size of the buf that holds incoming msg
* @rcvdfd : pointer to hold recvd file descriptor if not NULL.
*
* RETURN : the total bytes of received msg
*==========================================================================*/
int mm_camera_socket_recvmsg(
int fd,
void *msg,
uint32_t buf_size,
int *rcvdfd)
{
struct msghdr msgh;
struct iovec iov[1];
struct cmsghdr *cmsghp = NULL;
char control[CMSG_SPACE(sizeof(int))];
int rcvd_fd = -1;
int rcvd_len = 0;
if ( (msg == NULL) || (buf_size <= 0) ) {
LOGE("msg buf is NULL");
return -1;
}
memset(&msgh, 0, sizeof(msgh));
msgh.msg_name = NULL;
msgh.msg_namelen = 0;
msgh.msg_control = control;
msgh.msg_controllen = sizeof(control);
iov[0].iov_base = msg;
iov[0].iov_len = buf_size;
msgh.msg_iov = iov;
msgh.msg_iovlen = 1;
if ( (rcvd_len = recvmsg(fd, &(msgh), 0)) <= 0) {
LOGE("recvmsg failed");
return rcvd_len;
}
LOGD("msg_ctrl %p len %zd", msgh.msg_control,
msgh.msg_controllen);
if( ((cmsghp = CMSG_FIRSTHDR(&msgh)) != NULL) &&
(cmsghp->cmsg_len == CMSG_LEN(sizeof(int))) ) {
if (cmsghp->cmsg_level == SOL_SOCKET &&
cmsghp->cmsg_type == SCM_RIGHTS) {
LOGD("CtrlMsg is valid");
rcvd_fd = *((int *) CMSG_DATA(cmsghp));
LOGD("Receieved fd=%d", rcvd_fd);
} else {
LOGE("Unexpected Control Msg. Line=%d");
}
}
if (rcvdfd) {
*rcvdfd = rcvd_fd;
}
return rcvd_len;
}

File diff suppressed because it is too large Load diff

Some files were not shown because too many files have changed in this diff Show more