# CameraService

<Badge tone="type">class · Singleton&lt;CameraService&gt;</Badge> <Badge>Unity component</Badge> <Badge>singleton</Badge>

```csharp
public sealed class CameraService : Singleton<CameraService>, ICameraService
```

**Namespace:** `AR51.Unity.SDK` · **Inherits:** `Singleton<CameraService>` (a Unity `MonoBehaviour`) · implements `ICameraService`

Controls this device's local camera capture and streaming — used when the Unity instance is itself acting as a capture device. Drop the component on a GameObject, call [`StartStreaming`](#startstreaming) to begin capture, then pull frames off the collection returned by [`GetFeed`](#getfeed). Backed by an internal device `CameraAdapter`.

:::note[Units]
Pixel dimensions (`width`/`height`, `PreviewWidth`/`PreviewHeight`) are in **pixels**; `fps` is frames/second; `jpgQuality` is `0–100`. AR 51 spatial data elsewhere in the SDK is in **meters** — `CameraService` itself carries no spatial units.
:::

:::note[Internal — not documented]
`CameraService`'s `CameraAdapters` (and the NatDevice integration) are device-capture / third-party plumbing for grabbing frames from the local camera hardware. They are not part of the documented public surface — use the properties and methods below instead.
:::

## Properties

<div className="apiPropTable">

| Property | Type | Access | Description |
|---|---|---|---|
| **Capture state** | | | |
| `IsStreaming` | `bool` | get | `true` while capture/streaming is active |
| `Frame` | [`Texture`](https://docs.unity3d.com/ScriptReference/Texture.html) | get | the latest captured frame |
| `HologramsEnabled` | `bool` | get / set | composite holograms into the captured frame |
| `Recorder` | [`IVideoRecorder`](/docs/sdk-api/unity-api/connection) | get | the active video recorder, if any |
| `Characteristics` | [`ICameraCharacteristics`](/docs/sdk-api/unity-api/connection) | get | static capabilities of the backing camera |
| **Scene references** | | | |
| `MainCamera` | [`Camera`](https://docs.unity3d.com/ScriptReference/Camera.html) | field | scene main-camera reference |
| `NoFeedDefault` | [`Texture2D`](https://docs.unity3d.com/ScriptReference/Texture2D.html) | field | fallback texture shown when there is no feed |
| `NoFeedDefaultJpg` | `byte[]` | field | fallback JPG bytes when there is no feed |
| **Preview** | | | |
| `PreviewWidth` | `int` | get / set | preview width in **pixels** |
| `PreviewHeight` | `int` | get / set | preview height in **pixels** |
| **Exposure** | | | |
| `ExposureLock` | `bool` | get / set | lock auto-exposure |
| `ExposureBias` | `float` | get / set | exposure-bias value (clamped to the min/max below) |
| `ExposureBiasMin` | `float` | get | minimum supported exposure bias |
| `ExposureBiasMax` | `float` | get | maximum supported exposure bias |
| **Focus** | | | |
| `AutoFocus` | `bool` | get / set | enable continuous auto-focus |

</div>

## Method summary

| Method | Returns | |
|---|---|---|
| [`StartStreaming`](#startstreaming) | `void` | <Badge>instance</Badge> |
| [`SuspendStreaming`](#suspendstreaming) | `void` | <Badge>instance</Badge> |
| [`ResumeStreaming`](#resumestreaming) | `void` | <Badge>instance</Badge> |
| [`StopStreaming`](#stopstreaming) | `void` | <Badge>instance</Badge> |
| [`GetFeed`](#getfeed) | `BlockingCollection<CameraFrame>` | <Badge>instance</Badge> |
| [`StartTestStreaming`](#startteststreaming) | `void` | <Badge>instance</Badge> |

→ Full descriptions in [Method details](#method-details) below.

## Method details

### StartStreaming

<ApiBody kind="method" tags="instance">

```csharp
public void StartStreaming(int width, int height, int fps, int jpgQuality, bool hologramsEnabled);
```

Begins camera capture/streaming. After calling this, read frames off the collection returned by [`GetFeed`](#getfeed).

<Params>
<Param name="width" type="int">capture width in **pixels**</Param>
<Param name="height" type="int">capture height in **pixels**</Param>
<Param name="fps" type="int">target frame rate, frames/second</Param>
<Param name="jpgQuality" type="int">JPG encode quality, `0–100`</Param>
<Param name="hologramsEnabled" type="bool">composite holograms into each captured frame (sets `HologramsEnabled`)</Param>
</Params>

<Example inferred>

```csharp
var cam = CameraService.Instance;            // Singleton<CameraService>
cam.StartStreaming(1280, 720, 30, 80, hologramsEnabled: true);

var feed = cam.GetFeed();
foreach (CameraFrame frame in feed.GetConsumingEnumerable())
{
    // process each captured frame (e.g. frame.Jpg)
}
```

</Example>

</ApiBody>

### SuspendStreaming

<ApiBody kind="method" tags="instance">

```csharp
public void SuspendStreaming();
```

Pauses capture without tearing it down. Pair with [`ResumeStreaming`](#resumestreaming) to continue with the same configuration (e.g. across an application-pause). `IsStreaming` reflects the suspended state.

</ApiBody>

### ResumeStreaming

<ApiBody kind="method" tags="instance">

```csharp
public void ResumeStreaming();
```

Resumes capture previously paused with [`SuspendStreaming`](#suspendstreaming).

</ApiBody>

### StopStreaming

<ApiBody kind="method" tags="instance">

```csharp
public void StopStreaming();
```

Stops capture and tears down the stream. After this, `IsStreaming` is `false` and [`GetFeed`](#getfeed) no longer yields new frames.

</ApiBody>

### GetFeed

<ApiBody kind="method" tags="instance">

```csharp
public BlockingCollection<CameraFrame> GetFeed();
```

The frame queue for the active stream. Pull frames off it (e.g. with `GetConsumingEnumerable()`); each item is a [`CameraFrame`](/docs/sdk-api/unity-api/connection). Call after [`StartStreaming`](#startstreaming) (or [`StartTestStreaming`](#startteststreaming)).

<Returns type="BlockingCollection<CameraFrame>" typeHref="/docs/sdk-api/unity-api/connection#types">the live frame collection for the current stream</Returns>

</ApiBody>

### StartTestStreaming

<ApiBody kind="method" tags="instance">

```csharp
public void StartTestStreaming();
```

Convenience entry point for testing: starts streaming at **1280×720 @ 30 fps, quality 100**. Equivalent to calling [`StartStreaming`](#startstreaming) with those values. Read the result via [`GetFeed`](#getfeed).

</ApiBody>

## See also

- [`CameraFeedClient`](/docs/sdk-api/unity-api/classes/camerafeedclient) — the client for consuming a **remote** CVS camera feed (this class is for the **local** device camera)
- [`RenderService`](/docs/sdk-api/unity-api/classes/renderservice) — renders and re-encodes a remote camera's composited feed
- [Connection & Services](/docs/sdk-api/unity-api/connection) — `CameraFrame`, `IVideoRecorder`, `ICameraCharacteristics`, and the service entry points
- [Class index](/docs/sdk-api/unity-api/classes) — all Unity SDK types
