diff options
author | Dave Sparks <davidsparks@android.com> | 2009-10-13 02:28:54 -0700 |
---|---|---|
committer | Dave Sparks <davidsparks@android.com> | 2009-10-13 02:52:00 -0700 |
commit | a6118c6383c6f5703a576d08586a340fd71d28a4 (patch) | |
tree | f32befe2dc535480d0305fd93cb1f88d5e1e1e21 /core/java/android/hardware | |
parent | 6dc3f4e553d333b9f115a222a9a684bb2aa55b5e (diff) | |
download | frameworks_base-a6118c6383c6f5703a576d08586a340fd71d28a4.zip frameworks_base-a6118c6383c6f5703a576d08586a340fd71d28a4.tar.gz frameworks_base-a6118c6383c6f5703a576d08586a340fd71d28a4.tar.bz2 |
Throttle camera preview frames to the app. Bug 2180302.
With higher frame rates and larger preview frames, we can easily
flood the application with too much data. This patch fakes the
old camera preview mode by doing continuous one-shot frames.
After the previous frame is handled, if the application hasn't
cleared the preview callback, we start another one-shot preview
frame. With this change, the application should never have more
than one preview frame unless it is explicitly saving references
to them.
modified: core/java/android/hardware/Camera.java
Diffstat (limited to 'core/java/android/hardware')
-rw-r--r-- | core/java/android/hardware/Camera.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index 3806fa8..0c1c7ec 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -229,7 +229,9 @@ public class Camera { public final void setPreviewCallback(PreviewCallback cb) { mPreviewCallback = cb; mOneShot = false; - setHasPreviewCallback(cb != null, false); + // Always use one-shot mode. We fake camera preview mode by + // doing one-shot preview continuously. + setHasPreviewCallback(cb != null, true); } /** @@ -280,10 +282,19 @@ public class Camera { case CAMERA_MSG_PREVIEW_FRAME: if (mPreviewCallback != null) { - mPreviewCallback.onPreviewFrame((byte[])msg.obj, mCamera); + PreviewCallback cb = mPreviewCallback; if (mOneShot) { + // Clear the callback variable before the callback + // in case the app calls setPreviewCallback from + // the callback function mPreviewCallback = null; + } else { + // We're faking the camera preview mode to prevent + // the app from being flooded with preview frames. + // Set to oneshot mode again. + setHasPreviewCallback(true, true); } + cb.onPreviewFrame((byte[])msg.obj, mCamera); } return; |