Search code examples
androidandroid-camerax

What's mean "Callback for when the camera has started exposing a frame"


"I am currently exploring the official Android CameraX documentation and came across the onCaptureStarted() method. However, I'm confused about its description, which states: 'Callback for when the camera has started exposing a frame.' Could someone clarify what this means in the context of CameraX? I'm new to understanding camera functionalities."

I have looked up related information, but I do not understand it.


Solution

  • The onCaptureStarted callback of CameraX ImageCapture is ultimately tied to the onCaptureStarted callback of Camera2 framework which also mentions "at the beginning of image exposure".

    This basically means when light is being exposed to the camera sensor in order to do a still image capture. In order to create a capture frame (which you can consider like a single image capture), the scene light is exposed on to the sensor for some amount of time. There are also other processes/calculations involved as well in order to correctly translate that light exposure to an image we are used to. The capture start time is considered as the time when this light exposure for a frame capture first begins and that is the time when onCaptureStarted is invoked.

    So, in layman's terms, it's a bit like -

    1. User requests a still image capture to CameraX
    2. CameraX submits an image capture request to camera framework
    3. Camera framework notifies user when the system has started exposing light to sensor to create a capture frame for this still image capture request. (Or multiple capture frames in case of some non-regular image captures)
    4. CameraX notifies user that this exposure has started via onCaptureStarted callback.
    5. The rest of the image capture process is completed which ultimately leads to an onCaptureSuccess callback and result image being available after some time (if everything goes well that is).

    See sensor frame duration and sensor exposure time for more details regarding the time taken for exposure. How much light is exposed to the sensor depends on how long this time is (as well as other factors like lens aperture, scene illuminance etc) which ultimately effects the image brightness and overall quality.

    One thing to note is that there can be multiple other pre-capture processes involved with an image capture in CameraX. For example, the torch may need to be enabled for an image capture and that may take some time. Or CameraX may still be waiting for some other previous request to be completed or camera to be started.

    So, the onCaptureStarted tells user when exactly the light exposure has begun for the main capture frame of a specific image capture request, which is usually a good time to trigger things like shutter sound or animation.