summaryrefslogtreecommitdiff
path: root/include/android
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2021-04-19 12:53:19 +0200
committerJacopo Mondi <jacopo@jmondi.org>2021-05-06 15:09:42 +0200
commitfcfb1dc02a6baed23a85aa1186dc8aa9b2217f49 (patch)
tree9f0577e9155af27983b2632911c0c5d95e55ce6d /include/android
parent131b2096937b070fa9348705996d269db5a74eb1 (diff)
libcamera: raspberry: Report sensor timestamp
Report the sensor's timestamp in the Request metadata by using the Unicam::Image buffer timestamp as an initial approximation. The buffer's timestamp is recorded at DMA-transfer time, and it does not theoretically matches the 'start of exposure' definition, but when used to compare two consecutive frames it gives an acceptable estimation of the sensor frame period duration. Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Naushir Patuck <naush@raspberrypi.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'include/android')
0 files changed, 0 insertions, 0 deletions
ef='#n52'>52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2018, Google Inc.
 *
 * media_object.cpp - Media device objects: entities, pads and links
 */

#include "libcamera/internal/media_object.h"

#include <errno.h>
#include <string>
#include <string.h>
#include <unistd.h>
#include <vector>

#include <linux/media.h>

#include "libcamera/internal/log.h"
#include "libcamera/internal/media_device.h"

/**
 * \file media_object.h
 * \brief Provides a class hierarchy that represents the  media objects exposed
 * by the Linux kernel Media Controller APIs.
 *
 * The abstract MediaObject class represents any Media Controller graph object
 * identified by an id unique in the media device context. It is subclassed by
 * the MediaEntity, MediaPad and MediaLink classes that represent the entities,
 * pads and links respectively. They are populated based on the media graph
 * information exposed by the Linux kernel through the MEDIA_IOC_G_TOPOLOGY
 * ioctl.
 *
 * As the media objects represent their kernel counterpart, information about
 * the properties they expose can be found in the Linux kernel documentation.
 *
 * All media objects are meant to be created and destroyed solely by the
 * MediaDevice and thus have private constructors and destructors.
 */

namespace libcamera {

LOG_DECLARE_CATEGORY(MediaDevice)

/**
 * \class MediaObject
 * \brief Base class for all media objects
 *
 * MediaObject is an abstract base class for all media objects in the
 * media graph. Each object is identified by a reference to the media
 * device it belongs to and a unique id within that media device.
 * This base class provide helpers to media objects to keep track of
 * these identifiers.
 *
 * \sa MediaEntity, MediaPad, MediaLink
 */

/**
 * \fn MediaObject::MediaObject()
 * \brief Construct a MediaObject part of the MediaDevice \a dev,
 * identified by the \a id unique within the device
 * \param[in] dev The media device this object belongs to
 * \param[in] id The media object id
 *
 * The caller shall ensure unicity of the object id in the media device context.
 * This constraint is neither enforced nor checked by the MediaObject.
 */

/**
 * \fn MediaObject::device()
 * \brief Retrieve the media device the media object belongs to
 * \return The MediaDevice
 */

/**
 * \fn MediaObject::id()
 * \brief Retrieve the media object id
 * \return The media object id
 */

/**
 * \var MediaObject::dev_
 * \brief The media device the media object belongs to
 */

/**
 * \var MediaObject::id_
 * \brief The media object id
 */

/**
 * \class MediaLink
 * \brief The MediaLink represents a link between two pads in the media graph.
 *
 * Links are created from the information provided by the Media Controller API
 * in the media_v2_link structure. They reference the source() and sink() pads
 * they connect and track the link status through link flags().
 *
 * Each link is referenced in the link array of both of the pads it connect.
 */

/**
 * \brief Enable or disable a link
 * \param[in] enable True to enable the link, false to disable it
 *
 * Set the status of a link according to the value of \a enable.
 * Links between two pads can be set to the enabled or disabled state freely,
 * unless they're immutable links, whose status cannot be changed.
 * Enabling an immutable link is not considered an error, while trying to
 * disable it is.
 *
 * Enabling a link establishes a data connection between two pads, while
 * disabling it interrupts that connection.
 *
 * \return 0 on success or a negative error code otherwise
 */
int MediaLink::setEnabled(bool enable)
{
	unsigned int flags = (flags_ & ~MEDIA_LNK_FL_ENABLED)
			   | (enable ? MEDIA_LNK_FL_ENABLED : 0);

	int ret = dev_->setupLink(this, flags);
	if (ret)
		return ret;

	flags_ = flags;

	return 0;
}

/**
 * \brief Construct a MediaLink
 * \param[in] link The media link kernel data
 * \param[in] source The source pad at the origin of the link
 * \param[in] sink The sink pad at the destination of the link
 */
MediaLink::MediaLink(const struct media_v2_link *link, MediaPad *source,
		     MediaPad *sink)
	: MediaObject(source->device(), link->id), source_(source),
	  sink_(sink), flags_(link->flags)
{
}

/**
 * \fn MediaLink::source()
 * \brief Retrieve the link's source pad