Skip to content

Commit

Permalink
Add SDES RtpStreamId and RepairedRtpStreamId item types
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed May 22, 2024
1 parent cb218e5 commit d561bdf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Implements packet types from:
- [RFC 3550 - RTP: A Transport Protocol for Real-Time Applications](https://datatracker.ietf.org/doc/html/rfc3550)
- [RFC 4585 - Extended RTP Profile for Real-time Transport Control Protocol (RTCP)-Based Feedback (RTP/AVPF)](https://datatracker.ietf.org/doc/html/rfc4585)
- [RFC 5104 - Codec Control Messages in the RTP Audio-Visual Profile with Feedback (AVPF)](https://datatracker.ietf.org/doc/html/rfc5104)
- [RFC 8852 - RTP Stream Identifier Source Description (SDES)](https://datatracker.ietf.org/doc/html/rfc8852)
- [RTP Extensions for Transport-wide Congestion Control](https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01)

For complete list of supported packet types, refer to the [documentation](https://hexdocs.pm/ex_rtcp/readme.html).
Expand Down
6 changes: 6 additions & 0 deletions lib/ex_rtcp/packet/source_description/chunk/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ defmodule ExRTCP.Packet.SourceDescription.Chunk.Item do
| :note
| :priv
| :mid
| :rtp_stream_id
| :repaired_rtp_stream_id

@typedoc """
Struct representing item contained by chunks in Source Description RTCP packets.
Expand Down Expand Up @@ -48,6 +50,8 @@ defmodule ExRTCP.Packet.SourceDescription.Chunk.Item do
defp type_to_id(:tool), do: 6
defp type_to_id(:note), do: 7
defp type_to_id(:priv), do: 8
defp type_to_id(:rtp_stream_id), do: 12
defp type_to_id(:repaired_rtp_stream_id), do: 13
defp type_to_id(:mid), do: 15

@doc false
Expand All @@ -72,6 +76,8 @@ defmodule ExRTCP.Packet.SourceDescription.Chunk.Item do
defp id_to_type(6), do: :tool
defp id_to_type(7), do: :note
defp id_to_type(8), do: :priv
defp id_to_type(12), do: :rtp_stream_id
defp id_to_type(13), do: :repaired_rtp_stream_id
defp id_to_type(15), do: :mid
defp id_to_type(_other), do: nil
end
26 changes: 17 additions & 9 deletions test/ex_rtcp/packet/source_description/chunk/item_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ defmodule ExRTCP.Packet.SourceDescription.Chunk.ItemTest do
end
end

test "MID item" do
mid = "1234"
mid_len = byte_size(mid)
item = %Item{type: :mid, text: mid}
assert <<15, mid_len, mid::binary>> == Item.encode(item)
test "non-RFC 3550 item types" do
types = [rtp_stream_id: 12, repaired_rtp_stream_id: 13, mid: 15]

for {item_type, item_id} <- types do
text = "123"
text_len = byte_size(text)
item = %Item{type: item_type, text: text}
assert <<item_id, text_len, text::binary>> == Item.encode(item)
end
end
end

Expand All @@ -57,11 +61,15 @@ defmodule ExRTCP.Packet.SourceDescription.Chunk.ItemTest do
end
end

test "MID item" do
mid = <<1, 2, 3>>
item = <<15, byte_size(mid), mid::binary>>
test "non-RFC 3550 item types" do
types = [rtp_stream_id: 12, repaired_rtp_stream_id: 13, mid: 15]

assert {:ok, %Item{type: :mid, text: ^mid}, <<>>} = Item.decode(item)
for {item_type, item_id} <- types do
text = "123"
text_len = byte_size(text)
item = <<item_id, text_len, text::binary>>
assert {:ok, %Item{type: ^item_type, text: ^text}, <<>>} = Item.decode(item)
end
end

test "invalid item" do
Expand Down

0 comments on commit d561bdf

Please sign in to comment.