Modified Android samples

This commit is contained in:
Andrey Kamaev 2011-07-14 13:39:25 +00:00
parent 87ad9b1c3e
commit f97e5f7353
2 changed files with 17 additions and 11 deletions

View File

@ -50,7 +50,7 @@ class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
@Override @Override
protected Bitmap processFrame(byte[] data) protected Bitmap processFrame(byte[] data)
{ {
Log.e("SAMP1", "processFrame begin"); //Log.e("SAMP1", "processFrame begin");
mYuv.put(0, 0, data); mYuv.put(0, 0, data);
@ -83,7 +83,7 @@ class Sample1View extends SampleViewBase implements SurfaceHolder.Callback {
Bitmap bmp = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888); Bitmap bmp = Bitmap.createBitmap(mFrameWidth, mFrameHeight, Bitmap.Config.ARGB_8888);
android.MatToBitmap(mRgba, bmp); android.MatToBitmap(mRgba, bmp);
Log.e("SAMP1", "processFrame end"); //Log.e("SAMP1", "processFrame end");
return bmp; return bmp;
} }

View File

@ -52,15 +52,16 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
} }
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
Log.i("SAMP1", "surfaceCreated");
mCamera = Camera.open(); mCamera = Camera.open();
mCamera.setPreviewCallback( mCamera.setPreviewCallback(
new PreviewCallback() { new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) { public void onPreviewFrame(byte[] data, Camera camera) {
synchronized(SampleViewBase.this) { synchronized(SampleViewBase.this) {
mFrame = data; mFrame = data;
Log.i("SAMP1", "before notify"); //Log.i("SAMP1", "before notify");
SampleViewBase.this.notify(); SampleViewBase.this.notify();
Log.i("SAMP1", "after notify"); //Log.i("SAMP1", "after notify");
} }
} }
} }
@ -69,6 +70,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
} }
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
Log.i("SAMP1", "surfaceDestroyed");
mThreadRun = false; mThreadRun = false;
if(mCamera != null) { if(mCamera != null) {
synchronized(this) { synchronized(this) {
@ -87,22 +89,26 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
Log.i(TAG, "Starting thread"); Log.i(TAG, "Starting thread");
Bitmap bmp = null; Bitmap bmp = null;
while(mThreadRun) { while(mThreadRun) {
Log.i("SAMP1", "before synchronized"); //Log.i("SAMP1", "before synchronized");
synchronized(this) { synchronized(this) {
Log.i("SAMP1", "in synchronized"); //Log.i("SAMP1", "in synchronized");
try { try {
this.wait(); this.wait();
Log.i("SAMP1", "before processFrame"); //Log.i("SAMP1", "before processFrame");
bmp = processFrame(mFrame); bmp = processFrame(mFrame);
Log.i("SAMP1", "after processFrame"); //Log.i("SAMP1", "after processFrame");
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
Canvas canvas = mHolder.lockCanvas(); if (bmp != null){
canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null); Canvas canvas = mHolder.lockCanvas();
mHolder.unlockCanvasAndPost(canvas); if (canvas != null){
canvas.drawBitmap(bmp, (canvas.getWidth()-mFrameWidth)/2, (canvas.getHeight()-mFrameHeight)/2, null);
mHolder.unlockCanvasAndPost(canvas);
}
}
} }
} }
} }