Show a patch.

GET /api/1.1/patches/3862/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 3862,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/3862/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3862/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200526142237.407557-4-jacopo@jmondi.org>",
    "date": "2020-05-26T14:22:32",
    "name": "[libcamera-devel,3/8] android: hal_manager: Do not hardcode properties",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "f1d22716eee503e16b1446ceda7c8d0a4a6d204a",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/3862/mbox/",
    "series": [
        {
            "id": 930,
            "url": "https://patchwork.libcamera.org/api/1.1/series/930/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=930",
            "date": "2020-05-26T14:22:29",
            "name": "android: Implament format translation",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/930/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3862/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3862/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 36DD96109B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 May 2020 16:19:26 +0200 (CEST)",
            "from localhost.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id B80C940004;\n\tTue, 26 May 2020 14:19:25 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 26 May 2020 16:22:32 +0200",
        "Message-Id": "<20200526142237.407557-4-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.26.2",
        "In-Reply-To": "<20200526142237.407557-1-jacopo@jmondi.org>",
        "References": "<20200526142237.407557-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/8] android: hal_manager: Do not hardcode\n\tproperties",
        "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": "Tue, 26 May 2020 14:19:26 -0000"
    },
    "content": "The CameraHalManager::getCameraInfo() method hardcodes the camera facing\nside and orientation (which corresponds, confusingly, to libcamera's\nlocation and rotation properties).\n\nInstead of hard-coding the values based on the camera id, cache the\nlibcamera Camera properties in a new initialize() method, and use them\nboth to report camera info and to populate the static metadata buffer.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp      | 80 ++++++++++++++++++++----------\n src/android/camera_device.h        |  8 +++\n src/android/camera_hal_manager.cpp | 10 ++--\n 3 files changed, 68 insertions(+), 30 deletions(-)",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex ad277cb059ca..69b25ed2f11f 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -53,7 +53,8 @@ CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor()\n  */\n \n CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camera)\n-\t: running_(false), camera_(camera), staticMetadata_(nullptr)\n+\t: running_(false), camera_(camera), staticMetadata_(nullptr),\n+\t  facing_(CAMERA_FACING_FRONT), orientation_(0)\n {\n \tcamera_->requestCompleted.connect(this, &CameraDevice::requestComplete);\n }\n@@ -67,6 +68,45 @@ CameraDevice::~CameraDevice()\n \t\tdelete it.second;\n }\n \n+/*\n+ * Initialize the camera static information.\n+ * This method is called before the camera device is open.\n+ */\n+int CameraDevice::initialize()\n+{\n+\t/* Initialize orientation and facing side of the camera. */\n+\tconst ControlList &properties = camera_->properties();\n+\n+\tif (properties.contains(properties::Location)) {\n+\t\tint32_t location = properties.get(properties::Location);\n+\t\tswitch (location) {\n+\t\tcase properties::CameraLocationFront:\n+\t\t\tfacing_ = CAMERA_FACING_FRONT;\n+\t\t\tbreak;\n+\t\tcase properties::CameraLocationBack:\n+\t\t\tfacing_ = CAMERA_FACING_BACK;\n+\t\t\tbreak;\n+\t\tcase properties::CameraLocationExternal:\n+\t\t\tfacing_ = CAMERA_FACING_EXTERNAL;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * The Android orientation metadata and libcamera rotation property are\n+\t * defined differently but have identical numerical values for Android\n+\t * devices such as phones and tablets.\n+\t */\n+\tif (properties.contains(properties::Rotation))\n+\t\torientation_ = properties.get(properties::Rotation);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Open a camera device. The static information on the camera shall have been\n+ * initialized with a call to CameraDevice::init();\n+ */\n int CameraDevice::open(const hw_module_t *hardwareModule)\n {\n \tint ret = camera_->acquire();\n@@ -112,8 +152,6 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \tif (staticMetadata_)\n \t\treturn staticMetadata_->get();\n \n-\tconst ControlList &properties = camera_->properties();\n-\n \t/*\n \t * The here reported metadata are enough to implement a basic capture\n \t * example application, but a real camera implementation will require\n@@ -278,15 +316,7 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \tstaticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,\n \t\t\t\t  &exposureTimeRange, 2);\n \n-\t/*\n-\t * The Android orientation metadata and libcamera rotation property are\n-\t * defined differently but have identical numerical values for Android\n-\t * devices such as phones and tablets.\n-\t */\n-\tint32_t orientation = 0;\n-\tif (properties.contains(properties::Rotation))\n-\t\torientation = properties.get(properties::Rotation);\n-\tstaticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation, 1);\n+\tstaticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation_, 1);\n \n \tstd::vector<int32_t> testPatterModes = {\n \t\tANDROID_SENSOR_TEST_PATTERN_MODE_OFF,\n@@ -332,20 +362,18 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n \t\t\t\t  lensApertures.data(),\n \t\t\t\t  lensApertures.size());\n \n-\tuint8_t lensFacing = ANDROID_LENS_FACING_FRONT;\n-\tif (properties.contains(properties::Location)) {\n-\t\tint32_t location = properties.get(properties::Location);\n-\t\tswitch (location) {\n-\t\tcase properties::CameraLocationFront:\n-\t\t\tlensFacing = ANDROID_LENS_FACING_FRONT;\n-\t\t\tbreak;\n-\t\tcase properties::CameraLocationBack:\n-\t\t\tlensFacing = ANDROID_LENS_FACING_BACK;\n-\t\t\tbreak;\n-\t\tcase properties::CameraLocationExternal:\n-\t\t\tlensFacing = ANDROID_LENS_FACING_EXTERNAL;\n-\t\t\tbreak;\n-\t\t}\n+\tuint8_t lensFacing;\n+\tswitch (facing_) {\n+\tdefault:\n+\tcase CAMERA_FACING_FRONT:\n+\t\tlensFacing = ANDROID_LENS_FACING_FRONT;\n+\t\tbreak;\n+\tcase CAMERA_FACING_BACK:\n+\t\tlensFacing = ANDROID_LENS_FACING_BACK;\n+\t\tbreak;\n+\tcase CAMERA_FACING_EXTERNAL:\n+\t\tlensFacing = ANDROID_LENS_FACING_EXTERNAL;\n+\t\tbreak;\n \t}\n \tstaticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1);\n \ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 350408c1a3e4..ace9c1b7c929 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -27,12 +27,17 @@ public:\n \tCameraDevice(unsigned int id, const std::shared_ptr<libcamera::Camera> &camera);\n \t~CameraDevice();\n \n+\tint initialize();\n+\n \tint open(const hw_module_t *hardwareModule);\n \tvoid close();\n \n \tunsigned int id() const { return id_; }\n \tcamera3_device_t *camera3Device() { return &camera3Device_; }\n \n+\tint facing() const { return facing_; }\n+\tint orientation() const { return orientation_; }\n+\n \tvoid setCallbacks(const camera3_callback_ops_t *callbacks);\n \tconst camera_metadata_t *getStaticMetadata();\n \tconst camera_metadata_t *constructDefaultRequestSettings(int type);\n@@ -69,6 +74,9 @@ private:\n \tCameraMetadata *staticMetadata_;\n \tstd::map<unsigned int, CameraMetadata *> requestTemplates_;\n \tconst camera3_callback_ops_t *callbacks_;\n+\n+\tint facing_;\n+\tint orientation_;\n };\n \n #endif /* __ANDROID_CAMERA_DEVICE_H__ */\ndiff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp\nindex b02d8d1a8362..02b6418fb36d 100644\n--- a/src/android/camera_hal_manager.cpp\n+++ b/src/android/camera_hal_manager.cpp\n@@ -65,8 +65,11 @@ int CameraHalManager::init()\n \tunsigned int index = 0;\n \tfor (auto &cam : cameraManager_->cameras()) {\n \t\tCameraDevice *camera = new CameraDevice(index, cam);\n-\t\tcameras_.emplace_back(camera);\n+\t\tret = camera->initialize();\n+\t\tif (ret)\n+\t\t\tcontinue;\n \n+\t\tcameras_.emplace_back(camera);\n \t\t++index;\n \t}\n \n@@ -107,9 +110,8 @@ int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info)\n \n \tCameraDevice *camera = cameras_[id].get();\n \n-\t/* \\todo Get these info dynamically inspecting the camera module. */\n-\tinfo->facing = id ? CAMERA_FACING_FRONT : CAMERA_FACING_BACK;\n-\tinfo->orientation = 0;\n+\tinfo->facing = camera->facing();\n+\tinfo->orientation = camera->orientation();\n \tinfo->device_version = CAMERA_DEVICE_API_VERSION_3_3;\n \tinfo->resource_cost = 0;\n \tinfo->static_camera_characteristics = camera->getStaticMetadata();\n",
    "prefixes": [
        "libcamera-devel",
        "3/8"
    ]
}