Merge "Add experimental camera session prepare API." into mnc-dr-dev
This commit is contained in:
@@ -138,6 +138,48 @@ public abstract class CameraCaptureSession implements AutoCloseable {
|
|||||||
*/
|
*/
|
||||||
public abstract void prepare(@NonNull Surface surface) throws CameraAccessException;
|
public abstract void prepare(@NonNull Surface surface) throws CameraAccessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Pre-allocate at most maxCount buffers for an output Surface.</p>
|
||||||
|
*
|
||||||
|
* <p>Like the {@link #prepare(Surface)} method, this method can be used to allocate output
|
||||||
|
* buffers for a given Surface. However, while the {@link #prepare(Surface)} method allocates
|
||||||
|
* the maximum possible buffer count, this method allocates at most maxCount buffers.</p>
|
||||||
|
*
|
||||||
|
* <p>If maxCount is greater than the possible maximum count (which is the sum of the buffer
|
||||||
|
* count requested by the creator of the Surface and the count requested by the camera device),
|
||||||
|
* only the possible maximum count is allocated, in which case the function acts exactly like
|
||||||
|
* {@link #prepare(Surface)}.</p>
|
||||||
|
*
|
||||||
|
* <p>The restrictions on when this method can be called are the same as for
|
||||||
|
* {@link #prepare(Surface)}.</p>
|
||||||
|
*
|
||||||
|
* <p>Repeated calls to this method are allowed, and a mix of {@link #prepare(Surface)} and
|
||||||
|
* this method is also allowed. Note that after the first call to {@link #prepare(Surface)},
|
||||||
|
* subsequent calls to either prepare method are effectively no-ops. In addition, this method
|
||||||
|
* is not additive in terms of buffer count. This means calling it twice with maxCount = 2
|
||||||
|
* will only allocate 2 buffers, not 4 (assuming the possible maximum is at least 2); to
|
||||||
|
* allocate two buffers on the first call and two on the second, the application needs to call
|
||||||
|
* prepare with prepare(surface, 2) and prepare(surface, 4).</p>
|
||||||
|
*
|
||||||
|
* @param maxCount the buffer count to try to allocate. If this is greater than the possible
|
||||||
|
* maximum for this output, the possible maximum is allocated instead. If
|
||||||
|
* maxCount buffers are already allocated, then prepare will do nothing.
|
||||||
|
* @param surface the output Surface for which buffers should be pre-allocated.
|
||||||
|
*
|
||||||
|
* @throws CameraAccessException if the camera device is no longer connected or has
|
||||||
|
* encountered a fatal error.
|
||||||
|
* @throws IllegalStateException if this session is no longer active, either because the
|
||||||
|
* session was explicitly closed, a new session has been created
|
||||||
|
* or the camera device has been closed.
|
||||||
|
* @throws IllegalArgumentException if the Surface is invalid, not part of this Session,
|
||||||
|
* or has already been used as a target of a CaptureRequest in
|
||||||
|
* this session or immediately prior sessions without an
|
||||||
|
* intervening tearDown call.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public abstract void prepare(int maxCount, @NonNull Surface surface)
|
||||||
|
throws CameraAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Free all buffers allocated for an output Surface.</p>
|
* <p>Free all buffers allocated for an output Surface.</p>
|
||||||
|
|||||||
@@ -102,4 +102,6 @@ interface ICameraDeviceUser
|
|||||||
int prepare(int streamId);
|
int prepare(int streamId);
|
||||||
|
|
||||||
int tearDown(int streamId);
|
int tearDown(int streamId);
|
||||||
|
|
||||||
|
int prepare2(int maxCount, int streamId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,6 +145,11 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession
|
|||||||
mDeviceImpl.prepare(surface);
|
mDeviceImpl.prepare(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare(int maxCount, Surface surface) throws CameraAccessException {
|
||||||
|
mDeviceImpl.prepare(maxCount, surface);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tearDown(Surface surface) throws CameraAccessException {
|
public void tearDown(Surface surface) throws CameraAccessException {
|
||||||
mDeviceImpl.tearDown(surface);
|
mDeviceImpl.tearDown(surface);
|
||||||
|
|||||||
@@ -168,6 +168,11 @@ public class CameraConstrainedHighSpeedCaptureSessionImpl
|
|||||||
mSessionImpl.prepare(surface);
|
mSessionImpl.prepare(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare(int maxCount, Surface surface) throws CameraAccessException {
|
||||||
|
mSessionImpl.prepare(maxCount, surface);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tearDown(Surface surface) throws CameraAccessException {
|
public void tearDown(Surface surface) throws CameraAccessException {
|
||||||
mSessionImpl.tearDown(surface);
|
mSessionImpl.tearDown(surface);
|
||||||
|
|||||||
@@ -679,6 +679,33 @@ public class CameraDeviceImpl extends CameraDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void prepare(int maxCount, Surface surface) throws CameraAccessException {
|
||||||
|
if (surface == null) throw new IllegalArgumentException("Surface is null");
|
||||||
|
if (maxCount <= 0) throw new IllegalArgumentException("Invalid maxCount given: " +
|
||||||
|
maxCount);
|
||||||
|
|
||||||
|
synchronized(mInterfaceLock) {
|
||||||
|
int streamId = -1;
|
||||||
|
for (int i = 0; i < mConfiguredOutputs.size(); i++) {
|
||||||
|
if (surface == mConfiguredOutputs.valueAt(i).getSurface()) {
|
||||||
|
streamId = mConfiguredOutputs.keyAt(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (streamId == -1) {
|
||||||
|
throw new IllegalArgumentException("Surface is not part of this session");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mRemoteDevice.prepare2(maxCount, streamId);
|
||||||
|
} catch (CameraRuntimeException e) {
|
||||||
|
throw e.asChecked();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// impossible
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void tearDown(Surface surface) throws CameraAccessException {
|
public void tearDown(Surface surface) throws CameraAccessException {
|
||||||
if (surface == null) throw new IllegalArgumentException("Surface is null");
|
if (surface == null) throw new IllegalArgumentException("Surface is null");
|
||||||
|
|
||||||
|
|||||||
@@ -636,6 +636,11 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
|
|||||||
return CameraBinderDecorator.NO_ERROR;
|
return CameraBinderDecorator.NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int prepare2(int maxCount, int streamId) {
|
||||||
|
// We don't support this in LEGACY mode.
|
||||||
|
return prepare(streamId);
|
||||||
|
}
|
||||||
|
|
||||||
public int tearDown(int streamId) {
|
public int tearDown(int streamId) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "tearDown called.");
|
Log.d(TAG, "tearDown called.");
|
||||||
|
|||||||
Reference in New Issue
Block a user