AOSP Framework & Internals
2 min read

Camera HAL

Learn about Camera HAL.

Introduction

The Camera Hardware Abstraction Layer (HAL) connects the CameraService in the Android framework to the vendor-specific Image Signal Processor (ISP) and camera sensor drivers. Due to the massive bandwidth required by high-resolution sensors and the complexity of modern computational photography, the Camera HAL is one of the most sophisticated components in AOSP.

Camera HAL 3 (CameraDevice HAL)

Modern Android devices exclusively use the Camera HAL 3 architecture. Unlike older versions which operated on a state-machine basis (preview, capture, record), HAL 3 operates on a strictly pipeline-based, per-frame request model.

The primary interface exposed by the vendor is ICameraDeviceSession. The framework uses this to submit requests, configure streams, and receive image data.

Camera Request Model

In HAL 3, the framework sends a CaptureRequest for every single frame. This request contains all the manual settings for that specific frame (ISO, exposure time, autofocus region).

// Framework submitting a batch of requests to the HAL
Return<void> processCaptureRequest_3_4(
    const hidl_vec<CaptureRequest>& requests,
    const hidl_vec<BufferCache>& cachesToRemove,
    processCaptureRequest_3_4_cb _hidl_cb);

The HAL takes these requests, queues them into the hardware ISP, and processes them asynchronously. This allows the framework to dynamically adjust exposure on a frame-by-frame basis without disrupting the video stream.

CaptureResult and Metadata

Once the sensor captures the frame and the ISP processes it, the HAL returns a CaptureResult back to the framework via a callback.

This result contains not just the image buffers, but a massive block of Metadata (stored in a specialized camera_metadata_t struct). This metadata tells the framework exactly what physical settings were applied to that specific frame. If the framework requested an ISO of 400, but the hardware clamped it to 800 due to lighting, the CaptureResult metadata will reflect the actual ISO 800 value.

Multi-camera HAL

Modern smartphones have multiple physical lenses (Wide, Ultrawide, Telephoto). The HAL represents these as a single "Logical Camera" to the application layer.

Behind the scenes, the Multi-camera HAL handles the complex logic of switching between physical sensors as the user zooms. It must align the image streams, match color calibration across different lenses, and sometimes even fuse data from two sensors simultaneously (e.g., using the telephoto for center detail and the wide for edge detail) to output a single logical frame to the framework.