fix some of the requested changes

pull/421/head
Giacomo Randazzo 6 years ago
parent a05e1416cd
commit 8b2d988fdf
  1. 5
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/MockCameraController.java
  2. 1
      cameraview/src/main/gles/com/otaliastudios/cameraview/TextureMediaEncoder.java
  3. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  4. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  5. 36
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  6. 15
      cameraview/src/main/java/com/otaliastudios/cameraview/OverlayLayout.java
  7. 13
      cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java
  8. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java
  9. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/SurfaceDrawer.java
  10. 6
      cameraview/src/main/res/values/attrs.xml
  11. 2
      demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java
  12. 3
      demo/src/main/res/layout/activity_camera.xml

@ -134,9 +134,4 @@ public class MockCameraController extends CameraController {
void setPlaySounds(boolean playSounds) { void setPlaySounds(boolean playSounds) {
} }
@Override
void setDisableOverlayFor(@NonNull DisableOverlayFor disableOverlayFor) {
}
} }

@ -141,7 +141,6 @@ class TextureMediaEncoder extends VideoMediaEncoder<TextureMediaEncoder.Config>
drainOutput(false); drainOutput(false);
// Future note: passing scale values to the viewport? They are scaleX and scaleY, // Future note: passing scale values to the viewport? They are scaleX and scaleY,
// but flipped based on the mConfig.scaleFlipped boolean. // but flipped based on the mConfig.scaleFlipped boolean.
// mViewport.drawFrame(mConfig.textureId, mConfig.overlayTextureId, transform, overlayTransform);
mViewport.drawFrame(mConfig.textureId, transform); mViewport.drawFrame(mConfig.textureId, transform);
mViewport.drawFrame(mConfig.overlayTextureId, overlayTransform); mViewport.drawFrame(mConfig.overlayTextureId, overlayTransform);
mWindow.setPresentationTime(frame.timestamp); mWindow.setPresentationTime(frame.timestamp);

@ -503,15 +503,6 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
return false; return false;
} }
@Override
void setDisableOverlayFor(@NonNull DisableOverlayFor disableOverlayFor) {
if (mDisableOverlayFor != disableOverlayFor) {
LOG.w("DisableOverlayFor setting was changed while recording. " +
"Changes will take place starting from next video/picture.");
mDisableOverlayFor = disableOverlayFor;
}
}
// Choose the best default focus, based on session type. // Choose the best default focus, based on session type.
private void applyDefaultFocus(@NonNull Camera.Parameters params) { private void applyDefaultFocus(@NonNull Camera.Parameters params) {
@ -790,7 +781,8 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
// Reset facing and start. // Reset facing and start.
mFacing = realFacing; mFacing = realFacing;
GlCameraPreview cameraPreview = (GlCameraPreview) mPreview; GlCameraPreview cameraPreview = (GlCameraPreview) mPreview;
mVideoRecorder = new SnapshotVideoRecorder(videoResult, Camera1.this, cameraPreview, mDisableOverlayFor != DisableOverlayFor.VIDEO, videoSurfaceDrawerList); // TODO when we'll have the API for setting where to draw each view, we'll fix the withOverlay parameter..
mVideoRecorder = new SnapshotVideoRecorder(videoResult, Camera1.this, cameraPreview, true, videoSurfaceDrawerList);
mVideoRecorder.start(); mVideoRecorder.start();
} }
}); });

@ -52,7 +52,6 @@ abstract class CameraController implements
protected float mZoomValue; protected float mZoomValue;
protected float mExposureCorrectionValue; protected float mExposureCorrectionValue;
protected boolean mPlaySounds; protected boolean mPlaySounds;
protected DisableOverlayFor mDisableOverlayFor;
@Nullable private SizeSelector mPreviewStreamSizeSelector; @Nullable private SizeSelector mPreviewStreamSizeSelector;
private SizeSelector mPictureSizeSelector; private SizeSelector mPictureSizeSelector;
@ -374,8 +373,6 @@ abstract class CameraController implements
abstract void setPlaySounds(boolean playSounds); abstract void setPlaySounds(boolean playSounds);
abstract void setDisableOverlayFor(@NonNull DisableOverlayFor disableOverlayFor);
//endregion //endregion
//region final getters //region final getters
@ -471,11 +468,6 @@ abstract class CameraController implements
return mPictureRecorder != null; return mPictureRecorder != null;
} }
@NonNull
final DisableOverlayFor getDisableOverlayFor() {
return mDisableOverlayFor;
}
//endregion //endregion
//region Orientation utils //region Orientation utils

