2021-02-23 18:03:37 +08:00
|
|
|
using System.Threading;
|
|
|
|
using BililiveRecorder.Flv.Pipeline;
|
2021-04-29 23:51:06 +08:00
|
|
|
using BililiveRecorder.Flv.Pipeline.Actions;
|
2021-02-23 18:03:37 +08:00
|
|
|
|
|
|
|
namespace BililiveRecorder.Core.ProcessingRules
|
|
|
|
{
|
2022-05-16 23:28:31 +08:00
|
|
|
internal 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;
|
|
|
|
|
2022-06-17 17:42:50 +08:00
|
|
|
private static readonly ProcessingComment comment_before = new ProcessingComment(CommentType.Logging, false, "New file before data by split rule");
|
|
|
|
private static readonly ProcessingComment comment_after = new ProcessingComment(CommentType.Logging, false, "New file after data by split rule");
|
2021-04-07 18:24:05 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|