A method for processing dynamic detection messages of network cameras based on USB port UAC protocol
By using USB port UAC protocol to transmit dynamic detection messages between the webcam and Android box, the problems of high hardware costs and serious signal interference caused by serial port connection in the existing technology are solved, and more stable and economical dynamic detection messages are achieved. transmission.
Patent Information
- Application Number
- CN202411433384.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-10-15
AI Technical Summary
In the prior art, the transmission of dynamic detection messages between the webcam and the Android box depends on the serial port connection, resulting in high hardware costs, complex design and serious signal interference, affecting the transmission stability of dynamic detection messages.
The mobile detection message processing method of the webcam based on the USB port UAC protocol is adopted. After the dynamic detection message is packetized, it is transmitted to the Android box through the USB port UAC protocol, eliminating the serial port connection hardware, and directly using the sound card device to transmit audio messages.
It reduces hardware costs, avoids signal interference between USB cable and serial port cable, improves the stability of dynamic detection message transmission, and is suitable for the Android smart terminal equipment industry.
Smart Images

Figure CN118964239B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of digital information transmission, and in particular relates to a method for processing dynamic detection messages of a network camera based on a USB port UAC protocol. Background Art
[0002] Currently, the communication architecture between the webcam IPC and the Android box consists of a USB-based protocol and a four-wire serial port protocol. After capturing video, the webcam transmits it to the Android box via the USB port's UVC video device class protocol. The Android box can then request the IPC to change video information such as resolution and frame rate. When the webcam's motion detection module detects an object passing by, it encapsulates the motion detection image and transmits it to the Android box via the four-wire serial port. The Android box can also send commands to the webcam, such as starting and stopping motion detection and configuring it.
[0003] Because the Android box can only obtain one configured video stream at a time through the UVC protocol, according to the Android system's video framework, its motion detection message detection can only be processed in Android's HAL layer. However, the HAL layer only runs when Android calls IPC to display the video screen. When the Android system is not running, motion detection processing cannot be performed. Therefore, motion detection messages cannot be generated on the Android side, but only on the IPC side. To solve this problem, the existing technology adds a four-wire serial port to transmit motion detection messages.
[0004] However, both the IPC and the Android box require corresponding hardware module support, which not only increases the additional hardware cost and hardware design complexity, but also makes the USB cable and serial port cable prone to signal interference, resulting in unstable transmission of dynamic inspection messages. Summary of the Invention
[0005] In view of this, some embodiments disclose a method for processing a network camera motion detection message based on the USB port UAC protocol, including:
[0006] The motion detection module of the network camera detects the movement of the object, generates a motion detection message, and sends a motion detection message sending request;
[0007] In response to the motion detection message sending request, the motion detection message is packaged to generate a motion detection message packet, and the motion detection message packet is written into the sound card device of the network camera;
[0008] The sound card device of the network camera sends the dynamic detection message packet as audio information to the Android box through the USB port UAC protocol;
[0009] The Android box receives the dynamic inspection message package and performs post-processing.
[0010] Furthermore, some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol, in which the data structure of the motion detection message packet is a start identifier, a total data length, a packet sequence number, an internal block sequence number, data, and an end identifier arranged in sequence; wherein the start identifier is SWPICUAC; the total data length is the motion detection message data length; the packet sequence number is the generated message sequence number; the internal block sequence number is the sequence number of the internal block of the split motion detection message; the data refers to the motion detection message data, including the generation time, location, size, and picture; and the end identifier is CEND.
[0011] Some embodiments disclose a method for processing a network camera motion detection message based on the USB port UAC protocol, wherein the method for encapsulating a motion detection message into a motion detection message packet includes:
[0012] The replication start marker SWPICUAC;
[0013] Add the total data length of the current dynamic inspection message;
[0014] Add the packet number of the current dynamic inspection message;
[0015] Add the internal block number of the current animal inspection message packet;
[0016] Copy the current dynamic inspection message data;
[0017] Load the end marker CEND and generate an animal inspection message package.
[0018] Some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol. The data offset of the motion detection message data is the internal block number * 236. If the remaining valid data length is greater than or equal to 236 bytes, only 236 bytes are copied when copying the motion detection message, otherwise all remaining data are copied.
[0019] Some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol. After a motion detection message packet is generated, the count sequence number of the message packet counter is incremented by one, and the internal block sequence number counter of the motion detection message is reset to 0.
[0020] In some embodiments, a method for processing a network camera motion detection message based on the USB port UAC protocol is disclosed. The post-processing of the motion detection message packet includes unpacking and repacking the motion detection message packet. The specific method includes:
[0021] When the data received by the Android box is greater than or equal to 256 bytes, it starts to extract the dynamic inspection message package;
[0022] Search for the start marker, determine the starting position S1, and then determine whether the data of S1 plus 252 is the end marker;
[0023] If not, add 8 to S1 as the new starting position S1 and search for the starting mark again;
[0024] If yes, extract the dynamic inspection message packet information and perform byte order conversion; then enter the subsequent dynamic inspection message assembly process;
[0025] The process of assembling dynamic inspection messages includes:
[0026] Start assembling the dynamic inspection message; receive the dynamic inspection message package;
[0027] Determine whether the message packet sequence numbers of the last motion detection message packet and the currently received motion detection message packet are consistent;
[0028] If the message packet sequence number of the previous motion detection message packet is consistent with the message packet sequence number of the currently received motion detection message packet, then further determine whether the current motion detection message packet is 1 greater than the internal block sequence number of the currently received motion detection message packet. If not, discard it; if so, extract the current motion detection message;
[0029] If the message packet sequence numbers of the previous motion detection message packet are inconsistent with the currently received motion detection message packet, further determine whether the internal block sequence number of the currently received motion detection message packet is 0; if not 0, discard it; if 0, set the internal block sequence number of the currently received motion detection message packet to -1, use the message packet sequence number of the currently received motion detection message packet as the sequence number of the current motion detection message, and set the total data length of the currently received motion detection message packet to 0; then extract the current motion detection message;
[0030] Further, determine whether the total data length of the received motion detection message packets with the same message packet sequence number is greater than or equal to the total data length of the current motion detection message; if so, the assembly of the current motion detection message is completed; if not, continue to assemble the current motion detection message.
[0031] Some embodiments disclose a method for processing a network camera motion detection message based on a USB port UAC protocol, wherein the assembled motion detection message enters a motion detection message processing module for processing.
[0032] Some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol, which includes repeated filtering and disorderly discarding of motion detection message packets during the unpacking and repacking process of the motion detection messages.
[0033] Some embodiments disclose a method for processing a network camera motion detection message based on the USB port UAC protocol, further comprising configuring a sound card device of the core of the network camera.
[0034] Some embodiments disclose a method for processing a network camera motion detection message based on the USB port UAC protocol, which also includes a method for connecting the network camera to an Android box, specifically including:
[0035] Android box registers USB hot plug monitoring event;
[0036] After the network camera's sound card device is configured, the Android box monitors the corresponding state change event, calls the callback function, and handles the hot plug event in the callback function;
[0037] Obtain USB device description information and determine whether the USB device is a network camera USB device based on the product name, manufacturer and serial number;
[0038] If not, no UAC device connection processing is performed;
[0039] If so, obtain the configuration of each USB port and extract the device control port, data transmission port, and sampling rate information corresponding to the network camera USB device UAC;
[0040] Unbind the device control port corresponding to UAC from the Android kernel driver;
[0041] Select the supported data sampling rate through the unbound device control port;
[0042] Unbind the data transmission port corresponding to UAC from the Android kernel driver and start data transmission and reception on the data transmission port;
[0043] Start the UAC data receiving thread.
[0044] The disclosed method for processing webcam motion detection messages based on the USB port UAC protocol in an embodiment of the present invention packages the webcam's motion detection message and transmits it as an audio message to an Android box via the USB port UAC protocol. Upon receiving the motion detection message packet, the Android box unpacks and processes it, and then processes the motion detection message. This method omits the serial port connection hardware between the webcam and the Android box, reducing hardware costs, avoiding signal interference between the USB cable and the serial port cable, and improving the stability of motion detection message transmission. The method has promising application prospects in the Android smart terminal device industry. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 A flowchart of a method for processing a network camera motion detection message based on the USB port UAC protocol disclosed in some embodiments;
[0046] Figure 2A flow chart of a motion detection message packet disclosed in some embodiments;
[0047] Figure 3 A flowchart of depacketizing and merging dynamic inspection message packets disclosed in some embodiments;
[0048] Figure 4 This is a flow chart of a method for connecting a webcam to an Android box disclosed in some embodiments. DETAILED DESCRIPTION
[0049] The term "embodiment" is used herein specifically to describe any embodiment as "exemplary," and should not be construed as superior or preferable to other embodiments. Performance indicators in the embodiments of the present invention were tested using conventional testing methods in the art, unless otherwise specified. It should be understood that the terms used in the embodiments of the present invention are intended solely to describe specific implementations and are not intended to limit the disclosure of the embodiments of the present invention.
[0050] Unless otherwise specified, the technical and scientific terms used herein have the same meanings as commonly understood by those skilled in the art to which the embodiments of the present invention pertain; any experimental methods and technical means not otherwise specified in the embodiments of the present invention refer to experimental methods and technical means commonly used by those skilled in the art.
[0051] The terms "substantially" and "approximately" as used herein are used to describe small fluctuations. For example, they can refer to less than or equal to ±5%, such as less than or equal to ±2%, such as less than or equal to ±1%, such as less than or equal to ±0.5%, such as less than or equal to ±0.2%, such as less than or equal to ±0.1%, such as less than or equal to ±0.05%. The numerical data expressed or presented in this article in a range format are used only for convenience and brevity and should therefore be flexibly interpreted as including not only the values explicitly listed as the limits of the range, but also all independent values or sub-ranges contained in the range. For example, a numerical range of "1-5%" should be interpreted as including not only the explicitly listed values of 1% to 5%, but also the independent values and sub-ranges within the range shown. Therefore, independent values such as 2%, 3.5% and 4% and sub-ranges such as 1% to 3%, 2% to 4% and 3% to 5% are included in this numerical range. This principle also applies to ranges that only list one numerical value. In addition, such an interpretation applies regardless of the width of the range or the characteristics described.
[0052] In this article, IPC refers to a network camera, a new generation of cameras that combines traditional cameras with network technology. UVC stands for the USB Video Device Class transport protocol, used for controlling and transmitting video data, providing a standardized way to connect and use video devices without the need for installing specific drivers. UAC stands for the USB Audio Device Class transport protocol, used for controlling and transmitting audio data, providing a standardized way to connect and use audio devices without the need for installing specific drivers. Four-wire serial port wiring typically refers to the wiring scheme used for asynchronous serial port connections between terminal devices. It uses four wires to achieve bidirectional data transmission. Specifically, a four-wire serial port connection consists of two data wires, TXD+ and TXD-, and two signal ground wires, RXD+ and RXD-, for full-duplex communication. Motion detection refers to the process of detecting movement when a moving object passes within the camera's field of view and performing a series of linked functions, such as recording, alarming, linked snapshots, and linked video uploads, generating a series of motion detection messages. Motion detection recording can typically significantly reduce hard drive space.
[0053] In this article, Libusb is a USB device access interface library that provides Android applications with access to control data transfers to and from USB devices on both Unix and non-Unix systems without the need for kernel-mode drivers. Alsa-lib is a Linux application-level C library that provides a unified, standardized interface for audio application development. Applications simply call this API to control underlying sound card devices, such as playback and recording. Alsa-lib, in user space, provides a unified API interface for applications, hiding driver-level implementation details and simplifying applications.
[0054] Android supports USB microphones. When a USB microphone is plugged in, the driver will generate a corresponding sound card node and a corresponding input event. After the framework detects the input event and finds that it is a USB microphone, it will call the corresponding interface of audioflinger to notify that a USB microphone is plugged in, and audioflinger will start the corresponding processing flow.
[0055] When a USB device is plugged in, the gadget module of the USB device is bound to the corresponding module by the corresponding functional module driver. For example, UAC is bound to the sound card input driver module by default. If the gadget module binding is not required, it needs to be unbound from the driver through libusb_detach_kernel_driver of libusb.
[0056] Throughout this document, including in the claims, transitional terms such as "comprises," "includes," "with," "having," "contains," "involving," and "accommodating" are understood to be open-ended, meaning "including but not limited to." Only the transitional terms "consisting of" and "composed of" are closed transitional terms.
[0057] In order to better illustrate the present invention, numerous specific details are provided in the following specific examples. It should be understood by those skilled in the art that the present invention can be practiced without certain specific details. In the examples, some methods, means, instruments, and equipment well known to those skilled in the art are not described in detail in order to highlight the main purpose of the present invention.
[0058] Under the premise of no conflict, the technical features disclosed in the embodiments of the present invention can be arbitrarily combined, and the resulting technical solutions belong to the contents disclosed in the embodiments of the present invention.
[0059] In some embodiments, a method for processing a network camera motion detection message based on a USB port UAC protocol is provided. Figure 1 As shown, the steps include:
[0060] S1. The motion detection module of the network camera detects the motion of an object, generates a motion detection message, and sends a motion detection message sending request;
[0061] S2, in response to the motion detection message sending request, packages the motion detection message to generate a motion detection message packet, and writes the motion detection message packet to the sound card device of the network camera. Usually, after receiving the motion detection message sending request, the sending thread packages the motion detection message, and then writes the packaged motion detection message packet to the sound card device multiple times until a new motion detection request is received. Usually, in the process of generating motion detection messages, the network camera dynamically generates multiple motion detection messages at regular intervals. Since there may be various differences and distinctions between the motion detection messages, it is necessary to package the motion detection messages according to set rules to generate a motion detection message packet with a set data structure to facilitate transmission, parsing and assembly.
[0062] Normally, the Android box may not read data in time. If the network camera's motion detection information is written too quickly, it will cause loss when the Android box receives the packet. Therefore, the motion detection message usually needs to be sent multiple times, for example, each packet is sent at least 4 times.
[0063] S3. The sound card device of the network camera sends the dynamic detection message packet as audio information to the Android box through the USB port UAC protocol;
[0064] S4. The Android box receives the motion detection message packet and performs post-processing. Typically, after reading UAC data via libusb, the Android system unpacks the received motion detection message packet according to the packetization protocol. Encapsulated motion detection message packets are often sent repeatedly, and there is a small probability of packet loss and out-of-order transmission. Therefore, the code needs to implement duplicate filtering and out-of-order discarding of motion detection message packets. The motion detection information in the stored motion detection message packet is then extracted and submitted to the corresponding processing module for further processing.
[0065] Some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol, in which the data structure of the motion detection message packet is a start identifier, a total data length, a packet sequence number, an internal block sequence number, data and an end identifier arranged in sequence; wherein the start identifier is SWPICUAC; the total data length is the motion detection message data length; the packet sequence number is the sequence number of the generated motion detection message, and each motion detection message corresponds to a sequence number; the internal block sequence number is the sequence number of the internal block of the split motion detection message. Usually, if the same message does not need to be split, the internal block sequence number is set to 0; if the same message needs to be split into multiple, the internal block sequence number starts from 0 and is set in a naturally increasing order; the data refers to the motion detection message data, including the generation time, location, size, and picture; the end identifier is CEND.
[0066] Typically, the data structure of a motion detection message packet is a start flag, total data length, packet sequence number, internal block sequence number, data, and end flag. The total length of the motion detection message packet is 256 bytes; the start flag startflag is an 8-byte flag SWPICUAC; the total data length dataSize is the 4-byte motion detection message data length, which is in network byte order. Usually, the ordered length of the last block is the remainder of the total length divided by 236. When the remainder is 0, the length of the last block is 236 bytes; the number of small blocks requested this time is (dataSize+235) / 236; the packet sequence number picIndex of the motion detection message is a 2-byte message sequence number, which is in network byte order. Each time a dynamic motion detection message is generated, its value increases by one; the message sequence number can usually be used to determine whether a message is lost; the internal block sequence number splitIndex is the sequence number of the split internal block of the motion detection message, which is usually a 2-byte unsigned short integer. Short data is in network byte order, with values increasing sequentially. The sequence number can be used to determine whether a data block has been lost, and duplicate data blocks need to be discarded. Data refers to the motion detection message data, including the generation time, location, size, and image. Typically, the data can be up to 236 bytes. The end flag is the 4-byte CEND. Typically, if the motion detection message is longer than 236 bytes, it is fragmented into 236-byte segments. The internal segment sequence number, splitIndex, is the segment sequence number.
[0067] Some embodiments disclose a method for processing a network camera motion detection message based on a USB port UAC protocol, such as Figure 2 As shown, the method for generating a motion detection message packet by encapsulating the motion detection message packet includes the following steps:
[0068] S201, replication start marker SWPICUAC;
[0069] S202, add the total data length of the current dynamic inspection message;
[0070] S203, adding the information packet sequence number of the current animal inspection message;
[0071] S204, adding the internal block sequence number of the current animal inspection message packet;
[0072] S205, copy the current dynamic inspection message data;
[0073] S206: Load the end marker CEND and generate an animal inspection message packet.
[0074] Usually, a motion detection message needs to be split into internal block messages, and then each internal message is packaged into a motion detection message packet according to the packetization rules, and finally multiple motion detection message packets are formed, which are transmitted through the UAC protocol on the USB end; when the motion detection message packet is generated, the 8-byte SWPICUAC start identifier is copied; then the total length of the motion detection message, the information packet number of the motion detection message, and the internal block number are encoded in network byte order in sequence; and then the motion detection message data is copied; usually, the generated motion detection message will not exceed 1M bytes. Generally, the maximum value of the internal block number splitIndex is 65536, and 65536*236 is about 14M bytes, so the data offset of the copied motion detection message is splitIndex*236. If the remaining valid data length is greater than or equal to 236, 236 bytes are copied, otherwise all the remaining data are copied; finally, the CEND end identifier is added; after the motion detection message is encapsulated and sent, its picIndex counter is incremented by 1, and the splitIndex counter is reset to 0. Typically, when generating a motion detection message packet, the memory address offset of the copied 236 bytes of the motion detection message within the motion detection message is the data offset. The remaining valid data length refers to the length of the motion detection message data that needs to be assembled after the completed assembly when assembling or splitting the motion detection message. Typically, multiple motion detection message packets formed by splitting the same motion detection message have the same motion detection message packet sequence number, and multiple motion detection message packets with the same motion detection message packet sequence number have different internal block sequence numbers.
[0075] Some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol. After a motion detection message packet is generated, the count sequence number of the message packet counter is incremented by one, and the internal block sequence number counter of the motion detection message is reset to 0.
[0076] Some embodiments disclose a method for processing a network camera motion detection message based on a USB port UAC protocol, wherein the post-processing of the motion detection message packet includes a process of unpacking and repacking the motion detection message packet, such as Figure 3 As shown, the specific methods include:
[0077] When the data received by the Android box is greater than or equal to 256 bytes, it starts to extract the dynamic inspection message package;
[0078] Search for the start marker, determine the starting position S1, and then determine whether the data of S1 plus 252 is the end marker;
[0079] If not, add 8 to S1 as the new starting position S1 and search for the starting mark again;
[0080] If yes, extract the dynamic inspection message packet information and perform byte order conversion; then enter the subsequent dynamic inspection message assembly process;
[0081] The process of assembling dynamic inspection messages includes:
[0082] Start assembling the motion detection message and receive the motion detection message packet. Usually, a motion detection message may be packaged into multiple motion detection message packets. Assembly of the motion detection message usually means unpacking and assembling the multiple motion detection message packets obtained by splitting the same motion detection message into packets to obtain a complete motion detection message.
[0083] Determine whether the message packet sequence numbers of the last motion detection message packet and the currently received motion detection message packet are consistent;
[0084] If the message packet sequence number of the previous motion detection message packet is consistent with that of the currently received motion detection message packet, then further determine whether the internal block sequence number of the currently received motion detection message packet is 1 greater than the internal block sequence number of the previous motion detection message packet. If not, discard it; if so, extract the currently received motion detection message, copy the data in the received motion detection information packet to the buffer of the assembly application, and the memory offset address copied in the buffer is splitIndex*236, and a fixed 236 bytes is copied. Finally, determine whether the current motion detection information is received through dataSize; after completion, submit it to the motion detection message processing module for processing;
[0085] If the message packet sequence number of the previous motion detection message packet is inconsistent with the currently received motion detection message packet, it is further determined whether the internal block sequence number of the currently received motion detection message packet is 0; if it is not 0, it is discarded; if it is 0, the internal block sequence number of the currently received motion detection message packet is set to -1, and the message packet sequence number of the currently received motion detection message packet is used as the sequence number of the current motion detection message, and the total data length of the currently received motion detection message packet is set to 0; usually, the Android box end may start to receive UAC data in the middle. If it is found that splitIndex=0 in its motion detection message packet, it means that the first split-generated packet of the motion detection information has been received. At this time, the currently received picIndex is set to the picIndex number of the currently received motion detection message packet, and the data length is set to 0;
[0086] Then extract the current dynamic inspection message; copy the data in the currently received dynamic inspection information package to the assembly application buffer. The memory offset address copied in the buffer is splitIndex*236, and a fixed 236 bytes is copied. Finally, determine whether the dynamic inspection information has been received through dataSize; after completion, submit it to the dynamic inspection message processing module for processing;
[0087] Furthermore, in some embodiments, it is also necessary to determine whether the total data length of the received motion detection message packets with the same message packet sequence number is greater than or equal to the total data length of the current motion detection message; if not, continue to assemble the current motion detection message; if so, the assembly of the current motion detection message is completed; set the message packet sequence number and internal block sequence number of the motion detection message packet expected to be received next time, and clear the received data length to zero.
[0088] Some embodiments disclose a method for processing a network camera motion detection message based on a USB port UAC protocol, wherein the assembled motion detection message enters a motion detection message processing module for processing.
[0089] Some embodiments disclose a method for processing motion detection messages of a network camera based on the USB port UAC protocol, which includes repeated filtering and disorderly discarding of motion detection message packets during the unpacking and repacking process of the motion detection messages.
[0090] Some embodiments disclose methods for processing dynamic detection messages for webcams based on the USB port UAC protocol, further comprising configuring the webcam kernel's sound card device. Typically, the webcam IPC kernel configuration includes sound card-related configurations, such as USB Audio / MIDI drivers, USB DRD Core support, and USB gadget UAC support. Furthermore, the webcam is configured to generate a sound card node upon startup and to disable the webcam's UAC audio function.
[0091] Furthermore, you need to compile and connect the alsa-lib open source library, and import the relevant configuration into the IPC end. The initialization of alsa calls the snd_pcm_open and snd_pcm_hw_params_xxx series functions; write data to the uac sound card function snd_pcm_writei to implement alsa support.
[0092] Typically, the Android kernel configuration supports the UAC function by default. The sound framework on the Android box usually supports UAC sound input by default. To prevent the webcam's motion detection message packets from being captured by the Android system's sound framework, you need to use Libusb to unbind the UAC corresponding to the webcam's USB port from the kernel driver. This ensures that the Android system's sound framework does not mistakenly intercept motion detection messages as audio information.
[0093] Some embodiments disclose a method for processing a network camera motion detection message based on the USB port UAC protocol, further comprising a method for connecting the network camera to an Android box end, wherein the network camera and the UAC device on the Android box end are connected to each other, such as Figure 4 As shown, specifically including:
[0094] Android box registers USB hot plug monitoring event;
[0095] After the network camera's sound card device is configured, the Android box monitors the corresponding state change event, calls the callback function, and handles the hot plug event in the callback function;
[0096] Obtain USB device description information and determine whether the USB device is a network camera USB device based on the product name, manufacturer and serial number;
[0097] If not, the UAC device connection process will not be performed. Generally, if the USB device is determined to be a non-webcam device based on the product name, manufacturer and serial number, it can be determined to be another USB device, such as a USB storage device, microphone, etc., that is, the USB device will be ignored and the UAC device connection process between the webcam and the Android box will be stopped.
[0098] If so, obtain the configuration of each USB port and extract the device control port, data transmission port, and sampling rate information corresponding to the network camera USB device UAC;
[0099] Usually, after calling libusb_open in the callback function to open the corresponding USB device, libusb_get_device_descriptor is called to obtain the USB device description information. The device's product name, manufacturer, and serial number are used to determine whether it is the corresponding network camera IPC USB device to prevent normal USB devices from being misjudged. If it is determined to be a network camera USB device, libusb_get_config_descriptor is called to obtain the configuration of each USB port and extract the device control port, data transmission port, and sampling rate information corresponding to the UAC.
[0100] Unbind the device control port corresponding to UAC from the Android kernel driver and start data transmission and reception of the device control port;
[0101] Select the supported data sampling rate through the unbound device control port. Usually, you can call libusb_control_transfer through the device control port to select the supported data sampling rate. For example, you can select a sampling rate of 8000.
[0102] Unbind the data transmission port corresponding to UAC from the Android kernel driver and start data transmission and reception on the data transmission port. Usually, you can call libusb_detach_kernel_driver to unbind the UAC control port from the Android kernel driver, that is, uninstall the sound card corresponding to / dev / snd / pcmCx, where x is a number, i.e. the sound card number. And enable libusb_claim_interface to control the use permission of the device control port through the libusb module. Use the same steps to unbind the UAC data receiving port from the Android kernel driver and enable libusb to send and receive data.
[0103] Start the UAC data receiving thread.
[0104] The disclosed method for processing webcam motion detection messages based on the USB port UAC protocol in an embodiment of the present invention packages the webcam's motion detection message and transmits it as an audio message to an Android box via the USB port UAC protocol. Upon receiving the motion detection message packet, the Android box unpacks and processes it, and then processes the motion detection message. This method omits the serial port connection hardware between the webcam and the Android box, reducing hardware costs, avoiding signal interference between the USB cable and the serial port cable, and improving the stability of motion detection message transmission. The method has promising application prospects in the Android smart terminal device industry.
[0105] The technical solutions and technical details disclosed in the embodiments of the present invention are merely illustrative of the inventive concept of the present invention and do not constitute a limitation on the technical solutions of the embodiments of the present invention. Any conventional changes, replacements or combinations of the technical details disclosed in the embodiments of the present invention have the same inventive concept as the present invention and are within the scope of protection of the claims of the present invention.
Claims
1. A method for processing a network camera motion detection message based on a USB port UAC protocol, characterized in that: include: The motion detection module of the network camera detects the motion of the object, generates a motion detection message, and sends a motion detection message sending request; In response to the motion detection message sending request, the motion detection message is packaged to generate a motion detection message packet, and the motion detection message packet is written into the sound card device of the network camera; the data structure of the motion detection message packet is a start identifier, a total data length, a packet sequence number, an internal block sequence number, data and an end identifier arranged in sequence; wherein, the total length of the motion detection message packet is 256 bytes, the start identifier is an 8-byte length SWPICUAC; the total data length is a 4-byte length of the motion detection message data length; the packet sequence number is a generated 2-byte message sequence number; the internal block sequence number is a sequence number of the split motion detection message internal block, which is a 2-byte unsigned short integer data; the data refers to the motion detection message data, including the generation time, location, size, and picture, with a maximum of 236 bytes; the end identifier is a 4-byte length CEND; The sound card device of the network camera sends the dynamic detection message packet as audio information to the Android box through the USB port UAC protocol; The Android box receives the dynamic inspection message package and performs post-processing.
2. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 1, characterized in that: The method of generating a dynamic inspection message packet by encapsulating the dynamic inspection message packet includes: The replication start marker SWPICUAC; Add the total data length of the current dynamic inspection message; Add the packet number of the current dynamic inspection message; Add the internal block number of the current dynamic inspection message packet; Copy the current dynamic inspection message data; Load the end marker CEND and generate an animal inspection message package.
3. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 2 is characterized in that: The data offset of the motion detection message data is the internal block number * 236. If the remaining valid data length is greater than or equal to 236 bytes, only 236 bytes are copied when the motion detection message is copied, otherwise all the remaining data are copied.
4. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 2, characterized in that: After the motion detection message packet is generated, the count sequence number of the message packet counter is incremented by 1, and the internal block sequence number counter of the motion detection message is reset to 0.
5. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 1, characterized in that: The post-processing of the dynamic detection message packet includes the process of unpacking and repacking the dynamic detection message packet. The specific methods include: When the data received by the Android box is greater than or equal to 256 bytes, it starts to extract the dynamic inspection message package; Search for the start mark, determine the start position S1, and then determine whether the data of S1 plus 252 is the end mark; If not, add 8 to S1 as the new starting position S1 and search for the starting mark again; If yes, extract the dynamic inspection message packet information and perform byte order conversion; then enter the subsequent dynamic inspection message assembly process; The dynamic inspection message assembly process includes: Start assembling the dynamic inspection message; receive the dynamic inspection message package; Determine whether the message packet sequence numbers of the last motion detection message packet and the currently received motion detection message packet are consistent; If the message packet sequence number of the previous motion detection message packet is consistent with that of the currently received motion detection message packet, further determine whether the internal block sequence number of the currently received motion detection message packet is 1 greater than the internal block sequence number of the previous motion detection message packet. If not, discard it; if so, extract the currently received motion detection message; If the message packet sequence number of the previous motion detection message packet is inconsistent with the currently received motion detection message packet, further determine whether the internal block sequence number of the currently received motion detection message packet is 0; if it is not 0, discard it; if it is 0, set the internal block sequence number of the currently received motion detection message packet to -1, use the message packet sequence number of the currently received motion detection message packet as the sequence number of the current motion detection message, and set the total data length of the currently received motion detection message packet to 0; then extract the currently received motion detection message; Further, determine whether the total data length of the received motion detection message packets with the same message packet sequence number is greater than or equal to the total data length of the current motion detection message; if so, the current motion detection message assembly is completed; if not, continue to assemble the current motion detection message.
6. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 5, characterized in that: The assembled dynamic inspection message enters the dynamic inspection message processing module for processing.
7. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 5, characterized in that: The process of unpacking and packing the animal inspection message also includes repeated filtering and disorderly discarding of the animal inspection message packets.
8. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 1, characterized in that: It also includes configuring the kernel's sound card device for the webcam.
9. The method for processing network camera motion detection messages based on USB port UAC protocol according to claim 7, characterized in that: It also includes the connection method between the webcam and the Android box, including: The Android box registers the USB hot-plug monitoring event; After the sound card device of the network camera is configured, the Android box monitors the corresponding state change event, calls the callback function, and handles the hot plug event in the callback function; Obtain the USB device description information and determine whether the USB device is a network camera USB device based on the product name, manufacturer and serial number; If not, no UAC device connection processing is performed; If so, obtain the configuration of each USB port and extract the device control port, data transmission port, and sampling rate information corresponding to the network camera USB device UAC; Unbind the device control port corresponding to UAC from the Android kernel driver; Select the supported data sampling rate through the unbound device control port; Unbind the data transmission port corresponding to UAC from the Android kernel driver and start data transmission and reception of the data transmission port; Start the UAC data receiving thread.
Citation Information
Patent Citations
Message processing method and device and electronic system
CN115499491A
Data processing method and device and multimedia data acquisition equipment
CN118075604A