DeepMedia logodeepmedia

Camera SDK

Version 0.8.5

Search

Choose platform

Other versions of this page

Concepts

API Design

Unless otherwise stated, the SDK APIs can be considered thread-safe. When any action is expensive in terms of time or performance, it will be represented by a suspending / async function which you can execute in a CoroutineScopeawait in your code.

In general, the SDK makes extensive use of kotlinx.coroutine APIs: for example, many mutable variables are exposed as a StateFlow<T>. Basic experience with such APIs and concepts is required in order to use the SDK efficiently.

In general, the SDK makes extensive use of Swift concurrency and Combine APIs. For example, you may find mutable variables exposed as a Sequence or a Publisher. Basic experience with such APIs and concepts is required in order to use the SDK efficiently.

The Camera SDK APIs are distributed among two main classes:

  • CameraManager
  • CameraDevice

Camera Manager

The entry point of the library is called CameraManager. A manager is responsible for managing a set of devices, each of them representing a connection to one or more physical camera sensors currently available on the device.

⚠️

Only use one CameraManager at a time.

Creating a Manager

The CameraManager has a public constructor accepting an array of CameraFeatures:

kotlin logokotlin
val manager = CameraManager(features = listOf(CameraFeature.Preview, CameraFeature.JpegPicture))
swift
let manager = CameraManager(features: [.preview, .jpegPicture])

These features are hints to what you plan to do with the cameras. It is very important that this list reflects the intended usage, otherwise the manager may fail at allocating resources and sensor connections, or provide low-quality outputs.

FeatureMeaning
CameraFeature.Preview.previewStreaming real-time preview of the camera stream into one or more views.
CameraFeature.JpegPicture.jpegPictureCapturing high quality JPEG pictures.
CameraFeature.Video.videoRecording video files.
CameraFeature.Barcode.barcodeDetecting barcodes in real-time.

Manager Lifecycle

You should use one manager at a time, because managers take an exclusive lock on system resources like camera access.

Whenever you are done with a manager, and before creating a new one, make sure it leaves the scope so it is garbage collected and goes through deinitialization. This will make sure that resources are released for the next manager (or next app).

Whenever you are done with a manager, and before creating a new one, make sure you invoke CameraManager.destroy(). This will make sure that resources are released for the next manager (or next app).

kotlin logokotlin
manager.destroy()

Permissions

By design, the SDK will not ask the user for camera access permissions, nor microphone usage in case of video recordings. It is your responsibility to do so and, once granted, interact with APIs that would otherwise fail.

When permissions are missing and an API requiring it is invoked, it will fail by throwing a MissingPermissionExceptionMissingPermissionError.

Subscribe to the DeepMedia Newsletter

The latest news about DeepMedia products, open source projects and software development at our company.

By clicking “Subscribe”, you agree that DeepMedia may use your email address to send you newsletters, including commercial communications, and to process your personal data for this purpose. You agree that DeepMedia may process said data using third-party services for this purpose in accordance with the DeepMedia Privacy Policy. You can revoke this consent at any time using the unsubscribe link included in each email or by writing at contact@deepmedia.io.