pull/696/head
Mattia Iavarone 6 years ago
parent b8a78a5fe5
commit d1ef3d1ac2
  1. 12
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java
  2. 30
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/tools/RecoverCameraRule.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/MediaEncoder.java
  4. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/video/encoding/TextureMediaEncoder.java

@ -139,6 +139,18 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
}
});
controller.mCrashHandler = crashThread.getHandler();
// Ensure that important CameraExceptions are thrown, otherwise they are just
// logged and the test goes on.
camera.addCameraListener(new CameraListener() {
@Override
public void onCameraError(@NonNull CameraException exception) {
super.onCameraError(exception);
if (exception.isUnrecoverable()) {
throw exception;
}
}
});
}
});
}

@ -1,6 +1,7 @@
package com.otaliastudios.cameraview.tools;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.otaliastudios.cameraview.CameraException;
import com.otaliastudios.cameraview.CameraListener;
@ -21,16 +22,6 @@ public class RecoverCameraRule implements TestRule {
}
private final Callback mCallback;
private final CameraListener mListener = new CameraListener() {
@Override
public void onCameraError(@NonNull CameraException exception) {
super.onCameraError(exception);
if (exception.isUnrecoverable()) {
mException = exception;
}
}
};
private CameraException mException;
public RecoverCameraRule(@NonNull Callback callback) {
mCallback = callback;
@ -41,23 +32,30 @@ public class RecoverCameraRule implements TestRule {
return new Statement() {
@Override
public void evaluate() throws Throwable {
mException = null;
mCallback.getCamera().addCameraListener(mListener);
try {
base.evaluate();
} catch (Throwable throwable) {
if (mException != null) {
CameraException exception = findCameraException(throwable);
if (exception != null) {
mCallback.getLogger().e("**************************************");
mCallback.getLogger().e("!!! TEST FAILED, TRYING TO RECOVER !!!");
mCallback.getLogger().e("**************************************");
mException = null;
mCallback.getCamera().destroy();
base.evaluate();
}
} finally {
mCallback.getCamera().removeCameraListener(mListener);
}
}
};
}
@Nullable
private CameraException findCameraException(@NonNull Throwable throwable) {
if (throwable instanceof CameraException
&& ((CameraException) throwable).isUnrecoverable()) {
return (CameraException) throwable;
}
if (throwable.getCause() == null) return null;
if (throwable == throwable.getCause()) return null;
return findCameraException(throwable.getCause());
}
}

@ -407,7 +407,7 @@ public abstract class MediaEncoder {
}
while (true) {
int encoderStatus = mMediaCodec.dequeueOutputBuffer(mBufferInfo, OUTPUT_TIMEOUT_US);
LOG.i(mName, "DRAINING - Got status:", encoderStatus);
LOG.v(mName, "DRAINING - Got status:", encoderStatus);
if (encoderStatus == MediaCodec.INFO_TRY_AGAIN_LATER) {
// no output available yet
if (!drainAll) break; // out of while

@ -186,7 +186,7 @@ public class TextureMediaEncoder extends VideoMediaEncoder<TextureConfig> {
drainOutput(false);
// Then draw on the surface.
LOG.i("onEvent -",
LOG.v("onEvent -",
"frameNumber:", mFrameNumber,
"timestampUs:", frame.timestampUs(),
"hasReachedMaxLength:", hasReachedMaxLength(),
@ -228,7 +228,7 @@ public class TextureMediaEncoder extends VideoMediaEncoder<TextureConfig> {
mWindow.setPresentationTime(frame.timestampNanos);
mWindow.swapBuffers();
mFramePool.recycle(frame);
LOG.i("onEvent -",
LOG.v("onEvent -",
"frameNumber:", mFrameNumber,
"timestampUs:", frame.timestampUs(),
"hasReachedMaxLength:", hasReachedMaxLength(),

Loading…
Cancel
Save