UNPKG

@flashport/flashport

Version:

FlashPort is a TypeScript 2D graphics library that largely replicates the Flash ActionScript 3.0 library

346 lines (345 loc) 16.8 kB
import { BitmapData } from "../display/BitmapData"; import { DisplayObject } from "../display/DisplayObject"; import { EventDispatcher } from "../events/EventDispatcher"; import { Rectangle } from "../geom/Rectangle"; import { ByteArray } from "../utils/ByteArray"; /** * Dispatched when a camera reports its status. * @eventType flash.events.StatusEvent.STATUS */ /** * Dispatched when a camera begins or ends a session. * @eventType flash.events.ActivityEvent.ACTIVITY */ /** * Use the Camera class to capture video from the client system's camera. * Use the Video class to monitor the video locally. * Use the NetConnection and NetStream classes to transmit the video to Flash Media Server. * Flash Media Server can send the video stream to other servers and broadcast it to other clients running Flash Player. * * <p class="- topic/p ">A Camera instance captures video in landscape aspect ratio. On devices that can change the screen orientation, * such as mobile phones, a Video object attached to the camera will only show upright video in a landscape-aspect orientation. * Thus, mobile apps should use a landscape orientation when displaying video and should not auto-rotate.</p><p class="- topic/p ">As of AIR 2.6, autofocus is enabled automatically on mobile devices with an autofocus camera. If the camera does not support continuous autofocus, * and many mobile device cameras do not, then the camera is focused when the Camera object is attached to a video stream and whenever * the <codeph class="+ topic/ph pr-d/codeph ">setMode()</codeph> method is called. On desktop computers, autofocus behavior is dependent on the camera driver and settings.</p><p class="- topic/p ">In an AIR application on Android and iOS, the camera does not capture video while an AIR app is not the active, foreground application. * In addition, streaming connections can be lost when the application is in the background. On iOS, the camera video cannot be * displayed when an application uses the GPU rendering mode. The camera video can still be streamed to a server.</p><p class="- topic/p "><b class="+ topic/ph hi-d/b ">Mobile Browser Support:</b> This class is not supported in mobile browsers.</p><p class="- topic/p "><i class="+ topic/ph hi-d/i ">AIR profile support:</i> This feature is supported * on desktop operating systems, but it is not supported on all mobile devices. It is not * supported on AIR for TV devices. See * <xref href="http://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html" class="- topic/xref "> * AIR Profile Support</xref> for more information regarding API support across multiple profiles.</p><p class="- topic/p ">You can test * for support at run time using the <codeph class="+ topic/ph pr-d/codeph ">Camera.isSupported</codeph> property. * Note that for AIR for TV devices, <codeph class="+ topic/ph pr-d/codeph ">Camera.isSupported</codeph> is <codeph class="+ topic/ph pr-d/codeph ">true</codeph> but * <codeph class="+ topic/ph pr-d/codeph ">Camera.getCamera()</codeph> always returns <codeph class="+ topic/ph pr-d/codeph ">null</codeph>.</p><p class="- topic/p "> * For information about capturing audio, see the Microphone class. * </p><p class="- topic/p "><b class="+ topic/ph hi-d/b ">Important: </b>Flash Player displays a Privacy dialog box that lets the user choose whether * to allow or deny access to the camera. Make sure your application window size is at least 215 x 138 pixels; * this is the minimum size required to display the dialog box. * </p><p class="- topic/p ">To create or reference a Camera object, use the <codeph class="+ topic/ph pr-d/codeph ">getCamera()</codeph> method.</p> * * EXAMPLE: * * The following example shows the image from a camera after acknowledging the * security warning. The Stage is set such that it cannot be scaled and is aligned to the * top-left of the player window. The <codeph class="+ topic/ph pr-d/codeph ">activity</codeph> event is dispatched at the * start and end (if any) of the session and is captured by the <codeph class="+ topic/ph pr-d/codeph ">activityHandler()</codeph> * method, which prints out information about the event. * * <p class="- topic/p "><b class="+ topic/ph hi-d/b ">Note:</b> A camera must be attached to your computer for this example * to work correctly.</p><codeblock xml:space="preserve" class="+ topic/pre pr-d/codeblock "> * * package { * import flash.display.Sprite; * import flash.display.StageAlign; * import flash.display.StageScaleMode; * import flash.events.*; * import flash.media.Camera; * import flash.media.Video; * * public class CameraExample extends Sprite { * private var video:Video; * * public function CameraExample() { * stage.scaleMode = StageScaleMode.NO_SCALE; * stage.align = StageAlign.TOP_LEFT; * * var camera:Camera = Camera.getCamera(); * * if (camera != null) { * camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler); * video = new Video(camera.width * 2, camera.height * 2); * video.attachCamera(camera); * addChild(video); * } else { * trace("You need a camera."); * } * } * * private function activityHandler(event:ActivityEvent):void { * trace("activityHandler: " + event); * } * } * } * </codeblock> * @langversion 3.0 * @playerversion Flash 9 */ export declare class Camera extends EventDispatcher { private static _mediaDevices; private _stream; private _videoElement; private _cameraStream; private _cameraId; private _diffCanvas; private _diffContext; private _motionCanvas; private _motionContext; private _motionTimer; private _motionLevel; private _pixelDiffThreshold; private _diffWidth; private _diffHeight; private _diffdata; private _activityLevel; private _motionTimeout; private _motionDetected; private _showMotionCanvas; private static _name; private static _names; private static _devices; static dispatchObject: DisplayObject; /** * The amount of motion the camera is detecting. Values range from 0 (no motion is being detected) to * 100 (a large amount of motion is being detected). The value of this property can help you determine if you need to pass a setting * to the setMotionLevel() method. * If the camera is available but is not yet being used because the * Video.attachCamera() method has not been called, this property * is set to -1.If you are streaming only uncompressed local video, this property is set only if you have assigned a function to the event * handler. Otherwise, it is undefined. * @langversion 3.0 * @playerversion Flash 9 */ get activityLevel(): number; /** * The maximum amount of bandwidth the current outgoing video feed can use, in bytes. * A value of 0 means the feed can use as much bandwidth as needed to maintain the desired frame quality. * To set this property, use the setQuality() method. * @langversion 3.0 * @playerversion Flash 9 */ get bandwidth(): number; /** * The rate at which the camera is capturing data, in frames per second. * This property cannot be set; however, you can use the setMode() method * to set a related property—fps—which specifies the maximum * frame rate at which you would like the camera to capture data. * @langversion 3.0 * @playerversion Flash 9 */ get currentFPS(): number; /** * The maximum rate at which the camera can capture data, in frames per second. * The maximum rate possible depends on the capabilities of the camera; this frame rate may not be achieved. * To set a desired value for this property, use the setMode() method.To determine the rate at which the camera is currently capturing data, use the currentFPS property. * @langversion 3.0 * @playerversion Flash 9 */ get fps(): number; /** * The current capture height, in pixels. To set a value for this property, * use the setMode() method. * @langversion 3.0 * @playerversion Flash 9 */ get height(): number; /** * A zero-based integer that specifies the index of the camera, as reflected in * the array returned by the names property. * @langversion 3.0 * @playerversion Flash 9 */ get index(): number; /** * The isSupported property is set to true if the * Camera class is supported on the current platform, otherwise it is * set to false. * @langversion 3.0 * @playerversion Flash 10.1 * @playerversion AIR 2 */ static get isSupported(): boolean; /** * The number of video frames transmitted in full (called keyframes) * instead of being interpolated by the video compression algorithm. * The default value is 15, which means that every 15th frame is a keyframe. * A value of 1 means that every frame is a keyframe. The allowed values are * 1 through 48. * @langversion 3.0 * @playerversion Flash 9 */ get keyFrameInterval(): number; /** * Indicates whether a local view of what the camera is capturing is compressed * and decompressed (true), as it would be for live transmission using * Flash Media Server, or uncompressed (false). The default value is * false. * * Although a compressed stream is useful for testing, such as when previewing * video quality settings, it has a significant processing cost. The local view * is compressed, edited for transmission as it would be over a live connection, * and then decompressed for local viewing. * To set this value, use Camera.setLoopback(). To set the amount of * compression used when this property is true, use Camera.setQuality(). * @langversion 3.0 * @playerversion Flash 9 */ get loopback(): boolean; /** * The amount of motion required to invoke the activity event. Acceptable values range from 0 to 100. * The default value is 50. * Video can be displayed regardless of the value of the motionLevel property. For more information, see * setMotionLevel(). * @langversion 3.0 * @playerversion Flash 9 */ get motionLevel(): number; /** * The number of milliseconds between the time the camera stops detecting motion and the time the activity event is invoked. The * default value is 2000 (2 seconds). * To set this value, use setMotionLevel(). * @langversion 3.0 * @playerversion Flash 9 */ get motionTimeout(): number; /** * A Boolean value indicating whether the user has denied access to the camera * (true) or allowed access (false) in the Flash Player Privacy dialog box. * * When this value changes, the statusevent is dispatched. * @langversion 3.0 * @playerversion Flash 9 */ get muted(): boolean; /** * The name of the current camera, as returned by the camera hardware. * @langversion 3.0 * @playerversion Flash 9 */ get name(): string; /** * @langversion 3.0 * @playerversion Flash 9 */ static get names(): any[]; get position(): string; /** * @langversion 3.0 * @playerversion Flash 9 */ get quality(): number; /** * The current capture width, in pixels. To set a desired value for this property, * use the setMode() method. * @langversion 3.0 * @playerversion Flash 9 */ get width(): number; /** * retrieves the available camera stream. */ get cameraStream(): MediaStream; set cameraStream(value: MediaStream); /** * video element used for camera. */ get videoElement(): HTMLVideoElement; set videoElement(value: HTMLVideoElement); get showMotionCanvas(): boolean; set showMotionCanvas(value: boolean); private static _scanHardware; constructor(); copyToByteArray(rect: Rectangle, destination: ByteArray): void; copyToVector(rect: Rectangle, destination: number[]): void; /** * Draws the current camera frame to the destination bitmapdata. * @param destination the BitmapData object to use for drawing. */ drawToBitmapData(destination: BitmapData): void; /** * @param name Specifies which camera to get, as determined from the array * returned by the names property. For most applications, get the default camera * by omitting this parameter. To specify a value for this parameter, use the string representation * of the zero-based index position within the Camera.names array. For example, to specify the third * camera in the array, use Camera.getCamera("2"). * @param facingMode Used to specify on mobile devices to use front facing camera "user" or the back camera "environment". * @return If the name parameter is not specified, this method returns a reference * to the default camera or, if it is in use by another application, to the first * available camera. (If there is more than one camera installed, the user may specify * the default camera in the Flash Player Camera Settings panel.) If no cameras are available * or installed, the method returns null. * @langversion 3.0 * @playerversion Flash 9 */ static getCamera(name?: string, minWidth?: number, minHeight?: number, facingMode?: string): Camera; setCursor(value: boolean): void; /** * @param keyFrameInterval A value that specifies which video frames are transmitted in full * (as keyframes) instead of being interpolated by the video compression algorithm. * A value of 1 means that every frame is a keyframe, a value of 3 means that every third frame * is a keyframe, and so on. Acceptable values are 1 through 48. * @langversion 3.0 * @playerversion Flash 9 */ setKeyFrameInterval(keyFrameInterval: number): void; /** * @param compress Specifies whether to use a compressed video stream (true) * or an uncompressed stream (false) for a local view of what the camera * is receiving. * @langversion 3.0 * @playerversion Flash 9 */ setLoopback(compress?: boolean): void; /** * @param width The requested capture width, in pixels. The default value is 160. * @param height The requested capture height, in pixels. The default value is 120. * @param fps The requested rate at which the camera should capture data, in frames per second. * The default value is 15. * @param favorArea Specifies whether to manipulate the width, height, and frame rate if * the camera does not have a native mode that meets the specified requirements. * The default value is true, which means that maintaining capture size * is favored; using this parameter selects the mode that most closely matches * width and height values, even if doing so adversely affects * performance by reducing the frame rate. To maximize frame rate at the expense * of camera height and width, pass false for the favorArea parameter. * @langversion 3.0 * @playerversion Flash 9 */ setMode(width: number, height: number, fps: number, favorArea?: boolean): void; /** * @param motionLevel Specifies the amount of motion required to dispatch the * activity event. Acceptable values range from 0 to 100. The default value is 50. * @param timeout Specifies how many milliseconds must elapse without activity * before Flash Player considers activity to have stopped and dispatches the activity event. * The default value is 2000 milliseconds (2 seconds). * @langversion 3.0 * @playerversion Flash 9 */ setMotionLevel(motionLevel: number, timeout?: number): void; private onMotionTimeout; private onMotionTimer; private processDiff; /** * @param bandwidth Specifies the maximum amount of bandwidth that the current outgoing video * feed can use, in bytes per second. To specify that Flash Player video can use as much bandwidth * as needed to maintain the value of quality, pass 0 for * bandwidth. The default value is 16384. * @param quality An integer that specifies the required level of picture quality, * as determined by the amount of compression being applied to each video frame. * Acceptable values range from 1 (lowest quality, maximum compression) to 100 (highest * quality, no compression). To specify that picture quality can vary as needed to avoid * exceeding bandwidth, pass 0 for quality. * @langversion 3.0 * @playerversion Flash 9 */ setQuality(bandwidth: number, quality: number): void; }