-
Notifications
You must be signed in to change notification settings - Fork 0
/
depayloader.ex
43 lines (36 loc) · 1.2 KB
/
depayloader.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
defmodule Membrane.RTP.AAC.Depayloader do
@moduledoc """
Depayloader for RTP payloads constructed in accordance with RFC3640.
"""
use Membrane.Filter
alias Membrane.Buffer
alias Membrane.{AAC, RTP}
alias Membrane.RTP.AAC.Utils
def_input_pad :input, accepted_format: %RTP{}
def_output_pad :output, accepted_format: %AAC{encapsulation: :none}
def_options mode: [
spec: Utils.mode(),
description: """
The bitrate mode that dictates the maximum length of a single frame. For more information refer to typedoc of `Membrane.RTP.AAC.Utils.mode()`.
"""
]
@impl true
def handle_init(_ctx, options) do
state =
options
|> Map.from_struct()
{[], state}
end
@impl true
def handle_stream_format(:input, _stream_fmt, _ctx, state) do
{[stream_format: {:output, %AAC{}}], state}
end
@impl true
def handle_buffer(:input, buffer, _ctx, state) do
with {:ok, payload} <- Utils.parse_packet(buffer.payload, state.mode) do
{[buffer: {:output, %Buffer{buffer | payload: payload}}], state}
else
{:error, reason} -> raise "Cannot parse packet due to: #{inspect(reason)}"
end
end
end