音频相关+thread+pipe+queue

博客提供了做实时播放时的相关资料,聚焦于信息技术领域中实时播放方面的内容,能为相关从业者或学习者提供一定参考。

做实时播放时的一些资料

// FFmpegOut - FFmpeg video encoding plugin for Unity // https://github.com/keijiro/KlakNDI using System.Collections.Generic; using System.Diagnostics; using System.Threading; using Unity.Collections; namespace FFmpegOut { public sealed class FFmpegPipe : System.IDisposable { #region Public methods public static bool IsAvailable { get { return System.IO.File.Exists(ExecutablePath); } } public FFmpegPipe(string arguments) { // Start FFmpeg subprocess. _subprocess = Process.Start(new ProcessStartInfo { FileName = ExecutablePath, Arguments = arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true }); // Start copy/pipe subthreads. _copyThread = new Thread(CopyThread); _pipeThread = new Thread(PipeThread); _copyThread.Start(); _pipeThread.Start(); } public void PushFrameData(NativeArray<byte> data) { // Update the copy queue and notify the copy thread with a ping. lock (_copyQueue) _copyQueue.Enqueue(data); _copyPing.Set(); } public void SyncFrameData() { // Wait for the copy queue to get emptied with using pong // notification signals sent from the copy thread. while (_copyQueue.Count > 0) _copyPong.WaitOne(); // When using a slower codec (e.g. HEVC, ProRes), frames may be // queued too much, and it may end up with an out-of-memory error. // To avoid this problem, we wait for pipe queue entries to be // comsumed by the pipe thread. while (_pipeQueue.Count > 4) _pipePong.WaitOne(); } public string CloseAndGetOutput() { // Terminate the subthreads. _terminate = true; _copyPing.Set(); _pipePing.Set(); _copyThread.Join(); _pipeThread.Join(); // Close FFmpeg subprocess. _subprocess.StandardInput.Close(); _subprocess.WaitForExit(); var outputReader = _subprocess.StandardError; var error = outputReader.ReadToEnd(); _subprocess.Close(); _subprocess.Dispose(); outputReader.Close(); outputReader.Dispose(); // Nullify members (just for ease of debugging). _subprocess = null; _copyThread = null; _pipeThread = null; _copyQueue = null; _pipeQueue = _freeBuffer = null; return error; } #endregion #region IDisposable implementation public void Dispose() { if (!_terminate) CloseAndGetOutput(); } ~FFmpegPipe() { if (!_terminate) UnityEngine.Debug.LogError( "An unfinalized FFmpegPipe object was detected. " + "It should be explicitly closed or disposed " + "before being garbage-collected." ); } #endregion #region Private members Process _subprocess; Thread _copyThread; Thread _pipeThread; AutoResetEvent _copyPing = new AutoResetEvent(false); AutoResetEvent _copyPong = new AutoResetEvent(false); AutoResetEvent _pipePing = new AutoResetEvent(false); AutoResetEvent _pipePong = new AutoResetEvent(false); bool _terminate; Queue<NativeArray<byte>> _copyQueue = new Queue<NativeArray<byte>>(); Queue<byte[]> _pipeQueue = new Queue<byte[]>(); Queue<byte[]> _freeBuffer = new Queue<byte[]>(); public static string ExecutablePath { get { var basePath = UnityEngine.Application.streamingAssetsPath; var platform = UnityEngine.Application.platform; if (platform == UnityEngine.RuntimePlatform.OSXPlayer || platform == UnityEngine.RuntimePlatform.OSXEditor) return basePath + "/FFmpegOut/macOS/ffmpeg"; if (platform == UnityEngine.RuntimePlatform.LinuxPlayer || platform == UnityEngine.RuntimePlatform.LinuxEditor) return basePath + "/FFmpegOut/Linux/ffmpeg"; return basePath + "/FFmpegOut/Windows/ffmpeg.exe"; } } #endregion #region Subthread entry points // CopyThread - Copies frames given from the readback queue to the pipe // queue. This is required because readback buffers are not under our // control -- they'll be disposed before being processed by us. They // have to be buffered by end-of-frame. void CopyThread() { while (!_terminate) { // Wait for ping from the main thread. _copyPing.WaitOne(); // Process all entries in the copy queue. while (_copyQueue.Count > 0) { // Retrieve an copy queue entry without dequeuing it. // (We don't want to notify the main thread at this point.) NativeArray<byte> source; lock (_copyQueue) source = _copyQueue.Peek(); // Try allocating a buffer from the free buffer list. byte[] buffer = null; if (_freeBuffer.Count > 0) lock (_freeBuffer) buffer = _freeBuffer.Dequeue(); // Copy the contents of the copy queue entry. if (buffer == null || buffer.Length != source.Length) buffer = source.ToArray(); else source.CopyTo(buffer); // Push the buffer entry to the pipe queue. lock (_pipeQueue) _pipeQueue.Enqueue(buffer); _pipePing.Set(); // Ping the pipe thread. // Dequeue the copy buffer entry and ping the main thread. lock (_copyQueue) _copyQueue.Dequeue(); _copyPong.Set(); } } } // PipeThread - Receives frame entries from the copy thread and push // them into the FFmpeg pipe. void PipeThread() { var pipe = _subprocess.StandardInput.BaseStream; while (!_terminate) { // Wait for the ping from the copy thread. _pipePing.WaitOne(); // Process all entries in the pipe queue. while (_pipeQueue.Count > 0) { // Retrieve a frame entry. byte[] buffer; lock (_pipeQueue) buffer = _pipeQueue.Dequeue(); // Write it into the FFmpeg pipe. try { pipe.Write(buffer, 0, buffer.Length); pipe.Flush(); } catch { // Pipe.Write could raise an IO exception when ffmpeg // is terminated for some reason. We just ignore this // situation and assume that it will be resolved in the // main thread. #badcode } // Add the buffer to the free buffer list to reuse later. lock (_freeBuffer) _freeBuffer.Enqueue(buffer); _pipePong.Set(); } } } #endregion } } 这个有录制视频的方法吗
10-23
【事件触发一致性】研究多智能体网络如何通过分布式事件驱动控制实现有限时间内的共识(Matlab代码实现)内容概要:本文围绕多智能体网络中的事件触发一致性问题,研究如何通过分布式事件驱动控制实现有限时间内的共识,并提供了相应的Matlab代码实现方案。文中探讨了事件触发机制在降低通信负担、提升系统效率方面的优势,重点分析了多智能体系统在有限时间收敛的一致性控制策略,涉及系统模型构建、触发条件设计、稳定性与收敛性分析等核心技术环节。此外,文档还展示了该技术在航空航天、电力系统、机器人协同、无人机编队等多个前沿领域的潜在应用,体现了其跨学科的研究价值和工程实用性。; 适合人群:具备一定控制理论基础和Matlab编程能力的研究生、科研人员及从事自动化、智能系统、多智能体协同控制等相关领域的工程技术人员。; 使用场景及目标:①用于理解和实现多智能体系统在有限时间内达成一致的分布式控制方法;②为事件触发控制、分布式优化、协同控制等课题提供算法设计与仿真验证的技术参考;③支撑科研项目开发、学术论文复现及工程原型系统搭建; 阅读建议:建议结合文中提供的Matlab代码进行实践操作,重点关注事件触发条件的设计逻辑与系统收敛性证明之间的关系,同时可延伸至其他应用场景进行二次开发与性能优化。
【四旋翼无人机】具备螺旋桨倾斜机构的全驱动四旋翼无人机:建模与控制研究(Matlab代码、Simulink仿真实现)内容概要:本文围绕具备螺旋桨倾斜机构的全驱动四旋翼无人机展开,重点研究其动力学建模与控制系统设计。通过Matlab代码与Simulink仿真实现,详细阐述了该类无人机的运动学与动力学模型构建过程,分析了螺旋桨倾斜机构如何提升无人机的全向机动能力与姿态控制性能,并设计相应的控制策略以实现稳定飞行与精确轨迹跟踪。文中涵盖了从系统建模、控制器设计到仿真验证的完整程,突出了全驱动结构相较于传统四旋翼在欠驱动问题上的优势。; 适合人群:具备一定控制理论基础和Matlab/Simulink使用经验的自动化、航空航天及相关专业的研究生、科研人员或无人机开发工程师。; 使用场景及目标:①学习全驱动四旋翼无人机的动力学建模方法;②掌握基于Matlab/Simulink的无人机控制系统设计与仿真技术;③深入理解螺旋桨倾斜机构对飞行性能的影响及其控制实现;④为相关课题研究或工程开发提供可复现的技术参考与代码支持。; 阅读建议:建议读者结合提供的Matlab代码与Simulink模型,逐步跟进文档中的建模与控制设计步骤,动手实践仿真过程,以加深对全驱动无人机控制原理的理解,并可根据实际需求对模型与控制器进行修改与优化。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值