mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-13 15:29:45 +03:00
Source files in libcamera start by a comment block header, which includes the file name and a one-line description of the file contents. While the latter is useful to get a quick overview of the file contents at a glance, the former is mostly a source of inconvenience. The name in the comments can easily get out of sync with the file name when files are renamed, and copy & paste during development have often lead to incorrect names being used to start with. Readers of the source code are expected to know which file they're looking it. Drop the file name from the header comment block. The change was generated with the following script: ---------------------------------------- dirs="include/libcamera src test utils" declare -rA patterns=( ['c']=' \* ' ['cpp']=' \* ' ['h']=' \* ' ['py']='# ' ['sh']='# ' ) for ext in ${!patterns[@]} ; do files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done) pattern=${patterns[${ext}]} for file in $files ; do name=$(basename ${file}) sed -i "s/^\(${pattern}\)${name} - /\1/" "$file" done done ---------------------------------------- This misses several files that are out of sync with the comment block header. Those will be addressed separately and manually. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
173 lines
3.8 KiB
C++
173 lines
3.8 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Collabora Ltd.
|
|
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
|
|
*
|
|
* GStreamer Capture Pad
|
|
*/
|
|
|
|
#include "gstlibcamerapad.h"
|
|
|
|
#include <libcamera/stream.h>
|
|
|
|
#include "gstlibcamera-utils.h"
|
|
|
|
using namespace libcamera;
|
|
|
|
struct _GstLibcameraPad {
|
|
GstPad parent;
|
|
StreamRole role;
|
|
GstLibcameraPool *pool;
|
|
GstClockTime latency;
|
|
};
|
|
|
|
enum {
|
|
PROP_0,
|
|
PROP_STREAM_ROLE
|
|
};
|
|
|
|
G_DEFINE_TYPE(GstLibcameraPad, gst_libcamera_pad, GST_TYPE_PAD)
|
|
|
|
static void
|
|
gst_libcamera_pad_set_property(GObject *object, guint prop_id,
|
|
const GValue *value, GParamSpec *pspec)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(object);
|
|
GLibLocker lock(GST_OBJECT(self));
|
|
|
|
switch (prop_id) {
|
|
case PROP_STREAM_ROLE:
|
|
self->role = (StreamRole)g_value_get_enum(value);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void
|
|
gst_libcamera_pad_get_property(GObject *object, guint prop_id, GValue *value,
|
|
GParamSpec *pspec)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(object);
|
|
GLibLocker lock(GST_OBJECT(self));
|
|
|
|
switch (prop_id) {
|
|
case PROP_STREAM_ROLE:
|
|
g_value_set_enum(value, static_cast<gint>(self->role));
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static gboolean
|
|
gst_libcamera_pad_query(GstPad *pad, GstObject *parent, GstQuery *query)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(pad);
|
|
|
|
if (query->type != GST_QUERY_LATENCY)
|
|
return gst_pad_query_default(pad, parent, query);
|
|
|
|
/* TRUE here means live, we assumes that max latency is the same as min
|
|
* as we have no idea that duration of frames. */
|
|
gst_query_set_latency(query, TRUE, self->latency, self->latency);
|
|
return TRUE;
|
|
}
|
|
|
|
static void
|
|
gst_libcamera_pad_init(GstLibcameraPad *self)
|
|
{
|
|
GST_PAD_QUERYFUNC(self) = gst_libcamera_pad_query;
|
|
}
|
|
|
|
static GType
|
|
gst_libcamera_stream_role_get_type()
|
|
{
|
|
static GType type = 0;
|
|
static const GEnumValue values[] = {
|
|
{
|
|
static_cast<gint>(StreamRole::StillCapture),
|
|
"libcamera::StillCapture",
|
|
"still-capture",
|
|
}, {
|
|
static_cast<gint>(StreamRole::VideoRecording),
|
|
"libcamera::VideoRecording",
|
|
"video-recording",
|
|
}, {
|
|
static_cast<gint>(StreamRole::Viewfinder),
|
|
"libcamera::Viewfinder",
|
|
"view-finder",
|
|
},
|
|
{ 0, NULL, NULL }
|
|
};
|
|
|
|
if (!type)
|
|
type = g_enum_register_static("GstLibcameraStreamRole", values);
|
|
|
|
return type;
|
|
}
|
|
|
|
static void
|
|
gst_libcamera_pad_class_init(GstLibcameraPadClass *klass)
|
|
{
|
|
auto *object_class = G_OBJECT_CLASS(klass);
|
|
|
|
object_class->set_property = gst_libcamera_pad_set_property;
|
|
object_class->get_property = gst_libcamera_pad_get_property;
|
|
|
|
auto *spec = g_param_spec_enum("stream-role", "Stream Role",
|
|
"The selected stream role",
|
|
gst_libcamera_stream_role_get_type(),
|
|
static_cast<gint>(StreamRole::VideoRecording),
|
|
(GParamFlags)(GST_PARAM_MUTABLE_READY
|
|
| G_PARAM_CONSTRUCT
|
|
| G_PARAM_READWRITE
|
|
| G_PARAM_STATIC_STRINGS));
|
|
g_object_class_install_property(object_class, PROP_STREAM_ROLE, spec);
|
|
}
|
|
|
|
StreamRole
|
|
gst_libcamera_pad_get_role(GstPad *pad)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(pad);
|
|
GLibLocker lock(GST_OBJECT(self));
|
|
return self->role;
|
|
}
|
|
|
|
GstLibcameraPool *
|
|
gst_libcamera_pad_get_pool(GstPad *pad)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(pad);
|
|
return self->pool;
|
|
}
|
|
|
|
void
|
|
gst_libcamera_pad_set_pool(GstPad *pad, GstLibcameraPool *pool)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(pad);
|
|
|
|
if (self->pool)
|
|
g_object_unref(self->pool);
|
|
self->pool = pool;
|
|
}
|
|
|
|
Stream *
|
|
gst_libcamera_pad_get_stream(GstPad *pad)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(pad);
|
|
|
|
if (self->pool)
|
|
return gst_libcamera_pool_get_stream(self->pool);
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void
|
|
gst_libcamera_pad_set_latency(GstPad *pad, GstClockTime latency)
|
|
{
|
|
auto *self = GST_LIBCAMERA_PAD(pad);
|
|
GLibLocker lock(GST_OBJECT(self));
|
|
self->latency = latency;
|
|
}
|