|
|
|
|
@ -92,9 +92,10 @@ type formatProcessorH264 struct {
@@ -92,9 +92,10 @@ type formatProcessorH264 struct {
|
|
|
|
|
format *formats.H264 |
|
|
|
|
log logger.Writer |
|
|
|
|
|
|
|
|
|
encoder *rtph264.Encoder |
|
|
|
|
decoder *rtph264.Decoder |
|
|
|
|
lastKeyFrameReceived time.Time |
|
|
|
|
encoder *rtph264.Encoder |
|
|
|
|
decoder *rtph264.Decoder |
|
|
|
|
lastKeyFrameTimeReceived bool |
|
|
|
|
lastKeyFrameTime time.Time |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newH264( |
|
|
|
|
@ -116,7 +117,6 @@ func newH264(
@@ -116,7 +117,6 @@ func newH264(
|
|
|
|
|
PacketizationMode: forma.PacketizationMode, |
|
|
|
|
} |
|
|
|
|
t.encoder.Init() |
|
|
|
|
t.lastKeyFrameReceived = time.Now() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return t, nil |
|
|
|
|
@ -173,19 +173,20 @@ func (t *formatProcessorH264) updateTrackParametersFromNALUs(nalus [][]byte) {
@@ -173,19 +173,20 @@ func (t *formatProcessorH264) updateTrackParametersFromNALUs(nalus [][]byte) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (t *formatProcessorH264) checkKeyFrameInterval(isKeyFrame bool) { |
|
|
|
|
if isKeyFrame { |
|
|
|
|
t.lastKeyFrameReceived = time.Now() |
|
|
|
|
} else { |
|
|
|
|
now := time.Now() |
|
|
|
|
if now.Sub(t.lastKeyFrameReceived) >= maxKeyFrameInterval { |
|
|
|
|
t.lastKeyFrameReceived = now |
|
|
|
|
t.log.Log(logger.Warn, "no H264 key frames received in %v, stream can't be decoded") |
|
|
|
|
} |
|
|
|
|
func (t *formatProcessorH264) checkKeyFrameInterval(ntp time.Time, isKeyFrame bool) { |
|
|
|
|
if !t.lastKeyFrameTimeReceived || isKeyFrame { |
|
|
|
|
t.lastKeyFrameTimeReceived = true |
|
|
|
|
t.lastKeyFrameTime = ntp |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ntp.Sub(t.lastKeyFrameTime) >= maxKeyFrameInterval { |
|
|
|
|
t.lastKeyFrameTime = ntp |
|
|
|
|
t.log.Log(logger.Warn, "no H264 key frames received in %v, stream can't be decoded", maxKeyFrameInterval) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (t *formatProcessorH264) remuxAccessUnit(nalus [][]byte) [][]byte { |
|
|
|
|
func (t *formatProcessorH264) remuxAccessUnit(ntp time.Time, nalus [][]byte) [][]byte { |
|
|
|
|
isKeyFrame := false |
|
|
|
|
n := 0 |
|
|
|
|
|
|
|
|
|
@ -212,7 +213,7 @@ func (t *formatProcessorH264) remuxAccessUnit(nalus [][]byte) [][]byte {
@@ -212,7 +213,7 @@ func (t *formatProcessorH264) remuxAccessUnit(nalus [][]byte) [][]byte {
|
|
|
|
|
n++ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
t.checkKeyFrameInterval(isKeyFrame) |
|
|
|
|
t.checkKeyFrameInterval(ntp, isKeyFrame) |
|
|
|
|
|
|
|
|
|
if n == 0 { |
|
|
|
|
return nil |
|
|
|
|
@ -278,7 +279,6 @@ func (t *formatProcessorH264) Process(unit Unit, hasNonRTSPReaders bool) error {
@@ -278,7 +279,6 @@ func (t *formatProcessorH264) Process(unit Unit, hasNonRTSPReaders bool) error {
|
|
|
|
|
if hasNonRTSPReaders || t.decoder != nil || t.encoder != nil { |
|
|
|
|
if t.decoder == nil { |
|
|
|
|
t.decoder = t.format.CreateDecoder() |
|
|
|
|
t.lastKeyFrameReceived = time.Now() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if t.encoder != nil { |
|
|
|
|
@ -294,7 +294,7 @@ func (t *formatProcessorH264) Process(unit Unit, hasNonRTSPReaders bool) error {
@@ -294,7 +294,7 @@ func (t *formatProcessorH264) Process(unit Unit, hasNonRTSPReaders bool) error {
|
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tunit.AU = t.remuxAccessUnit(au) |
|
|
|
|
tunit.AU = t.remuxAccessUnit(tunit.NTP, au) |
|
|
|
|
tunit.PTS = pts |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -304,7 +304,7 @@ func (t *formatProcessorH264) Process(unit Unit, hasNonRTSPReaders bool) error {
@@ -304,7 +304,7 @@ func (t *formatProcessorH264) Process(unit Unit, hasNonRTSPReaders bool) error {
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
t.updateTrackParametersFromNALUs(tunit.AU) |
|
|
|
|
tunit.AU = t.remuxAccessUnit(tunit.AU) |
|
|
|
|
tunit.AU = t.remuxAccessUnit(tunit.NTP, tunit.AU) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// encode into RTP
|
|
|
|
|
|