mirror of https://bitbucket.org/ausocean/av.git
Merged in http-post-fix (pull request #250)
codec/h264/parse.go: skip over access unit delimiters when getting nalType Approved-by: Alan Noble <anoble@gmail.com>
This commit is contained in:
commit
04fa5c1e2b
|
@ -11,7 +11,7 @@ const (
|
||||||
naluTypeSEI
|
naluTypeSEI
|
||||||
NALTypeSPS
|
NALTypeSPS
|
||||||
naluTypePPS
|
naluTypePPS
|
||||||
naluTypeAccessUnitDelimiter
|
NALTypeAccessUnitDelimiter
|
||||||
naluTypeEndOfSequence
|
naluTypeEndOfSequence
|
||||||
naluTypeEndOfStream
|
naluTypeEndOfStream
|
||||||
naluTypeFillerData
|
naluTypeFillerData
|
||||||
|
|
|
@ -26,14 +26,20 @@ LICENSE
|
||||||
|
|
||||||
package h264
|
package h264
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"bitbucket.org/ausocean/av/codec/h264/h264dec"
|
||||||
|
)
|
||||||
|
|
||||||
var errNotEnoughBytes = errors.New("not enough bytes to read")
|
var errNotEnoughBytes = errors.New("not enough bytes to read")
|
||||||
|
|
||||||
// NALType returns the NAL type of the given NAL unit bytes. The given NAL unit
|
// NALType returns the NAL type of the given NAL unit bytes. The given NAL unit
|
||||||
// may be in byte stream or packet format.
|
// may be in byte stream or packet format.
|
||||||
|
// NB: access unit delimiters are skipped.
|
||||||
func NALType(n []byte) (int, error) {
|
func NALType(n []byte) (int, error) {
|
||||||
sc := frameScanner{buf: n}
|
sc := frameScanner{buf: n}
|
||||||
|
for {
|
||||||
b, ok := sc.readByte()
|
b, ok := sc.readByte()
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errNotEnoughBytes
|
return 0, errNotEnoughBytes
|
||||||
|
@ -51,9 +57,12 @@ func NALType(n []byte) (int, error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errNotEnoughBytes
|
return 0, errNotEnoughBytes
|
||||||
}
|
}
|
||||||
return int(b & 0x1f), nil
|
nalType := int(b & 0x1f)
|
||||||
|
if nalType != h264dec.NALTypeAccessUnitDelimiter {
|
||||||
|
return nalType, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return int(b & 0x1f), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type frameScanner struct {
|
type frameScanner struct {
|
||||||
|
|
|
@ -101,7 +101,10 @@ func TestEncodeVideo(t *testing.T) {
|
||||||
|
|
||||||
// Create the dst and write the test data to encoder.
|
// Create the dst and write the test data to encoder.
|
||||||
dst := &destination{}
|
dst := &destination{}
|
||||||
_, err := NewEncoder(nopCloser{dst}, 25, EncodeH264).Write(data)
|
e := NewEncoder(nopCloser{dst}, 25, EncodeH264)
|
||||||
|
e.NALBasedPSI(false, psiSendCount)
|
||||||
|
|
||||||
|
_, err := e.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not write data to encoder, failed with err: %v\n", err)
|
t.Fatalf("could not write data to encoder, failed with err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue