v4l2: Use Object::invokeMethod() return value

Now that Object::invokeMethod() supports returning a value, use it and
drop the return value method argument.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Laurent Pinchart 2020-01-04 06:48:10 +02:00
parent 94f62f6b59
commit b4415f1c98
3 changed files with 82 additions and 96 deletions

View file

@ -34,23 +34,21 @@ V4L2Camera::~V4L2Camera()
camera_->release(); camera_->release();
} }
void V4L2Camera::open(int *ret) int V4L2Camera::open()
{ {
/* \todo Support multiple open. */ /* \todo Support multiple open. */
if (camera_->acquire() < 0) { if (camera_->acquire() < 0) {
LOG(V4L2Compat, Error) << "Failed to acquire camera"; LOG(V4L2Compat, Error) << "Failed to acquire camera";
*ret = -EINVAL; return -EINVAL;
return;
} }
config_ = camera_->generateConfiguration({ StreamRole::Viewfinder }); config_ = camera_->generateConfiguration({ StreamRole::Viewfinder });
if (!config_) { if (!config_) {
camera_->release(); camera_->release();
*ret = -EINVAL; return -EINVAL;
return;
} }
*ret = 0; return 0;
} }
void V4L2Camera::close() void V4L2Camera::close()
@ -92,9 +90,9 @@ void V4L2Camera::requestComplete(Request *request)
bufferSema_.release(); bufferSema_.release();
} }
void V4L2Camera::configure(int *ret, StreamConfiguration *streamConfigOut, int V4L2Camera::configure(StreamConfiguration *streamConfigOut,
const Size &size, PixelFormat pixelformat, const Size &size, PixelFormat pixelformat,
unsigned int bufferCount) unsigned int bufferCount)
{ {
StreamConfiguration &streamConfig = config_->at(0); StreamConfiguration &streamConfig = config_->at(0);
streamConfig.size.width = size.width; streamConfig.size.width = size.width;
@ -106,8 +104,7 @@ void V4L2Camera::configure(int *ret, StreamConfiguration *streamConfigOut,
CameraConfiguration::Status validation = config_->validate(); CameraConfiguration::Status validation = config_->validate();
if (validation == CameraConfiguration::Invalid) { if (validation == CameraConfiguration::Invalid) {
LOG(V4L2Compat, Debug) << "Configuration invalid"; LOG(V4L2Compat, Debug) << "Configuration invalid";
*ret = -EINVAL; return -EINVAL;
return;
} }
if (validation == CameraConfiguration::Adjusted) if (validation == CameraConfiguration::Adjusted)
LOG(V4L2Compat, Debug) << "Configuration adjusted"; LOG(V4L2Compat, Debug) << "Configuration adjusted";
@ -115,24 +112,25 @@ void V4L2Camera::configure(int *ret, StreamConfiguration *streamConfigOut,
LOG(V4L2Compat, Debug) << "Validated configuration is: " LOG(V4L2Compat, Debug) << "Validated configuration is: "
<< streamConfig.toString(); << streamConfig.toString();
*ret = camera_->configure(config_.get()); int ret = camera_->configure(config_.get());
if (*ret < 0) if (ret < 0)
return; return ret;
*streamConfigOut = config_->at(0); *streamConfigOut = config_->at(0);
return 0;
} }
void V4L2Camera::mmap(void **ret, unsigned int index) void *V4L2Camera::mmap(unsigned int index)
{ {
Stream *stream = *camera_->streams().begin(); Stream *stream = *camera_->streams().begin();
*ret = stream->buffers()[index].planes()[0].mem(); return stream->buffers()[index].planes()[0].mem();
} }
void V4L2Camera::allocBuffers(int *ret, unsigned int count) int V4L2Camera::allocBuffers(unsigned int count)
{ {
*ret = camera_->allocateBuffers(); int ret = camera_->allocateBuffers();
if (*ret == -EACCES) return ret == -EACCES ? -EBUSY : ret;
*ret = -EBUSY;
} }
void V4L2Camera::freeBuffers() void V4L2Camera::freeBuffers()
@ -140,85 +138,76 @@ void V4L2Camera::freeBuffers()
camera_->freeBuffers(); camera_->freeBuffers();
} }
void V4L2Camera::streamOn(int *ret) int V4L2Camera::streamOn()
{ {
*ret = 0;
if (isRunning_) if (isRunning_)
return; return 0;
int ret = camera_->start();
if (ret < 0)
return ret == -EACCES ? -EBUSY : ret;
*ret = camera_->start();
if (*ret < 0) {
if (*ret == -EACCES)
*ret = -EBUSY;
return;
}
isRunning_ = true; isRunning_ = true;
for (std::unique_ptr<Request> &req : pendingRequests_) { for (std::unique_ptr<Request> &req : pendingRequests_) {
/* \todo What should we do if this returns -EINVAL? */ /* \todo What should we do if this returns -EINVAL? */
*ret = camera_->queueRequest(req.release()); ret = camera_->queueRequest(req.release());
if (*ret < 0) { if (ret < 0)
if (*ret == -EACCES) return ret == -EACCES ? -EBUSY : ret;
*ret = -EBUSY;
return;
}
} }
pendingRequests_.clear(); pendingRequests_.clear();
return 0;
} }
void V4L2Camera::streamOff(int *ret) int V4L2Camera::streamOff()
{ {
*ret = 0;
/* \todo Restore buffers to reqbufs state? */ /* \todo Restore buffers to reqbufs state? */
if (!isRunning_) if (!isRunning_)
return; return 0;
int ret = camera_->stop();
if (ret < 0)
return ret == -EACCES ? -EBUSY : ret;
*ret = camera_->stop();
if (*ret < 0) {
if (*ret == -EACCES)
*ret = -EBUSY;
return;
}
isRunning_ = false; isRunning_ = false;
return 0;
} }
void V4L2Camera::qbuf(int *ret, unsigned int index) int V4L2Camera::qbuf(unsigned int index)
{ {
Stream *stream = config_->at(0).stream(); Stream *stream = config_->at(0).stream();
std::unique_ptr<Buffer> buffer = stream->createBuffer(index); std::unique_ptr<Buffer> buffer = stream->createBuffer(index);
if (!buffer) { if (!buffer) {
LOG(V4L2Compat, Error) << "Can't create buffer"; LOG(V4L2Compat, Error) << "Can't create buffer";
*ret = -ENOMEM; return -ENOMEM;
return;
} }
std::unique_ptr<Request> request = std::unique_ptr<Request> request =
std::unique_ptr<Request>(camera_->createRequest()); std::unique_ptr<Request>(camera_->createRequest());
if (!request) { if (!request) {
LOG(V4L2Compat, Error) << "Can't create request"; LOG(V4L2Compat, Error) << "Can't create request";
*ret = -ENOMEM; return -ENOMEM;
return;
} }
*ret = request->addBuffer(std::move(buffer)); int ret = request->addBuffer(std::move(buffer));
if (*ret < 0) { if (ret < 0) {
LOG(V4L2Compat, Error) << "Can't set buffer for request"; LOG(V4L2Compat, Error) << "Can't set buffer for request";
*ret = -ENOMEM; return -ENOMEM;
return;
} }
if (!isRunning_) { if (!isRunning_) {
pendingRequests_.push_back(std::move(request)); pendingRequests_.push_back(std::move(request));
return; return 0;
} }
*ret = camera_->queueRequest(request.release()); ret = camera_->queueRequest(request.release());
if (*ret < 0) { if (ret < 0) {
LOG(V4L2Compat, Error) << "Can't queue request"; LOG(V4L2Compat, Error) << "Can't queue request";
if (*ret == -EACCES) return ret == -EACCES ? -EBUSY : ret;
*ret = -EBUSY;
} }
return 0;
} }

