本讲是android camera专题系列的第16讲,我们介绍android camera2 api专题的deferred surface。
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
android camera2 api课程体系
deferred surface回顾
deferred surface请参阅链接:
deferred surface实战
创建outputconfiguration的方式
synchronized( background_camera_lock ) {
surface preview_surface = null;
if (!musepreviewdeferredsurface) {
preview_surface = getpreviewsurface();
}
if( video_recorder != null ) {
if( supports_photo_video_recording && !want_video_high_speed && want_photo_video_recording ) {
if (!musepreviewdeferredsurface && !menablepreviewsharesurface) {
surfaces = arrays.aslist(preview_surface, video_recorder_surface, imagereader.getsurface());
} else {
captureoutputconfiguration = new outputconfiguration(imagereader.getsurface());
if (preview_surface != null) {
mpreviewoutputconfiguration = new outputconfiguration(preview_surface);
} else {
mpreviewoutputconfiguration = new outputconfiguration(
new android.util.size(mpreviewwidth, mpreviewheight),
surfacetexture.class);
}
if (menablepreviewsharesurface) {
mpreviewoutputconfiguration.enablesurfacesharing();
mpreviewoutputconfiguration.addsurface(video_recorder_surface);
} else {
recordoutputconfiguration = new outputconfiguration(video_recorder_surface);
}
}
}
else {
if (!musepreviewdeferredsurface && !menablepreviewsharesurface) {
surfaces = arrays.aslist(preview_surface, video_recorder_surface);
} else {
if (preview_surface != null) {
mpreviewoutputconfiguration = new outputconfiguration(preview_surface);
} else {
mpreviewoutputconfiguration = new outputconfiguration(
new android.util.size(mpreviewwidth, mpreviewheight),
surfacetexture.class);
}
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
if (!musepreviewdeferredsurface && !menablepreviewsharesurface) {
surfaces = collections.singletonlist(preview_surface);
} else {
if (preview_surface != null) {
mpreviewoutputconfiguration = new outputconfiguration(preview_surface);
} else {
mpreviewoutputconfiguration = new outputconfiguration(
new android.util.size(mpreviewwidth, mpreviewheight),
surfacetexture.class
);
if (menablepreviewsharesurface) {
mpreviewoutputconfiguration.enablesurfacesharing();
}
}
}
}
else if( imagereaderraw != null ) {
surfaces = arrays.aslist(preview_surface, imagereader.getsurface(), imagereaderraw.getsurface());
}
else {
if (!musepreviewdeferredsurface && !menablepreviewsharesurface) {
surfaces = arrays.aslist(preview_surface, imagereader.getsurface());
} else {
if (preview_surface != null) {
mpreviewoutputconfiguration = new outputconfiguration(preview_surface);
} else {
mpreviewoutputconfiguration = new outputconfiguration(
new android.util.size(mpreviewwidth, mpreviewheight),
surfacetexture.class
);
if (menablepreviewsharesurface) {
mpreviewoutputconfiguration.enablesurfacesharing();
}
captureoutputconfiguration = new outputconfiguration(imagereader.getsurface());
}
}
}
if( mydebug.log ) {
log.i(tag, "texture: " msurfacetexture);
log.i(tag, "preview_surface: " preview_surface);
}
}
调用addsurface,然后finalizeoutputconfigurations
if (musepreviewdeferredsurface) {
mpreviewoutputconfiguration.addsurface(surface);
try {
list finalizeoutputconfigs = new arraylist<>();
finalizeoutputconfigs.add(mpreviewoutputconfiguration);
mcameracapturesession.finalizeoutputconfigurations(finalizeoutputconfigs);
} catch (exception e) {
log.e(tag, "finalizeoutputconfigurations with exception:" e.tostring());
}
}