Skip to content

Commit 031c7ff

Browse files
authored
Merge pull request #2 from gBillal/fix-wrong-padding-for-bye-packet
Fix wrong padding for Bye packet
1 parent 33ea629 commit 031c7ff

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/ex_rtcp/packet/goodbye.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule ExRTCP.Packet.Goodbye do
4040
len = byte_size(reason)
4141

4242
pad_len =
43-
case rem(len, 4) do
43+
case rem(len + 1, 4) do
4444
0 -> 0
4545
other -> 4 - other
4646
end

test/ex_rtcp/packet/goodbye_test.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ defmodule ExRTCP.Packet.GoodbyeTest do
2323

2424
test "packet with reason" do
2525
sources = [@ssrc, @ssrc + 1, @ssrc + 2]
26-
reason = "1234"
26+
reason = "123"
2727

2828
packet = %Goodbye{
2929
sources: sources,
3030
reason: reason
3131
}
3232

3333
assert {encoded, 3, 203} = Goodbye.encode(packet)
34+
assert rem(byte_size(encoded), 4) == 0
3435

3536
bin = for i <- sources, do: <<i::32>>, into: <<>>
3637
bin = <<bin::binary, byte_size(reason)::8, reason::binary>>
@@ -40,17 +41,18 @@ defmodule ExRTCP.Packet.GoodbyeTest do
4041

4142
test "packet with reason that's not multiple of 32 bits" do
4243
sources = [@ssrc, @ssrc + 1, @ssrc + 2]
43-
reason = "123456"
44+
reason = "1234"
4445

4546
packet = %Goodbye{
4647
sources: sources,
4748
reason: reason
4849
}
4950

5051
assert {encoded, 3, 203} = Goodbye.encode(packet)
52+
assert rem(byte_size(encoded), 4) == 0
5153

5254
bin = for i <- sources, do: <<i::32>>, into: <<>>
53-
bin = <<bin::binary, byte_size(reason)::8, reason::binary, 0, 0>>
55+
bin = <<bin::binary, byte_size(reason)::8, reason::binary, 0, 0, 0>>
5456

5557
assert encoded == bin
5658
end

test/ex_rtcp/packet_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,17 @@ defmodule ExRTCP.PacketTest do
6868
assert {:error, :unknown_type} = Packet.decode(bin)
6969
end
7070
end
71+
72+
describe "encode/decode" do
73+
test "Encode decode" do
74+
original_packet = %Goodbye{
75+
sources: [12345, 67890],
76+
reason: "Session ended"
77+
}
78+
79+
encoded = Packet.encode(original_packet)
80+
assert {:ok, decoded_packet} = Packet.decode(encoded)
81+
assert original_packet == decoded_packet
82+
end
83+
end
7184
end

0 commit comments

Comments
 (0)