|
|
@ -155,6 +155,11 @@ NdkCamera::NdkCamera(int32_t width, int32_t height, const NdkCamera::CAMERA_PARA
|
|
|
|
mOutputTarget = NULL;
|
|
|
|
mOutputTarget = NULL;
|
|
|
|
mSessionOutput = NULL;
|
|
|
|
mSessionOutput = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mImageReader2 = NULL;
|
|
|
|
|
|
|
|
mImageWindow2 = NULL;
|
|
|
|
|
|
|
|
mOutputTarget2 = NULL;
|
|
|
|
|
|
|
|
mSessionOutput2 = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
camera_device = 0;
|
|
|
|
camera_device = 0;
|
|
|
|
|
|
|
|
|
|
|
|
capture_session_output_container = 0;
|
|
|
|
capture_session_output_container = 0;
|
|
|
@ -165,6 +170,12 @@ NdkCamera::NdkCamera(int32_t width, int32_t height, const NdkCamera::CAMERA_PARA
|
|
|
|
mResult = { 0 };
|
|
|
|
mResult = { 0 };
|
|
|
|
mLdr = ~0;
|
|
|
|
mLdr = ~0;
|
|
|
|
mFinalLdr = 0;
|
|
|
|
mFinalLdr = 0;
|
|
|
|
|
|
|
|
mFinalBurstCaptures = m_params.burstCaptures;
|
|
|
|
|
|
|
|
if (mFinalBurstCaptures == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mFinalBurstCaptures = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mFinalOutputFormat = (m_params.burstRawCapture == 0) ? AIMAGE_FORMAT_YUV_420_888 : AIMAGE_FORMAT_RAW16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NdkCamera::~NdkCamera()
|
|
|
|
NdkCamera::~NdkCamera()
|
|
|
@ -618,6 +629,25 @@ int NdkCamera::open(const std::string& cameraId) {
|
|
|
|
status = ACaptureSessionOutputContainer_add(capture_session_output_container, mSessionOutput);
|
|
|
|
status = ACaptureSessionOutputContainer_add(capture_session_output_container, mSessionOutput);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_params.burstRawCapture == 1) // Auto
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mstatus = AImageReader_new(foundRes.org_width(), foundRes.org_height(), AIMAGE_FORMAT_YUV_420_888, burstCaptures, &mImageReader2);
|
|
|
|
|
|
|
|
if (mstatus == AMEDIA_OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
AImageReader_ImageListener listener;
|
|
|
|
|
|
|
|
listener.context = this;
|
|
|
|
|
|
|
|
listener.onImageAvailable = ::onImageAvailable;
|
|
|
|
|
|
|
|
mstatus = AImageReader_setImageListener(mImageReader2, &listener);
|
|
|
|
|
|
|
|
mstatus = AImageReader_getWindow(mImageReader2, &mImageWindow2);
|
|
|
|
|
|
|
|
ANativeWindow_acquire(mImageWindow2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
status = ACameraOutputTarget_create(mImageWindow2, &mOutputTarget2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status = ACaptureSessionOutput_create(mImageWindow2, &mSessionOutput2);
|
|
|
|
|
|
|
|
status = ACaptureSessionOutputContainer_add(capture_session_output_container, mSessionOutput2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CaptureRequest *request = CreateRequest(true);
|
|
|
|
CaptureRequest *request = CreateRequest(true);
|
|
|
|
mCaptureRequests.push_back(request);
|
|
|
|
mCaptureRequests.push_back(request);
|
|
|
|
#if 0
|
|
|
|
#if 0
|
|
|
@ -852,11 +882,12 @@ NdkCamera::CaptureRequest* NdkCamera::CreateRequest(bool isPreviewRequest)
|
|
|
|
CaptureRequest *request = new CaptureRequest();
|
|
|
|
CaptureRequest *request = new CaptureRequest();
|
|
|
|
std::memset(request, 0, sizeof(CaptureRequest));
|
|
|
|
std::memset(request, 0, sizeof(CaptureRequest));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool autoSwitchToOneFrame = (m_params.burstRawCapture == 1) && (mFinalOutputFormat == AIMAGE_FORMAT_YUV_420_888);
|
|
|
|
request->pThis = this;
|
|
|
|
request->pThis = this;
|
|
|
|
request->imageReader = isPreviewRequest ? mPreviewImageReader : mImageReader;
|
|
|
|
request->imageReader = isPreviewRequest ? mPreviewImageReader : (autoSwitchToOneFrame ? mImageReader2 : mImageReader);
|
|
|
|
request->imageWindow = isPreviewRequest ? mPreviewImageWindow : mImageWindow;
|
|
|
|
request->imageWindow = isPreviewRequest ? mPreviewImageWindow : (autoSwitchToOneFrame ? mImageWindow2 : mImageWindow);
|
|
|
|
request->imageTarget = isPreviewRequest ? mPreviewOutputTarget : mOutputTarget;
|
|
|
|
request->imageTarget = isPreviewRequest ? mPreviewOutputTarget : (autoSwitchToOneFrame ? mOutputTarget2 : mOutputTarget);
|
|
|
|
request->sessionOutput = isPreviewRequest ? mPreviewSessionOutput : mSessionOutput;
|
|
|
|
request->sessionOutput = isPreviewRequest ? mPreviewSessionOutput : (autoSwitchToOneFrame ? mSessionOutput2 : mSessionOutput);
|
|
|
|
request->templateId = isPreviewRequest ? TEMPLATE_PREVIEW : (ACameraDevice_request_template)m_params.requestTemplate;
|
|
|
|
request->templateId = isPreviewRequest ? TEMPLATE_PREVIEW : (ACameraDevice_request_template)m_params.requestTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
// mCaptureRequests.push_back(request);
|
|
|
|
// mCaptureRequests.push_back(request);
|
|
|
@ -1130,6 +1161,28 @@ void NdkCamera::close()
|
|
|
|
mImageReader = 0;
|
|
|
|
mImageReader = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mOutputTarget2 != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ACameraOutputTarget_free(mOutputTarget2);
|
|
|
|
|
|
|
|
mOutputTarget2 = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mImageWindow2 != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ANativeWindow_release(mImageWindow2);
|
|
|
|
|
|
|
|
mImageWindow2 = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mImageReader2 != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// AImageReader_setImageListener(image_reader, NULL);
|
|
|
|
|
|
|
|
//XYLOG(XYLOG_SEVERITY_DEBUG, "CameraStatus::AImageReader_delete %s", mCameraId.c_str());
|
|
|
|
|
|
|
|
AImageReader_delete(mImageReader2);
|
|
|
|
|
|
|
|
//XYLOG(XYLOG_SEVERITY_DEBUG, "CameraStatus::End AImageReader_delete %s", mCameraId.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mImageReader2 = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mPreviewSessionOutput != NULL)
|
|
|
|
if (mPreviewSessionOutput != NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (capture_session_output_container)
|
|
|
|
if (capture_session_output_container)
|
|
|
@ -1149,6 +1202,15 @@ void NdkCamera::close()
|
|
|
|
ACaptureSessionOutput_free(mSessionOutput);
|
|
|
|
ACaptureSessionOutput_free(mSessionOutput);
|
|
|
|
mSessionOutput = 0;
|
|
|
|
mSessionOutput = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSessionOutput2 != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (capture_session_output_container)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ACaptureSessionOutputContainer_remove(capture_session_output_container, mSessionOutput2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ACaptureSessionOutput_free(mSessionOutput2);
|
|
|
|
|
|
|
|
mSessionOutput2 = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (capture_session_output_container)
|
|
|
|
if (capture_session_output_container)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1198,7 +1260,7 @@ void NdkCamera::onImageAvailable(AImageReader* reader)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
avgY = avgY / (uint64_t)y_len;
|
|
|
|
avgY = avgY / (uint64_t)y_len;
|
|
|
|
m_locker.lock();
|
|
|
|
m_locker.lock();
|
|
|
|
mLdr = avgY;
|
|
|
|
mLdr = (uint8_t)avgY;
|
|
|
|
m_locker.unlock();
|
|
|
|
m_locker.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1674,11 +1736,23 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
|
|
|
|
|
|
|
|
|
|
|
|
if (readyForCapture/* && mCaptureRequests.size() > 1*/)
|
|
|
|
if (readyForCapture/* && mCaptureRequests.size() > 1*/)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "Ready for Capture AFS=%u AES=%u AWBS=%u Time=%u",
|
|
|
|
|
|
|
|
(unsigned int)afState, (unsigned int)aeState, (unsigned int)awbState, (unsigned int)(ts - m_startTime));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must update mFinalLdr As getBurstCaptures getOutputFormat depends mFinalLdr
|
|
|
|
// Must update mFinalLdr As getBurstCaptures getOutputFormat depends mFinalLdr
|
|
|
|
mFinalLdr = mLdr;
|
|
|
|
if (mLdr != ~0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mFinalLdr = mLdr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "Ready for Capture AFS=%u AES=%u AWBS=%u LDR=%u Time=%u",
|
|
|
|
|
|
|
|
(unsigned int)afState, (unsigned int)aeState, (unsigned int)awbState, mFinalLdr, (unsigned int)(ts - m_startTime));
|
|
|
|
|
|
|
|
if (m_params.burstRawCapture == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mFinalLdr > 50)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_WARNING, "Switch to OneFrame Capture(YUV) As LDR=%u", mFinalLdr);
|
|
|
|
|
|
|
|
mFinalOutputFormat = AIMAGE_FORMAT_YUV_420_888;
|
|
|
|
|
|
|
|
mFinalBurstCaptures = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t burstCaptures = getBurstCaptures();
|
|
|
|
uint32_t burstCaptures = getBurstCaptures();
|
|
|
|
if (burstCaptures == 0)
|
|
|
|
if (burstCaptures == 0)
|
|
|
@ -1898,13 +1972,13 @@ bool NdkCamera::IsCameraAvailable(const std::string& cameraId)
|
|
|
|
|
|
|
|
|
|
|
|
int32_t NdkCamera::getOutputFormat() const
|
|
|
|
int32_t NdkCamera::getOutputFormat() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (m_params.burstRawCapture == 0) ? AIMAGE_FORMAT_YUV_420_888 : ((m_params.burstRawCapture != 1 || mFinalLdr <= 50) ? AIMAGE_FORMAT_RAW16 : AIMAGE_FORMAT_YUV_420_888);
|
|
|
|
return mFinalOutputFormat;
|
|
|
|
// return m_params.burstRawCapture ? AIMAGE_FORMAT_RAW16 : AIMAGE_FORMAT_YUV_420_888;
|
|
|
|
// return m_params.burstRawCapture ? AIMAGE_FORMAT_RAW16 : AIMAGE_FORMAT_YUV_420_888;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t NdkCamera::getBurstCaptures() const
|
|
|
|
int32_t NdkCamera::getBurstCaptures() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (m_params.burstRawCapture == 0) ? 1 : ((m_params.burstRawCapture != 1 || mFinalLdr <= 50) ? m_params.burstCaptures : 1);
|
|
|
|
return mFinalBurstCaptures;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NdkCamera::CreateSession(ANativeWindow* previewWindow,
|
|
|
|
void NdkCamera::CreateSession(ANativeWindow* previewWindow,
|
|
|
|