15d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall/*
25d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * Copyright (C) 2014 The Android Open Source Project
35d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall *
45d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * Licensed under the Apache License, Version 2.0 (the "License");
55d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * you may not use this file except in compliance with the License.
65d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * You may obtain a copy of the License at
75d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall *
85d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall *      http://www.apache.org/licenses/LICENSE-2.0
95d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall *
105d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * Unless required by applicable law or agreed to in writing, software
115d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * distributed under the License is distributed on an "AS IS" BASIS,
125d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * See the License for the specific language governing permissions and
145d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall * limitations under the License.
155d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall */
1612f608f3d2089439a108788a1908941eea4277b9Puneet Lall
1712f608f3d2089439a108788a1908941eea4277b9Puneet Lallpackage com.android.camera.one.v2.sharedimagereader.imagedistributor;
1812f608f3d2089439a108788a1908941eea4277b9Puneet Lall
1912f608f3d2089439a108788a1908941eea4277b9Puneet Lallimport com.android.camera.async.BufferQueue;
2012f608f3d2089439a108788a1908941eea4277b9Puneet Lallimport com.android.camera.one.v2.camera2proxy.ImageProxy;
2112f608f3d2089439a108788a1908941eea4277b9Puneet Lallimport com.android.camera.one.v2.core.CaptureStream;
225d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall
231318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lallimport java.util.concurrent.TimeUnit;
241318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lallimport java.util.concurrent.TimeoutException;
251318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall
265d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall/**
2712f608f3d2089439a108788a1908941eea4277b9Puneet Lall * An interface for {@link CaptureStream}s which route images into a
2812f608f3d2089439a108788a1908941eea4277b9Puneet Lall * {@link BufferQueue}.
2912f608f3d2089439a108788a1908941eea4277b9Puneet Lall * <p>
3012f608f3d2089439a108788a1908941eea4277b9Puneet Lall * For example, an implementation of this may be added to a
3112f608f3d2089439a108788a1908941eea4277b9Puneet Lall * {@link com.android.camera.one.v2.core.RequestBuilder} to then get Images
3212f608f3d2089439a108788a1908941eea4277b9Puneet Lall * corresponding to that request as a queue.
331318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall * <p>
341318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall * Note that images always arrive in order. Different implementations may behave
351318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall * differently with respect to how images are dropped. For example, some may act
361318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall * like a ring-buffer and automatically drop the oldest image when a new image
371318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall * arrives. Others may close new images immediately if no capacity is available.
385d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall */
3912f608f3d2089439a108788a1908941eea4277b9Puneet Lallpublic interface ImageStream extends BufferQueue<ImageProxy>, CaptureStream {
401318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    /**
411318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * Closes the ImageStream. After being closed, no more images will be
421318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * available and any images left in the stream are closed.
431318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     */
441318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    @Override
451318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    public void close();
461318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall
471318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    /**
481318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * Blocks, returning the next available image.
491318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *
501318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @return The next available image.
511318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @throws InterruptedException If interrupted while waiting for the next
521318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *             image.
531318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @throws com.android.camera.async.BufferQueue.BufferQueueClosedException
541318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *             If the stream is closed and no more images will be available.
551318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     */
561318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    @Override
571318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    public ImageProxy getNext() throws InterruptedException, BufferQueueClosedException;
581318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall
591318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    /**
601318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * Blocks, returning the next available image.
611318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *
621318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @param timeout The maximum amount of time to wait.
631318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @param unit The unit associated with the timeout.
641318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @return The next available image.
651318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @throws InterruptedException If interrupted while waiting for the next
661318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *             image.
671318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @throws com.android.camera.async.BufferQueue.BufferQueueClosedException
681318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *             If the stream is closed and no more images will be available.
691318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @throws TimeoutException If no new image is made available within the
701318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *             specified time limit.
711318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     */
721318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    @Override
731318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    public ImageProxy getNext(long timeout, TimeUnit unit) throws InterruptedException,
741318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall            TimeoutException,
751318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall            BufferQueueClosedException;
761318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall
771318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    /**
781318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * Immediately returns the next available image without removing it from the
791318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * stream. Note that the ImageStream still owns the image, so the caller
801318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * MUST NOT close it.
811318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *
821318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @return The next available value if one exists, or null if no value
831318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *         exists yet or the stream is closed.
841318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     */
851318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    @Override
861318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    public ImageProxy peekNext();
871318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall
881318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    /**
891318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * Immediately discards the next available image, if one exists.
901318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     */
911318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    @Override
921318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    public void discardNext();
931318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall
941318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    /**
951318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     * @return True if the stream has been closed by either the producer or the
961318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     *         consumer.
971318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall     */
981318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    @Override
991318feb043f89f8309a7d4cf53ccaa7a58939c98Puneet Lall    public boolean isClosed();
1005d4fb6accab3bcbe737d52747c328de5cc092d02Puneet Lall}
101