/* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.camera2.legacy; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.utils.SubmitInfo; import android.util.Log; import android.util.Pair; import java.util.ArrayDeque; import java.util.List; /** * A queue of bursts of requests. * *
This queue maintains the count of frames that have been produced, and is thread safe.
*/ public class RequestQueue { private static final String TAG = "RequestQueue"; private static final long INVALID_FRAME = -1; private BurstHolder mRepeatingRequest = null; private final ArrayDequeIf 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. */ public synchronized PairIf 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. * @return the submission info, including the new request id, and the last frame number, which * 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. */ public synchronized SubmitInfo submit(CaptureRequest[] requests, boolean repeating) { int requestId = mCurrentRequestId++; BurstHolder burst = new BurstHolder(requestId, repeating, requests, mJpegSurfaceIds); long lastFrame = INVALID_FRAME; if (burst.isRepeating()) { Log.i(TAG, "Repeating capture request set."); if (mRepeatingRequest != null) { lastFrame = (mCurrentRepeatingFrameNumber == INVALID_FRAME) ? INVALID_FRAME : mCurrentRepeatingFrameNumber - 1; } mCurrentRepeatingFrameNumber = INVALID_FRAME; mRepeatingRequest = burst; } else { mRequestQueue.offer(burst); lastFrame = calculateLastFrame(burst.getRequestId()); } SubmitInfo info = new SubmitInfo(requestId, lastFrame); return info; } private long calculateLastFrame(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"); } }