summaryrefslogtreecommitdiff
path: root/src/gstreamer/gstlibcamerasrc.h
blob: fdea2f10d95d5c449ae760b8dac15f5b58e92c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Collabora Ltd.
 *     Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
 *
 * gstlibcamerasrc.h - GStreamer Capture Element
 */

#pragma once

#include <gst/gst.h>

G_BEGIN_DECLS

#define GST_TYPE_LIBCAMERA_SRC gst_libcamera_src_get_type()
G_DECLARE_FINAL_TYPE(GstLibcameraSrc, gst_libcamera_src,
		     GST_LIBCAMERA, SRC, GstElement)

G_END_DECLS
='#n44'>44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
.. SPDX-License-Identifier: CC-BY-SA-4.0

.. _python-bindings:

Python Bindings for libcamera
=============================

.. warning::
    The bindings are under work, and the API will change.

Differences to the C++ API
--------------------------

As a rule of thumb the bindings try to follow the C++ API when possible. This
chapter lists the differences.

Mostly these differences fall under two categories:

1. Differences caused by the inherent differences between C++ and Python.
   These differences are usually caused by the use of threads or differences in
   C++ vs Python memory management.

2. Differences caused by the code being work-in-progress. It's not always
   trivial to create a binding in a satisfying way, and the current bindings
   contain simplified versions of the C++ API just to get forward. These
   differences are expected to eventually go away.

Coding Style
------------

The C++ code for the bindings follows the libcamera coding style as much as
possible. Note that the indentation does not quite follow the clang-format
style, as clang-format makes a mess of the style used.

The API visible to the Python side follows the Python style as much as possible.

This means that e.g. ``Camera::generateConfiguration`` maps to
``Camera.generate_configuration``.

CameraManager
-------------

The Python API provides a singleton CameraManager via ``CameraManager.singleton()``.
There is no need to start or stop the CameraManager.

Handling Completed Requests
---------------------------

The Python bindings do not expose the ``Camera::requestCompleted`` signal
directly as the signal is invoked from another thread and it has real-time
constraints. Instead the bindings queue the completed requests internally and
use an eventfd to inform the user that there are completed requests.

The user can wait on the eventfd, and upon getting an event, use
``CameraManager.get_ready_requests()`` to clear the eventfd event and to get
the completed requests.

Controls & Properties
---------------------

The classes related to controls and properties are rather complex to implement
directly in the Python bindings. There are some simplifications in the Python
bindings:

- There is no ControlValue class. Python objects are automatically converted
  to ControlValues and vice versa.
- There is no ControlList class. A Python dict with ControlId keys and Python
  object values is used instead.
- There is no ControlInfoMap class. A Python dict with ControlId keys and
  ControlInfo values is used instead.