版本 Android 12 USB camera
1、` …/3.4/default/ExternalCameraDevice.cpp | 28 +++±
…/default/ExternalCameraDeviceSession.cpp | 116 +++++++++++++++±-
…/ExternalCameraDeviceSession_3.4.h | 2 +
3 files changed, 133 insertions(+), 13 deletions(-)
diff --git a/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp b/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
index f4dd6d4b8b…a55f3e8735 100755
— a/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
+++ b/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
@@ -24,6 +24,7 @@
#include <linux/videodev2.h>
#include <linux/v4l2-subdev.h>
#include <linux/videodev2.h>
+#include <cutils/properties.h>
#include “android-base/macros.h”
#include “CameraMetadata.h”
#include “…/…/3.2/default/include/convert.h”
@@ -43,6 +44,8 @@ namespace V3_4 {
namespace implementation {
namespace {
+
mMirrorCameraEnable = true;
}
-ExternalCameraDevice::~ExternalCameraDevice() {}
+ExternalCameraDevice::~ExternalCameraDevice() {
bool ExternalCameraDevice::isInitFailed() {
Mutex::Autolock _l(mLock);
@@ -444,8 +456,18 @@ status_t ExternalCameraDevice::initDefaultCharsKeys(
UPDATE(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
&opticalStabilizationMode, 1);
ALOGD(“ExternalCameraDevice ----$$$$----!!”);
/*if(mMirrorCameraEnable){
const char* dev = mCameraId.c_str();
int index = atoi(dev);
ALOGE("dev:%s index:%d", dev, index);
const uint8_t facing = (index / 2) % 2 ? ANDROID_LENS_FACING_FRONT : ANDROID_LENS_FACING_BACK;
ALOGD("ExternalCameraDevice ----$$$$----!! (index / 2) % 2 == %d",(index / 2) % 2);
UPDATE(ANDROID_LENS_FACING, &facing, 1);
}else{*/
const uint8_t facing = ANDROID_LENS_FACING_EXTERNAL;
UPDATE(ANDROID_LENS_FACING, &facing, 1);
//}
// iseReduction
const uint8_t noiseReductionMode = ANDROID_NOISE_REDUCTION_MODE_OFF;
diff --git a/hardware/interfaces/camera/device/3.4/default/ExternalCameraDeviceSession.cpp b/hardware/interfaces/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
index cb13e2c131…3ed8052f7c 100755
— a/hardware/interfaces/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
+++ b/hardware/interfaces/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
@@ -43,7 +43,7 @@
#include <fcntl.h>
#include <poll.h>
#include <unistd.h>
+#include <cutils/properties.h>
#include “ExternalCameraDevice_3_4.h”
#include “subvideo.h”
@@ -102,6 +102,7 @@ constexpr int IOCTL_RETRY_SLEEP_US = 33000; // 33ms * MAX_RETRY = 0.5 seconds
// Constants for tryLock during dumpstate
static constexpr int kDumpLockRetries = 50;
static constexpr int kDumpLockSleep = 60000;
+static bool mMirrorCameraEnable = false;
bool tryLock(Mutex& mutex)
{
@@ -309,6 +310,13 @@ ExternalCameraDeviceSession::ExternalCameraDeviceSession(
}
ALOGD(“@%s,mCameraId:%s,mSubDevice:%d”,FUNCTION,mCameraId.c_str(),mSubDevice);
#endif
+
char value[92];
//ALOGD("ExternalCameraDeviceSession ----000----!!");
property_get("mirror.able", value, "0");
if (atoi(value)) {
mMirrorCameraEnable = true;
}}
void ExternalCameraDeviceSession::createPreviewBuffer() {
@@ -484,6 +492,7 @@ ExternalCameraDeviceSession::~ExternalCameraDeviceSession() {
ALOGE(“ExternalCameraDeviceSession deleted before close!”);
close(/callerIsDtor/true);
}
@@ -2448,9 +2457,59 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
input.yStride = tempFrameWidth; //mYu12Frame->mWidth;
input.cb = (uint8_t*)(req->mVirAddr) + tempFrameWidth * tempFrameHeight;
input.cStride = tempFrameWidth; //mYu12Frame->mWidth;
LOGD("format is BLOB or YV12, use software NV12ToI420");
ALOGD("format is BLOB or YV12, use software NV12ToI420");ATRACE_BEGIN("NV12toI420");
int res = libyuv::NV12ToI420(
//ALOGD("ExternalCameraDeviceSession ----00----!!");
if(mMirrorCameraEnable){
int res = libyuv::NV12ToI420(
static_cast<uint8_t*>(input.y),
input.yStride,
static_cast<uint8_t*>(input.cb),
input.cStride,
static_cast<uint8_t*>(mInternalYu12FrameLayout.y),
mInternalYu12FrameLayout.yStride,
static_cast<uint8_t*>(mInternalYu12FrameLayout.cb),
mInternalYu12FrameLayout.cStride,
static_cast<uint8_t*>(),
mInternalYu12FrameLayout.cStride,
mInternalYu12Frame->mWidth, mInternalYu12Frame->mHeight);
if (res == 0) {
camera_metadata_ro_entry entry = mCameraCharacteristics.find(ANDROID_SENSOR_ORIENTATION);
int orientation = entry.data.i32[0];
entry = mCameraCharacteristics.find(ANDROID_LENS_FACING);
int facing = entry.data.u8[0];
ALOGE("sensor orientation:%d facing:%d,ANDROID_LENS_FACING_FRONT:%d", orientation, facing, ANDROID_LENS_FACING_FRONT);
if (facing == ANDROID_LENS_FACING_FRONT) {
/*ALOGE("y:%d,yStride:%d,cb:%d,cr:%d,cStride:%d", mInternalYu12FrameLayout.y,
mInternalYu12FrameLayout.yStride, mInternalYu12FrameLayout.cb, ,
mInternalYu12FrameLayout.cStride);
ALOGE("mWidth:%d,mHeight:%d", mInternalYu12Frame->mWidth, mInternalYu12Frame->mHeight);*/
if (orientation % 180) {
ALOGE("I420Scale");
res = libyuv::I420Scale(static_cast<uint8_t*>(mInternalYu12FrameLayout.y), mInternalYu12FrameLayout.yStride,
static_cast<uint8_t*>(mInternalYu12FrameLayout.cb), mInternalYu12FrameLayout.cStride,
static_cast<uint8_t*>(), mInternalYu12FrameLayout.cStride,
mInternalYu12Frame->mWidth, mInternalYu12Frame->mHeight,
static_cast<uint8_t*>(mYu12FrameLayout.y), mYu12FrameLayout.yStride,
static_cast<uint8_t*>(mYu12FrameLayout.cb), mYu12FrameLayout.cStride,
static_cast<uint8_t*>(), mYu12FrameLayout.cStride,
mYu12Frame->mWidth, mYu12Frame->mHeight
,libyuv::kFilterNone);
}
else {
ALOGE("I420Mirror");
res = libyuv::I420Mirror(static_cast<uint8_t*>(mInternalYu12FrameLayout.y), mInternalYu12FrameLayout.yStride,
static_cast<uint8_t*>(mInternalYu12FrameLayout.cb), mInternalYu12FrameLayout.cStride,
static_cast<uint8_t*>(), mInternalYu12FrameLayout.cStride,
static_cast<uint8_t*>(mYu12FrameLayout.y), mYu12FrameLayout.yStride,
static_cast<uint8_t*>(mYu12FrameLayout.cb), mYu12FrameLayout.cStride,
static_cast<uint8_t*>(), mYu12FrameLayout.cStride,
mYu12Frame->mWidth, mYu12Frame->mHeight);
}
}
}
}else{
int res = libyuv::NV12ToI420(static_cast<uint8_t*>(input.y),input.yStride,static_cast<uint8_t*>(input.cb),
@@ -2462,6 +2521,8 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
static_cast<uint8_t*>(),
mYu12TempLayout.cStride,
mTempYu12Frame->mWidth, mTempYu12Frame->mHeight);
}
ATRACE_END();IMapper::Rect inputCrop;inputCrop.left = mapleft;
@@ -2497,6 +2558,7 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
libyuv::FilterMode::kFilterNone);
if (res != 0) {
//ALOGD("ExternalCameraDeviceSession ----11----!!");// For some webcam, the first few V4L2 frames might ALOGE("%s: Convert V4L2 frame to YU12 failed! res %d", __FUNCTION__, res);lk.unlock();
@@ -2535,6 +2597,7 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
ATRACE_END();
if (res != 0) {
//ALOGD("ExternalCameraDeviceSession ----22----!!");// For some webcam, the first few V4L2 frames might ALOGE("%s: Convert V4L2 frame to YU12 failed! res %d", __FUNCTION__, res);lk.unlock();
@@ -2572,6 +2635,7 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
ATRACE_END();
if (res != 0) {
//ALOGD("ExternalCameraDeviceSession ----33----!!");// For some webcam, the first few V4L2 frames might ALOGE("%s: Convert V4L2 frame to YU12 failed! res %d", __FUNCTION__, res);lk.unlock();
@@ -2610,6 +2674,7 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
ATRACE_END();
if (res != 0) {
//ALOGD("ExternalCameraDeviceSession ----44----!!");// For some webcam, the first few V4L2 frames might ALOGE("%s: Convert V4L2 frame to YU12 failed! res %d", __FUNCTION__, res);lk.unlock();
@@ -2647,6 +2712,7 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
ATRACE_END();
if (res != 0) {
//ALOGD("ExternalCameraDeviceSession ----55----!!");// For some webcam, the first few V4L2 frames might ALOGE("%s: Convert V4L2 frame to YU12 failed! res %d", __FUNCTION__, res);lk.unlock();
@@ -2676,6 +2742,7 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
mYu12Frame->mWidth, mYu12Frame->mHeight);
ATRACE_END();
if (ret != 0) {
//ALOGD("ExternalCameraDeviceSession ----66----!!");// For some webcam, the first few V4L2 frames might ALOGE("%s: Convert V4L2 frame to YU12 failed! res %d", __FUNCTION__, ret);lk.unlock();
@@ -3076,13 +3143,32 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
}
isJpegNeedCropScale = false;
} else {
camera2::RgaCropScale::rga_scale_crop(
tempFrameWidth, tempFrameHeight, req->mShareFd,
HAL_PIXEL_FORMAT_YCrCb_NV12, handle_fd,
halBuf.width, halBuf.height, 100, false, true,
(halBuf.format == PixelFormat::YCRCB_420_SP), is16Align,
req->frameIn->mFourcc == V4L2_PIX_FMT_YUYV);
ALOGV("%s: ANDROID_SCALER_CROP_REGION not set",__FUNCTION__);
//ALOGD("ExternalCameraDeviceSession ----%%%%0----!!");
if(mMirrorCameraEnable){
/*camera_metadata_ro_entry entry = mCameraCharacteristics.find(ANDROID_LENS_FACING);
int facing = entry.data.u8[0];
bool isFront = facing == ANDROID_LENS_FACING_EXTERNAL;
bool isVideo = !((halBuf.usage & GRALLOC_USAGE_HW_TEXTURE) == GRALLOC_USAGE_HW_TEXTURE);
bool mirror = (isFront) && (isVideo);
ALOGV("---zc usage:%" PRIx64, static_cast<uint64_t>(halBuf.usage));
ALOGV("---zc GRALLOC_USAGE_HW_TEXTURE:%x,VIDEO_ENCODER:%x", GRALLOC_USAGE_HW_TEXTURE, BufferUsage::VIDEO_ENCODER);
ALOGV("---zc isFront:%d,isVideo:%d,mirror:%d", isFront, isVideo, mirror);*/
camera2::RgaCropScale::rga_scale_crop(
tempFrameWidth, tempFrameHeight, req->mShareFd,
HAL_PIXEL_FORMAT_YCrCb_NV12, handle_fd,
halBuf.width, halBuf.height, 100, true, true,
(halBuf.format == PixelFormat::YCRCB_420_SP), is16Align,
req->frameIn->mFourcc == V4L2_PIX_FMT_YUYV);
ALOGV("%s: ANDROID_SCALER_CROP_REGION not set",__FUNCTION__);
}else{
camera2::RgaCropScale::rga_scale_crop(
tempFrameWidth, tempFrameHeight, req->mShareFd,
HAL_PIXEL_FORMAT_YCrCb_NV12, handle_fd,
halBuf.width, halBuf.height, 100, false, true,
(halBuf.format == PixelFormat::YCRCB_420_SP), is16Align,
req->frameIn->mFourcc == V4L2_PIX_FMT_YUYV);
ALOGV("%s: ANDROID_SCALER_CROP_REGION not set",__FUNCTION__);
}}
#ifdef DUMP_YUV
{
@@ -3170,6 +3256,16 @@ Status ExternalCameraDeviceSession::OutputThread::allocateIntermediateBuffers(
}
}
mInternalYu12Frame.clear();
mInternalYu12Frame = new AllocatedFrame(v4lSize.width, v4lSize.height);
int ret = mInternalYu12Frame->allocate(&mInternalYu12FrameLayout);
if (ret != 0) {
ALOGE("%s: allocating YU12 frame failed!", __FUNCTION__);
}
sp<AllocatedFrame> mInternalYu12Frame;std::unordered_map<Size, sp<AllocatedFrame>, SizeHasher> mIntermediateBuffers;std::unordered_map<Size, sp<AllocatedFrame>, SizeHasher> mScaledYu12Frames;YCbCrLayout mYu12FrameLayout;YCbCrLayout mYu12ThumbFrameLayout;YCbCrLayout mYu12TempLayout;
YCbCrLayout mInternalYu12FrameLayout;uint32_t mBlobBufferSize = 0; // 0 -> HAL derive buffer size, else: use given sizestd::string mExifMake;
–
2.25.1
`
本文发布于:2024-02-02 18:49:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170687096245738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |