Skip to content

Commit

Permalink
Handle media attribute parsing without trailing new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
clone1018 committed Mar 11, 2024
1 parent ea367eb commit 3eb5f67
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ex_sdp/media.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ defmodule ExSDP.Media do
@spec parse_optional([binary()], t()) :: {:ok, {[binary()], t()}} | {:error, atom()}
def parse_optional(lines, media)

def parse_optional([], media), do: {:ok, {[""], finalize_optional_parsing(media)}}

def parse_optional([""], media), do: {:ok, {[""], finalize_optional_parsing(media)}}

def parse_optional(["" | rest], media),
Expand Down
41 changes: 41 additions & 0 deletions test/ex_sdp/media_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,47 @@ defmodule ExSDP.MediaTest do
type: :audio
} == medium
end

test "processes audio with attributes without trailing newlines" do
media = "audio 58712 UDP/TLS/RTP/SAVPF 111"

attributes =
"""
a=rtpmap:111 OPUS/48000/2
a=fmtp:111 minptime=10;maxaveragebitrate=96000;stereo=1;sprop-stereo=1;useinbandfec=1
"""
|> String.split("\n", trim: true)

parsed_attributes = [
%Attribute.RTPMapping{
clock_rate: 48000,
encoding: "OPUS",
params: 2,
payload_type: 111
},
%Attribute.FMTP{
pt: 111,
minptime: 10,
maxaveragebitrate: 96000,
stereo: true,
useinbandfec: true,
unknown: ["sprop-stereo=1"]
}
]

{:ok, {[""], medium}} =
media
|> Media.parse()
~> ({:ok, medium} -> Media.parse_optional(attributes, medium))

assert %Media{
attributes: parsed_attributes,
fmt: ~c"o",
port: 58712,
protocol: "UDP/TLS/RTP/SAVPF",
type: :audio
} == medium
end
end

describe "Session property inheritance mechanism" do
Expand Down

0 comments on commit 3eb5f67

Please sign in to comment.