Multi-process video stream sharing method based on dynamic data distribution
By using dynamic data allocation and shared memory technology in audio and video office software, the problem of low transmission efficiency of video stream data between multiple processes is solved, efficient video stream sharing and rendering is achieved, and system performance and user experience are improved.
Patent Information
- Application Number
- CN202410768494.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-27
AI Technical Summary
In audio and video office software, the transmission of video stream data between multiple processes is cumbersome and inefficient, and may lead to cache failure and frequent page exchanges, reducing system performance and the speed and efficiency of inter-process data sharing.
Adopt a multi-process video stream sharing method based on dynamic data allocation, dynamically calculate and allocate a fixed size shared memory space through shared memory space and synchronization mechanism, use video ID to identify the memory area, and circular queue management data writing to ensure that reading and Synchronization of write operations, dynamically adjusting memory size to adapt to changes in bit rate and frame rate of video streams.
It realizes fast and efficient sharing of video stream data among multiple processes, improves video rendering efficiency, reduces data transmission overhead and delay, ensures data security and system flexibility and scalability, and improves user experience.
Smart Images

Figure CN118714403A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of audio and video data processing, and in particular to a multi-process video stream sharing method based on dynamic data allocation, and is especially applicable to the design and implementation of sharing video stream data among multiple processes in calls or meetings of office software. Background Art
[0002] When using audio and video office software, video calls and video conferences are often used. The video function allows users to communicate face to face at work, greatly improving office efficiency.
[0003] In the development process of audio and video office software, the problem of sharing video stream data between multiple processes is often encountered. However, the transmission of video stream data between multiple processes is cumbersome and inefficient. When multiple processes frequently access and modify the same memory area, it may cause cache failure and frequent page swapping, thereby reducing system performance and reducing the speed and efficiency of data sharing between processes.
[0004] Therefore, how to quickly and efficiently share video stream data between multiple processes has become a problem that everyone has to think about. Summary of the invention
[0005] In order to solve the problems in the prior art that video stream data is cumbersome and inefficient when transmitted between multiple processes, the purpose of the present invention is to provide a multi-process video stream sharing method based on dynamic data allocation. The method realizes fast and efficient sharing of video stream data between multiple processes through memory sharing, thereby improving the video rendering efficiency.
[0006] The present invention achieves the above-mentioned purpose through the following technical solutions:
[0007] A multi-process video stream sharing method based on dynamic data allocation, the method comprising the following steps:
[0008] Determine the size of the shared memory space, how to manage it, and the synchronization mechanism between processes;
[0009] When opening a user video, dynamically calculate and allocate a fixed-size shared memory space, and use the video ID to identify the shared memory area;
[0010] When receiving user video stream data, determine whether the shared memory area has been created based on the video ID. If it has been created, write the video stream data into the corresponding shared memory area based on the video ID;
[0011] When the video stream data needs to be rendered, the video stream data in the corresponding shared memory area is read according to the video ID. After the data is read, it is decoded according to the encoding method and data format of the video stream, and the decoded video frame is rendered on the interface.
[0012] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, when writing data, a circular queue or other data structure is used to manage the shared memory space to ensure that the data writing does not overwrite the unread data;
[0013] When reading data in a shared memory area, a synchronization mechanism is required to ensure that the read operation does not conflict with the write operation.
[0014] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, if the video stream data is transmitted in real time, the rendering process needs to continuously read data from the shared memory area and render it to maintain smooth video playback;
[0015] If there are multiple video streams in the system that need to be shared simultaneously, use multiple shared memory areas to store different video stream data separately.
[0016] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, when dynamically calculating and allocating a fixed-size shared memory space, the method includes the following steps:
[0017] Use the CreateFileMapping function in Windows to create a file mapping kernel object and specify the name of the file mapping object with the video ID;
[0018] Use the MapViewOfFile function in Windows to map the created file mapping object to the address space of the current application and obtain the memory space address.
[0019] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, when writing video stream data into a corresponding shared memory area according to a video ID, the method comprises the following steps:
[0020] Get video stream data from the video source;
[0021] The video stream data is copied from the source buffer to the shared memory area using the memory copy function through the memory space address.
[0022] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, when reading video stream data in a shared memory area, the method comprises the following steps:
[0023] Use the OpenFileMapping function in Windows to open the file mapping object with the name corresponding to the video ID;
[0024] Use the MapViewOfFile function in Windows to map the open file mapping object to the address space of the current application and obtain the memory space address;
[0025] The video stream data is read from the shared memory area using the memory copy function through the memory space address.
[0026] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, when processing video data, the encoding format is first determined, and according to the encoding format, the corresponding decoder is selected or implemented, and the compressed video frames are decoded into original pixel data or other intermediate formats using the decoder for subsequent processing or display; then, the frame rate is obtained, and when displaying the video, it is necessary to ensure that the video frames are played at the correct frame rate; if the frame rate of the video needs to be changed, the frame rate of the video is changed based on a direct combination method that does not consider the object motion information or a motion compensation method that uses the object motion information for compensatory interpolation; then, a timestamp is obtained and stored together with the video frame, and used to synchronize the audio and video streams; if the video needs to be edited or processed, the timestamp needs to be adjusted to reflect the new video stream structure or duration.
[0027] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, in order to consider the real-time performance and frame rate of the video stream, the size of the shared memory area is dynamically adjusted according to the bit rate and frame rate of the video stream in the implementation of the multi-process video stream sharing method, which specifically includes:
[0028] When a user video stream is opened for the first time, the initial shared memory space is allocated based on the expected bit rate and frame rate of the video stream;
[0029] Monitor the real-time bit rate of the video stream. If the actual bit rate is higher than the initial assumption, increase the size of the shared memory area to prevent memory overflow. On the contrary, if the actual bit rate is lower than the initial assumption and there is enough shared memory space, consider reducing the size of the shared memory area appropriately to save resources.
[0030] The size of the shared memory area is dynamically adjusted according to the actual value of the frame rate.
[0031] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, the following steps are further performed:
[0032] Set the upper and lower thresholds of memory usage. When the memory usage exceeds the upper threshold, the memory expansion operation is triggered; when the memory usage is lower than the lower threshold, the memory contraction operation is triggered. Among them, a smooth adjustment strategy is adopted, that is, only a small part of the memory size is adjusted each time, or a certain adjustment interval is set.
[0033] According to a multi-process video stream sharing method based on dynamic data allocation provided by the present invention, the following steps are further performed:
[0034] Monitor the usage of shared memory areas in real time. When the memory usage is too high, dynamically adjust the memory allocation strategy or take other measures to avoid memory overflow.
[0035] Perform resource limits and priority management on processes to ensure that critical processes have access to sufficient resources.
[0036] It can be seen that compared with the prior art, the present invention has the following beneficial effects:
[0037] 1. Dynamic resource allocation: The present invention can dynamically calculate and allocate a fixed-size shared memory space according to the actual needs of the user's video. This dynamic allocation strategy ensures the effective use of resources and avoids waste of resources. The present invention can accurately manage the resources of each video stream by identifying the shared memory area with the video ID, thereby improving the flexibility and scalability of the system.
[0038] 2. Efficient inter-process communication: The present invention uses shared memory space to store video stream data. This method avoids frequent copying and transmission of data between multiple processes, thereby reducing the overhead and delay of data transmission. Shared memory provides an efficient inter-process communication method, allowing multiple processes to quickly access and share video stream data.
[0039] 3. Optimize video processing: When video stream data needs to be rendered, this method can quickly read the video stream data in the corresponding shared memory area according to the video ID. This direct reading method reduces the data transmission and processing time, and improves the real-time and smoothness of video rendering. The decoding and rendering operations are based on the read video stream data. This process ensures the continuity and accuracy of video processing.
[0040] 4. Data security: By introducing a synchronization mechanism between processes, this method can ensure that simultaneous access to a shared memory area by multiple processes will not lead to data inconsistency or data corruption. This synchronization mechanism ensures data security and integrity.
[0041] 5. Improve user experience: Since this method can quickly process video stream data and render video frames in real time, it can improve the user's viewing experience and users can enjoy smooth and clear video playback effects.
[0042] In summary, the multi-process video stream sharing method based on dynamic data allocation of the present invention provides an efficient and reliable video stream sharing solution for the development of audio and video office software through the advantages of dynamic resource allocation, efficient inter-process communication, optimized video processing, data security, easy expansion and maintenance, and improved user experience.
[0043] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 The present invention is a flowchart of a multi-process video stream sharing method embodiment based on dynamic data allocation.
[0045] Figure 2 It is a schematic diagram of the system structure of multi-process video stream sharing in an embodiment of a multi-process video stream sharing method based on dynamic data allocation of the present invention.
[0046] Figure 3 The present invention is a flowchart of creating a shared memory space and writing video stream data in an embodiment of a multi-process video stream sharing method based on dynamic data allocation.
[0047] Figure 4 The present invention is a flowchart of reading memory data from a created shared memory in an embodiment of a multi-process video stream sharing method based on dynamic data allocation. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. 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.
[0049] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0050] Shared memory is a technology that allows multiple processes to share the same physical memory area. It allows multiple processes to directly access the data in the shared memory without copying, thereby achieving fast and efficient data sharing. In this case, video stream data can be stored in the shared memory area, and multiple processes can directly access the memory area, thereby achieving the sharing of video stream data, which is convenient, fast and efficient.
[0051] See also Figures 1 to 4 The present invention provides a multi-process video stream sharing method based on dynamic data allocation, the method comprising the following steps:
[0052] Step S1, determining the size of the shared memory space, the management method, and the synchronization mechanism between processes;
[0053] Step S2, when opening a user video, dynamically calculate and allocate a fixed-size shared memory space, and use the video ID to identify the shared memory area;
[0054] Step S3, when receiving the user video stream data, judging whether the shared memory area has been created according to the video ID, if it has been created, writing the video stream data into the corresponding shared memory area according to the video ID;
[0055] Step S4, when the video stream data needs to be rendered, the video stream data in the corresponding shared memory area is read according to the video ID. After the data is read, it is decoded according to the encoding method and data format of the video stream, and the decoded video frame is rendered on the interface.
[0056] In this embodiment, when writing data, a circular queue or other data structure is used to manage the shared memory space to ensure that data writing does not overwrite unread data; when reading data in the shared memory area, a synchronization mechanism is required to ensure that the read operation does not conflict with the write operation.
[0057] In this embodiment, if the video stream data is transmitted in real time, the rendering process needs to continuously read data from the shared memory area and render it to maintain smooth video playback; if there are multiple video streams in the system that need to be shared at the same time, multiple shared memory areas are used to store different video stream data respectively.
[0058] In the above step S2, when dynamically calculating and allocating a shared memory space of a fixed size, the following steps are included:
[0059] Use the CreateFileMapping function in Windows to create a file mapping kernel object and specify the name of the file mapping object with the video ID;
[0060] Use the MapViewOfFile function in Windows to map the created file mapping object to the address space of the current application and obtain the memory space address.
[0061] In the above step S3, when the video stream data is written into the corresponding shared memory area according to the video ID, the following steps are included:
[0062] Get video stream data from the video source;
[0063] The video stream data is copied from the source buffer to the shared memory area using the memory copy function through the memory space address.
[0064] In the above step S4, when reading the video stream data in the shared memory area, the following steps are included:
[0065] Use the OpenFileMapping function in Windows to open the file mapping object with the name corresponding to the video ID;
[0066] Use the MapViewOfFile function in Windows to map the open file mapping object to the address space of the current application and obtain the memory space address;
[0067] The video stream data is read from the shared memory area using the memory copy function through the memory space address.
[0068] In this embodiment, when processing video data, the encoding format is first determined, such as H.264, H.265 (HEVC), VP9, etc., which can be obtained from the metadata of the video stream; according to the encoding format, the corresponding decoder is selected or implemented. In Windows, such as Media Frameworks such as Foundation or DirectShow are used to handle different video encoding formats; decoders are used to decode compressed video frames into raw pixel data or other intermediate formats for subsequent processing or display; then, the frame rate is obtained, which defines the number of frames displayed per second in the video, which can be obtained from the metadata of the video stream; when displaying the video, it is necessary to ensure that the video frames are played at the correct frame rate, which can be achieved through a timer or synchronization mechanism to ensure smooth playback of the video; if the frame rate of the video needs to be changed, for example, converting a high frame rate video to a low frame rate to save bandwidth, the frame rate of the video can be changed based on a direct combination method that does not consider the object motion information or a motion compensation method that uses the object motion information for compensatory interpolation; then, a timestamp is obtained and stored with the video frame and used to synchronize the audio and video streams; if the video needs to be edited or processed (such as clipping, merging, transcoding, etc.), the timestamp needs to be adjusted to reflect the new video stream structure or duration.
[0069] In this embodiment, in order to consider the real-time performance and frame rate of the video stream, the size of the shared memory area is dynamically adjusted according to the bit rate and frame rate of the video stream, which specifically includes:
[0070] When a user video stream is opened for the first time, the initial shared memory space is allocated based on the expected bit rate and frame rate of the video stream;
[0071] Monitor the real-time bit rate of the video stream. If the actual bit rate is higher than the initial assumption, increase the size of the shared memory area to prevent memory overflow. On the contrary, if the actual bit rate is lower than the initial assumption and there is enough shared memory space, consider reducing the size of the shared memory area appropriately to save resources.
[0072] The size of the shared memory area is dynamically adjusted according to the actual value of the frame rate.
[0073] In this embodiment, the following is also performed:
[0074] Set the upper and lower thresholds of memory usage. When the memory usage exceeds the upper threshold, the memory expansion operation is triggered; when the memory usage is lower than the lower threshold, the memory contraction operation is triggered. Among them, a smooth adjustment strategy is adopted, that is, only a small part of the memory size is adjusted each time, or a certain adjustment interval is set.
[0075] In this embodiment, the following is also performed:
[0076] Monitor the usage of shared memory areas in real time. When the memory usage is too high, dynamically adjust the memory allocation strategy or take other measures to avoid memory overflow.
[0077] Perform resource limits and priority management on processes to ensure that critical processes have access to sufficient resources.
[0078] In practical applications, this embodiment achieves the target function by dynamically creating a shared memory space, writing video stream data into the shared memory space, and reading video stream data from the shared memory space. For example, a desktop multi-process video stream sharing method based on "Work Bao", which is a converged communication office system that provides the best solution for business office.
[0079] When dynamically creating shared memory space, use the CreateFileMapping function in Windows to create a file mapping kernel object and specify the name of the file mapping object with the video ID. The CreateFileMapping function is an API function in the Windows system and is located in the 'Windows.h' header file. Its function is to create a file mapping kernel object, which allows applications to map files to memory, so that multiple processes can share file contents in their address spaces, thereby achieving data sharing between processes. Its function prototype is as follows:
[0080]
[0081]
[0082] Use the MapViewOfFile function in Windows to map the created file mapping object to the address space of the current application and obtain the memory space address. The MapViewOfFile function is an API function in the Windows system, located in the 'Windows.h' header file. Its function is to map a file mapping object to the address space of the current process in order to access the data in the file mapping object. Its function prototype is as follows:
[0083]
[0084] When writing the video stream data into the shared memory space, the video stream data in yuv420p format is obtained, and the video stream data is copied to the corresponding memory through the memory space address using the memory copy method.
[0085] Use the OpenFileMapping function in Windows to open the file mapping object with the name corresponding to the video ID. The OpenFileMapping function is an API function in the Windows system, located in the 'Windows.h' header file. Its function is to open an existing file mapping object so that multiple processes can access the shared memory area. By opening an existing file mapping object, data sharing and communication between multiple processes can be achieved, and fast and efficient data sharing can be achieved. Multiple processes can directly access data in shared memory without copying and transmitting data. This can greatly improve the speed of data access and reduce system overhead, thereby facilitating collaboration and data exchange between processes. Its function prototype is as follows:
[0086]
[0087] Use the MapViewOfFile function in Windows to map the opened file mapping object to the address space of the current application and obtain the memory space address. The MapViewOfFile function is an API function in the Windows system, located in the 'Windows.h' header file. Its function is to map a file mapping object to the address space of the current process in order to access the data in the file mapping object. Its function prototype is as follows:
[0088]
[0089] The video stream data is read from the memory through the memory space address using the memory copy method.
[0090] In summary, the present invention can dynamically calculate and allocate a fixed-size shared memory space according to the actual needs of the user's video. This dynamic allocation strategy ensures the effective use of resources and avoids waste of resources. The present invention can accurately manage the resources of each video stream by identifying the shared memory area with a video ID, thereby improving the flexibility and scalability of the system. The present invention uses a shared memory space to store video stream data. This method avoids frequent copying and transmission of data between multiple processes, thereby reducing the overhead and delay of data transmission. Shared memory provides an efficient inter-process communication method, so that multiple processes can quickly access and share video stream data. When it is necessary to render video stream data, the present invention can quickly read the video stream data in the corresponding shared memory area according to the video ID. This direct reading method reduces the data transmission and processing time, and improves the real-time and smoothness of video rendering. The decoding and rendering operations are performed based on the read video stream data. This process ensures the continuity and accuracy of video processing. The present invention introduces an inter-process synchronization mechanism. This method can ensure that simultaneous access to the shared memory area by multiple processes will not cause data inconsistency or data damage. This synchronization mechanism ensures the security and integrity of the data. Since the present invention can quickly process video stream data and render video frames in real time, it can improve the user's viewing experience and the user can enjoy smooth and clear video playback effects.
[0091] Therefore, the multi-process video stream sharing method based on dynamic data allocation of the present invention provides an efficient and reliable video stream sharing solution for the development of audio and video office software through the advantages of dynamic resource allocation, efficient inter-process communication, optimized video processing, data security, easy expansion and maintenance, and improved user experience.
[0092] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0093] The above-mentioned embodiments are only preferred embodiments of the present invention and cannot be used to limit the scope of protection of the present invention. Any non-substantial changes and substitutions made by technicians in this field on the basis of the present invention shall fall within the scope of protection required by the present invention.
Claims
1. A multi-process video stream sharing method based on dynamic data allocation, characterized in that: The method comprises the following steps: Determine the size of the shared memory space, how to manage it, and the synchronization mechanism between processes; When opening a user video, dynamically calculate and allocate a fixed-size shared memory space, and use the video ID to identify the shared memory area; When receiving user video stream data, determine whether the shared memory area has been created based on the video ID. If it has been created, write the video stream data into the corresponding shared memory area based on the video ID; When the video stream data needs to be rendered, the video stream data in the corresponding shared memory area is read according to the video ID. After the data is read, it is decoded according to the encoding method and data format of the video stream, and the decoded video frame is rendered on the interface.
2. The method according to claim 1, characterized in that: When writing data, use a circular queue or other data structure to manage the shared memory space to ensure that data writes do not overwrite unread data; When reading data in a shared memory area, a synchronization mechanism is required to ensure that the read operation does not conflict with the write operation.
3. The method according to claim 1, characterized in that: If the video stream data is transmitted in real time, the rendering process needs to continuously read data from the shared memory area and render it to maintain smooth video playback; If there are multiple video streams in the system that need to be shared simultaneously, use multiple shared memory areas to store different video stream data separately.
4. The method according to claim 1, characterized in that: When dynamically calculating and allocating a fixed-size shared memory space, the following steps are included: Use the CreateFileMapping function in Windows to create a file mapping kernel object and specify the name of the file mapping object with the video ID; Use the MapViewOfFile function in Windows to map the created file mapping object to the address space of the current application and obtain the memory space address.
5. The method according to claim 1, characterized in that: When writing the video stream data into the corresponding shared memory area according to the video ID, the following steps are included: Get video stream data from the video source; The video stream data is copied from the source buffer to the shared memory area using the memory copy function through the memory space address.
6. The method according to claim 1, characterized in that: When reading video stream data in the shared memory area, the following steps are included: Use the OpenFileMapping function in Windows to open the file mapping object with the name corresponding to the video ID; Use the MapViewOfFile function in Windows to map the open file mapping object to the address space of the current application and obtain the memory space address; The video stream data is read from the shared memory area using the memory copy function through the memory space address.
7. The method according to claim 1, characterized in that: When processing video data, first determine the encoding format, select or implement the corresponding decoder based on the encoding format, and use the decoder to decode the compressed video frames into raw pixel data or other intermediate formats for subsequent processing or display; then, obtain the frame rate. When displaying the video, it is necessary to ensure that the video frames are played at the correct frame rate; if the frame rate of the video needs to be changed, the frame rate of the video is changed based on a direct combination method that does not consider the object motion information or a motion compensation method that uses the object motion information for compensatory interpolation; then, obtain a timestamp and store it together with the video frame, and use it to synchronize the audio and video streams; if the video needs to be edited or processed, the timestamp needs to be adjusted to reflect the new video stream structure or duration.
8. The method according to claim 1, characterized in that: In the implementation of the multi-process video stream sharing method, in order to consider the real-time performance and frame rate of the video stream, the size of the shared memory area is dynamically adjusted according to the bit rate and frame rate of the video stream, which specifically includes: When a user video stream is opened for the first time, the initial shared memory space is allocated based on the expected bit rate and frame rate of the video stream; Monitor the real-time bit rate of the video stream. If the actual bit rate is higher than the initial assumption, increase the size of the shared memory area to prevent memory overflow. On the contrary, if the actual bit rate is lower than the initial assumption and there is enough shared memory space, consider reducing the size of the shared memory area appropriately to save resources. The size of the shared memory area is dynamically adjusted according to the actual value of the frame rate.
9. The method according to claim 8, characterized in that Also execute: Set the upper and lower thresholds of memory usage. When the memory usage exceeds the upper threshold, the memory expansion operation is triggered; when the memory usage is lower than the lower threshold, the memory contraction operation is triggered. Among them, a smooth adjustment strategy is adopted, that is, only a small part of the memory size is adjusted each time, or a certain adjustment interval is set.
10. The method according to claim 9, characterized in that Also execute: Monitor the usage of shared memory areas in real time. When the memory usage is too high, dynamically adjust the memory allocation strategy or take other measures to avoid memory overflow. Perform resource limits and priority management on processes to ensure that critical processes have access to sufficient resources.
Citation Information
Cited By
Real-time multi-camera synchronization method and system based on multiple processes
CN121037514A
Data processing method, and device
WO2026124230A1
