[go: up one dir, main page]

CN118972695A - Camera interaction method, system and server - Google Patents

Camera interaction method, system and server Download PDF

Info

Publication number
CN118972695A
CN118972695A CN202411442250.0A CN202411442250A CN118972695A CN 118972695 A CN118972695 A CN 118972695A CN 202411442250 A CN202411442250 A CN 202411442250A CN 118972695 A CN118972695 A CN 118972695A
Authority
CN
China
Prior art keywords
camera
virtual
data
physical
server
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202411442250.0A
Other languages
Chinese (zh)
Inventor
张作宸
卢伟
周勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianjin Zhuolang Kunlun Cloud Software Technology Co ltd
Original Assignee
Tianjin Zhuolang Kunlun Cloud Software Technology Co ltd
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 Tianjin Zhuolang Kunlun Cloud Software Technology Co ltd filed Critical Tianjin Zhuolang Kunlun Cloud Software Technology Co ltd
Priority to CN202411442250.0A priority Critical patent/CN118972695A/en
Publication of CN118972695A publication Critical patent/CN118972695A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/66Remote control of cameras or camera parts, e.g. by remote control devices
    • H04N23/661Transmitting camera control signals through networks, e.g. control via the Internet
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/42Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by implementation details or hardware specially adapted for video compression or decompression, e.g. dedicated software implementation
    • H04N19/423Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by implementation details or hardware specially adapted for video compression or decompression, e.g. dedicated software implementation characterised by memory arrangements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/44Decoders specially adapted therefor, e.g. video decoders which are asymmetric with respect to the encoder

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)

Abstract

本发明提供了一种摄像头交互方法、系统及服务器,涉及摄像头交互领域,该方案通过在客户端设置的编码器对物理摄像头采集的原始数据进行编码压缩后,减少了网络带宽的压力;并通过服务端中额外设置的虚拟摄像头,实现了物理摄像头和虚拟机之间的解耦,进一步降低了虚拟机虚拟总线的带宽压力,从而有效缓解现有技术中虚拟机在网络状态不佳时导致的应用程序显示画面断层,闪屏或卡顿等情况。

The present invention provides a camera interaction method, system and server, and relates to the field of camera interaction. The scheme reduces the pressure of network bandwidth by encoding and compressing the original data collected by the physical camera through an encoder arranged on the client; and realizes the decoupling between the physical camera and the virtual machine through a virtual camera additionally arranged in the server, further reducing the bandwidth pressure of the virtual bus of the virtual machine, thereby effectively alleviating the problems of application display screen faults, screen flashing or freeze caused by the virtual machine in the prior art when the network status is not good.

Description

摄像头交互方法、系统及服务器Camera interaction method, system and server

技术领域Technical Field

本发明涉及摄像头交互领域,尤其是涉及一种摄像头交互方法、系统及服务器。The present invention relates to the field of camera interaction, and in particular to a camera interaction method, system and server.

背景技术Background Art

目前基于网络的摄像头交互方案大都采用重定向转发方式,具体的说,客户端主机连接物理摄像头,通过网络传输该摄像头的相关信息至相应的服务端,再通过服务端设置的虚拟总线转发到虚拟机中。当虚拟机内的相关应用程序需要使用摄像头时,通过视频代理驱动即可使用物理摄像头采集的视频数据,进而显示其录制的视频画面。At present, most of the network-based camera interaction solutions adopt the redirection forwarding method. Specifically, the client host connects to the physical camera, transmits the relevant information of the camera to the corresponding server through the network, and then forwards it to the virtual machine through the virtual bus set by the server. When the relevant application in the virtual machine needs to use the camera, the video proxy driver can use the video data collected by the physical camera to display the recorded video screen.

该方案利用物理摄像头采集的原始数据包,通过各协议的封装解包等操作,从而完成虚拟端与物理端之间的摄像头交互过程。但此类方案需要较高的网络带宽,在物理摄像头数量较多的情况下会导致虚拟总线的压力较大,尤其是在网络状态不佳时会导致虚拟机中的应用程序显示画面断层、闪屏或卡顿。This solution uses the original data packets collected by the physical camera and completes the camera interaction process between the virtual end and the physical end through operations such as encapsulation and unpacking of various protocols. However, this solution requires a higher network bandwidth, which will cause greater pressure on the virtual bus when there are a large number of physical cameras, especially when the network status is poor, which will cause the application display in the virtual machine to be disconnected, flicker or freeze.

发明内容Summary of the invention

有鉴于此,本发明的目的在于提供一种摄像头交互方法、系统及服务器,通过在客户端设置的编码器对物理摄像头采集的原始数据进行编码压缩后,减少了网络带宽的压力;并通过服务端中额外设置的虚拟摄像头,实现了物理摄像头和虚拟机之间的解耦,进一步降低了虚拟机虚拟总线的带宽压力,从而有效缓解现有技术中虚拟机在网络状态不佳时导致的应用程序显示画面断层,闪屏或卡顿等情况。In view of this, the purpose of the present invention is to provide a camera interaction method, system and server, which reduces the pressure on network bandwidth by encoding and compressing the original data collected by the physical camera through an encoder set on the client; and through the virtual camera additionally set in the server, the decoupling between the physical camera and the virtual machine is achieved, and the bandwidth pressure of the virtual bus of the virtual machine is further reduced, thereby effectively alleviating the problems of application display screen faults, screen flashing or freezes caused by the virtual machine in the prior art when the network status is not good.

第一方面,本发明实施方式提供了一种摄像头交互方法,该方法应用于包含虚拟端和物理端的服务器中,虚拟端设置有虚拟机以及虚拟摄像头;物理端包括:客户端主机、物理摄像头和编码器;编码器的输入端通过客户端主机连接物理摄像头,编码器的输出端经过服务器的服务端与虚拟摄像头的输入端相连接;虚拟摄像头的输出端与虚拟机相连接;In a first aspect, an embodiment of the present invention provides a camera interaction method, which is applied to a server including a virtual end and a physical end, wherein the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, and the output end of the encoder is connected to the input end of the virtual camera through the server end; the output end of the virtual camera is connected to the virtual machine;

该方法包括:The method includes:

基于物理摄像头与编码器所在客户端之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,并利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接;Generate enumerated device data corresponding to the virtual camera based on the device connection parameters between the physical camera and the client where the encoder is located, and use the virtual connection instruction generated by the enumerated device data to control the virtual camera to complete the connection with the virtual machine;

当监测到虚拟机发出的摄像头请求指令后,根据摄像头请求指令生成虚拟摄像头对应的视频请求指令,并控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据;When a camera request instruction issued by the virtual machine is detected, a video request instruction corresponding to the virtual camera is generated according to the camera request instruction, and after the server is controlled to send the video request instruction to the physical camera, callback data of the physical camera is received in real time;

利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,并控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据;The callback data is encoded by an encoder to obtain the video stream data corresponding to the physical camera, and the virtual camera is controlled to generate the video response data corresponding to the camera request instruction based on the video stream data;

控制服务端将视频响应数据发送至虚拟机中。The control server sends the video response data to the virtual machine.

在一种实施方式中,基于物理摄像头与编码器所在客户端之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,包括:In one implementation, generating enumerated device data corresponding to a virtual camera based on device connection parameters between a physical camera and a client where an encoder is located includes:

基于提供物理摄像头工作环境的客户端主机与编码器所在客户端之间的连接状态参数,获取物理摄像头与编码器所在客户端之间的设备连接参数;Based on the connection status parameters between the client host providing the physical camera working environment and the client where the encoder is located, the device connection parameters between the physical camera and the client where the encoder is located are obtained;

当检测到物理摄像头处于已插入客户端主机的状态时,基于设备连接参数控制虚拟摄像头向物理摄像头发送设备描述符请求指令,并实时接收物理摄像头响应的设备描述符;When it is detected that the physical camera is in a state of being inserted into the client host, the virtual camera is controlled to send a device descriptor request instruction to the physical camera based on the device connection parameters, and the device descriptor of the physical camera response is received in real time;

控制虚拟摄像头向物理摄像头发送配置描述符请求指令,并实时接收物理摄像头响应的配置描述符;Control the virtual camera to send a configuration descriptor request instruction to the physical camera, and receive the configuration descriptor responded by the physical camera in real time;

利用设备描述符和配置描述符生成枚举设备数据。Generates enumerated device data using device descriptors and configuration descriptors.

在一种实施方式中,利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接,包括:In one embodiment, the virtual connection instruction generated by enumerating device data is used to control the virtual camera to complete the connection with the virtual machine, including:

将枚举设备数据中包含的设备描述符、配置描述符、接口描述符、端点描述符、视频头描述符、终端描述符、处理单元描述符、视频帧描述符上述一种或多种描述符数据缓存至虚拟摄像头的存储单元;Cache one or more descriptor data of a device descriptor, a configuration descriptor, an interface descriptor, an endpoint descriptor, a video head descriptor, a terminal descriptor, a processing unit descriptor, and a video frame descriptor contained in the enumerated device data to a storage unit of the virtual camera;

控制服务端从存储单元中获取描述符数据,并利用描述符数据生成虚拟摄像头对应的设备加载指令;The control server obtains the descriptor data from the storage unit, and generates a device loading instruction corresponding to the virtual camera using the descriptor data;

利用设备加载指令控制虚拟摄像头加载至虚拟机中并执行连接处理。The device loading instruction is used to control the virtual camera to be loaded into the virtual machine and perform connection processing.

在一种实施方式中,控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据,包括:In one implementation, after the control server sends the video request instruction to the physical camera, the callback data of the physical camera is received in real time, including:

基于视频请求指令获取对应的物理摄像头;Obtain the corresponding physical camera based on the video request instruction;

控制服务端将视频请求指令发送至对应的物理摄像头,并控制物理摄像头根据视频请求指令实时采集并获取视频流数据;The control server sends the video request instruction to the corresponding physical camera, and controls the physical camera to collect and obtain video stream data in real time according to the video request instruction;

将视频流数据按照虚拟摄像头的格式需求进行转化后,控制物理摄像头将已完成格式转化的视频流数据作为回调数据发送至服务端;After converting the video stream data according to the format requirements of the virtual camera, the physical camera is controlled to send the video stream data that has completed the format conversion as callback data to the server;

