summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjianhuac <jianhuac@codeaurora.org>2016-12-19 16:09:46 +0800
committerweijiew <weijiew@codeaurora.org>2016-12-30 18:44:42 +0800
commit6b3797c9ac592dcd1aabb8271d40c5e0dd5f9bb1 (patch)
treed7f80bb028d091a77edc7c31b29c698217e41ffe
parent1fd9901abce1ff4eb09b5aaa3be22e1a0d846ff7 (diff)
downloadandroid_packages_apps_Snap-6b3797c9ac592dcd1aabb8271d40c5e0dd5f9bb1.tar.gz
android_packages_apps_Snap-6b3797c9ac592dcd1aabb8271d40c5e0dd5f9bb1.tar.bz2
android_packages_apps_Snap-6b3797c9ac592dcd1aabb8271d40c5e0dd5f9bb1.zip
SnapdragonCamera:Improve camera app's robustness
We just load RenderScript engine once when initialize CaptureModule and destory it when destory CaptureModule, instead of load-destory engine by muti-thread when open-close camera device. Change-Id: I76f9e5f99061fb1557624ab683c37837ae1414f7
-rw-r--r--src/com/android/camera/CameraActivity.java3
-rw-r--r--src/com/android/camera/CameraModule.java2
-rwxr-xr-xsrc/com/android/camera/CaptureModule.java7
-rw-r--r--src/com/android/camera/PanoCaptureModule.java5
-rw-r--r--src/com/android/camera/PhotoModule.java3
-rw-r--r--src/com/android/camera/VideoModule.java3
-rw-r--r--src/com/android/camera/WideAnglePanoramaModule.java3
-rw-r--r--[-rwxr-xr-x]src/com/android/camera/imageprocessor/FrameProcessor.java41
8 files changed, 38 insertions, 29 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index d3c39793a..cc17fa3f0 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -1858,6 +1858,9 @@ public class CameraActivity extends Activity
if (mAutoTestEnabled) {
unregisterReceiver(mAutoTestReceiver);
}
+ if(mCurrentModule != null){
+ mCurrentModule.onDestroy();
+ }
super.onDestroy();
}
diff --git a/src/com/android/camera/CameraModule.java b/src/com/android/camera/CameraModule.java
index bc44425d1..3396b9d2f 100644
--- a/src/com/android/camera/CameraModule.java
+++ b/src/com/android/camera/CameraModule.java
@@ -39,6 +39,8 @@ public interface CameraModule {
public void onStop();
+ public void onDestroy();
+
public void installIntentFilter();
public void onActivityResult(int requestCode, int resultCode, Intent data);
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 184b03a1d..a025f3514 100755
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -2189,6 +2189,13 @@ public class CaptureModule implements CameraModule, PhotoController,
}
@Override
+ public void onDestroy() {
+ if(mFrameProcessor != null){
+ mFrameProcessor.onDestory();
+ }
+ }
+
+ @Override
public void installIntentFilter() {
}
diff --git a/src/com/android/camera/PanoCaptureModule.java b/src/com/android/camera/PanoCaptureModule.java
index c6045d1c3..f4c7624f0 100644
--- a/src/com/android/camera/PanoCaptureModule.java
+++ b/src/com/android/camera/PanoCaptureModule.java
@@ -458,6 +458,11 @@ public class PanoCaptureModule implements CameraModule, PhotoController {
}
+ @Override
+ public void onDestroy() {
+
+ }
+
public Uri savePanorama(byte[] jpegData, int width, int height, int orientation) {
long timeTaken = System.currentTimeMillis();
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 2d67fa9c0..c1416f7fa 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -2159,6 +2159,9 @@ public class PhotoModule
public void onStop() {}
@Override
+ public void onDestroy() {}
+
+ @Override
public void onCaptureCancelled() {
mActivity.setResultEx(Activity.RESULT_CANCELED, new Intent());
mActivity.finish();
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index e420addcb..e651843be 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -602,6 +602,9 @@ public class VideoModule implements CameraModule,
@Override
public void onStop() {}
+ @Override
+ public void onDestroy() {}
+
private void loadCameraPreferences() {
CameraSettings settings = new CameraSettings(mActivity, mParameters,
mCameraId, CameraHolder.instance().getCameraInfo());
diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java
index 2d4ec1419..0aab8f804 100644
--- a/src/com/android/camera/WideAnglePanoramaModule.java
+++ b/src/com/android/camera/WideAnglePanoramaModule.java
@@ -1225,6 +1225,9 @@ public class WideAnglePanoramaModule
}
@Override
+ public void onDestroy() {}
+
+ @Override
public void installIntentFilter() {
}
diff --git a/src/com/android/camera/imageprocessor/FrameProcessor.java b/src/com/android/camera/imageprocessor/FrameProcessor.java
index 519d77458..b1b415acd 100755..100644
--- a/src/com/android/camera/imageprocessor/FrameProcessor.java
+++ b/src/com/android/camera/imageprocessor/FrameProcessor.java
@@ -92,22 +92,22 @@ public class FrameProcessor {
public static final int LISTENER_TRACKING_FOCUS = 2;
private CaptureModule mModule;
private boolean mIsVideoOn = false;
- private boolean mIsInitialized = false;
public FrameProcessor(Activity activity, CaptureModule module) {
mActivity = activity;
mModule = module;
mPreviewFilters = new ArrayList<ImageFilter>();
mFinalFilters = new ArrayList<ImageFilter>();
+
+ mRs = RenderScript.create(mActivity);
+ mRsYuvToRGB = new ScriptC_YuvToRgb(mRs);
+ mRsRotator = new ScriptC_rotator(mRs);
}
private void init(Size previewDim) {
mIsActive = true;
mSize = previewDim;
synchronized (mAllocationLock) {
- mRs = RenderScript.create(mActivity);
- mRsYuvToRGB = new ScriptC_YuvToRgb(mRs);
- mRsRotator = new ScriptC_rotator(mRs);
mInputImageReader = ImageReader.newInstance(mSize.getWidth(), mSize.getHeight(), ImageFormat.YUV_420_888, 8);
Type.Builder rgbTypeBuilder = new Type.Builder(mRs, Element.RGBA_8888(mRs));
@@ -138,7 +138,6 @@ public class FrameProcessor {
mTask = new ProcessingTask();
mInputImageReader.setOnImageAvailableListener(mTask, mProcessingHandler);
mIsAllocationEverUsed = false;
- mIsInitialized = true;
}
}
@@ -197,13 +196,7 @@ public class FrameProcessor {
}
}
if(isFrameFilterEnabled() || isFrameListnerEnabled()) {
- new Thread() {
- public void run() {
- init(size);
- }
- }.start();
- } else {
- mIsInitialized = true;
+ init(size);
}
}
@@ -224,18 +217,8 @@ public class FrameProcessor {
}
- private void waitForInitialization() {
- while(!mIsInitialized) {
- try {
- Thread.sleep(10);
- } catch(InterruptedException e) {
- }
- }
- }
-
public void onClose() {
mIsActive = false;
- waitForInitialization();
synchronized (mAllocationLock) {
if (mIsAllocationEverUsed) {
if (mInputAllocation != null) {
@@ -251,15 +234,10 @@ public class FrameProcessor {
mVideoOutputAllocation.destroy();
}
}
- if (mRs != null) {
- mRs.destroy();
- }
- mRs = null;
mProcessAllocation = null;
mOutputAllocation = null;
mInputAllocation = null;
mVideoOutputAllocation = null;
- mIsInitialized = false;
}
if (mProcessingThread != null) {
mProcessingThread.quitSafely();
@@ -296,6 +274,13 @@ public class FrameProcessor {
}
}
+ public void onDestory(){
+ if (mRs != null) {
+ mRs.destroy();
+ }
+ mRs = null;
+ }
+
private Surface getReaderSurface() {
synchronized (mAllocationLock) {
if (mInputImageReader == null) {
@@ -339,7 +324,6 @@ public class FrameProcessor {
}
public void setOutputSurface(Surface surface) {
- waitForInitialization();
mSurfaceAsItIs = surface;
if (mFinalFilters.size() != 0) {
mOutputAllocation.setSurface(surface);
@@ -347,7 +331,6 @@ public class FrameProcessor {
}
public void setVideoOutputSurface(Surface surface) {
- waitForInitialization();
if (surface == null) {
synchronized (mAllocationLock) {
if (mVideoOutputAllocation != null) {