Methods Summary |
---|
public void | failAll()Called to alert the {@link CaptureCollector} all pending captures have failed.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h;
while ((h = mActiveRequests.pollFirst()) != null) {
h.setPreviewFailed();
h.setJpegFailed();
}
mPreviewCaptureQueue.clear();
mPreviewProduceQueue.clear();
mJpegCaptureQueue.clear();
mJpegProduceQueue.clear();
} finally {
lock.unlock();
}
|
public void | failNextJpeg()Called to alert the {@link CaptureCollector} that the next pending jpeg capture has failed.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h1 = mJpegCaptureQueue.peek();
CaptureHolder h2 = mJpegProduceQueue.peek();
// Find the request with the lowest frame number.
CaptureHolder h = (h1 == null) ? h2 :
((h2 == null) ? h1 :
((h1.compareTo(h2) <= 0) ? h1 :
h2));
if (h != null) {
mJpegCaptureQueue.remove(h);
mJpegProduceQueue.remove(h);
mActiveRequests.remove(h);
h.setJpegFailed();
}
} finally {
lock.unlock();
}
|
public void | failNextPreview()Called to alert the {@link CaptureCollector} that the next pending preview capture has failed.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h1 = mPreviewCaptureQueue.peek();
CaptureHolder h2 = mPreviewProduceQueue.peek();
// Find the request with the lowest frame number.
CaptureHolder h = (h1 == null) ? h2 :
((h2 == null) ? h1 :
((h1.compareTo(h2) <= 0) ? h1 :
h2));
if (h != null) {
mPreviewCaptureQueue.remove(h);
mPreviewProduceQueue.remove(h);
mActiveRequests.remove(h);
h.setPreviewFailed();
}
} finally {
lock.unlock();
}
|
public boolean | hasPendingPreviewCaptures()Check if there are any pending capture requests that use the Camera1 API preview output.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
return !mPreviewCaptureQueue.isEmpty();
} finally {
lock.unlock();
}
|
public RequestHolder | jpegCaptured(long timestamp)Called to alert the {@link CaptureCollector} that the jpeg capture has begun.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mJpegCaptureQueue.poll();
if (h == null) {
Log.w(TAG, "jpegCaptured called with no jpeg request on queue!");
return null;
}
h.setJpegTimestamp(timestamp);
return h.mRequest;
} finally {
lock.unlock();
}
|
public android.util.Pair | jpegProduced()Called to alert the {@link CaptureCollector} that the jpeg capture has completed.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mJpegProduceQueue.poll();
if (h == null) {
Log.w(TAG, "jpegProduced called with no jpeg request on queue!");
return null;
}
h.setJpegProduced();
return new Pair<>(h.mRequest, h.mTimestamp);
} finally {
lock.unlock();
}
|
private void | onPreviewCompleted()
mInFlightPreviews--;
if (mInFlightPreviews < 0) {
throw new IllegalStateException(
"More preview captures completed than requests queued.");
}
if (mInFlightPreviews == 0) {
mPreviewsEmpty.signalAll();
}
|
private void | onRequestCompleted(android.hardware.camera2.legacy.CaptureCollector$CaptureHolder capture)
RequestHolder request = capture.mRequest;
mInFlight--;
if (DEBUG) {
Log.d(TAG, "Completed request " + request.getRequestId() +
", " + mInFlight + " requests remain in flight.");
}
if (mInFlight < 0) {
throw new IllegalStateException(
"More captures completed than requests queued.");
}
mCompletedRequests.add(capture);
mActiveRequests.remove(capture);
mNotFull.signalAll();
if (mInFlight == 0) {
mIsEmpty.signalAll();
}
|
public android.util.Pair | previewCaptured(long timestamp)Called to alert the {@link CaptureCollector} that the preview capture has begun.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mPreviewCaptureQueue.poll();
if (h == null) {
if (DEBUG) {
Log.d(TAG, "previewCaptured called with no preview request on queue!");
}
return null;
}
h.setPreviewTimestamp(timestamp);
return new Pair<>(h.mRequest, h.mTimestamp);
} finally {
lock.unlock();
}
|
public RequestHolder | previewProduced()Called to alert the {@link CaptureCollector} that the preview capture has completed.
final ReentrantLock lock = this.mLock;
lock.lock();
try {
CaptureHolder h = mPreviewProduceQueue.poll();
if (h == null) {
Log.w(TAG, "previewProduced called with no preview request on queue!");
return null;
}
h.setPreviewProduced();
return h.mRequest;
} finally {
lock.unlock();
}
|
public boolean | queueRequest(RequestHolder holder, LegacyRequest legacy, long timeout, java.util.concurrent.TimeUnit unit)Queue a new request.
For requests that use the Camera1 API preview output stream, this will block if there are
already {@code maxInFlight} requests in progress (until at least one prior request has
completed). For requests that use the Camera1 API jpeg callbacks, this will block until
all prior requests have been completed to avoid stopping preview for
{@link android.hardware.Camera#takePicture} before prior preview requests have been
completed.
CaptureHolder h = new CaptureHolder(holder, legacy);
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.mLock;
lock.lock();
try {
if (DEBUG) {
Log.d(TAG, "queueRequest for request " + holder.getRequestId() +
" - " + mInFlight + " requests remain in flight.");
}
if (!(h.needsJpeg || h.needsPreview)) {
throw new IllegalStateException("Request must target at least one output surface!");
}
if (h.needsJpeg) {
// Wait for all current requests to finish before queueing jpeg.
while (mInFlight > 0) {
if (nanos <= 0) {
return false;
}
nanos = mIsEmpty.awaitNanos(nanos);
}
mJpegCaptureQueue.add(h);
mJpegProduceQueue.add(h);
}
if (h.needsPreview) {
while (mInFlight >= mMaxInFlight) {
if (nanos <= 0) {
return false;
}
nanos = mNotFull.awaitNanos(nanos);
}
mPreviewCaptureQueue.add(h);
mPreviewProduceQueue.add(h);
mInFlightPreviews++;
}
mActiveRequests.add(h);
mInFlight++;
return true;
} finally {
lock.unlock();
}
|
private boolean | removeRequestIfCompleted(RequestHolder holder, android.util.MutableLong timestamp)
int i = 0;
for (CaptureHolder h : mCompletedRequests) {
if (h.mRequest.equals(holder)) {
timestamp.value = h.mTimestamp;
mCompletedRequests.remove(i);
return true;
}
i++;
}
return false;
|
public boolean | waitForEmpty(long timeout, java.util.concurrent.TimeUnit unit)Wait all queued requests to complete.
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.mLock;
lock.lock();
try {
while (mInFlight > 0) {
if (nanos <= 0) {
return false;
}
nanos = mIsEmpty.awaitNanos(nanos);
}
return true;
} finally {
lock.unlock();
}
|
public boolean | waitForPreviewsEmpty(long timeout, java.util.concurrent.TimeUnit unit)Wait all queued requests that use the Camera1 API preview output to complete.
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.mLock;
lock.lock();
try {
while (mInFlightPreviews > 0) {
if (nanos <= 0) {
return false;
}
nanos = mPreviewsEmpty.awaitNanos(nanos);
}
return true;
} finally {
lock.unlock();
}
|
public boolean | waitForRequestCompleted(RequestHolder holder, long timeout, java.util.concurrent.TimeUnit unit, android.util.MutableLong timestamp)Wait for the specified request to be completed (all buffers available).
May not wait for the same request more than once, since a successful wait
will erase the history of that request.
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.mLock;
lock.lock();
try {
while (!removeRequestIfCompleted(holder, /*out*/timestamp)) {
if (nanos <= 0) {
return false;
}
nanos = mNotFull.awaitNanos(nanos);
}
return true;
} finally {
lock.unlock();
}
|