控制服务端实时接收物理摄像头发送的回调数据。Control the server to receive callback data sent by the physical camera in real time.

在一种实施方式中,利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,包括:In one implementation, the callback data is encoded by an encoder to obtain video stream data corresponding to the physical camera, including:

基于回调数据获取物理摄像头对应的初始数据;其中,初始数据为YUV编码数据;Based on the callback data, the initial data corresponding to the physical camera is obtained; wherein the initial data is YUV encoded data;

控制编码器对初始数据进行编码转换后,得到转换编码数据;其中,转换编码数据为H265、H264、MJPEG上述一种或多种编码数据;After controlling the encoder to perform encoding conversion on the initial data, converted encoded data is obtained; wherein the converted encoded data is one or more encoded data of H265, H264, MJPEG, etc.;

根据转换编码数据生成物理摄像头对应的视频流数据。Generate video stream data corresponding to the physical camera based on the converted encoded data.

在一种实施方式中,控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据,包括:In one implementation, controlling the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data includes:

判断虚拟摄像头的预设存储区中是否包含视频流数据对应的历史数据;Determine whether the preset storage area of the virtual camera contains historical data corresponding to the video stream data;

如果是,则基于历史数据生成视频响应数据;如果否,则基于视频流数据生成视频响应数据,并将视频响应数据作为历史数据保存至存储区中。If yes, then the video response data is generated based on the historical data; if no, then the video response data is generated based on the video stream data, and the video response data is saved in the storage area as historical data.

在一种实施方式中,当检测到虚拟机发出的摄像头关闭指令后,该方法还包括:In one embodiment, after detecting a camera closing instruction issued by the virtual machine, the method further includes:

控制虚拟机向虚拟摄像头发送第一关闭指令,并利用第一关闭指令控制虚拟摄像头处于关闭状态;Control the virtual machine to send a first closing instruction to the virtual camera, and use the first closing instruction to control the virtual camera to be in a closed state;

控制服务端向物理摄像头发送第二关闭指令,并利用第二关闭指令控制物理摄像头处于关闭状态。The control server sends a second shutdown instruction to the physical camera, and uses the second shutdown instruction to control the physical camera to be in a closed state.

在一种实施方式中,当检测到物理摄像头处于离线状态时,该方法还包括:In one embodiment, when it is detected that the physical camera is in an offline state, the method further includes:

控制服务端生成虚拟摄像头对应的关闭指令,并控制服务端将关闭指令发送至虚拟机中。The control server generates a close instruction corresponding to the virtual camera, and controls the server to send the close instruction to the virtual machine.

第二方面,本发明实施方式提供一种摄像头交互系统,该系统应用于包含虚拟端和物理端的服务器中,虚拟端设置有虚拟机以及虚拟摄像头;物理端包括:客户端主机、物理摄像头和编码器;编码器的输入端通过客户端主机连接物理摄像头,编码器的输出端经过服务器的服务端与虚拟摄像头的输入端相连接;虚拟摄像头的输出端与虚拟机相连接;In a second aspect, an embodiment of the present invention provides a camera interaction system, which is applied to a server including a virtual end and a physical end, wherein the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, and the output end of the encoder is connected to the input end of the virtual camera through the server end; the output end of the virtual camera is connected to the virtual machine;

该系统包括:The system includes:

连接交互模块,用于基于物理摄像头与编码器所在客户端之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,并利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接;A connection interaction module is used to generate enumerated device data corresponding to the virtual camera based on the device connection parameters between the physical camera and the client where the encoder is located, and use the virtual connection instructions generated by the enumerated device data to control the virtual camera to complete the connection with the virtual machine;

指令交互模块,用于当监测到虚拟机发出的摄像头请求指令后,根据摄像头请求指令生成虚拟摄像头对应的视频请求指令,并控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据;The instruction interaction module is used to generate a video request instruction corresponding to the virtual camera according to the camera request instruction after monitoring the camera request instruction issued by the virtual machine, and control the server to send the video request instruction to the physical camera, and receive the callback data of the physical camera in real time;

数据交互模块,用于利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,并控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据;The data interaction module is used to encode the callback data using an encoder to obtain the video stream data corresponding to the physical camera, and control the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data;

视频交互模块,用于控制服务端将视频响应数据发送至虚拟机中。The video interaction module is used to control the server to send video response data to the virtual machine.

第三方面,本发明实施方式还提供一种服务器,该服务器包含虚拟端和物理端,虚拟端设置有虚拟机以及虚拟摄像头;物理端包括:客户端主机、物理摄像头和编码器;编码器的输入端通过客户端主机连接物理摄像头,编码器的输出端经过服务器的服务端与虚拟摄像头的输入端相连接;虚拟摄像头的输出端与虚拟机相连接;In a third aspect, an embodiment of the present invention further provides a server, the server comprising a virtual end and a physical end, the virtual end being provided with a virtual machine and a virtual camera; the physical end comprising: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera via the client host, the output end of the encoder is connected to the input end of the virtual camera via the server end; the output end of the virtual camera is connected to the virtual machine;

服务器在对虚拟摄像头与物理摄像头的视频数据交互过程中,采用上述第一方面中提到的摄像头交互方法的步骤。During the process of video data interaction between the virtual camera and the physical camera, the server adopts the steps of the camera interaction method mentioned in the first aspect above.

第四方面,本发明实施方式还提供一种电子设备,包括处理器和存储器,存储器存储有能够被处理器执行的计算机可执行指令,处理器执行计算机可执行指令以实现第一方面提供的摄像头交互方法的步骤。In a fourth aspect, an embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the steps of the camera interaction method provided in the first aspect.

第五方面,本发明实施方式还提供一种存储介质,该存储介质存储有计算机可执行指令,计算机可执行指令在被处理器调用和执行时,计算机可执行指令促使处理器实现第一方面提供的摄像头交互方法的步骤。In a fifth aspect, an embodiment of the present invention further provides a storage medium, which stores computer executable instructions. When the computer executable instructions are called and executed by a processor, the computer executable instructions prompt the processor to implement the steps of the camera interaction method provided in the first aspect.

本发明实施方式提供的一种摄像头交互方法、系统及服务器,应用于包含虚拟端和物理端的服务器中,虚拟端设置有虚拟机以及虚拟摄像头;物理端包括:客户端主机、物理摄像头和编码器;编码器的输入端通过客户端主机连接物理摄像头,编码器的输出端经过服务器的服务端与虚拟摄像头的输入端相连接;虚拟摄像头的输出端与虚拟机相连接。在对虚拟摄像头与物理摄像头的视频数据交互过程中,该方法首先基于物理摄像头与编码器所在客户端之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,并利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接;当监测到虚拟机发出的摄像头请求指令后,根据摄像头请求指令生成虚拟摄像头对应的视频请求指令,并控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据;然后利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,并控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据;最后控制服务端将视频响应数据发送至虚拟机中。该方案通过在客户端设置的编码器对物理摄像头采集的原始数据进行编码压缩后,减少了网络带宽的压力;并通过服务端中额外设置的虚拟摄像头,实现了物理摄像头和虚拟机之间的解耦,进一步降低了虚拟机虚拟总线的带宽压力,从而有效缓解现有技术中虚拟机在网络状态不佳时导致的应用程序显示画面断层,闪屏或卡顿等情况。A camera interaction method, system and server provided by the embodiment of the present invention are applied to a server including a virtual end and a physical end, wherein the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, and the output end of the encoder is connected to the input end of the virtual camera through the server end of the server; the output end of the virtual camera is connected to the virtual machine. In the process of video data interaction between the virtual camera and the physical camera, the method first generates enumerated device data corresponding to the virtual camera based on the device connection parameters between the physical camera and the client where the encoder is located, and uses the virtual connection instruction generated by the enumerated device data to control the virtual camera and the virtual machine to complete the connection; when the camera request instruction issued by the virtual machine is monitored, a video request instruction corresponding to the virtual camera is generated according to the camera request instruction, and after controlling the server end to send the video request instruction to the physical camera, the callback data of the physical camera is received in real time; then the callback data is encoded by the encoder to obtain the video stream data corresponding to the physical camera, and the virtual camera is controlled to generate the video response data corresponding to the camera request instruction based on the video stream data; finally, the server end is controlled to send the video response data to the virtual machine. This solution reduces the pressure on network bandwidth by encoding and compressing the raw data collected by the physical camera through an encoder set up on the client; and through the additional virtual camera set up on the server, it achieves decoupling between the physical camera and the virtual machine, further reducing the bandwidth pressure of the virtual machine's virtual bus, thereby effectively alleviating the problems of application display interruptions, screen flashing or freezing caused by the virtual machine in the existing technology when the network status is poor.

本发明的其他特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本发明而了解。本发明的目的和其他优点在说明书、权利要求书以及附图中所特别指出的结构来实现和获得。Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.

为使本发明的上述目的、特征和优点能更明显易懂,下文特举较佳实施例,并配合所附附图,作详细说明如下。In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

为了更清楚地说明本发明具体实施方式或现有技术中的技术方案,下面将对具体实施方式或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施方式,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

图1为本发明实施例提供的一种摄像头交互方法的流程图;FIG1 is a flow chart of a camera interaction method provided by an embodiment of the present invention;

图2为本发明实施例提供的一种摄像头交互方法中,基于物理摄像头与编码器之间的设备连接参数生成虚拟摄像头对应的枚举设备数据的流程图;FIG2 is a flow chart of generating enumerated device data corresponding to a virtual camera based on device connection parameters between a physical camera and an encoder in a camera interaction method provided by an embodiment of the present invention;

图3为本发明实施例提供的一种摄像头交互方法中,利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接的流程图;3 is a flow chart of controlling a virtual camera to complete connection with a virtual machine by using a virtual connection instruction generated by enumerating device data in a camera interaction method provided by an embodiment of the present invention;

图4为本发明实施例提供的一种摄像头交互方法中,控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据的流程图;FIG4 is a flow chart of a camera interaction method provided by an embodiment of the present invention, in which a control server sends a video request instruction to a physical camera and then receives callback data of the physical camera in real time;

