summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-09-02 12:17:09 +0200
committerJacopo Mondi <jacopo@jmondi.org>2020-09-18 11:31:56 +0200
commit45fe8e99c83889816df320c6d27f7a2019744693 (patch)
tree85905a9a7f873d362f782977d2fc742942b985d4
parentfacadb188efa32e0846fb59b73d8d669b7686e29 (diff)
android: camera_device: Make CameraStream a class
Complete the transformation of CameraStream into a class and provide a read-only interface that allows to access its parameters but not modify them at run-time. No functional changes intended but this change aims to make the code more robust by enforcing a stricter interface in the CameraStream class. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r--src/android/camera_device.cpp11
-rw-r--r--src/android/camera_device.h14
2 files changed, 14 insertions, 11 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index b245c9a1..70d77a17 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -169,8 +169,9 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer,
}
}
-CameraStream::CameraStream(PixelFormat f, Size s, unsigned int i, Encoder *e)
- : format(f), size(s), index_(i), encoder_(e)
+CameraStream::CameraStream(PixelFormat format, Size size,
+ unsigned int index, Encoder *encoder)
+ : format_(format), size_(size), index_(index), encoder_(encoder)
{
}
@@ -1409,7 +1410,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
descriptor->buffers[i].buffer = camera3Buffers[i].buffer;
/* Software streams are handled after hardware streams complete. */
- if (cameraStream->format == formats::MJPEG)
+ if (cameraStream->format() == formats::MJPEG)
continue;
/*
@@ -1473,7 +1474,7 @@ void CameraDevice::requestComplete(Request *request)
CameraStream *cameraStream =
static_cast<CameraStream *>(descriptor->buffers[i].stream->priv);
- if (cameraStream->format != formats::MJPEG)
+ if (cameraStream->format() != formats::MJPEG)
continue;
Encoder *encoder = cameraStream->encoder();
@@ -1508,7 +1509,7 @@ void CameraDevice::requestComplete(Request *request)
exif.setMake("libcamera");
exif.setModel("cameraModel");
exif.setOrientation(orientation_);
- exif.setSize(cameraStream->size);
+ exif.setSize(cameraStream->size());
/*
* We set the frame's EXIF timestamp as the time of encode.
* Since the precision we need for EXIF timestamp is only one
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 49a2e7f3..1837748d 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -27,18 +27,20 @@
class CameraMetadata;
-struct CameraStream {
+class CameraStream
+{
public:
- CameraStream(libcamera::PixelFormat, libcamera::Size, unsigned int i,
- Encoder *e = nullptr);
+ CameraStream(libcamera::PixelFormat format, libcamera::Size size,
+ unsigned int index, Encoder *encoder = nullptr);
+ const libcamera::PixelFormat &format() const { return format_; }
+ const libcamera::Size &size() const { return size_; }
unsigned int index() const { return index_; }
Encoder *encoder() const { return encoder_.get(); }
- libcamera::PixelFormat format;
- libcamera::Size size;
-
private:
+ libcamera::PixelFormat format_;
+ libcamera::Size size_;
/*
* The index of the libcamera StreamConfiguration as added during
* configureStreams(). A single libcamera Stream may be used to deliver
lass="hl ppc">#include "libcamera/internal/message.h" #include "libcamera/internal/semaphore.h" #include "libcamera/internal/thread.h" /** * \file object.h * \brief Base object to support automatic signal disconnection */ namespace libcamera { LOG_DEFINE_CATEGORY(Object) /** * \class Object * \brief Base object to support automatic signal disconnection * * The Object class simplifies signal/slot handling for classes implementing * slots. By inheriting from Object, an object is automatically disconnected * from all connected signals when it gets destroyed. * * Object instances are bound to the thread of their parent, or the thread in * which they're created when they have no parent. When a message is posted to * an object, its handler will run in the object's thread. This allows * implementing easy message passing between threads by inheriting from the * Object class. * * Deleting an object from a thread other than the one the object is bound to is * unsafe, unless the caller ensures that the object isn't processing any * message concurrently. * * Object slots connected to signals will also run in the context of the * object's thread, regardless of whether the signal is emitted in the same or * in another thread. * * \sa Message, Signal, Thread */ /** * \brief Construct an Object instance * \param[in] parent The object parent * * The new Object instance is bound to the thread of its \a parent, or to the * current thread if the \a parent is nullptr. */ Object::Object(Object *parent) : parent_(parent), pendingMessages_(0) { thread_ = parent ? parent->thread() : Thread::current(); if (parent) parent->children_.push_back(this); } /** * \brief Destroy an Object instance * * Deleting an Object automatically disconnects all signals from the Object's * slots. All the Object's children are made orphan, but stay bound to their * current thread. * * Object instances shall be destroyed from the thread they are bound to, * otherwise undefined behaviour may occur. If deletion of an Object needs to * be scheduled from a different thread, deleteLater() shall be used. */ Object::~Object() { /* * Move signals to a private list to avoid concurrent iteration and * deletion of items from Signal::disconnect(). */ std::list<SignalBase *> signals(std::move(signals_)); for (SignalBase *signal : signals) signal->disconnect(this); if (pendingMessages_) thread()->removeMessages(this); if (parent_) { auto it = std::find(parent_->children_.begin(), parent_->children_.end(), this); ASSERT(it != parent_->children_.end()); parent_->children_.erase(it); } for (auto child : children_) child->parent_ = nullptr; } /** * \brief Schedule deletion of the instance in the thread it belongs to * * This function schedules deletion of the Object when control returns to the * event loop that the object belongs to. This ensures the object is destroyed * from the right context, as required by the libcamera threading model. * * If this function is called before the thread's event loop is started, the * object will be deleted when the event loop starts. * * Deferred deletion can be used to control the destruction context with shared * pointers. An object managed with shared pointers is deleted when the last * reference is destroyed, which makes difficult to ensure through software * design which context the deletion will take place in. With a custom deleter