Home/docs/reference/ErikaPresenterHandle
ErikaPresenterHandle reference
ErikaPresenterHandle Reference
All 82 functions of the push-model entry point: lifecycle, playback and runtime parameters, subtitles, danmaku, output diagnostics, surface and presentation, render loop, JSON bridge, and screenshots. Built only for macOS / iOS / tvOS / Windows / Android / OpenHarmony / Linux; on other targets create returns NULL.
Lifecycle and configurationライフサイクル#
ErikaPresenterHandle *erika_presenter_create(void)
Creates a Presenter. A NULL return means creation failed; read the reason with erika_last_error_message.
ErikaPresenterHandle *erika_presenter_create_with_config(ErikaPresenterConfig config)
Creates a Presenter from a configuration. config selects the output mode, EDR headroom, and upscaling mode.
ErikaPresenterHandle *erika_presenter_create_with_output_mode(int32_t output_mode, float edr_headroom)
Creates a Presenter from an output mode and headroom. Equivalent to create_with_config with the corresponding fields set.
ErikaPresenterHandle *erika_presenter_create_with_output_mode_and_alpha(int32_t output_mode, float edr_headroom, int32_t video_alpha_mode)
Extends create_with_output_mode with an ErikaVideoAlphaMode: Opaque (default; the picture is fully opaque) or PackedAlphaRight (side-by-side source: color in the left half, grayscale alpha in the right half; the GPU reconstructs premultiplied alpha and presents at half the encoded width).
void erika_presenter_destroy(ErikaPresenterHandle *handle)
Destroys the Presenter and releases all resources.
Playback and runtime parameters再生#
ErikaStatus erika_presenter_open(ErikaPresenterHandle *handle, const char *uri)
Opens media. uri is a local path or an HTTP(S) URL. The call synchronously probes stream information, parses tracks, and sets the state to Ready. After it returns, call the play function to start asynchronous decoding and presentation.
ErikaStatus erika_presenter_open_with_headers(ErikaPresenterHandle *handle, const char *uri, const ErikaHttpHeader *headers, uintptr_t header_count)
Opens media with custom HTTP request headers.
ErikaStatus erika_presenter_open_with_options( ErikaPresenterHandle *handle, const char *uri, const ErikaOpenOptions *options)
Opens media with ErikaOpenOptions, which can carry HTTP request headers, the read-ahead window, and the back-buffer budget in a single call. The options are borrowed only for the duration of the call; set reserved to zero. start_position_micros is the starting time in microseconds; 0 opens at the beginning. It occupies the first former reserved slot, so zero-initialized older structs still open at the beginning.
ErikaStatus erika_presenter_open_with_options_cancellable(ErikaPresenterHandle *presenter, const char *uri, const ErikaOpenOptions *options, const ErikaColdOpenCancellation *ticket)
Like erika_presenter_open_with_options, with an ErikaColdOpenCancellation. A NULL ticket behaves the same; once another thread calls erika_cold_open_cancellation_cancel, this synchronous open returns an error early from its connection or retry wait. Added in 0.3.8 and experimental: the ticket serves this one open, and the presenter itself still must not be shared across threads.
ErikaStatus erika_presenter_play(ErikaPresenterHandle *handle)
Starts playback. play only enqueues the work; the final outcome is reported by a StateChanged or Error event.
ErikaStatus erika_presenter_pause(ErikaPresenterHandle *handle)
Pauses playback.
ErikaStatus erika_presenter_stop(ErikaPresenterHandle *handle)
Stops playback.
ErikaStatus erika_presenter_close(ErikaPresenterHandle *handle)
Closes the media and releases its resources.
ErikaStatus erika_presenter_seek(ErikaPresenterHandle *handle, uint64_t position_micros)
Seeks to the given position, in microseconds.
ErikaStatus erika_presenter_set_playback_rate(ErikaPresenterHandle *handle, double rate)
Sets the playback rate. 1.0 is normal speed; the value is clamped to 0.25–16×.
ErikaStatus erika_presenter_set_volume(ErikaPresenterHandle *handle, double volume)
Sets the volume, in the range 0.0–1.0.
ErikaStatus erika_presenter_set_muted(ErikaPresenterHandle *handle, bool muted)
Mutes or unmutes without losing volume; changes made while muted apply on unmute.
ErikaStatus erika_presenter_set_upscaler(ErikaPresenterHandle *handle, int32_t mode)
Selects an ErikaLumaUpscalerMode. Unsupported configurations retain native sampling and report Inactive; background compilation reports Building. See the upscaling guide for platform requirements.
ErikaStatus erika_presenter_load_upscaler_model(ErikaPresenterHandle *handle, const char *name, const uint8_t *data, uintptr_t data_len)
Loads an Erika .esr model or an FSRCNNX / Anime4K CNN mpv hook shader from memory. The host supplies the weights; select Custom mode after loading.
ErikaStatus erika_presenter_clear_upscaler_model(ErikaPresenterHandle *handle)
Unloads the current custom model.
ErikaStatus erika_presenter_set_subtitle_scale(ErikaPresenterHandle *handle, double scale)
Sets the subtitle scale factor.
Subtitle fonts and styles字幕#
ErikaStatus erika_presenter_set_subtitle_font(ErikaPresenterHandle *handle, const char *family, const char *file_path)
Sets the fallback subtitle font. NULL or an empty string clears the corresponding half. Container ASS scripts keep their own fonts unless you pass the font-name override bit through set_subtitle_style.
ErikaStatus erika_presenter_register_subtitle_memory_font(ErikaPresenterHandle *handle, const uint8_t *data, uintptr_t data_len, uint64_t *out_font_id)
Registers in-memory font data and outputs a font id. The data is never written to disk. The renderer rebuilds its cache according to the selected-font generation: a font in the selected set takes effect on the active subtitle track immediately after it is replaced, while a font that is registered but not selected does not trigger a renderer rebuild. (Replacing a custom font file path with a same-named file is detected by mtime and size and reloaded immediately.)
ErikaStatus erika_presenter_select_subtitle_memory_fonts(ErikaPresenterHandle *handle, const uint64_t *font_ids, uintptr_t font_count)
Selects an ordered set of fallback fonts.
ErikaStatus erika_presenter_clear_subtitle_memory_fonts(ErikaPresenterHandle *handle)
Clears the in-memory font registry.
ErikaStatus erika_presenter_get_subtitle_memory_font_status(ErikaPresenterHandle *handle, ErikaSubtitleMemoryFontStatus *out_status)
Reads the registry status (count, byte total, selected font ids). Release the result with erika_subtitle_memory_font_status_free.
ErikaStatus erika_presenter_get_subtitle_memory_font_info(ErikaPresenterHandle *handle, uint64_t font_id, ErikaSubtitleMemoryFontInfo *out_info)
Reads the faces and metadata of the given font. Release the result with erika_subtitle_memory_font_info_free.
ErikaStatus erika_presenter_set_subtitle_style(ErikaPresenterHandle *handle, ErikaSubtitleStyle style)
Applies a subtitle style override. The bit flags in style.override_mask control which fields take effect; for each field’s values and clamping range, see the types section of the C ABI overview.
Output and diagnostics出力と診断#
ErikaStatus erika_presenter_set_output_headroom(ErikaPresenterHandle *handle, float headroom, bool known)
Provides the desired headroom and a validity flag, which feed output negotiation.
ErikaStatus erika_presenter_get_upscaler_status(ErikaPresenterHandle *handle, ErikaUpscalerStatus *out_status)
Reads the upscaler status: requested mode, active backend, fallback count, and frame counts.
ErikaStatus erika_presenter_get_output_status(ErikaPresenterHandle *handle, ErikaOutputStatus *out_status)
Reads the output status: active encoding, surface format, headroom, and fallback reason.
ErikaStatus erika_presenter_get_resource_status(ErikaPresenterHandle *handle, ErikaPresenterResourceStatus *out_status)
Reads a renderer memory snapshot. Device-level counters are process-wide and may include allocations made by other Presenters.
Tracksトラック#
ErikaStatus erika_presenter_add_external_subtitle(ErikaPresenterHandle *handle, const char *uri, int64_t *out_track_id)
Adds an external subtitle track and outputs the track id.
ErikaStatus erika_presenter_remove_subtitle_track(ErikaPresenterHandle *handle, int64_t track_id)
Removes a subtitle track.
ErikaStatus erika_presenter_select_audio_track(ErikaPresenterHandle *handle, int64_t track_id)
Selects an audio track.
ErikaStatus erika_presenter_select_subtitle_track(ErikaPresenterHandle *handle, int64_t track_id)
Selects a subtitle track. An id of -1 disables subtitles.
ErikaStatus erika_presenter_track_selection(ErikaPresenterHandle *handle, ErikaTrackSelection *out_selection)
Reads the currently selected video, audio, and subtitle tracks.
ErikaStatus erika_presenter_tracks(ErikaPresenterHandle *handle, ErikaTrackInfo *out_tracks, uintptr_t capacity, uintptr_t *out_len)
Reads the track list using the counted-array idiom. Release each populated record with erika_track_info_free.
Danmaku弾幕#
load_* functions replace all danmaku with a single anonymous track; add_*_track functions build a list of named tracks. Input is Bilibili XML (a file path or URL) or JSON (an inline string). offset_micros shifts the timeline of a single track; the global offset applies to all tracks.
ErikaStatus erika_presenter_load_danmaku_file(ErikaPresenterHandle *handle, const char *uri)
Loads Bilibili XML danmaku from a file or URL, replacing all danmaku with a single anonymous track.
ErikaStatus erika_presenter_load_danmaku_json(ErikaPresenterHandle *handle, const char *json)
Loads danmaku from inline JSON, replacing all danmaku with a single anonymous track. For the data format and field specification, see the Danmaku JSON contract.
ErikaStatus erika_presenter_add_danmaku_track_file(ErikaPresenterHandle *handle, const char *uri, const char *name, int64_t offset_micros, uint64_t *out_track_id)
Adds a named danmaku track (XML file) with an optional timeline offset, and outputs the track id.
ErikaStatus erika_presenter_add_danmaku_track_json(ErikaPresenterHandle *handle, const char *json, const char *name, int64_t offset_micros, uint64_t *out_track_id)
Adds a named danmaku track (inline JSON) with an optional timeline offset, and outputs the track id. For the data format and field specification, see the Danmaku JSON contract.
ErikaStatus erika_presenter_remove_danmaku_track(ErikaPresenterHandle *handle, uint64_t track_id)
Removes a danmaku track.
ErikaStatus erika_presenter_set_danmaku_track_enabled(ErikaPresenterHandle *handle, uint64_t track_id, bool enabled)
Enables or disables a single danmaku track.
ErikaStatus erika_presenter_set_danmaku_track_offset(ErikaPresenterHandle *handle, uint64_t track_id, int64_t offset_micros)
Sets the timeline offset of a single danmaku track.
ErikaStatus erika_presenter_set_danmaku_global_offset(ErikaPresenterHandle *handle, int64_t offset_micros)
Sets the global danmaku timeline offset.
ErikaStatus erika_presenter_danmaku_tracks(ErikaPresenterHandle *handle, ErikaDanmakuTrackInfo *out_tracks, uintptr_t capacity, uintptr_t *out_len)
Reads the danmaku track list using the counted-array idiom. Release each populated record with erika_danmaku_track_info_free.
ErikaStatus erika_presenter_clear_danmaku(ErikaPresenterHandle *handle)
Clears all danmaku tracks.
ErikaStatus erika_presenter_set_danmaku_enabled(ErikaPresenterHandle *handle, bool enabled)
Enables or disables danmaku display globally.
ErikaStatus erika_presenter_set_danmaku_config(ErikaPresenterHandle *handle, ErikaDanmakuConfig config)
Applies the danmaku layout and display configuration.
ErikaStatus erika_presenter_set_danmaku_config_ptr(ErikaPresenterHandle *handle, const ErikaDanmakuConfig *config)
Applies a danmaku configuration passed by pointer. Equivalent to the by-value version.
ErikaStatus erika_presenter_get_danmaku_config(ErikaPresenterHandle *handle, ErikaDanmakuConfig *out_config)
Reads the danmaku configuration currently in effect.
ErikaStatus erika_presenter_set_danmaku_font(ErikaPresenterHandle *handle, const char *family, const char *file_path)
Sets the danmaku font family and font file.
ErikaStatus erika_presenter_set_danmaku_block_words_json(ErikaPresenterHandle *handle, const char *json)
Sets the danmaku block-word list, as a JSON array.
ErikaStatus erika_presenter_set_debug_hud_enabled(ErikaPresenterHandle *handle, bool enabled)
Enables or disables the debug HUD overlay.
Surface and presentationサーフェス#
The rendering backend (native Metal, native D3D11, or wgpu) is determined by the Presenter configuration, not by the attach call. Call resize_surface after any change to the drawable size or scale.
ErikaStatus erika_presenter_attach_metal_layer(ErikaPresenterHandle *handle, uint64_t raw_layer, uint32_t width, uint32_t height, double scale)
Attaches a Metal surface (macOS / iOS). raw_layer is a CAMetalLayer* cast to uint64_t.
ErikaStatus erika_presenter_attach_wgpu_surface(ErikaPresenterHandle *handle, ErikaWgpuSurfaceKind kind, uint64_t raw_window, uint64_t raw_display, uint32_t width, uint32_t height, double scale)
Attaches a wgpu surface. raw_window and raw_display are the platform handles for the given kind.
ErikaStatus erika_presenter_attach_wgpu_surface_with_output_capabilities(ErikaPresenterHandle *handle, ErikaWgpuSurfaceKind kind, uint64_t raw_window, uint64_t raw_display, uint32_t width, uint32_t height, double scale, ErikaSurfaceOutputCapabilities output_capabilities)
Attaches a wgpu surface together with an output capabilities declaration, for HDR negotiation.
ErikaStatus erika_presenter_attach_windows_hwnd(ErikaPresenterHandle *handle, uint64_t hwnd, uint64_t hinstance, uint32_t width, uint32_t height, double scale)
Attaches a Windows surface. A wrapper over the WindowsHwnd variant of attach_wgpu_surface: hwnd is an HWND and hinstance is an HINSTANCE.
ErikaStatus erika_presenter_attach_flutter_texture(ErikaPresenterHandle *handle, ErikaFlutterTextureKind kind, int64_t texture_id, uint32_t width, uint32_t height, double scale)
Binds a Flutter texture surface identified by the texture registrar’s texture_id (currently Apple’s MacOsTextureRegistrar / IosTextureRegistrar). The host always retains ownership of the pixel buffer.
ErikaStatus erika_presenter_set_flutter_texture_buffer(ErikaPresenterHandle *handle, uint64_t raw_texture, uint32_t width, uint32_t height)
Selects the host GPU texture to render the next frame into, before each render_tick. On Apple platforms, raw_texture is an id<MTLTexture> cast to uint64_t; it must be BGRA8Unorm and match the declared size. The texture is borrowed only for that frame, and the host may reuse or release it after render_tick returns.
ErikaStatus erika_presenter_windows_composition_swapchain_iunknown(ErikaPresenterHandle *handle, void **out_swapchain)
Windows only. When attached with the direct_composition capability and playing with a transparent alpha mode or overlay blending, returns the premultiplied-alpha DirectComposition swap chain that liberika created. The returned IUnknown has been AddRef’d; the caller owns that COM reference and must Release it. Fetch it again after the decoder or output device recreates the swap chain (an unchanged pointer means it was not recreated).
ErikaStatus erika_presenter_resize_surface(ErikaPresenterHandle *handle, uint32_t width, uint32_t height, double scale)
Resizes the surface or changes its scale. Call it after any change to the drawable size.
ErikaStatus erika_presenter_detach_surface(ErikaPresenterHandle *handle)
Detaches the current surface.
Render loop and eventsレンダーループ#
ErikaStatus erika_presenter_render_tick(ErikaPresenterHandle *handle, double time_seconds, ErikaPresenterStats *out_stats)
Call once per display frame. time_seconds is the host display clock time (the presentation timestamp), used for vsync-quantized scheduling. out_stats may be NULL.
ErikaStatus erika_presenter_audio_only_tick(ErikaPresenterHandle *handle, ErikaPresenterStats *out_stats)
Audio-only tick. Suspends video decoding, for background audio playback.
ErikaStatus erika_presenter_get_stats(ErikaPresenterHandle *handle, ErikaPresenterStats *out_stats)
Reads the cumulative statistics, identical to those from render_tick. You can query them at any time.
ErikaStatus erika_presenter_poll_event(ErikaPresenterHandle *handle, ErikaEvent *out_event)
Polls the event queue without blocking. Returns NoEvent when the queue is empty. For the event kinds and the payload fields of each ErikaEvent, see the event table in the C ABI overview.
JSON bridgeJSON ブリッジ#
For hosts that already serialize structured parameters over a platform channel. For the method table, see the JSON bridge.
char *erika_presenter_invoke_json(ErikaPresenterHandle *handle, const char *method, const char *arguments_json)
Calls a named method. The returned JSON string is owned by the caller; release it with erika_string_free.
char *erika_presenter_render_tick_json(ErikaPresenterHandle *handle, double time_seconds)
JSON variant of render_tick; returns the statistics as JSON.
char *erika_presenter_poll_event_json(ErikaPresenterHandle *handle)
JSON variant of poll_event. Returns NULL when idle.
Screenshotsスクリーンショット#
ErikaStatus erika_presenter_capture_frame_rgba(ErikaPresenterHandle *handle, uint32_t width, uint32_t height, uint8_t *out_rgba, uintptr_t out_capacity)
Renders the current composited frame (video and subtitles, without danmaku or the debug HUD) offscreen into a caller-allocated RGBA8 buffer. out_capacity must be at least width × height × 4. Fails if no frame is available.
Display target time#
ErikaStatus erika_presenter_render_tick_with_timing( ErikaPresenterHandle *handle, double time_seconds, const double *presentation_delay_seconds, ErikaPresenterStats *out_stats)
presentation_delay_seconds is the number of seconds from the call to the display target time. It can be negative, within ±0.25 seconds. Pass NULL to keep the sampling behavior of render_tick. Subtitles, danmaku, and video use the same target-time snapshot, and the playback clock is unchanged.
Flutter frame handoff#
ErikaStatus erika_presenter_windows_flutter_texture_iunknown( ErikaPresenterHandle *handle, void **out_texture)
On Windows, returns a completed, immutable SDR Flutter GPU texture. The returned COM reference has been AddRef’d; the caller must Release it after use.
ErikaStatus erika_presenter_copy_flutter_frame_rgba( ErikaPresenterHandle *handle, uint8_t *out_rgba, uintptr_t capacity, uint32_t *out_width, uint32_t *out_height)
Copies the current Flutter texture frame as tightly packed RGBA data; used for Linux pixel-buffer textures. Capacity and dimensions are handled as output parameters, and the caller supplies the buffer.
Diagnostics snapshot#
ErikaStatus erika_presenter_get_diagnostics_json(ErikaPresenterHandle *handle, char **out_json)
Reads, in one call, the decoder and the hardware decoding path actually in use, presentation counters and timings, output/HDR state, audio, buffer depth, and scheduling timing. It only reads counters: it does not decode, render, or wait on the playback thread. Unknown values are null. The rule that a single handle must not be called concurrently still applies.
On success, returns a caller-owned JSON string that carries a schema; release it with erika_string_free. Returns NULL on failure. For compatibility with older native libraries, resolve the symbol as optional; a missing symbol means the feature is unsupported. The corresponding JSON bridge method is getDiagnosticsSnapshot.
Playback and native texture APIs#
ErikaStatus erika_presenter_set_open_start_position(ErikaPresenterHandle *handle, uint64_t position_micros)
Sets the start for the next open whose options do not specify a nonzero position; in microseconds. 0 clears it, and the next open consumes it.
ErikaStatus erika_presenter_set_subtitle_delay(ErikaPresenterHandle *handle, int64_t delay_micros)
Positive values show subtitles later, negative earlier; applies to embedded and external tracks, clamped to ±10 minutes. 0 restores the original timestamps.
ErikaStatus erika_presenter_set_danmaku_random_colors(ErikaPresenterHandle *handle, bool enabled)
Enables or disables random danmaku colors.
ErikaStatus erika_presenter_capture_frame_rgba_with_danmaku(ErikaPresenterHandle *handle, uint32_t width, uint32_t height, uint8_t *out_rgba, uintptr_t out_capacity)
Outputs SDR RGBA8 with video, subtitles and enabled danmaku, without the debug HUD. No surface or prior render tick is required; the caller buffer must hold at least width × height × 4 bytes.
ErikaPresenterHandle *erika_presenter_create_for_texture_export(ErikaPresenterConfig config)
Selects WgpuFallback for native texture export; returns NULL and sets last_error on failure.
ErikaStatus erika_presenter_export_frame_texture(ErikaPresenterHandle *handle, uint32_t width, uint32_t height, double content_scale, ErikaTextureFrame **out_frame)
Exports an immutable SDR native texture from WgpuFallback, with video, subtitles and enabled danmaku but no HUD. Supports Linux Vulkan OPAQUE_FD and Apple Metal, without a surface, Flutter registrar, CPU readback or GPU texture copy. It waits for producer GPU completion and pumps audio. NoEvent means no video yet; out_frame is NULL on any non-Ok result.
ErikaStatus erika_texture_frame_get_info(const ErikaTextureFrame *frame, ErikaExternalTextureInfo *out_info)
A texture frame can outlive its presenter. Release only after consumer GPU work and imported aliases retire. get_info returns borrowed handles: a Metal consumer may independently retain the texture through all GPU use; duplicate the Vulkan OPAQUE_FD before import (0 is valid), match device and driver UUIDs, and import the dedicated allocation with identical properties. Acquire queue ownership from EXTERNAL with old layout GENERAL before reading. Read-only pixels are sRGB-encoded RGBA in UNORM storage.
void erika_texture_frame_release(ErikaTextureFrame *frame)
Release after consumer GPU work and aliases have retired.