summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ta Chen <weita@google.com>2011-08-15 10:26:31 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-15 10:26:31 -0700
commit3a73cd704cb7a6caa8267af55d191cceeef94d16 (patch)
tree8ba1219b599ec4d8305a7d28d12f981bf2d0b792
parentd76c995b2387a42ad838daf7c05994203e20aaba (diff)
parent0adf2489520d3a98a56e081aeacb1ab9336a012f (diff)
downloadLegacyCamera-3a73cd704cb7a6caa8267af55d191cceeef94d16.zip
LegacyCamera-3a73cd704cb7a6caa8267af55d191cceeef94d16.tar.gz
LegacyCamera-3a73cd704cb7a6caa8267af55d191cceeef94d16.tar.bz2
Merge "Remove the flag - mUseSurfaceTexture."
-rw-r--r--src/com/android/camera/panorama/MosaicFrameProcessor.java39
-rw-r--r--src/com/android/camera/panorama/PanoramaActivity.java36
2 files changed, 14 insertions, 61 deletions
diff --git a/src/com/android/camera/panorama/MosaicFrameProcessor.java b/src/com/android/camera/panorama/MosaicFrameProcessor.java
index 502d41f..a0f732f 100644
--- a/src/com/android/camera/panorama/MosaicFrameProcessor.java
+++ b/src/com/android/camera/panorama/MosaicFrameProcessor.java
@@ -31,7 +31,7 @@ public class MosaicFrameProcessor {
private static final int Y_COORD_INDEX = 5;
private Mosaic mMosaicer;
- private final byte[][] mFrames = new byte[NUM_FRAMES_IN_BUFFER][]; // Space for N frames
+ private boolean mIsMosaicMemoryAllocated = false;
private final long [] mFrameTimestamp = new long[NUM_FRAMES_IN_BUFFER];
private float mTranslationLastX;
private float mTranslationLastY;
@@ -56,20 +56,18 @@ public class MosaicFrameProcessor {
private int mPreviewWidth;
private int mPreviewHeight;
private int mPreviewBufferSize;
- private boolean mUseSurfaceTexture;
public interface ProgressListener {
public void onProgress(boolean isFinished, float translationRate,
int traversedAngleX, int traversedAngleY);
}
- public MosaicFrameProcessor(int sweepAngle, int previewWidth, int previewHeight, int bufSize, boolean useSurfaceTexture) {
+ public MosaicFrameProcessor(int sweepAngle, int previewWidth, int previewHeight, int bufSize) {
mMosaicer = new Mosaic();
mCompassThreshold = sweepAngle;
mPreviewWidth = previewWidth;
mPreviewHeight = previewHeight;
mPreviewBufferSize = bufSize;
- mUseSurfaceTexture = useSurfaceTexture;
}
public void setProgressListener(ProgressListener listener) {
@@ -77,25 +75,19 @@ public class MosaicFrameProcessor {
}
public void initialize() {
- setupMosaicer(mPreviewWidth, mPreviewHeight, mPreviewBufferSize, mUseSurfaceTexture);
+ setupMosaicer(mPreviewWidth, mPreviewHeight, mPreviewBufferSize);
reset();
}
public void clear() {
+ mIsMosaicMemoryAllocated = false;
mMosaicer.freeMosaicMemory();
-
- for (int i = 0; i < NUM_FRAMES_IN_BUFFER; i++) {
- mFrames[i] = null;
- }
}
- private void setupMosaicer(int previewWidth, int previewHeight, int bufSize, boolean useSurfaceTexture) {
+ private void setupMosaicer(int previewWidth, int previewHeight, int bufSize) {
Log.v(TAG, "setupMosaicer w, h=" + previewWidth + ',' + previewHeight + ',' + bufSize);
mMosaicer.allocateMosaicMemory(previewWidth, previewHeight);
-
- for (int i = 0; i < NUM_FRAMES_IN_BUFFER; i++) {
- mFrames[i] = new byte[bufSize];
- }
+ mIsMosaicMemoryAllocated = true;
mFillIn = 0;
if (mMosaicer != null) {
@@ -125,8 +117,8 @@ public class MosaicFrameProcessor {
// Processes the last filled image frame through the mosaicer and
// updates the UI to show progress.
// When done, processes and displays the final mosaic.
- public void processFrame(byte[] data) {
- if (mFrames[mFillIn] == null) {
+ public void processFrame() {
+ if (!mIsMosaicMemoryAllocated) {
// clear() is called and buffers are cleared, stop computation.
// This can happen when the onPause() is called in the activity, but still some frames
// are not processed yet and thus the callback may be invoked.
@@ -135,10 +127,6 @@ public class MosaicFrameProcessor {
long t1 = System.currentTimeMillis();
mFrameTimestamp[mFillIn] = t1;
- // TODO: Remove the case of byte data copy when SurfaceTexture is ready
- if(!mUseSurfaceTexture)
- System.arraycopy(data, 0, mFrames[mFillIn], 0, data.length);
-
mCurrProcessFrameIdx = mFillIn;
mFillIn = ((mFillIn + 1) % NUM_FRAMES_IN_BUFFER);
@@ -147,8 +135,7 @@ public class MosaicFrameProcessor {
if (mCurrProcessFrameIdx != mLastProcessFrameIdx) {
mLastProcessFrameIdx = mCurrProcessFrameIdx;
- // Access the image data and the timestamp associated with it...
- byte[] currentFrame = mFrames[mCurrProcessFrameIdx];
+ // Access the timestamp associated with it...
long timestamp = mFrameTimestamp[mCurrProcessFrameIdx];
// Keep track of what compass bearing we started at...
@@ -168,7 +155,7 @@ public class MosaicFrameProcessor {
&& mTraversedAngleY < mCompassThreshold) {
// If we are still collecting new frames for the current mosaic,
// process the new frame.
- translateFrame(currentFrame, timestamp);
+ calculateTranslationRate(timestamp);
// Publish progress of the ongoing processing
if (mProgressListener != null) {
@@ -184,13 +171,11 @@ public class MosaicFrameProcessor {
}
}
- public void translateFrame(final byte[] data, long now) {
+ public void calculateTranslationRate(long now) {
float deltaTime = (now - mLastProcessedFrameTimestamp) / 1000.0f;
mLastProcessedFrameTimestamp = now;
- float[] frameData = mUseSurfaceTexture ?
- mMosaicer.setSourceImageFromGPU() :
- mMosaicer.setSourceImage(data);
+ float[] frameData = mMosaicer.setSourceImageFromGPU();
mTotalFrameCount = (int) frameData[FRAME_COUNT_INDEX];
float translationCurrX = frameData[X_COORD_INDEX];
float translationCurrY = frameData[Y_COORD_INDEX];
diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java
index 8276b0e..3fe9b5b 100644
--- a/src/com/android/camera/panorama/PanoramaActivity.java
+++ b/src/com/android/camera/panorama/PanoramaActivity.java
@@ -98,8 +98,6 @@ public class PanoramaActivity extends Activity implements
private long mTimeTaken;
private Handler mMainHandler;
private SurfaceTexture mSurface;
- private boolean mUseSurfaceTexture = true;
-
private boolean mThreadRunning;
@Override
@@ -238,19 +236,6 @@ public class PanoramaActivity extends Activity implements
int orientation = Util.getDisplayOrientation(Util.getDisplayRotation(this),
CameraHolder.instance().getBackCameraId());
mCameraDevice.setDisplayOrientation(orientation);
-
- if(!mUseSurfaceTexture) {
- int bufSize = getPreviewBufSize();
- Log.v(TAG, "BufSize = " + bufSize);
- for (int i = 0; i < 10; i++) {
- try {
- mCameraDevice.addCallbackBuffer(new byte[bufSize]);
- } catch (OutOfMemoryError e) {
- Log.v(TAG, "Buffer allocation failed: buffer " + i);
- break;
- }
- }
- }
}
private boolean switchToOtherMode(int mode) {
@@ -296,7 +281,7 @@ public class PanoramaActivity extends Activity implements
// Wait on the condition variable (will be opened when GPU->CPU transfer is done).
mRealTimeMosaicView.waitUntilPreviewReady();
- mMosaicFrameProcessor.processFrame(null);
+ mMosaicFrameProcessor.processFrame();
}
public synchronized void onFrameAvailable(SurfaceTexture surface) {
@@ -328,19 +313,6 @@ public class PanoramaActivity extends Activity implements
}
});
- if (!mUseSurfaceTexture) {
- // Preview callback used whenever new viewfinder frame is available
- mCameraDevice.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() {
- @Override
- public void onPreviewFrame(final byte[] data, Camera camera) {
- mMosaicFrameProcessor.processFrame(data);
- // The returned buffer needs be added back to callback buffer
- // again.
- camera.addCallbackBuffer(data);
- }
- });
- }
-
mCaptureLayout.setVisibility(View.VISIBLE);
mPreview.setVisibility(View.INVISIBLE); // will be re-used, invisible is better than gone.
mRealTimeMosaicView.setVisibility(View.VISIBLE);
@@ -354,10 +326,6 @@ public class PanoramaActivity extends Activity implements
mMosaicFrameProcessor.setProgressListener(null);
stopPreview();
- if (!mUseSurfaceTexture) {
- mCameraDevice.setPreviewCallbackWithBuffer(null);
- }
-
mSurface.setOnFrameAvailableListener(null);
// TODO: show some dialog for long computation.
@@ -503,7 +471,7 @@ public class PanoramaActivity extends Activity implements
if (mMosaicFrameProcessor == null) {
// Start the activity for the first time.
mMosaicFrameProcessor = new MosaicFrameProcessor(DEFAULT_SWEEP_ANGLE - 5,
- mPreviewWidth, mPreviewHeight, getPreviewBufSize(), mUseSurfaceTexture);
+ mPreviewWidth, mPreviewHeight, getPreviewBufSize());
}
mMosaicFrameProcessor.initialize();
}