summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/imageprocessor/FrameProcessor.java
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 /src/com/android/camera/imageprocessor/FrameProcessor.java
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
Diffstat (limited to 'src/com/android/camera/imageprocessor/FrameProcessor.java')
-rw-r--r--[-rwxr-xr-x]src/com/android/camera/imageprocessor/FrameProcessor.java41
1 files changed, 12 insertions, 29 deletions
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) {