View Source Membrane.HTTPAdaptiveStream.Storage behaviour (Membrane HTTP Adaptive Stream plugin v0.12.0)

Behaviour for storing manifests and stream segments.

Link to this section 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 segments grouped by track.

Removes all the saved segments and manifest for given id.

Clears the manifest cache.

Initializes the storage.

Stores serialized manifest files

Link to this section Types

@type callback_result_t() :: :ok | {:error, reason :: any()}
@type config_t() :: struct()
@type metadata_t() :: segment_metadata_t() | partial_segment_metadata() | %{}
@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.

Link to this type

partial_segment_metadata()

View Source
@type partial_segment_metadata() :: %{
  duration: Membrane.Time.t(),
  independent: boolean(),
  byte_offset: non_neg_integer()
}
@type segment_metadata_t() :: %{duration: Membrane.Time.t()}
@type state_t() :: any()
@opaque t()

Link to this section Callbacks

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

Generates the storage state based on the configuration struct.

Link to this callback

remove(parent_id, resource_name, context, state_t)

View Source
@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.

Link to this callback

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

View Source
@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

Link to this section Functions

Link to this function

apply_segment_changeset(storage, track_id, changeset, buffer)

View Source
@spec apply_segment_changeset(
  t(),
  track_id :: term(),
  Membrane.HTTPAdaptiveStream.Manifest.Track.Changeset.t(),
  buffer :: Membrane.Buffer.t()
) :: {callback_result_t(), t()}

Stores a new segment and removes stale ones.

Link to this function

clean_all_track_segments(storage, segments_per_track)

View Source
@spec clean_all_track_segments(t(), %{required(id :: any()) => [String.t()]}) ::
  {callback_result_t(), t()}

Removes all segments grouped by track.

Link to this function

cleanup(storage, id, segments)

View Source
@spec cleanup(t(), id :: any(), segments :: [String.t()]) ::
  {callback_result_t(), t()}

Removes all the saved segments and manifest for given id.

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

Clears the manifest cache.

Link to this function

new(storage_config, opts \\ [])

View Source
@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
Link to this function

store_header(storage, track_id, name, payload)

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

Stores stream header file.

Link to this function

store_manifests(storage, manifests)

View Source
@spec store_manifests(t(), [
  {id :: :master | term(), {name :: String.t(), content :: String.t()}}
]) ::
  {callback_result_t(), t()}

Stores serialized manifest files