Dala.Media.Clock (dala v0.3.0)

Copy Markdown View Source

Realtime frame-clock for AV sync and animation.

Uses audio clock as master (audio glitches are more noticeable than video drops). Drives the animation system and frame pacing.

Architecture:

Audio Clock (master)
    
Frame Pacer
    
Video Frame Selection
    
Frame Presentation

Summary

Functions

Returns a specification to start this module under a supervisor.

Get current AV drift in microseconds.

Report a video frame presentation (called by video renderer).

Start the frame clock.

Start ticking at the target FPS.

Get frame statistics.

Stop ticking.

Register a listener process that receives {:clock, :tick, %{frame: n, timestamp_us: us}}.

Unsubscribe a listener.

Update the audio master clock (called by audio output callback).

Types

clock_ref()

@type clock_ref() :: pid()

timestamp_us()

@type timestamp_us() :: integer()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

drift(pid)

@spec drift(clock_ref()) :: integer()

Get current AV drift in microseconds.

report_video_frame(pid, pts_us)

@spec report_video_frame(clock_ref(), timestamp_us()) :: :ok

Report a video frame presentation (called by video renderer).

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the frame clock.

start_ticking(pid)

@spec start_ticking(clock_ref()) :: :ok

Start ticking at the target FPS.

stats(pid)

@spec stats(clock_ref()) :: %{
  frame_count: non_neg_integer(),
  dropped_frames: non_neg_integer(),
  drift_us: integer(),
  target_fps: pos_integer()
}

Get frame statistics.

stop_ticking(pid)

@spec stop_ticking(clock_ref()) :: :ok

Stop ticking.

subscribe(pid, listener)

@spec subscribe(clock_ref(), pid()) :: :ok

Register a listener process that receives {:clock, :tick, %{frame: n, timestamp_us: us}}.

unsubscribe(pid, listener)

@spec unsubscribe(clock_ref(), pid()) :: :ok

Unsubscribe a listener.

update_audio_clock(pid, timestamp_us)

@spec update_audio_clock(clock_ref(), timestamp_us()) :: :ok

Update the audio master clock (called by audio output callback).