-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
defmodule ExWebRTC.SDPUtils do | ||
@moduledoc false | ||
|
||
@spec get_media_direction(ExSDP.Media.t()) :: | ||
:sendrecv | :sendonly | :recvonly | :inactive | nil | ||
def get_media_direction(media) do | ||
Enum.find(media.attributes, fn attr -> | ||
attr in [:sendrecv, :sendonly, :recvonly, :inactive] | ||
end) | ||
end | ||
|
||
@spec ensure_mid(ExSDP.t()) :: :ok | {:error, :missing_mid | :duplicated_mid} | ||
def ensure_mid(sdp) do | ||
sdp.media | ||
|> Enum.reduce_while({:ok, []}, fn media, {:ok, acc} -> | ||
case ExSDP.Media.get_attributes(media, :mid) do | ||
[{:mid, mid}] -> {:cont, {:ok, [mid | acc]}} | ||
[] -> {:halt, {:error, :missing_mid}} | ||
other when is_list(other) -> {:halt, {:error, :duplicated_mid}} | ||
end | ||
end) | ||
|> case do | ||
{:ok, mids} -> if Enum.uniq(mids) == mids, do: :ok, else: {:error, :duplicated_mid} | ||
error -> error | ||
end | ||
end | ||
|
||
@spec ensure_bundle(ExSDP.t()) :: | ||
:ok | ||
| {:error, | ||
:non_exhaustive_bundle_group | ||
| :missing_budnle_group | ||
| :multiple_bundle_groups | ||
| :invalid_bundle_group} | ||
def ensure_bundle(sdp) do | ||
groups = ExSDP.get_attributes(sdp, ExSDP.Attribute.Group) | ||
|
||
mline_mids = | ||
Enum.map(sdp.media, fn media -> | ||
{:mid, mid} = ExSDP.Media.get_attribute(media, :mid) | ||
mid | ||
end) | ||
|
||
case groups do | ||
[%ExSDP.Attribute.Group{semantics: "BUNDLE", mids: group_mids}] -> | ||
case {mline_mids -- group_mids, group_mids -- mline_mids} do | ||
{[], []} -> :ok | ||
{_, []} -> {:error, :non_exhaustive_bundle_group} | ||
_other -> {:error, :invalid_bundle_group} | ||
end | ||
|
||
[] -> | ||
{:error, :missing_bundle_group} | ||
|
||
other when is_list(other) -> | ||
{:error, :multiple_bundle_groups} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ExUnit.start() | ||
ExUnit.start(capture_logs: true) |