Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle media attribute parsing without trailing new lines #46

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading