← All extensions

Native extension · Flagship

KlugMedia

com.klug.media

Camera, two-way voice and hardware echo cancellation in one native session, publishing and receiving H.264 and Opus over standard RTMP.

iOSAndroidmacOS In production

Overview

AIR does not currently provide an up-to-date implementation for real-time media streaming. KlugMedia adds it as a native extension. Camera, microphone, encoder and echo cancellation run together in one native session, and ActionScript only sends commands and receives status.

Video is published and received as H.264, voice as Opus, both over standard RTMP. Received video is drawn natively on top of the AIR stage, so it stays sharp and smooth even on older devices.

KlugMedia is in daily use in the PetCam App, our proof of concept, on the App Store, Google Play and the Mac.

Features

  • Camera capture and H.264 publishing in one native session
  • Native H.264 receive and display, aspect-correct, with crop-to-fill and rotation
  • Two-way Opus voice with hardware echo cancellation, both sides talking at once
  • Native camera preview, camera switch, torch and zoom
  • Snapshots taken straight from the camera image
  • MP4 recording of live streams on the Klug streaming server, picture and sound
  • Automatic bitrate adaptation on weak networks
  • Standard RTMP, so it works with ordinary media servers

Streaming server

KlugMedia comes with matching server software, developed together with the extension and tuned for AIR apps: stream handling, reliable reconnects, the two-way voice relay, MP4 recording and live viewing in a web browser.

The server is described on the overview page: Streaming server.

Supported platforms

iOS arm64
Android arm64 · armv7
macOS Apple silicon · Intel
iPad apps on the Mac Apple silicon · in development

Coming soon: iPad apps on the Mac

On Macs with Apple silicon, the iOS build of an AIR app can run as an iPad app. KlugMedia supports this mode with camera, live video and two-way voice, including external USB cameras. One build then serves iPhone, iPad and Mac. This is in development and will be available soon.

Getting started

Add the extension to your application descriptor:

app.xml
<extensions>
    <extensionID>com.klug.media</extensionID>
</extensions>

Request camera and microphone permission before the first start. The extension then owns the capture: do not open an AIR Camera or Microphone at the same time.

Quick example

Publish
Station.as
import com.klug.petcam.camera.CameraStreamANE;

var media:CameraStreamANE = CameraStreamANE.instance;
if ( media.isSupported )
{
    // camera, H.264 and RTMP in one native session
    media.startPublish( "rtmp://your.server/live", "station-1",
                        640, 480, 12, 800 );
}
Receive
Viewer.as
// play the stream natively inside a rectangle of the stage
media.startReceive( "rtmp://your.server/live", "station-1",
                    0, 0, 640, 480, 0, CameraStreamANE.RECEIVE_FIT );
Two-way voice
Voice.as
var voice:OpusVoiceBridge = new OpusVoiceBridge(
        new NativeOpusCodec(), 48000, 1, 960 );
voice.setVoiceProcessing( true );   // hardware echo cancellation
voice.start();

API overview

isSupportedTrue where the native media session is available.
startPublish(…)Starts the camera and publishes video and voice over RTMP.
stopPublish()Stops publishing and releases the camera.
startReceive(…)Plays a remote stream natively inside a rectangle of the stage.
stopReceive()Stops playback and removes the native view.
showPreview(…) / hidePreview()Native camera preview over the stage.
switchCamera()Switches between front and back camera while streaming.
setTorch(on)Turns the camera light on or off while streaming.
captureSnapshot(w, h)Saves a JPEG from the live camera image.
OpusVoiceBridgeTwo-way voice: start, stop, echo cancellation on or off.

Requirements

AIR SDK51.x (HARMAN)
iOSiOS 17 or later
AndroidAndroid 6.0 (API 23) or later
macOSmacOS 11 or later
PermissionsCamera and microphone
ServerAny RTMP server; the matching Klug streaming server is recommended