Thanks for the info. My dissect function is ensuring that the packets lengths are correct as far as i can tell. Everything from {:tcp, data} is buffered and is able to be parsed successfully as RTP packets i think. The recursive function takes care of this: (i’ve added more comments)
# complete packet verified length
def disect(<<36, 0::integer-8, length::integer-16, chunk::binary-size(length), rest::binary>>, acc, state) do
# chunk is an RTP packet, forward to RTP parser
# rest should be the beginning of the next packet, it may not be complete
disect(rest, acc ++ [%Buffer{payload: chunk}], state)
end
# this has never actually happened in my tests because my camera is currently configured to only output
# one channel currently.
def disect(<<36, channel::integer-8, length::integer-16, _chunk::binary-size(length), rest::binary>>, acc, state) do
# _chunk is a RTP packet, but we don't need it
IO.puts "ignoring channel: #{channel}"
disect(rest, acc, state)
end
# this packet is not complete. Stop recursion, dispatch complete packets, buffer the incomplete data
def disect(<<36, _::binary>> = incomplete, acc, state) do
# need to request more data
{{:ok, [buffer: {:output, acc}, redemand: :output]}, %{state | buffer: incomplete}}
end


















