diff --git a/generator/FLVGenerator.go b/generator/FLVGenerator.go index eda24c4a..c7c42edb 100644 --- a/generator/FLVGenerator.go +++ b/generator/FLVGenerator.go @@ -115,51 +115,63 @@ func (g *flvGenerator) ResetTimestamp() { g.currentTimestamp = 0 } -// getNalType returns the naltype byte from the passed frame i.e. nalUnit -func getNalType(frame []byte) byte { +func isKeyFrame(frame []byte) bool { byteChannel := make(chan byte, len(frame)) for i := range frame { byteChannel <- frame[i] } - for len(byteChannel) >= 5 { - aByte := <-byteChannel - for i := 1; aByte == 0x00 && i != 4; i++ { + for len(byteChannel) >= 5{ + aByte := <-byteChannel + for i:=1; aByte == 0x00 && i != 4; i++ { aByte = <-byteChannel - if (aByte == 0x01 && i == 2) || (aByte == 0x01 && i == 3) { + if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) { aByte = <-byteChannel - return aByte & 0x1F + nalType := aByte & 0x1F + switch nalType { + case interFrameCode: + return false + case keyFrameCode: + return true + case 6: + return true + } } } } - return 0x00 -} - -// isKeyFrame checks the nature of the passed frame - returning true if the -// frame is keyframe and false otherwise -func isKeyFrame(frame []byte) bool { - nalType := getNalType(frame) - switch { - case nalType == interFrameCode: - return false - case nalType == keyFrameCode || nalType == 6: - return true - } return false } -// isSequenceHeader checks the nature of the passed frame and returns true -// if it is a sequnce header and false otherwise func isSequenceHeader(frame []byte) bool { - nalType := getNalType(frame) - switch { - case nalType == 1 || nalType == 5: - return false - case nalType == 6 || nalType == 7 || nalType == 8: - return true + byteChannel := make(chan byte, len(frame)) + for i := range frame { + byteChannel <- frame[i] + } + for len(byteChannel) >= 5{ + aByte := <-byteChannel + for i:=1; aByte == 0x00 && i != 4; i++ { + aByte = <-byteChannel + if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) { + aByte = <-byteChannel + nalType := aByte & 0x1F + switch nalType { + case 1: + return false + case 5: + return false + case 6: + return true + case 7: + return true + case 8: + return true + } + } + } } return false } + // generate takes in raw video data from the input chan and packetises it into // flv tags, which are then passed to the output channel. func (g *flvGenerator) generate() {