图5为本发明实施例提供的一种摄像头交互方法中,利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据的流程图;FIG5 is a flow chart of obtaining video stream data corresponding to a physical camera after encoding callback data using an encoder in a camera interaction method provided by an embodiment of the present invention;

图6为本发明实施例提供的一种摄像头交互方法中,控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据的流程图;6 is a flow chart of controlling a virtual camera to generate video response data corresponding to a camera request instruction based on video stream data in a camera interaction method provided by an embodiment of the present invention;

图7为本发明实施例提供的一种摄像头交互方法中,当检测到虚拟机发出的摄像头关闭指令后的流程图;FIG7 is a flow chart of a camera interaction method provided by an embodiment of the present invention, when a camera closing instruction issued by a virtual machine is detected;

图8为本发明实施例提供的一种摄像头交互方法的交互流程图;FIG8 is an interaction flow chart of a camera interaction method provided by an embodiment of the present invention;

图9为本发明实施例提供的一种摄像头交互系统的结构示意图;FIG9 is a schematic structural diagram of a camera interaction system provided by an embodiment of the present invention;

图10为本发明实施例提供的一种服务器的结构示意图;FIG10 is a schematic diagram of the structure of a server provided in an embodiment of the present invention;

图11为本发明实施例提供的一种电子设备的结构示意图。FIG. 11 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

图标:icon:

910-连接交互模块;920-指令交互模块;930-数据交互模块;940-视频交互模块;910-connection interaction module; 920-command interaction module; 930-data interaction module; 940-video interaction module;

10-虚拟端;10a-虚拟机;10b-虚拟摄像头;10-virtual terminal; 10a-virtual machine; 10b-virtual camera;

20-物理端;20a-客户端主机;20b-物理摄像头;20c-编码器;20-physical end; 20a-client host; 20b-physical camera; 20c-encoder;

30-服务端;30-Server;

101-处理器;102-存储器;103-总线;104-通信接口。101 - processor; 102 - memory; 103 - bus; 104 - communication interface.

具体实施方式DETAILED DESCRIPTION

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合实施例对本发明的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described in combination with the embodiments below. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

目前基于网络的摄像头交互方案大都采用重定向转发方式,具体的说,客户端主机连接物理摄像头如USB接口摄像头,通过网络传输该摄像头的相关信息至相应的服务端,再通过服务端设置的USB虚拟总线转发到虚拟机中。当虚拟机内的相关应用程序需要使用摄像头时,通过视频代理驱动即可使用物理摄像头采集的视频数据,进而显示其录制的视频画面。At present, most of the network-based camera interaction solutions adopt the redirection forwarding method. Specifically, the client host connects to a physical camera, such as a USB interface camera, and transmits the relevant information of the camera to the corresponding server through the network, and then forwards it to the virtual machine through the USB virtual bus set by the server. When the relevant application in the virtual machine needs to use the camera, the video data collected by the physical camera can be used through the video proxy driver to display the recorded video screen.

以USB摄像头为例,此类方案利用USB摄像头采集的原始URB数据包,通过各协议的封装解包等操作,从而完成虚拟端与物理端之间的摄像头交互过程。由于URB包的数据量较大,需要较高的网络带宽,尤其是在USB摄像头数量较多的情况下会导致USB虚拟总线的压力较大。实际使用过程中,在网络状态不佳时会导致虚拟机中的应用程序显示画面断层、闪屏或卡顿,用户体验感较差。Taking USB cameras as an example, this type of solution uses the original URB data packets collected by the USB camera, and completes the camera interaction process between the virtual end and the physical end through operations such as encapsulation and unpacking of various protocols. Due to the large amount of data in the URB packet, a higher network bandwidth is required, especially when there are a large number of USB cameras, which will cause greater pressure on the USB virtual bus. In actual use, when the network status is poor, the application in the virtual machine will display screen faults, flashing or freezing, and the user experience will be poor.

基于此,本发明实施提供了一种摄像头交互方法、系统及服务器,通过在客户端设置的编码器对物理摄像头采集的原始数据进行编码压缩后,减少了网络带宽的压力;并通过服务端中额外设置的虚拟摄像头,实现了物理摄像头和虚拟机之间的解耦,进一步降低了虚拟机虚拟总线的带宽压力,有效缓解现有技术中虚拟机在网络状态不佳时导致的应用程序显示画面断层,闪屏或卡顿等情况,从而解决现有技术中存在的上述问题。Based on this, the present invention provides a camera interaction method, system and server, which reduces the pressure on network bandwidth by encoding and compressing the original data collected by the physical camera through an encoder set on the client; and through the virtual camera additionally set in the server, the decoupling between the physical camera and the virtual machine is achieved, further reducing the bandwidth pressure of the virtual machine's virtual bus, and effectively alleviating the problems of application display screen faults, screen flashing or freezes caused by the virtual machine in the prior art when the network status is not good, thereby solving the above-mentioned problems existing in the prior art.

为便于对本实施例进行理解,首先对本发明实施例所公开的一种摄像头交互方法,该方法应用于包含虚拟端和物理端的服务器中,虚拟端设置有虚拟机以及虚拟摄像头;物理端包括:客户端主机、物理摄像头和编码器;编码器的输入端通过客户端主机连接物理摄像头,编码器的输出端经过服务器的服务端与虚拟摄像头的输入端相连接;虚拟摄像头的输出端与虚拟机相连接;To facilitate understanding of this embodiment, first, a camera interaction method disclosed in an embodiment of the present invention is applied to a server including a virtual end and a physical end, wherein the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, and the output end of the encoder is connected to the input end of the virtual camera through the server end; the output end of the virtual camera is connected to the virtual machine;

如图1所示,该方法包括以下步骤:As shown in FIG1 , the method comprises the following steps:

步骤S101,基于物理摄像头与编码器所在客户端之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,并利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接;Step S101, generating enumerated device data corresponding to the virtual camera based on the device connection parameters between the physical camera and the client where the encoder is located, and controlling the virtual camera to complete the connection with the virtual machine using the virtual connection instruction generated by the enumerated device data;

步骤S102,当监测到虚拟机发出的摄像头请求指令后,根据摄像头请求指令生成虚拟摄像头对应的视频请求指令,并控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据;Step S102, when a camera request instruction issued by the virtual machine is monitored, a video request instruction corresponding to the virtual camera is generated according to the camera request instruction, and after the server is controlled to send the video request instruction to the physical camera, callback data of the physical camera is received in real time;

步骤S103,利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,并控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据;Step S103, using an encoder to encode the callback data to obtain video stream data corresponding to the physical camera, and controlling the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data;

步骤S104,控制服务端将视频响应数据发送至虚拟机中。Step S104, controlling the server to send the video response data to the virtual machine.

本实施例中的摄像头交互方法在结构层面上额外设置了编码器和虚拟摄像头,通过客户端主机将编码器与物理摄像头连接,并将虚拟摄像头与虚拟机连接,而编码器与虚拟摄像头之间通过网络传输线路与服务器的服务端相连接,从而实现了视频数据交互通道,用以实现具体的交互过程。The camera interaction method in this embodiment additionally sets up an encoder and a virtual camera at the structural level, connects the encoder to the physical camera through the client host, and connects the virtual camera to the virtual machine, and the encoder and the virtual camera are connected to the server end of the server through a network transmission line, thereby realizing a video data interaction channel to implement a specific interaction process.

具体的说,该方法包含了两类数据的交互,一类是基于物理摄像头与编码器所在客户端之间的设备连接参数生成的枚举设备数据,另一类就是通过编码器处理后的视频流数据。具体的说,枚举设备数据包含各类设备描述符,可通过此类数据来对交互指令进行设置;而视频流数据通过编码器的编码处理后进行精简,进而执行传输交互过程。Specifically, the method includes the interaction of two types of data, one is the enumerated device data generated based on the device connection parameters between the physical camera and the client where the encoder is located, and the other is the video stream data processed by the encoder. Specifically, the enumerated device data contains various device descriptors, which can be used to set the interaction instructions; and the video stream data is simplified after being encoded by the encoder, and then the transmission interaction process is performed.

该方法在得到枚举设备数据后,首先执行设备的连接过程,利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接,并可同时执行物理摄像头的连接过程,使其与编码器完成连接后能够通过服务端与虚拟摄像头进行交互。After obtaining the enumerated device data, the method first executes the device connection process, uses the virtual connection instruction generated by the enumerated device data to control the virtual camera to complete the connection with the virtual machine, and can simultaneously execute the connection process of the physical camera, so that after completing the connection with the encoder, it can interact with the virtual camera through the server.

当监测到虚拟机发出的摄像头请求指令后,首先根据该指令生成虚拟摄像头对应的视频请求指令,然后控制服务端将该指令发送至物理摄像头进行调用,并实时接收物理摄像头响应该指令时的回调数据。通俗的说,虚拟机请求与物理摄像头进行交互时,首先将该请求指令转化为虚拟摄像头的相关指令,此时在虚拟机一侧的虚拟摄像头执行触发;随后虚拟摄像头与物理摄像头进行关联处理,通过服务端将视频请求指令发送至物理摄像头,从而对物理摄像头进行调用。When the camera request command issued by the virtual machine is detected, the video request command corresponding to the virtual camera is first generated according to the command, and then the server is controlled to send the command to the physical camera for calling, and the callback data when the physical camera responds to the command is received in real time. In layman's terms, when the virtual machine requests to interact with the physical camera, the request command is first converted into the relevant command of the virtual camera, and the virtual camera on the virtual machine side is triggered at this time; then the virtual camera is associated with the physical camera, and the video request command is sent to the physical camera through the server, thereby calling the physical camera.

物理摄像头经过该指令的响应后,其视频流作为回调数据发送服务端,此时利用编码器对回调数据进行编码处理后得到物理摄像头对应的已压缩后的视频流数据,并在该视频流数据的基础上生成摄像头请求指令所对应的视频响应数据,最终发送至虚拟机中实现摄像头的交互过程。After the physical camera responds to the command, its video stream is sent to the server as callback data. At this time, the callback data is encoded by the encoder to obtain the compressed video stream data corresponding to the physical camera, and the video response data corresponding to the camera request command is generated based on the video stream data, and finally sent to the virtual machine to realize the camera interaction process.

