@@ -613,7 +613,7 @@ func (p *StreamPlayerHandler) controllerLoop(
613613 logger .Debugf (ctx , "checking if we get get the position" )
614614 err = p .withPlayer (ctx , func (ctx context.Context , player player.Player ) {
615615 var pos time.Duration
616- pos , err = player .GetPosition (ctx )
616+ pos , err = player .GetAudioPosition (ctx )
617617 logger .Debugf (ctx , "result of getting the position: %v %v" , pos , err )
618618 if err != nil {
619619 err = fmt .Errorf ("unable to get the position: %w" , err )
@@ -669,7 +669,7 @@ func (p *StreamPlayerHandler) controllerLoop(
669669 logger .Errorf (ctx , "unable to unpause: %v" , err )
670670 }
671671 }
672- pos , err = player .GetPosition (ctx )
672+ pos , err = player .GetAudioPosition (ctx )
673673 if err != nil {
674674 err = fmt .Errorf ("unable to get position: %w" , err )
675675 }
@@ -794,6 +794,7 @@ func (p *StreamPlayerHandler) controllerLoop(
794794
795795 logger .Debugf (ctx , "finished waiting for a publisher at '%s'" , p .StreamID )
796796
797+ traceLogLevel := logger .LevelTrace
797798 jitterBufDurationIncrease := time .Duration (0 )
798799 increaseJitterBufferBy := func (inc time.Duration ) {
799800 if inc == 0 {
@@ -811,6 +812,11 @@ func (p *StreamPlayerHandler) controllerLoop(
811812 )
812813 }
813814 commitJitterBufferIncrease := func () {
815+ logger .Logf (ctx , traceLogLevel ,
816+ "StreamPlayer[%s].controllerLoop: committing jitter buffer increase of %v" ,
817+ p .StreamID ,
818+ jitterBufDurationIncrease ,
819+ )
814820 increaseJitterBufferBy (jitterBufDurationIncrease )
815821 jitterBufDurationIncrease = 0
816822 }
@@ -848,15 +854,14 @@ func (p *StreamPlayerHandler) controllerLoop(
848854 timeDelta := now .Sub (prevNow )
849855 prevNow = now
850856
851- traceLogLevel := logger .LevelTrace
852857 if time .Since (lastDebugReportAt ) > 10 * time .Second {
853858 traceLogLevel = logger .LevelDebug
854859 lastDebugReportAt = time .Now ()
855860 }
856861
857862 err := p .withPlayer (ctx , func (ctx context.Context , player player.Player ) {
858863 now := time .Now ()
859- pos , err := player .GetPosition (ctx )
864+ pos , err := player .GetAudioPosition (ctx )
860865 if err != nil {
861866 logger .Errorf (ctx ,
862867 "StreamPlayer[%s].controllerLoop: unable to get the current position: %v" ,
@@ -945,10 +950,10 @@ func (p *StreamPlayerHandler) controllerLoop(
945950 restart ()
946951 return
947952 }
948- minBuf := noMovementDuration + p . CurrentJitterBufDuration
949- if minBuf > jitterBufDurationIncrease {
950- jitterBufDurationIncrease = minBuf
951- logger .Debugf (ctx , "StreamPlayer[%s].controllerLoop: no movement duration == %v, setting the jitterBufDurationIncrease to %v" , p .StreamID , noMovementDuration , minBuf )
953+ minExtraBuf := noMovementDuration
954+ if minExtraBuf > jitterBufDurationIncrease {
955+ jitterBufDurationIncrease = minExtraBuf
956+ logger .Debugf (ctx , "StreamPlayer[%s].controllerLoop: no movement duration == %v, setting the jitterBufDurationIncrease to %v" , p .StreamID , noMovementDuration , minExtraBuf )
952957 }
953958 }
954959
@@ -983,7 +988,14 @@ func (p *StreamPlayerHandler) controllerLoop(
983988 if jitterBufDurationIncreaseNew < 0 {
984989 jitterBufDurationIncreaseNew = 0
985990 }
986- increaseJitterBufferBy (jitterBufDurationIncrease - jitterBufDurationIncreaseNew )
991+ commitIncreaseNowDuration := jitterBufDurationIncrease - jitterBufDurationIncreaseNew
992+ logger .Logf (ctx , traceLogLevel ,
993+ "StreamPlayer[%s].controllerLoop: increasing the jitter buffer by %v (%v - %v)" ,
994+ p .StreamID ,
995+ commitIncreaseNowDuration ,
996+ jitterBufDurationIncrease , jitterBufDurationIncreaseNew ,
997+ )
998+ increaseJitterBufferBy (commitIncreaseNowDuration )
987999 jitterBufDurationIncrease = jitterBufDurationIncreaseNew
9881000 }
9891001 }
0 commit comments