add FindDataNALUInAVCCNALUs and IsDataNALU

This commit is contained in:
nareix 2016-07-01 19:19:44 +08:00
parent 116764e6c3
commit cef54937c5

View File

@ -16,6 +16,11 @@ const (
NALU_AUD = 9 NALU_AUD = 9
) )
func IsDataNALU(b []byte) bool {
typ := b[0] & 0x1f
return typ >= 1 && typ <= 5
}
/* /*
From: http://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream From: http://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream
@ -215,23 +220,23 @@ func WalkNALUsAVCC(nalus [][]byte, write func([]byte)) {
} }
} }
func CheckNALUsType(b []byte) int { func CheckNALUsType(b []byte) (typ int) {
if len(b) < 4 { _, typ = SplitNALUs(b)
return NALU_RAW return
}
func FindDataNALUInAVCCNALUs(b []byte) (data []byte, ok bool) {
var typ int
var nalus [][]byte
if nalus, typ = SplitNALUs(b); typ != NALU_AVCC {
return
} }
for _, nalu := range nalus {
val3 := bits.GetUIntBE(b, 24) if IsDataNALU(nalu) {
val4 := bits.GetUIntBE(b, 32) return nalu, true
}
if val4+4 == uint(len(b)) {
return NALU_AVCC
} }
return
if val4 == 1 || val3 == 1 {
return NALU_ANNEXB
}
return NALU_RAW
} }
const ( const (