FLV: Fix bug in UpdateTimestampOffsetRule

This commit is contained in:
Genteure 2021-04-27 21:30:49 +08:00
parent 0944260e46
commit 2bb94639cb

View File

@ -58,8 +58,8 @@ namespace BililiveRecorder.Flv.Pipeline.Rules
} }
else else
{ {
context.AddComment(comment2); context.AddComment(comment2);
yield return PipelineDisconnectAction.Instance; yield return PipelineDisconnectAction.Instance;
yield break; yield break;
} }
} }
@ -102,21 +102,55 @@ namespace BililiveRecorder.Flv.Pipeline.Rules
public bool Calculate(out int offset) public bool Calculate(out int offset)
{ {
this.ReduceOffsetRange(this.lastAudio, null); {
this.lastAudio = null; var last = this.lastAudio;
this.lastAudio = null;
this.ReduceOffsetRange(last, null);
}
if (this.minOffset == this.maxOffset) if (this.minOffset == this.maxOffset)
{ {
// 理想情况允许偏移范围只有一个值
offset = this.minOffset; offset = this.minOffset;
return true; return true;
} }
else if (this.minOffset <= this.maxOffset) else if (this.minOffset < this.maxOffset)
{ {
offset = (this.minOffset + this.maxOffset) / 2; // 允许偏移的值是一个范围
return true; if (this.minOffset != int.MinValue)
{
if (this.maxOffset != int.MaxValue)
{
// 有一个有效范围,取平均值
offset = (int)(((long)this.minOffset + this.maxOffset) / 2L);
return true;
}
else
{
// 无效最大偏移,以最小偏移为准
offset = this.minOffset + 1;
return true;
}
}
else
{
if (this.maxOffset != int.MaxValue)
{
// 无效最小偏移,以最大偏移为准
offset = this.maxOffset - 1;
return true;
}
else
{
// 无效结果
offset = 0;
return false;
}
}
} }
else else
{ {
// 范围无效
offset = 0; offset = 0;
return false; return false;
} }