View file

@ -48,23 +48,23 @@ public:
V4L2Camera(std::shared_ptr<Camera> camera); V4L2Camera(std::shared_ptr<Camera> camera);
~V4L2Camera(); ~V4L2Camera();
void open(int *ret); int open();
void close(); void close();
void getStreamConfig(StreamConfiguration *streamConfig); void getStreamConfig(StreamConfiguration *streamConfig);
std::vector<FrameMetadata> completedBuffers(); std::vector<FrameMetadata> completedBuffers();
void mmap(void **ret, unsigned int index); void *mmap(unsigned int index);
void configure(int *ret, StreamConfiguration *streamConfigOut, int configure(StreamConfiguration *streamConfigOut,
const Size &size, PixelFormat pixelformat, const Size &size, PixelFormat pixelformat,
unsigned int bufferCount); unsigned int bufferCount);
void allocBuffers(int *ret, unsigned int count); int allocBuffers(unsigned int count);
void freeBuffers(); void freeBuffers();
void streamOn(int *ret); int streamOn();
void streamOff(int *ret); int streamOff();
void qbuf(int *ret, unsigned int index); int qbuf(unsigned int index);
Semaphore bufferSema_; Semaphore bufferSema_;

View file

@ -40,9 +40,8 @@ int V4L2CameraProxy::open(bool nonBlocking)
{ {
LOG(V4L2Compat, Debug) << "Servicing open"; LOG(V4L2Compat, Debug) << "Servicing open";
int ret; int ret = vcam_->invokeMethod(&V4L2Camera::open,
vcam_->invokeMethod(&V4L2Camera::open, ConnectionTypeBlocking, ConnectionTypeBlocking);
&ret);
if (ret < 0) { if (ret < 0) {
errno = -ret; errno = -ret;
return -1; return -1;
@ -91,9 +90,8 @@ void *V4L2CameraProxy::mmap(size_t length, int prot, int flags, off_t offset)
return MAP_FAILED; return MAP_FAILED;
} }
void *val; void *val = vcam_->invokeMethod(&V4L2Camera::mmap,
vcam_->invokeMethod(&V4L2Camera::mmap, ConnectionTypeBlocking, ConnectionTypeBlocking, index);
&val, index);
buffers_[index].flags |= V4L2_BUF_FLAG_MAPPED; buffers_[index].flags |= V4L2_BUF_FLAG_MAPPED;
mmaps_[val] = index; mmaps_[val] = index;
@ -245,9 +243,11 @@ int V4L2CameraProxy::vidioc_s_fmt(struct v4l2_format *arg)
return ret; return ret;
Size size(arg->fmt.pix.width, arg->fmt.pix.height); Size size(arg->fmt.pix.width, arg->fmt.pix.height);
vcam_->invokeMethod(&V4L2Camera::configure, ConnectionTypeBlocking, ret = vcam_->invokeMethod(&V4L2Camera::configure,
&ret, &streamConfig_, size, ConnectionTypeBlocking,
v4l2ToDrm(arg->fmt.pix.pixelformat), bufferCount_); &streamConfig_, size,
v4l2ToDrm(arg->fmt.pix.pixelformat),
bufferCount_);
if (ret < 0) if (ret < 0)
return -EINVAL; return -EINVAL;
@ -297,9 +297,8 @@ int V4L2CameraProxy::freeBuffers()
{ {
LOG(V4L2Compat, Debug) << "Freeing libcamera bufs"; LOG(V4L2Compat, Debug) << "Freeing libcamera bufs";
int ret; int ret = vcam_->invokeMethod(&V4L2Camera::streamOff,
vcam_->invokeMethod(&V4L2Camera::streamOff, ConnectionTypeBlocking);
ConnectionTypeBlocking, &ret);
if (ret < 0) { if (ret < 0) {
LOG(V4L2Compat, Error) << "Failed to stop stream"; LOG(V4L2Compat, Error) << "Failed to stop stream";
return ret; return ret;
@ -327,10 +326,11 @@ int V4L2CameraProxy::vidioc_reqbufs(struct v4l2_requestbuffers *arg)
return freeBuffers(); return freeBuffers();
Size size(curV4L2Format_.fmt.pix.width, curV4L2Format_.fmt.pix.height); Size size(curV4L2Format_.fmt.pix.width, curV4L2Format_.fmt.pix.height);
vcam_->invokeMethod(&V4L2Camera::configure, ConnectionTypeBlocking, ret = vcam_->invokeMethod(&V4L2Camera::configure,
&ret, &streamConfig_, size, ConnectionTypeBlocking,
v4l2ToDrm(curV4L2Format_.fmt.pix.pixelformat), &streamConfig_, size,
arg->count); v4l2ToDrm(curV4L2Format_.fmt.pix.pixelformat),
arg->count);
if (ret < 0) if (ret < 0)
return -EINVAL; return -EINVAL;
@ -343,8 +343,8 @@ int V4L2CameraProxy::vidioc_reqbufs(struct v4l2_requestbuffers *arg)
arg->count = streamConfig_.bufferCount; arg->count = streamConfig_.bufferCount;
bufferCount_ = arg->count; bufferCount_ = arg->count;
vcam_->invokeMethod(&V4L2Camera::allocBuffers, ret = vcam_->invokeMethod(&V4L2Camera::allocBuffers,
ConnectionTypeBlocking, &ret, arg->count); ConnectionTypeBlocking, arg->count);
if (ret < 0) { if (ret < 0) {
arg->count = 0; arg->count = 0;
return ret; return ret;
@ -392,9 +392,8 @@ int V4L2CameraProxy::vidioc_qbuf(struct v4l2_buffer *arg)
arg->index >= bufferCount_) arg->index >= bufferCount_)
return -EINVAL; return -EINVAL;
int ret; int ret = vcam_->invokeMethod(&V4L2Camera::qbuf, ConnectionTypeBlocking,
vcam_->invokeMethod(&V4L2Camera::qbuf, ConnectionTypeBlocking, arg->index);
&ret, arg->index);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -437,9 +436,8 @@ int V4L2CameraProxy::vidioc_streamon(int *arg)
if (!validateBufferType(*arg)) if (!validateBufferType(*arg))
return -EINVAL; return -EINVAL;
int ret; int ret = vcam_->invokeMethod(&V4L2Camera::streamOn,
vcam_->invokeMethod(&V4L2Camera::streamOn, ConnectionTypeBlocking);
ConnectionTypeBlocking, &ret);
return ret; return ret;
} }
@ -451,9 +449,8 @@ int V4L2CameraProxy::vidioc_streamoff(int *arg)
if (!validateBufferType(*arg)) if (!validateBufferType(*arg))
return -EINVAL; return -EINVAL;
int ret; int ret = vcam_->invokeMethod(&V4L2Camera::streamOff,
vcam_->invokeMethod(&V4L2Camera::streamOff, ConnectionTypeBlocking);
ConnectionTypeBlocking, &ret);
for (struct v4l2_buffer &buf : buffers_) for (struct v4l2_buffer &buf : buffers_)
buf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE); buf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE);