From d561bdf7ed80002c453b50ff22b395e0d28dc884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wala?= Date: Wed, 22 May 2024 17:33:13 +0200 Subject: [PATCH] Add SDES `RtpStreamId` and `RepairedRtpStreamId` item types --- README.md | 1 + .../packet/source_description/chunk/item.ex | 6 +++++ .../source_description/chunk/item_test.exs | 26 ++++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a4690d5..b7d5f92 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lib/ex_rtcp/packet/source_description/chunk/item.ex b/lib/ex_rtcp/packet/source_description/chunk/item.ex index 03dd381..8b5471c 100644 --- a/lib/ex_rtcp/packet/source_description/chunk/item.ex +++ b/lib/ex_rtcp/packet/source_description/chunk/item.ex @@ -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. @@ -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 @@ -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 diff --git a/test/ex_rtcp/packet/source_description/chunk/item_test.exs b/test/ex_rtcp/packet/source_description/chunk/item_test.exs index 39a9ad1..9ef8eac 100644 --- a/test/ex_rtcp/packet/source_description/chunk/item_test.exs +++ b/test/ex_rtcp/packet/source_description/chunk/item_test.exs @@ -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.encode(item) + end end end @@ -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 = <> + assert {:ok, %Item{type: ^item_type, text: ^text}, <<>>} = Item.decode(item) + end end test "invalid item" do