第15讲 surface sharing实战 -凯发k8旗舰厅

本讲是android camera专题系列的第15讲,我们介绍android camera2 api专题的surface sharing。

更多资源:

资源 描述
在线课程
知识星球 星球名称:深入浅出android camera
星球id: 17296815
wechat 极客笔记圈

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();
    }
}

camera课程

python教程

java教程

web教程

数据库教程

图形图像教程

办公软件教程

linux教程

计算机教程

大数据教程

开发工具教程

android camera2 api

网站地图