Custom RTC endpoint PCM -> RTC

Hi, i am trying the solution proposed here (not sure if I am expected to post in the same thread or not)

I have a PCM audio that i am trying to route to multiple WebRTC endpoints, and it seems i am not handling the audio very well. For debugging I'm sending the output to a file and while the file gets written it is unplayable.

The main pipeline receive the input from a pubsub (temporary easy solution to push audio in until I can make an proper endpoint / element, the PubSubSource was previously used and worked in a pipeline used to push to HLS)

def_output_pad(:output, availability: :on_request, demand_unit: :buffers, accepted_format: _any)

  @impl true
  def handle_pad_added(Pad.ref(:output, {_track_id, _rid}) = pad, _ctx, state) do
    payloader = RTP.PayloadFormat.get(state.track.encoding).payloader

    payloader_bin = %PayloaderBin{
      payloader: payloader,
      ssrc: 18,
      payload_type: 96,
      clock_rate: state.track.clock_rate

    spec = [
      child(:input, %PubSubSource{})
      |> child(:encoder, %Opus.Encoder{
        application: :audio,
        input_stream_format: %RawAudio{
          channels: 2,
          sample_format: :s16le,
          sample_rate: 16000
      |> child(:parser, %Opus.Parser{delimitation: :undelimit})
      |> child(:payloader, payloader_bin)
      |> child(:track_sender, %StaticTrackSender{
        track: state.track,
        is_keyframe: true
      |> via_out(:output)
      |> bin_output(pad)

    {[spec: spec], state}

Thank you for you help

5 responses