From patchwork Wed Jul 3 08:00:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 1592 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A772D61570 for ; Wed, 3 Jul 2019 10:00:31 +0200 (CEST) Received: from neptunite.flets-east.jp (p1871204-ipngn14001hodogaya.kanagawa.ocn.ne.jp [153.220.127.204]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3E49224B; Wed, 3 Jul 2019 10:00:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562140831; bh=0lfv3ebIrfnTrad1gW5etS9qqRfT+3ME5te7dwLePFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DOnHjHLo2hMaRDI9UJLAT1I4ZltjQM3H0ZRexvsMOQeKEW7+7rNwrjnihDijFE5rr vPrI2epGvz7c1RH/6Xr2gpnT0ZAX6I5KzbttzFpM3jd4FFwle2vMV49gQImtoDRmZj HQvgNFBB59h2sEiB2spu5FYYf+jbm99FKoQD5Omg= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Jul 2019 17:00:04 +0900 Message-Id: <20190703080007.21376-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703080007.21376-1-paul.elder@ideasonboard.com> References: <20190703080007.21376-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 4/7] libcamera: proxy: add default linux proxy X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jul 2019 08:00:31 -0000 Add a default linux proxy. Signed-off-by: Paul Elder --- New in v2 - replaces the dummy/linux default shim src/libcamera/meson.build | 7 +- src/libcamera/proxy/meson.build | 3 + src/libcamera/proxy/proxy_linux_default.cpp | 90 +++++++++++++++++++ src/libcamera/proxy_worker/meson.build | 18 ++++ .../proxy_linux_default_worker.cpp | 46 ++++++++++ 5 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 src/libcamera/proxy/meson.build create mode 100644 src/libcamera/proxy/proxy_linux_default.cpp create mode 100644 src/libcamera/proxy_worker/meson.build create mode 100644 src/libcamera/proxy_worker/proxy_linux_default_worker.cpp diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 412564f..e470fe7 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -65,10 +65,7 @@ includes = [ ] subdir('pipeline') - -proxy_install_dir = join_paths(get_option('libdir'), 'libcamera', 'proxy') -config_h.set('IPA_PROXY_DIR', - '"' + join_paths(get_option('prefix'), proxy_install_dir) + '"') +subdir('proxy') libudev = dependency('libudev', required : false) @@ -103,3 +100,5 @@ libcamera = shared_library('camera', libcamera_dep = declare_dependency(sources : [libcamera_api, libcamera_h], include_directories : libcamera_includes, link_with : libcamera) + +subdir('proxy_worker') diff --git a/src/libcamera/proxy/meson.build b/src/libcamera/proxy/meson.build new file mode 100644 index 0000000..508ed5f --- /dev/null +++ b/src/libcamera/proxy/meson.build @@ -0,0 +1,3 @@ +libcamera_sources += files([ + 'proxy_linux_default.cpp', +]) diff --git a/src/libcamera/proxy/proxy_linux_default.cpp b/src/libcamera/proxy/proxy_linux_default.cpp new file mode 100644 index 0000000..1de028a --- /dev/null +++ b/src/libcamera/proxy/proxy_linux_default.cpp @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * proxy_linux_default.cpp - Default Image Processing Algorithm proxy for Linux + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ipa_module.h" +#include "ipa_proxy.h" +#include "ipc_unixsocket.h" +#include "log.h" +#include "process.h" +#include "process_manager.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(ProxyLinuxDefault) + +class ProxyLinuxDefault : public Proxy +{ +public: + ProxyLinuxDefault(IPAModule *ipam); + ~ProxyLinuxDefault(); + + int init(); + +private: + Process *proc_; + + IPCUnixSocket *socket_; +}; + +int ProxyLinuxDefault::init() +{ + std::cout << "initializing IPA via dummy proxy!" << std::endl; + + return 0; +} + +ProxyLinuxDefault::ProxyLinuxDefault(IPAModule *ipam) + : Proxy(ipam) +{ + std::cout << "initializing dummy proxy: loading IPA from " + << ipam->path() << std::endl; + + std::vector fds; + std::vector args; + args.push_back(ipam->path()); + const std::string path = resolvePath("proxy_linux_default"); + if (path.empty()) + return; + + socket_ = new IPCUnixSocket(); + int fd = socket_->create(); + if (fd < 0) + return; + args.push_back(std::to_string(fd)); + + proc_ = new Process(); + proc_->exec(path, args, fds); + + valid_ = true; + return; +} + +ProxyLinuxDefault::~ProxyLinuxDefault() +{ + if (proc_) + delete proc_; + if (socket_) + delete socket_; +} + +REGISTER_IPA_PROXY(ProxyLinuxDefault) + +}; /* namespace libcamera */ diff --git a/src/libcamera/proxy_worker/meson.build b/src/libcamera/proxy_worker/meson.build new file mode 100644 index 0000000..6f927c5 --- /dev/null +++ b/src/libcamera/proxy_worker/meson.build @@ -0,0 +1,18 @@ +ipa_proxy_sources = [ + ['proxy_linux_default', 'proxy_linux_default_worker.cpp'] +] + +proxy_install_dir = join_paths(get_option('libdir'), 'libcamera', 'proxy') + +foreach t : ipa_proxy_sources + proxy = executable(t[0], + t[1], + name_prefix : '', + include_directories : includes, + install : true, + install_dir : proxy_install_dir, + link_with : libcamera) +endforeach + +config_h.set('IPA_PROXY_DIR', + '"' + join_paths(get_option('prefix'), proxy_install_dir) + '"') diff --git a/src/libcamera/proxy_worker/proxy_linux_default_worker.cpp b/src/libcamera/proxy_worker/proxy_linux_default_worker.cpp new file mode 100644 index 0000000..86b7689 --- /dev/null +++ b/src/libcamera/proxy_worker/proxy_linux_default_worker.cpp @@ -0,0 +1,46 @@ +#include + +#include + +#include + +#include "ipa_module.h" +#include "ipc_unixsocket.h" +#include "utils.h" + +using namespace libcamera; + +int main(int argc, char **argv) +{ + if (argc < 3) { + std::cout << "hello world! no args" << std::endl; + return 0; + } + + int fd = std::stoi(argv[2]); + std::cout << "hello world! we're starting! fd = " << fd << ", path = " << argv[1] << std::endl; + + std::unique_ptr ipam = utils::make_unique(argv[1]); + if (!ipam->isValid() || !ipam->load()) { + std::cerr << "Houston, we have a problem: IPAModule should be valid but isn't" << std::endl; + return -1; + } + + IPCUnixSocket socket; + if (socket.bind(fd) < 0) { + std::cerr << "IPC socket binding failed" << std::endl; + return -1; + } + + std::unique_ptr ipa = ipam->createInstance(); + if (!ipa) { + std::cerr << "Failed to create IPA interface" << std::endl; + return -1; + } + + std::cout << "hello world from the proxy worker!" << std::endl; + + /* TODO IPC listening loop */ + + return 0; +}