Home/docs/reference/ErikaHandle
ErikaHandle reference
ErikaHandle Reference
All functions of the pull-model entry point: lifecycle, playback control, tracks and subtitles, state and events, surface attachment, and the general helper functions shared by both entry points. Signatures and comments in erika.h are authoritative.
Lifecycle and errorsライフサイクル#
ErikaHandle *erika_create(void)
Creates a player handle. Cannot fail.
void erika_destroy(ErikaHandle *handle)
Destroys the handle and releases all internal resources.
char *erika_last_error_message(void)
Reads a human-readable message for the most recent error on this thread. The returned string is owned by the caller; release it with erika_string_free. You must read it on the same thread where the error occurred.
void erika_string_free(char *value)
Frees a standalone string returned by liberika.
void erika_subtitle_memory_font_status_free(ErikaSubtitleMemoryFontStatus *status)
Frees the array and string fields inside ErikaSubtitleMemoryFontStatus.
void erika_subtitle_memory_font_info_free(ErikaSubtitleMemoryFontInfo *info)
Frees the array and string fields inside ErikaSubtitleMemoryFontInfo.
Playback control再生制御#
ErikaStatus erika_open(ErikaHandle *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_open_with_headers(ErikaHandle *handle, const char *uri, const ErikaHttpHeader *headers, uintptr_t header_count)
Opens media with custom HTTP request headers.
ErikaStatus erika_open_with_options( ErikaHandle *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_play(ErikaHandle *handle)
Starts playback. play only enqueues the work; the final outcome is reported by a StateChanged or Error event.
ErikaStatus erika_pause(ErikaHandle *handle)
Pauses playback.
ErikaStatus erika_stop(ErikaHandle *handle)
Stops playback.
ErikaStatus erika_close(ErikaHandle *handle)
Closes the media and releases its resources, moving to the Closed state. Destroy the handle afterward; create a new handle for the next playback.
ErikaStatus erika_seek(ErikaHandle *handle, uint64_t position_micros)
Seeks to the given position, in microseconds.
Tracks and subtitlesトラック#
ErikaStatus erika_add_external_subtitle(ErikaHandle *handle, const char *uri, int64_t *out_track_id)
Adds an external subtitle track and outputs the track id.
ErikaStatus erika_remove_subtitle_track(ErikaHandle *handle, int64_t track_id)
Removes a subtitle track.
ErikaStatus erika_select_audio_track(ErikaHandle *handle, int64_t track_id)
Selects an audio track.
ErikaStatus erika_select_subtitle_track(ErikaHandle *handle, int64_t track_id)
Selects a subtitle track. An id of -1 disables subtitles.
ErikaStatus erika_track_selection(ErikaHandle *handle, ErikaTrackSelection *out_selection)
Reads the currently selected video, audio, and subtitle tracks.
ErikaStatus erika_tracks(ErikaHandle *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.
void erika_track_info_free(ErikaTrackInfo *track)
Frees the string fields inside ErikaTrackInfo.
void erika_danmaku_track_info_free(ErikaDanmakuTrackInfo *track)
Frees the string fields inside ErikaDanmakuTrackInfo.
State and events状態とイベント#
ErikaStatus erika_state(ErikaHandle *handle, ErikaState *out_state)
Reads the current playback state.
ErikaStatus erika_poll_event(ErikaHandle *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. After an Error event, you can get details from erika_last_error_message.
Surface attachmentサーフェス#
ErikaStatus erika_attach_metal_layer(ErikaHandle *handle, uint64_t raw_layer, uint32_t width, uint32_t height, double scale)
Attaches a Metal surface. raw_layer is a CAMetalLayer* cast to uint64_t.
ErikaStatus erika_attach_wgpu_surface(ErikaHandle *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_attach_wgpu_surface_with_output_capabilities(ErikaHandle *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_attach_flutter_texture(ErikaHandle *handle, ErikaFlutterTextureKind kind, int64_t texture_id, uint32_t width, uint32_t height, double scale)
Attaches a Flutter texture surface.
ErikaStatus erika_detach_surface(ErikaHandle *handle)
Detaches the current surface.
Standalone GIF export#
ErikaStatus erika_export_gif( const ErikaGifExportOptions *options, ErikaGifExportResult *out_result)
A standalone, synchronous export entry point that needs no player or surface. Times are in milliseconds; UI hosts should run it on a worker thread. On success it fills in the dimensions, frame count, and file size.
C
ErikaGifExportOptions options = {
.input_uri = "/path/input.mp4",
.output_path = "/path/output.gif",
.start_millis = 5000,
.end_millis = 10000,
.frames_per_second = 10,
.output_width = 640,
.output_height = 360,
.quality = ErikaGifExportQuality_High,
.loop_count = 0,
};
ErikaGifExportResult result = {0};
ErikaStatus status = erika_export_gif(&options, &result);
Standalone frame export and logging · 0.3.0#
Frame export is synchronous; UI hosts should run it on a worker thread. The input position_millis is in milliseconds; the result’s timestamp_micros and duration_micros are in microseconds. HDR (PQ / HLG / Dolby Vision) is tone-mapped along the SDR display path, and the result sets ERIKA_FRAME_EXPORT_TONE_MAPPED (1) in reserved_flags.
ErikaStatus erika_export_frame( const ErikaFrameExportOptions *options, ErikaFrameExportResult *out_result)
Standalone, synchronous export of the image at a media timestamp, returned as RGBA or PNG. It preserves the display aspect ratio, scales down to fit within the optional size limits, and never scales up. It has its own demuxer and a multithreaded software decoder, so it needs no player or surface.
void erika_frame_export_result_free(ErikaFrameExportResult *result)
Frees the data in the result and resets the result. Do not substitute erika_string_free or the host’s free.
ErikaStatus erika_frame_export_session_open( const ErikaFrameExportSessionOptions *options, ErikaFrameExportSession **out_session)
Opens a media file once for continuous frame capture and returns a session on success. Zero out reserved and reserved_flags when you initialize the structs.
ErikaStatus erika_frame_export_session_frame( ErikaFrameExportSession *session, const ErikaFrameExportRequest *request, ErikaFrameExportResult *out_result)
Exports the image at the given time from the session. For increasing requests with no intervening keyframe, it keeps decoding; otherwise it seeks again. The result is identical to a single export, and you free each one with result_free.
void erika_frame_export_session_close(ErikaFrameExportSession *session)
Closes and releases the session; accepts NULL. Calls on one session must be serialized: they must not run concurrently with close, and the session must not be used after it is closed.
ErikaStatus erika_log_read_json( uint32_t limit, int32_t min_level, uint64_t since_seq, char **out_json)
Reads the process-wide redacted log ring, which holds at most 2000 entries / 512 KiB. limit=0 reads all retained entries, min_level=-1 applies no level filter, and since_seq takes the previous nextSeq for incremental reads. Callable from any thread with no handle. Free a successful string with erika_string_free; on failure, out_json is NULL.
Standalone frame export decodes only the media image; it does not include the current Presenter’s subtitles or danmaku. Native erika_presenter_capture_frame_rgba includes video and subtitles but not danmaku, while Web capture() includes all three.
Related types
erika.h
typedef enum ErikaFrameExportFormat {
ErikaFrameExportFormat_Rgba = 0, /* rows of width * 4 bytes, alpha 255 */
ErikaFrameExportFormat_Png = 1, /* PNG file bytes, 8-bit RGB */
} ErikaFrameExportFormat;
typedef struct ErikaFrameExportOptions {
const char *input_uri;
const ErikaHttpHeader *headers;
uintptr_t header_count;
uint64_t position_millis;
uint64_t http_read_ahead_bytes;
uint32_t max_width;
uint32_t max_height;
int32_t format;
uint32_t reserved_flags;
uint64_t reserved[4];
} ErikaFrameExportOptions;
typedef struct ErikaFrameExportResult {
uint8_t *data;
uintptr_t data_len;
uint64_t timestamp_micros;
uint64_t duration_micros;
uint32_t width;
uint32_t height;
uint32_t source_width;
uint32_t source_height;
int32_t format;
uint32_t reserved_flags;
uint64_t reserved[2];
} ErikaFrameExportResult;
typedef struct ErikaFrameExportSessionOptions {
const char *input_uri;
const ErikaHttpHeader *headers;
uintptr_t header_count;
uint64_t http_read_ahead_bytes;
uint32_t reserved_flags;
uint64_t reserved[4];
} ErikaFrameExportSessionOptions;
typedef struct ErikaFrameExportRequest {
uint64_t position_millis;
uint32_t max_width;
uint32_t max_height;
int32_t format; /* ErikaFrameExportFormat */
uint32_t reserved_flags;
uint64_t reserved[4];
} ErikaFrameExportRequest;
typedef enum ErikaLogLevel {
ErikaLogLevel_Trace = 0,
ErikaLogLevel_Debug = 1,
ErikaLogLevel_Info = 2,
ErikaLogLevel_Warn = 3,
ErikaLogLevel_Error = 4,
} ErikaLogLevel;Logs redact URL query parameters, credential-type fields, request headers, and the user’s home directory. Hosts that must work with older runtimes should resolve the diagnostics symbols as optional. The JSON bridge provides getLogs, exportFrame, and exportFrames; see Method discovery.