第19讲 App如何实现ZSL功能 - Android Camera2 API

2024年10月25日 第19讲 App如何实现ZSL功能 极客笔记

本讲是Android Camera专题系列的第19讲,我们介绍Android Camera2 API专题的实战_App如何实现ZSL功能。

更多资源:

资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出Android Camera
星球ID: 17296815
Wechat 极客笔记圈

Reprocessable Architecture

Reprocessable Flow

GeekCamera2 ZSL

判断是否支持Reprocess

mStaticMetadata = new StaticMetadata(manager.getCameraCharacteristics(cameraIdS));
mIsReprocesableSupport =
        mStaticMetadata.isCapabilitySupported(
                CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING) ||
                mStaticMetadata.isCapabilitySupported(
                        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING);

获取Input Size和Format

private void setupInputSizeAndFormat() {
    if (mIsReprocesableSupport) {
        mMaxInputStreams =
                mStaticMetadata.getValueFromKeyNonNull(CameraCharacteristics.REQUEST_MAX_NUM_INPUT_STREAMS);
    }
    if (MyDebug.LOG) {
        Log.i(TAG, "[ZSL] max supported input streams:" + mMaxInputStreams +
                        ",mIsReprocesableSupport:" + mIsReprocesableSupport +
                        ",mEnableReprocessable:" + mEnableReprocessable);
    }
    try {
        if (mEnableReprocessable && mIsReprocesableSupport) {
            if (isOpaqueReprocessSupported(cameraIdS)) {
                mInputFormat = ImageFormat.PRIVATE;
                mInputSize = getMaxSize(mInputFormat, StaticMetadata.StreamDirection.Input);
                Log.i(TAG, "[ZSL] choose private reprocess.");
                return;
            }
            if (isYuvReprocessSupported(cameraIdS)) {
                mInputFormat = ImageFormat.YUV_420_888;
                mInputSize = getMaxSize(mInputFormat, StaticMetadata.StreamDirection.Input);
                Log.i(TAG, "[ZSL] choose yuv reprocess.");
                return;
            }
        }
    } catch (Exception e) {
    }

    if (MyDebug.LOG) {
        Log.i(TAG, "Reprocess not enabled.");
    }
}

创建InputConfiguration

if (mEnableReprocessable && mMaxInputStreams > 0 && mIsReprocesableSupport) {
    Log.i(TAG, "[ZSL] new InputConfiguration.");
    inputConfiguration = new InputConfiguration(mInputSize.getWidth(),
            mInputSize.getHeight(),
            mInputFormat);
}

获取Reprocess CaptureRequest

if (mEnableReprocessable && mMaxInputStreams > 0 && mIsReprocesableSupport) {
    try {
        Log.i(TAG, "[ZSL] createReprocessCaptureRequest begin");
        Image inputImage = mInputImageReaderListener.getImage(3000);
        Log.i(TAG, "[ZSL] createReprocessCaptureRequest");
        stillBuilder = mCameraDevice.createReprocessCaptureRequest(
                mZslResultListener.getCaptureResult(3000, inputImage.getTimestamp()));
        Log.i(TAG, "[ZSL] Image writer queueInputImage, timestamp:" + inputImage.getTimestamp());
        mInputImageWriter.queueInputImage(inputImage);
        inputImage.close();
        Log.i(TAG, "[ZSL] createReprocessCaptureRequest end");
    } catch (Exception e) {
        Log.e(TAG, "createReprocessCaptureRequest failed:" + e.toString());
    }
}

本文链接:http://so.lmcjl.com/news/16154/

展开阅读全文