Skip to content

Commit b8d1ac2

Browse files
author
Alexander Malaev
committed
Add bitrate fmtp parsing for G7221
1 parent ea367eb commit b8d1ac2

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/ex_sdp/attribute/fmtp.ex

+11-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ defmodule ExSDP.Attribute.FMTP do
6767
:dtmf_tones,
6868
# RED
6969
:redundant_payloads,
70+
# G7221
71+
:bitrate,
7072
unknown: []
7173
]
7274

@@ -115,6 +117,8 @@ defmodule ExSDP.Attribute.FMTP do
115117
dtmf_tones: String.t() | nil,
116118
# RED
117119
redundant_payloads: [RTPMapping.payload_type_t()] | nil,
120+
# G7221
121+
bitrate: non_neg_integer() | nil,
118122
# params that are currently not supported
119123
unknown: [String.t()]
120124
}
@@ -326,6 +330,10 @@ defmodule ExSDP.Attribute.FMTP do
326330
do: {rest, %{fmtp | repair_window: value}}
327331
end
328332

333+
defp parse_param(["bitrate=" <> value | rest], fmtp) do
334+
with {:ok, value} <- Utils.parse_numeric_string(value), do: {rest, %{fmtp | bitrate: value}}
335+
end
336+
329337
defp parse_param([head | rest] = params, fmtp) do
330338
# this is for non-key-value parameters as `key=value` format is not mandatory
331339
cond do
@@ -430,7 +438,9 @@ defimpl String.Chars, for: ExSDP.Attribute.FMTP do
430438
# Telephone Events
431439
Serializer.maybe_serialize("dtmf-tones", fmtp.dtmf_tones),
432440
# RED
433-
Serializer.maybe_serialize_list(fmtp.redundant_payloads, "/")
441+
Serializer.maybe_serialize_list(fmtp.redundant_payloads, "/"),
442+
# G7221
443+
Serializer.maybe_serialize("bitrate", fmtp.bitrate)
434444
]
435445
|> Enum.filter(fn param -> param != "" end)
436446
|> Enum.join(";")

test/ex_sdp/attribute/fmtp_test.exs

+22
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ defmodule ExSDP.Attribute.FMTPTest do
3333
assert {:error, :invalid_pt} == FMTP.parse(fmtp)
3434
end
3535

36+
test "parses proper fmtp with G7221 bitrate parameter" do
37+
fmtp = "98 bitrate=48000"
38+
39+
expected = %FMTP{
40+
pt: 98,
41+
bitrate: 48_000
42+
}
43+
44+
assert {:ok, expected} == FMTP.parse(fmtp)
45+
end
46+
3647
test "parses proper fmtp with simple DTMF tones parameter" do
3748
fmtp = "100 0-15"
3849

@@ -255,5 +266,16 @@ defmodule ExSDP.Attribute.FMTPTest do
255266

256267
assert "#{fmtp}" == expected
257268
end
269+
270+
test "serializes FMTP with bitrate parameter for G7221" do
271+
fmtp = %FMTP{
272+
pt: 98,
273+
bitrate: 48_000
274+
}
275+
276+
expected = "fmtp:98 bitrate=48000"
277+
278+
assert "#{fmtp}" == expected
279+
end
258280
end
259281
end

0 commit comments

Comments
 (0)