Commit 19cf2a85 by liulongfei

修复分辨率改变导致视频渲染停止的问题

parent 9a970560
......@@ -138,6 +138,11 @@ namespace VIZ.Framework.Common
else
{
StopRendering();
// 在丢失前景缓冲区后重新创建
this.CreateAndBindTargets();
StartRendering();
}
}
......
......@@ -132,14 +132,6 @@ namespace VIZ.Framework.Common
SolidColorBrush brush = new SolidColorBrush(context.Target, info.DrawingBorderColor);
context.Target.DrawRectangle(drawRect, brush, info.DrawingBorderWidth);
#if DEBUG
//StringBuilder sb = new StringBuilder();
//sb.AppendLine($"【渲染裁切框】 {info.TimeCode}");
//sb.Append($"========================= END =========================");
//log.Debug(sb.ToString());
#endif
}
}
}
......@@ -136,14 +136,6 @@ namespace VIZ.Framework.Common
if (renderInfo == null)
return;
#if DEBUG
//StringBuilder sb = new StringBuilder();
//sb.AppendLine($"========================= BEGIN =========================");
//sb.Append($"【渲染视频】 {renderInfo.Frame.TimeStamp}");
//log.Debug(sb.ToString());
#endif
context.VideoRenderInfo = renderInfo;
// 绘制视频
......
......@@ -11,7 +11,7 @@ namespace VIZ.Framework.Common
/// <summary>
/// 视频帧
/// </summary>
public interface IVideoFrame : IDisposable
public interface IVideoFrame : IVideoControlSync, IDisposable
{
/// <summary>
/// 宽度
......@@ -29,11 +29,6 @@ namespace VIZ.Framework.Common
int Length { get; set; }
/// <summary>
/// 时间戳
/// </summary>
long TimeStamp { get; set; }
/// <summary>
/// 是否是最后一帧
/// </summary>
bool IsEnd { get; set; }
......
......@@ -26,7 +26,10 @@ namespace VIZ.Framework.Common
/// <summary>
/// 最大队列长度
/// </summary>
public int MaxQueueCount { get; set; } = 100;
/// <remarks>
/// 40ms * 50 = 2s
/// </remarks>
public int MaxQueueCount { get; set; } = 50;
/// <summary>
/// 帧同步时触发
......@@ -36,12 +39,12 @@ namespace VIZ.Framework.Common
/// <summary>
/// 视频帧队列
/// </summary>
public ConcurrentQueue<IVideoControlSync> VideoFrameQueue { get; private set; } = new ConcurrentQueue<IVideoControlSync>();
private ConcurrentQueue<IVideoControlSync> VideoFrameQueue = new ConcurrentQueue<IVideoControlSync>();
/// <summary>
/// 数据帧队列
/// </summary>
public ConcurrentQueue<IVideoControlSync> DataFrameQueue { get; private set; } = new ConcurrentQueue<IVideoControlSync>();
private ConcurrentQueue<IVideoControlSync> DataFrameQueue = new ConcurrentQueue<IVideoControlSync>();
/// <summary>
/// 视频帧待处理数据
......@@ -63,58 +66,107 @@ namespace VIZ.Framework.Common
}
/// <summary>
/// 添加
/// </summary>
/// <param name="videoFrame">视频帧</param>
public void AppendVideoFrame(IVideoControlSync videoFrame)
{
this.VideoFrameQueue.Enqueue(videoFrame);
}
/// <summary>
/// 添加数据帧
/// </summary>
/// <param name="dataFrame">数据帧</param>
public void AppendDataFrame(IVideoControlSync dataFrame)
{
this.DataFrameQueue.Enqueue(dataFrame);
}
/// <summary>
/// 执行不需要对齐并且处理视频帧
/// </summary>
public void ExecuteVideo()
{
IVideoControlSync video = this.VideoFrame;
if (this.VideoFrame == null)
{
this.VideoFrameQueue.TryDequeue(out video);
}
if (video == null)
return;
this.triggerEvent(video, null);
this.VideoFrame = null;
}
/// <summary>
/// 执行对齐
/// </summary>
public void Execute()
public void ExecuteSync()
{
try
{
IVideoControlSync video = this.VideoFrame;
IVideoControlSync data = this.DataFrame;
if (this.VideoFrame == null)
while (true)
{
this.VideoFrameQueue.TryDequeue(out video);
}
IVideoControlSync video = this.VideoFrame;
IVideoControlSync data = this.DataFrame;
if (this.DataFrame == null)
{
this.DataFrameQueue.TryDequeue(out data);
}
if (this.VideoFrame == null)
{
this.VideoFrameQueue.TryDequeue(out video);
}
int videoQueueCount = this.VideoFrameQueue.Count;
if (this.DataFrame == null)
{
this.DataFrameQueue.TryDequeue(out data);
}
// 没有视频帧时不处理
if (video == null)
return;
int videoQueueCount = this.VideoFrameQueue.Count;
// 有视频帧 没有数据帧
if (data == null)
{
// 如果视频帧队列在等待队列长度范围内,那么不处理
if (videoQueueCount < this.MaxQueueCount)
// 没有视频帧时不处理
if (video == null)
return;
// 处理数据
this.triggerEvent(video, null);
this.VideoFrame = null;
// 有视频帧 没有数据帧
if (data == null)
{
// 如果视频帧队列在等待队列长度范围内,那么不处理
if (videoQueueCount < this.MaxQueueCount)
return;
return;
}
// 处理数据
this.triggerEvent(video, null);
this.VideoFrame = null;
// 如果视频帧的时间戳小于数据的时间戳
if (video.TimeStamp < data.TimeStamp)
{
this.triggerEvent(video, null);
this.VideoFrame = null;
return;
}
return;
}
// 如果视频帧的时间戳小于数据的时间戳
if (video.TimeStamp < data.TimeStamp)
{
this.triggerEvent(video, null);
this.VideoFrame = null;
return;
}
// 如果视频帧的时间等于数据帧时间那么正常处理
if (video.TimeStamp == data.TimeStamp)
{
// 处理数据
this.triggerEvent(video, data);
this.VideoFrame = null;
this.DataFrame = null;
// 处理数据
this.triggerEvent(video, data);
this.VideoFrame = null;
this.DataFrame = null;
return;
}
// 抛弃该数据帧
this.DataFrame = null;
}
}
catch (Exception ex)
{
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -14,6 +15,10 @@ namespace VIZ.Framework.Connection
[ConnPackageProvider(ConnPackageProviderType.UDP)]
public class ConnSingleJsonPackageProvider : IConnPackageProvider
{
public ConnSingleJsonPackageProvider()
{
}
/// <summary>
/// 日志
/// </summary>
......
......@@ -55,5 +55,11 @@ namespace VIZ.Framework.UnitTest
string str = "{'signal': 'detect', 'bboxes': [[914.5606, 144.6889, 1877.504, 380.21176]], 'id': 'E0:4F:43:E6:48:C2__CAM_1'}";
AlgorithmPackageBase @base = Newtonsoft.Json.JsonConvert.DeserializeObject<AlgorithmPackageBase>(str);
}
[TestMethod]
public void TimeTest()
{
long l = TimeSpan.FromSeconds(1).Ticks;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment