2021-02-08 16:51:19 +08:00
|
|
|
using System;
|
2021-02-23 18:03:37 +08:00
|
|
|
using System.Collections.Generic;
|
2021-02-08 16:51:19 +08:00
|
|
|
using System.Threading.Tasks;
|
2021-02-23 18:03:37 +08:00
|
|
|
using BililiveRecorder.Flv.Amf;
|
2021-02-08 16:51:19 +08:00
|
|
|
|
|
|
|
namespace BililiveRecorder.Flv.Pipeline.Rules
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 处理收到 Script Tag 的情况
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 本规则为一般规则
|
|
|
|
/// </remarks>
|
|
|
|
public class HandleNewScriptRule : ISimpleProcessingRule
|
|
|
|
{
|
2021-02-27 20:44:04 +08:00
|
|
|
private static readonly ProcessingComment comment = new ProcessingComment(CommentType.Other, "收到了非 onMetaData 的 Script Tag");
|
|
|
|
|
2021-02-08 16:51:19 +08:00
|
|
|
public Task RunAsync(FlvProcessingContext context, Func<Task> next)
|
|
|
|
{
|
2021-02-23 18:03:37 +08:00
|
|
|
if (context.OriginalInput is PipelineScriptAction scriptAction)
|
2021-02-08 16:51:19 +08:00
|
|
|
{
|
2021-02-23 18:03:37 +08:00
|
|
|
var data = scriptAction.Tag.ScriptData;
|
|
|
|
if (!(data is null)
|
|
|
|
&& data.Values.Count == 2
|
|
|
|
&& data.Values[0] is ScriptDataString name
|
|
|
|
&& name == "onMetaData")
|
|
|
|
{
|
|
|
|
ScriptDataEcmaArray? value = data.Values[1] switch
|
|
|
|
{
|
|
|
|
ScriptDataObject obj => obj,
|
|
|
|
ScriptDataEcmaArray arr => arr,
|
|
|
|
_ => null
|
|
|
|
};
|
|
|
|
|
|
|
|
if (value is null)
|
|
|
|
value = new ScriptDataEcmaArray();
|
|
|
|
|
|
|
|
context.ClearOutput();
|
|
|
|
context.AddNewFileAtStart();
|
|
|
|
context.Output.Add(new PipelineScriptAction(new Tag
|
|
|
|
{
|
|
|
|
Type = TagType.Script,
|
|
|
|
ScriptData = new ScriptTagBody(new List<IScriptDataValue>
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
value
|
|
|
|
})
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-27 20:44:04 +08:00
|
|
|
context.AddComment(comment);
|
2021-02-23 18:03:37 +08:00
|
|
|
context.ClearOutput();
|
|
|
|
}
|
2021-02-08 16:51:19 +08:00
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
2021-02-23 18:03:37 +08:00
|
|
|
else
|
|
|
|
return next();
|
2021-02-08 16:51:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|