[{"id":5032,"web_url":"https://patchwork.libcamera.org/comment/5032/","msgid":"<20200605082207.gndpsrmjtsopizm6@uno.localdomain>","date":"2020-06-05T08:22:07","subject":"Re: [libcamera-devel] [PATCH v2 1/4] android: camera_device: Build\n\tstream configuration","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Jacopo,\n   you lazy ass which overlooked test runs\n\nOn Thu, Jun 04, 2020 at 03:35:00PM +0200, Jacopo Mondi wrote:\n> Build the stream configuration map by applying the Android Camera3\n> requested resolutions and formats to the libcamera Camera device.\n>\n> For each required format test a list of required and optional\n> resolutions, construct a map to translate from Android format to the\n> libcamera formats and store the available stream configuration to\n> be provided to the Android framework through static metadata.\n>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/android/camera_device.cpp | 218 ++++++++++++++++++++++++++++++++++\n>  src/android/camera_device.h   |  12 ++\n>  2 files changed, 230 insertions(+)\n>\n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index b30263451b76..0c462f53c9cc 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -8,6 +8,8 @@\n>  #include \"camera_device.h\"\n>  #include \"camera_ops.h\"\n>\n> +#include <vector>\n> +\n>  #include <libcamera/controls.h>\n>  #include <libcamera/property_ids.h>\n>\n> @@ -15,9 +17,70 @@\n>  #include \"libcamera/internal/utils.h\"\n>\n>  #include \"camera_metadata.h\"\n> +#include \"system/graphics.h\"\n>\n>  using namespace libcamera;\n>\n> +namespace {\n> +\n> +/*\n> + * \\var camera3Resolutions\n> + * \\brief The list of image resolutions defined as mandatory to be supported by\n> + * the Android Camera3 specification\n> + */\n> +const std::vector<Size> camera3Resolutions = {\n> +\t{ 320, 240 },\n> +\t{ 640, 480 },\n> +\t{ 1280, 720 },\n> +\t{ 1920, 1080 }\n> +};\n> +\n> +/*\n> + * \\struct Camera3Format\n> + * \\brief Data associated with an Android format identifier\n> + * \\var Camera3Format::libcameraFormats: List of libcamera pixel formats\n> + * compatible with the Android format\n> + * \\var Camera3Format::scalerFormat: The format identifier to be reported to the\n> + * android framework through the static format configuration map\n> + */\n> +struct Camera3Format {\n> +\tstd::vector<PixelFormat> libcameraFormats;\n> +\tcamera_metadata_enum_android_scaler_available_formats_t scalerFormat;\n> +};\n> +\n> +/*\n> + * \\var camera3FormatsMap\n> + * \\brief Associate Android format code with ancillary data\n> + */\n> +const std::map<int, const Camera3Format> camera3FormatsMap = {\n> +\t{\n> +\t\tHAL_PIXEL_FORMAT_BLOB, {\n> +\t\t\t{ PixelFormat(DRM_FORMAT_MJPEG) },\n> +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_BLOB\n> +\t\t}\n> +\t},\n> +\n> +\t{\n> +\t\tHAL_PIXEL_FORMAT_YCbCr_420_888, {\n> +\t\t\t{ PixelFormat(DRM_FORMAT_NV12), PixelFormat(DRM_FORMAT_NV21) },\n> +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888\n> +\t\t}\n> +\t},\n> +\n> +\t/*\n> +\t * \\todo Translate IMPLEMENTATION_DEFINED inspecting the\n> +\t * gralloc usage flag. For now, copy the YCbCr_420 configuration.\n> +\t */\n> +\t{\n> +\t\tHAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, {\n> +\t\t\t{ PixelFormat(DRM_FORMAT_NV12), PixelFormat(DRM_FORMAT_NV21) },\n> +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888\n> +\t\t}\n\ns/ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888/ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED\n\n> +\t},\n> +};\n> +\n> +} /* namespace */\n> +\n>  LOG_DECLARE_CATEGORY(HAL);\n>\n>  /*\n> @@ -100,6 +163,161 @@ int CameraDevice::initialize()\n>  \tif (properties.contains(properties::Rotation))\n>  \t\torientation_ = properties.get(properties::Rotation);\n>\n> +\tint ret = camera_->acquire();\n> +\tif (ret) {\n> +\t\tLOG(HAL, Error) << \"Failed to temporarily acquire the camera\";\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tret = initializeFormats();\n> +\tcamera_->release();\n> +\treturn ret;\n> +}\n> +\n> +/*\n> + * Initialize the format conversion map to translate from Android format\n> + * identifier to libcamera pixel formats and fill in the list of supported\n> + * stream configurations to be reported to the Android camera framework through\n> + * the static stream configuration metadata.\n> + */\n> +int CameraDevice::initializeFormats()\n> +{\n> +\t/*\n> +\t * Get the maximum output resolutions\n> +\t * \\todo Get this from the camera properties once defined\n> +\t */\n> +\tstd::unique_ptr<CameraConfiguration> cameraConfig =\n> +\t\tcamera_->generateConfiguration({ StillCapture });\n> +\tif (!cameraConfig) {\n> +\t\tLOG(HAL, Error) << \"Failed to get maximum resolution\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\tStreamConfiguration &cfg = cameraConfig->at(0);\n> +\n> +\t/*\n> +\t * \\todo JPEG - Adjust the maximum available resolution by taking the\n> +\t * JPEG encoder requirements into account (alignment and aspect ratio).\n> +\t */\n> +\tconst Size maxRes = cfg.size;\n> +\tLOG(HAL, Debug) << \"Maximum supported resolution: \" << maxRes.toString();\n> +\n> +\t/*\n> +\t * Build the list of supported image resolutions.\n> +\t *\n> +\t * The resolutions listed in camera3Resolution are mandatory to be\n> +\t * supported, up to the camera maximum resolution.\n> +\t *\n> +\t * Augment the list by adding resolutions calculated from the camera\n> +\t * maximum one.\n> +\t */\n> +\tstd::vector<Size> cameraResolutions;\n> +\tstd::copy_if(camera3Resolutions.begin(), camera3Resolutions.end(),\n> +\t\t     std::back_inserter(cameraResolutions),\n> +\t\t     [&](const Size &res) { return res < maxRes; });\n> +\n> +\t/* Camera3 specification suggests to add 1/2 and 1/4 max resolution. */\n> +\tfor (unsigned int divider = 2;; divider <<= 1) {\n> +\t\tSize derivedSize{\n> +\t\t\tmaxRes.width / divider,\n> +\t\t\tmaxRes.height / divider,\n> +\t\t};\n> +\n> +\t\tif (derivedSize.width < 320 ||\n> +\t\t    derivedSize.height < 240)\n> +\t\t\tbreak;\n> +\n> +\t\tcameraResolutions.push_back(derivedSize);\n> +\t}\n> +\tcameraResolutions.push_back(maxRes);\n> +\n> +\t/* Remove duplicated entries from the list of supported resolutions. */\n> +\tstd::sort(cameraResolutions.begin(), cameraResolutions.end());\n> +\tauto last = std::unique(cameraResolutions.begin(), cameraResolutions.end());\n> +\tcameraResolutions.erase(last, cameraResolutions.end());\n> +\n> +\t/*\n> +\t * Build the list of supported camera formats.\n> +\t *\n> +\t * To each Android format a list of compatible libcamera formats is\n> +\t * associated. The first libcamera format that tests successful is added\n> +\t * to the format translation map used when configuring the streams.\n> +\t * It is then tested against the list of supported camera resolutions to\n> +\t * build the stream configuration map reported through the camera static\n> +\t * metadata.\n> +\t */\n> +\tfor (const auto &format : camera3FormatsMap) {\n> +\t\tint androidFormat = format.first;\n> +\t\tconst Camera3Format &camera3Format = format.second;\n> +\t\tconst std::vector<PixelFormat> &libcameraFormats =\n> +\t\t\tcamera3Format.libcameraFormats;\n> +\n> +\t\t/*\n> +\t\t * Test the libcamera formats that can produce images\n> +\t\t * compatible with the Android defined format.\n> +\t\t */\n> +\t\tPixelFormat mappedFormat{};\n> +\t\tfor (const PixelFormat &format : libcameraFormats) {\n> +\t\t\t/* \\todo Fixed mapping for JPEG. */\n> +\t\t\tif (androidFormat == HAL_PIXEL_FORMAT_BLOB) {\n> +\t\t\t\tmappedFormat = PixelFormat(DRM_FORMAT_MJPEG);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\n> +\t\t\t/*\n> +\t\t\t * The stream configuration size can be adjusted,\n> +\t\t\t * not the pixel format.\n> +\t\t\t *\n> +\t\t\t * \\todo This could be simplified once all pipeline\n> +\t\t\t * handlers will report the StreamFormats list of\n> +\t\t\t * supported formats.\n> +\t\t\t */\n> +\t\t\tcfg.pixelFormat = format;\n> +\n> +\t\t\tCameraConfiguration::Status status = cameraConfig->validate();\n> +\t\t\tif (status != CameraConfiguration::Invalid &&\n> +\t\t\t    cfg.pixelFormat == format) {\n> +\t\t\t\tmappedFormat = format;\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\t\tif (!mappedFormat.isValid()) {\n> +\t\t\tLOG(HAL, Error) << \"Failed to map Android format \"\n> +\t\t\t\t\t<< utils::hex(androidFormat);\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Record the mapping and then proceed to generate the\n> +\t\t * stream configurations map, by testing the image resolutions.\n> +\t\t */\n> +\t\tformatsMap_[androidFormat] = mappedFormat;\n> +\n> +\t\tfor (const Size &res : cameraResolutions) {\n> +\t\t\tcfg.pixelFormat = mappedFormat;\n> +\t\t\tcfg.size = res;\n> +\n> +\t\t\tCameraConfiguration::Status status = cameraConfig->validate();\n> +\t\t\t/*\n> +\t\t\t * Unconditionally report we can produce JPEG.\n> +\t\t\t *\n> +\t\t\t * \\todo The JPEG stream will be implemented as an\n> +\t\t\t * HAL-only stream, but some cameras can produce it\n> +\t\t\t * directly. As of now, claim support for JPEG without\n> +\t\t\t * inspecting where the JPEG stream is produced.\n> +\t\t\t */\n> +\t\t\tif (androidFormat != HAL_PIXEL_FORMAT_BLOB &&\n> +\t\t\t    status != CameraConfiguration::Valid)\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\tstreamConfigurations_.push_back({ res, camera3Format.scalerFormat });\n> +\t\t}\n> +\t}\n> +\n> +\tLOG(HAL, Debug) << \"Collected stream configuration map: \";\n> +\tfor (const auto &entry : streamConfigurations_)\n> +\t\tLOG(HAL, Debug) << \"{ \" << entry.resolution.toString() << \" - \"\n> +\t\t\t\t<< utils::hex(entry.androidScalerCode);\n\nMissing closing \" }\"\n\nWill wait for more comments and fix in next versions\n\nThanks\n  j","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3246E603C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 10:18:48 +0200 (CEST)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id DC623240031\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 08:18:47 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","Date":"Fri, 5 Jun 2020 10:22:07 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200605082207.gndpsrmjtsopizm6@uno.localdomain>","References":"<20200604133503.14689-1-jacopo@jmondi.org>\n\t<20200604133503.14689-2-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200604133503.14689-2-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v2 1/4] android: camera_device: Build\n\tstream configuration","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 08:18:48 -0000"}},{"id":5034,"web_url":"https://patchwork.libcamera.org/comment/5034/","msgid":"<5f363b01-a684-8e88-3b1d-acc66b761c8e@ideasonboard.com>","date":"2020-06-05T08:28:07","subject":"Re: [libcamera-devel] [PATCH v2 1/4] android: camera_device: Build\n\tstream configuration","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn 04/06/2020 14:35, Jacopo Mondi wrote:\n> Build the stream configuration map by applying the Android Camera3\n> requested resolutions and formats to the libcamera Camera device.\n> \n> For each required format test a list of required and optional\n> resolutions, construct a map to translate from Android format to the\n> libcamera formats and store the available stream configuration to\n> be provided to the Android framework through static metadata.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/android/camera_device.cpp | 218 ++++++++++++++++++++++++++++++++++\n>  src/android/camera_device.h   |  12 ++\n>  2 files changed, 230 insertions(+)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index b30263451b76..0c462f53c9cc 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -8,6 +8,8 @@\n>  #include \"camera_device.h\"\n>  #include \"camera_ops.h\"\n>  \n> +#include <vector>\n> +\n>  #include <libcamera/controls.h>\n>  #include <libcamera/property_ids.h>\n>  \n> @@ -15,9 +17,70 @@\n>  #include \"libcamera/internal/utils.h\"\n>  \n>  #include \"camera_metadata.h\"\n> +#include \"system/graphics.h\"\n>  \n>  using namespace libcamera;\n>  \n> +namespace {\n> +\n> +/*\n> + * \\var camera3Resolutions\n> + * \\brief The list of image resolutions defined as mandatory to be supported by\n> + * the Android Camera3 specification\n> + */\n> +const std::vector<Size> camera3Resolutions = {\n> +\t{ 320, 240 },\n> +\t{ 640, 480 },\n> +\t{ 1280, 720 },\n> +\t{ 1920, 1080 }\n> +};\n> +\n> +/*\n> + * \\struct Camera3Format\n> + * \\brief Data associated with an Android format identifier\n> + * \\var Camera3Format::libcameraFormats: List of libcamera pixel formats\n\ndo you need to prefix Camera3Format:: in the same comment block?\n\n> + * compatible with the Android format\n> + * \\var Camera3Format::scalerFormat: The format identifier to be reported to the\n> + * android framework through the static format configuration map\n> + */\n> +struct Camera3Format {\n> +\tstd::vector<PixelFormat> libcameraFormats;\n> +\tcamera_metadata_enum_android_scaler_available_formats_t scalerFormat;\n> +};\n> +\n> +/*\n> + * \\var camera3FormatsMap\n> + * \\brief Associate Android format code with ancillary data\n> + */\n> +const std::map<int, const Camera3Format> camera3FormatsMap = {\n> +\t{\n> +\t\tHAL_PIXEL_FORMAT_BLOB, {\n\nIs there no defined MJPEG format for Android HAL ? 'just a blob' :-S\n\n\n> +\t\t\t{ PixelFormat(DRM_FORMAT_MJPEG) },\n> +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_BLOB\n> +\t\t}\n> +\t},\n> +\n> +\t{\n> +\t\tHAL_PIXEL_FORMAT_YCbCr_420_888, {\n> +\t\t\t{ PixelFormat(DRM_FORMAT_NV12), PixelFormat(DRM_FORMAT_NV21) },\n> +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888\n\nHow is the ordering determined between multiple formats like that ?\n\nI.e. - how does something know what the correct format to choose will be?\n\nAh ok - I see below they get iterated with calls to validate them....\n\n> +\t\t}\n> +\t},\n> +\n> +\t/*\n> +\t * \\todo Translate IMPLEMENTATION_DEFINED inspecting the\n> +\t * gralloc usage flag. For now, copy the YCbCr_420 configuration.\n> +\t */\n> +\t{\n> +\t\tHAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, {\n> +\t\t\t{ PixelFormat(DRM_FORMAT_NV12), PixelFormat(DRM_FORMAT_NV21) },\n> +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888\n> +\t\t}\n> +\t},\n> +};\n> +\n> +} /* namespace */\n> +\n>  LOG_DECLARE_CATEGORY(HAL);\n>  \n>  /*\n> @@ -100,6 +163,161 @@ int CameraDevice::initialize()\n>  \tif (properties.contains(properties::Rotation))\n>  \t\torientation_ = properties.get(properties::Rotation);\n>  \n> +\tint ret = camera_->acquire();\n> +\tif (ret) {\n> +\t\tLOG(HAL, Error) << \"Failed to temporarily acquire the camera\";\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tret = initializeFormats();\n> +\tcamera_->release();\n> +\treturn ret;\n> +}\n> +\n> +/*\n> + * Initialize the format conversion map to translate from Android format\n> + * identifier to libcamera pixel formats and fill in the list of supported\n> + * stream configurations to be reported to the Android camera framework through\n> + * the static stream configuration metadata.\n> + */\n> +int CameraDevice::initializeFormats()\n> +{\n> +\t/*\n> +\t * Get the maximum output resolutions\n> +\t * \\todo Get this from the camera properties once defined\n> +\t */\n> +\tstd::unique_ptr<CameraConfiguration> cameraConfig =\n> +\t\tcamera_->generateConfiguration({ StillCapture });\n> +\tif (!cameraConfig) {\n> +\t\tLOG(HAL, Error) << \"Failed to get maximum resolution\";\n> +\t\treturn -EINVAL;\n> +\t}\n> +\tStreamConfiguration &cfg = cameraConfig->at(0);\n> +\n> +\t/*\n> +\t * \\todo JPEG - Adjust the maximum available resolution by taking the\n> +\t * JPEG encoder requirements into account (alignment and aspect ratio).\n> +\t */\n> +\tconst Size maxRes = cfg.size;\n\nDo we already define that a generateConfiguration({ StillCapture })\nshould return the largest size as a default?\n\nOr should the 'max' size further inspect the cfg.formats() and determine\nthe largest supported size from there?\n\n> +\tLOG(HAL, Debug) << \"Maximum supported resolution: \" << maxRes.toString();\n> +\n> +\t/*\n> +\t * Build the list of supported image resolutions.\n> +\t *\n> +\t * The resolutions listed in camera3Resolution are mandatory to be\n> +\t * supported, up to the camera maximum resolution.\n> +\t *\n> +\t * Augment the list by adding resolutions calculated from the camera\n> +\t * maximum one.\n> +\t */\n> +\tstd::vector<Size> cameraResolutions;\n> +\tstd::copy_if(camera3Resolutions.begin(), camera3Resolutions.end(),\n> +\t\t     std::back_inserter(cameraResolutions),\n> +\t\t     [&](const Size &res) { return res < maxRes; });\n> +\n> +\t/* Camera3 specification suggests to add 1/2 and 1/4 max resolution. */\n> +\tfor (unsigned int divider = 2;; divider <<= 1) {\n> +\t\tSize derivedSize{\n> +\t\t\tmaxRes.width / divider,\n> +\t\t\tmaxRes.height / divider,\n> +\t\t};\n> +\n> +\t\tif (derivedSize.width < 320 ||\n> +\t\t    derivedSize.height < 240)\n> +\t\t\tbreak;\n> +\n> +\t\tcameraResolutions.push_back(derivedSize);\n> +\t}\n> +\tcameraResolutions.push_back(maxRes);\n> +\n> +\t/* Remove duplicated entries from the list of supported resolutions. */\n> +\tstd::sort(cameraResolutions.begin(), cameraResolutions.end());\n> +\tauto last = std::unique(cameraResolutions.begin(), cameraResolutions.end());\n> +\tcameraResolutions.erase(last, cameraResolutions.end());\n\nAh, I had to look that up:\nhttps://en.cppreference.com/w/cpp/algorithm/unique shows you have to\nmanually erase to the end after a unique. It looks odd in the code if\nyou don't know that ;-)\n\n> +\n> +\t/*\n> +\t * Build the list of supported camera formats.\n> +\t *\n> +\t * To each Android format a list of compatible libcamera formats is\n> +\t * associated. The first libcamera format that tests successful is added\n> +\t * to the format translation map used when configuring the streams.\n> +\t * It is then tested against the list of supported camera resolutions to\n> +\t * build the stream configuration map reported through the camera static\n> +\t * metadata.\n> +\t */\n> +\tfor (const auto &format : camera3FormatsMap) {\n> +\t\tint androidFormat = format.first;\n> +\t\tconst Camera3Format &camera3Format = format.second;\n> +\t\tconst std::vector<PixelFormat> &libcameraFormats =\n> +\t\t\tcamera3Format.libcameraFormats;\n> +\n> +\t\t/*\n> +\t\t * Test the libcamera formats that can produce images\n> +\t\t * compatible with the Android defined format.\n> +\t\t */\n> +\t\tPixelFormat mappedFormat{};\n> +\t\tfor (const PixelFormat &format : libcameraFormats) {\n\nYou're aliasing const auto &format, and const PixelFormat &format here...\n\nNot necessarily a problem, but prevents accessing the camera3FormatsMap\nentry ...\n\n> +\t\t\t/* \\todo Fixed mapping for JPEG. */\n\n/me takes note....\n\n> +\t\t\tif (androidFormat == HAL_PIXEL_FORMAT_BLOB) {\n> +\t\t\t\tmappedFormat = PixelFormat(DRM_FORMAT_MJPEG);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\n> +\t\t\t/*\n> +\t\t\t * The stream configuration size can be adjusted,\n> +\t\t\t * not the pixel format.\n> +\t\t\t *\n> +\t\t\t * \\todo This could be simplified once all pipeline\n> +\t\t\t * handlers will report the StreamFormats list of\n> +\t\t\t * supported formats.\n> +\t\t\t */\n> +\t\t\tcfg.pixelFormat = format;\n> +\n> +\t\t\tCameraConfiguration::Status status = cameraConfig->validate();\n> +\t\t\tif (status != CameraConfiguration::Invalid &&\n> +\t\t\t    cfg.pixelFormat == format) {\n> +\t\t\t\tmappedFormat = format;\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n> +\t\tif (!mappedFormat.isValid()) {\n> +\t\t\tLOG(HAL, Error) << \"Failed to map Android format \"\n> +\t\t\t\t\t<< utils::hex(androidFormat);\n\nIs it worth putting a char * mapping of the android format name in\ncamera3FormatsMap to be able to easily diagnose which format failed here?\n\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Record the mapping and then proceed to generate the\n> +\t\t * stream configurations map, by testing the image resolutions.\n> +\t\t */\n> +\t\tformatsMap_[androidFormat] = mappedFormat;\n> +\n> +\t\tfor (const Size &res : cameraResolutions) {\n> +\t\t\tcfg.pixelFormat = mappedFormat;\n> +\t\t\tcfg.size = res;\n> +\n> +\t\t\tCameraConfiguration::Status status = cameraConfig->validate();\n> +\t\t\t/*\n> +\t\t\t * Unconditionally report we can produce JPEG.\n> +\t\t\t *\n> +\t\t\t * \\todo The JPEG stream will be implemented as an\n> +\t\t\t * HAL-only stream, but some cameras can produce it\n> +\t\t\t * directly. As of now, claim support for JPEG without\n> +\t\t\t * inspecting where the JPEG stream is produced.\n> +\t\t\t */\n> +\t\t\tif (androidFormat != HAL_PIXEL_FORMAT_BLOB &&\n> +\t\t\t    status != CameraConfiguration::Valid)\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\tstreamConfigurations_.push_back({ res, camera3Format.scalerFormat });\n> +\t\t}\n> +\t}\n> +\n> +\tLOG(HAL, Debug) << \"Collected stream configuration map: \";\n> +\tfor (const auto &entry : streamConfigurations_)\n> +\t\tLOG(HAL, Debug) << \"{ \" << entry.resolution.toString() << \" - \"\n> +\t\t\t\t<< utils::hex(entry.androidScalerCode);\n> +\n>  \treturn 0;\n>  }\n>  \n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index a87f7623c790..d31b7233e795 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -7,12 +7,15 @@\n>  #ifndef __ANDROID_CAMERA_DEVICE_H__\n>  #define __ANDROID_CAMERA_DEVICE_H__\n>  \n> +#include <map>\n>  #include <memory>\n> +#include <vector>\n>  \n>  #include <hardware/camera3.h>\n>  \n>  #include <libcamera/buffer.h>\n>  #include <libcamera/camera.h>\n> +#include <libcamera/geometry.h>\n>  #include <libcamera/request.h>\n>  #include <libcamera/stream.h>\n>  \n> @@ -59,6 +62,12 @@ private:\n>  \t\tcamera3_stream_buffer_t *buffers;\n>  \t};\n>  \n> +\tstruct Camera3StreamConfiguration {\n> +\t\tlibcamera::Size resolution;\n> +\t\tint androidScalerCode;\n> +\t};\n> +\n> +\tint initializeFormats();\n>  \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n>  \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream);\n>  \tstd::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,\n> @@ -75,6 +84,9 @@ private:\n>  \tstd::map<unsigned int, CameraMetadata *> requestTemplates_;\n>  \tconst camera3_callback_ops_t *callbacks_;\n>  \n> +\tstd::vector<Camera3StreamConfiguration> streamConfigurations_;\n> +\tstd::map<int, libcamera::PixelFormat> formatsMap_;\n> +\n>  \tint facing_;\n>  \tint orientation_;\n>  };\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72574603C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 10:28:11 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DB670F9;\n\tFri,  5 Jun 2020 10:28:10 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"B4Rouuha\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591345691;\n\tbh=9aDvV8uRajdSc4hIqrqVXSHFWax4Rf/DBe0yGcBhAYA=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=B4RouuhawMTlbZBE8eJ1hp0KfBeU1nFwqTzGigCbOQNHNUSFBvRP3rLqkZl6onwh5\n\tBw6XJcGhxjfumwrHGAK7fCRi3/MV2b+wk9mf85AyOZXkpAkR4bka4BnYnsa/MuIr3p\n\tUAXMNTq3CGMMAzicQxRfBH5xun3/fi796rHD/oaY=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Jacopo Mondi <jacopo@jmondi.org>, libcamera-devel@lists.libcamera.org","References":"<20200604133503.14689-1-jacopo@jmondi.org>\n\t<20200604133503.14689-2-jacopo@jmondi.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\t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\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<5f363b01-a684-8e88-3b1d-acc66b761c8e@ideasonboard.com>","Date":"Fri, 5 Jun 2020 09:28:07 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.7.0","MIME-Version":"1.0","In-Reply-To":"<20200604133503.14689-2-jacopo@jmondi.org>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH v2 1/4] android: camera_device: Build\n\tstream configuration","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 08:28:11 -0000"}},{"id":5036,"web_url":"https://patchwork.libcamera.org/comment/5036/","msgid":"<20200605083918.2kyg4ricwnvtpiji@uno.localdomain>","date":"2020-06-05T08:39:18","subject":"Re: [libcamera-devel] [PATCH v2 1/4] android: camera_device: Build\n\tstream configuration","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Kieran\n\nOn Fri, Jun 05, 2020 at 09:28:07AM +0100, Kieran Bingham wrote:\n> Hi Jacopo,\n>\n> On 04/06/2020 14:35, Jacopo Mondi wrote:\n> > Build the stream configuration map by applying the Android Camera3\n> > requested resolutions and formats to the libcamera Camera device.\n> >\n> > For each required format test a list of required and optional\n> > resolutions, construct a map to translate from Android format to the\n> > libcamera formats and store the available stream configuration to\n> > be provided to the Android framework through static metadata.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  src/android/camera_device.cpp | 218 ++++++++++++++++++++++++++++++++++\n> >  src/android/camera_device.h   |  12 ++\n> >  2 files changed, 230 insertions(+)\n> >\n> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> > index b30263451b76..0c462f53c9cc 100644\n> > --- a/src/android/camera_device.cpp\n> > +++ b/src/android/camera_device.cpp\n> > @@ -8,6 +8,8 @@\n> >  #include \"camera_device.h\"\n> >  #include \"camera_ops.h\"\n> >\n> > +#include <vector>\n> > +\n> >  #include <libcamera/controls.h>\n> >  #include <libcamera/property_ids.h>\n> >\n> > @@ -15,9 +17,70 @@\n> >  #include \"libcamera/internal/utils.h\"\n> >\n> >  #include \"camera_metadata.h\"\n> > +#include \"system/graphics.h\"\n> >\n> >  using namespace libcamera;\n> >\n> > +namespace {\n> > +\n> > +/*\n> > + * \\var camera3Resolutions\n> > + * \\brief The list of image resolutions defined as mandatory to be supported by\n> > + * the Android Camera3 specification\n> > + */\n> > +const std::vector<Size> camera3Resolutions = {\n> > +\t{ 320, 240 },\n> > +\t{ 640, 480 },\n> > +\t{ 1280, 720 },\n> > +\t{ 1920, 1080 }\n> > +};\n> > +\n> > +/*\n> > + * \\struct Camera3Format\n> > + * \\brief Data associated with an Android format identifier\n> > + * \\var Camera3Format::libcameraFormats: List of libcamera pixel formats\n>\n> do you need to prefix Camera3Format:: in the same comment block?\n>\n\nDon't I ? Actually, this is not even parsed by Doxygen, I chose to\nkeep the same syntax for consistency, but I could drop the prefix\n\n> > + * compatible with the Android format\n> > + * \\var Camera3Format::scalerFormat: The format identifier to be reported to the\n> > + * android framework through the static format configuration map\n> > + */\n> > +struct Camera3Format {\n> > +\tstd::vector<PixelFormat> libcameraFormats;\n> > +\tcamera_metadata_enum_android_scaler_available_formats_t scalerFormat;\n> > +};\n> > +\n> > +/*\n> > + * \\var camera3FormatsMap\n> > + * \\brief Associate Android format code with ancillary data\n> > + */\n> > +const std::map<int, const Camera3Format> camera3FormatsMap = {\n> > +\t{\n> > +\t\tHAL_PIXEL_FORMAT_BLOB, {\n>\n> Is there no defined MJPEG format for Android HAL ? 'just a blob' :-S\n\nSeems so\n\n>\n>\n> > +\t\t\t{ PixelFormat(DRM_FORMAT_MJPEG) },\n> > +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_BLOB\n> > +\t\t}\n> > +\t},\n> > +\n> > +\t{\n> > +\t\tHAL_PIXEL_FORMAT_YCbCr_420_888, {\n> > +\t\t\t{ PixelFormat(DRM_FORMAT_NV12), PixelFormat(DRM_FORMAT_NV21) },\n> > +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888\n>\n> How is the ordering determined between multiple formats like that ?\n>\n> I.e. - how does something know what the correct format to choose will be?\n>\n> Ah ok - I see below they get iterated with calls to validate them....\n\nYes\n\n>\n> > +\t\t}\n> > +\t},\n> > +\n> > +\t/*\n> > +\t * \\todo Translate IMPLEMENTATION_DEFINED inspecting the\n> > +\t * gralloc usage flag. For now, copy the YCbCr_420 configuration.\n> > +\t */\n> > +\t{\n> > +\t\tHAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, {\n> > +\t\t\t{ PixelFormat(DRM_FORMAT_NV12), PixelFormat(DRM_FORMAT_NV21) },\n> > +\t\t\tANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888\n> > +\t\t}\n> > +\t},\n> > +};\n> > +\n> > +} /* namespace */\n> > +\n> >  LOG_DECLARE_CATEGORY(HAL);\n> >\n> >  /*\n> > @@ -100,6 +163,161 @@ int CameraDevice::initialize()\n> >  \tif (properties.contains(properties::Rotation))\n> >  \t\torientation_ = properties.get(properties::Rotation);\n> >\n> > +\tint ret = camera_->acquire();\n> > +\tif (ret) {\n> > +\t\tLOG(HAL, Error) << \"Failed to temporarily acquire the camera\";\n> > +\t\treturn ret;\n> > +\t}\n> > +\n> > +\tret = initializeFormats();\n> > +\tcamera_->release();\n> > +\treturn ret;\n> > +}\n> > +\n> > +/*\n> > + * Initialize the format conversion map to translate from Android format\n> > + * identifier to libcamera pixel formats and fill in the list of supported\n> > + * stream configurations to be reported to the Android camera framework through\n> > + * the static stream configuration metadata.\n> > + */\n> > +int CameraDevice::initializeFormats()\n> > +{\n> > +\t/*\n> > +\t * Get the maximum output resolutions\n> > +\t * \\todo Get this from the camera properties once defined\n> > +\t */\n> > +\tstd::unique_ptr<CameraConfiguration> cameraConfig =\n> > +\t\tcamera_->generateConfiguration({ StillCapture });\n> > +\tif (!cameraConfig) {\n> > +\t\tLOG(HAL, Error) << \"Failed to get maximum resolution\";\n> > +\t\treturn -EINVAL;\n> > +\t}\n> > +\tStreamConfiguration &cfg = cameraConfig->at(0);\n> > +\n> > +\t/*\n> > +\t * \\todo JPEG - Adjust the maximum available resolution by taking the\n> > +\t * JPEG encoder requirements into account (alignment and aspect ratio).\n> > +\t */\n> > +\tconst Size maxRes = cfg.size;\n>\n> Do we already define that a generateConfiguration({ StillCapture })\n> should return the largest size as a default?\n>\n\nWe're not enforcing that afaict, it's up to pipeline handlers, but I\nexpect they return the maximum available resolution in that case.\n\nAnyway, this is just temporary, as we'll have a property that reports\nthe maximum image resolution you can get from a camera.\n\n> Or should the 'max' size further inspect the cfg.formats() and determine\n> the largest supported size from there?\n>\n\nIf only more than 2 pipeline handlers provided StreamFormats we could,\nbut again, I would switch to inspecting the property once it's\navailable\n\n> > +\tLOG(HAL, Debug) << \"Maximum supported resolution: \" << maxRes.toString();\n> > +\n> > +\t/*\n> > +\t * Build the list of supported image resolutions.\n> > +\t *\n> > +\t * The resolutions listed in camera3Resolution are mandatory to be\n> > +\t * supported, up to the camera maximum resolution.\n> > +\t *\n> > +\t * Augment the list by adding resolutions calculated from the camera\n> > +\t * maximum one.\n> > +\t */\n> > +\tstd::vector<Size> cameraResolutions;\n> > +\tstd::copy_if(camera3Resolutions.begin(), camera3Resolutions.end(),\n> > +\t\t     std::back_inserter(cameraResolutions),\n> > +\t\t     [&](const Size &res) { return res < maxRes; });\n> > +\n> > +\t/* Camera3 specification suggests to add 1/2 and 1/4 max resolution. */\n> > +\tfor (unsigned int divider = 2;; divider <<= 1) {\n> > +\t\tSize derivedSize{\n> > +\t\t\tmaxRes.width / divider,\n> > +\t\t\tmaxRes.height / divider,\n> > +\t\t};\n> > +\n> > +\t\tif (derivedSize.width < 320 ||\n> > +\t\t    derivedSize.height < 240)\n> > +\t\t\tbreak;\n> > +\n> > +\t\tcameraResolutions.push_back(derivedSize);\n> > +\t}\n> > +\tcameraResolutions.push_back(maxRes);\n> > +\n> > +\t/* Remove duplicated entries from the list of supported resolutions. */\n> > +\tstd::sort(cameraResolutions.begin(), cameraResolutions.end());\n> > +\tauto last = std::unique(cameraResolutions.begin(), cameraResolutions.end());\n> > +\tcameraResolutions.erase(last, cameraResolutions.end());\n>\n> Ah, I had to look that up:\n> https://en.cppreference.com/w/cpp/algorithm/unique shows you have to\n> manually erase to the end after a unique. It looks odd in the code if\n> you don't know that ;-)\n>\n> > +\n> > +\t/*\n> > +\t * Build the list of supported camera formats.\n> > +\t *\n> > +\t * To each Android format a list of compatible libcamera formats is\n> > +\t * associated. The first libcamera format that tests successful is added\n> > +\t * to the format translation map used when configuring the streams.\n> > +\t * It is then tested against the list of supported camera resolutions to\n> > +\t * build the stream configuration map reported through the camera static\n> > +\t * metadata.\n> > +\t */\n> > +\tfor (const auto &format : camera3FormatsMap) {\n> > +\t\tint androidFormat = format.first;\n> > +\t\tconst Camera3Format &camera3Format = format.second;\n> > +\t\tconst std::vector<PixelFormat> &libcameraFormats =\n> > +\t\t\tcamera3Format.libcameraFormats;\n> > +\n> > +\t\t/*\n> > +\t\t * Test the libcamera formats that can produce images\n> > +\t\t * compatible with the Android defined format.\n> > +\t\t */\n> > +\t\tPixelFormat mappedFormat{};\n> > +\t\tfor (const PixelFormat &format : libcameraFormats) {\n>\n> You're aliasing const auto &format, and const PixelFormat &format here...\n>\n> Not necessarily a problem, but prevents accessing the camera3FormatsMap\n> entry ...\n\nAh right, this was not intentional, even if it seems harmless. I'll\nchange this\n\n>\n> > +\t\t\t/* \\todo Fixed mapping for JPEG. */\n>\n> /me takes note....\n>\n\nYeah, about this, and the above todo note as well, please\n\n\t/*\n\t * \\todo JPEG - Adjust the maximum available resolution by taking the\n\t * JPEG encoder requirements into account (alignment and aspect ratio).\n\t */\n\n> > +\t\t\tif (androidFormat == HAL_PIXEL_FORMAT_BLOB) {\n> > +\t\t\t\tmappedFormat = PixelFormat(DRM_FORMAT_MJPEG);\n> > +\t\t\t\tbreak;\n> > +\t\t\t}\n> > +\n> > +\t\t\t/*\n> > +\t\t\t * The stream configuration size can be adjusted,\n> > +\t\t\t * not the pixel format.\n> > +\t\t\t *\n> > +\t\t\t * \\todo This could be simplified once all pipeline\n> > +\t\t\t * handlers will report the StreamFormats list of\n> > +\t\t\t * supported formats.\n> > +\t\t\t */\n> > +\t\t\tcfg.pixelFormat = format;\n> > +\n> > +\t\t\tCameraConfiguration::Status status = cameraConfig->validate();\n> > +\t\t\tif (status != CameraConfiguration::Invalid &&\n> > +\t\t\t    cfg.pixelFormat == format) {\n> > +\t\t\t\tmappedFormat = format;\n> > +\t\t\t\tbreak;\n> > +\t\t\t}\n> > +\t\t}\n> > +\t\tif (!mappedFormat.isValid()) {\n> > +\t\t\tLOG(HAL, Error) << \"Failed to map Android format \"\n> > +\t\t\t\t\t<< utils::hex(androidFormat);\n>\n> Is it worth putting a char * mapping of the android format name in\n> camera3FormatsMap to be able to easily diagnose which format failed here?\n>\n\nnot strictly required but might be nice\n\nThanks\n  j\n\n> > +\t\t\treturn -EINVAL;\n> > +\t\t}\n> > +\n> > +\t\t/*\n> > +\t\t * Record the mapping and then proceed to generate the\n> > +\t\t * stream configurations map, by testing the image resolutions.\n> > +\t\t */\n> > +\t\tformatsMap_[androidFormat] = mappedFormat;\n> > +\n> > +\t\tfor (const Size &res : cameraResolutions) {\n> > +\t\t\tcfg.pixelFormat = mappedFormat;\n> > +\t\t\tcfg.size = res;\n> > +\n> > +\t\t\tCameraConfiguration::Status status = cameraConfig->validate();\n> > +\t\t\t/*\n> > +\t\t\t * Unconditionally report we can produce JPEG.\n> > +\t\t\t *\n> > +\t\t\t * \\todo The JPEG stream will be implemented as an\n> > +\t\t\t * HAL-only stream, but some cameras can produce it\n> > +\t\t\t * directly. As of now, claim support for JPEG without\n> > +\t\t\t * inspecting where the JPEG stream is produced.\n> > +\t\t\t */\n> > +\t\t\tif (androidFormat != HAL_PIXEL_FORMAT_BLOB &&\n> > +\t\t\t    status != CameraConfiguration::Valid)\n> > +\t\t\t\tcontinue;\n> > +\n> > +\t\t\tstreamConfigurations_.push_back({ res, camera3Format.scalerFormat });\n> > +\t\t}\n> > +\t}\n> > +\n> > +\tLOG(HAL, Debug) << \"Collected stream configuration map: \";\n> > +\tfor (const auto &entry : streamConfigurations_)\n> > +\t\tLOG(HAL, Debug) << \"{ \" << entry.resolution.toString() << \" - \"\n> > +\t\t\t\t<< utils::hex(entry.androidScalerCode);\n> > +\n> >  \treturn 0;\n> >  }\n> >\n> > diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> > index a87f7623c790..d31b7233e795 100644\n> > --- a/src/android/camera_device.h\n> > +++ b/src/android/camera_device.h\n> > @@ -7,12 +7,15 @@\n> >  #ifndef __ANDROID_CAMERA_DEVICE_H__\n> >  #define __ANDROID_CAMERA_DEVICE_H__\n> >\n> > +#include <map>\n> >  #include <memory>\n> > +#include <vector>\n> >\n> >  #include <hardware/camera3.h>\n> >\n> >  #include <libcamera/buffer.h>\n> >  #include <libcamera/camera.h>\n> > +#include <libcamera/geometry.h>\n> >  #include <libcamera/request.h>\n> >  #include <libcamera/stream.h>\n> >\n> > @@ -59,6 +62,12 @@ private:\n> >  \t\tcamera3_stream_buffer_t *buffers;\n> >  \t};\n> >\n> > +\tstruct Camera3StreamConfiguration {\n> > +\t\tlibcamera::Size resolution;\n> > +\t\tint androidScalerCode;\n> > +\t};\n> > +\n> > +\tint initializeFormats();\n> >  \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n> >  \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream);\n> >  \tstd::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,\n> > @@ -75,6 +84,9 @@ private:\n> >  \tstd::map<unsigned int, CameraMetadata *> requestTemplates_;\n> >  \tconst camera3_callback_ops_t *callbacks_;\n> >\n> > +\tstd::vector<Camera3StreamConfiguration> streamConfigurations_;\n> > +\tstd::map<int, libcamera::PixelFormat> formatsMap_;\n> > +\n> >  \tint facing_;\n> >  \tint orientation_;\n> >  };\n> >\n>\n> --\n> Regards\n> --\n> Kieran","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AF7C561027\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Jun 2020 10:35:57 +0200 (CEST)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 4B6051BF210;\n\tFri,  5 Jun 2020 08:35:57 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","Date":"Fri, 5 Jun 2020 10:39:18 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200605083918.2kyg4ricwnvtpiji@uno.localdomain>","References":"<20200604133503.14689-1-jacopo@jmondi.org>\n\t<20200604133503.14689-2-jacopo@jmondi.org>\n\t<5f363b01-a684-8e88-3b1d-acc66b761c8e@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<5f363b01-a684-8e88-3b1d-acc66b761c8e@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/4] android: camera_device: Build\n\tstream configuration","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 05 Jun 2020 08:35:57 -0000"}}]