WO2019056203A1 - 一种低延时音视频传输方法、装置及计算机可读存储介质 - Google Patents

一种低延时音视频传输方法、装置及计算机可读存储介质 Download PDF

Info

Publication number
WO2019056203A1
WO2019056203A1 PCT/CN2017/102438 CN2017102438W WO2019056203A1 WO 2019056203 A1 WO2019056203 A1 WO 2019056203A1 CN 2017102438 W CN2017102438 W CN 2017102438W WO 2019056203 A1 WO2019056203 A1 WO 2019056203A1
Authority
WO
WIPO (PCT)
Prior art keywords
audio
monitoring client
socket
completion port
video
Prior art date
Application number
PCT/CN2017/102438
Other languages
English (en)
French (fr)
Inventor
王海龙
Original Assignee
深圳市海能通信股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市海能通信股份有限公司 filed Critical 深圳市海能通信股份有限公司
Priority to CN201780009046.1A priority Critical patent/CN108702486B/zh
Priority to PCT/CN2017/102438 priority patent/WO2019056203A1/zh
Publication of WO2019056203A1 publication Critical patent/WO2019056203A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N7/00Television systems
    • H04N7/18Closed-circuit television [CCTV] systems, i.e. systems in which the video signal is not broadcast
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms

Definitions

  • the present invention relates to the field of data communication transmission technologies, and in particular, to a low-latency audio and video transmission method, apparatus, and computer readable storage medium.
  • the security monitoring system is based on digital network as the transmission medium and network video server core. It comprehensively uses digital video processing technology, automatic control, network transmission technology and artificial intelligence. It not only has fast video processing capability, digital information anti-interference ability, It is convenient for quick query and record, and relies on the network to take advantage of the broadband network.
  • IP network Through the IP network, the monitoring video center and any point that can connect to the network are interconnected to achieve the ideal remote, centralized, closed-circuit monitoring system. Real-time effects. Since the all-digital network video centralized monitoring mode is based on the characteristics of the network, there is no need to increase equipment investment.
  • the remote or local monitoring center on the network can monitor, record or arbitrarily play back one or more monitoring scenes in real time, and the authorized networked computer can also realize The monitoring function avoids the inconvenience and lack of supervision and management caused by geographical location.
  • the monitoring client and the server generally use network communication based on TCP/IP, and the program is written by using the Socket communication programming interface.
  • the goal is to establish a communication connection using the client/server model between different machines in the network where TCP/IP is set up.
  • the basic steps in the client to use TCP/IP and Socket communication programming are: 1 Declare a socket type variable, you need to provide the local IP address and communication port in the variable definition and specify the protocol type. Since TCP/IP-based socket communication is introduced here, the protocol type should be TCP/IP. In the programming interface, this type is represented by AF-INET.
  • the server-side communication software enters the state of waiting for the client connection, and if the connection is received, the other party
  • the connection request acquires the IP address and communication port of the other party, and sends a response signal to the other party that the connection is successful.
  • the "multi-thread synchronization" communication method is that when the network operation is performed, the main thread is suspended, and the main thread waits for the network operation to be completed before continuing to execute the subsequent code, that is, either executing the main thread or performing network operations;
  • a thread is generally established by corresponding to each monitoring client, so that switching between threads consumes a large amount of CPU resources. Therefore, the existing security monitoring system is transmitted during the audio and video data network. Due to the limitation of the maximum number of connections and the blocking problem when multi-thread synchronization, a delay defect occurs.
  • the main purpose of the present invention is to provide a low-latency audio and video transmission method, device and computer
  • the readable storage medium is designed to solve the technical problem that the existing security monitoring system generates delays in the transmission of audio and video data networks.
  • the present invention provides a low-latency audio and video transmission method, the method comprising the following steps:
  • the Socket of the monitoring client is bound to the completion port
  • the specific steps of binding the monitoring client Socket to the completion port include:
  • the method further includes:
  • the next audio-video communication request is delivered.
  • step of receiving the network connection request of the monitoring client specifically includes:
  • a Socket for listening is created, bound to the completion port, and the network connection request of the client is monitored on the designated completion port.
  • step of receiving the network connection request of the monitoring client specifically includes:
  • step of receiving the network connection request of the monitoring client specifically includes:
  • a low-latency audio and video transmission apparatus including a processor, a memory, and a data bus;
  • the data bus is used to implement connection communication between the processor and the memory
  • the processor is configured to execute a low-latency audio and video transmission program stored in the memory to implement the following steps:
  • the Socket of the monitoring client is bound to the completion port
  • another aspect of the present invention provides a computer readable storage medium having a low latency audio and video transmission program stored thereon, the low latency audio and video transmission program being The steps of the low-latency audio and video transmission method described above are implemented when the processor executes.
  • the low-latency audio and video transmission method and device and the computer-readable storage medium provided by the present invention establish a plurality of worker threads in advance by completing a port, firstly avoiding thread context switching, because when the thread wants to execute, there is always CPU resources are available, then let these threads wait, wait until there is
  • the audio and video communication request of the monitoring client comes, the audio and video communication requests are added to a common message queue, and then the worker threads are queued to retrieve the message from the message queue and process it.
  • Asynchronous communication and load balancing problems using multi-worker process automatic adjustment technology, effectively improve the number of concurrent connections; using the completion port asynchronous call AcceptEx function, using event-triggered non-blocking asynchronous model, reducing the delay of data forwarding time.
  • FIG. 1 is a flow chart of a first low-latency audio and video transmission method according to an embodiment of the present invention
  • FIG. 2 is a flow chart of a second low-rate audio and video transmission method according to an embodiment of the present invention
  • FIG. 3 is a structural block diagram of a first low-latency audio and video transmission apparatus according to an embodiment of the present invention.
  • FIG. 4 is a schematic flowchart of a program for monitoring client access by using an accept method
  • FIG. 5 is a schematic flowchart of a program for monitoring client access by using an AcceptEx method
  • an embodiment of the present invention provides a low-latency audio and video transmission method, where the method includes the following steps:
  • the specific steps of establishing multiple worker threads by using the main thread include:
  • the specific steps of binding the monitoring client Socket to the completion port when the monitoring client communicates with the server include:
  • a second low-latency audio and video transmission method includes the following steps:
  • S202 Establish, by the main thread, multiple worker threads, for processing an audio and video communication request, to implement communication with the client.
  • the step of receiving the network connection request of the monitoring client specifically includes:
  • a Socket for listening is created, bound to the completion port, and the network connection request of the client is monitored on the designated completion port.
  • the step of receiving the network connection request of the monitoring client specifically includes:
  • the step of receiving the network connection request of the monitoring client specifically includes:
  • the hardware structure of the low-delay audio and video transmission device provided by the embodiment of the present invention, specifically, the low-interval audio and video transmission device 30 includes at least a processor 31, a memory 32, and a data bus 33.
  • the data bus 33 is used to implement connection communication between the processor 31 and the memory 32.
  • the memory 32 is a computer readable storage medium that can store at least one computer program that can be read, compiled, and executed by the processor 31. To achieve the corresponding processing flow.
  • the memory 32 is a computer readable storage medium in which a low-delay audio and video transmission program is stored, which is executable by the processor 31 to implement the following steps of the low-latency audio and video transmission method. :
  • the Socket of the monitoring client is bound to the completion port
  • Embodiment 1 the low-latency audio and video transmission method of Embodiment 1 is based on the same inventive concept, and the present embodiment
  • the low-latency audio and video transmission program in the low-latency audio and video transmission device can also perform and implement the other low-latency audio and video transmission method steps involved in the first embodiment, and thus will not be described in detail in this embodiment.
  • another aspect of the present invention provides a computer readable storage medium having a low latency audio and video transmission program stored thereon, the low latency audio and video transmission program being The steps of the low-latency audio and video transmission method described above are implemented when the processor executes.
  • the schematic diagram of the process adopting the accept mode and the schematic diagram of the process adopting the AcceptEx method are respectively performed, and the specific program steps include:
  • I submit a network request on the Socket, such as WSARecv(), and then the system performs the operation of receiving data; at this time, several pre-established Worker threads call the GetQueuedCompletionStatus() function respectively.
  • a request for audio and video communication in the message queue of the scan completion port for example, reading data, sending data, etc.
  • the request is retrieved from the message queue of the completion port, and the subsequent processing in this thread is continued.
  • the request for the next network communication is continued, and the loop is repeated.
  • _AcceptThread() is responsible for accessing the connection, and the connected Socket is bound to the completion port.
  • the other _WorkerThread() is responsible for monitoring the situation on the completed port. If there is a situation, it is taken out. Processing, if the CPU has multiple cores, it can be rotated by multiple worker threads. To process the information on the completed port.
  • Figure 5 cancels the accept mode of the blocking mode, that is, AcceptEx is also done asynchronously by completing the port, so the thread dedicated to the accept connection is canceled, and the completion port is used for the asynchronous AcceptEx call;
  • the Worker function that retrieves the completed port queue, according to the type of the completion operation delivered by the user, the Accept request of the delivery is found and processed accordingly.
  • AcceptEx is to complete the client's Socket before the client connects, that is, AcceptEx is the first Socket, and then the AcceptEx call is issued.
  • Sockets are built in advance; there is no need to build a Socket on site instead of accepting it after the client is connected.
  • a blocking method can be used to establish an access portal. For a large number of concurrent clients, it is crowded; and AcceptEx can simultaneously deliver multiple requests on the completion port, so that when the client is connected, it can be calm. Process the connection request.
  • the low-latency audio and video transmission method and device and the computer-readable storage medium provided by the present invention establish a plurality of worker threads in advance by completing a port, firstly avoiding thread context switching, because when the thread wants to execute, there is always CPU resources are available, and then let these threads wait, and when the audio and video communication request of the monitoring client comes, the audio and video communication requests are added to a common message queue, and then these worker threads
  • the queue is used to retrieve the message from the message queue and process it.
  • the problem of asynchronous communication and load balancing is realized.
  • the technology of automatic adjustment by multi-worker process is adopted to effectively increase the number of concurrent connections.
  • the AcceptEx function is called asynchronously by using the completion port.
  • the event-triggered non-blocking asynchronous model reduces the delay time for data forwarding.
  • the foregoing embodiment method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be through hardware, but in many cases, the former is better.
  • Implementation Based on such understanding, the technical solution of the present invention, which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a storage medium (such as ROM/RAM, disk,
  • the optical disc includes a number of instructions for causing a terminal device (which may be a cell phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the methods described in various embodiments of the present invention.

Abstract

本发明公开了一种低延时音视频传输方法、装置及计算机可读存储介质,旨在解决现有安防监控系统在音视频数据网络传输产生延时的技术问题。该方法包括以下步骤:通过主线程创建一完成端口,并保存所述完成端口的句柄;通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。

Description

一种低延时音视频传输方法、装置及计算机可读存储介质 技术领域
本发明涉及数据通讯传输技术领域,尤其涉及一种低延时音视频传输方法、装置及计算机可读存储介质。
背景技术
安防监控系统是以数字网络为传输介质、网络视频服务器核心,综合全面的使用数字视频处理技术、自动控制、网络传输技术和人工智能等技术,不仅有快速视频处理能力、数字信息抗干扰能力、便于快速查询记录等优点,而且依托网络,发挥宽带网络带来的优势,通过IP网络,把监控视频中心和能够连接网络的任何一个点进行互联结合,达到理想的闭路监控系统的远程、集中、实时效果。由于全数字化网络视频集中监控模式基于网络的特性,无须增加设备投资,网络上的远程或本地监控中心均可以实时监控、录像或任意回放一个或多个监控现场画面,授权的联网电脑也可以实现监控功能,避免了地理位置间隔原因造成监督管理的不便和缺位。
网络视频监控过程中,往往需要实现多个监控客户端和服务器之间的交互通信,监控客户端与服务器之间一般是采用利用基于TCP/IP进行网络通信,利用Socket通信编程接口编写程序,其目的是在TCP/IP所组建网络的不同机器之间利用客户/服务器模式建立通信连接。具体来说,在客户端利用基于TCP/IP和Socket通信编程的基本步骤是:①声明一个套接字类型的变量,需要在该变量定义中提供本机IP地址和通信端口并指明协议类型,由于在此介绍的是基于TCP/IP的套接字通信,因此协议类型应该是TCP/IP,在编程接口中该类型用AF-INET来表示;②向对方发出连接请求,连接时 编程者需要提供对方TCP/IP地址和通信端口,同Socket实现程序自动向对提供本机TCP/IP地址和通信端口;③如果连接成功,会收到对方的应答信号,通信就可以通过套接字的相关操作来实现。利用Socket来实现服务器端通信软件的步骤是:①声明一个套接字类型的变量,需要在该变量定义中提供本机IP地址和通信端口并指明协议类型,由于在此介绍的是基于TCP/IP的套接字通信,因此协议类型应该是TCP/IP,在编程接口中该类型用AF-INET来表示;②服务器端通信软件进入等待客户端连接的状态,如果收到连接,则从对方连接请求中获取对方的IP地址和通信端口,并向对方发送连接成功的应答信号。
但是现有的Socket高并发技术多数还是采用多线程的同步技术,在进行高并发TCP连接处理时,最高的并发数量都要受到系统对用户单一进程同时可打开文件数量的限制(这是因为系统为每个TCP连接都要创建一个Socket句柄,每个Socket句柄同时也是一个文件句柄)。例如,每个进程最多允许同时打开1024个文件,这1024个文件中还得除去每个进程必然打开的标准输入,标准输出,标准错误,服务器监听Socket,进程间通讯的unix域Socket等文件,那么剩下的可用于客户端Socket连接的文件数就只有大概1024-10=1014个左右。也就是说缺省情况下,基于Linux的通讯程序最多允许同时1014个TCP并发连接。“多线程同步”的通信方式是在进行网络操作的时候,主线程被挂起,主线程要等待网络操作完成之后,才能继续执行后续的代码,就是说要么执行主线程,要么执行网络操作;为了处理多个监控客户端的通信请求,一般通过对应每一监控客户端建立一线程,这样线程之间的切换将消耗大量的CPU资源,因此,现有的安防监控系统在音视频数据网络传输时,受最大连接数的限制问题和多线程同步时的阻塞问题,从而产生了延时缺陷。
发明内容
本发明的主要目的在于提出一种低延时音视频传输方法、装置及计算机 可读存储介质,旨在解决现有安防监控系统在音视频数据网络传输产生延时的技术问题。
为实现上述目的,本发明提供的一种低延时音视频传输方法,该方法包括以下步骤:
通过主线程创建一完成端口,并保存所述完成端口的句柄;
通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;
当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
进一步的,所述通过所述主线程建立多个工作者线程的具体步骤包括:
查询并获得所述服务器的CPU数量,对应所述CPU数量建立相同数量的所述工作者线程或者对应所述CUP数量建立两倍数量的所述工作者线程。
进一步的,所述当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定的具体步骤包括:
接收所述监控客户端的网络连接请求,将所述监控客户端的Socket中的设备句柄与所述完成端口进行绑定,并反馈一接收网络数据包的请求。
进一步的,所述从所述消息队列中调取并处理所述音视频通信请求的步骤之后,还包括:
所述工作者线程根据所述音视频通信请求执行后续线程后,在投递下一所述音视频通信请求。
进一步的,所述接收所述监控客户端的网络连接请求的步骤具体包括:
创建一用于监听的Socket,绑定到所述完成端口上,在指定所述完成端口上监听所述客户端的网络连接请求。
进一步的,所述接收所述监控客户端的网络连接请求的步骤具体包括:
创建一监听线程,利用Accept函数以普通阻塞方式接收所述监控客户端的Socket的网络连接请求,并把连入的所述Socket和所述完成端口绑定;
进一步的,所述接收所述监控客户端的网络连接请求的步骤具体包括:
通过所述完成端口异步调用AcceptEx函数接收所述监控客户端的Socket的网络连接请求,并把连入的所述Socket和所述完成端口绑定。
基于同一发明构思,本发明的另一方面,提供了一种低延时音视频传输装置,所述低延时音视频传输装置包括处理器、存储器及数据总线;
所述数据总线用于实现处理器和存储器之间的连接通信;
所述处理器用于执行存储器中存储的低延时音视频传输程序,以实现以下步骤:
通过主线程创建一完成端口,并保存所述完成端口的句柄;
通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;
当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
基于同一发明构思,本发明的另一方面,提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有低延时音视频传输程序,所述低延时音视频传输程序被处理器执行时实现上述的低延时音视频传输方法的步骤。
本发明技术方案的有益效果:
本发明提供的低延时音视频传输方法、装置及计算机可读存储介质,通过完成端口来事先建立多个工作者线程,首先是避免了线程的上下文切换,因为线程想要执行时,总有CPU资源可用,然后让这几个线程等着,等到有 监控客户端的音视频通信请求来到时,就把这些音视频通信请求都加入到一个公共消息队列中去,然后这几个工作者线程就排队逐一去从消息队列中取出消息并加以处理,实现了异步通信和负载均衡的问题,采用多工作者进程自动调节的技术,有效的提高并发连接数;采用完成端口异步调用AcceptEx函数,利用事件触发的非阻塞异步模型,缩小了数据转发的延时时间。
附图说明
图1为本发明实施例提供的第一种低延时音视频传输方法流程框图;
图2为本发明实施例提供的第二种低延时音视频传输方法流程框图;
图3为本发明实施例提供的第一种低延时音视频传输装置结构框图;
图4为采用accept方式进行监控客户端接入的程序流程示意图;
图5为采用AcceptEx方式进行监控客户端接入的程序流程示意图;
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。
在后续的描述中,使用用于表示元件的诸如“模块”、“部件”或“单元”的后缀仅为了有利于本发明的说明,其本身没有特定的意义。因此,“模块”、“部件”或“单元”可以混合地使用。
实施例1
如图1所示,本发明实施例提供了一种低延时音视频传输方法,该方法包括以下步骤:
S101、通过主线程创建一完成端口,并保存所述完成端口的句柄;
S102、通过所述主线程建立多个工作者线程,用于处理音视频通信请求, 实现与客户端通信;
S103、当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
S104、通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
其中,所述通过所述主线程建立多个工作者线程的具体步骤包括:
查询并获得所述服务器的CPU数量,对应所述CPU数量建立相同数量的所述工作者线程或者对应所述CUP数量建立两倍数量的所述工作者线程。
其中,所述当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定的具体步骤包括:
接收所述监控客户端的网络连接请求,将所述监控客户端的Socket中的设备句柄与所述完成端口进行绑定,并反馈一接收网络数据包的请求。
如图2所示,本发明实施提供的第二种低延时音视频传输方法,该方法包括以下步骤:
S201、通过主线程创建一完成端口,并保存所述完成端口的句柄;
S202、通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;
S203、当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
S204、通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
S205、所述工作者线程根据所述音视频通信请求执行后续线程后,在投递下一所述音视频通信请求。
其中,所述接收所述监控客户端的网络连接请求的步骤具体包括:
创建一用于监听的Socket,绑定到所述完成端口上,在指定所述完成端口上监听所述客户端的网络连接请求。
其中,所述接收所述监控客户端的网络连接请求的步骤具体包括:
创建一监听线程,利用Accept函数以普通阻塞方式接收所述监控客户端的Socket的网络连接请求,并把连入的所述Socket和所述完成端口绑定;
其中,所述接收所述监控客户端的网络连接请求的步骤具体包括:
通过所述完成端口异步调用AcceptEx函数接收所述监控客户端的Socket的网络连接请求,并把连入的所述Socket和所述完成端口绑定。
实施例2
如图3所示,本发明实施例提供的一种低延时音视频传输装置硬件结构,具体地,所述低延时音视频传输装置30至少包括处理器31、存储器32以及数据总线33。数据总线33用于实现处理器31和存储器32之间的连接通信,存储器32作为一种计算机可读存储介质,可以存储至少一个计算机程序,这些计算机程序可供处理器31读取、编译并执行,从而实现对应的处理流程。在本实施例中,存储器32作为一种计算机可读存储介质,其中存储有低延时音视频传输程序,该程序可供处理器31执行,从而实现如下的低延时音视频传输方法的步骤:
通过主线程创建一完成端口,并保存所述完成端口的句柄;
通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;
当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
另外,与实施例1的低延时音视频传输方法基于同一发明构思,本实施 的低延时音视频传输装置中的低延时音视频传输程序还能够执行并实现实施例1所涉及的其他低延时音视频传输方法步骤,故本实施例不再赘述。
实施例3
基于同一发明构思,本发明的另一方面,提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有低延时音视频传输程序,所述低延时音视频传输程序被处理器执行时实现上述的低延时音视频传输方法的步骤。
如图4、5所示,分别是采用accept方式的流程示意图和采用AcceptEx方式的流程示意图,具体程序步骤包括:
调用CreateIoCompletionPort()函数创建一个完成端口,而且在一般情况下,我们需要且只需要建立这一个完成端口,把它的句柄保存好。
根据系统中有多少个CPU处理器,就建立多少个工作者(Worker)线程,这几个线程是专门用来和监控客户端进行通信的;可以采用启动一个独立的监听线程,专门用来accept监控客户端的连接请求;或者利用性能更高更好的异步AcceptEx()请求。
每当有监控客户端连入的时候,再次调用CreateIoCompletionPort()函数,把新连入的Socket(也就是前面的设备句柄),与目前的完成端口绑定在一起。
例如,监控客户端连入之后,我在这个Socket上提交一个网络请求,例如WSARecv(),然后系统去执行接收数据的操作;而此时,预先建立的几个Worker线程分别调用GetQueuedCompletionStatus()函数在扫描完成端口的消息队列里是否有音视频通信的请求存在(例如读取数据,发送数据等),若是则将这个请求从完成端口的消息队列中取回来,继续执行本线程中后面的处理代码,处理完毕之后,再继续投递下一个网络通信的请求,如此循环。
图4中是由_AcceptThread()负责接入连接,并把连入的Socket和完成端口绑定,另外的多个_WorkerThread()就负责监控完成端口上的情况,一旦有情况,就取出来处理,如果CPU有多核的话,就可以多个工作者线程轮着 来处理完成端口上的信息。
图5中取消了阻塞方式的accept调用,也就是说,AcceptEx也是通过完成端口来异步完成的,所以就取消了专门用于accept连接的线程,用了完成端口来进行异步的AcceptEx调用;然后在检索完成端口队列的Worker函数中,根据用户投递的完成操作的类型,再来找出其中的投递的Accept请求,加以对应的处理。
AcceptEx是在客户端连入之前,就把客户端的Socket建立完成,也就是说,AcceptEx是先建立的Socket,然后才发出的AcceptEx调用,在进行客户端的通信之前,无论是否有客户端连入,Socket都是提前建立完成;而不需要像accept是在客户端连入了之后,再现场去建立Socket。
相比accept只能阻塞方式建立一个连入的入口,对于大量的并发客户端来讲,显得拥挤;而AcceptEx可以同时在完成端口上投递多个请求,这样有客户端连入的时候,能从容不迫的处理连入请求。
在投递AcceptEx时,可以顺便在AcceptEx的同时,收取客户端发来的第一组数据,这个是同时进行的,收到AcceptEx完成的通知时,已经把这第一组数据接完毕;但是,如果客户端只是连入但是不发送数据时,就不会收到这个AcceptEx完成的通知。
本发明提供的低延时音视频传输方法、装置及计算机可读存储介质,通过完成端口来事先建立多个工作者线程,首先是避免了线程的上下文切换,因为线程想要执行时,总有CPU资源可用,然后让这几个线程等着,等到有监控客户端的音视频通信请求来到时,就把这些音视频通信请求都加入到一个公共消息队列中去,然后这几个工作者线程就排队逐一去从消息队列中取出消息并加以处理,实现了异步通信和负载均衡的问题,采用多工作者进程自动调节的技术,有效的提高并发连接数;采用完成端口异步调用AcceptEx函数,利用事件触发的非阻塞异步模型,缩小了数据转发的延时时间。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。
上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本发明各个实施例所述的方法。
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。

Claims (9)

  1. 一种低延时音视频传输方法,其特征在于,所述方法包括以下步骤:
    通过主线程创建一完成端口,并保存所述完成端口的句柄;
    通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;
    当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
    通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
  2. 根据权利要求1所述的一种低延时音视频传输方法,其特征在于,所述通过所述主线程建立多个工作者线程的具体步骤包括:
    查询并获得所述服务器的CPU数量,对应所述CPU数量建立相同数量的所述工作者线程或者对应所述CUP数量建立两倍数量的所述工作者线程。
  3. 根据权利要求1所述的一种低延时音视频传输方法,其特征在于,所述当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定的具体步骤包括:
    接收所述监控客户端的网络连接请求,将所述监控客户端的Socket中的设备句柄与所述完成端口进行绑定,并反馈一接收网络数据包的请求。
  4. 根据权利要求1所述的一种低延时音视频传输方法,其特征在于,所述从所述消息队列中调取并处理所述音视频通信请求的步骤之后,还包括:
    所述工作者线程根据所述音视频通信请求执行后续线程后,在投递下一所述音视频通信请求。
  5. 根据权利要求3所述的一种低延时音视频传输方法,其特征在于,所述接收所述监控客户端的网络连接请求的步骤具体包括:
    创建一用于监听的Socket,绑定到所述完成端口上,在指定所述完成端 口上监听所述客户端的网络连接请求。
  6. 根据权利要求3所述的一种低延时音视频传输方法,其特征在于,所述接收所述监控客户端的网络连接请求的步骤具体包括:
    创建一监听线程,利用Accept函数以普通阻塞方式接收所述监控客户端的Socket的网络连接请求,并把连入的所述Socket和所述完成端口绑定;
  7. 根据权利要求3所述的一种低延时音视频传输方法,其特征在于,所述接收所述监控客户端的网络连接请求的步骤具体包括:
    通过所述完成端口异步调用AcceptEx函数接收所述监控客户端的Socket的网络连接请求,并把连入的所述Socket和所述完成端口绑定。
  8. 一种低延时音视频传输装置,其特征在于,所述低延时音视频传输装置包括处理器、存储器及数据总线;
    所述数据总线用于实现处理器和存储器之间的连接通信;
    所述处理器用于执行存储器中存储的低延时音视频传输程序,以实现以下步骤:
    通过主线程创建一完成端口,并保存所述完成端口的句柄;
    通过所述主线程建立多个工作者线程,用于处理音视频通信请求,实现与客户端通信;
    当监控客户端与服务器进行通信时,将监控客户端的Socket与所述完成端口进行绑定;
    通过所述Socket向所述服务器提交音视频通信请求,所述工作者线程扫描所述完成端口的消息队列,从所述消息队列中调取并处理所述音视频通信请求。
  9. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有低延时音视频传输程序,所述低延时音视频传输程序被处理器执行时实现如权利要求1-7任一项所述的低延时音视频传输方法的步骤。
PCT/CN2017/102438 2017-09-20 2017-09-20 一种低延时音视频传输方法、装置及计算机可读存储介质 WO2019056203A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201780009046.1A CN108702486B (zh) 2017-09-20 2017-09-20 一种低延时音视频传输方法、装置及计算机可读存储介质
PCT/CN2017/102438 WO2019056203A1 (zh) 2017-09-20 2017-09-20 一种低延时音视频传输方法、装置及计算机可读存储介质

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2017/102438 WO2019056203A1 (zh) 2017-09-20 2017-09-20 一种低延时音视频传输方法、装置及计算机可读存储介质

Publications (1)

Publication Number Publication Date
WO2019056203A1 true WO2019056203A1 (zh) 2019-03-28

Family

ID=63844102

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/102438 WO2019056203A1 (zh) 2017-09-20 2017-09-20 一种低延时音视频传输方法、装置及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN108702486B (zh)
WO (1) WO2019056203A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111901689A (zh) * 2020-06-17 2020-11-06 视联动力信息技术股份有限公司 流媒体数据的传输方法、装置、终端设备和存储介质

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109688424A (zh) * 2018-12-29 2019-04-26 深圳中移视讯技术有限公司 视音频数据传输方法、执法采集工作站及可读存储介质
CN109814996B (zh) * 2019-01-04 2024-03-22 平安科技(深圳)有限公司 流媒体传输控制方法、装置及存储介质、计算机设备
CN110380991A (zh) * 2019-07-24 2019-10-25 成都甄识科技有限公司 一种IOCP机制及基于eFPGA和IOCP的物联网通信加速系统
CN110442442B (zh) * 2019-08-13 2022-07-26 中核控制系统工程有限公司 核电厂dcs平台工程师站软件维护网络通讯方法
CN110798450B (zh) * 2019-09-25 2022-08-23 视联动力信息技术股份有限公司 一种音视频数据的处理方法、装置及存储介质
CN112114955B (zh) * 2020-09-28 2021-05-14 广州锦行网络科技有限公司 Windows平台下实现单进程单线程完成端口的方法
CN112631788B (zh) * 2021-01-06 2023-11-28 上海哔哩哔哩科技有限公司 数据传输方法及数据传输服务器
CN113992637B (zh) * 2021-09-10 2024-04-09 广州极飞科技股份有限公司 音视频数据接收方法、装置、设备、系统和存储介质

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101159747A (zh) * 2007-11-12 2008-04-09 中兴通讯股份有限公司 一种基于tcp并发多链路的通信系统及其方法
CN201590870U (zh) * 2009-11-17 2010-09-22 上海途锐信息技术有限公司 基于3g网络的视频实时传输系统
CN101982955A (zh) * 2010-11-19 2011-03-02 深圳华大基因科技有限公司 高性能文件传输系统及方法
CN102314382A (zh) * 2010-07-06 2012-01-11 中兴通讯股份有限公司 一种紧急探查系统信息的方法及模块
CN103078905A (zh) * 2012-12-25 2013-05-01 泉州豪杰信息科技发展有限公司 一种gps终端的通讯管理方法
CN103391289A (zh) * 2013-07-16 2013-11-13 中船重工(武汉)凌久高科有限公司 一种基于完成端口模型的多链路安全通信方法
CN104917811A (zh) * 2015-04-16 2015-09-16 上海行践自行车科技发展有限公司 公共交通系统的车辆租赁信息的通信方法和通信系统
CN106603685A (zh) * 2016-12-23 2017-04-26 深圳市三维通机器人系统有限公司 基于大数据高并发通信的agv通信方法及其系统

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101159747A (zh) * 2007-11-12 2008-04-09 中兴通讯股份有限公司 一种基于tcp并发多链路的通信系统及其方法
CN201590870U (zh) * 2009-11-17 2010-09-22 上海途锐信息技术有限公司 基于3g网络的视频实时传输系统
CN102314382A (zh) * 2010-07-06 2012-01-11 中兴通讯股份有限公司 一种紧急探查系统信息的方法及模块
CN101982955A (zh) * 2010-11-19 2011-03-02 深圳华大基因科技有限公司 高性能文件传输系统及方法
CN103078905A (zh) * 2012-12-25 2013-05-01 泉州豪杰信息科技发展有限公司 一种gps终端的通讯管理方法
CN103391289A (zh) * 2013-07-16 2013-11-13 中船重工(武汉)凌久高科有限公司 一种基于完成端口模型的多链路安全通信方法
CN104917811A (zh) * 2015-04-16 2015-09-16 上海行践自行车科技发展有限公司 公共交通系统的车辆租赁信息的通信方法和通信系统
CN106603685A (zh) * 2016-12-23 2017-04-26 深圳市三维通机器人系统有限公司 基于大数据高并发通信的agv通信方法及其系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
CHEN LINGLING: "Design and implementation of public bicycle rental system service platform based on IOCP and JSON", 2014 INTERNATIONAL CONFERENCE ON APPLIED SCIENCES, ENGINEERING AND TECHNO- LOGY (ICASET, 30 July 2014 (2014-07-30) *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111901689A (zh) * 2020-06-17 2020-11-06 视联动力信息技术股份有限公司 流媒体数据的传输方法、装置、终端设备和存储介质

Also Published As

Publication number Publication date
CN108702486B (zh) 2020-08-04
CN108702486A (zh) 2018-10-23

Similar Documents

Publication Publication Date Title
WO2019056203A1 (zh) 一种低延时音视频传输方法、装置及计算机可读存储介质
CN106161537B (zh) 远程过程调用的处理方法、装置、系统及电子设备
US9277030B2 (en) Stream processing using a client-server architecture
US8732709B2 (en) Transaction management in a web service messaging environment
US20070033284A1 (en) System server for data processing with multiple clients and a data processing method
CN108270732A (zh) 一种流媒体处理方法及系统
CN108055311B (zh) Http异步请求方法、装置、服务器、终端和存储介质
US20170034311A1 (en) Method for selecting between multiple RPC frameworks during a TCP/IP session
US10177975B2 (en) Method and apparatus of performing remote management of a managed machine
WO2021226781A1 (zh) 防火墙规则的更新方法、装置、服务器及存储介质
CN109327511A (zh) 一种基于http协议的数据请求方法和服务器
US20180302486A1 (en) Proxy apparatus and method for data collection
WO2019061636A1 (zh) 调用系统工具的方法、装置、可读存储介质及设备
CN112395242B (zh) 多芯片控制方法、装置、电子设备和计算机可读存储介质
CN108259605B (zh) 一种基于多数据中心的数据调用系统及方法
WO2023231681A1 (zh) 账号创建方法、物联网多租户系统、设备、程序和介质
WO2020119608A1 (zh) 基于Spark Shuffle的远程直接内存访问系统及方法
CN113965628A (zh) 消息调度方法、服务器和存储介质
CN107819855A (zh) 一种消息分发方法及装置
CN102693434B (zh) 射频识别设备接口层的通信装置及方法
WO2020259326A1 (zh) 一种信号传输方法及装置
US20120191772A1 (en) Processing a unit of work
CN111555950B (zh) 报文处理方法、装置、服务器和存储介质
CN112738153A (zh) 业务系统中的网关选择方法、系统、装置、服务器及介质
WO2020047829A1 (zh) 一种基于netconf的数据处理方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17925895

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 07/09/2020)

122 Ep: pct application non-entry in european phase

Ref document number: 17925895

Country of ref document: EP

Kind code of ref document: A1