Cross-thread data flow transmission medium
By designing a cross-thread data flow delivery medium and using queues and custom containers to realize data delivery, the problem of instability of thread pipeline flow in the existing technology is solved, the reliability and real-time of data delivery are improved, and data integrity and real-time are ensured. sex.
Patent Information
- Application Number
- CN202411065101.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-11-19
AI Technical Summary
The existing PipedInputStream and PipedOutputStream cause unstable thread pipeline flow during the webcam sdk callback process, resulting in blocking problems, making it difficult to achieve stable cross-thread data transmission.
Design a cross-thread data stream delivery medium, including data containers, data entrances and data exits, realize data delivery through queues and custom containers, provide put() function and read function, support cache and refresh mechanisms, and ensure real-time data and integrity.
Improve the reliability and real-timeness of data transfer between threads. Manually set the size through queues and custom containers to ensure that data is not lost, and data preprocessing is implemented through function pointers, solving thread blocking and data stability problems.
Smart Images

Figure CN118984316A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cross-thread data stream transmission, in particular to a cross-thread data stream transmission medium. Background Art
[0002] In the process of connecting with the network camera, audio and video are obtained through the corresponding SDK, and video data is obtained through the corresponding callback audio. In another business thread, the data in the callback thread needs to be obtained for decoding and streaming. The existing implementation scheme. For example, the piped input stream PipedInputStream and the piped output stream PipedOutputStream in Java have similar functions, but each callback of the SDK is in a different thread. When using PipedInputStream and PipedInputStream, problems such as blocking in the callback thread will cause problems with the thread pipeline stream, which is extremely unstable to use.
[0003] Therefore, we propose a cross-thread data flow transmission medium to realize data transmission between threads, ensure stability, and customize the thread cache according to your own needs. When the thread is blocked, the data is refreshed to ensure the real-time performance of the data. Summary of the invention
[0004] The purpose of the present invention is to overcome the shortcomings of the prior art, adapt to actual needs, and provide a cross-thread data stream transmission medium to solve the technical problems that the current SDK callbacks in different threads each time, and when using PipedInputStream and PipedInputStream, the callback thread is blocked, which will cause problems with the thread pipeline flow and is extremely unstable to use.
[0005] In order to achieve the purpose of the present invention, the technical solution adopted by the present invention is: designing a cross-thread data stream transmission medium, including a cross-thread data stream transmission medium, the cross-thread data stream transmission medium includes a data container, a data inlet and a data outlet;
[0006] The cross-thread data stream transmission medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the steps of the cross-thread data stream transmission method. The steps of the cross-thread data stream transmission method are as follows:
[0007] S1: The input thread starts to read data from the hardware device or software and writes it to the medium through the put() function (it is also necessary to determine whether the container has turned on the blocking switch);
[0008] S2: Initialize the idle queue, data queue and a certain number of data containers. The idle queue stores containers without data, and the data queue stores containers with written data. The container objects can be defined by themselves.
[0009] S3: When writing data, if there is no free container or the free container space is insufficient, a free container is obtained from the free queue. After the free container is full of data, it is stored in the data queue.
[0010] S4: When the reading thread reads data, it reads from the data container. When there is no readable data in the data container or the data container is empty, the data container is taken out from the data queue;
[0011] S5: After reading the required data from the data container, corresponding operations such as transcoding, decoding, and data compensation can be defined according to business needs. These operations are injected into the medium through function pointers and similar methods and the corresponding execution order is specified. These operations are defined according to business needs;
[0012] S6: After the data container reads the data, if there is still data in the container, it proceeds to the next reading step. When there is no data to be read, it is returned to the idle queue;
[0013] S7: When the output thread reads data, if a large amount of historical data is found in the data queue, the data queue is manually refreshed to return the queue with data to the idle queue and write new data into the data queue to ensure the real-time nature of the data and achieve the refresh effect;
[0014] S8: The process defines a global start and global end operation through callback, so that the entire process starts and ends work, and recycles the data container and queue after the work ends;
[0015] S9: Some thread-related steps involved in the middle can be adjusted according to the business.
[0016] Preferably, after writing into the medium through the put() function in S1, it is also necessary to determine whether the blocking switch of the container is turned on.
[0017] Preferably, the data container is used to initialize a cache container. When data integrity needs to be ensured, the cache can ensure that data will not be lost when data transmission is abnormal. The size of the container can be adjusted according to demand, taking into account both real-time and integrity. The cache is reset after the data is read to ensure that data can be continuously written to the cache.
[0018] Preferably, the data entry is used to provide a data interface. At the thread generating the data, the data is written through this entry. The return value can indicate whether the data is written successfully. If the writing fails, an error can be reported or the exception can be recorded.
[0019] Preferably, the data export is used to provide a data interface, and the thread that needs data obtains the data generated by other threads through this interface, and blocks this thread at this interface to wait for data to be written or record the exception of data acquisition.
[0020] Compared with the prior art, the present invention has the following beneficial effects:
[0021] 1. The present invention uses queues and custom containers, and can manually set the container size and queue size, which can ensure both real-time performance and data integrity, and can effectively improve the reliability of data transmission between threads; during the data reading process, if there is too much data in the data queue, the historical data can be removed by refreshing the data to ensure the real-time performance of the data; at the same time, the data can be pre-processed in a custom manner during the data transmission process in a manner similar to a function pointer. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0023] The present invention is further described below in conjunction with the accompanying drawings and embodiments:
[0024] A medium for transferring data streams across threads, see Figure 1 , including a cross-thread data flow transmission medium, the cross-thread data flow transmission medium includes a data container, a data inlet and a data outlet;
[0025] The cross-thread data stream transmission medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the steps of the cross-thread data stream transmission method. The steps of the cross-thread data stream transmission method are as follows:
[0026] S1: The input thread starts to read data from the hardware device or software and writes it to the medium through the put() function (it is also necessary to determine whether the container has turned on the blocking switch);
[0027] S2: Initialize the idle queue, data queue and a certain number of data containers. The idle queue stores containers without data, and the data queue stores containers with written data. The container objects can be defined by themselves.
[0028] S3: When writing data, if there is no free container or the free container space is insufficient, a free container is obtained from the free queue. After the free container is full of data, it is stored in the data queue.
[0029] S4: When the reading thread reads data, it reads from the data container. When there is no readable data in the data container or the data container is empty, the data container is taken out from the data queue;
[0030] S5: After reading the required data from the data container, corresponding operations such as transcoding, decoding, and data compensation can be defined according to business needs. These operations are injected into the medium through function pointers and similar methods and the corresponding execution order is specified. These operations are defined according to business needs;
[0031] S6: After the data container reads the data, if there is still data in the container, it proceeds to the next reading step. When there is no data to be read, it is returned to the idle queue;
[0032] S7: When the output thread reads data, if a large amount of historical data is found in the data queue, the data queue is manually refreshed to return the queue with data to the idle queue and write new data into the data queue to ensure the real-time nature of the data and achieve the refresh effect;
[0033] S8: The process defines a global start and global end operation through callback, so that the entire process starts and ends work, and recycles the data container and queue after the work ends;
[0034] S9: Some thread-related steps involved in the middle can be adjusted according to the business, working principles and benefits.
[0035] For details, see Figure 1 After S1 writes data to the medium through the put() function, it is necessary to determine whether the container has opened the blocking switch.
[0036] For further information, see Figure 1 The data container is used to initialize a cache container. When data integrity needs to be ensured, the cache can ensure that data will not be lost when data transmission is abnormal. The size of the container can be adjusted according to needs, taking into account both real-time and integrity. The cache is reset after the data is read to ensure that data can be continuously written to the cache.
[0037] It is worth noting that see Figure 1 The data entry is used to provide a data interface. At the thread that generates the data, the data is written through this entry. The return value can indicate whether the data is written successfully. If the writing fails, an error can be reported or the exception can be recorded.
[0038] It is worth noting that see Figure 1 The data export is used to provide a data interface. The thread that needs data can obtain the data generated by other threads through this interface. The thread is blocked at this interface to wait for data to be written or record the exception of data acquisition.
[0039] Embodiment 1
[0040] The present invention describes the process of cross-thread data flow transmission in the form of pseudo code, and the pseudo code is as follows:
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048] In addition, the components designed in the present invention are all universal standard parts or components known to technical personnel in this field. Their structures and principles can be known to technical personnel through technical manuals or through conventional experimental methods. They can be fully implemented by technical personnel in this field. Needless to say, the content protected by the present invention does not involve improvements to internal structures and methods.
[0049] The embodiments of the present invention disclose preferred embodiments, but are not limited thereto. A person skilled in the art can easily understand the spirit of the present invention based on the above embodiments and make different extensions and changes. However, as long as they do not deviate from the spirit of the present invention, they are all within the protection scope of the present invention.
Claims
1. A cross-thread data stream transmission medium, comprising a cross-thread data stream transmission medium, It is characterized in that The cross-thread data flow transmission medium includes a data container, a data inlet and a data outlet; The cross-thread data stream transmission medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the steps of the cross-thread data stream transmission method. The steps of the cross-thread data stream transmission method are as follows: S1: The input thread starts to read data from the hardware device or software and writes it to the medium through the put() function (it is also necessary to determine whether the container has turned on the blocking switch); S2: Initialize the idle queue, data queue and a certain number of data containers. The idle queue stores containers without data, and the data queue stores containers with written data. The container objects can be defined by themselves. S3: When writing data, if there is no free container or the free container space is insufficient, a free container is obtained from the free queue. After the free container is full of data, it is stored in the data queue. S4: When the reading thread reads data, it reads from the data container. When there is no readable data in the data container or the data container is empty, the data container is taken out from the data queue; S5: After reading the required data from the data container, corresponding operations such as transcoding, decoding, and data compensation can be defined according to business needs. These operations are injected into the medium through function pointers and similar methods and the corresponding execution order is specified. These operations are defined according to business needs; S6: After the data container reads the data, if there is still data in the container, it proceeds to the next reading step. When there is no data to be read, it is returned to the idle queue; S7: When the output thread reads data, if a large amount of historical data is found in the data queue, the data queue is manually refreshed to return the queue with data to the idle queue and write new data into the data queue to ensure the real-time nature of the data and achieve the refresh effect; S8: The process defines a global start and global end operation through callback, so that the entire process starts and ends work, and recycles the data container and queue after the work ends; S9: Some thread-related steps involved in the middle can be adjusted according to the business.
2. A cross-thread data stream transmission medium as claimed in claim 1, It is characterized in that After the data is written into the medium by the put() function in S1, it is necessary to determine whether the container has opened the blocking switch.
3. A cross-thread data stream transmission medium as claimed in claim 1, It is characterized in that The data container is used to initialize a cache container. When data integrity needs to be ensured, the cache can ensure that data will not be lost when data transmission is abnormal. The size of the container can be adjusted according to needs, taking into account both real-time and integrity. The cache is reset after the data is read to ensure that data can be continuously written to the cache.
4. A cross-thread data stream transmission medium as claimed in claim 1, It is characterized in that The data entry is used to provide a data interface. At the thread that generates the data, the data is written through this entry. The return value can indicate whether the data is written successfully. If the writing fails, an error can be reported or the exception can be recorded.
5. A cross-thread data stream transmission medium as claimed in claim 1, It is characterized in that The data export is used to provide a data interface. At the thread that needs data, the data generated by other threads is obtained through this interface. The thread is blocked at this interface to wait for data to be written or to record the exception of data acquisition.
