From 84ad104499d9efc0253dae1a60ee070ed375ad95 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 20 Oct 2022 00:44:55 +0300 Subject: Move test applications to src/apps/ The cam and qcam test application share code, currently through a crude hack that references the cam source files directly from the qcam meson.build file. To prepare for the introduction of hosting that code in a static library, move all applications to src/apps/. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/cam/file_sink.cpp | 137 -------------------------------------------------- 1 file changed, 137 deletions(-) delete mode 100644 src/cam/file_sink.cpp (limited to 'src/cam/file_sink.cpp') diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp deleted file mode 100644 index 9d60c04e..00000000 --- a/src/cam/file_sink.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * file_sink.cpp - File Sink - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "dng_writer.h" -#include "file_sink.h" -#include "image.h" - -using namespace libcamera; - -FileSink::FileSink(const libcamera::Camera *camera, - const std::map &streamNames, - const std::string &pattern) - : camera_(camera), streamNames_(streamNames), pattern_(pattern) -{ -} - -FileSink::~FileSink() -{ -} - -int FileSink::configure(const libcamera::CameraConfiguration &config) -{ - int ret = FrameSink::configure(config); - if (ret < 0) - return ret; - - return 0; -} - -void FileSink::mapBuffer(FrameBuffer *buffer) -{ - std::unique_ptr image = - Image::fromFrameBuffer(buffer, Image::MapMode::ReadOnly); - assert(image != nullptr); - - mappedBuffers_[buffer] = std::move(image); -} - -bool FileSink::processRequest(Request *request) -{ - for (auto [stream, buffer] : request->buffers()) - writeBuffer(stream, buffer, request->metadata()); - - return true; -} - -void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer, - [[maybe_unused]] const ControlList &metadata) -{ - std::string filename; - size_t pos; - int fd, ret = 0; - - if (!pattern_.empty()) - filename = pattern_; - -#ifdef HAVE_TIFF - bool dng = filename.find(".dng", filename.size() - 4) != std::string::npos; -#endif /* HAVE_TIFF */ - - if (filename.empty() || filename.back() == '/') - filename += "frame-#.bin"; - - pos = filename.find_first_of('#'); - if (pos != std::string::npos) { - std::stringstream ss; - ss << streamNames_[stream] << "-" << std::setw(6) - << std::setfill('0') << buffer->metadata().sequence; - filename.replace(pos, 1, ss.str()); - } - - Image *image = mappedBuffers_[buffer].get(); - -#ifdef HAVE_TIFF - if (dng) { - ret = DNGWriter::write(filename.c_str(), camera_, - stream->configuration(), metadata, - buffer, image->data(0).data()); - if (ret < 0) - std::cerr << "failed to write DNG file `" << filename - << "'" << std::endl; - - return; - } -#endif /* HAVE_TIFF */ - - fd = open(filename.c_str(), O_CREAT | O_WRONLY | - (pos == std::string::npos ? O_APPEND : O_TRUNC), - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - if (fd == -1) { - ret = -errno; - std::cerr << "failed to open file " << filename << ": " - << strerror(-ret) << std::endl; - return; - } - - for (unsigned int i = 0; i < buffer->planes().size(); ++i) { - const FrameMetadata::Plane &meta = buffer->metadata().planes()[i]; - - Span data = image->data(i); - unsigned int length = std::min(meta.bytesused, data.size()); - - if (meta.bytesused > data.size()) - std::cerr << "payload size " << meta.bytesused - << " larger than plane size " << data.size() - << std::endl; - - ret = ::write(fd, data.data(), length); - if (ret < 0) { - ret = -errno; - std::cerr << "write error: " << strerror(-ret) - << std::endl; - break; - } else if (ret != (int)length) { - std::cerr << "write error: only " << ret - << " bytes written instead of " - << length << std::endl; - break; - } - } - - close(fd); -} -- cgit v1.2.1