在一种实施方式中,基于物理摄像头与编码器之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,如图2所示,包括:In one implementation, enumerated device data corresponding to a virtual camera is generated based on device connection parameters between a physical camera and an encoder, as shown in FIG2 , including:

步骤S201,基于提供物理摄像头工作环境的客户端主机与编码器所在客户端之间的连接状态参数,获取物理摄像头与编码器所在客户端之间的设备连接参数;Step S201, based on the connection status parameters between the client host providing the physical camera working environment and the client where the encoder is located, obtaining the device connection parameters between the physical camera and the client where the encoder is located;

步骤S202,当检测到物理摄像头处于已插入客户端主机的状态时,基于设备连接参数控制虚拟摄像头向物理摄像头发送设备描述符请求指令,并实时接收物理摄像头响应的设备描述符;Step S202, when it is detected that the physical camera is in a state of being inserted into the client host, the virtual camera is controlled based on the device connection parameters to send a device descriptor request instruction to the physical camera, and the device descriptor of the physical camera response is received in real time;

步骤S203,控制虚拟摄像头向物理摄像头发送配置描述符请求指令,并实时接收物理摄像头响应的配置描述符;Step S203, controlling the virtual camera to send a configuration descriptor request instruction to the physical camera, and receiving the configuration descriptor responded by the physical camera in real time;

步骤S204,利用设备描述符和配置描述符生成枚举设备数据。Step S204: Generate enumerated device data using the device descriptor and the configuration descriptor.

枚举设备数据本质上说使基于客户端主机与编码器所在客户端之间的连接状态参数所生成的,该阶段可理解为连接阶段。此时的物理摄像头需要与客户端主机相连接,客户端主机为实际存在的主机,内置有USB接口,物理摄像头通过USB接口插入至客户端主机从而实现连接。在获取枚举设备数据的过程中,首先基于获取物理摄像头与编码器之间的设备连接参数,进而判断物理摄像头是否插入至客户端主机。从客户端的角度上看,当客户端主机决定设备连接时,就执行获取枚举设备数据的步骤。此时基于设备连接参数向物理摄像头发送设备描述符请求指令,并实时接收物理摄像头响应的设备描述符;此外向物理摄像头发送配置描述符请求指令,并实时接收物理摄像头响应的配置描述符,进而利用获取的设备描述符和配置描述符生成所需的枚举设备数据。The enumerated device data is essentially generated based on the connection status parameters between the client host and the client where the encoder is located. This stage can be understood as the connection stage. At this time, the physical camera needs to be connected to the client host. The client host is an actual host with a built-in USB interface. The physical camera is inserted into the client host through the USB interface to achieve connection. In the process of obtaining the enumerated device data, firstly, the device connection parameters between the physical camera and the encoder are obtained, and then it is determined whether the physical camera is inserted into the client host. From the perspective of the client, when the client host decides to connect the device, the step of obtaining the enumerated device data is executed. At this time, a device descriptor request instruction is sent to the physical camera based on the device connection parameters, and the device descriptor responded by the physical camera is received in real time; in addition, a configuration descriptor request instruction is sent to the physical camera, and the configuration descriptor responded by the physical camera is received in real time, and then the required enumerated device data is generated using the obtained device descriptor and configuration descriptor.

在一种实施方式中,利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接,如图3所示,包括:In one embodiment, the virtual connection instruction generated by enumerating device data is used to control the virtual camera to complete the connection with the virtual machine, as shown in FIG3, including:

步骤S301,将枚举设备数据中包含的设备描述符、配置描述符、接口描述符、端点描述符、视频头描述符、终端描述符、处理单元描述符、视频帧描述符上述一种或多种描述符数据缓存至虚拟摄像头的存储单元;Step S301, caching one or more descriptor data of a device descriptor, a configuration descriptor, an interface descriptor, an endpoint descriptor, a video head descriptor, a terminal descriptor, a processing unit descriptor, and a video frame descriptor contained in the enumerated device data into a storage unit of the virtual camera;

步骤S302,控制服务端从存储单元中获取描述符数据,并利用描述符数据生成虚拟摄像头对应的设备加载指令;Step S302, controlling the server to obtain descriptor data from the storage unit, and using the descriptor data to generate a device loading instruction corresponding to the virtual camera;

步骤S303,利用设备加载指令控制虚拟摄像头加载至虚拟机中并执行连接处理。Step S303, using the device loading instruction to control the virtual camera to be loaded into the virtual machine and perform connection processing.

具体的说,连接阶段是虚拟摄像头数据准备阶段,它从客户端决定设备连接时开始,发送查询指令CMD_VCAM_CHECK,查看是否支持虚拟摄像头。当超时时间内(如3秒)没有回应,则不支持,否则虚拟摄像头请求设备描述符,此描述符描述设备的基本信息,如pid,vid等重要标识。待客户端回复后,继续请求设备的配置描述符信息,客户端回复配置描述符以及其所有子描述符,如接口描述符、端点描述符、VC、VS等各描述符信息。所有信息都将缓存在虚拟摄像头中,当这些信息准备完成后,虚拟摄像头以attach的方式插入到虚拟机上。此时虚拟机内可在设备管理器中查看到摄像头信息,到此连接阶段结束。Specifically, the connection phase is the virtual camera data preparation phase, which starts when the client decides to connect the device and sends the query command CMD_VCAM_CHECK to check whether the virtual camera is supported. If there is no response within the timeout (such as 3 seconds), it is not supported, otherwise the virtual camera requests the device descriptor, which describes the basic information of the device, such as pid, vid and other important identifiers. After the client responds, continue to request the device's configuration descriptor information, and the client responds with the configuration descriptor and all its sub-descriptors, such as interface descriptors, endpoint descriptors, VC, VS and other descriptor information. All information will be cached in the virtual camera. When this information is prepared, the virtual camera is inserted into the virtual machine in the attach mode. At this time, the camera information can be viewed in the device manager in the virtual machine, and this connection phase ends.

在一种实施方式中,控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据,如图4所示,包括:In one implementation, after the control server sends the video request instruction to the physical camera, the callback data of the physical camera is received in real time, as shown in FIG4 , including:

步骤S401,基于视频请求指令获取对应的物理摄像头;Step S401, obtaining a corresponding physical camera based on a video request instruction;

步骤S402,控制服务端将视频请求指令发送至对应的物理摄像头,并控制物理摄像头根据视频请求指令实时采集并获取视频流数据;Step S402, controlling the server to send the video request instruction to the corresponding physical camera, and controlling the physical camera to collect and obtain video stream data in real time according to the video request instruction;

步骤S403,将视频流数据按照虚拟摄像头的格式需求进行转化后,控制物理摄像头将已完成格式转化的视频流数据作为回调数据发送至服务端;Step S403, after converting the video stream data according to the format requirements of the virtual camera, the physical camera is controlled to send the video stream data that has completed the format conversion as callback data to the server;

步骤S404,控制服务端实时接收物理摄像头发送的回调数据。Step S404, controlling the server to receive the callback data sent by the physical camera in real time.

此时可简单理解为数据传输阶段,数据传输阶段是虚拟摄像头将数据以映射的方式传输到虚拟机的过程。首先基于视频请求指令来确定所对应的物理摄像头,然后在服务端的控制下将视频请求指令发送至所对应的物理摄像头中,使得物理视像头根据视频请求指令来执行工作,从而采集并得到视频流数据。This can be simply understood as the data transmission stage, which is the process of the virtual camera transmitting data to the virtual machine in a mapping manner. First, the corresponding physical camera is determined based on the video request instruction, and then the video request instruction is sent to the corresponding physical camera under the control of the server, so that the physical camera performs the work according to the video request instruction, thereby collecting and obtaining video stream data.

值得一提的是,获取的视频流数据的格式具有一定的需求,需要按照虚拟摄像头的格式需求进行转化,从而将完成格式化的视频流数据作为回调数据用于服务端的接收。具体的,在一种实施方式中,利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,如图5所示,包括:It is worth mentioning that the format of the acquired video stream data has certain requirements and needs to be converted according to the format requirements of the virtual camera, so that the formatted video stream data is used as callback data for reception by the server. Specifically, in one embodiment, the callback data is encoded by an encoder to obtain the video stream data corresponding to the physical camera, as shown in FIG5, including:

步骤S501,基于回调数据获取物理摄像头对应的初始数据;其中,初始数据为YUV编码数据;Step S501, obtaining initial data corresponding to the physical camera based on the callback data; wherein the initial data is YUV encoded data;

步骤S502,控制编码器对初始数据进行编码转换后,得到转换编码数据;其中,转换编码数据为H265、H264、MJPEG上述一种或多种编码数据;Step S502, controlling the encoder to perform encoding conversion on the initial data to obtain converted encoded data; wherein the converted encoded data is one or more encoded data of H265, H264, MJPEG, etc.;

步骤S503,根据转换编码数据生成物理摄像头对应的视频流数据。Step S503, generating video stream data corresponding to the physical camera according to the converted coded data.

在具体场景中,设备视频流数据即视频数据,此时不再需要从物理摄像头中拿传统的单包URB数据,而是从USB摄像头取一帧帧完整的yuv数据,在经过新增的编码器后,并根据虚拟机内的用户选择,编码成对应的编码数据(如:H265/H264/MJPEG)。当用户在虚拟机内控制相关应用程序打开摄像头时,虚拟摄像头会不断地向客户端请求数据帧。当检测到有来自USB摄像头的数据时,马上上报给虚拟机,虚拟机内软件即可看到视频画面。In specific scenarios, the device video stream data is the video data. At this time, it is no longer necessary to take the traditional single-packet URB data from the physical camera. Instead, the complete YUV data is taken from the USB camera frame by frame. After passing through the newly added encoder, it is encoded into the corresponding encoded data (such as H265/H264/MJPEG) according to the user's selection in the virtual machine. When the user controls the relevant application in the virtual machine to open the camera, the virtual camera will continuously request data frames from the client. When data from the USB camera is detected, it is immediately reported to the virtual machine, and the software in the virtual machine can see the video screen.