@ -121,7 +121,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
int videoMaxDuration = a.getInteger(R.styleable.CameraView_cameraVideoMaxDuration, 0); int videoMaxDuration = a.getInteger(R.styleable.CameraView_cameraVideoMaxDuration, 0);
int videoBitRate = a.getInteger(R.styleable.CameraView_cameraVideoBitRate, 0); int videoBitRate = a.getInteger(R.styleable.CameraView_cameraVideoBitRate, 0);
int audioBitRate = a.getInteger(R.styleable.CameraView_cameraAudioBitRate, 0); int audioBitRate = a.getInteger(R.styleable.CameraView_cameraAudioBitRate, 0);
DisableOverlayFor disableOverlayFor = DisableOverlayFor.fromValue(a.getInteger(R.styleable.CameraView_cameraDisableOverlayFor, DisableOverlayFor.DEFAULT.value()));
// Picture size selector // Picture size selector
List<SizeSelector> pictureConstraints = new ArrayList<>(3); List<SizeSelector> pictureConstraints = new ArrayList<>(3);
@ -228,7 +227,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoMaxSize(videoMaxSize); setVideoMaxSize(videoMaxSize);
setVideoMaxDuration(videoMaxDuration); setVideoMaxDuration(videoMaxDuration);
setVideoBitRate(videoBitRate); setVideoBitRate(videoBitRate);
setDisableOverlayFor(disableOverlayFor);
// Apply gestures // Apply gestures
mapGesture(Gesture.TAP, tapGesture); mapGesture(Gesture.TAP, tapGesture);
@ -779,8 +777,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setVideoCodec((VideoCodec) control); setVideoCodec((VideoCodec) control);
} else if (control instanceof Preview) { } else if (control instanceof Preview) {
setPreview((Preview) control); setPreview((Preview) control);
} else if (control instanceof DisableOverlayFor) {
setDisableOverlayFor((DisableOverlayFor) control);
} }
} }
@ -1683,38 +1679,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
return mCameraController.isTakingPicture(); return mCameraController.isTakingPicture();
} }
/**
* Sets the mode where the overlay is disabled.
*
* @see DisableOverlayFor#NONE
* @see DisableOverlayFor#PICTURE
* @see DisableOverlayFor#VIDEO
* @param mode desired mode.
*/
public void setDisableOverlayFor(@NonNull DisableOverlayFor mode) {
mCameraController.setDisableOverlayFor(mode);
}
/**
* Gets the current mode where the overlay is disabled.
* @return a mode
*/
@NonNull
public DisableOverlayFor getDisableOverlayFor() {
return mCameraController.getDisableOverlayFor();
}
/**
* Force the overlay to be redrawn.
*/
public void invalidateOverlay() {
if (mPreviewOverlayLayout != null) {
mPreviewOverlayLayout.postInvalidate();
}
}
//endregion //endregion
//region Callbacks and dispatching //region Callbacks and dispatching

@ -13,7 +13,7 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class OverlayLayout extends FrameLayout implements SurfaceDrawer { class OverlayLayout extends FrameLayout implements SurfaceDrawer {
public OverlayLayout(@NonNull Context context) { public OverlayLayout(@NonNull Context context) {
super(context); super(context);
@ -41,17 +41,4 @@ public class OverlayLayout extends FrameLayout implements SurfaceDrawer {
e.printStackTrace(); e.printStackTrace();
} }
} }
// invalidates children (and nested children) recursively
private void postInvalidateRecursive(ViewGroup layout) {
int count = layout.getChildCount();
View child;
for (int i = 0; i < count; i++) {
child = layout.getChildAt(i);
if(child instanceof ViewGroup)
postInvalidateRecursive((ViewGroup) child);
else
child.postInvalidate();
}
}
} }

