summaryrefslogtreecommitdiff
BranchCommit messageAuthorAge
imx8mp/extensible-formatipa: rkisp1: Use the extensible parameters formatJacopo Mondi8 months
imx8mp/extensible-format-v8ipa: rkisp1: params: Update to v8Jacopo Mondi6 months
imx8mp/extensible-format-v9rkisp1: params: update to v9Jacopo Mondi6 months
isi/raw_sensorlibcamera: imx8-isi: Split Bayer/YUV config generationJacopo Mondi2 years
isi/raw_sensor_v2fixup! libcamera: imx8-isi: Break out YUV format selectionJacopo Mondi2 years
jmondi/android/ndk/pinephoneproandroid: data: Add camera HAL config for PinephoneProJacopo Mondi2 years
jmondi/android/pinephoneproandroid: Fix improper file descriptor enumerationNicholas Roth2 years
jmondi/android/vndkipa: workaround libcxx duration limitationNicholas Roth16 months
jmondi/device-match-generalize[HACK] libcamera: pipeline: Add usb-test pipelineJacopo Mondi18 months
jmondi/imx8mp/debix-aipa: rkisp1: agc: Load ExposureValue from configJacopo Mondi23 months
jmondi/lc-compliance-crosWIP: test controls in a RequestJacopo Mondi14 months
jmondi/pinephonelibcamera: v4l2_pixelformat: Map formats::MJPEG to V4L2_PIX_FMT_JPEGJacopo Mondi3 years
jmondi/pinephonepro[WIP] camera_sensor: Do not consider FOV in getFormat()Jacopo Mondi2 years
jmondi/pinephonepro-af[HACK] ipa: af: Force AfModeContinuousJacopo Mondi17 months
jmondi/rk3399/google-dru-scarletipa: rkisp1: Add tuning files for Google DRU "Scarlet" sensorsJacopo Mondi23 months
jmondi/rockpi/af/imx519ipa: algorithms: af: Do not inherit from AlgorithmJacopo Mondi3 years
jmondi/rpi5-on-mainlinedebugJacopo Mondi13 months
multicontext/rpi/v3HACK: acquire media device non-exclusiveleyJacopo Mondi6 months
pfc/rkisp1-free-runipa: rkisp1: Initialize FrameContext.agc.meteringModeJacopo Mondi4 months
pfc/rkisp1-free-run-upstreaminglibcamera: rkisp1: Create main buffer pool out of if(!isRaw)Jacopo Mondi4 months
pfc/rkisp1-free-run-v2ipa: rkisp1: Have algos initialize FrameContextJacopo Mondi4 months
rcar-gen4libcamera: introduce rcar-gen4 supportJacopo Mondi6 weeks
yaml-emitterWIPJacopo Mondi4 months
 
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 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * v4l2_subdevice.cpp - V4L2 Subdevice
 */

#include "libcamera/internal/v4l2_subdevice.h"

#include <fcntl.h>
#include <iomanip>
#include <regex>
#include <sstream>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include <linux/media-bus-format.h>
#include <linux/v4l2-subdev.h>

#include <libcamera/geometry.h>

#include <libcamera/base/log.h>
#include <libcamera/base/utils.h>

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

/**
 * \file v4l2_subdevice.h
 * \brief V4L2 Subdevice API
 */

