FileDocCategorySizeDatePackage
RequestQueue.javaAPI DocAndroid 5.1 API5780Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.legacy

RequestQueue

public class RequestQueue extends Object
A queue of bursts of requests.

This queue maintains the count of frames that have been produced, and is thread safe.

Fields Summary
private static final String
TAG
private static final long
INVALID_FRAME
private BurstHolder
mRepeatingRequest
private final ArrayDeque
mRequestQueue
private long
mCurrentFrameNumber
private long
mCurrentRepeatingFrameNumber
private int
mCurrentRequestId
private final List
mJpegSurfaceIds
Constructors Summary
public RequestQueue(List jpegSurfaceIds)


       
        mJpegSurfaceIds = jpegSurfaceIds;
    
Methods Summary
private longcalculateLastFrame(int requestId)

        long total = mCurrentFrameNumber;
        for (BurstHolder b : mRequestQueue) {
            total += b.getNumberOfRequests();
            if (b.getRequestId() == requestId) {
                return total - 1;
            }
        }
        throw new IllegalStateException(
                "At least one request must be in the queue to calculate frame number");
    
public synchronized android.util.PairgetNext()
Return and remove the next burst on the queue.

If a repeating burst is returned, it will not be removed.

return
a pair containing the next burst and the current frame number, or null if none exist.

        BurstHolder next = mRequestQueue.poll();
        if (next == null && mRepeatingRequest != null) {
            next = mRepeatingRequest;
            mCurrentRepeatingFrameNumber = mCurrentFrameNumber +
                    next.getNumberOfRequests();
        }

        if (next == null) {
            return null;
        }

        Pair<BurstHolder, Long> ret =  new Pair<BurstHolder, Long>(next, mCurrentFrameNumber);
        mCurrentFrameNumber += next.getNumberOfRequests();
        return ret;
    
public synchronized longstopRepeating(int requestId)
Cancel a repeating request.

param
requestId the id of the repeating request to cancel.
return
the last frame to be returned from the HAL for the given repeating request, or {@code INVALID_FRAME} if none exists.

        long ret = INVALID_FRAME;
        if (mRepeatingRequest != null && mRepeatingRequest.getRequestId() == requestId) {
            mRepeatingRequest = null;
            ret = (mCurrentRepeatingFrameNumber == INVALID_FRAME) ? INVALID_FRAME :
                    mCurrentRepeatingFrameNumber - 1;
            mCurrentRepeatingFrameNumber = INVALID_FRAME;
            Log.i(TAG, "Repeating capture request cancelled.");
        } else {
            Log.e(TAG, "cancel failed: no repeating request exists for request id: " + requestId);
        }
        return ret;
    
public synchronized longstopRepeating()
Cancel a repeating request.

return
the last frame to be returned from the HAL for the given repeating request, or {@code INVALID_FRAME} if none exists.

        if (mRepeatingRequest == null) {
            Log.e(TAG, "cancel failed: no repeating request exists.");
            return INVALID_FRAME;
        }
        return stopRepeating(mRepeatingRequest.getRequestId());
    
public synchronized intsubmit(java.util.List requests, boolean repeating, android.hardware.camera2.utils.LongParcelable frameNumber)
Add a the given burst to the queue.

If the burst is repeating, replace the current repeating burst.

param
requests the burst of requests to add to the queue.
param
repeating true if the burst is repeating.
param
frameNumber an output argument that contains either the frame number of the last frame that will be returned for this request, or the frame number of the last frame that will be returned for the current repeating request if this burst is set to be repeating.
return
the request id.

        int requestId = mCurrentRequestId++;
        BurstHolder burst = new BurstHolder(requestId, repeating, requests, mJpegSurfaceIds);
        long ret = INVALID_FRAME;
        if (burst.isRepeating()) {
            Log.i(TAG, "Repeating capture request set.");
            if (mRepeatingRequest != null) {
                ret = (mCurrentRepeatingFrameNumber == INVALID_FRAME) ? INVALID_FRAME :
                        mCurrentRepeatingFrameNumber - 1;
            }
            mCurrentRepeatingFrameNumber = INVALID_FRAME;
            mRepeatingRequest = burst;
        } else {
            mRequestQueue.offer(burst);
            ret = calculateLastFrame(burst.getRequestId());
        }
        frameNumber.setNumber(ret);
        return requestId;