From 830d8ea647a9f56348fcd599cc93fcf22db01134 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Wed, 20 Nov 2019 14:20:22 +1030 Subject: [PATCH] protocol/rtp: add Timestamp parsing function --- protocol/rtp/parse.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/protocol/rtp/parse.go b/protocol/rtp/parse.go index 16e64c5d..6daa5469 100644 --- a/protocol/rtp/parse.go +++ b/protocol/rtp/parse.go @@ -82,6 +82,16 @@ func Sequence(d []byte) (uint16, error) { return binary.BigEndian.Uint16(d[2:]), nil } +// Timestamp returns the RTP timestamp of an RTP packet. An error is returned +// if the packet is not valid. +func Timestamp(d []byte) (uint32, error) { + err := checkPacket(d) + if err != nil { + return 0, err + } + return binary.BigEndian.Uint32(d[4:]), nil +} + // checkPacket checks the validity of the packet, firstly by checking size and // then also checking that version is compatible with these utilities. func checkPacket(d []byte) error {