namespace libcamera {

LOG_DECLARE_CATEGORY(V4L2)

namespace {

/*
 * \struct V4L2SubdeviceFormatInfo
 * \brief Information about media bus formats
 * \param bitsPerPixel Bits per pixel
 * \param name Name of MBUS format
 */
struct V4L2SubdeviceFormatInfo {
	unsigned int bitsPerPixel;
	const char *name;
};

/*
 * \var formatInfoMap
 * \brief A map that associates V4L2SubdeviceFormatInfo struct to V4L2 media
 * bus codes
 */
const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {
	{ V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE, { 16, "RGB444_2X8_PADHI_BE" } },
	{ V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, { 16, "RGB444_2X8_PADHI_LE" } },
	{ V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, { 16, "RGB555_2X8_PADHI_BE" } },
	{ V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, { 16, "RGB555_2X8_PADHI_LE" } },
	{ V4L2_MBUS_FMT_BGR565_2X8_BE, { 16, "BGR565_2X8_BE" } },
	{ V4L2_MBUS_FMT_BGR565_2X8_LE, { 16, "BGR565_2X8_LE" } },
	{ V4L2_MBUS_FMT_RGB565_2X8_BE, { 16, "RGB565_2X8_BE" } },
	{ V4L2_MBUS_FMT_RGB565_2X8_LE, { 16, "RGB565_2X8_LE" } },
	{ V4L2_MBUS_FMT_RGB666_1X18, { 18, "RGB666_1X18" } },
	{ V4L2_MBUS_FMT_RGB888_1X24, { 24, "RGB888_1X24" } },
	{ V4L2_MBUS_FMT_RGB888_2X12_BE, { 24, "RGB888_2X12_BE" } },
	{ V4L2_MBUS_FMT_RGB888_2X12_LE, { 24, "RGB888_2X12_LE" } },
	{ V4L2_MBUS_FMT_ARGB8888_1X32, { 32, "ARGB8888_1X32" } },
	{ V4L2_MBUS_FMT_Y8_1X8, { 8, "Y8_1X8" } },
	{ V4L2_MBUS_FMT_UV8_1X8, { 8, "UV8_1X8" } },
	{ V4L2_MBUS_FMT_UYVY8_1_5X8, { 12, "UYVY8_1_5X8" } },
	{ V4L2_MBUS_FMT_VYUY8_1_5X8, { 12, "VYUY8_1_5X8" } },
	{ V4L2_MBUS_FMT_YUYV8_1_5X8, { 12, "YUYV8_1_5X8" } },
	{ V4L2_MBUS_FMT_YVYU8_1_5X8, { 12, "YVYU8_1_5X8" } },
	{ V4L2_MBUS_FMT_UYVY8_2X8, { 16, "UYVY8_2X8" } },
	{ V4L2_MBUS_FMT_VYUY8_2X8, { 16, "VYUY8_2X8" } },
	{ V4L2_MBUS_FMT_YUYV8_2X8, { 16, "YUYV8_2X8" } },
	{ V4L2_MBUS_FMT_YVYU8_2X8, { 16, "YVYU8_2X8" } },
	{ V4L2_MBUS_FMT_Y10_1X10, { 10, "Y10_1X10" } },
	{ V4L2_MBUS_FMT_UYVY10_2X10, { 20, "UYVY10_2X10" } },
	{ V4L2_MBUS_FMT_VYUY10_2X10, { 20, "VYUY10_2X10" } },
	{ V4L2_MBUS_FMT_YUYV10_2X10, { 20, "YUYV10_2X10" } },
	{ V4L2_MBUS_FMT_YVYU10_2X10, { 20, "YVYU10_2X10" } },
	{ V4L2_MBUS_FMT_Y12_1X12, { 12, "Y12_1X12" } },
	{ V4L2_MBUS_FMT_UYVY8_1X16, { 16, "UYVY8_1X16" } },
	{ V4L2_MBUS_FMT_VYUY8_1X16, { 16, "VYUY8_1X16" } },
	{ V4L2_MBUS_FMT_YUYV8_1X16, { 16, "YUYV8_1X16" } },
	{ V4L2_MBUS_FMT_YVYU8_1X16, { 16, "YVYU8_1X16" } },
	{ V4L2_MBUS_FMT_YDYUYDYV8_1X16, { 16, "YDYUYDYV8_1X16" } },
	{ V4L2_MBUS_FMT_UYVY10_1X20, { 20, "UYVY10_1X20" } },
	{ V4L2_MBUS_FMT_VYUY10_1X20, { 20, "VYUY10_1X20" } },
	{ V4L2_MBUS_FMT_YUYV10_1X20, { 20, "YUYV10_1X20" } },
	{ V4L2_MBUS_FMT_YVYU10_1X20, { 20, "YVYU10_1X20" } },
	{ V4L2_MBUS_FMT_YUV10_1X30, { 30, "YUV10_1X30" } },
	{ V4L2_MBUS_FMT_AYUV8_1X32, { 32, "AYUV8_1X32" } },
	{ V4L2_MBUS_FMT_UYVY12_2X12, { 24, "UYVY12_2X12" } },
	{ V4L2_MBUS_FMT_VYUY12_2X12, { 24, "VYUY12_2X12" } },
	{ V4L2_MBUS_FMT_YUYV12_2X12, { 24, "YUYV12_2X12" } },
	{ V4L2_MBUS_FMT_YVYU12_2X12, { 24, "YVYU12_2X12" } },
	{ V4L2_MBUS_FMT_UYVY12_1X24, { 24, "UYVY12_1X24" } },
	{ V4L2_MBUS_FMT_VYUY12_1X24, { 24, "VYUY12_1X24" } },
	{ V4L2_MBUS_FMT_YUYV12_1X24, { 24, "YUYV12_1X24" } },
	{ V4L2_MBUS_FMT_YVYU12_1X24, { 24, "YVYU12_1X24" } },
	{ V4L2_MBUS_FMT_SBGGR8_1X8, { 8, "SBGGR8_1X8" } },
	{ V4L2_MBUS_FMT_SGBRG8_1X8, { 8, "SGBRG8_1X8" } },
	{ V4L2_MBUS_FMT_SGRBG8_1X8, { 8, "SGRBG8_1X8" } },
	{ V4L2_MBUS_FMT_SRGGB8_1X8, { 8, "SRGGB8_1X8" } },
	{ V4L2_MBUS_FMT_SBGGR10_ALAW8_1X8, { 8, "SBGGR10_ALAW8_1X8" } },
	{ V4L2_MBUS_FMT_SGBRG10_ALAW8_1X8, { 8, "SGBRG10_ALAW8_1X8" } },
	{ V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8, { 8, "SGRBG10_ALAW8_1X8" } },
	{ V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8, { 8, "SRGGB10_ALAW8_1X8" } },
	{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, { 8, "SBGGR10_DPCM8_1X8" } },
	{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, { 8, "SGBRG10_DPCM8_1X8" } },