Skip to main content

CameraService

class · Singleton<CameraService> Unity component singleton
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 to begin capture, then pull frames off the collection returned by GetFeed. Backed by an internal device CameraAdapter.

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 metersCameraService itself carries no spatial units.

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

PropertyTypeAccessDescription
Capture state
IsStreamingboolgettrue while capture/streaming is active
FrameTexturegetthe latest captured frame
HologramsEnabledboolget / setcomposite holograms into the captured frame
RecorderIVideoRecordergetthe active video recorder, if any
CharacteristicsICameraCharacteristicsgetstatic capabilities of the backing camera
Scene references
MainCameraCamerafieldscene main-camera reference
NoFeedDefaultTexture2Dfieldfallback texture shown when there is no feed
NoFeedDefaultJpgbyte[]fieldfallback JPG bytes when there is no feed
Preview
PreviewWidthintget / setpreview width in pixels
PreviewHeightintget / setpreview height in pixels
Exposure
ExposureLockboolget / setlock auto-exposure
ExposureBiasfloatget / setexposure-bias value (clamped to the min/max below)
ExposureBiasMinfloatgetminimum supported exposure bias
ExposureBiasMaxfloatgetmaximum supported exposure bias
Focus
AutoFocusboolget / setenable continuous auto-focus

Method summary

MethodReturns
StartStreamingvoidinstance
SuspendStreamingvoidinstance
ResumeStreamingvoidinstance
StopStreamingvoidinstance
GetFeedBlockingCollection<CameraFrame>instance
StartTestStreamingvoidinstance

→ Full descriptions in Method details below.

Method details

StartStreaming

methodinstance
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.

Parameters
widthintcapture width in pixels
heightintcapture height in pixels
fpsinttarget frame rate, frames/second
jpgQualityintJPG encode quality, 0–100
hologramsEnabledboolcomposite holograms into each captured frame (sets HologramsEnabled)
Exampleinferred
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)
}

SuspendStreaming

methodinstance
public void SuspendStreaming();

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

ResumeStreaming

methodinstance
public void ResumeStreaming();

Resumes capture previously paused with SuspendStreaming.

StopStreaming

methodinstance
public void StopStreaming();

Stops capture and tears down the stream. After this, IsStreaming is false and GetFeed no longer yields new frames.

GetFeed

methodinstance
public BlockingCollection<CameraFrame> GetFeed();

The frame queue for the active stream. Pull frames off it (e.g. with GetConsumingEnumerable()); each item is a CameraFrame. Call after StartStreaming (or StartTestStreaming).

ReturnsBlockingCollection<CameraFrame>the live frame collection for the current stream

StartTestStreaming

methodinstance
public void StartTestStreaming();

Convenience entry point for testing: starts streaming at 1280×720 @ 30 fps, quality 100. Equivalent to calling StartStreaming with those values. Read the result via GetFeed.

See also

  • CameraFeedClient — the client for consuming a remote CVS camera feed (this class is for the local device camera)
  • RenderService — renders and re-encodes a remote camera's composited feed
  • Connection & ServicesCameraFrame, IVideoRecorder, ICameraCharacteristics, and the service entry points
  • Class index — all Unity SDK types
Was this page helpful?