[libcamera-devel] [PATCH v2 7/9] android: camera_device: Add buffers for each stream to Requests

Kieran Bingham kieran.bingham at ideasonboard.com
Fri Jul 3 12:48:41 CEST 2020


Hi Laurent,

On 03/07/2020 01:47, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Thu, Jul 02, 2020 at 10:36:52PM +0100, Kieran Bingham wrote:
>> Construct a FrameBuffer for every buffer given in the camera3Request
>> and add it to the libcamera Request on the appropriate stream.
>>
>> The correct stream is obtained from the private data of the camera3_stream
>> associated with the camera3_buffer.
>>
>> Comments regarding supporting only one buffer are now removed.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
>> ---
>>  src/android/camera_device.cpp | 38 ++++++++++++++---------------------
>>  1 file changed, 15 insertions(+), 23 deletions(-)
>>
>> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
>> index fc3962dac230..eea8c8c50352 100644
>> --- a/src/android/camera_device.cpp
>> +++ b/src/android/camera_device.cpp
>> @@ -977,6 +977,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>>  
>>  		/* Maintain internal state of all stream mappings. */
>>  		streams_[i].androidStream = stream;
>> +		stream->priv = static_cast<void*>(&streams_[i]);
> 
> We could also store i in stream->priv, and remove libcameraIndex from
> CameraStream. Up to you.
> 

At this stage we could, especially as I don't think I actaully needed to
use the halStream, so only index is in this structure currently.

However, it will (very likely) grow in $FUTURE_PATCHES, so I'll keep the
struct and keep the index in it.

Maybe the struct could already be a class, but I'll defer that until I
find out if it really needs to be a full class or a struct is simpler.


> Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Thanks.



> 
>>  
>>  		StreamConfiguration streamConfiguration;
>>  
>> @@ -1045,9 +1046,6 @@ static FrameBuffer *newFrameBuffer(const buffer_handle_t camera3buffer)
>>  
>>  int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)
>>  {
>> -	StreamConfiguration *streamConfiguration = &config_->at(0);
>> -	Stream *stream = streamConfiguration->stream();
>> -
>>  	if (camera3Request->num_output_buffers != 1) {
>>  		LOG(HAL, Error) << "Invalid number of output buffers: "
>>  				<< camera3Request->num_output_buffers;
>> @@ -1085,30 +1083,28 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
>>  		camera_->createRequest(reinterpret_cast<uint64_t>(descriptor));
>>  
>>  	for (unsigned int i = 0; i < descriptor->numBuffers; ++i) {
>> +		CameraStream *cameraStream = static_cast<CameraStream*>(camera3Buffers[i].stream->priv);
>> +
>>  		/*
>>  		 * Keep track of which stream the request belongs to and store
>>  		 * the native buffer handles.
>> -		 *
>> -		 * \todo Currently we only support one capture buffer. Copy
>> -		 * all of them to be ready once we'll support more.
>>  		 */
>>  		descriptor->buffers[i].stream = camera3Buffers[i].stream;
>>  		descriptor->buffers[i].buffer = camera3Buffers[i].buffer;
>> -	}
>>  
>> -	/*
>> -	 * Create a libcamera buffer using the dmabuf descriptors of the first
>> -	 * and (currently) only supported request buffer.
>> -	 */
>> -	FrameBuffer *buffer = newFrameBuffer(*camera3Buffers[0].buffer);
>> -	if (!buffer) {
>> -		LOG(HAL, Error) << "Failed to create buffer";
>> -		delete request;
>> -		delete descriptor;
>> -		return -ENOMEM;
>> -	}
>> +		FrameBuffer *buffer = newFrameBuffer(*camera3Buffers[0].buffer);
>> +		if (!buffer) {
>> +			LOG(HAL, Error) << "Failed to create buffer";
>> +			delete request;
>> +			delete descriptor;
>> +			return -ENOMEM;
>> +		}
>> +
>> +		StreamConfiguration *streamConfiguration = &config_->at(cameraStream->libcameraIndex);
>> +		Stream *stream = streamConfiguration->stream();
>>  
>> -	request->addBuffer(stream, buffer);
>> +		request->addBuffer(stream, buffer);
>> +	}
>>  
>>  	int ret = camera_->queueRequest(request);
>>  	if (ret) {
>> @@ -1142,10 +1138,6 @@ void CameraDevice::requestComplete(Request *request)
>>  	captureResult.frame_number = descriptor->frameNumber;
>>  	captureResult.num_output_buffers = descriptor->numBuffers;
>>  	for (unsigned int i = 0; i < descriptor->numBuffers; ++i) {
>> -		/*
>> -		 * \todo Currently we only support one capture buffer. Prepare
>> -		 * all of them to be ready once we'll support more.
>> -		 */
>>  		descriptor->buffers[i].acquire_fence = -1;
>>  		descriptor->buffers[i].release_fence = -1;
>>  		descriptor->buffers[i].status = status;
> 

-- 
Regards
--
Kieran


More information about the libcamera-devel mailing list