Regarding (de)serialization in isolated IPA calls, we have four layers: - struct - byte vector + fd vector - IPCMessage - IPC payload The proxy handles the upper three layers (with help from the IPADataSerializer), and passes an IPCMessage to the IPC mechanism (implemented as an IPCPipe), which sends an IPC payload to its worker counterpart. When a FileDescriptor is involved, previously it was only a FileDescriptor in the first layer; in the lower three it was an int. To reduce the risk of potential fd leaks in the future, keep the FileDescriptor as-is throughout the upper three layers. Only the IPC mechanism will deal with ints, if it so wishes, when it does the actual IPC. IPCPipeUnixSocket does deal with ints for sending fds, so the conversion between IPCMessage and IPCUnixSocket::Payload converts between FileDescriptor and int. Additionally, change the data portion of the serialized form of FileDescriptor to a 32-bit unsigned integer, for alightnment purposes and in preparation for conversion to an index into the fd array. Also update the deserializer of FrameBuffer::Plane accordingly. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Tested-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2020, Google Inc.
|
|
*
|
|
* ipc_pipe.h - Image Processing Algorithm IPC module for IPA proxies
|
|
*/
|
|
#ifndef __LIBCAMERA_INTERNAL_IPA_IPC_H__
|
|
#define __LIBCAMERA_INTERNAL_IPA_IPC_H__
|
|
|
|
#include <vector>
|
|
|
|
#include <libcamera/base/signal.h>
|
|
|
|
#include <libcamera/file_descriptor.h>
|
|
|
|
#include "libcamera/internal/ipc_unixsocket.h"
|
|
|
|
namespace libcamera {
|
|
|
|
class IPCMessage
|
|
{
|
|
public:
|
|
struct Header {
|
|
uint32_t cmd;
|
|
uint32_t cookie;
|
|
};
|
|
|
|
IPCMessage();
|
|
IPCMessage(uint32_t cmd);
|
|
IPCMessage(const Header &header);
|
|
IPCMessage(IPCUnixSocket::Payload &payload);
|
|
|
|
IPCUnixSocket::Payload payload() const;
|
|
|
|
Header &header() { return header_; }
|
|
std::vector<uint8_t> &data() { return data_; }
|
|
std::vector<FileDescriptor> &fds() { return fds_; }
|
|
|
|
const Header &header() const { return header_; }
|
|
const std::vector<uint8_t> &data() const { return data_; }
|
|
const std::vector<FileDescriptor> &fds() const { return fds_; }
|
|
|
|
private:
|
|
Header header_;
|
|
|
|
std::vector<uint8_t> data_;
|
|
std::vector<FileDescriptor> fds_;
|
|
};
|
|
|
|
class IPCPipe
|
|
{
|
|
public:
|
|
IPCPipe();
|
|
virtual ~IPCPipe();
|
|
|
|
bool isConnected() const { return connected_; }
|
|
|
|
virtual int sendSync(const IPCMessage &in,
|
|
IPCMessage *out) = 0;
|
|
|
|
virtual int sendAsync(const IPCMessage &data) = 0;
|
|
|
|
Signal<const IPCMessage &> recv;
|
|
|
|
protected:
|
|
bool connected_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_INTERNAL_IPA_IPC_H__ */
|