简体   繁体   English

WebRTC:在JavaScript和本机代码对等之间同步视频帧

[英]WebRTC: Synchronize video frames between JavaScript and Native Code peers

It follows the design I'm trying to implement a proper way: I have a JavaScript peer that is sending a video track to a Native Code peer. 它遵循我尝试实现正确方法的设计:我有一个JavaScript对等方,正在将视频轨道发送到Native Code对等方。 At some point during the transmission (actually immediately after the connection has been established, but it could be at any moment) I want to start a stopwatch on JS peer side and perform some temporized operations, actually some rendering on a canvas overlaying the video playback. 在传输过程中的某个时刻(实际上是在建立连接后立即,但是可能随时会出现),我想在JS对等端启动一个秒表并执行一些临时化的操作,实际上是在画布上进行一些渲染以覆盖视频播放。 On Native peer side I want to be able to synchronize on the instant the stopwatch started on JS peer, and consider only received frames recorded after that instant, performing some other kind of processing. 在本机对等端,我希望能够在秒表从JS对等点开始的瞬间进行同步,并只考虑该瞬间之后记录的接收帧,并执行其他某种处理。 What I am doing now (fragile and limiting solution): 我现在正在做什么(脆弱且有限的解决方案):

  • As soon as the peers connect, tracking RTCPeerConnection.iceConnectionState , I start the stopwatch on the JS peer; 一旦对等连接,跟踪RTCPeerConnection.iceConnectionState ,我就在JS对等上启动秒表;
  • As soon as the first webrtc::VideoFrame arrives on the Native peer I store the frame timespam; 当第一个webrtc::VideoFrame到达本地对等体时,我就存储帧时间垃圾邮件;
  • On Native peer I use first frame timestamp to compute relative time in a similar way the stopwatch allows me on JS peer. 在本机对等方上,我使用第一帧时间戳来计算相对时间,秒表允许我在JS对等方上使用。

This design is limiting because I may want to synchronize on any instant, not just on peers connection establishment, and also fragile because I think the WebRTC protocol is allowed to drop the very first received frames for any reason (delays or transmission errors). 这种设计是有局限性的,因为我可能想在任何时刻进行同步,而不仅是在对等方的连接建立上,而且还很脆弱,因为我认为WebRTC协议由于任何原因(延迟或传输错误)都被允许丢弃最早接收到的帧。 Ideally I would like to take a timestamp at the chosen synchronization point in the JS peer, send it to the Native peer and be able to compare webrtc::VideoFrame timestamps. 理想情况下,我想在JS对等体中选定的同步点处添加一个时间戳记,将其发送到本机对等体,并能够比较webrtc::VideoFrame时间戳记。 I am unable to do it naively because VideoFrame::timestamp_us() is clearly skewed by some amount I am not aware of. 我无法天真地执行此操作,因为VideoFrame::timestamp_us()明显偏向了一些我不知道的程度。 Also I can't interpret VideoFrame::timestamp() , which is poorly documented in api/video/video_frame.h , VideoFrame::ntp_time_ms() is deprecated and actually always return -1 . 我也无法解释VideoFrame::timestamp() ,该文件在api/video/video_frame.h很少记录,但不推荐使用VideoFrame::ntp_time_ms() ,并且实际上总是返回-1 What I should do to accomplish this kind of synchronization between the two peers? 我应该怎么做才能实现两个同级之间的这种同步?

The design can be properly implemented by sending synchronization event timestamps in NTP sender time to the receiver. 通过将NTP 发送方时间中的同步事件时间戳发送给接收方,可以正确地实现该设计。 The receiver then must be able to estimate sender NTP timestamps on the frames, comparing it to the the the timestamp of the synchronization event. 然后,接收者必须能够估计帧上的发送者NTP时间戳,并将其与同步事件的时间戳进行比较。 A Proof of concept patch enabling this method exists and has been pushed to Native WebRTC project in this tracking issue . 支持此方法的概念证明补丁已存在,并且在此跟踪问题中已推送到Native WebRTC项目。 More details to come later. 稍后会有更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM