pull/696/head
Mattia Iavarone 6 years ago
parent 13d3126170
commit 56e4100384
  1. 2
      .github/workflows/emulator_script.sh
  2. 21
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java
  3. 16
      cameraview/src/main/java/com/otaliastudios/cameraview/video/SnapshotVideoRecorder.java

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
adb logcat -c adb logcat -c
adb logcat CameraOrchestrator:I CameraEngine:I CameraView:I CameraCallbacks:I *:E -v color & adb logcat CameraOrchestrator:I CameraEngine:I CameraView:I CameraCallbacks:I CameraIntegrationTest:I MediaEncoderEngine:I AudioMediaEncoder:I VideoMediaEncoder:I TextureMediaEncoder:I *:E -v color &
./gradlew cameraview:connectedCheck ./gradlew cameraview:connectedCheck

@ -87,7 +87,7 @@ public abstract class CameraIntegrationTest extends BaseTest {
@Before @Before
public void setUp() { public void setUp() {
LOG.e("Test started. Setting up camera."); LOG.w("[TEST STARTED]", "Setting up camera.");
WorkerHandler.destroyAll(); WorkerHandler.destroyAll();
uiSync(new Runnable() { uiSync(new Runnable() {
@ -115,7 +115,8 @@ public abstract class CameraIntegrationTest extends BaseTest {
WorkerHandler crashThread = WorkerHandler.get("CrashThread"); WorkerHandler crashThread = WorkerHandler.get("CrashThread");
crashThread.getThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { crashThread.getThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override @Override
public void uncaughtException(Thread t, Throwable e) { public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {
LOG.e("[UNCAUGHT EXCEPTION]", "Exception in exception handler:", e);
uiExceptionOp.controller().end(e); uiExceptionOp.controller().end(e);
} }
}); });
@ -126,9 +127,10 @@ public abstract class CameraIntegrationTest extends BaseTest {
@After @After
public void tearDown() { public void tearDown() {
LOG.e("Test ended. Tearing down camera."); LOG.w("[TEST ENDED]", "Tearing down camera.");
camera.destroy(); camera.destroy();
WorkerHandler.destroyAll(); WorkerHandler.destroyAll();
LOG.w("[TEST ENDED]", "Torn down camera.");
} }
private void waitForUiException() throws Throwable { private void waitForUiException() throws Throwable {
@ -144,9 +146,11 @@ public abstract class CameraIntegrationTest extends BaseTest {
camera.open(); camera.open();
CameraOptions result = open.await(DELAY); CameraOptions result = open.await(DELAY);
if (expectSuccess) { if (expectSuccess) {
LOG.i("[OPEN SYNC]", "Expecting success.");
assertNotNull("Can open", result); assertNotNull("Can open", result);
onOpenSync(); onOpenSync();
} else { } else {
LOG.i("[OPEN SYNC]", "Expecting failure.");
assertNull("Should not open", result); assertNull("Should not open", result);
} }
return result; return result;
@ -166,8 +170,10 @@ public abstract class CameraIntegrationTest extends BaseTest {
camera.close(); camera.close();
Boolean result = close.await(DELAY); Boolean result = close.await(DELAY);
if (expectSuccess) { if (expectSuccess) {
LOG.i("[CLOSE SYNC]", "Expecting success.");
assertNotNull("Can close", result); assertNotNull("Can close", result);
} else { } else {
LOG.i("[CLOSE SYNC]", "Expecting failure.");
assertNull("Should not close", result); assertNull("Should not close", result);
} }
} }
@ -198,6 +204,7 @@ public abstract class CameraIntegrationTest extends BaseTest {
// long after the actual stop() call, so if we're still processing, let's wait more. // long after the actual stop() call, so if we're still processing, let's wait more.
if (expectSuccess && camera.isTakingVideo()) { if (expectSuccess && camera.isTakingVideo()) {
while (camera.isTakingVideo()) { while (camera.isTakingVideo()) {
LOG.w("[WAIT VIDEO]", "Waiting extra", DELAY, "milliseconds...");
video.listen(); video.listen();
result = video.await(DELAY); result = video.await(DELAY);
} }
@ -208,9 +215,11 @@ public abstract class CameraIntegrationTest extends BaseTest {
// Now we should be OK. // Now we should be OK.
if (expectSuccess) { if (expectSuccess) {
LOG.i("[WAIT VIDEO]", "Expecting success.");
assertEquals("Should call onVideoRecordingEnd", 0, onVideoRecordingEnd.getCount()); assertEquals("Should call onVideoRecordingEnd", 0, onVideoRecordingEnd.getCount());
assertNotNull("Should end video", result); assertNotNull("Should end video", result);
} else { } else {
LOG.i("[WAIT VIDEO]", "Expecting failure.");
assertNull("Should not end video", result); assertNull("Should not end video", result);
} }
return result; return result;
@ -228,8 +237,10 @@ public abstract class CameraIntegrationTest extends BaseTest {
})); }));
PictureResult result = pic.await(DELAY); PictureResult result = pic.await(DELAY);
if (expectSuccess) { if (expectSuccess) {
LOG.i("[WAIT PICTURE]", "Expecting success.");
assertNotNull("Can take picture", result); assertNotNull("Can take picture", result);
} else { } else {
LOG.i("[WAIT PICTURE]", "Expecting failure.");
assertNull("Should not take picture", result); assertNull("Should not take picture", result);
} }
return result; return result;
@ -256,9 +267,11 @@ public abstract class CameraIntegrationTest extends BaseTest {
} }
Boolean result = op.await(DELAY); Boolean result = op.await(DELAY);
if (expectSuccess) { if (expectSuccess) {
LOG.i("[WAIT VIDEO START]", "Expecting success.");
assertNotNull("should start video recording or get CameraError", result); assertNotNull("should start video recording or get CameraError", result);
assertTrue("should start video recording successfully", result); assertTrue("should start video recording successfully", result);
} else { } else {
LOG.i("[WAIT VIDEO START]", "Expecting failure.");
assertTrue("should not start video recording", result == null || !result); assertTrue("should not start video recording", result == null || !result);
} }
} }
@ -285,9 +298,11 @@ public abstract class CameraIntegrationTest extends BaseTest {
} }
Boolean result = op.await(DELAY); Boolean result = op.await(DELAY);
if (expectSuccess) { if (expectSuccess) {
LOG.i("[WAIT VIDEO SNAP START]", "Expecting success.");
assertNotNull("should start video recording or get CameraError", result); assertNotNull("should start video recording or get CameraError", result);
assertTrue("should start video recording successfully", result); assertTrue("should start video recording successfully", result);
} else { } else {
LOG.i("[WAIT VIDEO SNAP START]", "Expecting failure.");
assertTrue("should not start video recording", result == null || !result); assertTrue("should not start video recording", result == null || !result);
} }
} }

@ -231,16 +231,16 @@ public class SnapshotVideoRecorder extends VideoRecorder implements RendererFram
} }
if (mCurrentState == STATE_RECORDING) { if (mCurrentState == STATE_RECORDING) {
LOG.v("dispatching frame.");
TextureMediaEncoder textureEncoder
= (TextureMediaEncoder) mEncoderEngine.getVideoEncoder();
TextureMediaEncoder.Frame frame = textureEncoder.acquireFrame();
frame.timestampNanos = surfaceTexture.getTimestamp();
// NOTE: this is an approximation but it seems to work:
frame.timestampMillis = System.currentTimeMillis();
surfaceTexture.getTransformMatrix(frame.transform);
synchronized (mEncoderEngineLock) { synchronized (mEncoderEngineLock) {
if (mEncoderEngine != null) { // Can be null on teardown. if (mEncoderEngine != null) { // Can be null on teardown.
LOG.v("dispatching frame.");
TextureMediaEncoder textureEncoder
= (TextureMediaEncoder) mEncoderEngine.getVideoEncoder();
TextureMediaEncoder.Frame frame = textureEncoder.acquireFrame();
frame.timestampNanos = surfaceTexture.getTimestamp();
// NOTE: this is an approximation but it seems to work:
frame.timestampMillis = System.currentTimeMillis();
surfaceTexture.getTransformMatrix(frame.transform);
mEncoderEngine.notify(TextureMediaEncoder.FRAME_EVENT, frame); mEncoderEngine.notify(TextureMediaEncoder.FRAME_EVENT, frame);
} }
} }

Loading…
Cancel
Save