@ -47,7 +47,8 @@ class SnapshotPictureRecorder extends PictureRecorder {
mOutputRatio = outputRatio; mOutputRatio = outputRatio;
mFormat = mController.mPreviewFormat; mFormat = mController.mPreviewFormat;
mSensorPreviewSize = mController.mPreviewStreamSize; mSensorPreviewSize = mController.mPreviewStreamSize;
mWithOverlay = mController.mDisableOverlayFor != DisableOverlayFor.PICTURE; // TODO when we'll have the API for setting where to draw each view, we'll fix this.
mWithOverlay = true;
mSurfaceDrawerList = surfaceDrawerList; mSurfaceDrawerList = surfaceDrawerList;
} }
@ -80,18 +81,18 @@ class SnapshotPictureRecorder extends PictureRecorder {
mOverlayTextureId = viewport.createTexture(); mOverlayTextureId = viewport.createTexture();
} }
mSurfaceTexture = new SurfaceTexture(mTextureId, true); mSurfaceTexture = new SurfaceTexture(mTextureId, true);
if (mOverlayTextureId != 0) { if (mWithOverlay) {
mOverlaySurfaceTexture = new SurfaceTexture(mOverlayTextureId, true); mOverlaySurfaceTexture = new SurfaceTexture(mOverlayTextureId, true);
} }
// Need to crop the size. // Need to crop the size.
Rect crop = CropHelper.computeCrop(mResult.size, mOutputRatio); Rect crop = CropHelper.computeCrop(mResult.size, mOutputRatio);
mResult.size = new Size(crop.width(), crop.height()); mResult.size = new Size(crop.width(), crop.height());
mSurfaceTexture.setDefaultBufferSize(mResult.size.getWidth(), mResult.size.getHeight()); mSurfaceTexture.setDefaultBufferSize(mResult.size.getWidth(), mResult.size.getHeight());
if (mOverlaySurfaceTexture != null) { if (mWithOverlay) {
mOverlaySurfaceTexture.setDefaultBufferSize(mResult.size.getWidth(), mResult.size.getHeight()); mOverlaySurfaceTexture.setDefaultBufferSize(mResult.size.getWidth(), mResult.size.getHeight());
} }
mTransform = new float[16]; mTransform = new float[16];
if (mOverlaySurfaceTexture != null) { if (mWithOverlay) {
mOverlayTransform = new float[16]; mOverlayTransform = new float[16];
} }
} }
@ -131,7 +132,7 @@ class SnapshotPictureRecorder extends PictureRecorder {
mSurfaceTexture.updateTexImage(); mSurfaceTexture.updateTexImage();
mSurfaceTexture.getTransformMatrix(mTransform); mSurfaceTexture.getTransformMatrix(mTransform);
Surface drawOnto = new Surface(mOverlaySurfaceTexture); Surface drawOnto = new Surface(mOverlaySurfaceTexture);
if (mOverlaySurfaceTexture != null) { if (mWithOverlay) {
for (SurfaceDrawer surfaceDrawer : mSurfaceDrawerList) { for (SurfaceDrawer surfaceDrawer : mSurfaceDrawerList) {
surfaceDrawer.drawOnSurface(drawOnto); surfaceDrawer.drawOnSurface(drawOnto);
} }
@ -194,7 +195,7 @@ class SnapshotPictureRecorder extends PictureRecorder {
// Future note: passing scale values to the viewport? // Future note: passing scale values to the viewport?
// They are simply realScaleX and realScaleY. // They are simply realScaleX and realScaleY.
viewport.drawFrame(mTextureId, mTransform); viewport.drawFrame(mTextureId, mTransform);
if (mOverlayTransform != null) { if (mWithOverlay) {
viewport.drawFrame(mOverlayTextureId, mOverlayTransform); viewport.drawFrame(mOverlayTextureId, mOverlayTransform);
} }
// don't - surface.swapBuffers(); // don't - surface.swapBuffers();

@ -136,9 +136,12 @@ class SnapshotVideoRecorder extends VideoRecorder implements GlCameraPreview.Ren
mOverlaySurfaceTexture.updateTexImage(); mOverlaySurfaceTexture.updateTexImage();
mOverlaySurfaceTexture.getTransformMatrix(textureFrame.overlayTransform); mOverlaySurfaceTexture.getTransformMatrix(textureFrame.overlayTransform);
} }
// Sometimes when the video ends an Exception is thrown saying that nofify was called on
// a null object. This might be highlighting a bigger problem, but checking for null /* TODO
// fixes the Exception. * Sometimes when the video ends an Exception is thrown saying that notify was called on
* a null object. This might be highlighting a bigger problem, but checking for null
* fixes the Exception.
*/
if (mEncoderEngine != null) { if (mEncoderEngine != null) {
mEncoderEngine.notify(TextureMediaEncoder.FRAME_EVENT, textureFrame); mEncoderEngine.notify(TextureMediaEncoder.FRAME_EVENT, textureFrame);
} }

@ -2,6 +2,6 @@ package com.otaliastudios.cameraview;
import android.view.Surface; import android.view.Surface;
public interface SurfaceDrawer { interface SurfaceDrawer {
void drawOnSurface(Surface surface); void drawOnSurface(Surface surface);
} }

@ -124,12 +124,6 @@
<attr name="cameraExperimental" format="boolean" /> <attr name="cameraExperimental" format="boolean" />
<attr name="cameraDisableOverlayFor" format="enum">
<enum name="none" value="0" />
<enum name="picture" value="1" />
<enum name="video" value="2" />
</attr>
</declare-styleable> </declare-styleable>
<declare-styleable name="CameraView_Layout"> <declare-styleable name="CameraView_Layout">

@ -185,13 +185,11 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
switch (camera.toggleFacing()) { switch (camera.toggleFacing()) {
case BACK: case BACK:
watermarkTitle.setText("Back facing"); watermarkTitle.setText("Back facing");
camera.invalidateOverlay();
message("Switched to back camera!", false); message("Switched to back camera!", false);
break; break;
case FRONT: case FRONT:
watermarkTitle.setText("Front facing"); watermarkTitle.setText("Front facing");
camera.invalidateOverlay();
message("Switched to front camera!", false); message("Switched to front camera!", false);
break; break;
} }

@ -26,8 +26,7 @@
app:cameraGesturePinch="zoom" app:cameraGesturePinch="zoom"
app:cameraGestureScrollHorizontal="exposureCorrection" app:cameraGestureScrollHorizontal="exposureCorrection"
app:cameraGestureScrollVertical="none" app:cameraGestureScrollVertical="none"
app:cameraMode="picture" app:cameraMode="picture">
app:cameraDisableOverlayFor="none">
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"

Loading…
Cancel
Save