Bit 연산
Buffer = <<"123456789A">>,
Pivot = 5,
<<A:Pivot/binary, B/Binary>> = Buffer.
Bit Syntax를 이용한 RTP 헤더 정의
<< 2:2,
Padding:1,
Extension:1,
SyncSrcCount:4,
Marker:1,
PayloadType:7,
Sequence:16/big-unsigned-integer,
Timestamp:32/big-unsigned-integer,
SyncSource:32/big-unsigned-integer,
_/binary >>
RTP 파싱
parse(Packet) when is_binary(Packet) ->
case Packet of
<<2:2, _Padding:1, Extension:1, SyncSrcCount:4, Marker:1,
PayloadType:7, Sequence:16/big-unsigned-integer,
Timestamp:32/big-unsigned-integer,
SyncSource:32/big-unsigned-integer, _/binary>> ->
RtpHeaderLen = (12 + (4*SyncSrcCount)),
ExtensionBytes =
case Extension of
1 -> <<_:RtpHeaderLen/binary, _:16/big,
Length:16/big, _/binary>> = Packet, 4 + Length;
0 -> 0
end,
StartOfPayload = RtpHeaderLen + ExtensionBytes,
case Packet of
<<_:StartOfPayload/binary, Payload/binary>> ->
ParsedPacket = #rtp_packet{timestamp = Timestamp,
sync_src = SyncSource,
marker = Marker,
payload_type = PayloadType,
sequence = Sequence,
payload = Payload},
{ok, ParsedPacket};
_ -> false
end;
_ -> false
end.