在一种实施方式中,控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据,如图6所示,包括:In one implementation, controlling the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data, as shown in FIG6 , includes:

步骤S601,判断虚拟摄像头的预设存储区中是否包含视频流数据对应的历史数据;Step S601, determining whether the preset storage area of the virtual camera contains historical data corresponding to the video stream data;

步骤S602,如果是,则基于历史数据生成视频响应数据;如果否,则基于视频流数据生成视频响应数据,并将视频响应数据作为历史数据保存至存储区中。Step S602: if yes, generate video response data based on the historical data; if no, generate video response data based on the video stream data, and save the video response data as historical data in the storage area.

实际场景中,可判断虚拟摄像头预设存储区中的每一帧数据的数据正确性,帧完整性以及是否过期。如果是过期数据,则丢弃。如果否,则基于视频流数据生成视频响应数据,并将视频响应数据保存至存储区,一旦虚拟机发出数据请求指令时,虚拟摄像头向虚拟总线地址提交存储区中最旧的一帧视频数据。In actual scenarios, the data correctness, frame integrity and expiration of each frame of data in the preset storage area of the virtual camera can be determined. If it is expired data, it is discarded. If not, video response data is generated based on the video stream data and saved to the storage area. Once the virtual machine issues a data request instruction, the virtual camera submits the oldest frame of video data in the storage area to the virtual bus address.

视频响应数据的获取过程可结合虚拟摄像头中是否包含响应的历史视频流数据来执行,具体的说在虚拟摄像头拿到数据后,等待虚拟机指令下发取数据,当虚拟机下发请求到来,在存储区中发现有对应的历史数据,即可将其映射到虚拟机内,从而虚拟机中的应用程序显示出画面。当虚拟摄像头的相关存储区内没有数据时,则马上请求并获取下一个视频响应数据,如此反复,达到播放视频的效果。The process of obtaining the video response data can be combined with whether the virtual camera contains the corresponding historical video stream data. Specifically, after the virtual camera obtains the data, it waits for the virtual machine to issue an instruction to obtain the data. When the virtual machine sends a request, it finds the corresponding historical data in the storage area and maps it to the virtual machine, so that the application in the virtual machine displays the picture. When there is no data in the relevant storage area of the virtual camera, it immediately requests and obtains the next video response data, and repeats this process to achieve the effect of playing the video.

在一种实施方式中,当检测到虚拟机发出的摄像头关闭指令后,如图7所示,该方法还包括:In one embodiment, after detecting a camera closing instruction issued by the virtual machine, as shown in FIG7 , the method further includes:

步骤S701,控制虚拟机向虚拟摄像头发送第一关闭指令,并利用第一关闭指令控制虚拟摄像头处于关闭状态;Step S701, controlling the virtual machine to send a first closing instruction to the virtual camera, and using the first closing instruction to control the virtual camera to be in a closed state;

步骤S702,控制服务端向物理摄像头发送第二关闭指令,并利用第二关闭指令控制物理摄像头处于关闭状态。Step S702, control the server to send a second closing instruction to the physical camera, and use the second closing instruction to control the physical camera to be in a closed state.

当用户在虚拟机内关闭摄像头时,首先控制虚拟机向虚拟摄像头发送第一关闭指令,从而关闭虚拟摄像头;进而控制服务端向物理摄像头发送第二关闭指令,从而关闭物理摄像头,整个过程的交互中,虚拟摄像头与物理摄像头完成直接交互。When the user turns off the camera in the virtual machine, the virtual machine is first controlled to send a first closing instruction to the virtual camera, thereby turning off the virtual camera; then the server is controlled to send a second closing instruction to the physical camera, thereby turning off the physical camera. During the entire interaction process, the virtual camera and the physical camera complete direct interaction.

在一种实施方式中,当检测到物理摄像头处于离线状态时,该方法还包括:控制服务端生成虚拟摄像头对应的关闭指令,并控制服务端将关闭指令发送至虚拟机中。In one embodiment, when it is detected that the physical camera is in an offline state, the method further includes: controlling the server to generate a shutdown instruction corresponding to the virtual camera, and controlling the server to send the shutdown instruction to the virtual machine.

断开连接阶段也是需要用户操作触发的阶段,是虚拟摄像头是否资源的过程。当用户断开摄像头连接或者拔掉摄像头时,客户端会发送断开摄像头指令到虚拟摄像头,虚拟摄像头拿到信息后从虚拟摄像头拔掉,虚拟机内将不再有任何摄像头相关的信息,同时虚拟摄像头会回收所有的内存等资源。The disconnection phase is also a phase that requires user operation to trigger. It is the process of whether the virtual camera is a resource. When the user disconnects the camera or unplugs the camera, the client will send a disconnect camera command to the virtual camera. After the virtual camera receives the information, it will be unplugged from the virtual camera. There will be no camera-related information in the virtual machine. At the same time, the virtual camera will reclaim all memory and other resources.

总结而言,该实施例中的摄像头交互方法在客户端的执行侧增加了编码器,在服务端的执行侧增加了虚拟摄像头,同时虚拟机内部不再需要视频代理驱动,其主要在数据流的处理上做了优化。In summary, the camera interaction method in this embodiment adds an encoder on the client execution side and a virtual camera on the server execution side. At the same time, the video proxy driver is no longer required inside the virtual machine. It mainly optimizes the processing of data streams.

数据流分为两部分,即枚举设备数据和视频流数据,枚举设备相关数据,包含如设备描述符,配置描述符,接口描述符,端点描述符,VC头描述符,VC输入/输出终端描述符,VC处理单元描述符,VS输入头描述符,各编码类型的视频帧描述符等数据。从USB摄像头拿到后,直接传到新加的虚拟uvc摄像头存储,uvc摄像头支持的格式描述信息固定为编码格式,不再是USB设备中的数据格式,待虚拟uvc摄像头通过网络从USB摄像头获取到所需的所有信息后,虚拟uvc摄像头接入虚拟机系统。在虚拟机内设备管理器中,即可查看到虚拟摄像头设备的相关信息。The data stream is divided into two parts, namely, enumerated device data and video stream data. The enumerated device-related data includes data such as device descriptors, configuration descriptors, interface descriptors, endpoint descriptors, VC header descriptors, VC input/output terminal descriptors, VC processing unit descriptors, VS input header descriptors, and video frame descriptors of various encoding types. After getting it from the USB camera, it is directly transferred to the newly added virtual uvc camera for storage. The format description information supported by the uvc camera is fixed to the encoding format, and is no longer the data format in the USB device. After the virtual uvc camera obtains all the required information from the USB camera through the network, the virtual uvc camera is connected to the virtual machine system. In the device manager in the virtual machine, you can view the relevant information of the virtual camera device.

设备视频流数据即视频数据。不再从设备拿传统的单包URB数据,而是从USB摄像头取一帧帧完整的yuv数据。经过新增的编码器后,根据虚拟机内的用户选择,编码成对应的编码数据(如:H265/H264/MJPEG)。当用户在虚拟机内打开摄像头时,虚拟uvc摄像头会不断地向客户端请求数据帧。当检测到有来自USB摄像头的数据时,马上上报给虚拟机,虚拟机内软件即可看到视频画面。The device video stream data is the video data. Instead of taking the traditional single-packet URB data from the device, it takes complete frames of YUV data from the USB camera. After passing through the newly added encoder, it is encoded into the corresponding encoded data (such as H265/H264/MJPEG) according to the user's selection in the virtual machine. When the user opens the camera in the virtual machine, the virtual UVC camera will continuously request data frames from the client. When data from the USB camera is detected, it is immediately reported to the virtual machine, and the software in the virtual machine can see the video screen.

当用户在虚拟机内关闭摄像头时,虚拟uvc摄像头会通知usb摄像头关闭视频流。整个过程的交互中,虚拟uvc摄像头与USB摄像头直接的交互。以上数据都是以自定义的VCAM协议作为载体组包和解包。下面以虚拟摄像头为聚焦点描述VCAM协议,虚拟摄像头使用qemu虚拟出uvc的空设备,设备数据填充流程如图8所示的一种摄像头交互方法的交互流程图,从图中可以看出,物理摄像头客户端主机与虚拟摄像头以网络方式交互,虚拟摄像头与虚拟机之间以uvc方式交互。整个交互流程大致分为3个阶段:连接阶段,数据传输阶段,断开连接阶段。When the user turns off the camera in the virtual machine, the virtual uvc camera will notify the usb camera to turn off the video stream. In the whole process of interaction, the virtual uvc camera interacts directly with the USB camera. The above data are all packaged and unpacked using the custom VCAM protocol as the carrier. The following describes the VCAM protocol with the virtual camera as the focus. The virtual camera uses qemu to virtualize an empty device of uvc. The device data filling process is shown in Figure 8, which is an interaction flow chart of a camera interaction method. It can be seen from the figure that the physical camera client host interacts with the virtual camera in a network manner, and the virtual camera interacts with the virtual machine in a uvc manner. The entire interaction process is roughly divided into three stages: connection stage, data transmission stage, and disconnection stage.

连接阶段是虚拟摄像头数据准备阶段,它从客户端决定设备连接时开始,发送查询指令CMD_VCAM_CHECK,查看是否支持虚拟摄像头。当超时时间内(如3秒)没有回应,则不支持,否则虚拟摄像头请求设备描述符(指令CMD_VCAM_DEVICE_DESC),此描述符描述设备的基本信息,如pid,vid等重要标识。待客户端回复后,继续请求设备的配置描述符信息(指令CMD_VCAM_CFG_DESC),客户端回复配置描述符以及其所有子描述符,如接口描述符,端点描述符,VC, VS等各描述符信息。所有信息都将缓存在虚拟摄像头中,当这些信息准备完成后,虚拟摄像头以attach的方式插入到虚拟机上。此时虚拟机内可在设备管理器中查看到摄像头信息,到此连接阶段结束。The connection phase is the virtual camera data preparation phase, which starts when the client decides to connect the device and sends a query command CMD_VCAM_CHECK to check whether the virtual camera is supported. If there is no response within the timeout (such as 3 seconds), it is not supported. Otherwise, the virtual camera requests the device descriptor (command CMD_VCAM_DEVICE_DESC), which describes the basic information of the device, such as pid, vid and other important identifiers. After the client responds, continue to request the device's configuration descriptor information (command CMD_VCAM_CFG_DESC), and the client responds with the configuration descriptor and all its sub-descriptors, such as interface descriptors, endpoint descriptors, VC, VS and other descriptor information. All information will be cached in the virtual camera. When this information is prepared, the virtual camera is inserted into the virtual machine in the attach mode. At this time, the camera information can be viewed in the device manager in the virtual machine, and this connection phase ends.

