mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-12-27 12:35:35 +08:00
29 lines
925 B
C#
29 lines
925 B
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BililiveRecorder.Flv.Pipeline;
|
|
|
|
namespace BililiveRecorder.Core.ProcessingRules
|
|
{
|
|
public class SplitRule : IFullProcessingRule
|
|
{
|
|
private static readonly FlvProcessingContext NewFileContext = new FlvProcessingContext(PipelineNewFileAction.Instance, new Dictionary<object, object?>());
|
|
|
|
// 0 = false, 1 = true
|
|
private int splitFlag = 0;
|
|
|
|
public async Task RunAsync(FlvProcessingContext context, ProcessingDelegate next)
|
|
{
|
|
await next(context).ConfigureAwait(false);
|
|
|
|
if (1 == Interlocked.Exchange(ref this.splitFlag, 0))
|
|
{
|
|
await next(NewFileContext).ConfigureAwait(false);
|
|
context.AddNewFileAtStart();
|
|
}
|
|
}
|
|
|
|
public void SetSplitFlag() => Interlocked.Exchange(ref this.splitFlag, 1);
|
|
}
|
|
}
|