From a2d1b09e92e570f0342a95605c09794b2c5651a0 Mon Sep 17 00:00:00 2001 From: Saxon Date: Sun, 19 May 2019 17:21:41 +0930 Subject: [PATCH] codec/h265: fixed lexer to get nal header into start of fragment Now getting the nal header and type from fu header for the first fragment. We can now lex and create HEVC MTS to RTP - working fine. Need to use RTCP now to continue stream. --- codec/h265/lex.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/codec/h265/lex.go b/codec/h265/lex.go index d67cf289..f5afa5e6 100644 --- a/codec/h265/lex.go +++ b/codec/h265/lex.go @@ -76,6 +76,7 @@ func (l *Lexer) Lex(dst io.Writer, src io.Reader, delay time.Duration) error { switch err { case nil: // Do nothing. case io.EOF: + fmt.Println("done") return nil default: return fmt.Errorf("source read error: %v\n", err) @@ -150,6 +151,11 @@ func (l *Lexer) handleFragmentation(d []byte) { start := d[2]&0x80 != 0 end := d[2]&0x40 != 0 + var head []byte + if start { + head = []byte{(d[0] & 0x81) | ((d[2] & 0x3f) << 1), d[1]} + } + d = d[3:] if l.donl { d = d[2:] @@ -158,7 +164,8 @@ func (l *Lexer) handleFragmentation(d []byte) { switch { case start && !end: l.frag = true - l.writeWithPrefix(d) + _d := append(head, d...) + l.writeWithPrefix(_d) case !start && end: l.frag = false fallthrough