2021-02-08 16:51:19 +08:00
|
|
|
using System;
|
|
|
|
using BililiveRecorder.Flv.Pipeline.Rules;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
namespace BililiveRecorder.Flv.Pipeline
|
|
|
|
{
|
|
|
|
public static class IProcessingPipelineBuilderExtensions
|
|
|
|
{
|
|
|
|
public static IProcessingPipelineBuilder Add<T>(this IProcessingPipelineBuilder builder) where T : IProcessingRule =>
|
|
|
|
builder.Add(next => (ActivatorUtilities.GetServiceOrCreateInstance<T>(builder.ServiceProvider)) switch
|
|
|
|
{
|
2021-03-09 00:50:13 +08:00
|
|
|
ISimpleProcessingRule simple => context => simple.Run(context, () => next(context)),
|
|
|
|
IFullProcessingRule full => context => full.Run(context, next),
|
2021-02-08 16:51:19 +08:00
|
|
|
_ => throw new ArgumentException($"Type ({typeof(T).FullName}) does not ISimpleProcessingRule or IFullProcessingRule")
|
|
|
|
});
|
|
|
|
|
|
|
|
public static IProcessingPipelineBuilder Add<T>(this IProcessingPipelineBuilder builder, T instance) where T : IProcessingRule =>
|
|
|
|
instance switch
|
|
|
|
{
|
2021-03-09 00:50:13 +08:00
|
|
|
ISimpleProcessingRule simple => builder.Add(next => context => simple.Run(context, () => next(context))),
|
|
|
|
IFullProcessingRule full => builder.Add(next => context => full.Run(context, next)),
|
2021-02-08 16:51:19 +08:00
|
|
|
_ => throw new ArgumentException($"Type ({typeof(T).FullName}) does not ISimpleProcessingRule or IFullProcessingRule")
|
|
|
|
};
|
|
|
|
|
|
|
|
public static IProcessingPipelineBuilder AddDefault(this IProcessingPipelineBuilder builder) =>
|
|
|
|
builder
|
2021-03-03 19:04:37 +08:00
|
|
|
.Add<HandleEndTagRule>()
|
2021-02-23 18:03:37 +08:00
|
|
|
.Add<HandleDelayedAudioHeaderRule>()
|
2021-04-20 20:41:26 +08:00
|
|
|
.Add<UpdateTimestampOffsetRule>()
|
|
|
|
.Add<UpdateTimestampJumpRule>()
|
2021-02-08 16:51:19 +08:00
|
|
|
.Add<HandleNewScriptRule>()
|
|
|
|
.Add<HandleNewHeaderRule>()
|
|
|
|
.Add<RemoveDuplicatedChunkRule>()
|
|
|
|
;
|
|
|
|
|
|
|
|
public static IProcessingPipelineBuilder AddRemoveFillerData(this IProcessingPipelineBuilder builder) =>
|
|
|
|
builder.Add<RemoveFillerDataRule>();
|
|
|
|
}
|
|
|
|
}
|