Fixed problem. nts: keep code simple

This commit is contained in:
Unknown 2018-03-13 15:30:02 +10:30
parent f68385330c
commit 37b315b9a1
1 changed files with 40 additions and 28 deletions

View File

@ -115,8 +115,7 @@ func (g *flvGenerator) ResetTimestamp() {
g.currentTimestamp = 0 g.currentTimestamp = 0
} }
// getNalType returns the naltype byte from the passed frame i.e. nalUnit func isKeyFrame(frame []byte) bool {
func getNalType(frame []byte) byte {
byteChannel := make(chan byte, len(frame)) byteChannel := make(chan byte, len(frame))
for i := range frame { for i := range frame {
byteChannel <- frame[i] byteChannel <- frame[i]
@ -127,39 +126,52 @@ func getNalType(frame []byte) byte {
aByte = <-byteChannel aByte = <-byteChannel
if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) { if ( aByte == 0x01 && i == 2 ) || ( aByte == 0x01 && i == 3 ) {
aByte = <-byteChannel aByte = <-byteChannel
return aByte & 0x1F nalType := aByte & 0x1F
} switch nalType {
} case interFrameCode:
}
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 return false
case nalType == keyFrameCode || nalType == 6: case keyFrameCode:
return true
case 6:
return true return true
} }
}
}
}
return false 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 { func isSequenceHeader(frame []byte) bool {
nalType := getNalType(frame) byteChannel := make(chan byte, len(frame))
switch { for i := range frame {
case nalType == 1 || nalType == 5: 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 return false
case nalType == 6 || nalType == 7 || nalType == 8: case 5:
return false
case 6:
return true
case 7:
return true
case 8:
return true return true
} }
}
}
}
return false return false
} }
// generate takes in raw video data from the input chan and packetises it into // generate takes in raw video data from the input chan and packetises it into
// flv tags, which are then passed to the output channel. // flv tags, which are then passed to the output channel.
func (g *flvGenerator) generate() { func (g *flvGenerator) generate() {