A method, device and storage medium for optimizing audio and video codec memory
By analyzing the life cycle of variables in audio and video codecs, and grouping them into corresponding memory units, the problem of large memory consumption of audio and video codecs is solved, and memory optimization and performance improvement are achieved.
Patent Information
- Application Number
- CN202011447342.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-09
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-12-09
AI Technical Summary
Existing audio and video codecs have high CPU usage due to dynamic memory allocation methods, and static memory allocation requires familiarity with the memory usage life cycle, affecting portability and cost, and has strict restrictions on memory consumption.
By analyzing the life cycle of variables in the audio and video codec, groups are merged into corresponding memory units to reduce memory consumption. Variable grouping and maximum variable merging strategies with no intersection in life cycles are used to optimize memory allocation.
It realizes the optimization of audio and video codec memory, reduces memory consumption, improves codec performance and portability, and reduces product cost.
Smart Images

Figure CN112506660B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of memory optimization, and in particular to a method, device and storage medium for optimizing the memory of an audio and video codec. Background Art
[0002] There are two existing memory allocation methods: 1. Use dynamic memory allocation. When a continuous memory block is needed, a continuous memory block is allocated to it. When a continuous memory block is not needed, the continuous memory block occupied by it is released. This (NEW / FREE method) or (Malloc / Free method) dynamic memory allocation method will get the lowest memory usage. Each data unit is allocated according to its complete life cycle, that is, when it starts to be used and released when it ends. 2. Use static memory allocation. During initialization, a fixed-size memory is allocated and divided into two types: (1) It is a global fixed and independently used memory area. Each variable occupies a fixed position and does not need to be shared with other variables; (2) It is a shared memory area similar to a draft paper. When a continuous data block needs to use memory, it is allocated at a fixed position in this memory block. When it is used up, this dirty memory, that is, the area where the content has been invalidated, continues to be allocated and used by other modules.
[0003] In the prior art, since the encoding and decoding process of the audio and video codec is relatively complicated, a large number of data units will be input / output to each module in each operation step, and the dynamic memory allocation method will seriously affect its encoding and decoding performance, resulting in an increase in the CPU's occupancy of the processor's million operations required for audio samples per second; therefore, commercial audio and video codecs cannot use the method of dynamically allocating and releasing memory, and the static memory allocation method requires that the module users of the codec are very familiar with the composition of the shared memory area, whether the modules and data blocks before the current operation module have ended their memory usage life cycle, and other information; moreover, audio and video codecs are mainly used in embedded platforms based on MCU / DSP, for example, decoders are mainly used for headphones; therefore, they have strict restrictions on the size of the memory, and excessive memory consumption will affect its portability and increase product costs. Summary of the invention
[0004] The purpose of the present application is to provide a method, device and storage medium for optimizing the memory of an audio and video codec in order to solve the problem of large memory consumption of an audio and video codec in the prior art.
[0005] To achieve the above-mentioned purpose, a technical solution adopted in the present application is: to provide a method for optimizing the memory of an audio and video codec, comprising: according to the life cycle of each variable among multiple variables used by the audio and video codec, grouping variables with no intersection in life cycle so that the life cycle of each variable in each group has no intersection; in any two groups, the group with a smaller number of bytes corresponding to the largest variable in the two groups is regarded as a smaller group, and the other group is regarded as a larger group, and it is determined whether there is an intersection between the life cycles of the first largest variable corresponding to the smaller group and the second largest variable corresponding to the larger group; if there is no intersection, merging the smaller group whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable into the larger group, wherein the third variable is a variable in the larger group whose life cycle has an intersection with the first largest variable; and according to the final grouping result, allocating the same memory unit to the variables in each group.
[0006] Another technical solution adopted by the present application is: to provide a device for optimizing the memory of an audio and video codec, which includes: a module for grouping variables with no intersection in life cycles according to the life cycles of each variable among multiple variables used by the audio and video codec, so that the life cycles of each variable in each group have no intersection; a module for classifying, in any two groups, the group with a smaller number of bytes corresponding to the largest variable in the two groups as a smaller group and the other group as a larger group, and judging whether there is any intersection between the life cycles of the first largest variable corresponding to the smaller group and the second largest variable corresponding to the larger group; a module for merging the smaller group whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable into the larger group if there is no intersection, wherein the third variable is a variable in the larger group whose life cycle has an intersection with the first largest variable; and a module for allocating corresponding identical memory units to the variables in each group according to the final grouping result.
[0007] Another technical solution adopted by the present invention is: providing a computer-readable storage medium storing computer instructions, which are operated to execute the method for optimizing the audio and video codec memory in solution one.
[0008] The beneficial effects of the present application are: providing a method, device and storage medium for optimizing the memory of an audio and video codec, by using a method of automatically constructing the memory structure of an audio and video codec by a life cycle analysis program of each module data unit, allocating corresponding memory units to multiple variables used in the audio and video codec, reducing memory consumption, and optimizing the memory of a given audio and video codec. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1It is a schematic diagram of a specific implementation method of the method for optimizing the memory of audio and video codecs of the present application;
[0010] Figure 2 It is a schematic diagram of a specific implementation method of optimizing the audio and video codec memory device of the present application. DETAILED DESCRIPTION
[0011] The preferred embodiments of the present application are described in detail below in conjunction with the accompanying drawings so that the advantages and features of the present application can be more easily understood by those skilled in the art, thereby making a clearer and more definite definition of the protection scope of the present application.
[0012] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0013] Figure 1 The flowchart diagram shows a specific implementation of the method for optimizing the audio and video codec memory of the present application.
[0014] exist Figure 1 In the specific implementation shown, the method for optimizing the audio and video codec memory of the present application includes process S101, process S102, process S103 and process S104.
[0015] Figure 1 The process S101 shown includes: according to the life cycle of each variable among a plurality of variables used by the audio and video codec, grouping the variables with non-intersecting life cycles into one group, so that the life cycles of the variables in each grouped group have no intersection.
[0016] In a specific embodiment of the present application, according to the life cycle of each variable among multiple variables used by the audio and video codec, the variables with non-intersecting life cycles are grouped into one group, so that the life cycles of each variable in each group are non-intersecting, including: grouping according to the memory size independently occupied by each variable with non-intersecting life cycles among the multiple variables, so that the difference between the memory sizes independently occupied by the variables in each group is minimized. Such a grouping method minimizes the memory occupied by multiple variables used by the audio and video codec.
[0017] In a specific example of the present application, preferably, first find variable A that occupies the largest number of bytes among multiple variables used by the audio and video codec, then find variable B that occupies the largest number of bytes and has no intersection with the life cycle of variable A among the remaining variables except variable A in descending order of the number of bytes occupied by each variable, and then find variable C that occupies the largest number of bytes and has no intersection with the life cycle of variable A and variable B among the remaining variables except variable A and variable B in descending order of the number of bytes occupied by each variable. Variable A, variable B, and variable C are divided into the first group.
[0018] In this specific example, if there is a variable D among the remaining variables except variable A, variable B and variable C whose life cycle has no intersection with variable A, variable B and variable C, then variable D will also be divided into the first group. The first group is grouped until there are no variables among the remaining variables whose life cycle has no intersection with the variables in the current first group.
[0019] In this specific example, if there are no variables other than variable A, variable B, variable C, and variable D whose life cycles have no intersection with variable A, variable B, variable C, and variable D, the first grouping is completed, and the remaining variables except variable A, variable B, variable C, and variable D are grouped into a second group in the same manner as the first group; until all the variables used by the audio and video codec participate in the grouping, the current grouping is completed.
[0020] Figure 1 The process S102 shown includes: in any two groups, the group with the smaller number of bytes corresponding to the largest variable in the two groups is defined as the smaller group, and the other group is defined as the larger group, and it is determined whether there is any intersection between the life cycles of the first largest variable corresponding to the smaller group and the second largest variable corresponding to the larger group.
[0021] In this specific embodiment, preferably, the variable with the largest number of bytes among the variables in the first group is found according to the number of bytes occupied by each variable, for example, the largest variable in the first group is variable A, and the variable with the largest number of bytes among the variables in the second group is found according to the number of bytes occupied by each variable, for example, the largest variable in the second group is variable E, and it is determined whether there is an intersection between the life cycles of variables A and E. The result of the determination is used as a prerequisite for the next step.
[0022] Figure 1 The process S103 shown includes: if there is no intersection, merging a smaller group whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable into a larger group, wherein the third variable is a variable in the larger group whose life cycle has an intersection with that of the first largest variable.
[0023] In a specific embodiment of the present application, a smaller group in which the sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable is merged into a larger group, and the larger group after the merger of the smaller group is judged with other groups so that the final groups can no longer be merged.
[0024] In a specific example of the present application, preferably, it is determined whether there is an intersection between the life cycles of variables A and E. If there is no intersection between the life cycles of variables A and E, then it is determined whether there is an intersection between the life cycles of variables B, C, and D in the first group and variable E, for example, if there is an intersection between the life cycles of variables D and E, the sum of the number of bytes occupied by variables D and E is compared with the number of bytes occupied by variable A. If the sum of the number of bytes occupied by variables D and E is less than or equal to the number of bytes occupied by variable A, the variables of the second group are merged into the first group; thereby further reducing memory consumption on the basis of the current grouping.
[0025] In a specific embodiment of the present application, a smaller group in which the sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable is merged into a larger group, and also includes: after adding a padding jump variable to each variable in the smaller group, the smaller group is assigned to the larger group.
[0026] In a specific example of the present application, preferably, a padding jump variable is added to all variables of the second group, so that each variable of the second group can share the same memory unit with the variables of the first group. The bytes occupied by the padding jump variable are not less than the number of bytes of the variable with the largest number of bytes among the remaining variables in the first group except variable A.
[0027] In a specific embodiment of the present application, if the sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable in the larger group is greater than the number of bytes occupied by the second largest variable, the two groups are judged separately from the other groups.
[0028] In a specific example of the present application, preferably, if the life cycles of variables D and E intersect, the sum of the number of bytes occupied by variables D and E is compared with the number of bytes occupied by variable A. If the sum of the number of bytes occupied by variables D and E is greater than the number of bytes occupied by variable A, the first group and the second group cannot be merged at this time, and the first group and the second group can be judged, merged, and other operations can be performed separately with other groups.
[0029] In a specific embodiment of the present application, it is determined whether there is an intersection between the life cycles of the first maximum variable corresponding to the smaller group and the second maximum variable corresponding to the larger group. If there is an intersection, the two groups are judged separately from the other groups.
[0030] In a specific example of the present application, preferably, if there is an intersection between the life cycles of variable A in the first group and variable E in the second group, the first group and the second group cannot be merged at this time, and the first group and the second group can be judged, merged, etc. with other groups respectively.
[0031] In a specific embodiment of the present application, it also includes: if the sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable in the larger group is greater than the number of bytes occupied by the second largest variable, and the sum of the number of bytes of the non-intersecting part of the life cycle of the first largest variable and the third variable is less than or equal to the number of bytes occupied by the second largest variable, and the first largest variable and the third variable perform read operations and write operations respectively, then the smaller group is merged into the larger group.
[0032] In a specific example of the present application, preferably, if the life cycles of variables D and E intersect, and the sum of the number of bytes occupied by variable D and the number of bytes occupied by the remaining part of variable E except the part that intersects with the life cycle of variable D is less than or equal to the number of bytes occupied by variable A. Then, it is determined whether variables D and variable E perform read operations and write operations respectively. If variables D and variable E perform read operations and write operations respectively, the variables of the second group can also be incorporated into the first group at this time, so that the memory consumption is further reduced on the basis of the current grouping.
[0033] Figure 1 The process S104 shown includes: allocating the same memory unit to the variables in each group according to the final grouping result.
[0034] In this specific embodiment, preferably, after the variables of the second group are merged into the first group, memory units are allocated to the variables in the current first group, and the size of the allocated memory unit is the number of bytes occupied by variable A. Corresponding memory units are allocated to each group in turn.
[0035] In a specific embodiment of the present application, if in the final grouping result, there are variables with overlapping life cycles in any group, and read operations and write operations are performed respectively, a fast read and slow write method is used so that the two variables use the same memory unit.
[0036] In a specific example of the present application, preferably, if in the final grouping result, the life cycles of variables D and E in the first group overlap, and the sum of the number of bytes occupied by variable D and the number of bytes occupied by the remaining part of variable E except the part that overlaps with the life cycle of variable D is less than or equal to the number of bytes occupied by variable A, and variable D and variable E perform read operations and write operations respectively, then variable D and variable E share the same memory unit using a fast read and slow write method.
[0037] Figure 2 The schematic diagram shows a specific implementation of the device for optimizing the memory of the audio and video codec of the present application.
[0038] exist Figure 2 In the specific implementation shown, the device for optimizing the audio and video codec memory of the present application may include: module 201, module 202, module 203 and module 204.
[0039] Figure 2 The module 201 shown is a module for grouping variables with no intersection in life cycle according to the life cycle of each variable among a plurality of variables used by the audio and video codec, so that the life cycle of each variable in each group has no intersection; Figure 2 The module 202 shown is a module for determining, in any two groups, the group with the smaller number of bytes corresponding to the largest variable in the two groups as the smaller group and the other group as the larger group, and determining whether there is an intersection between the life cycles of the first largest variable corresponding to the smaller group and the second largest variable corresponding to the larger group; Figure 2 The module 203 shown is a module for merging a smaller group whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable into a larger group if there is no intersection, wherein the third variable is a variable in the larger group whose life cycle has an intersection with that of the first largest variable; and Figure 2 The module 204 shown is a module for allocating corresponding identical memory units to the variables in each group according to the final grouping result.
[0040] In a specific embodiment of the present application, module 201, module 202, module 203, and module 204 in the device for optimizing audio and video codec memory of the present application can be directly in hardware, in a software module executed by a processor, or in a combination of the two.
[0041] The software modules may reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from and write information to the storage medium.
[0042] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gates or transistor logic, discrete hardware components, or any combination thereof. A general-purpose processor may be a microprocessor, but in an alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP core, or any other such configuration. In an alternative, the storage medium may be integrated with the processor. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In an alternative, the processor and the storage medium may reside in a user terminal as discrete components.
[0043] A device for optimizing the memory of an audio and video codec of the present application can be used to execute the method for optimizing the memory of an audio and video codec described in any of the above embodiments. The implementation principle and technical effect are similar and will not be repeated here.
[0044] In another specific embodiment of the present invention, a computer-readable storage medium stores computer instructions, and the computer instructions are operated to execute the method for optimizing the audio and video codec memory in solution one.
[0045] The present application discloses a method, device and storage medium for optimizing the memory of an audio and video codec. By using a method for automatically constructing the memory structure of an audio and video codec by a life cycle analysis program of each module data unit, corresponding memory units are allocated to multiple variables used in the audio and video codec, thereby reducing memory consumption and optimizing the memory of a given audio and video codec.
[0046] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0047] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0048] The above description is only an embodiment of the present application and does not limit the patent scope of the present application. Any equivalent structural transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for optimizing the memory of an audio and video codec, characterized in that: include: According to the life cycle of each variable among the multiple variables used by the audio and video codec, the variables with no intersection in the life cycle are grouped into one group, so that the life cycle of each variable in each group has no intersection; In any two groups, the group with the smaller number of bytes corresponding to the largest variable in the two groups is defined as the smaller group, and the other group is defined as the larger group, and it is determined whether there is any intersection between the life cycles of the first largest variable corresponding to the smaller group and the second largest variable corresponding to the larger group; If there is no intersection, merging the smaller group whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable into the larger group, wherein the third variable is a variable in the larger group whose life cycle has an intersection with that of the first largest variable; and According to the final grouping result, the same memory unit is allocated to the variables in each group.
2. The method for optimizing the memory of an audio and video codec according to claim 1, wherein: The step of merging the smaller group, whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable, into the larger group further includes: The larger group after being merged with the smaller group is judged together with other groups, so that the final groups cannot be merged with each other.
3. The method for optimizing the memory of an audio and video codec according to claim 1, wherein: The step of merging the smaller group, whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable, into the larger group further includes: After adding a padding jump variable to each variable in the smaller group, the smaller group is assigned to the larger group, wherein each variable of the smaller group to which the padding jump variable is added shares the same memory unit with the variables of the larger group, and the bytes occupied by the padding jump variable are not less than the number of bytes of the variable with the largest number of bytes among the remaining variables in the larger group except the first largest variable.
4. The method for optimizing the memory of an audio and video codec according to claim 1, wherein: If the sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable in the larger group is greater than the number of bytes occupied by the second largest variable, the two groups are respectively compared with other groups.
5. The method for optimizing the memory of an audio and video codec according to claim 1, wherein: The determining whether there is an intersection between the life cycles of the first maximum variable corresponding to the smaller group and the second maximum variable corresponding to the larger group; if there is an intersection, the two groups are respectively determined with other groups.
6. The method for optimizing the memory of an audio and video codec according to claim 1, wherein: Also includes: If the sum of the number of bytes occupied by the first maximum variable and the number of bytes occupied by the third variable in the larger group is greater than the number of bytes occupied by the second maximum variable, and the sum of the number of bytes of the non-intersecting part of the life cycle of the first maximum variable and the third variable is less than or equal to the number of bytes occupied by the second maximum variable, and the first maximum variable and the third variable perform read operations and write operations respectively, then the smaller group is merged into the larger group.
7. The method for optimizing the memory of an audio and video codec according to claim 6, wherein: The method of allocating the same memory unit to the variables in each group according to the final grouping result includes: By using a fast reading and slow writing method, the first maximum variable and the third variable use the same memory unit.
8. The method for optimizing the memory of an audio and video codec according to claim 1, wherein: The process of grouping variables with no intersection in life cycle according to the life cycle of each variable among the multiple variables used by the audio and video codec so that the life cycle of each variable in each group has no intersection includes: The grouping is performed according to the memory sizes independently occupied by each of the multiple variables whose life cycles have no intersection, so that the difference between the memory sizes independently occupied by the variables in each group is minimized.
9. A device for optimizing the memory of an audio and video codec, characterized in that: include: A module for grouping variables with no intersection in life cycles according to the life cycles of each variable among a plurality of variables used by the audio and video codec, so that the life cycles of each variable in each group have no intersection; A module for determining, in any two groups, the group with the smaller number of bytes corresponding to the maximum variable of the two groups as the smaller group and the other group as the larger group, and determining whether there is an intersection between the life cycles of the first maximum variable corresponding to the smaller group and the second maximum variable corresponding to the larger group; for merging the smaller group, whose sum of the number of bytes occupied by the first largest variable and the number of bytes occupied by the third variable is less than or equal to the number of bytes occupied by the second largest variable, into the larger group if there is no intersection, wherein the third variable is a module of a variable in the larger group whose life cycle has an intersection with that of the first largest variable; as well as A module used to allocate the same memory unit to the variables in each group according to the final grouping results.
10. A computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are operated to perform the method for optimizing audio and video codec memory according to any one of claims 1-8.
Citation Information
Patent Citations
Data area allocation method for temporary variables
CN108804222A
Operation method and device and related product
CN110162338A
