diff options
author | Shashi Shekhar <shashishekhar@google.com> | 2015-02-24 18:10:07 -0800 |
---|---|---|
committer | Shashi Shekhar <shashishekhar@google.com> | 2015-03-06 11:55:03 -0800 |
commit | 4361352633d1e106c1574c02ddd27c8891c5ee78 (patch) | |
tree | f9c8d17fd25052ccfc99beb10a8080ecb4427f63 | |
parent | e727428fb48a0df77a42eca417dec8749397d407 (diff) | |
download | android_packages_apps_Camera2-4361352633d1e106c1574c02ddd27c8891c5ee78.tar.gz android_packages_apps_Camera2-4361352633d1e106c1574c02ddd27c8891c5ee78.tar.bz2 android_packages_apps_Camera2-4361352633d1e106c1574c02ddd27c8891c5ee78.zip |
Change interface of BurstMediaItem to provide filepath.
- Instead of passing a byte array, use a file path for the burst media
item.
- Change the save operation in Stack saver to simply rename the image.
- The burst controller is now responsible for managing captured images and
implementations should free the captured images as soon as possible.
Change-Id: I6762972c68865d6ab15bd6fa20b60fb275f103f1
-rw-r--r-- | src/com/android/camera/Storage.java | 27 | ||||
-rw-r--r-- | src/com/android/camera/burst/BurstCaptureCommand.java | 7 | ||||
-rw-r--r-- | src/com/android/camera/burst/BurstController.java | 17 | ||||
-rw-r--r-- | src/com/android/camera/burst/BurstFacadeImpl.java | 3 | ||||
-rw-r--r-- | src/com/android/camera/burst/BurstMediaItem.java | 9 | ||||
-rw-r--r-- | src/com/android/camera/burst/BurstResultsSaver.java | 15 | ||||
-rw-r--r-- | src/com/android/camera/session/StackSaver.java | 10 | ||||
-rw-r--r-- | src/com/android/camera/session/StackSaverImpl.java | 34 | ||||
-rw-r--r-- | src_pd/com/android/camera/burst/BurstControllerImpl.java | 4 |
9 files changed, 70 insertions, 56 deletions
diff --git a/src/com/android/camera/Storage.java b/src/com/android/camera/Storage.java index 04ce734b4..f33993e45 100644 --- a/src/com/android/camera/Storage.java +++ b/src/com/android/camera/Storage.java @@ -317,6 +317,33 @@ public class Storage { } /** + * Renames a file. + * + * <p/> + * Can only be used for regular files, not directories. + * + * @param inputPath the original path of the file + * @param newFilePath the new path of the file + * @return false if rename was not successful + */ + public static boolean renameFile(File inputPath, File newFilePath) { + if (newFilePath.exists()) { + Log.e(TAG, "File path already exists: " + newFilePath.getAbsolutePath()); + return false; + } + if (inputPath.isDirectory()) { + Log.e(TAG, "Input path is directory: " + inputPath.getAbsolutePath()); + return false; + } + if (!createDirectoryIfNeeded(newFilePath.getAbsolutePath())) { + Log.e(TAG, "Failed to create parent directory for file: " + + newFilePath.getAbsolutePath()); + return false; + } + return inputPath.renameTo(newFilePath); + } + + /** * Writes the data to a file. * * @param path The path to the target file. diff --git a/src/com/android/camera/burst/BurstCaptureCommand.java b/src/com/android/camera/burst/BurstCaptureCommand.java index 91da26e00..1bf417893 100644 --- a/src/com/android/camera/burst/BurstCaptureCommand.java +++ b/src/com/android/camera/burst/BurstCaptureCommand.java @@ -160,11 +160,8 @@ public class BurstCaptureCommand implements CameraCommand { } } } finally { - // Make sure the images are closed after the callback. - try (Lifetime capturedImagesLifetime = new Lifetime()) { - for (ImageProxy image : capturedImages) { - capturedImagesLifetime.add(image); - } + try { + // Note: BurstController will release images after use mBurstController.processBurstResults(capturedImages); } finally { // Switch back to the old request. diff --git a/src/com/android/camera/burst/BurstController.java b/src/com/android/camera/burst/BurstController.java index da89d4c0e..9661cf68b 100644 --- a/src/com/android/camera/burst/BurstController.java +++ b/src/com/android/camera/burst/BurstController.java @@ -17,6 +17,7 @@ package com.android.camera.burst; import android.graphics.SurfaceTexture; import com.android.camera.one.v2.camera2proxy.ImageProxy; +import com.android.camera.session.CaptureSession; import java.util.List; @@ -32,9 +33,9 @@ import java.util.List; * processing on the results. * <p/> * Camera initializes the burst module by calling {@link #startBurst(SurfaceTexture, - * ImageStreamProperties, BurstResultsListener)}. The returned eviction strategy - * is used by the internal camera buffer to decide which frames to keep and - * which to reject. + * ImageStreamProperties, BurstResultsListener, CaptureSession)}. The returned + * eviction strategy is used by the internal camera buffer to decide which + * frames to keep and which to reject. * <p/> * Once burst finishes, camera calls the {@link #processBurstResults(List)} to * let the burst module retrieve burst results from the internal buffer. Once @@ -94,21 +95,21 @@ interface BurstController { * This surface should not be attached to any GL context. * @param imageStreamProperties the properties of the low-res image stream. * @param burstResultsListener the listener for burst results. + * @param captureSession the capture session associated with the burst. * @return the configuration of burst that can be used to control the * ongoing burst. */ public EvictionHandler startBurst(SurfaceTexture surfaceTexture, ImageStreamProperties imageStreamProperties, - BurstResultsListener burstResultsListener); + BurstResultsListener burstResultsListener, + CaptureSession captureSession); /** * Stops the burst. * <p/> * - * @param capturedImages list of images captured from the burst. All images - * are closed after this call completes. If implementations need - * to access images after this call they need to make a copy of - * images before returning. + * @param capturedImages list of images captured from the burst. Implementations should + * close the images as soon as possible. */ public void processBurstResults(List<ImageProxy> capturedImages); } diff --git a/src/com/android/camera/burst/BurstFacadeImpl.java b/src/com/android/camera/burst/BurstFacadeImpl.java index 253d50d9d..83f0ba6bd 100644 --- a/src/com/android/camera/burst/BurstFacadeImpl.java +++ b/src/com/android/camera/burst/BurstFacadeImpl.java @@ -153,7 +153,8 @@ class BurstFacadeImpl implements BurstFacade { mBurstController.startBurst( mSurfaceTextureContainer.get().getSurfaceTexture(), imageStreamProperties, - mBurstResultsListener); + mBurstResultsListener, + captureSession); // Start burst. mBurstTaker.get().startBurst(evictionHandler, mBurstController); diff --git a/src/com/android/camera/burst/BurstMediaItem.java b/src/com/android/camera/burst/BurstMediaItem.java index dce4df3db..bd7bfade9 100644 --- a/src/com/android/camera/burst/BurstMediaItem.java +++ b/src/com/android/camera/burst/BurstMediaItem.java @@ -14,6 +14,8 @@ package com.android.camera.burst; +import java.io.File; + /** * Represents a media item generated by a burst. */ @@ -40,12 +42,11 @@ public interface BurstMediaItem { public long getTimestamp(); /** - * Gets the raw data of the media. + * Gets the path to the media. * - * @return raw data of the media + * @return the path to media file. */ - // TODO: Fix this and perhaps use a URI here for saved artifact. - public byte[] getData(); + public File getFilePath(); /** * Gets the mime type of the media. diff --git a/src/com/android/camera/burst/BurstResultsSaver.java b/src/com/android/camera/burst/BurstResultsSaver.java index 104931700..0a5a97c63 100644 --- a/src/com/android/camera/burst/BurstResultsSaver.java +++ b/src/com/android/camera/burst/BurstResultsSaver.java @@ -19,16 +19,13 @@ package com.android.camera.burst; import android.os.AsyncTask; import android.text.TextUtils; -import com.android.camera.data.FilmstripItemData; import com.android.camera.debug.Log; import com.android.camera.debug.Log.Tag; -import com.android.camera.exif.ExifInterface; import com.android.camera.session.StackSaver; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.TimeZone; import java.util.concurrent.TimeUnit; class BurstResultsSaver { @@ -42,7 +39,6 @@ class BurstResultsSaver { * timestamp */ private static final String MEDIA_ITEM_FILENAME_FORMAT_STRING = "Burst_%s_%d_%d_%d"; - private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("UTC"); /** * Generates sequential timestamp with 1 second difference. @@ -155,21 +151,12 @@ class BurstResultsSaver { final String title = String.format(MEDIA_ITEM_FILENAME_FORMAT_STRING, artifactType, artifactIndex, index, mediaItem.getTimestamp()); String mimeType = mediaItem.getMimeType(); - ExifInterface exif = null; - if (FilmstripItemData.MIME_TYPE_JPEG.equals(mimeType)) { - exif = new ExifInterface(); - exif.addDateTimeStampTag( - ExifInterface.TAG_DATE_TIME, - timestamp, - UTC_TIMEZONE); - } - stackSaver.saveStackedImage(mediaItem.getData(), + stackSaver.saveStackedImage(mediaItem.getFilePath(), title, mediaItem.getWidth(), mediaItem.getHeight(), 0, // Artifacts returned from burst have upright orientation. - exif, timestamp, mimeType); } diff --git a/src/com/android/camera/session/StackSaver.java b/src/com/android/camera/session/StackSaver.java index 17c3f3821..4f51b6d21 100644 --- a/src/com/android/camera/session/StackSaver.java +++ b/src/com/android/camera/session/StackSaver.java @@ -17,7 +17,8 @@ package com.android.camera.session; import android.net.Uri; -import com.android.camera.exif.ExifInterface; + +import java.io.File; /** * Used to store images that belong to the same stack. @@ -27,17 +28,16 @@ public interface StackSaver { /** * Save a single image from a stack/burst. * - * @param data the bytes to write to disk + * @param inputImagePath the input image for the image. * @param title the title of this image, without the file extension * @param width the width of the image in pixels * @param height the height of the image in pixels * @param imageOrientation the image orientation in degrees - * @param exif the exif data for the image * @param captureTimeEpoch the capture time in millis since epoch * @param mimeType the mime type of the image * @return The Uri of the saved image, or null, of the image could not be * saved. */ - public Uri saveStackedImage(byte[] data, String title, int width, int height, - int imageOrientation, ExifInterface exif, long captureTimeEpoch, String mimeType); + public Uri saveStackedImage(File inputImagePath, String title, int width, int height, + int imageOrientation, long captureTimeEpoch, String mimeType); } diff --git a/src/com/android/camera/session/StackSaverImpl.java b/src/com/android/camera/session/StackSaverImpl.java index 69f912a05..f5b196863 100644 --- a/src/com/android/camera/session/StackSaverImpl.java +++ b/src/com/android/camera/session/StackSaverImpl.java @@ -22,10 +22,8 @@ import android.net.Uri; import com.android.camera.Storage; import com.android.camera.debug.Log; -import com.android.camera.exif.ExifInterface; import java.io.File; -import java.io.IOException; /** * Default implementation of the {@link StackSaver} interface. It creates a @@ -53,33 +51,33 @@ public class StackSaverImpl implements StackSaver { * store. TODO: Replace with a media storage storer that can be * mocked out in tests. */ - public StackSaverImpl(File stackDirectory, Location gpsLocation, ContentResolver contentResolver) { + public StackSaverImpl(File stackDirectory, Location gpsLocation, + ContentResolver contentResolver) { mStackDirectory = stackDirectory; mGpsLocation = gpsLocation; mContentResolver = contentResolver; } @Override - public Uri saveStackedImage(byte[] data, String title, int width, int height, - int imageOrientation, ExifInterface exif, long captureTimeEpoch, String mimeType) { - if (exif != null) { - exif.setTag(exif.buildTag(ExifInterface.TAG_ORIENTATION, imageOrientation)); - } - + public Uri saveStackedImage(File inputImagePath, String title, int width, int height, + int imageOrientation, long captureTimeEpoch, String mimeType) { String filePath = Storage.generateFilepath(mStackDirectory.getAbsolutePath(), title, mimeType); Log.d(TAG, "Saving using stack image saver: " + filePath); + File outputImagePath = new File(filePath); - long fileLength = 0; - try { - fileLength = Storage.writeFile(filePath, data, exif); - } catch (IOException e) { - e.printStackTrace(); - } - if (fileLength >= 0) { - return Storage.addImageToMediaStore(mContentResolver, title, captureTimeEpoch, - mGpsLocation, imageOrientation, fileLength, filePath, width, height, mimeType); + if (Storage.renameFile(inputImagePath, outputImagePath)) { + long fileLength = outputImagePath.length(); + if (fileLength > 0) { + return Storage.addImageToMediaStore(mContentResolver, title, captureTimeEpoch, + mGpsLocation, imageOrientation, fileLength, filePath, width, height, + mimeType); + } } + + Log.e(TAG, String.format("Unable to rename file from %s to %s.", + inputImagePath.getPath(), + filePath)); return null; } } diff --git a/src_pd/com/android/camera/burst/BurstControllerImpl.java b/src_pd/com/android/camera/burst/BurstControllerImpl.java index 6aad961a9..2c1d0a696 100644 --- a/src_pd/com/android/camera/burst/BurstControllerImpl.java +++ b/src_pd/com/android/camera/burst/BurstControllerImpl.java @@ -22,6 +22,7 @@ import com.android.camera.burst.BurstResultsListener; import com.android.camera.burst.EvictionHandler; import com.android.camera.burst.BurstController.ImageStreamProperties; import com.android.camera.one.v2.camera2proxy.ImageProxy; +import com.android.camera.session.CaptureSession; import java.util.List; @@ -41,7 +42,8 @@ class BurstControllerImpl implements BurstController { @Override public EvictionHandler startBurst(SurfaceTexture surfaceTexture, ImageStreamProperties imageStreamProperties, - BurstResultsListener resultsListener) { + BurstResultsListener resultsListener, + CaptureSession captureSession) { return null; } |