CameraModule.StreamingSession
ClassContinuous-frame camera session for SPECS.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported — Available on SPECS only
- SPECSFully supported
- Restricted when the Lens uses internet-connected APIs (see Privacy Restrictions).
- Camera Kit WebNot supported — Available on SPECS only
- Camera Kit MobileNot supported — Available on SPECS only
Since Lens Scripting v368Exposes user data
Continuous-frame camera session for SPECS. Created via CameraModule#createStreamingSession. After CameraModule.StreamingSession#start, frames are delivered via CameraModule.StreamingSession#onNewFrame until CameraModule.StreamingSession#stop is called.
Index
Properties
Methods
Remarks
Sessions are restartable: stop() releases the camera, start() can be called again with a new (or the same) StreamConfig.
Example
//@input Component.MeshVisual mesh
let cameraModule = require('LensStudio:CameraModule');
// Camera-first: pick the RGB camera, then its smallest streaming capability.
let rgb = cameraModule.getCameras().find(function (c) { return c.type == CameraModule.CameraType.Rgb; });
let stream = rgb && rgb.getStreams()
.filter(function (s) { return s.operation == CameraModule.Operation.Streaming; })
.sort(function (a, b) { return a.width - b.width; })[0];
let session = cameraModule.createStreamingSession();
let config = new CameraModule.StreamConfig();
config.minFrameRate = 15; // at least 15 fps; the camera may run faster, up to the capability's maxFrameRate
config.setConfig(CameraModule.ConfigKey.AutoExposureRegion, [0.25, 0.75, 0.25, 0.75]); // [left, right, top, bottom]: the center
session.onNewFrame.add(function (frame) {
if (frame.texture) script.mesh.mainPass.baseTex = frame.texture;
});
session.onStatusChanged.add(function (status) {
if (status == CameraModule.StreamStatus.Disconnected) print('Camera disconnected');
});
if (stream) {
config.stream = stream;
if (session.start(config) != CameraModule.Result.Success) print('Failed to start');
}
// Later: session.setConfig(CameraModule.ConfigKey.AutoExposureRegion, [0, 0.5, 0, 0.5]); // meter on the top-left
// Before stop(): session.setConfig(CameraModule.ConfigKey.AutoExposureRegion, [0, 1, 0, 1]); // meter the whole frame again
// Later: session.stop(); // Restartable.
Extends
Properties
onNewFrame
readonlyonNewFrame:event1<Frame,void>
Exposes user dataSPECS
Event triggered when a new camera frame is available.
Since
Lens Scripting Version 368
onStatusChanged
readonlyonStatusChanged:event1<StreamStatus,void>
Exposes user dataSPECS
Event triggered when session status changes (interruption, disconnection).
Since
Lens Scripting Version 368
Methods
getTypeName()
staticgetTypeName():TypeName<StreamingSession>
Exposes user dataSPECS
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<StreamingSession>
Since
Lens Scripting Version 368
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
setConfig()
setConfig(
key,values):Result
Exposes user dataSPECS
Reconfigure a live streaming session. AutoExposureRegion can change mid-stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | ConfigKey | Configuration key. |
values | number[] | Configuration values array. |
Returns
Success when accepted; NotStarted before start(); SessionStopped after a Disconnected status; InvalidConfig for SnapshotMfnrEnable; InvalidArgument for invalid values; ErrorGeneric when the camera service cannot apply the change.
Since
Lens Scripting Version 368
start()
start(
config?):Result
Exposes user dataSPECS
Start continuous frame delivery. The configured stream is opened and frames begin flowing to onNewFrame.
Throws when minFrameRate, rounded up to a whole Hz, exceeds the stream's maxFrameRate, or when outputWidth or outputHeight is set: they apply to capture sessions only.
Parameters
| Parameter | Type | Description |
|---|---|---|
config? | StreamConfig | Stream configuration whose stream's operation is Streaming. Required on every start(). |
Returns
Success if the session is now running. AlreadyStarted if it is already running; SessionStopped after a Disconnected status (create a new session); InvalidArgument for a missing stream or invalid tuning values; InvalidConfig when the stream's operation is not Streaming or a snapshot-only key is set; NotInitialized when the session's camera client is not available; ErrorGeneric when the camera service cannot be reached or cannot open the camera, or another stream would pass the session limits (see Result.ErrorGeneric).
Since
Lens Scripting Version 368
stop()
stop():
Result
Exposes user dataSPECS
Stop the session and release the underlying camera stream. Restartable: call CameraModule.StreamingSession#start again.
Returns
Success; NotStarted when the session is not running; SessionStopped after a Disconnected status.
Since
Lens Scripting Version 368