简体   繁体   English

TCP流:音频/视频同步

[英]TCP-Streaming: Audio/Video Synchronization

I have a question regarding TCP/Live-Streaming/Synchronization (programming language: Java): 我对TCP /实时流式传输/同步有疑问(编程语言:Java):

Let's say I have a Client, that is capturing the Audio and Video from a camera. 假设我有一个客户端,它正在从摄像机捕获音频和视频。 It is sending the audio and video data simultaneously (via Threads) via TCP-sockets to a server, that is receiving the audio and video stream simultaneously on two different threads. 它通过TCP套接字同时(通过线程)将音频和视频数据发送到服务器,该服务器在两个不同的线程上同时接收音频和视频流。

[I know, UDP is normally used for live-streaming applications but there are reasons, why I'm using TCP..] [我知道,UDP通常用于实时流应用程序,但是出于某些原因,我为什么要使用TCP。

So, the question is: Will there be any chance to get out of sync ever via TCP? 因此,问题是:是否有机会通过TCP失去同步? There are two streams on different sockets (one for audio, one for video), there may be a problem, that a packet has to be re-sent, but will the resend of the lost-packet be a problem (I mean, when resending a packet via TCP, will this cause a permanent delay or will the client just send the lost packet and the next packet faster for a few milliseconds)? 在不同的套接字上有两个流(一个用于音频,一个用于视频),可能存在一个问题,必须重新发送一个数据包,但是丢失数据包的重新发送会成为问题(我的意思是,当通过TCP重新发送数据包,这会导致永久性的延迟,还是客户端将丢失的数据包和下一个数据包更快地发送几毫秒)?

I'm sending the audio and video signal at the same time to the server. 我要同时将音频和视频信号发送到服务器。 Will they always arrive at the same time on the server? 他们将始终同时到达服务器上吗? If not, is there a way to produce/simulate the problem? 如果没有,是否有办法产生/模拟问题?

I've done some tests and the audio and video was always in sync. 我已经进行了一些测试,并且音频和视频始终保持同步。 But I'm not sure, if it will always be like that (even after more than 5 hours of streaming). 但我不确定是否会一直这样(即使在流式传输超过5小时之后)。

Thank you. 谢谢。

If you use two different sockets, there's no guarantee. 如果您使用两个不同的插座,则无法保证。 TCP guarantees data transmission in the correct order, but if you use two different streams for audio and video, it doesn't apply. TCP保证以正确的顺序进行数据传输,但是如果您将两个不同的流用于音频和视频,则不适用。

However, if the connection is fast enough there shouldn't be a problem. 但是,如果连接足够快,就不会有问题。 It sends it as fast as it can. 它以最快的速度发送。 If one stream gets "clogged up" though, it will delay and fall out of sync, but I doubt that would happen with your case for sending videos (as long as it's not too high an FPS or resolution). 但是,如果一个流“阻塞”,它将延迟并失去同步,但是我怀疑这种情况会在您发送视频的情况下发生(只要它不是FPS或分辨率太高)。

I think it would be safer to use a single stream, but I think your way is fine to be honest. 我认为使用单个流会更安全,但是老实说,我认为您的方法很好。 It all depends on: speed of the client, speed of the server, and speed of the network. 这完全取决于:客户端的速度,服务器的速度和网络的速度。

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

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