From 970a445ca4b721ed8e2eae6a31842e11202fd67b Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 20 May 2019 20:49:50 +0930 Subject: [PATCH] codec/h265/lexer.go & protocol/rtp/client.go: fixed lexer and rtp client. The lexer had a bug which is now fixed, and the RTP client is no longer looking for SSRC in rtp.NewClient (which means we miss a packet). --- codec/h265/lex.go | 7 ++++--- protocol/rtp/client.go | 17 ++++------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/codec/h265/lex.go b/codec/h265/lex.go index 6e81b167..ebe34013 100644 --- a/codec/h265/lex.go +++ b/codec/h265/lex.go @@ -151,14 +151,15 @@ func (l *Lexer) handleFragmentation(d []byte) { start := d[2]&0x80 != 0 end := d[2]&0x40 != 0 - old := d + b1 := (d[0] & 0x81) | ((d[2] & 0x3f) << 1) + b2 := d[1] if start { d = d[1:] if l.donl { d = d[2:] } - d[0] = (old[0] & 0x81) | ((old[2] & 0x3f) << 1) - d[1] = old[1] + d[0] = b1 + d[1] = b2 } else { d = d[3:] if l.donl { diff --git a/protocol/rtp/client.go b/protocol/rtp/client.go index 53b4d98f..e8418b0d 100644 --- a/protocol/rtp/client.go +++ b/protocol/rtp/client.go @@ -28,7 +28,6 @@ LICENSE package rtp import ( - "fmt" "net" "sync" ) @@ -59,17 +58,6 @@ func NewClient(addr string) (*Client, error) { if err != nil { return nil, err } - - buf := make([]byte, 4096) - n, err := c.Read(buf) - if err != nil { - return nil, err - } - c.ssrc, err = SSRC(buf[:n]) - if err != nil { - return nil, fmt.Errorf("could not parse SSRC from RTP packet, failed with error: %v", err) - } - return c, nil } @@ -85,9 +73,12 @@ func (c *Client) Read(p []byte) (int, error) { if err != nil { return n, err } + if c.ssrc == 0 { + c.ssrc, _ = SSRC(p[:n]) + } s, _ := Sequence(p[:n]) c.setSequence(s) - return c.r.Read(p) + return n, err } // setSequence sets the most recently received sequence number, and updates the