Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 committed Feb 23, 2024
1 parent 57d18f7 commit 8c507a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Membrane.RTP.TCP.Packetizer do
defmodule Membrane.RTP.TCP.Decapsulator do
@moduledoc """
This element provides functionality of packetizing bytestream from TCP
into RTP and RTCP Packets. The encapsulation is described in RFC 4571.
Expand Down Expand Up @@ -46,19 +46,14 @@ defmodule Membrane.RTP.TCP.Packetizer do
{unprocessed_data :: binary(), complete_packets :: [binary()]}
defp get_complete_packets(packets_binary, complete_packets \\ [])

defp get_complete_packets(packets_binary, complete_packets)
when byte_size(packets_binary) <= 2 do
{packets_binary, Enum.reverse(complete_packets)}
defp get_complete_packets(
<<payload_length::16, payload::binary-size(payload_length), rest::binary>>,
complete_packets
) do
get_complete_packets(rest, [payload | complete_packets])
end

defp get_complete_packets(packets_binary, complete_packets) do
<<payload_length::size(16), rest::binary>> = packets_binary

if payload_length > byte_size(rest) do
{packets_binary, Enum.reverse(complete_packets)}
else
<<complete_packet_binary::binary-size(payload_length)-unit(8), rest::binary>> = rest
get_complete_packets(rest, [complete_packet_binary | complete_packets])
end
defp get_complete_packets(unprocessed_data, complete_packets) do
{unprocessed_data, Enum.reverse(complete_packets)}
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Membrane.RTP.TCP.Depacketizer do
defmodule Membrane.RTP.TCP.Encapsulator do
@moduledoc """
This element provides functionality of serializing RTP and RTCP packets into a bytestream
that can be send over TCP connection. The encapsulation is described in RFC 4571.
Expand Down Expand Up @@ -32,14 +32,8 @@ defmodule Membrane.RTP.TCP.Depacketizer do

@impl true
def handle_buffer(:input, %Buffer{payload: payload, metadata: metadata}, _ctx, state) do
len_bytes =
case :binary.encode_unsigned(byte_size(payload), :big) do
<<len::size(8)>> -> <<0, len>>
<<len::binary-size(2)>> -> len
end

buffer = %Buffer{
payload: len_bytes <> payload,
payload: <<byte_size(payload)::size(16), payload::binary>>,
metadata: metadata
}

Expand Down

0 comments on commit 8c507a0

Please sign in to comment.