1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera.one.v2.imagesaver;
18 
19 import com.android.camera.app.OrientationManager;
20 import com.android.camera.async.SafeCloseable;
21 import com.android.camera.one.OneCamera;
22 import com.android.camera.one.v2.camera2proxy.ImageProxy;
23 import com.android.camera.one.v2.camera2proxy.TotalCaptureResultProxy;
24 import com.android.camera.session.CaptureSession;
25 import com.google.common.util.concurrent.ListenableFuture;
26 
27 import javax.annotation.ParametersAreNonnullByDefault;
28 import javax.annotation.concurrent.NotThreadSafe;
29 import javax.annotation.concurrent.ThreadSafe;
30 
31 /**
32  * An ImageSaver represents a single transaction which may involve processing
33  * one or more full-size and thumbnail images of varying formats resulting from
34  * a burst.
35  * <p>
36  * Methods will be called on the same thread according to the following state
37  * machine:<br>
38  * (addThumbnail | addFullSizeImage)* close
39  * <p>
40  * ImageSaver instances will never be reused after close.
41  * <p>
42  * ImageSaver does not have to be thread-safe because instances are confined to
43  * the thread they are created on.
44  */
45 @ParametersAreNonnullByDefault
46 @NotThreadSafe
47 public interface ImageSaver extends SafeCloseable {
48     /**
49      * Creates ImageSaver instances.
50      * <p>
51      * The same builder may be used simultaneously on multiple threads, so it
52      * must be thread-safe. However, ImageSaver instances are confined to the
53      * thread they are created on, so they do not need to be thread-safe.
54      */
55     @ThreadSafe
56     public interface Builder {
57         /**
58          * Creates a new ImageSaver which will be used to process and save a
59          * single set of images.
60          */
build( OneCamera.PictureSaverCallback pictureSaverCallback, OrientationManager.DeviceOrientation orientation, CaptureSession session)61         public ImageSaver build(
62                 OneCamera.PictureSaverCallback pictureSaverCallback,
63                 OrientationManager.DeviceOrientation orientation,
64                 CaptureSession session);
65     }
66 
67     /**
68      * Adds a thumbnail image to be processed.
69      * <p>
70      * Implementations must eventually close the image and must tolerate
71      * duplicate and out-of-order images.
72      */
addThumbnail(ImageProxy imageProxy)73     public void addThumbnail(ImageProxy imageProxy);
74 
75     /**
76      * Adds a full-size image to be processed along with a future to its
77      * metadata. Note that the metadata future may be cancelled or result in an
78      * exception if the camera system is being closed or the hardware reports an
79      * error.
80      * <p>
81      * Implementations must eventually close the image and must tolerate
82      * duplicate and out-of-order images.
83      */
addFullSizeImage(ImageProxy imageProxy, ListenableFuture<TotalCaptureResultProxy> metadata)84     public void addFullSizeImage(ImageProxy imageProxy, ListenableFuture<TotalCaptureResultProxy>
85             metadata);
86 
87     /**
88      * Indicates that no more images will be added.
89      */
close()90     public void close();
91 }
92