status_t Camera3Stream::registerBuffersLocked(camera3_device *hal3Device) { ATRACE_CALL(); status_t res; size_t bufferCount = getBufferCountLocked(); Vector<buffer_handle_t*> buffers; buffers.insertAt(NULL, 0, bufferCount); camera3_stream_buffer_set bufferSet = camera3_stream_buffer_set(); bufferSet.stream = this; bufferSet.num_buffers = bufferCount; bufferSet.buffers = buffers.editArray(); Vector<camera3_stream_buffer_t> streamBuffers; streamBuffers.insertAt(camera3_stream_buffer_t(), 0, bufferCount); // Register all buffers with the HAL. This means getting all the buffers // from the stream, providing them to the HAL with the // register_stream_buffers() method, and then returning them back to the // stream in the error state, since they won't have valid data. // // Only registered buffers can be sent to the HAL. uint32_t bufferIdx = 0; for (; bufferIdx < bufferCount; bufferIdx++) { res = getBufferLocked( &streamBuffers.editItemAt(bufferIdx) ); if (res != OK) { ALOGE("%s: Unable to get buffer %d for registration with HAL", __FUNCTION__, bufferIdx); // Skip registering, go straight to cleanup break; } sp<Fence> fence = new Fence(streamBuffers[bufferIdx].acquire_fence); fence->waitForever("Camera3Stream::registerBuffers"); buffers.editItemAt(bufferIdx) = streamBuffers[bufferIdx].buffer; } if (bufferIdx == bufferCount) { // Got all buffers, register with HAL ALOGV("%s: Registering %zu buffers with camera HAL", __FUNCTION__, bufferCount); ATRACE_BEGIN("camera3->register_stream_buffers"); res = hal3Device->ops->register_stream_buffers(hal3Device, &bufferSet); ATRACE_END(); } // Return all valid buffers to stream, in ERROR state to indicate // they weren't filled. for (size_t i = 0; i < bufferIdx; i++) { streamBuffers.editItemAt(i).release_fence = -1; streamBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR; returnBufferLocked(streamBuffers[i], 0); } return res; }
status_t Camera3Stream::startPrepare(int maxCount) { ATRACE_CALL(); Mutex::Autolock l(mLock); if (maxCount < 0) { ALOGE("%s: Stream %d: Can't prepare stream if max buffer count (%d) is < 0", __FUNCTION__, mId, maxCount); return BAD_VALUE; } // This function should be only called when the stream is configured already. if (mState != STATE_CONFIGURED) { ALOGE("%s: Stream %d: Can't prepare stream if stream is not in CONFIGURED " "state %d", __FUNCTION__, mId, mState); return INVALID_OPERATION; } // This function can't be called if the stream has already received filled // buffers if (mStreamUnpreparable) { ALOGE("%s: Stream %d: Can't prepare stream that's already in use", __FUNCTION__, mId); return INVALID_OPERATION; } if (getHandoutOutputBufferCountLocked() > 0) { ALOGE("%s: Stream %d: Can't prepare stream that has outstanding buffers", __FUNCTION__, mId); return INVALID_OPERATION; } size_t pipelineMax = getBufferCountLocked(); size_t clampedCount = (pipelineMax < static_cast<size_t>(maxCount)) ? pipelineMax : static_cast<size_t>(maxCount); size_t bufferCount = (maxCount == Camera3StreamInterface::ALLOCATE_PIPELINE_MAX) ? pipelineMax : clampedCount; mPrepared = bufferCount <= mLastMaxCount; if (mPrepared) return OK; mLastMaxCount = bufferCount; mPreparedBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount); mPreparedBufferIdx = 0; mState = STATE_PREPARING; return NOT_ENOUGH_DATA; }
status_t Camera3Stream::registerBuffersLocked(camera3_device *hal3Device) { ATRACE_CALL(); /** * >= CAMERA_DEVICE_API_VERSION_3_2: * * camera3_device_t->ops->register_stream_buffers() is not called and must * be NULL. */ if (hal3Device->common.version >= CAMERA_DEVICE_API_VERSION_3_2) { ALOGV("%s: register_stream_buffers unused as of HAL3.2", __FUNCTION__); if (hal3Device->ops->register_stream_buffers != NULL) { ALOGE("%s: register_stream_buffers is deprecated in HAL3.2; " "must be set to NULL in camera3_device::ops", __FUNCTION__); return INVALID_OPERATION; } return OK; } ALOGV("%s: register_stream_buffers using deprecated code path", __FUNCTION__); status_t res; size_t bufferCount = getBufferCountLocked(); Vector<buffer_handle_t*> buffers; buffers.insertAt(/*prototype_item*/NULL, /*index*/0, bufferCount); camera3_stream_buffer_set bufferSet = camera3_stream_buffer_set(); bufferSet.stream = this; bufferSet.num_buffers = bufferCount; bufferSet.buffers = buffers.editArray(); Vector<camera3_stream_buffer_t> streamBuffers; streamBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount); // Register all buffers with the HAL. This means getting all the buffers // from the stream, providing them to the HAL with the // register_stream_buffers() method, and then returning them back to the // stream in the error state, since they won't have valid data. // // Only registered buffers can be sent to the HAL. uint32_t bufferIdx = 0; for (; bufferIdx < bufferCount; bufferIdx++) { res = getBufferLocked( &streamBuffers.editItemAt(bufferIdx) ); if (res != OK) { ALOGE("%s: Unable to get buffer %d for registration with HAL", __FUNCTION__, bufferIdx); // Skip registering, go straight to cleanup break; } sp<Fence> fence = new Fence(streamBuffers[bufferIdx].acquire_fence); fence->waitForever("Camera3Stream::registerBuffers"); buffers.editItemAt(bufferIdx) = streamBuffers[bufferIdx].buffer; } if (bufferIdx == bufferCount) { // Got all buffers, register with HAL ALOGV("%s: Registering %zu buffers with camera HAL", __FUNCTION__, bufferCount); ATRACE_BEGIN("camera3->register_stream_buffers"); res = hal3Device->ops->register_stream_buffers(hal3Device, &bufferSet); ATRACE_END(); } // Return all valid buffers to stream, in ERROR state to indicate // they weren't filled. for (size_t i = 0; i < bufferIdx; i++) { streamBuffers.editItemAt(i).release_fence = -1; streamBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR; returnBufferLocked(streamBuffers[i], 0); } mPrepared = true; return res; }