数据传输阶段是需要用户操作触发的阶段,是虚拟摄像头将数据以映射的方式走uvc协议传输到虚拟机的过程。当用户点击打开摄像头的播放器,并进行播放时,虚拟摄像头会收到打开摄像头的相关指令,将指令CMD_VCAM_STREAM_ON通过网络传输给客户端,客户端收到指令后拿到物理摄像头的视频数据n,通过指令CMD_VCAM_STREAM_TRANS传输到虚拟摄像头。虚拟摄像头拿到数据后,等待虚拟机指令下发取数据,当虚拟机下发请求到来,发现有数据,即可映射到虚拟机内,从而软件显示出画面。当虚拟摄像头内没有数据时,马上请求下一个数据n+1,如此反复,达到播放视频的效果。当用户关闭播放器或关闭视频播放时,虚拟摄像头会收到来自虚拟机的关闭指令,即可发CMD_VCAM_STREAM_OFF指令到客户端,客户端将关闭数据传输。The data transmission stage is a stage that needs to be triggered by user operation. It is the process in which the virtual camera transmits data to the virtual machine through the UVC protocol in a mapped manner. When the user clicks to open the camera player and plays it, the virtual camera will receive the relevant instructions to open the camera, and transmit the instruction CMD_VCAM_STREAM_ON to the client through the network. After receiving the instruction, the client gets the video data n of the physical camera and transmits it to the virtual camera through the instruction CMD_VCAM_STREAM_TRANS. After the virtual camera gets the data, it waits for the virtual machine instruction to send the data. When the virtual machine sends the request, it finds that there is data and can map it to the virtual machine, so that the software displays the picture. When there is no data in the virtual camera, it immediately requests the next data n+1, and repeats this process to achieve the effect of playing the video. When the user closes the player or turns off the video playback, the virtual camera will receive the shutdown instruction from the virtual machine, and can send the CMD_VCAM_STREAM_OFF instruction to the client, and the client will turn off the data transmission.

断开连接阶段也是需要用户操作触发的阶段,是虚拟摄像头是否资源的过程。当用户断开摄像头连接或者拔掉摄像头时,客户端会发送断开摄像头指令CMD_VCAM_DETACH到虚拟摄像头,虚拟摄像头拿到信息后从虚拟摄像头拔掉(即detach),虚拟机内将不再有任何摄像头相关的信息。同时虚拟摄像头会回收所有的内存等资源。The disconnection phase is also a phase that requires user operation to trigger. It is the process of whether the virtual camera is a resource. When the user disconnects the camera or unplugs the camera, the client will send the disconnect camera command CMD_VCAM_DETACH to the virtual camera. After the virtual camera gets the information, it will be unplugged from the virtual camera (ie, detach), and there will be no more camera-related information in the virtual machine. At the same time, the virtual camera will reclaim all memory and other resources.

通过上述实施例中的摄像头交互方法可知,本方案放弃了urb大数据量传输,使用数据量小的编码数据传输,在执行远程摄像头的通讯过程中,具备数据量低、网络带宽要求低的特点,可在同等带宽情况下,支持更多的设备,减少了虚拟总线的压力。It can be seen from the camera interaction method in the above embodiment that this solution abandons the large data volume transmission of urb and uses coded data transmission with small data volume. In the process of executing remote camera communication, it has the characteristics of low data volume and low network bandwidth requirements. It can support more devices under the same bandwidth and reduce the pressure of the virtual bus.

实际场景中,在虚拟机运行的应用程序中的视频画面稳定性更好,不容易出现画面断层,闪屏,卡顿情况。该方法更好的解耦物理摄像头,可控性更强,因为相比传统方案所有数据依赖USB物理摄像头,本发明方案只需取其基础数据编码供虚拟UVC摄像头使用,并且数据在虚拟UVC摄像头中可自我策略控制,包括其他的设备描述信息都可自行控制,不再全部依赖实际USB摄像头。In actual scenarios, the video images in applications running in virtual machines are more stable, and are less likely to experience screen faults, screen flashes, or freezes. This method better decouples the physical camera and is more controllable, because compared to the traditional solution where all data depends on the USB physical camera, the solution of the present invention only needs to take its basic data encoding for use by the virtual UVC camera, and the data can be self-policy controlled in the virtual UVC camera, including other device description information that can be controlled by itself, and no longer entirely dependent on the actual USB camera.

对于前述实施例提供的摄像头交互方法,本发明实施例提供了一种摄像头交互系统,如图9所示,该系统应用于包含虚拟端和物理端的服务器中,虚拟端设置有虚拟机以及虚拟摄像头;物理端包括:客户端主机、物理摄像头和编码器;编码器的输入端通过客户端主机连接物理摄像头,编码器的输出端经过服务器的服务端与虚拟摄像头的输入端相连接;虚拟摄像头的输出端与虚拟机相连接;For the camera interaction method provided in the above embodiment, an embodiment of the present invention provides a camera interaction system, as shown in FIG9 , the system is applied to a server including a virtual end and a physical end, the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, and the output end of the encoder is connected to the input end of the virtual camera through the server end; the output end of the virtual camera is connected to the virtual machine;

该系统包括:The system includes:

连接交互模块910,用于基于物理摄像头与编码器所在客户端之间的设备连接参数生成虚拟摄像头对应的枚举设备数据,并利用枚举设备数据生成的虚拟连接指令控制虚拟摄像头与虚拟机完成连接;A connection interaction module 910 is used to generate enumerated device data corresponding to the virtual camera based on the device connection parameters between the physical camera and the client where the encoder is located, and use the virtual connection instruction generated by the enumerated device data to control the virtual camera to complete the connection with the virtual machine;

指令交互模块920,用于当监测到虚拟机发出的摄像头请求指令后,根据摄像头请求指令生成虚拟摄像头对应的视频请求指令,并控制服务端将视频请求指令发送至物理摄像头后,实时接收物理摄像头的回调数据;The instruction interaction module 920 is used to generate a video request instruction corresponding to the virtual camera according to the camera request instruction after monitoring the camera request instruction issued by the virtual machine, and control the server to send the video request instruction to the physical camera, and receive the callback data of the physical camera in real time;

数据交互模块930,用于利用编码器对回调数据进行编码处理后得到物理摄像头对应的视频流数据,并控制虚拟摄像头基于视频流数据生成摄像头请求指令对应的视频响应数据;The data interaction module 930 is used to encode the callback data using an encoder to obtain video stream data corresponding to the physical camera, and control the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data;

视频交互模块940,用于控制服务端将视频响应数据发送至虚拟机中。The video interaction module 940 is used to control the server to send the video response data to the virtual machine.

从上述实施例中提到的摄像头交互系统可知,该系统通过在客户端设置的编码器对物理摄像头采集的原始数据进行编码压缩后,减少了网络带宽的压力;并通过服务端中额外设置的虚拟摄像头,实现了物理摄像头和虚拟机之间的解耦,进一步降低了虚拟机虚拟总线的带宽压力,从而有效缓解现有技术中虚拟机在网络状态不佳时导致的应用程序显示画面断层,闪屏或卡顿等情况。From the camera interaction system mentioned in the above embodiment, it can be seen that the system reduces the pressure on network bandwidth by encoding and compressing the original data collected by the physical camera through the encoder set on the client; and through the virtual camera additionally set in the server, the decoupling between the physical camera and the virtual machine is realized, and the bandwidth pressure of the virtual bus of the virtual machine is further reduced, thereby effectively alleviating the problems of application display screen faults, screen flashing or freezes caused by the virtual machine in the prior art when the network status is poor.

本发明实施例中摄像头交互系统,其实现原理及产生的技术效果和前述摄像头交互方法实施例相同,为简要描述,装置实施例部分未提及之处,可参考前述摄像头交互方法实施例中相应内容。The camera interaction system in the embodiment of the present invention has the same implementation principle and technical effects as those in the aforementioned camera interaction method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned camera interaction method embodiment.

本实施例还提供一种服务器,如图10所示,该服务器包含虚拟端10和物理端20,虚拟端10设置有虚拟机10a以及虚拟摄像头10b;物理端20包括:客户端主机20a、物理摄像头20b和编码器20c;编码器20c的输入端通过客户端主机20a连接物理摄像头20b,编码器20c的输出端经过服务器的服务端30与虚拟摄像头10b的输入端相连接;虚拟摄像头10b的输出端与虚拟机10a相连接;The present embodiment also provides a server, as shown in FIG10 , the server comprises a virtual terminal 10 and a physical terminal 20, the virtual terminal 10 is provided with a virtual machine 10a and a virtual camera 10b; the physical terminal 20 comprises: a client host 20a, a physical camera 20b and an encoder 20c; the input end of the encoder 20c is connected to the physical camera 20b through the client host 20a, the output end of the encoder 20c is connected to the input end of the virtual camera 10b through the server end 30; the output end of the virtual camera 10b is connected to the virtual machine 10a;

服务器在对虚拟摄像头10b与物理摄像头20b的视频数据交互过程中,采用上述实施例中提到的摄像头交互方法的步骤。During the process of video data interaction between the virtual camera 10b and the physical camera 20b, the server adopts the steps of the camera interaction method mentioned in the above embodiment.

本发明实施例中服务器在采用摄像头交互方法过程中,其实现原理及产生的技术效果和前述摄像头交互方法实施例相同,为简要描述,装置实施例部分未提及之处,可参考前述摄像头交互方法实施例中相应内容。In the embodiment of the present invention, when the server adopts the camera interaction method, its implementation principle and the technical effects produced are the same as those in the aforementioned camera interaction method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference can be made to the corresponding contents in the aforementioned camera interaction method embodiment.

