Session class abstract
Base class for all FFmpegKit sessions.
Provides common access to session state, return code, output, logs, statistics, timing, and debug utilities. All concrete session types (FFmpegSession, FFprobeSession, FFplaySession, MediaInformationSession) extend this class.
Native handle lifetime
Each session owns an opaque native C++ object exposed as a
SessionHandle (handle). A platform-specific finalizer is attached at
construction time, when supported, to release abandoned session resources.
Testing without a native library
Use the protected Session.noFinalizer constructor in test subclasses
or mock factories. This sets an instance-level flag that suppresses
finalizer registration for that specific instance. Unlike the previous
static bool skipFinalizer approach, this flag cannot leak between
tests or affect unrelated sessions.
- Implementers
Constructors
- Session({SessionFinalizer? finalizer})
- Standard constructor — registerFinalizer will attach the native finalizer after handle is assigned.
- Session.noFinalizer({SessionFinalizer? finalizer})
- Constructor for use in test subclasses where no native library is loaded.
Properties
- command ↔ String
-
The command string that was (or will be) executed.
getter/setter pair
- handle ↔ SessionHandle
-
The platform-neutral opaque handle for this session.
getter/setter pair
- hasExecutionSettled → bool
-
Whether the queue-owned execution has reached its terminal handoff.
no setter
- hasExecutionStarted → bool
-
Whether the queue has handed this session to its executor.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasPendingExecutionRouting → bool
-
Whether a submitted execution still owns callback routing.
no setter
- hasTerminalCompletionBeenObserved → bool
-
Whether terminal observation has already ended restored observer demand.
no setter
- isCancelled → bool
-
Whether cancel has been called on this session.
no setter
- isDisposed → bool
-
Whether this session has released its native handle.
no setter
- isRestoredObserverRunning → bool
-
Reads the restored session state for observer-only bridge demand.
no setter
- isRestoredSession → bool
-
Whether this object was restored around an already-owned native handle.
no setter
- logsProcessed ↔ int
-
Index of the next log entry not yet dispatched to Dart callbacks.
getter/setter pair
- nextExpectedLogSequence ↔ int
-
Sequence of the next native log event that has not been delivered.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sessionId ↔ int
-
The C-layer session identifier. Stable for the session's entire lifetime.
getter/setter pair
Methods
-
acquireBridgeLease(
CallbackBridgeKind kind, {required void install(), required void uninstall()}) → void - Acquires a process-global callback bridge on behalf of this session.
-
adoptOwnedHandle(
SessionHandle ownedHandle, {required int readSessionId(SessionHandle), void onBeforeCommit()?, bool restoredSession = false}) → void - Adopts an already-owned handle or releases it if wrapper initialization cannot commit.
-
beginCompletionDispatch(
) → void - Enters the lifetime scope shared by local and global completion observers. Physical disposal is deferred while this scope is active.
-
cancel(
) → void - Requests cancellation of this session.
-
claimCompletionDispatch(
) → bool - Claims the single completion-callback dispatch for this session.
-
claimExecutionSubmission(
) → void - Claims this session for exactly one execution submission.
-
clearDebugLog(
) → void - Clears the accumulated debug log in the C layer.
-
clearExecutionErrorHandler(
) → void - Clears the error handler for a settled execution.
-
commitTerminalHistory(
) → void - Commits wrapper history after authoritative native terminal observation.
-
completeExecutionWithError(
{required Completer< void> completer, required Object error, required StackTrace stackTrace, required void cleanup()}) → void - Cleans up an asynchronous execution and preserves its original failure.
-
disableDebugLog(
) → void - Disables per-session debug logging in the C layer.
-
discardBeforeExecution(
) → void - Called by SessionQueueManager when a queued item is discarded.
-
dispatchDirectLogEvent(
{required int sequence, required int level, required String? message}) → void - Dispatches one structured log event in native insertion order.
-
dispatchExecutionError(
Object error, StackTrace stackTrace) → void - Dispatches an asynchronous execution failure to the active execution.
-
dispatchNativeCancellation(
) → void - Performs the platform cancellation dispatch.
-
dispatchPendingLogs(
) → void - Dispatches all buffered log entries that have not yet been delivered.
-
dispose(
) → void - Releases this session's native handle and associated Dart resources.
-
enableDebugLog(
) → void - Enables per-session debug logging in the C layer.
-
endCompletionDispatch(
) → void - Leaves the completion-observer lifetime scope. Disposal remains deferred until execution settlement has also completed.
-
ensureRoutingForSinkDemand(
void register()) → void - Registers a callback sink only when it can own live delivery.
-
executionStateForSubmission(
) → SessionState - Returns the state used by the one-shot submission guard.
-
getCommand(
) → String - Returns the command string as reported by the C layer.
-
getCreateTime(
) → DateTime - Returns the time at which the session object was created.
-
getDebugLog(
) → String - Returns the accumulated debug log for this session, or an empty string if none is available.
-
getDuration(
) → int - Returns the wall-clock execution duration in milliseconds.
-
getEndTime(
) → DateTime? -
Returns the time at which execution ended, or
nullif the session has not yet completed. -
getFailStackTrace(
) → String? -
Returns the failure stack trace captured when the session failed, or
nullif the session did not fail or no trace is available. -
getLogAt(
int index) → String -
Returns the log message at
index. -
getLogLevelAt(
int index) → int -
Returns the log level for the entry at
index. -
getLogs(
) → String? -
Returns all buffered log entries concatenated into a single string, or
nullif no log entries exist. Equivalent to getLogsAsString. -
getLogsAsString(
) → String? -
Returns all buffered log entries concatenated into a single string, or
nullif no log entries exist. -
getLogsCount(
) → int - Returns the number of log entries buffered for this session.
-
getOutput(
) → String? -
Returns the combined output of the session as a string, or
nullif no output is available yet. -
getReturnCode(
) → int - Returns the native exit code.
-
getSessionId(
) → int - Returns the unique session ID assigned by the C layer.
-
getStartTime(
) → DateTime? -
Returns the time at which execution started, or
nullif the session has not yet been executed. -
getState(
) → SessionState - Returns the current lifecycle state of this session.
-
getStatisticsAt(
int index) → Statistics? -
Returns the Statistics snapshot at
index, ornullif the index is out of range. -
getStatisticsCount(
) → int - Returns the number of statistics snapshots buffered for this session.
-
hasBridgeLease(
CallbackBridgeKind kind) → bool -
Returns whether this session currently owns a lease for
kind. -
isDebugLogEnabled(
) → bool -
Returns
trueif per-session debug logging is currently enabled. -
isFFmpegSession(
) → bool -
Returns
trueif this session is an FFmpegSession. -
isFFplaySession(
) → bool -
Returns
trueif this session is an FFplaySession. -
isFFprobeSession(
) → bool -
Returns
trueif this session is an FFprobeSession. -
isMediaInformationSession(
) → bool -
Returns
trueif this session is a MediaInformationSession. -
markCancelledBeforeExecution(
) → void - Records cancellation for a queue-wide discard without querying native state or dispatching a native cancellation call.
-
markExecutionSettled(
) → void - Marks the queue-owned execution as terminal.
-
markExecutionStarted(
) → void - Marks the queue handoff immediately before the executor is invoked.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
observeTerminalCompletion(
) → void - Commits terminal history before completion observers are invoked.
-
onCancelledBeforeStart(
) → void - Closes Dart-side callback and stream resources when execution is cancelled before native work starts. Concrete session types override this hook; it is deliberately separate from onDispose because a cancelled queued session still owns its native handle.
-
onDispose(
) → void - Gives concrete session types a hook to close Dart-side resources after the backend release has committed and the finalizer/error handler have been detached. This ordering prevents a post-release cleanup failure from causing a second native release.
-
onLogsDispatched(
List< Log> batch) → void - Called after dispatchPendingLogs drains a batch from the native buffer.
-
onRestoredCompletionSettled(
) → void - Gives concrete session types a chance to release completion-only routing while preserving any independent log/statistics sinks.
-
registerExecutionErrorHandler(
SessionExecutionErrorCallback callback) → void - Registers the handler used when the platform cannot deliver a normal completion event for an asynchronous execution.
-
registerFinalizer(
) → void - Attaches the platform finalizer to this session when supported.
-
releaseAllBridgeLeases(
) → void - Releases all callback bridges owned by this session.
-
releaseBridgeLease(
CallbackBridgeKind kind) → void - Releases one session-owned bridge lease without allowing cleanup failure to replace the execution's primary error.
-
releaseHandle(
SessionHandle handle) → void - Releases the platform handle owned by this session.
-
requireInitializedForExecution(
) → void - Requires the selected backend to be initialized before direct execution.
-
settleRestoredCompletionObservation(
) → void - Settles the completion-observation owner for a restored wrapper.
-
toString(
) → String -
A string representation of this object.
inherited
-
trackExecution(
Completer< void> completer) → void - Tracks an asynchronous execution so dispose can settle its internal wait even when disposal unregisters the completion callback first.
-
validateExecutionHandoff(
) → void - Revalidates the native lifecycle immediately before queue handoff.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited