outputStreams.push(getCallbackStreamId());
}
if (params.zslMode && !params.recordingHint) {
- res = mZslProcessor->updateStream(params);
+ res = updateProcessorStream(mZslProcessor, params);
if (res != OK) {
ALOGE("%s: Camera %d: Unable to update ZSL stream: %s (%d)",
__FUNCTION__, mCameraId, strerror(-res), res);
// assumption that the user will record video. To optimize recording
// startup time, create the necessary output streams for recording and
// video snapshot now if they don't already exist.
- res = mJpegProcessor->updateStream(params);
+ res = updateProcessorStream(mJpegProcessor, params);
if (res != OK) {
ALOGE("%s: Camera %d: Can't pre-configure still image "
"stream: %s (%d)",
ALOGV("%s: Camera %d: Starting picture capture", __FUNCTION__, mCameraId);
- res = mJpegProcessor->updateStream(l.mParameters);
+ res = updateProcessorStream(mJpegProcessor, l.mParameters);
if (res != OK) {
ALOGE("%s: Camera %d: Can't set up still image stream: %s (%d)",
__FUNCTION__, mCameraId, strerror(-res), res);
return res;
}
+template <typename ProcessorT>
+status_t Camera2Client::updateProcessorStream(sp<ProcessorT> processor,
+ camera2::Parameters params) {
+ status_t res;
+
+ res = processor->updateStream(params);
+
+ /**
+ * Can't update the stream if it's busy?
+ *
+ * Then we need to stop the device (by temporarily clearing the request
+ * queue) and then try again. Resume streaming once we're done.
+ */
+ if (res == -EBUSY) {
+ res = mStreamingProcessor->togglePauseStream(/*pause*/true);
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Can't pause streaming: %s (%d)",
+ __FUNCTION__, mCameraId, strerror(-res), res);
+ }
+
+ res = mDevice->waitUntilDrained();
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Waiting to stop streaming failed: %s (%d)",
+ __FUNCTION__, mCameraId, strerror(-res), res);
+ }
+
+ res = processor->updateStream(params);
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Failed to update processing stream "
+ " despite having halted streaming first: %s (%d)",
+ __FUNCTION__, mCameraId, strerror(-res), res);
+ }
+
+ res = mStreamingProcessor->togglePauseStream(/*pause*/false);
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Can't unpause streaming: %s (%d)",
+ __FUNCTION__, mCameraId, strerror(-res), res);
+ }
+ }
+
+ return res;
+}
} // namespace android
// Used with stream IDs
static const int NO_STREAM = -1;
+ template <typename ProcessorT>
+ status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params);
+
sp<camera2::FrameProcessor> mFrameProcessor;
/* Preview/Recording related members */
// CameraDevice semantics require device to already be idle before
// deleteStream is called, unlike for createStream.
if (mStatus != STATUS_IDLE) {
- CLOGE("Device not idle");
- return INVALID_OPERATION;
+ ALOGV("%s: Camera %d: Device not idle", __FUNCTION__, mId);
+ return -EBUSY;
}
sp<Camera3StreamInterface> deletedStream;
ALOGV("%s: Camera %d: Deleting stream %d since the buffer dimensions changed",
__FUNCTION__, mId, mCaptureStreamId);
res = device->deleteStream(mCaptureStreamId);
- if (res != OK) {
+ if (res == -EBUSY) {
+ ALOGV("%s: Camera %d: Device is busy, call updateStream again "
+ " after it becomes idle", __FUNCTION__, mId);
+ return res;
+ } else if (res != OK) {
ALOGE("%s: Camera %d: Unable to delete old output stream "
"for capture: %s (%d)", __FUNCTION__,
mId, strerror(-res), res);
mDevice(client->getCameraDevice()),
mId(client->getCameraId()),
mActiveRequest(NONE),
+ mPaused(false),
mPreviewRequestId(Camera2Client::kPreviewRequestIdStart),
mPreviewStreamId(NO_STREAM),
mRecordingRequestId(Camera2Client::kRecordingRequestIdStart),
return res;
}
mActiveRequest = type;
+ mPaused = false;
return OK;
}
+status_t StreamingProcessor::togglePauseStream(bool pause) {
+ ATRACE_CALL();
+ status_t res;
+
+ sp<CameraDeviceBase> device = mDevice.promote();
+ if (device == 0) {
+ ALOGE("%s: Camera %d: Device does not exist", __FUNCTION__, mId);
+ return INVALID_OPERATION;
+ }
+
+ ALOGV("%s: Camera %d: toggling pause to %d", __FUNCTION__, mId, pause);
+
+ Mutex::Autolock m(mMutex);
+
+ if (mActiveRequest == NONE) {
+ ALOGE("%s: Camera %d: Can't toggle pause, streaming was not started",
+ __FUNCTION__, mId);
+ return INVALID_OPERATION;
+ }
+
+ if (mPaused == pause) {
+ return OK;
+ }
+
+ if (pause) {
+ res = device->clearStreamingRequest();
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Can't clear stream request: %s (%d)",
+ __FUNCTION__, mId, strerror(-res), res);
+ return res;
+ }
+ } else {
+ CameraMetadata &request =
+ (mActiveRequest == PREVIEW) ? mPreviewRequest
+ : mRecordingRequest;
+ res = device->setStreamingRequest(request);
+ if (res != OK) {
+ ALOGE("%s: Camera %d: Unable to set preview request to resume: "
+ "%s (%d)",
+ __FUNCTION__, mId, strerror(-res), res);
+ return res;
+ }
+ }
+
+ mPaused = pause;
+ return OK;
+}
+
status_t StreamingProcessor::stopStream() {
ATRACE_CALL();
status_t res;
}
mActiveRequest = NONE;
+ mPaused = false;
return OK;
}
result.append(" Preview request:\n");
write(fd, result.string(), result.size());
mPreviewRequest.dump(fd, 2, 6);
+ result.clear();
} else {
result.append(" Preview request: undefined\n");
- write(fd, result.string(), result.size());
}
if (mRecordingRequest.entryCount() != 0) {
result = " Recording request:\n";
write(fd, result.string(), result.size());
mRecordingRequest.dump(fd, 2, 6);
+ result.clear();
} else {
result = " Recording request: undefined\n";
- write(fd, result.string(), result.size());
}
+ const char* streamTypeString[] = {
+ "none", "preview", "record"
+ };
+ result.append(String8::format(" Active request: %s (paused: %s)\n",
+ streamTypeString[mActiveRequest],
+ mPaused ? "yes" : "no"));
+
+ write(fd, result.string(), result.size());
+
return OK;
}
status_t startStream(StreamType type,
const Vector<uint8_t> &outputStreams);
+ // Toggle between paused and unpaused. Stream must be started first.
+ status_t togglePauseStream(bool pause);
+
status_t stopStream();
// Returns the request ID for the currently streaming request
int mId;
StreamType mActiveRequest;
+ bool mPaused;
// Preview-related members
int32_t mPreviewRequestId;
"dimensions changed",
__FUNCTION__, client->getCameraId(), mZslStreamId);
res = device->deleteStream(mZslStreamId);
- if (res != OK) {
+ if (res == -EBUSY) {
+ ALOGV("%s: Camera %d: Device is busy, call updateStream again "
+ " after it becomes idle", __FUNCTION__, mId);
+ return res;
+ } else if(res != OK) {
ALOGE("%s: Camera %d: Unable to delete old output stream "
"for ZSL: %s (%d)", __FUNCTION__,
client->getCameraId(), strerror(-res), res);