Memory multiplexing method, electronic device, and computer-readable storage medium
By setting the cache size and time according to the cache size and decoding rate in the multimedia data processing system, memory resources are dynamically reused, solving the resource waste and fragmentation problems caused by static partitioning and dynamic management, and achieving efficient memory utilization and continuity of multimedia tasks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- UBTECH ROBOTICS CORP LTD
- Filing Date
- 2026-01-28
- Publication Date
- 2026-06-05
AI Technical Summary
Existing memory allocation methods result in low resource utilization in multimedia data processing systems. Static partitioning causes idle memory to be unavailable for other tasks, while dynamic management leads to memory fragmentation, making it difficult to balance the continuity of core multimedia tasks with the execution needs of auxiliary tasks.
By obtaining the cache size and decoding rate of the first multimedia data in the first buffer of the device memory, setting the second cache size and generating the decoding time of the second multimedia data, if the first time is greater than the preset time, the second multimedia data is cached in the buffer, thereby realizing dynamic reuse of memory resources.
It improves memory resource utilization, reduces memory fragmentation, ensures the continuity of multimedia tasks, and enhances the stability of the multimedia data processing system.
Smart Images

Figure CN122152499A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a memory reuse method, electronic device, and computer-readable storage medium. Background Technology
[0002] In modern multimedia data processing systems, memory resource management is a core factor determining device performance and stability. Multimedia data is typically continuous and real-time; improper memory allocation can easily lead to data delays or frame drops, impacting user experience. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this application provides a memory reuse method, an electronic device, and a computer-readable storage medium, which can improve memory resource utilization, reduce memory fragmentation, ensure the continuity of multimedia tasks, and improve the stability of multimedia data processing systems.
[0004] Firstly, this application provides a memory reuse method, which includes:
[0005] Obtain the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer; Based on the first buffer size, decoding rate, and first buffer, a second buffer size for buffering the first multimedia data is set, and a first time for decoding the second multimedia data in the first buffer is generated; the first buffer size is greater than or equal to the second buffer size. If the first time exceeds the preset second time, the second multimedia data is cached in the first buffer.
[0006] Secondly, this application also provides a memory multiplexing device, which includes: The acquisition unit is used to acquire the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer. The generation unit is configured to set a second buffer size for buffering the first multimedia data based on the first buffer size, the decoding rate, and the first buffer, and generate a first time for decoding the second multimedia data in the first buffer; the first buffer size is greater than or equal to the second buffer size. A caching unit is used to cache second multimedia data in a first buffer if the first time is longer than a preset second time.
[0007] Thirdly, embodiments of the present invention provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the memory reuse method provided in the first aspect above.
[0008] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the memory reuse method provided in the first aspect.
[0009] Fifthly, embodiments of this application also provide a computer program product, including a computer program or instructions, wherein the computer program or instructions are executed by a processor using the memory reuse method provided in the first aspect.
[0010] The memory reuse method provided in this application obtains the first cache size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer. Based on the first cache size, the decoding rate and the first buffer, a second cache size for caching the first multimedia data is set. A first time for decoding the second multimedia data in the first buffer is generated. Then, when the first time is greater than a preset second time, the second multimedia data is cached in the first buffer. This can effectively reuse memory resources, improve memory resource utilization, reduce memory fragmentation, ensure the continuity of multimedia tasks, and thus improve the stability of the multimedia data processing system. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is an application scenario diagram of the memory reuse method provided in the embodiments of this application; Figure 2 This is a first flowchart illustrating the memory reuse method provided in an embodiment of this application; Figure 3 This is a second flowchart illustrating the memory reuse method provided in an embodiment of this application; Figure 4 A schematic block diagram of a memory multiplexing device provided in an embodiment of this application; Figure 5 A schematic block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0015] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0016] It should also be further understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0017] Furthermore, in this application, unless otherwise explicitly specified or limited in the embodiments, the terms "installation," "connection," "joining," and "fixing" appearing in the embodiments should be interpreted broadly. For example, a connection can be a fixed connection, a detachable connection, or an integral part; it can also be a mechanical connection, an electrical connection, etc. Of course, it can also be a direct connection, or an indirect connection through an intermediate medium, or it can be the internal communication between two components, or the interaction between two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific implementation.
[0018] In related technologies, with the popularization of applications such as high-definition video, audio streaming, and image processing, multimedia data processing systems need to process massive amounts of data in real time, thus placing higher demands on the read and write speed, capacity allocation, and management efficiency of device memory.
[0019] Current memory allocation methods include static partitioning and dynamic management. Static partitioning can allocate fixed-size memory regions to different tasks, such as reserving specific capacity for audio decoding tasks and reserving another portion for image preloading tasks. However, when a task is not in an active state, its allocated memory region remains idle for a long time and cannot be called by other tasks, resulting in low overall memory resource utilization.
[0020] Dynamic memory management temporarily allocates memory space during task execution. However, frequent allocation and deallocation operations cause memory fragmentation, resulting in a large number of discrete small free areas that are difficult to meet the needs of subsequent larger memory requests, further reducing memory usage efficiency. Especially in resource-constrained environments such as embedded devices, this often leads to task interruptions or system response delays, making it difficult to balance the continuity of core multimedia tasks with the execution requirements of auxiliary tasks.
[0021] Therefore, how to dynamically coordinate memory allocation based on real-time status, and effectively reuse idle memory resources while ensuring the smooth operation of critical tasks, is a technical problem that urgently needs to be solved.
[0022] To address this, this application provides a memory reuse method. By obtaining the first cache size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer, and setting a second cache size for caching the first multimedia data according to the first cache size, the decoding rate, and the first buffer, a first time for decoding the second multimedia data in the first buffer is generated. Then, when the first time is greater than a preset second time, the second multimedia data is cached in the first buffer. This effectively reuses memory resources, improves memory resource utilization, reduces memory fragmentation, ensures the continuity of multimedia tasks, and thus improves the stability of the multimedia data processing system.
[0023] Please see Figure 1 , Figure 1 This diagram illustrates an application scenario of the memory reuse method provided in this application. The memory reuse method provided in this application can be applied to a terminal device 110. The terminal device 110 includes a device memory 111 and a hardware timer 112. The device memory 111 includes a first buffer 1111 and a second buffer 1112. The first buffer 1111 is configured to cache first multimedia data for decoding. The first multimedia data can be audio data. The second buffer 1112 can cache decoded second multimedia data, which can be images. The first buffer 1111 can be an audio decoding buffer, and the second buffer 1112 can be a display buffer. The hardware timer 112 can be configured to time the decoding of the second multimedia data cached in the first buffer 1111, ensuring that the first multimedia data in the first buffer 1111 can be replenished in a timely manner. The terminal device 110 can be a mobile phone, laptop, desktop computer, tablet, or other similar device.
[0024] It should be noted that the application scenarios described in the following embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0025] The memory reuse method provided in this application will be described in detail below.
[0026] like Figure 2 As shown, the method includes the following steps S210~S230.
[0027] S210. Obtain the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer. S220. Based on the first buffer size, decoding rate and first buffer, set the second buffer size for buffering the first multimedia data, and generate the first time to decode the second multimedia data in the first buffer; the first buffer size is greater than or equal to the second buffer size. S230. If the first time is greater than the preset second time, the second multimedia data is cached in the first buffer.
[0028] In this embodiment, the first buffer is set as a specific area in the device memory for temporarily storing the first multimedia data. The capacity and structure of the first buffer can be configured according to actual application requirements.
[0029] The first multimedia data can be understood as multimedia content that needs to be processed first or played continuously, such as audio or video streams. The first multimedia data is buffered in the first buffer and awaits decoding.
[0030] The first buffer size represents the amount of first multimedia data actually buffered in the first buffer at a given moment. The first buffer size reflects the current fill status of the first buffer.
[0031] Decoding rate can be understood as the speed at which the first multimedia data is read from the first buffer and decoded. Decoding rate is typically related to the encoding format of the multimedia data and playback requirements.
[0032] The second buffer size can be understood as a preset buffer size threshold for the first multimedia data in the first buffer, which is used as a basis for judging the sufficiency of the data in the first buffer when calculating the reusable time.
[0033] The second multimedia data can be understood as secondary multimedia content, such as image data or auxiliary information, temporarily cached in the first buffer. The second multimedia data is cached and decoded using the free memory resources within the first buffer without affecting the processing of the first multimedia data.
[0034] The first time is a time value that can be calculated based on the first buffer size, the second buffer size, and the decoding rate. The first time represents a safe time window during which the first buffer can be used to cache the second multimedia data without affecting the normal decoding of the first multimedia data.
[0035] The second time can be understood as a preset time threshold, which is used to determine whether the calculated first time is long enough to allow the second multimedia data to be cached in the first buffer.
[0036] Specifically, during memory reuse, this application can obtain the first cache size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer. The first cache size can be obtained from the data management module of the first buffer through periodic sampling or polling. The decoding rate can be obtained from the real-time decoding speed of the first multimedia data obtained from the decoder module. For example, this application can read the data volume of the first buffer at fixed time intervals and calculate the average decoding rate by combining the data volume read previously and the time interval.
[0037] After obtaining the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer, a first time for decoding the second multimedia data in the first buffer can be generated based on the first buffer size, the decoding rate, and the second buffer size. The second buffer size can be a preset fixed value. For example, it can be set to a certain percentage of the first buffer capacity. The first time can be calculated by dividing the difference between the first buffer size and the second buffer size by the decoding rate, thereby securely supporting the duration of the second multimedia data caching operation.
[0038] Meanwhile, having a first cache size greater than or equal to a second cache size ensures that the cached amount of the first multimedia data in the first buffer is relatively sufficient during subsequent calculations and operations, providing a safe foundation for subsequent memory reuse operations. If the first cache size is lower than the second cache size, it may indicate that the amount of data in the first buffer is insufficient. In this case, memory reuse operations should not be performed to avoid affecting the normal processing of the first multimedia data.
[0039] Furthermore, after generating the first time, it can be determined whether the first time is greater than the second time. If it is greater, the second multimedia data is cached in the first buffer. The second time can be an empirical value, such as 200 milliseconds, representing the minimum safe time required for caching the second multimedia data. When the calculated first time satisfies the condition of being greater than the preset second time, it is determined that a sufficiently long safe time window exists, allowing memory reuse. The second multimedia data can then be written to the first buffer and cached using this idle time period. For example, when the first time is calculated to be 3.6 seconds and the preset second time is 200 milliseconds, the operation of caching the second multimedia data in the first buffer will be triggered. The formula for calculating the first time can be: T_budget=(L_current-L_low) / R_decode Where L_current is the first buffer size, i.e. the current buffer data size (KB); L_low is the second buffer size, i.e. the buffer size corresponding to the low watermark (KB); and R_decode is the first multimedia data decoding rate, which can be the data consumption rate of audio decoding and playback (KB / s).
[0040] In this application, by monitoring the status of the first multimedia data in the first buffer in real time and intelligently deciding whether to cache the second multimedia data in the first buffer based on a precisely calculated time window, dynamic and efficient reuse of device memory resources can be achieved, effectively avoiding the resource waste caused by traditional static partitioning and the memory fragmentation problem caused by dynamic management, and improving the overall utilization of memory.
[0041] In some embodiments, setting a second buffer size for caching the first multimedia data based on the first buffer size, the decoding rate, and the first buffer, and generating a first time for decoding the second multimedia data in the first buffer, includes: generating the amount of data for decoding the first multimedia data in the first buffer based on the first buffer size and the second buffer size; and generating the first time based on the amount of data and the decoding rate.
[0042] In this embodiment, the amount of data to be decoded in the first buffer is generated based on the first buffer amount and the second buffer amount, so as to know how much data to decode from the first multimedia data without affecting the continuous playback of the first multimedia data, thereby providing an accurate basis for subsequent time calculation.
[0043] Specifically, the amount of data to be decoded in the first buffer can be generated in several ways. For example, it can be determined by calculating the difference between the current first buffer size and the second buffer size. If the first buffer size represents the amount of first multimedia data already cached in the first buffer, and the second buffer size represents the minimum safe buffer size (i.e., low watermark) set to ensure continuous playback of the first multimedia data, then the amount of data to be decoded is the portion of the current buffer size that exceeds the minimum safe buffer size. Alternatively, the first buffer size can be compared with a preset upper limit threshold (e.g., high watermark) used to trigger the caching operation of the second multimedia data, and the amount of data to be decoded from the current buffer size to the upper limit threshold can be calculated to free up space for the second multimedia data without affecting the playback of the first multimedia data.
[0044] Meanwhile, in the process of generating the first time based on the data volume and the decoding rate, this application can combine the decodeable data volume with the actual decoding rate of the first multimedia data to convert it into a specific time length, namely the first time. This allows the time required to decode a specific amount of data within the first buffer to serve as a safe window period for determining whether memory reuse can be safely performed.
[0045] In this application, by calculating time in steps, the uncertainty of time calculation can be resolved, improving the accuracy and reliability of memory reuse decisions. This ensures that the calculation is based on the difference between the current cache state and the set threshold, accurately quantifying the amount of data to be processed and avoiding the deviation that may be introduced by direct estimation. At the same time, by using the decoding rate to convert the amount of data into time values, the time budget calculation can be made more consistent with the actual decoding process, enhancing the accuracy of judging the safe window period. This ensures that the playback of the first multimedia data will not be interrupted during memory reuse operations, while maximizing the utilization efficiency of memory resources.
[0046] In some embodiments, before caching the second multimedia data in the first buffer, the method further includes: interrupting the reading of the first multimedia data from the HTTPS data packet to suspend caching the first multimedia data in the HTTPS data packet into the first buffer; and decoding the first multimedia data in the first buffer to obtain the decoded first multimedia data.
[0047] In this embodiment, interrupting the reading of the first multimedia data from the HTTPS data packet pauses the caching of the first multimedia data in the HTTPS data packet into the first buffer, thereby stopping new first multimedia data from continuing to flow into the first buffer.
[0048] Specifically, this application can prevent data from entering system memory by sending a pause command to the network data receiving module to temporarily stop it from receiving HTTPS data packets from the network interface; or, this application can modify the status flag in the data stream processing logic so that even if HTTPS data packets are received, their content will not be written to the first buffer, but will be temporarily discarded or buffered in other temporary areas.
[0049] In addition, this application can also truncate the data stream by temporarily closing or suspending the network socket or file handle associated with HTTPS packet reading, thereby ensuring that existing data in the first buffer is not accidentally overwritten by new, unprocessed data during memory reuse operations, thus freeing up safe and stable space for subsequent second multimedia data caching operations.
[0050] Simultaneously, the first multimedia data in the first buffer is decoded to obtain the decoded first multimedia data, which can then be converted from the original encoding format into a decoding format that can be further used by the system.
[0051] During the decoding of the first multimedia data, the device's built-in hardware decoder or software decoding library can be invoked to parse and process the original multimedia data blocks in the first buffer. For example, compressed audio or video data can be decompressed into PCM or YUV format. Alternatively, the data in the first buffer can be transmitted to a dedicated decoding processing unit, which will perform the decoding operation and store the decoding result in a designated memory area or send it directly to the playback / display module. This ensures that all received first multimedia data in the first buffer is processed in a timely and complete manner before the second multimedia data is cached, avoiding interruption or loss of data processing due to task switching. At the same time, the space occupied by the decoded data in the first buffer is released to prepare for the caching of the second multimedia data.
[0052] In this application, by interrupting the reading of first multimedia data from HTTPS packets before caching second multimedia data in the first buffer, the inflow of new data is effectively paused, preventing the first buffer from being accidentally filled or overwritten by new first multimedia data during task switching. Then, the existing first multimedia data in the first buffer is decoded, ensuring that all received first multimedia data can be processed in a timely and complete manner and converted into a usable format. This not only solves the problem that first multimedia data may be overwritten before processing during memory reuse, leading to data loss or discontinuous playback, but also provides clear and usable memory space for caching subsequent second multimedia data by timely processing and releasing the data in the first buffer, thereby ensuring a smooth transition in the memory reuse process and the continuity and integrity of multimedia tasks.
[0053] In some embodiments, caching second multimedia data in a first buffer includes: loading the second multimedia data into the first buffer to cache the second multimedia data in the first buffer; decoding the second multimedia data in the first buffer to obtain decoded second multimedia data; and caching the decoded second multimedia data into a second buffer that matches the second multimedia data.
[0054] In this embodiment, by loading the second multimedia data into the first buffer to cache the second multimedia data into the first buffer, the second multimedia data to be processed can be read from its original storage location (e.g., local storage device, network server) into the first buffer in the device memory, providing a data source for subsequent decoding operations and realizing memory reuse of the first buffer.
[0055] During the process of loading the second multimedia data into the first buffer to cache the second multimedia data in the first buffer, the second multimedia data can be read as a data stream through a file I / O interface or network protocol stack, and sequentially written into the memory area reserved in the first buffer. This can improve data transmission efficiency and reduce CPU overhead. Alternatively, at the operating system level, this application can directly map the file containing the second multimedia data to the virtual address space of the first buffer through memory-mapped files, thereby realizing data "loading" and "caching". When the memory area is accessed, the file is automatically loaded.
[0056] Furthermore, this application decodes the second multimedia data in the first buffer to obtain the decoded second multimedia data, which can convert the original compressed format second multimedia data (e.g., JPEG format image data) loaded into the first buffer into an uncompressed format (e.g., RGB pixel data) that can be directly processed or displayed by the system.
[0057] Specifically, this application can directly read compressed data from the first buffer by calling a specific multimedia decoding library (e.g., an image decoder) built into the device, and generate decoded data in another specified area within the first buffer or in a temporarily allocated memory space.
[0058] Meanwhile, after obtaining the decoded second multimedia data, this application can cache the decoded second multimedia data into a second buffer that matches the second multimedia data for subsequent display, rendering or other specific processing, while releasing the first buffer so that it can continue to be used for other tasks.
[0059] During the process of caching the decoded second multimedia data into a second buffer that matches the second multimedia data, the second buffer can be directly pointed to the area in the first buffer that stores the decoded data through memory address remapping or pointer passing, or the decoded data can be directly written into the second buffer, thereby avoiding unnecessary data copying and improving efficiency.
[0060] In this application, loading the second multimedia data into the first buffer allows for direct use of existing memory space for data caching, avoiding the overhead of additional memory allocation and improving memory utilization. Decoding the second multimedia data in the first buffer reuses the same memory region for decoding operations, reducing data transfer between different memory regions and thus improving processing efficiency. Finally, the decoded second multimedia data is cached in a second buffer that matches the second multimedia data. Isolation storage is achieved based on data type matching, effectively preventing potential conflicts between the second and first multimedia data. This ensures the reliability and data integrity of the overall memory reuse process, enabling safe and efficient multitasking and data processing with limited memory resources. In particular, it effectively supports other tasks (such as image preloading) without interrupting core tasks such as audio playback.
[0061] In some embodiments, caching the second multimedia data in the first buffer further includes: if the second multimedia data is not cached in the first buffer within a preset third time period, interrupting the caching of the second multimedia data in the first buffer; and continuing to read the first multimedia data from the HTTPS data packet to cache the first multimedia data in the HTTPS data packet into the first buffer.
[0062] In this embodiment, the third time can be understood as a pre-set time threshold, which is used to measure the expected duration for the second multimedia data to be cached in the first buffer. The third time can be set based on factors such as the size of the second multimedia data, the expected network transmission rate, and the device's I / O performance, through empirical values or calculation models. For example, for image data of a specific size, an empirical loading and decoding time, such as 200 milliseconds, can be set.
[0063] In addition, the third time can be dynamically adjusted, for example, by dynamically calculating and updating based on real-time parameters such as the current load and the rate of decrease in the buffer level of the first multimedia data through an adaptive algorithm.
[0064] Specifically, when this application detects that the second multimedia data has not been cached in the first buffer within a third time period, it can interrupt the caching operation of the second multimedia data in the first buffer to forcibly stop the caching of the second multimedia data and release the right to use the first buffer to ensure the priority of the core task (i.e., the processing of the first multimedia data).
[0065] During the interruption process, this application can send an interrupt signal to the module responsible for caching the second multimedia data or set an interrupt flag. For example, the interrupt can be triggered by a hardware timer or by a software mechanism (such as setting a timeout callback function) to forcibly terminate the current data transmission or decoding operation and clean up the relevant temporary resources.
[0066] Simultaneously, after interrupting the caching of the second multimedia data, this application can immediately continue reading the first multimedia data from the HTTPS data packet to cache the first multimedia data in the first buffer, thereby quickly restoring the network download and caching of the first multimedia data and rapidly replenishing the level of the first buffer to ensure its continuity. Continuing to read the first multimedia data from the HTTPS data packet can be achieved by reactivating or resuming the HTTPS data packet reading task. For example, after interrupting the caching of the second multimedia data, a state machine can be used for management. When the second multimedia data caching is interrupted, the state machine immediately switches to the first multimedia data download state and triggers corresponding network requests and data write operations to ensure the rapid recovery of the data stream.
[0067] In this application, by introducing a timeout interrupt and recovery mechanism, the problem that excessive time consumption of the second multimedia data cache during memory reuse may lead to interruption of the first multimedia data processing or depletion of the buffer level is effectively solved. At the same time, the caching process of the second multimedia data is strictly monitored by a third time. If the caching is not completed within the specified time, the caching of the second multimedia data is immediately interrupted, thereby preventing it from occupying the first buffer resources for a long time and quickly restoring the reading and caching of the first multimedia data. This ensures that the first buffer level is replenished in a timely manner, guarantees the continuity, real-time performance, and user experience of the core audio service, ensures the stability of high-priority tasks, avoids system stagnation caused by cache timeout, and improves overall reliability and real-time performance.
[0068] In some embodiments, caching the second multimedia data in the first buffer further includes: if the amount of data decoded in the first multimedia data in the first buffer reaches the difference between the first buffer amount and the second buffer amount, and the second multimedia data has not been cached in the first buffer, interrupting the caching of the second multimedia data in the first buffer; and continuing to read the first multimedia data from the HTTPS data packet to cache the first multimedia data in the HTTPS data packet into the first buffer.
[0069] In this embodiment, the difference between the first buffer size and the second buffer size can be understood as the maximum amount of data consumed in decoding the first multimedia data in the first buffer during the process of loading the second multimedia data in the first buffer. When the amount of data decoded in the first multimedia data in the first buffer reaches the difference between the first buffer size and the second buffer size, it can be determined that the amount of first multimedia data in the first buffer has reached the low water level warning line. In order to ensure that the first multimedia data is replenished in the first buffer, it is necessary to immediately resume reading the first multimedia data from the HTTPS data packet to cache the first multimedia data in the HTTPS data packet into the first buffer.
[0070] Based on this, if the second multimedia data is not cached in the first buffer, the ongoing second multimedia data caching operation needs to be stopped immediately. Specifically, this can be achieved by sending an interrupt signal or stop instruction to the module responsible for caching the second multimedia data, so that it immediately stops writing data to the first buffer.
[0071] In this application, when the amount of first multimedia data decoded in the first buffer reaches the difference between the first cache size and the second cache size, it indicates that the consumption of core multimedia data (such as audio streams) is approaching the risk point that may lead to interruption. At the same time, the caching task of non-core second multimedia data (such as image preloading) has not yet been completed. This allows the system to interrupt the caching of second multimedia data in a timely and decisive manner, avoiding non-core tasks from continuing to occupy valuable memory resources and processing bandwidth, thereby immediately releasing resources. At the same time, this application quickly resumes reading the first multimedia data from HTTPS packets and caching it in the first buffer, ensuring the timely replenishment of the core multimedia data stream. This effectively solves the problem that the continuity and real-time performance of core multimedia services may be compromised due to secondary tasks occupying resources during memory reuse. It greatly improves the stability and user experience of the system in complex multi-tasking environments and guarantees the absolute priority of core services.
[0072] In some embodiments, the memory reuse method further includes: if the first cache size reaches a third cache size set by the first buffer to cache the first multimedia data, interrupting the reading of the first multimedia data from the HTTPS data packet to pause caching the first multimedia data in the HTTPS data packet into the first buffer; and caching the second multimedia data in the first buffer.
[0073] In this embodiment, the third buffer size is a pre-set threshold, which can be understood as the higher water level or near-full state of the first buffer. When the first buffer size reaches or exceeds the third buffer size, it can be determined that the first buffer has stored enough first multimedia data. At this time, it is advisable to pause the inflow of first multimedia data to free up resources for other tasks.
[0074] Specifically, this application can periodically check the current data volume of the first buffer. When the data volume reaches or exceeds the third buffer volume, it interrupts the reading of the first multimedia data from the HTTPS data packet to pause the caching of the first multimedia data in the HTTPS data packet into the first buffer, and caches the second multimedia data in the first buffer.
[0075] In this application, when the first cache size reaches the third cache size set by the first buffer to cache the first multimedia data, the reading of the first multimedia data is immediately interrupted and the second multimedia data is cached. This avoids the delay that may be caused by time calculation decisions when the buffer is close to saturation, thereby effectively solving the risks of inefficient reuse of memory resources, overfilled buffers and task switching delays. It realizes the reuse of memory regions, and can complete seamless task switching without additional memory allocation. It significantly optimizes memory sharing efficiency and improves the overall system response speed and resource utilization.
[0076] In some embodiments, before obtaining the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer, the method further includes: dividing the first buffer of preset memory in the device memory according to the first multimedia data, and setting a high watermark and a low watermark of the first buffer; generating a second buffer size according to the low watermark and the preset memory, and generating a third buffer size according to the high watermark and the preset memory.
[0077] In this embodiment, the present application may reserve and allocate a continuous or non-contiguous storage area in the memory space of the device for processing the first multimedia data, so as to provide a dedicated temporary storage place for the first multimedia data, so as to isolate the data of different tasks and thereby improve the data processing efficiency.
[0078] For example, at startup, this application may statically allocate a contiguous physical memory region from the device memory as a first buffer based on a preset fixed size (such as 96KB); or, at runtime, it may dynamically request a memory region that meets the requirements as a first buffer through the memory management unit based on the type, bitrate, or expected processing volume of the first multimedia data.
[0079] The high-water mark and low-water mark of the first buffer can be understood as two preset thresholds within the first buffer, used to indicate the state of the data volume in the buffer. The high-water mark indicates that the buffer is close to full, while the low-water mark indicates that the data volume in the buffer is low. The high-water mark and low-water mark serve as reference points for monitoring the buffer status, used to trigger or stop data read / write operations to effectively prevent buffer overflow or underloading. For example, this application can set the high-water mark to a certain percentage of the total capacity of the first buffer (e.g., 80%), and the low-water mark to another percentage of the total capacity (e.g., 20%).
[0080] The second buffer size can be understood as a key parameter for whether memory reuse operations can be performed safely. The second buffer size is closely related to the low watermark, and thus ensures that sufficient first multimedia data is still retained in the first buffer during memory reuse to avoid decoding interruption due to insufficient data. For example, the second buffer size can be directly set to the same amount of data as the low watermark, that is, when the amount of data in the first buffer drops to or below this value, memory reuse operations are not performed.
[0081] The third buffer size is a threshold used to trigger an interruption of the first multimedia data read and to begin caching the second multimedia data. The third buffer size optimizes memory reuse timing, prevents the first buffer from overflowing, and ensures that resource switching only occurs when the buffer has sufficient data, thereby improving system responsiveness and efficiency. For example, the third buffer size can be directly set to the same amount of data as the high-water mark; that is, when the amount of data in the first buffer reaches or exceeds this value, a memory reuse operation is triggered.
[0082] In this application, a first buffer of preset memory is divided by the first multimedia data, and a high watermark and a low watermark are set. A second buffer amount is generated based on the low watermark, and a third buffer amount is generated based on the high watermark. This allows for precise determination of when memory reuse can be safely performed, avoiding interruption of core multimedia data decoding due to insufficient data in the first buffer, thus ensuring the continuity and stability of core services. It also effectively prevents buffer overflow and provides sufficient time for loading the second multimedia data, ensuring the integrity and feasibility of the memory reuse method. Furthermore, by precisely controlling the timing of task switching, memory utilization is maximized, and the smoothness of core multimedia data playback is guaranteed.
[0083] In the memory reuse method provided in this embodiment of the invention, by obtaining the first cache amount of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer, and setting a second cache amount for caching the first multimedia data according to the first cache amount, the decoding rate and the first buffer, a first time for decoding the second multimedia data in the first buffer is generated. Then, when the first time is greater than a preset second time, the second multimedia data is cached in the first buffer, thereby effectively reusing memory resources, improving memory resource utilization, reducing memory fragmentation, ensuring the continuity of multimedia tasks, and thus improving the stability of the multimedia data processing system.
[0084] In some embodiments, such as Figure 3 As shown, this application provides a memory reuse method, which specifically includes the following steps: System initialization: The system is initialized and parameters are set. At the same time, a 96KB contiguous area is allocated from the device memory to be used entirely as an audio decoding buffer. The high watermark and low watermark of the buffer are set. For example, the high watermark is 80%, corresponding to a data volume of 96KB × 80% = 76.8KB, and the low watermark is 20%, corresponding to a data volume of 96KB × 20% = 19.2KB. The audio decoding playback speed (MP3 format, 128kbps bitrate) is R_decode = 16KB / s. Real-time monitoring and calculation: Assuming the current parameters are as follows: network download speed R_net = 20KB / s, and the current audio data filling amount in the audio decoding buffer is 80%, then: current audio data L_current = 96KB × 80% = 76.8KB, low watermark data amount = 96KB × 20% = 19.2KB, then the safe time to occupy is: T_budget = (L_current - low watermark data amount) / R_decode = (76.8KB / s - 19.2KB) / 16KB / s = 3.6s.
[0085] L_current=3.6s is greater than 200ms, triggering the safety window period; Memory Switching and Image Loading: Pause HTTPS packet reading and immediately switch the use of the shared memory area to the image preloading task. At the same time, the image preloading task reads the next frame of display image (such as a 15KB JPEG image) from the SD card into the audio decoding buffer for decoding. After decoding, the image is about 16KB and sent to the display buffer. Switching back to normal operation: Set a hardware timer with a timeout of 200ms. When the hardware timer times out or the audio buffer level drops to the low water level (30%) in advance, regardless of whether the image loading is complete or not, this application will immediately interrupt the preloading image task and unconditionally return the memory usage rights to the HTTPS download task to ensure that the audio data in the audio buffer can be replenished in a timely manner.
[0086] The memory reuse method provided in this application achieves highly efficient and intelligent memory reuse. Specifically, it establishes memory reuse on a computable deterministic basis, enabling a single 96KB physical memory to safely and efficiently serve two high-load tasks, with memory utilization approaching 100%. Simultaneously, this application can stably generate a safe window period of 200ms to 3.6s, sufficient to load and decode a JPG grayscale image. Furthermore, it reduces UI switching latency and ensures zero-interruption audio playback. Forced switching via a hardware timer guarantees the real-time performance and reliability of audio tasks under all circumstances. In addition, this application has low hardware costs and is easily integrated into existing embedded multimedia frameworks.
[0087] In some embodiments, the present invention also provides a memory reuse apparatus 300 for performing any of the aforementioned memory reuse methods.
[0088] Specifically, please refer to Figure 4 , Figure 4 This is a schematic block diagram of the memory reuse device 300 provided in an embodiment of the present invention.
[0089] like Figure 4 As shown, the memory multiplexing device 300 provided in this application includes: an acquisition unit 310, a generation unit 320, and a cache unit 330.
[0090] The acquisition unit 310 is used to acquire the first cache size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer; the generation unit 320 is used to generate a first time for decoding the second multimedia data in the first buffer based on the first cache size, the second cache size, the decoding rate, and the second cache size set in the first buffer for caching the first multimedia data; the first cache size is greater than or equal to the second cache size; the caching unit 330 is used to cache the second multimedia data in the first buffer if the first time is greater than the preset second time.
[0091] The memory reuse device 300 provided in this application embodiment can obtain the first cache amount of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer, and set a second cache amount for caching the first multimedia data according to the first cache amount, the decoding rate and the first buffer, generate a first time for decoding the second multimedia data in the first buffer, and then cache the second multimedia data in the first buffer when the first time is greater than a preset second time, thereby effectively reusing memory resources, improving memory resource utilization, reducing memory fragmentation, ensuring the continuity of multimedia tasks, and thus improving the stability of the multimedia data processing system.
[0092] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned memory reuse device and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.
[0093] The aforementioned memory multiplexing device can be implemented as a computer program, which can, for example, Figure 5 It runs on the electronic device shown.
[0094] Please see Figure 5 , Figure 5 This is a schematic block diagram of the electronic device 400 provided in an embodiment of the present invention.
[0095] See Figure 5 The electronic device 400 includes a processor 402, a memory, and a network interface 405 connected via a system bus 401. The memory may include a storage medium 403 and internal memory 404.
[0096] The storage medium 403 may store an operating system 4031 and a computer program 4032. When the computer program 4032 is executed, it causes the processor 402 to perform a memory reuse method.
[0097] The processor 402 provides computing and control capabilities to support the operation of the entire electronic device 400.
[0098] The internal memory 404 provides an environment for the execution of the computer program 4032 in the non-volatile storage medium 403. When the computer program 4032 is executed by the processor 402, the processor 402 can perform a memory reuse method.
[0099] This network interface 405 is used for network communication, such as providing data transmission. Those skilled in the art will understand that... Figure 5The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the electronic device 400 to which the present invention is applied. The specific electronic device 400 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0100] The processor 402 is used to run a computer program 4032 stored in the memory to perform the following functions: obtain the first cache size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer; based on the first cache size, the decoding rate and the first buffer, set a second cache size for caching the first multimedia data, and generate a first time for decoding the second multimedia data in the first buffer; the first cache size is greater than or equal to the second cache size; if the first time is greater than the preset second time, cache the second multimedia data in the first buffer.
[0101] Those skilled in the art will understand that Figure 5 The embodiments of the electronic device 400 shown do not constitute a limitation on the specific configuration of the electronic device 400. In other embodiments, the electronic device 400 may include more or fewer components than shown, or combine certain components, or have different component arrangements. For example, in some embodiments, the electronic device 400 may include only a memory and a processor 402. In such embodiments, the structure and function of the memory and processor 402 are different from those shown. Figure 5 The embodiments shown are consistent and will not be repeated here.
[0102] It should be understood that, in this embodiment of the invention, the processor 402 may be a Central Processing Unit (CPU), or it may be another general-purpose processor 402, a digital signal processor 402 (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor 402 may be a microprocessor 402, or it may be any conventional processor 402, etc.
[0103] According to one aspect of this application, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the following steps: obtaining a first buffer size of first multimedia data in a first buffer of device memory and a decoding rate of the first multimedia data in the first buffer; setting a second buffer size for buffering the first multimedia data according to the first buffer size, the decoding rate, and the first buffer size; generating a first time for decoding second multimedia data in the first buffer; the first buffer size being greater than or equal to the second buffer size; and if the first time is greater than a preset second time, buffering the second multimedia data in the first buffer.
[0104] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0105] In another embodiment of the present invention, a computer storage medium is provided. This storage medium may be a non-volatile computer-readable storage medium or a volatile storage medium. The storage medium stores a computer program 4032, wherein when executed by a processor 402, the computer program 4032 performs the following steps: obtaining a first buffer size of first multimedia data in a first buffer of device memory and a decoding rate of the first multimedia data in the first buffer; setting a second buffer size for buffering the first multimedia data according to the first buffer size, the decoding rate, and the first buffer, generating a first time for decoding the second multimedia data in the first buffer; the first buffer size being greater than or equal to the second buffer size; and if the first time is greater than a preset second time, buffering the second multimedia data in the first buffer.
[0106] The storage medium can be any computer-readable storage medium that can store program code, such as a USB flash drive, external hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0107] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0108] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0109] The steps in the methods of this application embodiment can be adjusted, merged, or deleted according to actual needs. The units in the apparatus of this application embodiment can be merged, divided, or deleted according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0110] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods provided in the various embodiments of this application.
[0111] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A memory reuse method, characterized in that, include: Obtain the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer; Based on the first buffer size, the decoding rate, and the first buffer, a second buffer size for caching the first multimedia data is set, and a first time for decoding the second multimedia data in the first buffer is generated. The first cache size is greater than or equal to the second cache size; If the first time is greater than the preset second time, the second multimedia data is cached in the first buffer.
2. The memory reuse method according to claim 1, characterized in that, The step of setting a second buffer size for caching the first multimedia data based on the first buffer size, the decoding rate, and the first buffer, and generating a first time for decoding the second multimedia data within the first buffer, includes: Based on the first cache size and the second cache size, generate the amount of data to decode the first multimedia data in the first buffer; The first time is generated based on the amount of data and the decoding rate.
3. The memory reuse method according to claim 1, characterized in that, Before caching the second multimedia data in the first buffer, the method further includes: Interrupt reading the first multimedia data from the HTTPS packet to pause caching the first multimedia data in the HTTPS packet into the first buffer; The first multimedia data in the first buffer is decoded to obtain the decoded first multimedia data.
4. The memory reuse method according to claim 3, characterized in that, The step of caching the second multimedia data in the first buffer includes: The second multimedia data is loaded into the first buffer to cache the second multimedia data in the first buffer; In the first buffer, the second multimedia data is decoded to obtain the decoded second multimedia data; The decoded second multimedia data is cached in a second buffer that matches the second multimedia data.
5. The memory reuse method according to claim 4, characterized in that, The step of caching the second multimedia data in the first buffer further includes: If the second multimedia data is not cached in the first buffer within the preset third time period, the caching of the second multimedia data in the first buffer will be interrupted. Continue reading the first multimedia data from the HTTPS data packet to cache the first multimedia data in the HTTPS data packet into the first buffer.
6. The memory reuse method according to claim 4, characterized in that, The step of caching the second multimedia data in the first buffer further includes: If the amount of data decoded in the first multimedia data in the first buffer reaches the difference between the first buffer amount and the second buffer amount, and the second multimedia data has not been fully cached in the first buffer, the caching of the second multimedia data in the first buffer is interrupted. Continue reading the first multimedia data from the HTTPS data packet to cache the first multimedia data in the HTTPS data packet into the first buffer.
7. The memory reuse method according to any one of claims 1-6, characterized in that, The method further includes: If the first cache size reaches the third cache size set by the first buffer to cache the first multimedia data, the reading of the first multimedia data from the HTTPS data packet is interrupted to pause the caching of the first multimedia data in the HTTPS data packet into the first buffer. The second multimedia data is cached in the first buffer.
8. The memory reuse method according to claim 7, characterized in that, Before obtaining the first buffer size of the first multimedia data in the first buffer of the device memory and the decoding rate of the first multimedia data in the first buffer, the method further includes: Based on the first multimedia data, a first buffer of preset memory is allocated in the device memory, and a high watermark and a low watermark are set for the first buffer. The second cache size is generated based on the low watermark and the preset memory, and the third cache size is generated based on the high watermark and the preset memory.
9. An electronic device, characterized in that, The system includes a memory and a processor, the memory storing a computer program, characterized in that the processor executes the computer program to implement the steps of the memory reuse method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the memory reuse method as described in any one of claims 1 to 8.