@snap/camera-kit
Version:
Camera Kit Web
121 lines (72 loc) • 4.01 kB
Markdown
[CameraKit Web SDK - v0.22.0](../README.md) / [Exports](../modules.md) / CameraKitSource
# Class: CameraKitSource
This general-purpose class represents a source of media for a [CameraKitSession](CameraKitSession.md).
When an instance is passed to [CameraKitSession.setSource](CameraKitSession.md#setsource), it will be "attached"
to the session. Later it may be "detached" from the session.
Passing a [CameraKitSourceSubscriber](../interfaces/CameraKitSourceSubscriber.md) to the constructor allows callers to specify behavior
that will occur when the source is attached and detached. This can be used to e.g. update the render size.
## Table of contents
### Constructors
- [constructor](CameraKitSource.md#constructor)
### Methods
- [copy](CameraKitSource.md#copy)
- [setRenderSize](CameraKitSource.md#setrendersize)
- [setTransform](CameraKitSource.md#settransform)
## Constructors
### constructor
• **new CameraKitSource**(`sourceInfo`, `subscriber?`, `deviceInfo?`): [`CameraKitSource`](CameraKitSource.md)
#### Parameters
| Name | Type |
| :------ | :------ |
| `sourceInfo` | [`CameraKitSourceInfo`](../interfaces/CameraKitSourceInfo.md) |
| `subscriber` | [`CameraKitSourceSubscriber`](../interfaces/CameraKitSourceSubscriber.md) |
| `deviceInfo` | `Partial`\<[`CameraKitDeviceOptions`](../interfaces/CameraKitDeviceOptions.md)\> |
#### Returns
[`CameraKitSource`](CameraKitSource.md)
## Methods
### copy
▸ **copy**(`deviceInfo?`): [`CameraKitSource`](CameraKitSource.md)
Make a copy of the source, sharing the same [CameraKitSourceSubscriber](../interfaces/CameraKitSourceSubscriber.md).
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `deviceInfo` | `Partial`\<[`CameraKitDeviceOptions`](../interfaces/CameraKitDeviceOptions.md)\> | Optionally provide new device info for the copy (e.g. to change the camera type). |
#### Returns
[`CameraKitSource`](CameraKitSource.md)
The new [CameraKitSource](CameraKitSource.md)
___
### setRenderSize
▸ **setRenderSize**(`width`, `height`): `Promise`\<`void`\>
Set the resolution used to render this source.
If greater performance is required, a smaller render size may boost frame-rate. It does come at a cost, including
loss of accuracy in various tracking and computer-vision algorithms (since they'll be operating on fewer pixels).
By default (i.e. if this method is never called), then the render size will match the size of the input media.
Best performance can be achieved by varying the size of the input media and allowing CameraKit to render at a
resolution that matches the input media -- this method should only be used if the input media resolution cannot
be changed to the desired size.
It’s important to distinguish render size from display size. The size at which the output canvases are displayed
on a web page is determined by the CSS of the page. It is distinct from the size at which CameraKit renders
Lenses. Performance is dominated by render size, while any display scaling (using CSS) can most often be thought
of as free.
The size of the Live and Capture [RenderTarget](../modules.md#rendertarget) is always the same.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `width` | `number` | pixels |
| `height` | `number` | pixels |
#### Returns
`Promise`\<`void`\>
Promise resolves when the render size has been successfully updated.
**`Todo`**
Currently it's only valid to call `setRenderSize` after `CameraKitSession.play` has been called. This
constraint should be removed, so callers don't have to understand the underlying LensCore state machine.
___
### setTransform
▸ **setTransform**(`transform`): `Promise`\<`void`\>
Apply a 2D transformation to the source (e.g. translation, rotation, scale).
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `transform` | [`Transform2D`](Transform2D.md) | Specifies the 3x3 matrix describing the transformation. |
#### Returns
`Promise`\<`void`\>