本讲是Android Camera专题系列的第16讲,我们介绍Android Camera2 API专题的Deferred Surface。
视频在线观看:
Android Camera2 API课程体系
Deferred Surface回顾
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<OutputConfiguration> finalizeOutputConfigs = new ArrayList<>();
finalizeOutputConfigs.add(mPreviewOutputConfiguration);
mCameraCaptureSession.finalizeOutputConfigurations(finalizeOutputConfigs);
} catch (Exception e) {
Log.e(TAG, "finalizeOutputConfigurations with exception:" + e.toString());
}
}