2021-02-08 16:51:19 +08:00
|
|
|
using System;
|
2021-02-23 18:03:37 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using BililiveRecorder.Flv.Amf;
|
2021-04-29 23:51:06 +08:00
|
|
|
using BililiveRecorder.Flv.Pipeline.Actions;
|
2021-02-08 16:51:19 +08:00
|
|
|
|
|
|
|
namespace BililiveRecorder.Flv.Pipeline.Rules
|
|
|
|
{
|
|
|
|
/// <summary>
|
2022-05-02 00:01:41 +08:00
|
|
|
/// 处理 Script Tag
|
2021-02-08 16:51:19 +08:00
|
|
|
/// </summary>
|
|
|
|
public class HandleNewScriptRule : ISimpleProcessingRule
|
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
private const string onMetaData = "onMetaData";
|
2021-04-07 18:24:05 +08:00
|
|
|
private static readonly ProcessingComment comment_onmetadata = new ProcessingComment(CommentType.Logging, "收到了 onMetaData");
|
2021-02-27 20:44:04 +08:00
|
|
|
|
2021-03-09 00:50:13 +08:00
|
|
|
public void Run(FlvProcessingContext context, Action next)
|
2021-02-08 16:51:19 +08:00
|
|
|
{
|
2021-03-09 00:50:13 +08:00
|
|
|
context.PerActionRun(this.RunPerAction);
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<PipelineAction?> RunPerAction(FlvProcessingContext context, PipelineAction action)
|
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
ScriptTagBody? data;
|
2021-03-09 00:50:13 +08:00
|
|
|
if (action is PipelineScriptAction scriptAction)
|
2021-02-08 16:51:19 +08:00
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
data = scriptAction.Tag.ScriptData;
|
|
|
|
if (data is not null)
|
2021-02-23 18:03:37 +08:00
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
if (data.Values.Count == 2
|
|
|
|
&& data.Values[0] is ScriptDataString name
|
|
|
|
&& name == onMetaData)
|
2021-02-23 18:03:37 +08:00
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
goto IsOnMetaData;
|
|
|
|
}
|
|
|
|
else if (data.Values.Count == 3
|
|
|
|
&& data.Values[2] is ScriptDataNull
|
|
|
|
&& data.Values[0] is ScriptDataString name2
|
|
|
|
&& name2 == onMetaData)
|
|
|
|
{
|
|
|
|
/* d1--ov-gotcha07.bilivideo.com
|
|
|
|
* CNAME d1--ov-gotcha07.bilivideo.com.a.bcelive.com
|
|
|
|
* CNAME d1--ov-gotcha07.bilivideo.com.zengslb.com
|
|
|
|
* Singapore AS21859 Zenlayer Inc
|
|
|
|
*
|
|
|
|
* 给的 script tag 数据里第三个位置多了个 NULL
|
|
|
|
*/
|
|
|
|
goto IsOnMetaData;
|
|
|
|
}
|
|
|
|
else
|
2021-02-23 18:03:37 +08:00
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
goto notOnMetaData;
|
|
|
|
}
|
2021-02-23 18:03:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-11 00:03:28 +08:00
|
|
|
goto notOnMetaData;
|
2021-02-23 18:03:37 +08:00
|
|
|
}
|
2021-02-08 16:51:19 +08:00
|
|
|
}
|
2021-02-23 18:03:37 +08:00
|
|
|
else
|
2021-08-11 00:03:28 +08:00
|
|
|
{
|
2021-03-09 00:50:13 +08:00
|
|
|
yield return action;
|
2021-08-11 00:03:28 +08:00
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsOnMetaData:
|
|
|
|
ScriptDataEcmaArray value = data.Values[1] switch
|
|
|
|
{
|
|
|
|
ScriptDataObject obj => obj,
|
|
|
|
ScriptDataEcmaArray arr => arr,
|
|
|
|
_ => new ScriptDataEcmaArray()
|
|
|
|
};
|
|
|
|
context.AddComment(comment_onmetadata);
|
|
|
|
yield return PipelineNewFileAction.Instance;
|
|
|
|
yield return (new PipelineScriptAction(new Tag
|
|
|
|
{
|
|
|
|
Type = TagType.Script,
|
|
|
|
ScriptData = new ScriptTagBody(new List<IScriptDataValue>
|
|
|
|
{
|
|
|
|
(ScriptDataString)onMetaData,
|
|
|
|
value
|
|
|
|
})
|
|
|
|
}));
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
notOnMetaData:
|
|
|
|
context.AddComment(new ProcessingComment(CommentType.Logging, "收到了非 onMetaData 的 Script Tag: " + (data?.ToJson() ?? "(null)")));
|
|
|
|
yield break;
|
2021-02-08 16:51:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|