I want to share with you some hidden gems available in Flash Player 11.2 and AIR 3.2, that we just released for beta this week. Those were not mentioned in the release notes, cause they will not be part of 11.2 and AIR 3.2, but will be part of a next release. But that's cool, quickly grab the beta builds, that way you can start playing with those APIs, just use -swf-version=15 to unlock them ;)

You won't find any docs on those, so here we go, let's start with the new API that we added on StageVideo : StageVideo.attachCamera(), it says it all. You can now attach your camera to a StageVideo object, to use very little CPU when displaying the camera stream:

public class StageVideo extends EventDispatcher
{
     public native function attachCamera(theCamera:Camera):void;
}

For the image processing lovers, we added Camera.drawToBitmapData, Camera.copyToByteArray, Camera.copyToVector. No need to manually BitmapData.draw a video object to get the camera pixels, and same for the pixels as a ByteArray or Vector. Notice that those should have very low impact on the GC. Rather than creating new buffers for each call, you get to provide the buffer to fill, and just call the API :

public final class Camera extends EventDispatcher
{
     public native function drawToBitmapData( destination:BitmapData ):void;
     public native function copyToByteArray( rect:Rectangle, destination:ByteArray ):void;
     public native function copyToVector( rect:Rectangle, destination:Vector. ):void
}

We also added an event, informing you about the availability of a new video frame, this way you can execute your image processing logic in this event rather than Event.ENTER_FRAME, way more efficient:

public class Event
{
     public static const VIDEO_FRAME:String = "videoFrame";
}

For those who recall this conversation on Twitter, some of these additions were added after a conversation with Mario and Eugene, hope you like these guys! :)

Inspirit - getFrameBytes