BililiveRecorder/BililiveRecorder.Core/ProcessingRules/SplitRule.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2021-02-23 18:03:37 +08:00
using System.Threading;
using BililiveRecorder.Flv.Pipeline;
namespace BililiveRecorder.Core.ProcessingRules
{
2021-03-09 01:04:31 +08:00
public class SplitRule : ISimpleProcessingRule
2021-02-23 18:03:37 +08:00
{
2021-02-27 13:28:21 +08:00
// 0 = none, 1 = after, 2 = before
2021-02-23 18:03:37 +08:00
private int splitFlag = 0;
2021-02-27 13:28:21 +08:00
private const int FLAG_NONE = 0;
private const int FLAG_BEFORE = 1;
private const int FLAG_AFTER = 2;
2021-04-07 18:24:05 +08:00
private static readonly ProcessingComment comment_before = new ProcessingComment(CommentType.Logging, "New file before data by split rule");
private static readonly ProcessingComment comment_after = new ProcessingComment(CommentType.Logging, "New file after data by split rule");
2021-03-09 01:04:31 +08:00
public void Run(FlvProcessingContext context, System.Action next)
2021-02-23 18:03:37 +08:00
{
2021-02-27 13:28:21 +08:00
var flag = Interlocked.Exchange(ref this.splitFlag, FLAG_NONE);
2021-02-23 18:03:37 +08:00
2021-02-27 13:28:21 +08:00
if (FLAG_BEFORE == flag)
2021-04-07 18:24:05 +08:00
{
context.AddComment(comment_before);
2021-03-09 01:04:31 +08:00
context.Actions.Insert(0, PipelineNewFileAction.Instance);
2021-04-07 18:24:05 +08:00
}
2021-03-09 01:04:31 +08:00
else if (FLAG_AFTER == flag)
2021-04-07 18:24:05 +08:00
{
context.AddComment(comment_after);
2021-03-09 01:04:31 +08:00
context.Actions.Add(PipelineNewFileAction.Instance);
2021-04-07 18:24:05 +08:00
}
2021-02-27 13:28:21 +08:00
2021-03-09 01:04:31 +08:00
next();
2021-02-23 18:03:37 +08:00
}
2021-02-27 13:28:21 +08:00
public void SetSplitBeforeFlag() => Interlocked.Exchange(ref this.splitFlag, FLAG_BEFORE);
public void SetSplitAfterFlag() => Interlocked.Exchange(ref this.splitFlag, FLAG_AFTER);
2021-02-23 18:03:37 +08:00
}
}