[libcamera-devel,RFC,3/4] libcamera: streamformat: add basic class for stream formats

Message ID 20190121230640.8783-4-niklas.soderlund@ragnatech.se
State Rejected
Headers show
Series
  • libcamera: add base for applications to configure cameras
Related show

Commit Message

Niklas Söderlund Jan. 21, 2019, 11:06 p.m. UTC
Each stream in a camera object have its own format specification. The
StreamFormat class holds all this information and should be filled in by
the application to configure a camera.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 include/libcamera/libcamera.h     |  1 +
 include/libcamera/meson.build     |  1 +
 include/libcamera/stream_format.h | 32 ++++++++++++
 src/libcamera/meson.build         |  1 +
 src/libcamera/stream_format.cpp   | 82 +++++++++++++++++++++++++++++++
 5 files changed, 117 insertions(+)
 create mode 100644 include/libcamera/stream_format.h
 create mode 100644 src/libcamera/stream_format.cpp

Patch

diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h
index 272dfd5e4a67d5de..7aefdcee51eca69c 100644
--- a/include/libcamera/libcamera.h
+++ b/include/libcamera/libcamera.h
@@ -13,6 +13,7 @@ 
 #include <libcamera/event_notifier.h>
 #include <libcamera/signal.h>
 #include <libcamera/stream.h>
+#include <libcamera/stream_format.h>
 #include <libcamera/timer.h>
 
 #endif /* __LIBCAMERA_LIBCAMERA_H__ */
diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
index 54a680787e5c17aa..ca4e43fe70e42277 100644
--- a/include/libcamera/meson.build
+++ b/include/libcamera/meson.build
@@ -6,6 +6,7 @@  libcamera_api = files([
     'libcamera.h',
     'signal.h',
     'stream.h',
+    'stream_format.h',
     'timer.h',
 ])
 
diff --git a/include/libcamera/stream_format.h b/include/libcamera/stream_format.h
new file mode 100644
index 0000000000000000..34d93c1c56284e6a
--- /dev/null
+++ b/include/libcamera/stream_format.h
@@ -0,0 +1,32 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * stream_format.h - Stream format interface
+ */
+#ifndef __LIBCAMERA_STREAM_FORMAT_H__
+#define __LIBCAMERA_STREAM_FORMAT_H__
+
+namespace libcamera {
+
+class StreamFormat final
+{
+public:
+	StreamFormat();
+
+	unsigned int width() const { return width_; };
+	unsigned int height() const { return height_; };
+	unsigned int pixelformat() const { return pixelformat_; };
+
+	void setDimension(unsigned int width, unsigned int height);
+	void setPixelFormat(unsigned int pixelformat);
+
+private:
+	unsigned int width_;
+	unsigned int height_;
+	unsigned int pixelformat_;
+};
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_STREAM_FORMAT_H__ */
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index 9f6ff99eebe2f5bc..819b92a511c3ee09 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -11,6 +11,7 @@  libcamera_sources = files([
     'pipeline_handler.cpp',
     'signal.cpp',
     'stream.cpp',
+    'stream_format.cpp',
     'timer.cpp',
     'v4l2_device.cpp',
 ])
diff --git a/src/libcamera/stream_format.cpp b/src/libcamera/stream_format.cpp
new file mode 100644
index 0000000000000000..9171980907b7a840
--- /dev/null
+++ b/src/libcamera/stream_format.cpp
@@ -0,0 +1,82 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * stream_format.cpp - Stream image format settings
+ */
+
+#include <libcamera/stream_format.h>
+
+/**
+ * \file stream_format.h
+ * \brief Stream format specification
+ *
+ * A camera device can provide frames in different resolutions and formats
+ * concurrently from a single image source. The StreamFormat class represents
+ * one of the multiple concurrent streams format.
+ *
+ * All streams exposed by a camera device share the same image source and are
+ * thus not fully independent. Parameters related to the image source, such as
+ * the exposure time or flash control, are common to all streams. Other
+ * parameters, such as format or resolution, may be specified per-stream,
+ * depending on the capabilities of the camera device.
+ */
+
+namespace libcamera {
+
+/**
+ * \class StreamFormat
+ * \brief Stream format settings
+ *
+ * The StreamFormat class models all parameters which an application can set
+ * for a individual stream which is part of a camera device.
+ */
+
+/**
+ * \brief Create a stream format information carrier
+ */
+StreamFormat::StreamFormat()
+	: width_(0), height_(0), pixelformat_(0)
+{
+}
+
+/**
+ * \fn StreamFormat::width()
+ * \brief Retrieve the Stream width
+ * \return The stream width
+ */
+
+/**
+ * \fn StreamFormat::height()
+ * \brief Retrieve the Stream height
+ * \return The stream height
+ */
+
+/**
+ * \fn StreamFormat::pixelformat()
+ * \brief Retrieve the Stream pixelformat
+ * \return The stream pixelformat
+ */
+
+/**
+ * \brief Set the width and height of the stream format
+ * \param[in] width The desired width of the stream
+ * \param[in] height The desired height of the stream
+ */
+void StreamFormat::setDimension(unsigned int width, unsigned int height)
+{
+	width_ = width;
+	height_ = height;
+}
+
+/**
+ * \brief Set the pixelformat of the stream format
+ * \param[in] pixelformat The desired pixelformat of the stream
+ */
+void StreamFormat::setPixelFormat(unsigned int pixelformat)
+{
+	pixelformat_ = pixelformat;
+}
+
+
+} /* namespace libcamera */