# RenderService

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

```csharp
public sealed class RenderService : Singleton<RenderService>, IRenderService
```

**Namespace:** `AR51.Unity.SDK` · **Implements:** `IRenderService`

Renders a remote CVS camera's JPG feed into a Unity camera positioned by that camera's extrinsics, composites the scene (holograms) on top, and re-encodes the result as a JPG stream. Use it to display a remote camera view with overlaid holograms. Internally it reads the camera's intrinsic/extrinsic matrices and FOV via [`CvsCameraInfo`](/docs/sdk-api/unity-api/connection#cvscamerainfo) to place the render camera. Lives in the scene as a singleton — reach it through `RenderService.Instance`.

:::note
**Units:** AR 51 mocap data and all SDK world-space positions are in **meters**; rotations are `Quaternion`; angles in **degrees**. The frame parameters on this class are in **pixels** (`width`/`height`), **frames per second** (`frameRate`), and **0–100** (`jpgQuality`).
:::

## Properties

<div className="apiPropTable">

| Property | Type | Default | Description |
|---|---|---|---|
| **Configuration** | | | |
| `RenderCameraPrefab` | [`GameObject`](https://docs.unity3d.com/ScriptReference/GameObject.html) | — | prefab instantiated per rendered camera |
| `RenderCameraCullingMask` | [`LayerMask`](https://docs.unity3d.com/ScriptReference/LayerMask.html) | — | layers the render camera draws (which holograms appear) |
| **Diagnostics** | | | |
| `LogDroppedFrames` | `bool` | `false` | log when output frames are dropped |

</div>

## Method summary

**Instance**

| Method | Returns | |
|---|---|---|
| [`StartRendering`](#startrendering) | `BlockingCollection<byte[]>` | <Badge>Unity component</Badge> |
| [`GetFeed`](#getfeed) | `BlockingCollection<byte[]>` | <Badge>Unity component</Badge> |
| [`StopRendering`](#stoprendering) | `void` | <Badge>Unity component</Badge> |

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

## Method details

### StartRendering

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

```csharp
public BlockingCollection<byte[]> StartRendering(string cameraId, string address, int port,
    int width, int height, int frameRate, int jpgQuality);
```

Begins compositing the named remote camera feed and returns the output stream. The service instantiates `RenderCameraPrefab`, places it using the camera's extrinsics/FOV (read via [`CvsCameraInfo`](/docs/sdk-api/unity-api/connection#cvscamerainfo)), renders the scene at the requested resolution, and re-encodes each composited frame to JPG. Call once per camera; pull frames off the returned collection.

<Params>
<Param name="cameraId" type="string">id of the remote camera to render (see [`CvsCameraInfo.Id`](/docs/sdk-api/unity-api/connection#cvscamerainfo))</Param>
<Param name="address" type="string">CVS / camera-feed service host (IP or hostname)</Param>
<Param name="port" type="int">service port</Param>
<Param name="width" type="int">output width in **pixels**</Param>
<Param name="height" type="int">output height in **pixels**</Param>
<Param name="frameRate" type="int">target output rate in **frames per second**</Param>
<Param name="jpgQuality" type="int">JPG encode quality, **0–100**</Param>
</Params>

<Returns type="BlockingCollection<byte[]>">a blocking collection of output JPG frames (each `byte[]` is one encoded frame). Take from it on a background thread to consume frames as they are produced.</Returns>

⚠️ The render camera is positioned by the remote camera's extrinsics; the SDK applies a 180° rotation about Z to map the CVS y-up / right-handed convention into Unity (see [`GetExtrinsic`](/docs/sdk-api/unity-api/recording-utilities#extensions)). If your overlay appears flipped or rotated, that handedness conversion is the place to look.

<Example inferred>

```csharp
using System.Collections.Concurrent;
using AR51.Unity.SDK;

var render = RenderService.Instance;
// 1920x1080 @ 30 fps, quality 90 — exact camera id/host/port come from your CVS deployment
BlockingCollection<byte[]> frames =
    render.StartRendering("cam-0", "127.0.0.1", 50051, 1920, 1080, 30, 90);

// Consume on a worker thread; each item is one composited JPG frame.
foreach (byte[] jpg in frames.GetConsumingEnumerable())
{
    // e.g. push to a Texture2D.LoadImage(jpg) on the Unity thread, or relay onward
}
```

</Example>

</ApiBody>

### GetFeed

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

```csharp
public BlockingCollection<byte[]> GetFeed(string cameraId, string address, int port);
```

Returns the **same** output collection for a camera that has already been started with [`StartRendering`](#startrendering). Use it to obtain the JPG stream from another part of your code without re-starting the render.

<Params>
<Param name="cameraId" type="string">id of an already-rendering camera</Param>
<Param name="address" type="string">the service host passed to `StartRendering`</Param>
<Param name="port" type="int">the service port passed to `StartRendering`</Param>
</Params>

<Returns type="BlockingCollection<byte[]>">the existing output JPG-frame collection for that camera</Returns>

</ApiBody>

### StopRendering

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

```csharp
public void StopRendering(string cameraId, string address, int port);
```

Stops compositing the named camera, tears down its render camera, and completes the output collection. Call this when you no longer need the feed (e.g. on disable / scene teardown).

<Params>
<Param name="cameraId" type="string">id of the camera to stop</Param>
<Param name="address" type="string">the service host passed to `StartRendering`</Param>
<Param name="port" type="int">the service port passed to `StartRendering`</Param>
</Params>

</ApiBody>

## See also

- [`CameraService`](/docs/sdk-api/unity-api/classes/cameraservice) — controls this device's **local** camera capture/streaming (vs. rendering a remote one)
- [`CameraFeedClient`](/docs/sdk-api/unity-api/classes/camerafeedclient) — enumerate remote cameras and fetch their `CvsCameraInfo`
- [`ServiceManager`](/docs/sdk-api/unity-api/classes/servicemanager) — the connection entry point that stands up the service host
- [`CvsCameraInfo`](/docs/sdk-api/unity-api/connection#cvscamerainfo) — the remote-camera data model whose matrices position the render camera
- [`GetExtrinsic` / `GetVerticalFOV`](/docs/sdk-api/unity-api/recording-utilities#extensions) — the `CvsCameraInfo` extension helpers used internally
- [Class index](/docs/sdk-api/unity-api/classes) — all Unity SDK types
