Skip to content

Commit

Permalink
Implementation on Camera2 API
Browse files Browse the repository at this point in the history
Change-Id: I57e10dca4b6b74460db1e1604c24676825742c24
  • Loading branch information
yaraki committed Jun 13, 2016
1 parent 272b36f commit 6ad510c
Show file tree
Hide file tree
Showing 5 changed files with 834 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.android.cameraview;

import android.graphics.Matrix;
import android.view.TextureView;

import java.util.Set;
Expand Down Expand Up @@ -66,6 +67,8 @@ interface Callback {

void onPictureTaken(byte[] data);

void onTransformUpdated(Matrix matrix);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.cameraview;

import android.graphics.SurfaceTexture;


/**
* Stores information about the {@link SurfaceTexture} showing camera preview.
*/
class SurfaceInfo {

SurfaceTexture surface;
int width;
int height;

void configure(SurfaceTexture s, int w, int h) {
surface = s;
width = w;
height = h;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Camera1 extends CameraViewImpl {

private final Camera.CameraInfo mCameraInfo = new Camera.CameraInfo();

private final PreviewInfo mPreviewInfo = new PreviewInfo();
private final SurfaceInfo mSurfaceInfo = new SurfaceInfo();

private final SizeMap mPreviewSizes = new SizeMap();

Expand All @@ -67,23 +67,11 @@ class Camera1 extends CameraViewImpl {

private int mDisplayOrientation;

private static class PreviewInfo {
SurfaceTexture surface;
int width;
int height;

void configure(SurfaceTexture s, int w, int h) {
surface = s;
width = w;
height = h;
}
}

private final TextureView.SurfaceTextureListener mSurfaceTextureListener
= new TextureView.SurfaceTextureListener() {

private void reconfigurePreview(SurfaceTexture surface, int width, int height) {
mPreviewInfo.configure(surface, width, height);
mSurfaceInfo.configure(surface, width, height);
if (mCamera != null) {
setUpPreview();
adjustCameraParameters();
Expand Down Expand Up @@ -124,7 +112,7 @@ TextureView.SurfaceTextureListener getSurfaceTextureListener() {
void start() {
chooseCamera();
openCamera();
if (mPreviewInfo.surface != null) {
if (mSurfaceInfo.surface != null) {
setUpPreview();
}
mShowingPreview = true;
Expand All @@ -142,7 +130,7 @@ void stop() {

private void setUpPreview() {
try {
mCamera.setPreviewTexture(mPreviewInfo.surface);
mCamera.setPreviewTexture(mSurfaceInfo.surface);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -346,17 +334,17 @@ private void adjustCameraParameters() {

@SuppressWarnings("SuspiciousNameCombination")
private Size chooseOptimalSize(SortedSet<Size> sizes) {
if (mPreviewInfo.width == 0 || mPreviewInfo.height == 0) { // Not yet laid out
if (mSurfaceInfo.width == 0 || mSurfaceInfo.height == 0) { // Not yet laid out
return sizes.first(); // Return the smallest size
}
int desiredWidth;
int desiredHeight;
if (mDisplayOrientation == 90 || mDisplayOrientation == 270) {
desiredWidth = mPreviewInfo.height;
desiredHeight = mPreviewInfo.width;
desiredWidth = mSurfaceInfo.height;
desiredHeight = mSurfaceInfo.width;
} else {
desiredWidth = mPreviewInfo.width;
desiredHeight = mPreviewInfo.height;
desiredWidth = mSurfaceInfo.width;
desiredHeight = mSurfaceInfo.height;
}
Size result = null;
for (Size size : sizes) { // Iterate from small to large
Expand Down
Loading

0 comments on commit 6ad510c

Please sign in to comment.