Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Feb 6, 2019
1 parent e6a97be commit f906d5c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 48 deletions.
17 changes: 10 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ dependencies {
implementation 'me.angrybyte.picker:picker:1.3.1'
implementation 'com.github.stfalcon:frescoimageviewer:0.5.0'
implementation 'com.facebook.fresco:fresco:1.10.0'
// implementation 'com.github.derlio.waveform:library:1.0.3@aar'

implementation 'com.github.derlio:audio-waveform:v1.0.1'
implementation 'org.firezenk:audiowaves:1.1@aar'
implementation 'com.maxproj.simplewaveform:app:1.0.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.3'
implementation('com.mikepenz:aboutlibraries:6.1.1@aar') {
transitive = true
}
implementation 'com.asksira.android:cameraviewplus:0.9.5'

implementation 'com.github.halilozercan:BetterVideoPlayer:1.1.0'
implementation 'io.github.silvaren:easyrs:0.5.3'
implementation 'org.jcodec:jcodec:0.2.3'
Expand All @@ -171,13 +171,16 @@ dependencies {
implementation "android.arch.lifecycle:extensions:1.1.1"

testImplementation "junit:junit:4.12"
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:core:1.0.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:core:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation "android.arch.persistence.room:testing:1.1.1"

// android-job
implementation 'com.evernote:android-job:1.2.6'

// new camera view: https://github.com/natario1/CameraView
implementation 'com.otaliastudios:cameraview:2.0.0-beta02'
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import android.util.Log;
import android.view.Surface;

import com.google.android.cameraview.CameraView;
import com.otaliastudios.cameraview.CameraView;
import com.otaliastudios.cameraview.Facing;
import com.otaliastudios.cameraview.Frame;
import com.otaliastudios.cameraview.FrameProcessor;
import com.otaliastudios.cameraview.Size;

import org.havenapp.main.PreferenceManager;
import org.havenapp.main.Utils;
Expand All @@ -46,6 +50,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import androidx.annotation.NonNull;
import androidx.renderscript.RenderScript;

import io.github.silvaren.easyrs.tools.Nv21Image;
Expand Down Expand Up @@ -202,28 +207,37 @@ public void addListener(MotionDetector.MotionListener listener) {
* (preferred is 640x480)
* in order to minimize CPU usage
*/
public synchronized void startCamera() {
public void startCamera() {


updateCamera();

cameraView.start();
cameraView.open();

cameraView.setOnFrameListener((data, width, height, rotationDegrees) -> {
cameraView.addFrameProcessor(new FrameProcessor() {
@Override
public void process(@NonNull Frame frame) {

long now = System.currentTimeMillis();
if (now < CameraViewHolder.this.lastTimestamp + PREVIEW_INTERVAL)
return;
long now = System.currentTimeMillis();
if (now < CameraViewHolder.this.lastTimestamp + PREVIEW_INTERVAL)
return;

CameraViewHolder.this.lastTimestamp = now;
CameraViewHolder.this.lastTimestamp = now;

if (!doingVideoProcessing) {
if (frame.getData() != null && frame.getSize() != null) {

Log.i("CameraViewHolder", "Processing new image");
byte[] data = frame.getData();
Size size = frame.getSize();
int width = size.getWidth();
int height = size.getHeight();
int rot = getCorrectCameraOrientation(cameraView.getFacing(),frame.getRotation());

mDecodeThreadPool.execute(() -> processNewFrame(data, width, height, rotationDegrees));
} else {
mEncodeVideoThreadPool.execute(() -> recordNewFrame(data, width, height, rotationDegrees));
if (!doingVideoProcessing) {
mDecodeThreadPool.execute(() -> processNewFrame(data, width, height, rot));
} else {
mEncodeVideoThreadPool.execute(() -> recordNewFrame(data, width, height, rot));
}
}
}
});

Expand All @@ -234,12 +248,10 @@ public void updateCamera ()
{
switch (prefs.getCamera()) {
case PreferenceManager.FRONT:
if (cameraView.getFacing() != CameraView.FACING_FRONT)
cameraView.setFacing(CameraView.FACING_FRONT);
cameraView.setFacing(Facing.FRONT);
break;
case PreferenceManager.BACK:
if (cameraView.getFacing() != CameraView.FACING_BACK)
cameraView.setFacing(CameraView.FACING_BACK);
cameraView.setFacing(Facing.BACK);
break;
default:
// camera = null;
Expand Down Expand Up @@ -321,8 +333,8 @@ private synchronized void processNewFrame (byte[] data, int width, int height, i
data,
width,
height,
cameraView.getDefaultOrientation(),
cameraView.getFacing());
rotationDegrees,
cameraView.getFacing()==Facing.FRONT);

lastPic = data;

Expand All @@ -349,12 +361,12 @@ private synchronized boolean recordVideo() {

mtxVideoRotate = new Matrix();

if (cameraView.getFacing() == CameraView.FACING_FRONT) {
mtxVideoRotate.postRotate(-cameraView.getDefaultOrientation());
if (cameraView.getFacing() == Facing.FRONT) {
mtxVideoRotate.postRotate(-cameraView.getRotation());
mtxVideoRotate.postScale(-1, 1, cameraView.getWidth() / 2, cameraView.getHeight() / 2);
}
else
mtxVideoRotate.postRotate(cameraView.getDefaultOrientation());
mtxVideoRotate.postRotate(cameraView.getRotation());

doingVideoProcessing = true;

Expand All @@ -374,13 +386,10 @@ private synchronized boolean recordVideo() {
public synchronized void stopCamera ()
{
if (cameraView != null) {
cameraView.stop();
cameraView.close();
}
}

public int getCameraFacing() {
return cameraView.getFacing();
}

public void destroy ()
{
Expand All @@ -391,7 +400,7 @@ public void destroy ()
stopCamera();
}

public int getCorrectCameraOrientation(int facing, int orientation) {
public int getCorrectCameraOrientation(Facing facing, int orientation) {

int rotation = context.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
Expand All @@ -416,7 +425,7 @@ public int getCorrectCameraOrientation(int facing, int orientation) {
}

int result;
if(facing == CameraView.FACING_FRONT){
if(facing == Facing.FRONT){
result = (orientation + degrees) % 360;
result = (360 - result) % 360;
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.graphics.Matrix;
import android.os.Handler;

import com.google.android.cameraview.CameraView;

import org.havenapp.main.sensors.media.ImageCodec;

Expand Down Expand Up @@ -84,7 +83,7 @@ public void detect(byte[] rawOldPic,
int width,
int height,
int rotationDegrees,
int cameraFacing) {
boolean facingFront) {

int[] newPicLuma = ImageCodec.N21toLuma(rawNewPic, width, height);
if (rawOldPic != null) {
Expand Down Expand Up @@ -118,7 +117,7 @@ public void detect(byte[] rawOldPic,

Matrix mtx = new Matrix();

if (cameraFacing == CameraView.FACING_FRONT) {
if (facingFront) {
mtx.postRotate(-rotationDegrees);
mtx.postScale(-1, 1, width / 2, height / 2);
}
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/org/havenapp/main/ui/CameraFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.cameraview.CameraView;
import com.otaliastudios.cameraview.CameraView;

import org.havenapp.main.PreferenceManager;
import org.havenapp.main.R;
Expand Down Expand Up @@ -84,13 +84,6 @@ public void stopCamera ()
}
}

/**
public void resetCamera ()
{
stopCamera();
initCamera();
}**/

public void initCamera ()
{

Expand Down
25 changes: 23 additions & 2 deletions src/main/res/layout/camera_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:foreground="@color/translucentOverlay25">

<com.google.android.cameraview.CameraView
<!--
<com.google.android.cameraview.CameraView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -18,7 +19,27 @@
app:flash="off"
app:maximumWidth="1080"
app:maximumPreviewWidth="1080"
app:useHighResPicture="false"/>
app:useHighResPicture="false"/>-->

<!-- Camera -->
<com.otaliastudios.cameraview.CameraView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:keepScreenOn="true"
app:cameraExperimental="true"
app:cameraPlaySounds="false"
app:cameraGrid="off"
app:cameraFlash="off"
app:cameraAudio="on"
app:cameraGestureTap="none"
app:cameraGestureLongTap="none"
app:cameraGesturePinch="none"
app:cameraGestureScrollHorizontal="none"
app:cameraGestureScrollVertical="none"
app:cameraMode="picture" />

<ImageView
android:id="@+id/new_image"
Expand Down

0 comments on commit f906d5c

Please sign in to comment.