summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/android')
-rw-r--r--src/android/camera_device.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index c219ea84..4a19aa03 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1265,6 +1265,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
streams_.clear();
streams_.reserve(stream_list->num_streams);
+ std::vector<Camera3StreamConfig> streamConfigs;
+ streamConfigs.reserve(stream_list->num_streams);
+
/* First handle all non-MJPEG streams. */
camera3_stream_t *jpegStream = nullptr;
for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
@@ -1295,14 +1298,11 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
continue;
}
- StreamConfiguration streamConfiguration;
- streamConfiguration.size = size;
- streamConfiguration.pixelFormat = format;
-
- config_->addConfiguration(streamConfiguration);
- streams_.emplace_back(this, CameraStream::Type::Direct,
- stream, config_->size() - 1);
- stream->priv = static_cast<void *>(&streams_.back());
+ Camera3StreamConfig streamConfig;
+ streamConfig.streams = { { stream, CameraStream::Type::Direct } };
+ streamConfig.config.size = size;
+ streamConfig.config.pixelFormat = format;
+ streamConfigs.push_back(std::move(streamConfig));
}
/* Now handle the MJPEG streams, adding a new stream if required. */
@@ -1311,8 +1311,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
int index = -1;
/* Search for a compatible stream in the non-JPEG ones. */
- for (unsigned int i = 0; i < config_->size(); i++) {
- StreamConfiguration &cfg = config_->at(i);
+ for (size_t i = 0; i < streamConfigs.size(); ++i) {
+ const auto &cfg = streamConfigs[i].config;
/*
* \todo The PixelFormat must also be compatible with
@@ -1335,28 +1335,36 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
* introduce a new stream to satisfy the request requirements.
*/
if (index < 0) {
- StreamConfiguration streamConfiguration;
-
/*
* \todo The pixelFormat should be a 'best-fit' choice
* and may require a validation cycle. This is not yet
* handled, and should be considered as part of any
* stream configuration reworks.
*/
- streamConfiguration.size.width = jpegStream->width;
- streamConfiguration.size.height = jpegStream->height;
- streamConfiguration.pixelFormat = formats::NV12;
+ Camera3StreamConfig streamConfig;
+ streamConfig.config.size.width = jpegStream->width;
+ streamConfig.config.size.height = jpegStream->height;
+ streamConfig.config.pixelFormat = formats::NV12;
+ streamConfigs.push_back(std::move(streamConfig));
- LOG(HAL, Info) << "Adding " << streamConfiguration.toString()
+ LOG(HAL, Info) << "Adding " << streamConfig.config.toString()
<< " for MJPEG support";
type = CameraStream::Type::Internal;
- config_->addConfiguration(streamConfiguration);
- index = config_->size() - 1;
+ index = streamConfigs.size() - 1;
}
- streams_.emplace_back(this, type, jpegStream, index);
- jpegStream->priv = static_cast<void *>(&streams_.back());
+ streamConfigs[index].streams.push_back({ jpegStream, type });
+ }
+
+ for (const auto &streamConfig : streamConfigs) {
+ config_->addConfiguration(streamConfig.config);
+
+ for (auto &stream : streamConfig.streams) {
+ streams_.emplace_back(this, stream.type, stream.stream,
+ config_->size() - 1);
+ stream.stream->priv = static_cast<void *>(&streams_.back());
+ }
}
switch (config_->validate()) {
' href='#n197'>197
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * stream.cpp - Video stream for a Camera
 */

#include <libcamera/stream.h>

/**
 * \file stream.h
 * \brief Video stream for a Camera
 *
 * A camera device can provide frames in different resolutions and formats
 * concurrently from a single image source. The Stream class represents
 * one of the multiple concurrent streams.
 *
 * All streams exposed by a camera device share the same image source and are
 * thus not fully independent. Parameters related to the image source, such as
 * the exposure time or flash control, are common to all streams. Other
 * parameters, such as format or resolution, may be specified per-stream,
 * depending on the capabilities of the camera device.
 *
 * Camera devices expose at least one stream, and may expose additional streams
 * based on the device capabilities. This can be used, for instance, to
 * implement concurrent viewfinder and video capture, or concurrent viewfinder,
 * video capture and still image capture.
 */

namespace libcamera {

/**
 * \struct StreamConfiguration
 * \brief Configuration parameters for a stream
 *
 * The StreamConfiguration structure models all information which can be
 * configured for a single video stream.
 */

/**
 * \var StreamConfiguration::width
 * \brief Stream width in pixels
 */

/**
 * \var StreamConfiguration::height
 * \brief Stream height in pixels
 */

/**
 * \var StreamConfiguration::pixelFormat
 * \brief Stream pixel format
 *
 * This is a little endian four character code representation of the pixel
 * format described in V4L2 using the V4L2_PIX_FMT_* definitions.
 */

/**
 * \var StreamConfiguration::bufferCount
 * \brief Requested number of buffers to allocate for the stream
 */

/**
 * \class StreamUsage
 * \brief Stream usage information
 *
 * The StreamUsage class describes how an application intends to use a stream.
 * Usages are specified by applications and passed to cameras, that then select
 * the most appropriate streams and their default configurations.
 */

/**
 * \enum StreamUsage::Role
 * \brief Identify the role a stream is intended to play
 * \var StreamUsage::StillCapture
 * The stream is intended to capture high-resolution, high-quality still images
 * with low frame rate. The captured frames may be exposed with flash.
 * \var StreamUsage::VideoRecording
 * The stream is intended to capture video for the purpose of recording or
 * streaming. The video stream may produce a high frame rate and may be
 * enhanced with video stabilization.
 * \var StreamUsage::Viewfinder
 * The stream is intended to capture video for the purpose of display on the
 * local screen. The StreamUsage includes the desired resolution. Trade-offs
 * between quality and usage of system resources are acceptable.
 */

/**
 * \fn StreamUsage::role()
 * \brief Retrieve the stream role
 *
 * \return The stream role
 */

/**
 * \fn StreamUsage::size()
 * \brief Retrieve desired size
 *
 * \return The desired size
 */

/**
 * \brief Create a stream usage
 * \param[in] role Stream role
 */
StreamUsage::StreamUsage(Role role)
	: role_(role)
{
}

/**
 * \brief Create a stream usage with a desired size
 * \param[in] role Stream role
 * \param[in] width The desired width
 * \param[in] height The desired height
 */
StreamUsage::StreamUsage(Role role, int width, int height)
	: role_(role), size_(Size(width, height))
{
}

/**
 * \class Stream
 * \brief Video stream for a camera
 *
 * The Stream class models all static information which are associated with a
 * single video stream. Streams are exposed by the Camera object they belong to.
 *
 * Cameras may supply more than one stream from the same video source. In such
 * cases an application can inspect all available streams and select the ones
 * that best fit its use case.
 *
 * \todo Add capabilities to the stream API. Without this the Stream class only
 * serves to reveal how many streams of unknown capabilities a camera supports.
 * This in itself is productive as it allows applications to configure and
 * capture from one or more streams even if they won't be able to select the
 * optimal stream for the task.
 */