ExMemvid.Encoder (ex_memvid v0.1.1)
A Encoder implementation for encoding text chunks into QR code videos.
Each encoder instance is responsible for managing one video encoding process with proper state transitions and error handling.
States
:ready
- Ready to accept chunks and configuration:collecting
- Collecting text chunks for encoding:building
- Building the video and index files:completed
- Successfully completed encoding:error
- Error state with failure information
State Data
The state machine maintains:
config
: ExMemvid configurationchunks
: List of text chunks to encodeindex_name
: Unique identifier for this encoding processoutput_path
: Video output file pathindex_path
: Index output file pathstats
: Encoding statistics (when completed)error
: Error information (when in error state)
Example Usage
# Start a new encoder process
{:ok, pid} = ExMemvid.EncoderStateMachine.start_link(
index_name: "my_video_001",
config: %ExMemvid.Config{codec: :h264}
)
# Add text chunks
:ok = ExMemvid.EncoderStateMachine.add_chunks(pid, ["chunk1", "chunk2"])
# Build the video
{:ok, stats} = ExMemvid.EncoderStateMachine.build_video(
pid,
"output/video.mp4",
"output/index.bin"
)
Summary
Functions
Adds text chunks to the encoder.
Adds text and automatically chunks it using the configured chunking settings.
Builds the QR code video and search index. This is an asynchronous operation that transitions the state machine to building state.
Returns a specification to start this module under a supervisor.
Gets the current state and data of the encoder.
Resets the encoder to ready state, clearing all chunks and previous results.
Starts a new encoder
Types
@type state_name() :: :ready | :collecting | :building | :completed | :error
Functions
@spec add_chunks(GenServer.server(), [String.t()]) :: :ok | {:error, term()}
Adds text chunks to the encoder.
@spec add_text(GenServer.server(), String.t()) :: :ok | {:error, term()}
Adds text and automatically chunks it using the configured chunking settings.
@spec build_video(GenServer.server(), Path.t(), Path.t()) :: {:ok, map()} | {:error, term()}
Builds the QR code video and search index. This is an asynchronous operation that transitions the state machine to building state.
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec get_state(GenServer.server()) :: {state_name(), map()}
Gets the current state and data of the encoder.
@spec reset(GenServer.server()) :: :ok
Resets the encoder to ready state, clearing all chunks and previous results.
@spec start_link(keyword()) :: GenServer.on_start()
Starts a new encoder
Options
:index_name
- Unique identifier for this encoder instance (required):config
- ExMemvid configuration (required):name
- Optional process name for registration