From b42e7f9b1310ba359eb1b42d11cfdb7e1658f1eb Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 26 Apr 2019 20:31:12 +0930 Subject: [PATCH 1/5] codec: created h264 and mjpeg packages to house lexers --- codec/{lex => h264}/lex.go | 52 +--------- codec/{lex => h264}/lex_test.go | 133 +------------------------- codec/mjpeg/lex.go | 155 ++++++++++++++++++++++++++++++ codec/mjpeg/lex_test.go | 163 ++++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+), 183 deletions(-) rename codec/{lex => h264}/lex.go (81%) rename codec/{lex => h264}/lex_test.go (67%) create mode 100644 codec/mjpeg/lex.go create mode 100644 codec/mjpeg/lex_test.go diff --git a/codec/lex/lex.go b/codec/h264/lex.go similarity index 81% rename from codec/lex/lex.go rename to codec/h264/lex.go index da0dd1b6..c9de1196 100644 --- a/codec/lex/lex.go +++ b/codec/h264/lex.go @@ -24,14 +24,9 @@ LICENSE You should have received a copy of the GNU General Public License along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ - -// Package lex provides lexers for video encodings. -package lex +package h264 import ( - "bufio" - "bytes" - "fmt" "io" "time" ) @@ -200,48 +195,3 @@ func (c *scanner) reload() error { c.off = 0 return nil } - -// MJPEG parses MJPEG frames read from src into separate writes to dst with -// successive writes being performed not earlier than the specified delay. -func MJPEG(dst io.Writer, src io.Reader, delay time.Duration) error { - var tick <-chan time.Time - if delay == 0 { - tick = noDelay - } else { - ticker := time.NewTicker(delay) - defer ticker.Stop() - tick = ticker.C - } - - r := bufio.NewReader(src) - for { - buf := make([]byte, 2, 4<<10) - n, err := r.Read(buf) - if n < 2 { - return nil - } - if err != nil { - return err - } - if !bytes.Equal(buf, []byte{0xff, 0xd8}) { - return fmt.Errorf("parser: not MJPEG frame start: %#v", buf) - } - var last byte - for { - b, err := r.ReadByte() - if err != nil { - return err - } - buf = append(buf, b) - if last == 0xff && b == 0xd9 { - break - } - last = b - } - <-tick - _, err = dst.Write(buf) - if err != nil { - return err - } - } -} diff --git a/codec/lex/lex_test.go b/codec/h264/lex_test.go similarity index 67% rename from codec/lex/lex_test.go rename to codec/h264/lex_test.go index a107b253..9912d751 100644 --- a/codec/lex/lex_test.go +++ b/codec/h264/lex_test.go @@ -25,12 +25,9 @@ LICENSE along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ -package lex +package h264 import ( - "bytes" - "reflect" - "testing" "time" ) @@ -221,131 +218,3 @@ func TestH264(t *testing.T) { } } */ - -var mjpegTests = []struct { - name string - input []byte - delay time.Duration - want [][]byte - err error -}{ - { - name: "empty", - }, - { - name: "null", - input: []byte{0xff, 0xd8, 0xff, 0xd9}, - delay: 0, - want: [][]byte{{0xff, 0xd8, 0xff, 0xd9}}, - }, - { - name: "null delayed", - input: []byte{0xff, 0xd8, 0xff, 0xd9}, - delay: time.Millisecond, - want: [][]byte{{0xff, 0xd8, 0xff, 0xd9}}, - }, - { - name: "full", - input: []byte{ - 0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9, - 0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9, - 0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9, - 0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9, - 0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9, - }, - delay: 0, - want: [][]byte{ - {0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9}, - {0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9}, - {0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9}, - {0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9}, - {0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9}, - }, - }, - { - name: "full delayed", - input: []byte{ - 0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9, - 0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9, - 0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9, - 0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9, - 0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9, - }, - delay: time.Millisecond, - want: [][]byte{ - {0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9}, - {0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9}, - {0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9}, - {0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9}, - {0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9}, - }, - }, -} - -// FIXME this needs to be adapted -/* -func TestMJEG(t *testing.T) { - for _, test := range mjpegTests { - var buf chunkEncoder - err := MJPEG(&buf, bytes.NewReader(test.input), test.delay) - if fmt.Sprint(err) != fmt.Sprint(test.err) { - t.Errorf("unexpected error for %q: got:%v want:%v", test.name, err, test.err) - } - if err != nil { - continue - } - got := [][]byte(buf) - if !reflect.DeepEqual(got, test.want) { - t.Errorf("unexpected result for %q:\ngot :%#v\nwant:%#v", test.name, got, test.want) - } - } -} -*/ - -type chunkEncoder [][]byte - -func (e *chunkEncoder) Encode(b []byte) error { - *e = append(*e, b) - return nil -} - -func (*chunkEncoder) Stream() <-chan []byte { panic("INVALID USE") } - -func TestScannerReadByte(t *testing.T) { - data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") - - for _, size := range []int{1, 2, 8, 1 << 10} { - r := newScanner(bytes.NewReader(data), make([]byte, size)) - var got []byte - for { - b, err := r.readByte() - if err != nil { - break - } - got = append(got, b) - } - if !bytes.Equal(got, data) { - t.Errorf("unexpected result for buffer size %d:\ngot :%q\nwant:%q", size, got, data) - } - } -} - -func TestScannerScanUntilZero(t *testing.T) { - data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit,\x00 sed do eiusmod tempor incididunt ut \x00labore et dolore magna aliqua.") - - for _, size := range []int{1, 2, 8, 1 << 10} { - r := newScanner(bytes.NewReader(data), make([]byte, size)) - var got [][]byte - for { - buf, _, err := r.scanUntilZeroInto(nil) - got = append(got, buf) - if err != nil { - break - } - } - want := bytes.SplitAfter(data, []byte{0}) - if !reflect.DeepEqual(got, want) { - t.Errorf("unexpected result for buffer zie %d:\ngot :%q\nwant:%q", size, got, want) - } - } -} diff --git a/codec/mjpeg/lex.go b/codec/mjpeg/lex.go new file mode 100644 index 00000000..07d0d50c --- /dev/null +++ b/codec/mjpeg/lex.go @@ -0,0 +1,155 @@ +/* +NAME + lex.go + +DESCRIPTION + See Readme.md + +AUTHOR + Dan Kortschak + +LICENSE + lex.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean) + + It is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. +*/ + +// Package lex provides lexers for video encodings. +package mjpeg + +import ( + "bufio" + "bytes" + "fmt" + "io" + "time" +) + +var noDelay = make(chan time.Time) + +func init() { + close(noDelay) +} + +// MJPEG parses MJPEG frames read from src into separate writes to dst with +// successive writes being performed not earlier than the specified delay. +func MJPEG(dst io.Writer, src io.Reader, delay time.Duration) error { + var tick <-chan time.Time + if delay == 0 { + tick = noDelay + } else { + ticker := time.NewTicker(delay) + defer ticker.Stop() + tick = ticker.C + } + + r := bufio.NewReader(src) + for { + buf := make([]byte, 2, 4<<10) + n, err := r.Read(buf) + if n < 2 { + return nil + } + if err != nil { + return err + } + if !bytes.Equal(buf, []byte{0xff, 0xd8}) { + return fmt.Errorf("parser: not MJPEG frame start: %#v", buf) + } + var last byte + for { + b, err := r.ReadByte() + if err != nil { + return err + } + buf = append(buf, b) + if last == 0xff && b == 0xd9 { + break + } + last = b + } + <-tick + _, err = dst.Write(buf) + if err != nil { + return err + } + } +} + +// scanner is a byte scanner. +type scanner struct { + buf []byte + off int + + // r is the source of data for the scanner. + r io.Reader +} + +// newScanner returns a scanner initialised with an io.Reader and a read buffer. +func newScanner(r io.Reader, buf []byte) *scanner { + return &scanner{r: r, buf: buf[:0]} +} + +// scanUntilZeroInto scans the scanner's underlying io.Reader until a zero byte +// has been read, appending all read bytes to dst. The resulting appended data, +// the last read byte and whether the last read byte was zero are returned. +func (c *scanner) scanUntilZeroInto(dst []byte) (res []byte, b byte, err error) { +outer: + for { + var i int + for i, b = range c.buf[c.off:] { + if b != 0x0 { + continue + } + dst = append(dst, c.buf[c.off:c.off+i+1]...) + c.off += i + 1 + break outer + } + dst = append(dst, c.buf[c.off:]...) + err = c.reload() + if err != nil { + break + } + } + return dst, b, err +} + +// readByte is an unexported ReadByte. +func (c *scanner) readByte() (byte, error) { + if c.off >= len(c.buf) { + err := c.reload() + if err != nil { + return 0, err + } + } + b := c.buf[c.off] + c.off++ + return b, nil +} + +// reload re-fills the scanner's buffer. +func (c *scanner) reload() error { + n, err := c.r.Read(c.buf[:cap(c.buf)]) + c.buf = c.buf[:n] + if err != nil { + if err != io.EOF { + return err + } + if n == 0 { + return io.EOF + } + } + c.off = 0 + return nil +} diff --git a/codec/mjpeg/lex_test.go b/codec/mjpeg/lex_test.go new file mode 100644 index 00000000..216658d8 --- /dev/null +++ b/codec/mjpeg/lex_test.go @@ -0,0 +1,163 @@ +/* +NAME + lex_test.go + +DESCRIPTION + See Readme.md + +AUTHOR + Dan Kortschak + +LICENSE + lex_test.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean) + + It is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. +*/ + +package mjpeg + +import ( + "bytes" + "reflect" + "testing" + "time" +) + +var mjpegTests = []struct { + name string + input []byte + delay time.Duration + want [][]byte + err error +}{ + { + name: "empty", + }, + { + name: "null", + input: []byte{0xff, 0xd8, 0xff, 0xd9}, + delay: 0, + want: [][]byte{{0xff, 0xd8, 0xff, 0xd9}}, + }, + { + name: "null delayed", + input: []byte{0xff, 0xd8, 0xff, 0xd9}, + delay: time.Millisecond, + want: [][]byte{{0xff, 0xd8, 0xff, 0xd9}}, + }, + { + name: "full", + input: []byte{ + 0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9, + 0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9, + 0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9, + 0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9, + 0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9, + }, + delay: 0, + want: [][]byte{ + {0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9}, + {0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9}, + {0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9}, + {0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9}, + {0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9}, + }, + }, + { + name: "full delayed", + input: []byte{ + 0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9, + 0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9, + 0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9, + 0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9, + 0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9, + }, + delay: time.Millisecond, + want: [][]byte{ + {0xff, 0xd8, 'f', 'u', 'l', 'l', 0xff, 0xd9}, + {0xff, 0xd8, 'f', 'r', 'a', 'm', 'e', 0xff, 0xd9}, + {0xff, 0xd8, 'w', 'i', 't', 'h', 0xff, 0xd9}, + {0xff, 0xd8, 'l', 'e', 'n', 'g', 't', 'h', 0xff, 0xd9}, + {0xff, 0xd8, 's', 'p', 'r', 'e', 'a', 'd', 0xff, 0xd9}, + }, + }, +} + +// FIXME this needs to be adapted +/* +func TestMJEG(t *testing.T) { + for _, test := range mjpegTests { + var buf chunkEncoder + err := MJPEG(&buf, bytes.NewReader(test.input), test.delay) + if fmt.Sprint(err) != fmt.Sprint(test.err) { + t.Errorf("unexpected error for %q: got:%v want:%v", test.name, err, test.err) + } + if err != nil { + continue + } + got := [][]byte(buf) + if !reflect.DeepEqual(got, test.want) { + t.Errorf("unexpected result for %q:\ngot :%#v\nwant:%#v", test.name, got, test.want) + } + } +} +*/ + +type chunkEncoder [][]byte + +func (e *chunkEncoder) Encode(b []byte) error { + *e = append(*e, b) + return nil +} + +func (*chunkEncoder) Stream() <-chan []byte { panic("INVALID USE") } + +func TestScannerReadByte(t *testing.T) { + data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") + + for _, size := range []int{1, 2, 8, 1 << 10} { + r := newScanner(bytes.NewReader(data), make([]byte, size)) + var got []byte + for { + b, err := r.readByte() + if err != nil { + break + } + got = append(got, b) + } + if !bytes.Equal(got, data) { + t.Errorf("unexpected result for buffer size %d:\ngot :%q\nwant:%q", size, got, data) + } + } +} + +func TestScannerScanUntilZero(t *testing.T) { + data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit,\x00 sed do eiusmod tempor incididunt ut \x00labore et dolore magna aliqua.") + + for _, size := range []int{1, 2, 8, 1 << 10} { + r := newScanner(bytes.NewReader(data), make([]byte, size)) + var got [][]byte + for { + buf, _, err := r.scanUntilZeroInto(nil) + got = append(got, buf) + if err != nil { + break + } + } + want := bytes.SplitAfter(data, []byte{0}) + if !reflect.DeepEqual(got, want) { + t.Errorf("unexpected result for buffer zie %d:\ngot :%q\nwant:%q", size, got, want) + } + } +} From 32621f0cfe845a3af7fa5bd386c5e7e7bf671ecd Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 26 Apr 2019 20:46:43 +0930 Subject: [PATCH 2/5] av: fixed build errors --- codec/h264/lex.go | 2 +- codec/h264/lex_test.go | 52 ++++++++++++++++++++++++++++++++++++++++- codec/mjpeg/lex.go | 2 +- codec/mjpeg/lex_test.go | 2 +- go.sum | 2 -- revid/revid.go | 7 +++--- 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/codec/h264/lex.go b/codec/h264/lex.go index c9de1196..2ed93fd3 100644 --- a/codec/h264/lex.go +++ b/codec/h264/lex.go @@ -43,7 +43,7 @@ var h264Prefix = [...]byte{0x00, 0x00, 0x01, 0x09, 0xf0} // successive writes being performed not earlier than the specified delay. // NAL units are split after type 1 (Coded slice of a non-IDR picture), 5 // (Coded slice of a IDR picture) and 8 (Picture parameter set). -func H264(dst io.Writer, src io.Reader, delay time.Duration) error { +func Lex(dst io.Writer, src io.Reader, delay time.Duration) error { var tick <-chan time.Time if delay == 0 { tick = noDelay diff --git a/codec/h264/lex_test.go b/codec/h264/lex_test.go index 9912d751..50b735bd 100644 --- a/codec/h264/lex_test.go +++ b/codec/h264/lex_test.go @@ -28,6 +28,9 @@ LICENSE package h264 import ( + "bytes" + "reflect" + "testing" "time" ) @@ -204,7 +207,7 @@ var h264Tests = []struct { func TestH264(t *testing.T) { for _, test := range h264Tests { var buf chunkEncoder - err := H264(&buf, bytes.NewReader(test.input), test.delay) + err := Lex(&buf, bytes.NewReader(test.input), test.delay) if fmt.Sprint(err) != fmt.Sprint(test.err) { t.Errorf("unexpected error for %q: got:%v want:%v", test.name, err, test.err) } @@ -218,3 +221,50 @@ func TestH264(t *testing.T) { } } */ +type chunkEncoder [][]byte + +func (e *chunkEncoder) Encode(b []byte) error { + *e = append(*e, b) + return nil +} + +func (*chunkEncoder) Stream() <-chan []byte { panic("INVALID USE") } + +func TestScannerReadByte(t *testing.T) { + data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") + + for _, size := range []int{1, 2, 8, 1 << 10} { + r := newScanner(bytes.NewReader(data), make([]byte, size)) + var got []byte + for { + b, err := r.readByte() + if err != nil { + break + } + got = append(got, b) + } + if !bytes.Equal(got, data) { + t.Errorf("unexpected result for buffer size %d:\ngot :%q\nwant:%q", size, got, data) + } + } +} + +func TestScannerScanUntilZero(t *testing.T) { + data := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit,\x00 sed do eiusmod tempor incididunt ut \x00labore et dolore magna aliqua.") + + for _, size := range []int{1, 2, 8, 1 << 10} { + r := newScanner(bytes.NewReader(data), make([]byte, size)) + var got [][]byte + for { + buf, _, err := r.scanUntilZeroInto(nil) + got = append(got, buf) + if err != nil { + break + } + } + want := bytes.SplitAfter(data, []byte{0}) + if !reflect.DeepEqual(got, want) { + t.Errorf("unexpected result for buffer zie %d:\ngot :%q\nwant:%q", size, got, want) + } + } +} diff --git a/codec/mjpeg/lex.go b/codec/mjpeg/lex.go index 07d0d50c..5595f588 100644 --- a/codec/mjpeg/lex.go +++ b/codec/mjpeg/lex.go @@ -44,7 +44,7 @@ func init() { // MJPEG parses MJPEG frames read from src into separate writes to dst with // successive writes being performed not earlier than the specified delay. -func MJPEG(dst io.Writer, src io.Reader, delay time.Duration) error { +func Lex(dst io.Writer, src io.Reader, delay time.Duration) error { var tick <-chan time.Time if delay == 0 { tick = noDelay diff --git a/codec/mjpeg/lex_test.go b/codec/mjpeg/lex_test.go index 216658d8..0888ce3d 100644 --- a/codec/mjpeg/lex_test.go +++ b/codec/mjpeg/lex_test.go @@ -96,7 +96,7 @@ var mjpegTests = []struct { // FIXME this needs to be adapted /* -func TestMJEG(t *testing.T) { +func Lex(t *testing.T) { for _, test := range mjpegTests { var buf chunkEncoder err := MJPEG(&buf, bytes.NewReader(test.input), test.delay) diff --git a/go.sum b/go.sum index 7ffe0a32..cd09945f 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ bitbucket.org/ausocean/iot v1.2.4 h1:M/473iQ0d4q+76heerjAQuqXzQyc5dZ3F7Bfuq6X7q4= bitbucket.org/ausocean/iot v1.2.4/go.mod h1:5HVLgPHccW2PxS7WDUQO6sKWMgk3Vfze/7d5bHs8EWU= -bitbucket.org/ausocean/utils v0.0.0-20190408050157-66d3b4d4041e h1:rn7Z1vE6m1NSH+mrPJPgquEfBDsqzBEH4Y6fxzyB6kA= -bitbucket.org/ausocean/utils v0.0.0-20190408050157-66d3b4d4041e/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8= bitbucket.org/ausocean/utils v1.2.6 h1:JN66APCV+hu6GebIHSu2KSywhLym4vigjSz5+fB0zXc= bitbucket.org/ausocean/utils v1.2.6/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= diff --git a/revid/revid.go b/revid/revid.go index d8068115..f8dc21df 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -40,7 +40,8 @@ import ( "sync" "time" - "bitbucket.org/ausocean/av/codec/lex" + "bitbucket.org/ausocean/av/codec/h264" + "bitbucket.org/ausocean/av/codec/mjpeg" "bitbucket.org/ausocean/av/container/flv" "bitbucket.org/ausocean/av/container/mts" "bitbucket.org/ausocean/iot/pi/netsender" @@ -259,10 +260,10 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.Writer, rate int) (io.W switch r.config.InputCodec { case H264: r.config.Logger.Log(logger.Info, pkg+"using H264 lexer") - r.lexTo = lex.H264 + r.lexTo = h264.Lex case Mjpeg: r.config.Logger.Log(logger.Info, pkg+"using MJPEG lexer") - r.lexTo = lex.MJPEG + r.lexTo = mjpeg.Lex } return nil } From 5d6e3171bf9a3d037bad0e81898de09c21a9525c Mon Sep 17 00:00:00 2001 From: Saxon Date: Sat, 27 Apr 2019 20:37:23 +0930 Subject: [PATCH 3/5] protocol/rtmp: fixed usage of h264 lexer in rtmp_test.go --- protocol/rtmp/rtmp_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol/rtmp/rtmp_test.go b/protocol/rtmp/rtmp_test.go index f2d661c5..9a741c8a 100644 --- a/protocol/rtmp/rtmp_test.go +++ b/protocol/rtmp/rtmp_test.go @@ -38,7 +38,7 @@ import ( "testing" "time" - "bitbucket.org/ausocean/av/codec/lex" + "bitbucket.org/ausocean/av/codec/h264" "bitbucket.org/ausocean/av/container/flv" ) @@ -199,7 +199,7 @@ func TestFromFrame(t *testing.T) { if err != nil { t.Errorf("Failed to create flv encoder with error: %v", err) } - err = lex.H264(flvEncoder, bytes.NewReader(videoData), time.Second/time.Duration(frameRate)) + err = h264.Lex(flvEncoder, bytes.NewReader(videoData), time.Second/time.Duration(frameRate)) if err != nil { t.Errorf("Lexing failed with error: %v", err) } @@ -249,7 +249,7 @@ func TestFromFile(t *testing.T) { if err != nil { t.Fatalf("failed to create encoder: %v", err) } - err = lex.H264(flvEncoder, f, time.Second/time.Duration(25)) + err = h264.Lex(flvEncoder, f, time.Second/time.Duration(25)) if err != nil { t.Errorf("Lexing and encoding failed with error: %v", err) } From 314a8dab9a822e9fe997a0c806392b5c3a851fb2 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 3 May 2019 19:52:23 +0930 Subject: [PATCH 4/5] codec: updated commenting and file header descriptions for files in h265 and mjpeg packages --- codec/h264/lex.go | 3 ++- codec/h264/lex_test.go | 2 +- codec/mjpeg/lex.go | 5 ++--- codec/mjpeg/lex_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/codec/h264/lex.go b/codec/h264/lex.go index 2ed93fd3..9600b104 100644 --- a/codec/h264/lex.go +++ b/codec/h264/lex.go @@ -3,7 +3,7 @@ NAME lex.go DESCRIPTION - See Readme.md + lex.go provides a lexer to lex h264 bytestream into access units. AUTHOR Dan Kortschak @@ -24,6 +24,7 @@ LICENSE You should have received a copy of the GNU General Public License along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ + package h264 import ( diff --git a/codec/h264/lex_test.go b/codec/h264/lex_test.go index 50b735bd..13efec14 100644 --- a/codec/h264/lex_test.go +++ b/codec/h264/lex_test.go @@ -3,7 +3,7 @@ NAME lex_test.go DESCRIPTION - See Readme.md + lex_test.go provides tests for the lexer in lex.go. AUTHOR Dan Kortschak diff --git a/codec/mjpeg/lex.go b/codec/mjpeg/lex.go index 5595f588..06e95a05 100644 --- a/codec/mjpeg/lex.go +++ b/codec/mjpeg/lex.go @@ -3,7 +3,7 @@ NAME lex.go DESCRIPTION - See Readme.md + lex.go provides a lexer to extract separate JPEG images from a MJPEG stream. AUTHOR Dan Kortschak @@ -25,7 +25,6 @@ LICENSE along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ -// Package lex provides lexers for video encodings. package mjpeg import ( @@ -42,7 +41,7 @@ func init() { close(noDelay) } -// MJPEG parses MJPEG frames read from src into separate writes to dst with +// Lex parses MJPEG frames read from src into separate writes to dst with // successive writes being performed not earlier than the specified delay. func Lex(dst io.Writer, src io.Reader, delay time.Duration) error { var tick <-chan time.Time diff --git a/codec/mjpeg/lex_test.go b/codec/mjpeg/lex_test.go index 0888ce3d..e92633f3 100644 --- a/codec/mjpeg/lex_test.go +++ b/codec/mjpeg/lex_test.go @@ -3,7 +3,7 @@ NAME lex_test.go DESCRIPTION - See Readme.md + lex_test.go provides testing for the lexer in lex.go. AUTHOR Dan Kortschak From 478db11ecc350a2823f8f8def6c52eb428d41557 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 6 May 2019 15:47:51 +0930 Subject: [PATCH 5/5] codec: file descriptions under file header so that they are put in godoc --- codec/h264/lex.go | 2 ++ codec/h264/lex_test.go | 2 ++ codec/mjpeg/lex.go | 2 ++ codec/mjpeg/lex_test.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/codec/h264/lex.go b/codec/h264/lex.go index 9600b104..3865eaa5 100644 --- a/codec/h264/lex.go +++ b/codec/h264/lex.go @@ -25,6 +25,8 @@ LICENSE along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ +// lex.go provides a lexer to lex h264 bytestream into access units. + package h264 import ( diff --git a/codec/h264/lex_test.go b/codec/h264/lex_test.go index 13efec14..d584ce18 100644 --- a/codec/h264/lex_test.go +++ b/codec/h264/lex_test.go @@ -25,6 +25,8 @@ LICENSE along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ +// lex_test.go provides tests for the lexer in lex.go. + package h264 import ( diff --git a/codec/mjpeg/lex.go b/codec/mjpeg/lex.go index 06e95a05..09ee2513 100644 --- a/codec/mjpeg/lex.go +++ b/codec/mjpeg/lex.go @@ -25,6 +25,8 @@ LICENSE along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ +// lex.go provides a lexer to extract separate JPEG images from a MJPEG stream. + package mjpeg import ( diff --git a/codec/mjpeg/lex_test.go b/codec/mjpeg/lex_test.go index e92633f3..59b4bd25 100644 --- a/codec/mjpeg/lex_test.go +++ b/codec/mjpeg/lex_test.go @@ -25,6 +25,8 @@ LICENSE along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. */ +// lex_test.go provides testing for the lexer in lex.go. + package mjpeg import (