@ -27,8 +27,10 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -27,8 +27,10 @@ public class HlsSessionWorker : IHlsSessionWorker
private readonly object _ sync = new ( ) ;
private string _ channelNumber ;
private bool _f irstProcess ;
private bool _ hasWrittenSegments ;
private DateTimeOffset _l astAccess ;
private DateTimeOffset _l astDelete = DateTimeOffset . MinValue ;
private bool _ seekNextItem ;
private Option < int > _ targetFramerate ;
private Timer _ timer ;
private DateTimeOffset _ transcodedUntil ;
@ -86,7 +88,11 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -86,7 +88,11 @@ public class HlsSessionWorker : IHlsSessionWorker
}
}
public void PlayoutUpdated ( ) = > _f irstProcess = true ;
public void PlayoutUpdated ( )
{
_f irstProcess = true ;
_ seekNextItem = true ;
}
public async Task Run ( string channelNumber , TimeSpan idleTimeout , CancellationToken incomingCancellationToken )
{
@ -203,7 +209,7 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -203,7 +209,7 @@ public class HlsSessionWorker : IHlsSessionWorker
IMediator mediator = scope . ServiceProvider . GetRequiredService < IMediator > ( ) ;
long ptsOffset = await GetPtsOffset ( mediator , _ channelNumber , _f irstProcess , cancellationToken ) ;
long ptsOffset = await GetPtsOffset ( mediator , _ channelNumber , cancellationToken ) ;
// _logger.LogInformation("PTS offset: {PtsOffset}", ptsOffset);
var request = new GetPlayoutItemProcessByChannelNumber (
@ -250,6 +256,13 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -250,6 +256,13 @@ public class HlsSessionWorker : IHlsSessionWorker
_l ogger . LogInformation ( "HLS process has completed for channel {Channel}" , _ channelNumber ) ;
_ transcodedUntil = processModel . Until ;
_f irstProcess = false ;
if ( _ seekNextItem )
{
_f irstProcess = true ;
_ seekNextItem = false ;
}
_ hasWrittenSegments = true ;
return true ;
}
else
@ -294,6 +307,14 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -294,6 +307,14 @@ public class HlsSessionWorker : IHlsSessionWorker
if ( commandResult . ExitCode = = 0 )
{
_f irstProcess = false ;
if ( _ seekNextItem )
{
_f irstProcess = true ;
_ seekNextItem = false ;
}
_ hasWrittenSegments = true ;
return true ;
}
}
@ -392,7 +413,6 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -392,7 +413,6 @@ public class HlsSessionWorker : IHlsSessionWorker
private async Task < long > GetPtsOffset (
IMediator mediator ,
string channelNumber ,
bool firstProcess ,
CancellationToken cancellationToken )
{
await Slim . WaitAsync ( cancellationToken ) ;
@ -400,8 +420,8 @@ public class HlsSessionWorker : IHlsSessionWorker
@@ -400,8 +420,8 @@ public class HlsSessionWorker : IHlsSessionWorker
{
long result = 0 ;
// the first process always starts at zero
if ( firstProces s)
// if we haven't yet written any segments, start at zero
if ( ! _ hasWrittenSegment s)
{
return result ;
}