Membrane.HTTPAdaptiveStream.Storage behaviour (Membrane HTTP Adaptive Stream plugin v0.20.2)

View Source

Behaviour for storing manifests and stream segments.

Summary

Types

The identifier of a parent that the resource belongs to (the track identifier).

t()

Callbacks

Generates the storage state based on the configuration struct.

Functions

Stores a new segment and removes stale ones.

Removes all the saved segments and manifest for given id.

Clears the manifest cache.

Initializes the storage.

Stores serialized manifest files

Types

callback_result_t()

@type callback_result_t() :: :ok | {:error, reason :: any()}

config_t()

@type config_t() :: struct()

header()

@type header() :: String.t()

metadata_t()

@type metadata_t() :: segment_metadata_t() | partial_segment_metadata() | %{}

parent_t()

@type parent_t() :: any()

The identifier of a parent that the resource belongs to (the track identifier).

It can either be a master or secondary playlist (a track playlist). In case of master playlist the identifier will be :master while for tracks it can be an arbitrary value.

partial_segment_metadata()

@type partial_segment_metadata() :: %{
  duration: Membrane.Time.t(),
  independent: boolean(),
  byte_offset: non_neg_integer()
}

segment_metadata_t()

@type segment_metadata_t() :: %{duration: Membrane.Time.t()}

segments()

@type segments() :: [String.t()]

state_t()

@type state_t() :: any()

t()

@opaque t()

Callbacks

init(config_t)

@callback init(config_t()) :: state_t()

Generates the storage state based on the configuration struct.

remove(parent_id, resource_name, context, state_t)

@callback remove(
  parent_id :: parent_t(),
  resource_name :: String.t(),
  context :: %{type: :manifest | :header | :segment},
  state_t()
) :: {callback_result_t(), state :: state_t()}

Removes the resource.

In case of removing a segment the storage should make sure to remove all previous partial segments with the same name. It is the user's responsibility to remember and distinguish between the partial segments.

store(parent_id, resource_name, content, metadata, context, state_t)

@callback store(
  parent_id :: parent_t(),
  resource_name :: String.t(),
  content :: String.t() | binary(),
  metadata :: metadata_t(),
  context :: %{
    type: :manifest | :header | :segment | :partial_segment,
    mode: :text | :binary
  },
  state_t()
) :: {callback_result_t(), state :: state_t()}

Stores the resource on a storage.

Gets the mode that should be used when writing to a file and type of the resource

Functions

apply_track_changeset(storage, track_id, changeset)

@spec apply_track_changeset(
  t(),
  track_id :: term(),
  Membrane.HTTPAdaptiveStream.Manifest.Changeset.t()
) :: {callback_result_t(), t()}

Stores a new segment and removes stale ones.

clean_all_tracks(storage, segments_per_track, header_per_track)

@spec clean_all_tracks(t(), %{required(id :: any()) => segments()}, %{
  required(id :: any()) => header()
}) ::
  {callback_result_t(), t()}

Removes all segments grouped by track.

cleanup(storage, id, segments, header)

@spec cleanup(t(), id :: any(), segments :: segments(), header :: header() | nil) ::
  {callback_result_t(), t()}

Removes all the saved segments and manifest for given id.

clear_cache(storage)

@spec clear_cache(t()) :: t()

Clears the manifest cache.

new(storage_config, opts \\ [])

@spec new(config_t(), [{:enable_cache, boolean()}]) :: t()

Initializes the storage.

Accepts the following options:

  • enable_cache - if true (default), manifests will be stored only if they've been changed

store_header(storage, track_id, name, payload)

@spec store_header(t(), track_id :: term(), name :: String.t(), payload :: binary()) ::
  {callback_result_t(), t()}

Stores stream header file.

store_manifests(storage, map)

Stores serialized manifest files