View Source Membrane.RTC.Engine.Track (Membrane RTC Engine v0.20.0)

Module representing media track.

Media track is a single audio or video. Tracks that are related to each other (e.g. audio from microphone that corresponds to video from a web cam) can be grouped into the same stream by assigning each of them the same stream id.

Summary

Types

Options that can be passed to new/7.

t()

This module contains

Possible track variants.

Functions

Returns depayloader for given track.

Checks whether track is a simulcast one or not.

Generates stream id, that can be used to mark tracks belonging to the same stream.

Returns list of supported track variants.

Types

@type encoding() :: atom()
@type framerate() :: {non_neg_integer(), non_neg_integer()} | nil
@type id() :: String.t()
@type opts_t() :: [
  id: String.t(),
  active?: boolean(),
  variants: [variant()],
  metadata: any(),
  ctx: map(),
  payload_type: non_neg_integer() | nil,
  framerate: framerate()
]

Options that can be passed to new/7.

If not provided:

  • id - will be generated
  • active? - true
  • variants - [:high]
  • metadata - nil
  • ctx - %{}

For more information refer to t/0.

@type t() :: %Membrane.RTC.Engine.Track{
  active?: boolean(),
  clock_rate: Membrane.RTP.clock_rate_t(),
  ctx: map(),
  encoding: encoding(),
  fmtp: ExSDP.Attribute.FMTP.t(),
  framerate: framerate(),
  id: id(),
  metadata: any(),
  origin: String.t(),
  payload_type: non_neg_integer() | nil,
  stream_id: String.t(),
  type: :audio | :video,
  variants: [variant()]
}

This module contains:

  • type - audio or video,
  • stream_id - media stream this track belongs to. Relationship between tracks (e.g. audio and video) can be indicated by assigning each of them the same stream_id. One stream_id can be assign to any number of tracks.
  • id - track id
  • origin - id of Endpoint this track belongs to
  • encoding - track encoding
  • variants - list of possible track variants. Refer to variant/0.
  • clock_rate - track clock rate
  • fmtp - struct describing format specific parameters e.g. for H264 it contains profile_level_id
  • active? - indicates whether track is still available or not (because client left a room)
  • metadata - any data passed by user to be linked with this track
  • ctx - any data Endpoints need to associate with Membrane.RTC.Engine.Track.t() for internal usage
  • framerate - track framerate. It's up to endpoints whether they set this field or not but if they do, they should only set it for video tracks with constant framerate. For audio tracks, framerate should always be nil. Defaults to nil.
@type variant() :: :high | :medium | :low

Possible track variants.

The usage should be as follows:

  • :high - main track variant
  • :medium - lower (in terms of quality) track variant
  • :low - the lowest track variant

Audio tracks can have only one variant - :high.

Functions

@spec get_depayloader(t()) :: Membrane.ChildrenSpec.child_definition() | nil

Returns depayloader for given track.

Depayloader can be used to unpack RTP stream i.e. get data out of RTP packets.

Returns Membrane child specification or nil if depayloader couldn't be determined.

Examples

@impl true
def handle_pad_added(Pad.ref(:input, track_id) = pad, _ctx, state) do
  children = %{
    {:track_receiver, track_id} => %TrackReceiver{
      track: Map.fetch!(state.tracks, track_id),
      initial_target_variant: :high
    },
    {:depayloader, track.id} => get_depayloader(track),
    {:serializer, track_id} => Membrane.Stream.Serializer,
    {:sink, track_id} => %Membrane.File.Sink{
      location: Path.join(state.output_dir_path, track_id)
    }
  }

  links = [
    link_bin_input(pad)
    |> to({:track_receiver, track_id})
    |> to({:depayloader, track.id})
    |> to({:serializer, track_id})
    |> to({:sink, track_id})
  ]

  {{:ok, spec: %ParentSpec{children: children, links: links}}, state}
end
@spec is_simulcast?(t()) :: boolean()

Checks whether track is a simulcast one or not.

Link to this function

new(type, stream_id, origin, encoding, clock_rate, fmtp, opts \\ [])

View Source
@spec new(
  :audio | :video,
  String.t(),
  String.t(),
  encoding(),
  Membrane.RTP.clock_rate_t(),
  ExSDP.Attribute.FMTP.t(),
  opts_t()
) :: t()

Creates a new track.

Tracks belonging to the same stream should have the same stream_id, that can be generated with stream_id/0.

@spec stream_id() :: String.t()

Generates stream id, that can be used to mark tracks belonging to the same stream.

@spec supported_variants() :: [variant()]

Returns list of supported track variants.