本实施例还提供一种电子设备,该电子设备的结构示意图如图11所示,该设备包括处理器101和存储器102;其中,存储器102用于存储一条或多条计算机指令,一条或多条计算机指令被处理器执行,以实现上述摄像头交互方法的步骤。This embodiment also provides an electronic device, the structural diagram of the electronic device is shown in Figure 11, and the device includes a processor 101 and a memory 102; wherein the memory 102 is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the steps of the above-mentioned camera interaction method.

图11所示的电子设备还包括总线103和通信接口104,处理器101、通信接口104和存储器102通过总线103连接。The electronic device shown in FIG. 11 further includes a bus 103 and a communication interface 104 , and the processor 101 , the communication interface 104 and the memory 102 are connected via the bus 103 .

其中,存储器102可能包含高速随机存取存储器(RAM,Random Access Memory),也可能还包括非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。总线103可以是ISA总线、PCI总线或EISA总线等。所述总线可以分为地址总线、数据总线、控制总线等。为便于表示,图11中仅用一个双向箭头表示,但并不表示仅有一根总线或一种类型的总线。The memory 102 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The bus 103 may be an ISA bus, a PCI bus, or an EISA bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, FIG. 11 only uses one bidirectional arrow to represent, but it does not mean that there is only one bus or one type of bus.

通信接口104用于通过网络接口与至少一个用户终端及其它网络单元连接,将封装好的IPv4报文或IPv4报文通过网络接口发送至用户终端。The communication interface 104 is used to connect to at least one user terminal and other network units through a network interface, and send the encapsulated IPv4 message or IPv4 message to the user terminal through the network interface.

