第15讲 Surface Sharing实战 - Android Camera2 API

本讲是Android Camera专题系列的第15讲,我们介绍Android Camera2 API专题的Surface Sharing。

视频在线观看:

加入知识星球与更多Camera同学交流

  • 星球名称:深入浅出Android Camera
  • 星球ID: 17296815

Android Camera2 API课程体系

Android Camera2 API课程体系

在创建Camera Capture Session前Add Share Surface

synchronized( background_camera_lock ) {
    Surface preview_surface = getPreviewSurface();
    if( video_recorder != null ) {
        if( supports_photo_video_recording && !want_video_high_speed && want_photo_video_recording ) {
            surfaces = Arrays.asList(preview_surface, video_recorder_surface, imageReader.getSurface());
            captureOutputConfiguration = new OutputConfiguration(imageReader.getSurface());
            mPreviewOutputConfiguration = new OutputConfiguration(preview_surface);
            if (mEnablePreviewShareSurface) {
                mPreviewOutputConfiguration.enableSurfaceSharing();
                mPreviewOutputConfiguration.addSurface(video_recorder_surface);
            } else {
                recordOutputConfiguration = new OutputConfiguration(video_recorder_surface);
            }
        }
        else {
            surfaces = Arrays.asList(preview_surface, video_recorder_surface);
            mPreviewOutputConfiguration = new OutputConfiguration(preview_surface);
            if (mEnablePreviewShareSurface) {
                mPreviewOutputConfiguration.enableSurfaceSharing();
                mPreviewOutputConfiguration.addSurface(video_recorder_surface);
            } else {
                recordOutputConfiguration = new OutputConfiguration(video_recorder_surface);
            }
        }
        // n.b., raw not supported for photo snapshots while video recording
    }
    else if( want_video_high_speed ) {
        // future proofing - at the time of writing want_video_high_speed is only set when recording video,
        // but if ever this is changed, can only support the preview_surface as a target
        surfaces = Collections.singletonList(preview_surface);
        mPreviewOutputConfiguration = new OutputConfiguration(preview_surface);
        mPreviewOutputConfiguration.enableSurfaceSharing();
    }
    else if( imageReaderRaw != null ) {
        surfaces = Arrays.asList(preview_surface, imageReader.getSurface(), imageReaderRaw.getSurface());
    }
    else {
        surfaces = Arrays.asList(preview_surface, imageReader.getSurface());
        mPreviewOutputConfiguration = new OutputConfiguration(preview_surface);
        mPreviewOutputConfiguration.enableSurfaceSharing();
        captureOutputConfiguration = new OutputConfiguration(imageReader.getSurface());
    }
    if( MyDebug.LOG ) {
        Log.i(TAG, "texture: " + mSurfaceTexture);
        Log.i(TAG, "preview_surface: " + preview_surface);
    }
}

在创建Camera Capture Session后Add Share Surface

@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
    if( MyDebug.LOG ) {
        Log.i(TAG, "onConfigured: " + session);
        Log.i(TAG, "captureSession was: " + mCameraCaptureSession);
    }
    if( mCameraDevice == null ) {
        if( MyDebug.LOG ) {
            Log.i(TAG, "camera is closed");
        }
        synchronized( background_camera_lock ) {
            callback_done = true;
            background_camera_lock.notifyAll();
        }
        return;
    }
    synchronized( background_camera_lock ) {
        mCameraCaptureSession = session;
        Surface surface = getPreviewSurface();
        if( MyDebug.LOG ) {
            Log.i(TAG, "add surface to previewBuilder: " + surface);
        }
        mPreviewBuilder.addTarget(surface);
        if( video_recorder != null ) {
            if( MyDebug.LOG ) {
                Log.i(TAG, "add video recorder surface to previewBuilder: " + video_recorder_surface);
            }
            mPreviewBuilder.addTarget(video_recorder_surface);
        }
        if (mEnablePreviewShareSurface) {
            mPreviewOutputConfiguration.addSurface(mPreviewImageReader.getSurface());
            try {
                mCameraCaptureSession.updateOutputConfiguration(mPreviewOutputConfiguration);
                mPreviewBuilder.addTarget(mPreviewImageReader.getSurface());
            } catch (Exception e) {
                Log.e(TAG, "updateOutputConfiguration with exception:" + e.toString());
            }
        }
        try {
            setRepeatingRequest();
        }
        catch(CameraAccessException e) {
            if( MyDebug.LOG ) {
                Log.e(TAG, "failed to start preview");
                Log.e(TAG, "reason: " + e.getReason());
                Log.e(TAG, "message: " + e.getMessage());
            }
            e.printStackTrace();
            // we indicate that we failed to start the preview by setting captureSession back to null
            // this will cause a CameraControllerException to be thrown below
            mCameraCaptureSession = null;
        }
    }
    synchronized( background_camera_lock ) {
        callback_done = true;
        background_camera_lock.notifyAll();
    }
}
赞(1)
未经允许不得转载:极客笔记 » 第15讲 Surface Sharing实战

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
Android Camera2参考
Android Camera2参考概述
Android Camera2参数参考
Android Camera2参数参考概述
Android Camera2指南
Android Camera2指南概述
Android Camera HAL开发
Android Camera HAL开发概述
Android Camera2 API
第2讲 Android Camera 架构介绍第3讲 Camera2 API 概述第4讲 Open和Close Camera流程第5讲 GeekCamera2介绍第6讲 Open和Close Camera代码实现第7讲 Hardware Level详解第8讲 AVAILABLE_CAPABILITIES详解第9讲 StreamConfigurationMap详解一第10讲 StreamConfigurationMap详解二第11讲 StreamConfigurationMap实战一第12讲 StreamConfigurationMap实战二第13讲 为什么需要OutputConfiguration第14讲 OutputConfiguration API详解第15讲 Surface Sharing实战第16讲 Deferred Surface实战第17讲 Reprocessable Capture Session详解一第18讲 Reprocessable Capture Session详解二第19讲 App如何实现ZSL功能第20讲 SessionConfiguration详解第21讲 createCaptureSession详解第22讲 SessionParameter实战第23讲 CaptureRequest详解第24讲 如何操作VendorTag第25讲 获取Physical Camera数据流第26讲 CameraCaptureSession详解第27讲 CameraCaptureSession.CaptureCallback详解第28讲 GeekCamera2连拍实战第29讲 SlowMotion实战第30讲 CaptureResult详解第31讲 AE自动曝光 Part 1第32讲 AE自动曝光 Part 2第33讲 AE自动曝光实战第34讲 AE手动曝光第35讲 AE手动曝光实战第36讲 Flash闪光灯控制第37讲 拍照打闪实战第38讲 通过CropRegion控制Zoom缩放第39讲 通过ZoomRatio控制Zoom缩放第40讲 Digital Zoom缩放实战第41讲 Touch AE实战第42讲 AF自动对焦第43讲 AF自动对焦 第二部分第44讲 AF自动对焦实战第45讲 手动对焦实战第46讲 AWB自动白平衡第47讲 AWB自动白平衡实战第48讲 FD人脸检测第49讲 Android13 Camera2 New APIs介绍