use of android.view.Surface in project platform_frameworks_base by android.
the class LegacyCameraDevice method submitRequestList.
/**
* Submit a burst of capture requests.
*
* @param requestList a list of capture requests to execute.
* @param repeating {@code true} if this 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 SubmitInfo submitRequestList(CaptureRequest[] requestList, boolean repeating) {
if (requestList == null || requestList.length == 0) {
Log.e(TAG, "submitRequestList - Empty/null requests are not allowed");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - Empty/null requests are not allowed");
}
List<Long> surfaceIds;
try {
surfaceIds = (mConfiguredSurfaces == null) ? new ArrayList<Long>() : getSurfaceIds(mConfiguredSurfaces);
} catch (BufferQueueAbandonedException e) {
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - configured surface is abandoned.");
}
// Make sure that there all requests have at least 1 surface; all surfaces are non-null
for (CaptureRequest request : requestList) {
if (request.getTargets().isEmpty()) {
Log.e(TAG, "submitRequestList - " + "Each request must have at least one Surface target");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - " + "Each request must have at least one Surface target");
}
for (Surface surface : request.getTargets()) {
if (surface == null) {
Log.e(TAG, "submitRequestList - Null Surface targets are not allowed");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - Null Surface targets are not allowed");
} else if (mConfiguredSurfaces == null) {
Log.e(TAG, "submitRequestList - must configure " + " device with valid surfaces before submitting requests");
throw new ServiceSpecificException(INVALID_OPERATION, "submitRequestList - must configure " + " device with valid surfaces before submitting requests");
} else if (!containsSurfaceId(surface, surfaceIds)) {
Log.e(TAG, "submitRequestList - cannot use a surface that wasn't configured");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - cannot use a surface that wasn't configured");
}
}
}
// TODO: further validation of request here
mIdle.close();
return mRequestThreadManager.submitCaptureRequests(requestList, repeating);
}
use of android.view.Surface in project platform_frameworks_base by android.
the class LegacyCameraDevice method getSurfaceIds.
static List<Long> getSurfaceIds(Collection<Surface> surfaces) throws BufferQueueAbandonedException {
if (surfaces == null) {
throw new NullPointerException("Null argument surfaces");
}
List<Long> surfaceIds = new ArrayList<>();
for (Surface s : surfaces) {
long id = getSurfaceId(s);
if (id == 0) {
throw new IllegalStateException("Configured surface had null native GraphicBufferProducer pointer!");
}
surfaceIds.add(id);
}
return surfaceIds;
}
use of android.view.Surface in project platform_frameworks_base by android.
the class SurfaceUtils method checkConstrainedHighSpeedSurfaces.
/**
* Verify that that the surfaces are valid for high-speed recording mode,
* and that the FPS range is supported
*
* @param surfaces the surfaces to verify as valid in terms of size and format
* @param fpsRange the target high-speed FPS range to validate
* @param config The stream configuration map for the device in question
*/
public static void checkConstrainedHighSpeedSurfaces(Collection<Surface> surfaces, Range<Integer> fpsRange, StreamConfigurationMap config) {
if (surfaces == null || surfaces.size() == 0 || surfaces.size() > 2) {
throw new IllegalArgumentException("Output target surface list must not be null and" + " the size must be 1 or 2");
}
List<Size> highSpeedSizes = null;
if (fpsRange == null) {
highSpeedSizes = Arrays.asList(config.getHighSpeedVideoSizes());
} else {
// Check the FPS range first if provided
Range<Integer>[] highSpeedFpsRanges = config.getHighSpeedVideoFpsRanges();
if (!Arrays.asList(highSpeedFpsRanges).contains(fpsRange)) {
throw new IllegalArgumentException("Fps range " + fpsRange.toString() + " in the" + " request is not a supported high speed fps range " + Arrays.toString(highSpeedFpsRanges));
}
highSpeedSizes = Arrays.asList(config.getHighSpeedVideoSizesFor(fpsRange));
}
for (Surface surface : surfaces) {
checkHighSpeedSurfaceFormat(surface);
// Surface size must be supported high speed sizes.
Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
if (!highSpeedSizes.contains(surfaceSize)) {
throw new IllegalArgumentException("Surface size " + surfaceSize.toString() + " is" + " not part of the high speed supported size list " + Arrays.toString(highSpeedSizes.toArray()));
}
// Each output surface must be either preview surface or recording surface.
if (!SurfaceUtils.isSurfaceForPreview(surface) && !SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
throw new IllegalArgumentException("This output surface is neither preview nor " + "hardware video encoding surface");
}
if (SurfaceUtils.isSurfaceForPreview(surface) && SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
throw new IllegalArgumentException("This output surface can not be both preview" + " and hardware video encoding surface");
}
}
// For 2 output surface case, they shouldn't be same type.
if (surfaces.size() == 2) {
// Up to here, each surface can only be either preview or recording.
Iterator<Surface> iterator = surfaces.iterator();
boolean isFirstSurfacePreview = SurfaceUtils.isSurfaceForPreview(iterator.next());
boolean isSecondSurfacePreview = SurfaceUtils.isSurfaceForPreview(iterator.next());
if (isFirstSurfacePreview == isSecondSurfacePreview) {
throw new IllegalArgumentException("The 2 output surfaces must have different" + " type");
}
}
}
use of android.view.Surface in project platform_frameworks_base by android.
the class RequestThreadManager method createDummySurface.
/**
* Fake preview for jpeg captures when there is no active preview
*/
private void createDummySurface() {
if (mDummyTexture == null || mDummySurface == null) {
mDummyTexture = new SurfaceTexture(/*ignored*/
0);
// TODO: use smallest default sizes
mDummyTexture.setDefaultBufferSize(640, 480);
mDummySurface = new Surface(mDummyTexture);
}
}
use of android.view.Surface in project platform_frameworks_base by android.
the class Camera method setPreviewCallbackAllocation.
/**
* <p>Set an {@link android.renderscript.Allocation Allocation} as the
* target of preview callback data. Use this method for efficient processing
* of camera preview data with RenderScript. The Allocation must be created
* with the {@link #createPreviewAllocation createPreviewAllocation }
* method.</p>
*
* <p>Setting a preview allocation will disable any active preview callbacks
* set by {@link #setPreviewCallback setPreviewCallback} or
* {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
* vice versa. Using a preview allocation still requires an active standard
* preview target to be set, either with
* {@link #setPreviewTexture setPreviewTexture} or
* {@link #setPreviewDisplay setPreviewDisplay}.</p>
*
* <p>To be notified when new frames are available to the Allocation, use
* {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
* update the frame currently accessible from the Allocation to the latest
* preview frame, call
* {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
*
* <p>To disable preview into the Allocation, call this method with a
* {@code null} parameter.</p>
*
* <p>Once a preview allocation is set, the preview size set by
* {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
* you wish to change the preview size, first remove the preview allocation
* by calling {@code setPreviewCallbackAllocation(null)}, then change the
* preview size, create a new preview Allocation with
* {@link #createPreviewAllocation createPreviewAllocation}, and set it as
* the new preview callback allocation target.</p>
*
* <p>If you are using the preview data to create video or still images,
* strongly consider using {@link android.media.MediaActionSound} to
* properly indicate image capture or recording start/stop to the user.</p>
*
* @param previewAllocation the allocation to use as destination for preview
* @throws IOException if configuring the camera to use the Allocation for
* preview fails.
* @throws IllegalArgumentException if the Allocation's dimensions or other
* parameters don't meet the requirements.
* @see #createPreviewAllocation
* @see #setPreviewCallback
* @see #setPreviewCallbackWithBuffer
* @hide
*/
public final void setPreviewCallbackAllocation(Allocation previewAllocation) throws IOException {
Surface previewSurface = null;
if (previewAllocation != null) {
Parameters p = getParameters();
Size previewSize = p.getPreviewSize();
if (previewSize.width != previewAllocation.getType().getX() || previewSize.height != previewAllocation.getType().getY()) {
throw new IllegalArgumentException("Allocation dimensions don't match preview dimensions: " + "Allocation is " + previewAllocation.getType().getX() + ", " + previewAllocation.getType().getY() + ". Preview is " + previewSize.width + ", " + previewSize.height);
}
if ((previewAllocation.getUsage() & Allocation.USAGE_IO_INPUT) == 0) {
throw new IllegalArgumentException("Allocation usage does not include USAGE_IO_INPUT");
}
if (previewAllocation.getType().getElement().getDataKind() != Element.DataKind.PIXEL_YUV) {
throw new IllegalArgumentException("Allocation is not of a YUV type");
}
previewSurface = previewAllocation.getSurface();
mUsingPreviewAllocation = true;
} else {
mUsingPreviewAllocation = false;
}
setPreviewCallbackSurface(previewSurface);
}
Aggregations