libcamera: base: shared_fd: Rename fd() to get()
For consistency with UniqueFD, rename the fd() function to get(). Renaming UniqueFD::get() to fd() would have been another option, but was rejected to keep as close as possible to the std::shared_ptr<> and std::unique_ptr<> APIs. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
This commit is contained in:
parent
5c85e70240
commit
560f5cf998
14 changed files with 39 additions and 38 deletions
|
@ -27,7 +27,7 @@ public:
|
|||
SharedFD &operator=(SharedFD &&other);
|
||||
|
||||
bool isValid() const { return fd_ != nullptr; }
|
||||
int fd() const { return fd_ ? fd_->fd() : -1; }
|
||||
int get() const { return fd_ ? fd_->fd() : -1; }
|
||||
UniqueFD dup() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -140,7 +140,7 @@ private:
|
|||
private:
|
||||
struct Plane {
|
||||
Plane(const FrameBuffer::Plane &plane)
|
||||
: fd(plane.fd.fd()), length(plane.length)
|
||||
: fd(plane.fd.get()), length(plane.length)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -608,12 +608,12 @@ std::unique_ptr<FrameBuffer> Device::createFrameBuffer(
|
|||
|
||||
unsigned int i = 0;
|
||||
for (const libcamera::FrameBuffer::Plane &plane : planes) {
|
||||
int fd = plane.fd.fd();
|
||||
int fd = plane.fd.get();
|
||||
uint32_t handle;
|
||||
|
||||
auto iter = fb->planes_.find(fd);
|
||||
if (iter == fb->planes_.end()) {
|
||||
ret = drmPrimeFDToHandle(fd_, plane.fd.fd(), &handle);
|
||||
ret = drmPrimeFDToHandle(fd_, plane.fd.get(), &handle);
|
||||
if (ret < 0) {
|
||||
ret = -errno;
|
||||
std::cerr
|
||||
|
|
|
@ -39,7 +39,7 @@ std::unique_ptr<Image> Image::fromFrameBuffer(const FrameBuffer *buffer, MapMode
|
|||
std::map<int, MappedBufferInfo> mappedBuffers;
|
||||
|
||||
for (const FrameBuffer::Plane &plane : buffer->planes()) {
|
||||
const int fd = plane.fd.fd();
|
||||
const int fd = plane.fd.get();
|
||||
if (mappedBuffers.find(fd) == mappedBuffers.end()) {
|
||||
const size_t length = lseek(fd, 0, SEEK_END);
|
||||
mappedBuffers[fd] = MappedBufferInfo{ nullptr, 0, length };
|
||||
|
@ -61,7 +61,7 @@ std::unique_ptr<Image> Image::fromFrameBuffer(const FrameBuffer *buffer, MapMode
|
|||
}
|
||||
|
||||
for (const FrameBuffer::Plane &plane : buffer->planes()) {
|
||||
const int fd = plane.fd.fd();
|
||||
const int fd = plane.fd.get();
|
||||
auto &info = mappedBuffers[fd];
|
||||
if (!info.address) {
|
||||
void *address = mmap(nullptr, info.mapLength, mmapFlags,
|
||||
|
|
|
@ -52,7 +52,7 @@ FrameWrap::FrameWrap(GstAllocator *allocator, FrameBuffer *buffer,
|
|||
outstandingPlanes_(0)
|
||||
{
|
||||
for (const FrameBuffer::Plane &plane : buffer->planes()) {
|
||||
GstMemory *mem = gst_fd_allocator_alloc(allocator, plane.fd.fd(),
|
||||
GstMemory *mem = gst_fd_allocator_alloc(allocator, plane.fd.get(),
|
||||
plane.offset + plane.length,
|
||||
GST_FD_MEMORY_FLAG_DONT_CLOSE);
|
||||
gst_memory_resize(mem, plane.offset, plane.length);
|
||||
|
|
|
@ -377,7 +377,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
|
|||
lsTableHandle_ = std::move(ipaConfig.lsTableHandle);
|
||||
if (lsTableHandle_.isValid()) {
|
||||
lsTable_ = mmap(nullptr, ipa::RPi::MaxLsGridSize, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, lsTableHandle_.fd(), 0);
|
||||
MAP_SHARED, lsTableHandle_.get(), 0);
|
||||
|
||||
if (lsTable_ == MAP_FAILED) {
|
||||
LOG(IPARPI, Error) << "dmaHeap mmap failure for LS table.";
|
||||
|
|
|
@ -208,7 +208,7 @@ SharedFD &SharedFD::operator=(SharedFD &&other)
|
|||
*/
|
||||
|
||||
/**
|
||||
* \fn SharedFD::fd()
|
||||
* \fn SharedFD::get()
|
||||
* \brief Retrieve the numerical file descriptor
|
||||
* \return The numerical file descriptor, which may be -1 if the SharedFD
|
||||
* instance is invalid
|
||||
|
@ -227,7 +227,7 @@ SharedFD &SharedFD::operator=(SharedFD &&other)
|
|||
*/
|
||||
UniqueFD SharedFD::dup() const
|
||||
{
|
||||
UniqueFD dupFd(::dup(fd()));
|
||||
UniqueFD dupFd(::dup(get()));
|
||||
if (!dupFd.isValid()) {
|
||||
int ret = -errno;
|
||||
LOG(SharedFD, Error)
|
||||
|
|
|
@ -218,7 +218,7 @@ ino_t fileDescriptorInode(const SharedFD &fd)
|
|||
return 0;
|
||||
|
||||
struct stat st;
|
||||
int ret = fstat(fd.fd(), &st);
|
||||
int ret = fstat(fd.get(), &st);
|
||||
if (ret < 0) {
|
||||
ret = -errno;
|
||||
LOG(Buffer, Fatal)
|
||||
|
|
|
@ -113,7 +113,7 @@ IPCUnixSocket::Payload IPCMessage::payload() const
|
|||
}
|
||||
|
||||
for (const SharedFD &fd : fds_)
|
||||
payload.fds.push_back(fd.fd());
|
||||
payload.fds.push_back(fd.get());
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)
|
|||
std::map<int, MappedBufferInfo> mappedBuffers;
|
||||
|
||||
for (const FrameBuffer::Plane &plane : buffer->planes()) {
|
||||
const int fd = plane.fd.fd();
|
||||
const int fd = plane.fd.get();
|
||||
if (mappedBuffers.find(fd) == mappedBuffers.end()) {
|
||||
const size_t length = lseek(fd, 0, SEEK_END);
|
||||
mappedBuffers[fd] = MappedBufferInfo{ nullptr, 0, length };
|
||||
|
@ -220,7 +220,7 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)
|
|||
}
|
||||
|
||||
for (const FrameBuffer::Plane &plane : buffer->planes()) {
|
||||
const int fd = plane.fd.fd();
|
||||
const int fd = plane.fd.get();
|
||||
auto &info = mappedBuffers[fd];
|
||||
if (!info.address) {
|
||||
void *address = mmap(nullptr, info.mapLength, mmapFlags,
|
||||
|
|
|
@ -1479,7 +1479,7 @@ void RPiCameraData::setIspControls(const ControlList &controls)
|
|||
Span<uint8_t> s = value.data();
|
||||
bcm2835_isp_lens_shading *ls =
|
||||
reinterpret_cast<bcm2835_isp_lens_shading *>(s.data());
|
||||
ls->dmabuf = lsTable_.fd();
|
||||
ls->dmabuf = lsTable_.get();
|
||||
}
|
||||
|
||||
isp_[Isp::Input].dev()->setControls(&ctrls);
|
||||
|
|
|
@ -282,7 +282,7 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const
|
|||
return false;
|
||||
|
||||
for (unsigned int i = 0; i < planes.size(); i++)
|
||||
if (planes_[i].fd != planes[i].fd.fd() ||
|
||||
if (planes_[i].fd != planes[i].fd.get() ||
|
||||
planes_[i].length != planes[i].length)
|
||||
return false;
|
||||
return true;
|
||||
|
@ -1517,9 +1517,9 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
|
|||
if (buf.memory == V4L2_MEMORY_DMABUF) {
|
||||
if (multiPlanar) {
|
||||
for (unsigned int p = 0; p < numV4l2Planes; ++p)
|
||||
v4l2Planes[p].m.fd = planes[p].fd.fd();
|
||||
v4l2Planes[p].m.fd = planes[p].fd.get();
|
||||
} else {
|
||||
buf.m.fd = planes[0].fd.fd();
|
||||
buf.m.fd = planes[0].fd.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ int V4L2Camera::getBufferFd(unsigned int index)
|
|||
if (buffers.size() <= index)
|
||||
return -1;
|
||||
|
||||
return buffers[index]->planes()[0].fd.fd();
|
||||
return buffers[index]->planes()[0].fd.get();
|
||||
}
|
||||
|
||||
int V4L2Camera::streamOn()
|
||||
|
|
|
@ -46,7 +46,7 @@ protected:
|
|||
/* Test creating empty SharedFD. */
|
||||
desc1_ = new SharedFD();
|
||||
|
||||
if (desc1_->fd() != -1) {
|
||||
if (desc1_->get() != -1) {
|
||||
std::cout << "Failed fd numerical check (default constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
|
@ -60,19 +60,19 @@ protected:
|
|||
* descriptor.
|
||||
*/
|
||||
desc1_ = new SharedFD(fd_);
|
||||
if (desc1_->fd() == fd_) {
|
||||
if (desc1_->get() == fd_) {
|
||||
std::cout << "Failed fd numerical check (lvalue ref constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (!isValidFd(fd_) || !isValidFd(desc1_->fd())) {
|
||||
if (!isValidFd(fd_) || !isValidFd(desc1_->get())) {
|
||||
std::cout << "Failed fd validity after construction (lvalue ref constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
int fd = desc1_->fd();
|
||||
int fd = desc1_->get();
|
||||
|
||||
delete desc1_;
|
||||
desc1_ = nullptr;
|
||||
|
@ -91,19 +91,19 @@ protected:
|
|||
int dupFdCopy = dupFd;
|
||||
|
||||
desc1_ = new SharedFD(std::move(dupFd));
|
||||
if (desc1_->fd() != dupFdCopy) {
|
||||
if (desc1_->get() != dupFdCopy) {
|
||||
std::cout << "Failed fd numerical check (rvalue ref constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (dupFd != -1 || !isValidFd(fd_) || !isValidFd(desc1_->fd())) {
|
||||
if (dupFd != -1 || !isValidFd(fd_) || !isValidFd(desc1_->get())) {
|
||||
std::cout << "Failed fd validity after construction (rvalue ref constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
fd = desc1_->fd();
|
||||
fd = desc1_->get();
|
||||
|
||||
delete desc1_;
|
||||
desc1_ = nullptr;
|
||||
|
@ -118,13 +118,14 @@ protected:
|
|||
desc1_ = new SharedFD(fd_);
|
||||
desc2_ = new SharedFD(*desc1_);
|
||||
|
||||
if (desc1_->fd() == fd_ || desc2_->fd() == fd_ || desc1_->fd() != desc2_->fd()) {
|
||||
if (desc1_->get() == fd_ || desc2_->get() == fd_ ||
|
||||
desc1_->get() != desc2_->get()) {
|
||||
std::cout << "Failed fd numerical check (copy constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (!isValidFd(desc1_->fd()) || !isValidFd(desc2_->fd())) {
|
||||
if (!isValidFd(desc1_->get()) || !isValidFd(desc2_->get())) {
|
||||
std::cout << "Failed fd validity after construction (copy constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
|
@ -133,7 +134,7 @@ protected:
|
|||
delete desc1_;
|
||||
desc1_ = nullptr;
|
||||
|
||||
if (!isValidFd(desc2_->fd())) {
|
||||
if (!isValidFd(desc2_->get())) {
|
||||
std::cout << "Failed fd validity after destruction (copy constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
|
@ -144,16 +145,16 @@ protected:
|
|||
|
||||
/* Test creating SharedFD by taking over other SharedFD. */
|
||||
desc1_ = new SharedFD(fd_);
|
||||
fd = desc1_->fd();
|
||||
fd = desc1_->get();
|
||||
desc2_ = new SharedFD(std::move(*desc1_));
|
||||
|
||||
if (desc1_->fd() != -1 || desc2_->fd() != fd) {
|
||||
if (desc1_->get() != -1 || desc2_->get() != fd) {
|
||||
std::cout << "Failed fd numerical check (move constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (!isValidFd(desc2_->fd())) {
|
||||
if (!isValidFd(desc2_->get())) {
|
||||
std::cout << "Failed fd validity after construction (move constructor)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
|
@ -168,16 +169,16 @@ protected:
|
|||
desc1_ = new SharedFD();
|
||||
desc2_ = new SharedFD(fd_);
|
||||
|
||||
fd = desc2_->fd();
|
||||
fd = desc2_->get();
|
||||
*desc1_ = *desc2_;
|
||||
|
||||
if (desc1_->fd() != fd || desc2_->fd() != fd) {
|
||||
if (desc1_->get() != fd || desc2_->get() != fd) {
|
||||
std::cout << "Failed fd numerical check (copy assignment)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (!isValidFd(desc1_->fd()) || !isValidFd(desc2_->fd())) {
|
||||
if (!isValidFd(desc1_->get()) || !isValidFd(desc2_->get())) {
|
||||
std::cout << "Failed fd validity after construction (copy assignment)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
|
@ -192,16 +193,16 @@ protected:
|
|||
desc1_ = new SharedFD();
|
||||
desc2_ = new SharedFD(fd_);
|
||||
|
||||
fd = desc2_->fd();
|
||||
fd = desc2_->get();
|
||||
*desc1_ = std::move(*desc2_);
|
||||
|
||||
if (desc1_->fd() != fd || desc2_->fd() != -1) {
|
||||
if (desc1_->get() != fd || desc2_->get() != -1) {
|
||||
std::cout << "Failed fd numerical check (move assignment)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
if (!isValidFd(desc1_->fd())) {
|
||||
if (!isValidFd(desc1_->get())) {
|
||||
std::cout << "Failed fd validity after construction (move assignment)"
|
||||
<< std::endl;
|
||||
return TestFail;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue