Skip to content

Commit 8966342

Browse files
authored
Revert "Migrate camera/android from SurfaceTexture->SurfaceProducer." (flutter#6964)
Reverts flutter/packages#6461 Resolves flutter#150549
1 parent 9c6f691 commit 8966342

File tree

6 files changed

+82
-42
lines changed

6 files changed

+82
-42
lines changed

packages/camera/camera_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.9+6
2+
3+
* Reverts changes to support Impeller.
4+
15
## 0.10.9+5
26

37
* Updates annotations lib to 1.8.0.

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.app.Activity;
1010
import android.content.Context;
1111
import android.graphics.ImageFormat;
12+
import android.graphics.SurfaceTexture;
1213
import android.hardware.camera2.CameraAccessException;
1314
import android.hardware.camera2.CameraCaptureSession;
1415
import android.hardware.camera2.CameraDevice;
@@ -62,7 +63,7 @@
6263
import io.flutter.plugins.camera.media.MediaRecorderBuilder;
6364
import io.flutter.plugins.camera.types.CameraCaptureProperties;
6465
import io.flutter.plugins.camera.types.CaptureTimeoutsWrapper;
65-
import io.flutter.view.TextureRegistry;
66+
import io.flutter.view.TextureRegistry.SurfaceTextureEntry;
6667
import java.io.File;
6768
import java.io.IOException;
6869
import java.util.ArrayList;
@@ -112,7 +113,7 @@ class Camera
112113
*/
113114
@VisibleForTesting int initialCameraFacing;
114115

115-
@VisibleForTesting final TextureRegistry.SurfaceProducer surfaceProducer;
116+
@VisibleForTesting final SurfaceTextureEntry flutterTexture;
116117
private final VideoCaptureSettings videoCaptureSettings;
117118
private final Context applicationContext;
118119
final DartMessenger dartMessenger;
@@ -213,16 +214,17 @@ public VideoCaptureSettings(@NonNull ResolutionPreset resolutionPreset, boolean
213214

214215
public Camera(
215216
final Activity activity,
216-
final TextureRegistry.SurfaceProducer surfaceProducer,
217+
final SurfaceTextureEntry flutterTexture,
217218
final CameraFeatureFactory cameraFeatureFactory,
218219
final DartMessenger dartMessenger,
219220
final CameraProperties cameraProperties,
220221
final VideoCaptureSettings videoCaptureSettings) {
222+
221223
if (activity == null) {
222224
throw new IllegalStateException("No activity available!");
223225
}
224226
this.activity = activity;
225-
this.surfaceProducer = surfaceProducer;
227+
this.flutterTexture = flutterTexture;
226228
this.dartMessenger = dartMessenger;
227229
this.applicationContext = activity.getApplicationContext();
228230
this.cameraProperties = cameraProperties;
@@ -241,6 +243,7 @@ public Camera(
241243
if (videoCaptureSettings.fps != null && videoCaptureSettings.fps.intValue() > 0) {
242244
recordingFps = videoCaptureSettings.fps;
243245
} else {
246+
244247
if (SdkCapabilityChecker.supportsEncoderProfiles()) {
245248
EncoderProfiles encoderProfiles = getRecordingProfile();
246249
if (encoderProfiles != null && encoderProfiles.getVideoProfiles().size() > 0) {
@@ -253,6 +256,7 @@ public Camera(
253256
}
254257

255258
if (recordingFps != null && recordingFps.intValue() > 0) {
259+
256260
final FpsRangeFeature fpsRange = new FpsRangeFeature(cameraProperties);
257261
fpsRange.setValue(new Range<Integer>(recordingFps, recordingFps));
258262
this.cameraFeatures.setFpsRange(fpsRange);
@@ -303,9 +307,8 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
303307

304308
MediaRecorderBuilder mediaRecorderBuilder;
305309

306-
// TODO(camsim99): Revert changes that allow legacy code to be used when recordingProfile is
307-
// null once this has largely been fixed on the Android side.
308-
// https://github.com/flutter/flutter/issues/119668
310+
// TODO(camsim99): Revert changes that allow legacy code to be used when recordingProfile is null
311+
// once this has largely been fixed on the Android side. https://github.com/flutter/flutter/issues/119668
309312
if (SdkCapabilityChecker.supportsEncoderProfiles() && getRecordingProfile() != null) {
310313
mediaRecorderBuilder =
311314
new MediaRecorderBuilder(
@@ -383,8 +386,7 @@ public void onOpened(@NonNull CameraDevice device) {
383386
cameraDevice = new DefaultCameraDeviceWrapper(device);
384387
try {
385388
startPreview();
386-
if (!recordingVideo) { // only send initialization if we werent already recording and
387-
// switching cameras
389+
if (!recordingVideo) { // only send initialization if we werent already recording and switching cameras
388390
dartMessenger.sendCameraInitializedEvent(
389391
resolutionFeature.getPreviewSize().getWidth(),
390392
resolutionFeature.getPreviewSize().getHeight(),
@@ -468,10 +470,11 @@ private void createCaptureSession(
468470

469471
// Build Flutter surface to render to.
470472
ResolutionFeature resolutionFeature = cameraFeatures.getResolution();
471-
surfaceProducer.setSize(
473+
SurfaceTexture surfaceTexture = flutterTexture.surfaceTexture();
474+
surfaceTexture.setDefaultBufferSize(
472475
resolutionFeature.getPreviewSize().getWidth(),
473476
resolutionFeature.getPreviewSize().getHeight());
474-
Surface flutterSurface = surfaceProducer.getSurface();
477+
Surface flutterSurface = new Surface(surfaceTexture);
475478
previewRequestBuilder.addTarget(flutterSurface);
476479

477480
List<Surface> remainingSurfaces = Arrays.asList(surfaces);
@@ -1157,8 +1160,7 @@ public void resumePreview() {
11571160
}
11581161

11591162
public void startPreview() throws CameraAccessException, InterruptedException {
1160-
// If recording is already in progress, the camera is being flipped, so send it through the
1161-
// VideoRenderer to keep the correct orientation.
1163+
// If recording is already in progress, the camera is being flipped, so send it through the VideoRenderer to keep the correct orientation.
11621164
if (recordingVideo) {
11631165
startPreviewWithVideoRendererStream();
11641166
} else {
@@ -1191,6 +1193,7 @@ private void startPreviewWithVideoRendererStream()
11911193
}
11921194

11931195
if (cameraProperties.getLensFacing() != initialCameraFacing) {
1196+
11941197
// If the new camera is facing the opposite way than the initial recording,
11951198
// the rotation should be flipped 180 degrees.
11961199
rotation = (rotation + 180) % 360;
@@ -1358,13 +1361,13 @@ public void uncaughtException(Thread thread, Throwable ex) {
13581361

13591362
public void setDescriptionWhileRecording(
13601363
@NonNull final Result result, CameraProperties properties) {
1364+
13611365
if (!recordingVideo) {
13621366
result.error("setDescriptionWhileRecordingFailed", "Device was not recording", null);
13631367
return;
13641368
}
13651369

1366-
// See VideoRenderer.java; support for this EGL extension is required to switch camera while
1367-
// recording.
1370+
// See VideoRenderer.java; support for this EGL extension is required to switch camera while recording.
13681371
if (!SdkCapabilityChecker.supportsEglRecordableAndroid()) {
13691372
result.error(
13701373
"setDescriptionWhileRecordingFailed",
@@ -1397,7 +1400,7 @@ public void dispose() {
13971400
Log.i(TAG, "dispose");
13981401

13991402
close();
1400-
surfaceProducer.release();
1403+
flutterTexture.release();
14011404
getDeviceOrientationManager().stop();
14021405
}
14031406

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/MethodCallHandlerImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,25 +393,27 @@ private void instantiateCamera(MethodCall call, Result result) throws CameraAcce
393393
Integer videoBitrate = call.argument("videoBitrate");
394394
Integer audioBitrate = call.argument("audioBitrate");
395395

396-
TextureRegistry.SurfaceProducer surfaceProducer = textureRegistry.createSurfaceProducer();
396+
TextureRegistry.SurfaceTextureEntry flutterSurfaceTexture =
397+
textureRegistry.createSurfaceTexture();
397398
DartMessenger dartMessenger =
398-
new DartMessenger(messenger, surfaceProducer.id(), new Handler(Looper.getMainLooper()));
399+
new DartMessenger(
400+
messenger, flutterSurfaceTexture.id(), new Handler(Looper.getMainLooper()));
399401
CameraProperties cameraProperties =
400402
new CameraPropertiesImpl(cameraName, CameraUtils.getCameraManager(activity));
401403
ResolutionPreset resolutionPreset = ResolutionPreset.valueOf(preset);
402404

403405
camera =
404406
new Camera(
405407
activity,
406-
surfaceProducer,
408+
flutterSurfaceTexture,
407409
new CameraFeatureFactoryImpl(),
408410
dartMessenger,
409411
cameraProperties,
410412
new Camera.VideoCaptureSettings(
411413
resolutionPreset, enableAudio, fps, videoBitrate, audioBitrate));
412414

413415
Map<String, Object> reply = new HashMap<>();
414-
reply.put("cameraId", surfaceProducer.id());
416+
reply.put("cameraId", flutterSurfaceTexture.id());
415417
result.success(reply);
416418
}
417419

0 commit comments

Comments
 (0)