haishin_kit library
Capture, mix, preview, publish, and play audio and video on native platforms.
Use MediaMixer to attach input sources and compose overlays through its Screen, StreamSession for network sessions, and StreamSessionView for native video previews and playback.
Platform integration
Use Flutter 3.44+, Dart 3.12+, and Xcode 26+ for Apple builds. The native Apple bridge uses HaishinKit.swift 2.3.2 through Swift Package Manager, targeting iOS 15 and macOS 12. CocoaPods installation of this plugin is not supported. Enable Swift Package Manager before resolving the consuming app:
flutter config --enable-swift-package-manager
flutter clean
flutter pub get
Add camera/microphone usage descriptions to the app's iOS/macOS Info.plist:
<key>NSCameraUsageDescription</key>
<string>Use the camera for publishing.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Use the microphone for publishing.</string>
On macOS, enable com.apple.security.device.audio-input and
com.apple.security.device.camera in the app's Debug and Release entitlements.
Android uses HaishinKit.kt 0.21.1 modules from JitPack and OpenGL composition. Use compile SDK 37+. The native bridge declares API 23, while Flutter 3.44 requires an Android app minimum of API 24. With the repository's current Kotlin plugin configuration, set these Android Gradle properties:
android.builtInKotlin=false
android.newDsl=false
Request camera and microphone permissions before capture. Android WHIP audio publishing needs an Opus encoder (available on Android 10+) and 48 kHz PCM. Plain HTTP requires the consuming app to allow cleartext traffic in its Android network-security configuration.
Native platform feature comparison
Verified against HaishinKit.swift 2.3.2 and HaishinKit.kt 0.21.1 on
2026-11-28. These are native library capabilities, not a promise that every
feature is exposed by Flutter or supported by every device/server.
The Flutter column below describes haishin_kit: 0.20.0, including its native
dependency migration and new codec, HDR, asset and scene APIs.
Native video and transport support
| Capability | Swift 2.3.2 | Kotlin 0.21.1 |
|---|---|---|
| RTMP/RTMPS camera encoding | H.264, HEVC | H.264, HEVC, AV1, VP8, VP9 |
| RTMP/RTMPS video reception | H.264, HEVC; AV1 with a VideoToolbox hardware decoder | H.264, HEVC, AV1, VP8, VP9 with suitable OS decoders |
| SRT MPEG-TS video, send/receive | H.264, HEVC | H.264, HEVC |
| SRT MPEG-TS audio | AAC | AAC |
| WHIP/WHEP video | H.264 | H.264, VP8, VP9 (profile 0) |
| WHIP/WHEP audio | Opus | Opus |
| HLG composition | 10-bit HLG with HEVC Main10 encoding | 10-bit HLG with HEVC Main10 or AV1 Main10 encoding |
| Rendering | Core Image / Metal | OpenGL; optional Vulkan for SDR |
| Portable scenes | Native SceneFile ZIP with embedded media | Same portable SceneFile format |
| Local video assets | AssetScreenObject; video track only | AssetScreenObject; video track only |
Codec support has three separate requirements: the transport must carry it, the OS must provide a compatible encoder/decoder, and the peer must accept the stream. Profile, size, frame rate and concurrent codec use also matter. An OS capability listing is not a successful encode/decode test. The SRT rows describe these SDKs' MPEG-TS implementation, rather than every codec that the MPEG-TS container can represent.
Swift's default streaming encoder uses VideoToolbox H.264/HEVC. Its optional AOMHaishinKit and VPXHaishinKit products provide separate codec APIs; their existence does not add AV1/VP8/VP9 camera publishing to the RTMP or RTC tables above. AV1 RTMP reception has no software fallback, and its HDR metadata path is outside the current Swift implementation. On unsupported hardware, native Swift keeps supported audio playing and ignores AV1 video.
Flutter exposure and migration status
The following APIs are included in 0.20.0. PR references link the implementation details. Use matching package and native release versions.
| Flutter capability | iOS / macOS | Android | Availability |
|---|---|---|---|
| RTMP/RTMPS, SRT, WHIP publishing and WHEP playback | Native session bridge | Native session bridge | Included in 0.20.0 |
| RTMP playback codec detection | Native H.264/HEVC/AV1 receive behavior | Native H.264/HEVC/AV1/VP8/VP9 receive behavior | Native dependency migration; no publishing codec selection required |
| OS encoder discovery and codec selection | H.264/HEVC; WHIP H.264 | RTMP five codecs; SRT H.264/HEVC; WHIP H.264/VP8/VP9 | PR #204 |
| HLG capture and native HDR preview | iOS 16+; macOS remains SDR | Android 13+ | RTMP only; PR #204 |
| Scene export/import and local video assets | iOS/macOS | Android | PR #206 |
| Explicit audio codec selection / complete audio capability report | Not exposed | Not exposed | Protocol defaults: AAC for RTMP/SRT, Opus for WHIP |
| Native recording and video-effect controls | Not exposed | Not exposed | Native SDK APIs are broader than the Flutter bridge |
| Vulkan backend selection | Not applicable | Not exposed; Flutter previews use OpenGL | Native module selection does not change Flutter's preview API |
HLG additionally needs a compatible camera, Main10 encoder, display, and server/player. HDR previews require the new native-surface widget; the legacy Flutter texture is SDR-only. The portable scene bridge packages local media, not capture permissions/devices, session settings or connection credentials. Its archive/resource limit is 32 MiB. Unsupported scene objects remain invisible and retain their serialized content for re-export.
Native Swift also targets tvOS, visionOS and Mac Catalyst; this Flutter package declares only iOS and macOS on Apple platforms. Do not infer Flutter support from native package targets. AssetScreenObject is unavailable on native visionOS, and its example uses a generated test signal for publishing.
Sources for this comparison: Swift encoder settings, Swift AV1 reception, Swift RTC formats, Kotlin RTMP muxer, Kotlin SRT stream, Kotlin RTC formats. Refresh both the native release tags and Flutter exposure table when upgrading dependencies; a platform codec's presence alone is insufficient.
Publishing and session lifecycle
The transport comes from the URL. Include the RTMP stream name in the full RTMP/RTMPS URL; pass complete SRT URLs with their query options. WHIP publishes and WHEP plays back using their respective complete HTTP(S) endpoints.
final mixer = await MediaMixer.create();
await mixer.attachAudio(0, AudioSource(sampleRate: 48000));
final cameras = await HaishinKitPlatformInterface.instance.videoSources;
if (cameras.isEmpty) throw StateError('No camera is available.');
await mixer.attachVideo(0, cameras.first);
final session = await StreamSession.create(
'https://example.com/whip',
StreamSessionMode.publish,
);
await mixer.startRunning();
await session.connect();
// When finished, including after failure or cancellation:
await session.close();
await session.dispose();
await mixer.dispose();
Observe StreamSession.readyState and handle StreamSessionException from connection attempts. The 48 kHz capture option in this example applies to Android; native capture behavior on Apple platforms is managed by the bridge. Android WHIP uses Opus and H.264 Baseline level 3.1, so keep custom video settings within those capabilities.
Playback
final session = await StreamSession.create(
'https://example.com/whep',
StreamSessionMode.playback,
);
Put StreamSessionView in the widget tree before calling StreamSession.connect. Close and dispose the session when playback finishes. SRT and HTTP(S) endpoints preserve paths/query parameters and do not use a separate RTMP stream-name field. The Dart API currently uses native default ICE/authentication settings, without parameters for bearer tokens or STUN/TURN.
Video assets and portable scenes
AssetScreenObject renders a local video's picture without mixing its audio. Supply a file URI or copy bundled/downloaded bytes into screen-owned storage:
final source = await mixer.screen!.cacheAsset(videoBytes, extension: 'mp4');
final clip = AssetScreenObject()
..source = source
..isLooping = true
..size = const ScreenObjectSize(width: 320, height: 240);
mixer.screen!.addChild(clip);
await mixer.screen!.exportScene() captures the actual native composition,
including the default camera node, as a .scene ZIP with local media.
Persist the returned bytes using your app's file-storage UI. Restore with
await mixer.screen!.importScene(bytes) while disconnected. Capture must be
running for Android's frame-coherent export. Await scene operations before
editing or disposing. Scene archives and packaged resources are limited to
32 MiB by the Flutter bridge. The native reader validates the shared archive
format. Scene files do not attach capture devices or restore session settings.
Imported children are RestoredScreenObject nodes with stable IDs, editable layout and retained type/element properties. Unsupported objects/resources survive subsequent exports without rendering. Screen-owned media URIs expire on disposal; export a scene before disposing to persist media elsewhere.
Video codecs and HLG HDR
Query HaishinKitPlatformInterface.instance.supportedVideoCodecs() for OS
encoders. Server/protocol support is a separate requirement: Android RTMP
publishing supports H.264, HEVC, AV1, VP8 and VP9; Apple RTMP publishing
supports H.264 and HEVC.
SRT publishes H.264 and HEVC on both platforms. Android WHIP
supports H.264/VP8/VP9; Apple WHIP uses H.264. No codecs are added by this API.
Use await session.setVideoCodec(codec) before connecting to preserve native
bitrate and dimensions. setVideoSettings explicitly applies all fields.
HLG capture and display require iOS 16+ or Android 13+, compatible camera, encoder and display hardware, and an Enhanced RTMP server. Select the same immutable range when creating the mixer and session:
final mixer = await MediaMixer.create(options: const MediaMixerOptions(
dynamicRangeMode: DynamicRangeMode.hlg,
));
final session = await StreamSession.create(
'rtmp://example.com/live/camera', StreamSessionMode.publish,
dynamicRangeMode: DynamicRangeMode.hlg,
);
await session.setVideoCodec(VideoCodec.hevc);
Attach capture sources and start the mixer as usual. Use StreamSessionView for the HDR preview; the legacy texture widget is SDR-only. HLG publishing uses HEVC Main10 on iOS and HEVC Main10 or AV1 Main10 on supported Android devices. HDR mode is RTMP-only in this plugin; macOS remains SDR. For playback, select the range when creating the session and use StreamSessionView. Apple HLG playback supports HEVC; AV1 HDR metadata is outside the native Apple SDK.
Developing the plugin
Regenerate data classes after editing their source definitions:
dart run build_runner build --delete-conflicting-outputs
Classes
- AssetScreenObject
- A local video file rendered by the OS decoder, without its audio track.
- AudioCodecSettings
- Settings for the session's audio encoder.
- AudioMixerSettings
- Settings for mixing captured audio.
- AudioSource
- Selects the default audio input for capture.
- HaishinKitPlatformInterface
- The contract that native implementations of HaishinKit must implement.
- ImageScreenObject
- Displays an image overlay on the composition screen.
- MediaMixer
- Captures and mixes audio and video for native streaming sessions.
- MediaMixerOptions
- Configures native dynamic range and Apple capture/audio mixing behavior.
- RestoredScreenObject
- A restored scene node retaining its native type and element properties.
- Screen
- The root of a mixer's native video composition.
- ScreenCoordinateTransform
- Maps composition pixels to preview-local coordinates and back.
- ScreenObject
- The ScreenObject class is the abstract base class for all objects that are rendered on the screen.
- ScreenObjectContainer
- The ScreenObjectContainer represents a collection of screen objects.
- ScreenObjectEdgeInsets
- Represents edge insets used for layout spacing around a ScreenObject.
- ScreenObjectEditor
- Edits direct children using layout measured by the native renderer.
- ScreenObjectSize
- The requested width and height of a screen object.
- StreamSession
- A native streaming session for publishing or playback.
- StreamSessionView
- Displays a session with a texture for SDR or a native HDR surface for HLG.
- StreamSessionViewTexture
- Displays an SDR video texture from a StreamSession.
- TextScreenObject
- Displays a text overlay on the composition screen.
- VideoCodecSettings
- Settings for the session's video encoder.
- VideoMixerSettings
- Constraints on the video mixer settings.
- VideoScreenObject
- Displays a video track on the composition screen.
- VideoSource
- Represents a video input source.
Enums
- CameraPosition
- Represents the position of the camera.
- CaptureSessionMode
- Determines how the native mixer manages capture on Apple platforms.
- DynamicRangeMode
- The capture, composition, and display range selected before creating a session.
- HorizontalAlignment
- Defines horizontal alignment options.
- ImageScreenObjectFormat
- Supported image formats for ImageScreenObject.
- ProfileLevel
- The H.264 profile and level requested for video encoding.
- StreamSessionMode
- Determines the direction of media transfer.
- StreamSessionReadyState
- Represents the current connection state of a session.
- VerticalAlignment
- Defines vertical alignment options.
- VideoCodec
- The video codec requested from the native OS encoder.
- VideoGravity
- Specifies how a video should be resized or scaled to fit within its container.
- VideoRenderingMode
- The type of image rendering mode.
Extensions
- AudioMixerSettingsPatterns on AudioMixerSettings
- Adds pattern-matching-related methods to AudioMixerSettings.
- MediaMixerOptionsPatterns on MediaMixerOptions
- Adds pattern-matching-related methods to MediaMixerOptions.
- ScreenObjectEdgeInsetsPatterns on ScreenObjectEdgeInsets
- Adds pattern-matching-related methods to ScreenObjectEdgeInsets.
- ScreenObjectSizePatterns on ScreenObjectSize
- Adds pattern-matching-related methods to ScreenObjectSize.
- VideoMixerSettingsPatterns on VideoMixerSettings
- Adds pattern-matching-related methods to VideoMixerSettings.
- VideoSourcePatterns on VideoSource
- Adds pattern-matching-related methods to VideoSource.
Exceptions / Errors
- MediaMixerException
- MediaMixerFailedToAttachException
- MediaMixerUnknownException
- StreamSessionConnectFailedException
- Thrown when establishing a session connection fails.
- StreamSessionException
- Base exception type for all session-related errors.
- StreamSessionUnknownException
- Thrown when an unexpected error occurs while handling a session.