处理器101可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器101中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器101可以是通用处理器,包括中央处理器(Central Processing Unit,简称CPU)、网络处理器(Network Processor,简称NP)等;还可以是数字信号处理器(DigitalSignal Processor,简称DSP)、专用集成电路(Application Specific IntegratedCircuit,简称ASIC)、现场可编程门阵列(Field-Programmable Gate Array,简称FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本公开实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本公开实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器102,处理器101读取存储器102中的信息,结合其硬件完成前述实施例的方法的步骤。The processor 101 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 101. The above processor 101 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 102, and the processor 101 reads the information in the memory 102 and completes the steps of the method of the above embodiment in combination with its hardware.

本发明实施例还提供了一种存储介质,该存储介质上存储有计算机程序,该计算机程序被处理器运行时执行前述实施例中摄像头交互方法的步骤。An embodiment of the present invention further provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the camera interaction method in the aforementioned embodiment are executed.

在本申请所提供的几个实施例中,应该理解到,所揭露的系统、设备和方法,可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,又例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些通信接口,设备或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个处理器可执行的非易失的计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以用软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that can be executed by a processor. Based on this understanding, the technical solution of the present invention can essentially or in other words, the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

最后应说明的是:以上所述实施例,仅为本发明的具体实施方式,用以说明本发明的技术方案,而非对其限制,本发明的保护范围并不局限于此,尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,其依然可以对前述实施例所记载的技术方案进行修改或可轻易想到变化,或者对其中部分技术特征进行等同替换;而这些修改、变化或者替换,并不使相应技术方案的本质脱离本发明实施例技术方案的精神和范围,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims (10)

1.一种摄像头交互方法,其特征在于,所述方法应用于包含虚拟端和物理端的服务器中,所述虚拟端设置有虚拟机以及虚拟摄像头;所述物理端包括:客户端主机、物理摄像头和编码器;所述编码器的输入端通过所述客户端主机连接所述物理摄像头,所述编码器的输出端经过所述服务器的服务端与所述虚拟摄像头的输入端相连接;所述虚拟摄像头的输出端与所述虚拟机相连接;1. A camera interaction method, characterized in that the method is applied to a server including a virtual end and a physical end, wherein the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, the output end of the encoder is connected to the input end of the virtual camera through the service end of the server; the output end of the virtual camera is connected to the virtual machine; 所述方法包括:The method comprises: 基于所述物理摄像头与所述编码器所在所述客户端之间的设备连接参数生成所述虚拟摄像头对应的枚举设备数据,并利用所述枚举设备数据生成的虚拟连接指令控制所述虚拟摄像头与所述虚拟机完成连接;Generate enumerated device data corresponding to the virtual camera based on device connection parameters between the physical camera and the client where the encoder is located, and use the virtual connection instruction generated by the enumerated device data to control the virtual camera to complete the connection with the virtual machine; 当监测到所述虚拟机发出的摄像头请求指令后,根据所述摄像头请求指令生成所述虚拟摄像头对应的视频请求指令,并控制所述服务端将所述视频请求指令发送至所述物理摄像头后,实时接收所述物理摄像头的回调数据;When a camera request instruction issued by the virtual machine is detected, a video request instruction corresponding to the virtual camera is generated according to the camera request instruction, and after the server is controlled to send the video request instruction to the physical camera, callback data of the physical camera is received in real time; 利用所述编码器对所述回调数据进行编码处理后得到所述物理摄像头对应的视频流数据,并控制所述虚拟摄像头基于所述视频流数据生成所述摄像头请求指令对应的视频响应数据;The encoder is used to encode the callback data to obtain video stream data corresponding to the physical camera, and the virtual camera is controlled to generate video response data corresponding to the camera request instruction based on the video stream data; 控制所述服务端将所述视频响应数据发送至所述虚拟机中。Control the server to send the video response data to the virtual machine. 2.根据权利要求1所述的摄像头交互方法,其特征在于,基于所述物理摄像头与所述编码器所在所述客户端之间的设备连接参数生成所述虚拟摄像头对应的枚举设备数据,包括:2. The camera interaction method according to claim 1, characterized in that the enumerated device data corresponding to the virtual camera is generated based on the device connection parameters between the physical camera and the client where the encoder is located, comprising: 基于提供所述物理摄像头工作环境的客户端主机与所述编码器所在所述客户端之间的连接状态参数,获取所述物理摄像头与所述编码器所在所述客户端之间的所述设备连接参数;Based on the connection status parameters between the client host providing the working environment of the physical camera and the client where the encoder is located, the device connection parameters between the physical camera and the client where the encoder is located are obtained; 当检测到所述物理摄像头处于已插入所述客户端主机的状态时,基于所述设备连接参数控制所述虚拟摄像头向所述物理摄像头发送设备描述符请求指令,并实时接收所述物理摄像头响应的设备描述符;When it is detected that the physical camera is in a state of being inserted into the client host, the virtual camera is controlled to send a device descriptor request instruction to the physical camera based on the device connection parameters, and the device descriptor of the physical camera response is received in real time; 控制所述虚拟摄像头向所述物理摄像头发送配置描述符请求指令,并实时接收所述物理摄像头响应的配置描述符;Control the virtual camera to send a configuration descriptor request instruction to the physical camera, and receive the configuration descriptor responded by the physical camera in real time; 利用所述设备描述符和所述配置描述符生成所述枚举设备数据。The enumerated device data is generated using the device descriptor and the configuration descriptor. 3.根据权利要求1所述的摄像头交互方法,其特征在于,利用所述枚举设备数据生成的虚拟连接指令控制所述虚拟摄像头与所述虚拟机完成连接,包括:3. The camera interaction method according to claim 1, characterized in that the virtual connection instruction generated by the enumerated device data is used to control the virtual camera to complete the connection with the virtual machine, comprising: 将所述枚举设备数据中包含的设备描述符、配置描述符、接口描述符、端点描述符、视频头描述符、终端描述符、处理单元描述符、视频帧描述符上述一种或多种描述符数据缓存至所述虚拟摄像头的存储单元;Cache one or more descriptor data of a device descriptor, a configuration descriptor, an interface descriptor, an endpoint descriptor, a video head descriptor, a terminal descriptor, a processing unit descriptor, and a video frame descriptor contained in the enumerated device data into a storage unit of the virtual camera; 控制所述服务端从所述存储单元中获取所述描述符数据,并利用所述描述符数据生成所述虚拟摄像头对应的设备加载指令;Controlling the server to obtain the descriptor data from the storage unit, and using the descriptor data to generate a device loading instruction corresponding to the virtual camera; 利用所述设备加载指令控制所述虚拟摄像头加载至所述虚拟机中并执行连接处理。The device loading instruction is used to control the virtual camera to be loaded into the virtual machine and perform connection processing. 4.根据权利要求1所述的摄像头交互方法,其特征在于,控制所述服务端将所述视频请求指令发送至所述物理摄像头后,实时接收所述物理摄像头的回调数据,包括:4. The camera interaction method according to claim 1, characterized in that after controlling the server to send the video request instruction to the physical camera, receiving the callback data of the physical camera in real time, comprises: 基于所述视频请求指令获取对应的所述物理摄像头;Acquire the corresponding physical camera based on the video request instruction; 控制所述服务端将所述视频请求指令发送至对应的所述物理摄像头,并控制所述物理摄像头根据所述视频请求指令实时采集并获取视频流数据;Control the server to send the video request instruction to the corresponding physical camera, and control the physical camera to collect and obtain video stream data in real time according to the video request instruction; 将所述视频流数据按照所述虚拟摄像头的格式需求进行转化后,控制所述物理摄像头将已完成格式转化的所述视频流数据作为回调数据发送至所述服务端;After converting the video stream data according to the format requirement of the virtual camera, controlling the physical camera to send the video stream data that has completed the format conversion as callback data to the server; 控制所述服务端实时接收所述物理摄像头发送的所述回调数据。Control the server to receive the callback data sent by the physical camera in real time. 5.根据权利要求4所述的摄像头交互方法,其特征在于,利用所述编码器对所述回调数据进行编码处理后得到所述物理摄像头对应的视频流数据,包括:5. The camera interaction method according to claim 4, characterized in that the process of encoding the callback data using the encoder to obtain the video stream data corresponding to the physical camera comprises: 基于所述回调数据获取所述物理摄像头对应的初始数据;其中,所述初始数据为YUV编码数据;Acquire initial data corresponding to the physical camera based on the callback data; wherein the initial data is YUV encoded data; 控制所述编码器对所述初始数据进行编码转换后,得到转换编码数据;其中,所述转换编码数据为H265、H264、MJPEG上述一种或多种编码数据;After controlling the encoder to perform encoding conversion on the initial data, converted encoded data is obtained; wherein the converted encoded data is one or more encoded data of H265, H264, MJPEG, etc.; 根据所述转换编码数据生成所述物理摄像头对应的所述视频流数据。The video stream data corresponding to the physical camera is generated according to the converted encoded data. 6.根据权利要求1所述的摄像头交互方法,其特征在于,控制所述虚拟摄像头基于所述视频流数据生成所述摄像头请求指令对应的视频响应数据,包括:6. The camera interaction method according to claim 1, characterized in that controlling the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data comprises: 判断所述虚拟摄像头的预设存储区中是否包含所述视频流数据对应的历史数据;Determining whether the preset storage area of the virtual camera contains historical data corresponding to the video stream data; 如果是,则基于所述历史数据生成所述视频响应数据;如果否,则基于所述视频流数据生成所述视频响应数据,并将所述视频响应数据作为所述历史数据保存至所述存储区中。If yes, the video response data is generated based on the historical data; if no, the video response data is generated based on the video stream data, and the video response data is saved in the storage area as the historical data. 7.根据权利要求1所述的摄像头交互方法,其特征在于,当检测到所述虚拟机发出的摄像头关闭指令后,所述方法还包括:7. The camera interaction method according to claim 1, characterized in that, after detecting a camera closing instruction issued by the virtual machine, the method further comprises: 控制所述虚拟机向所述虚拟摄像头发送第一关闭指令,并利用所述第一关闭指令控制所述虚拟摄像头处于关闭状态;Controlling the virtual machine to send a first closing instruction to the virtual camera, and using the first closing instruction to control the virtual camera to be in a closed state; 控制所述服务端向所述物理摄像头发送第二关闭指令,并利用所述第二关闭指令控制所述物理摄像头处于关闭状态。The server is controlled to send a second shutdown instruction to the physical camera, and the physical camera is controlled to be in a shutdown state using the second shutdown instruction. 8.根据权利要求1所述的摄像头交互方法,其特征在于,当检测到所述物理摄像头处于离线状态时,所述方法还包括:8. The camera interaction method according to claim 1, characterized in that when it is detected that the physical camera is in an offline state, the method further comprises: 控制所述服务端生成所述虚拟摄像头对应的关闭指令,并控制所述服务端将所述关闭指令发送至所述虚拟机中。The server is controlled to generate a closing instruction corresponding to the virtual camera, and the server is controlled to send the closing instruction to the virtual machine. 9.一种摄像头交互系统,其特征在于,所述系统应用于包含虚拟端和物理端的服务器中,所述虚拟端设置有虚拟机以及虚拟摄像头;所述物理端包括:客户端主机、物理摄像头和编码器;所述编码器的输入端通过所述客户端主机连接所述物理摄像头,所述编码器的输出端经过所述服务器的服务端与所述虚拟摄像头的输入端相连接;所述虚拟摄像头的输出端与所述虚拟机相连接;9. A camera interaction system, characterized in that the system is applied to a server including a virtual end and a physical end, the virtual end is provided with a virtual machine and a virtual camera; the physical end includes: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, the output end of the encoder is connected to the input end of the virtual camera through the service end of the server; the output end of the virtual camera is connected to the virtual machine; 所述系统包括:The system comprises: 连接交互模块,用于基于所述物理摄像头与所述编码器所在所述客户端之间的设备连接参数生成所述虚拟摄像头对应的枚举设备数据,并利用所述枚举设备数据生成的虚拟连接指令控制所述虚拟摄像头与所述虚拟机完成连接;A connection interaction module, configured to generate enumerated device data corresponding to the virtual camera based on device connection parameters between the physical camera and the client where the encoder is located, and control the virtual camera to complete the connection with the virtual machine using a virtual connection instruction generated by the enumerated device data; 指令交互模块,用于当监测到所述虚拟机发出的摄像头请求指令后,根据所述摄像头请求指令生成所述虚拟摄像头对应的视频请求指令,并控制所述服务端将所述视频请求指令发送至所述物理摄像头后,实时接收所述物理摄像头的回调数据;An instruction interaction module is used to generate a video request instruction corresponding to the virtual camera according to the camera request instruction after monitoring the camera request instruction issued by the virtual machine, and control the server to send the video request instruction to the physical camera, and then receive callback data of the physical camera in real time; 数据交互模块,用于利用所述编码器对所述回调数据进行编码处理后得到所述物理摄像头对应的视频流数据,并控制所述虚拟摄像头基于所述视频流数据生成所述摄像头请求指令对应的视频响应数据;A data interaction module, configured to obtain video stream data corresponding to the physical camera after encoding the callback data using the encoder, and control the virtual camera to generate video response data corresponding to the camera request instruction based on the video stream data; 视频交互模块,用于控制所述服务端将所述视频响应数据发送至所述虚拟机中。The video interaction module is used to control the server to send the video response data to the virtual machine. 10.一种服务器,其特征在于,所述服务器包含虚拟端和物理端,所述虚拟端设置有虚拟机以及虚拟摄像头;所述物理端包括:客户端主机、物理摄像头和编码器;所述编码器的输入端通过所述客户端主机连接所述物理摄像头,所述编码器的输出端经过所述服务器的服务端与所述虚拟摄像头的输入端相连接;所述虚拟摄像头的输出端与所述虚拟机相连接;10. A server, characterized in that the server comprises a virtual end and a physical end, the virtual end is provided with a virtual machine and a virtual camera; the physical end comprises: a client host, a physical camera and an encoder; the input end of the encoder is connected to the physical camera through the client host, the output end of the encoder is connected to the input end of the virtual camera through the service end of the server; the output end of the virtual camera is connected to the virtual machine; 所述服务器在对所述虚拟摄像头与所述物理摄像头的视频数据交互过程中,采用上述权利要求1至8任一项所述的摄像头交互方法的步骤。During the process of interacting video data between the virtual camera and the physical camera, the server adopts the steps of the camera interaction method described in any one of claims 1 to 8.
CN202411442250.0A 2024-10-16 2024-10-16 Camera interaction method, system and server Pending CN118972695A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202411442250.0A CN118972695A (en) 2024-10-16 2024-10-16 Camera interaction method, system and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202411442250.0A CN118972695A (en) 2024-10-16 2024-10-16 Camera interaction method, system and server

Publications (1)

Publication Number Publication Date
CN118972695A true CN118972695A (en) 2024-11-15

Family

ID=93391075

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202411442250.0A Pending CN118972695A (en) 2024-10-16 2024-10-16 Camera interaction method, system and server

Country Status (1)

Country Link
CN (1) CN118972695A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106331733A (en) * 2016-09-28 2017-01-11 广东科学技术职业学院 A method and system for real-time processing of audio and video data on a desktop cloud terminal
CN106790612A (en) * 2016-12-30 2017-05-31 深圳市杰云科技有限公司 A kind of dynamic virtual camera mapping method and system
CN115567518A (en) * 2022-12-06 2023-01-03 西安雷风电子科技有限公司成都分公司 Device, system and method for reorienting camera of cloud desktop
CN117255245A (en) * 2023-11-17 2023-12-19 深圳市法本信息技术股份有限公司 Camera matching method, device, terminal equipment and storage medium
WO2024055427A1 (en) * 2022-09-13 2024-03-21 广州视源电子科技股份有限公司 Data transmission method, system and apparatus, and electronic device and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106331733A (en) * 2016-09-28 2017-01-11 广东科学技术职业学院 A method and system for real-time processing of audio and video data on a desktop cloud terminal
CN106790612A (en) * 2016-12-30 2017-05-31 深圳市杰云科技有限公司 A kind of dynamic virtual camera mapping method and system
WO2024055427A1 (en) * 2022-09-13 2024-03-21 广州视源电子科技股份有限公司 Data transmission method, system and apparatus, and electronic device and storage medium
CN115567518A (en) * 2022-12-06 2023-01-03 西安雷风电子科技有限公司成都分公司 Device, system and method for reorienting camera of cloud desktop
CN117255245A (en) * 2023-11-17 2023-12-19 深圳市法本信息技术股份有限公司 Camera matching method, device, terminal equipment and storage medium

Similar Documents

Publication Publication Date Title
CN115244944B (en) URL projection method and device
US11792130B2 (en) Audio/video communication method, terminal, server, computer device, and storage medium
CN110121114B (en) Method for transmitting stream data and data transmitting apparatus
WO2021179557A1 (en) Video stream playback method, system and terminal, and storage medium
CN102158553A (en) Method and device for playing multi-media files for remote desktop
US12008393B2 (en) Method for remotely accessing data of a USB device by a virtual machine
WO2024244690A1 (en) Data processing method and related apparatus
CN118972695A (en) Camera interaction method, system and server
CN108462679B (en) Data transmission method and device
KR101710011B1 (en) Image data transmission and reception method and apparatus
CN103414938B (en) The control method and digital TV integrated machine of digital TV integrated machine internal communication
CN115883962A (en) Camera control method, system, electronic device and storage medium
CN104639979A (en) Video sharing method and system
CN100459695C (en) Method of transmitting video data, and transmission system
EP4287586A1 (en) Media playback method and apparatus and electronic device
CN115942000A (en) Video stream transcoding method, device, equipment and medium based on H.264 format
US20250133144A1 (en) Transmission method and apparatus, and terminal
CN115550862B (en) Data transmission method and system of electric power working robot and electronic equipment
CN115103451B (en) Video transmission method, device, electronic equipment and readable storage medium
WO2024212774A1 (en) Data transmission method and apparatus, electronic device, and storage medium
CN117579935A (en) Control and data transmission method, equipment and medium for cloud mobile phone camera
CN117812052A (en) Display device and media data conversion method
Zhou et al. Design of video transmission system based on IMX6ULL
KR101839415B1 (en) Image data transmission and reception method and apparatus
CN115297256A (en) Image data processing method, device, device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20241115

RJ01 Rejection of invention patent application after publication