Resource recovery method and device
By determining and recycling the codec that is in a non -working state, the problems that cannot be effectively recovered by the existing technology cannot be effectively recovered, and the efficient recycling of resources and the normal use of functions.
Patent Information
- Application Number
- CN202411345834.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-01-21
AI Technical Summary
The prior art can only recover the codec that occupies the most resources from the codecs corresponding to the background process, and cannot effectively recover the resources occupied by the codecs in the non-working state.
Provide a resource recovery method. By obtaining the first process and the codecs they created, in response to the target instruction, the target compilation of the non -working state is determined from the first codec, and the resources they occupy are recovered.
This method can give priority to recover the resources occupied by a non -working state codec, avoid recovering the codec that is in a working state, thereby preventing the function of resource recycling.
Smart Images

Figure CN119342289A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of resource recovery, and in particular to a resource recovery method and device. Background Art
[0002] When some processes of an electronic device are running, several codecs are created. Each codec occupies a part of the resources of the electronic device after it is created. Since the total amount of resources of the electronic device is limited, when the available resources are insufficient, it is necessary to reclaim some resources occupied by the codec.
[0003] The related technology simply reclaims the resources occupied by the codec that occupies the most resources from the codecs corresponding to the background process. Summary of the invention
[0004] To this end, this application discloses the following technical solutions:
[0005] The first aspect of the present application provides a resource recovery method, comprising:
[0006] Obtaining a first process, the first process creating at least one first codec;
[0007] In response to a target instruction, determining a target codec from among the first codecs;
[0008] Reclaiming resources occupied by the target codec;
[0009] The target codec is a codec in a non-working state among the first codecs.
[0010] Optionally, the determining a target codec from the first codec includes at least one of the following:
[0011] determining a second codec from the set of first codecs based on the target policy;
[0012] If the second codec is in a non-working state, determining the second codec as the target codec; or;
[0013] determining a second codec from the set of first codecs based on the target policy;
[0014] If the second codec is in working state, determine a third codec from a set of the first codecs excluding the second codec based on a target policy;
[0015] If the third codec is in a non-working state, determining that the third codec is the target codec; or;
[0016] determining a second codec from the set of first codecs based on a target policy;
[0017] If the second codec is in working state, determine a third codec from a set of the first codecs excluding the second codec based on a target policy;
[0018] If the third codec is in a working state, the codec that satisfies the target policy is determined in sequence by removing the codecs that have been determined to be in a working state from the first codecs based on the target policy, until a codec that satisfies the target policy and is in a non-working state is determined as the target codec.
[0019] Optionally, the determining the second codec from a set of first codecs based on the target strategy includes:
[0020] Determine a target process with the lowest execution priority from among the plurality of first processes;
[0021] Determining, based on a target process, a set of at least one first codec corresponding to the target process;
[0022] A second codec that occupies the most resources is determined from a set of at least one first codec corresponding to the target process.
[0023] Optionally, the determining the second codec from a set of first codecs based on the target strategy includes:
[0024] A second codec that occupies the most resources is determined from the set of first codecs.
[0025] Optionally, also include:
[0026] monitoring the first codec to obtain a target parameter indicating whether the first codec is working;
[0027] If the target parameter meets the target condition, it indicates that the first codec is in a working state;
[0028] If the target parameter does not meet the target condition, it indicates that the first codec is in a non-working state.
[0029] Optionally, monitoring the first codec to obtain a target parameter indicating whether the first codec is working includes:
[0030] Monitoring the number of image frames output by the first codec;
[0031] Determining an average frame rate of the first codec at a target time based on the number of image frames;
[0032] If the average frame rate is greater than the threshold, it indicates that the first codec is in a working state;
[0033] If the average frame rate is less than the threshold, it indicates that the first codec is in a non-working state.
[0034] Optionally, also include:
[0035] Determine a threshold corresponding to the first codec according to a parameter of the first codec;
[0036] If the average frame rate is greater than the threshold corresponding to the first codec, it indicates that the first codec is in a working state;
[0037] If the average frame rate is less than a threshold corresponding to the first codec, it indicates that the first codec is in a non-working state.
[0038] Optionally, the determining, according to the parameter of the first codec, a threshold value corresponding to the first codec includes:
[0039] A threshold corresponding to the first codec is determined according to resources occupied by the first codec.
[0040] Optionally, monitoring the first codec to obtain a target parameter indicating whether the first codec is working includes:
[0041] monitoring whether the first codec outputs an image frame;
[0042] If the image frame is output, it indicates that the first codec is in working state;
[0043] If no image frame is output, it indicates that the first codec is in a non-working state.
[0044] A second aspect of the present application provides a resource recovery device, comprising:
[0045] An obtaining unit, configured to obtain a first process, wherein the first process creates at least one first codec;
[0046] a determining unit, configured to determine a target codec from the first codecs in response to a target instruction;
[0047] A recycling unit, used for recycling resources occupied by the target codec;
[0048] The target codec is a codec in a non-working state among the first codecs. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0050] Figure 1 is a flow chart of a resource recovery method provided in an embodiment of the present application;
[0051] Figure 2 is a flow chart of a method for determining a target codec provided by an embodiment of the present application;
[0052] Figure 3 It is a structural schematic diagram of a resource recovery device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0054] This application embodiment provides a resource recovery method, see Figure 1 , the method may include the following steps.
[0055] S101: Obtain a first process, where the first process creates at least one first codec.
[0056] The recycling method of any embodiment of the present application may be executed by a management module for managing codecs in an electronic device.
[0057] There may be multiple processes in the operating system of the electronic device. Some processes in the operating system may create at least one first codec associated with the process, and the process may use the created first codec to encode or decode data obtained by the process, and the data to be encoded or decoded may include at least one of image data, audio data, and video data.
[0058] Exemplarily, the process corresponding to the video playback application can create a first codec, use the first codec to decode the video data to be played, and then display the decoded video data on the display; the process corresponding to the screen projection application can create a first codec, use the first codec to encode the image data for screen projection, and then send the encoded image data to another electronic device, so as to display the corresponding image based on the encoded image data on the display of the other electronic device.
[0059] Another part of the processes in the operating system may not create the first codec associated with the process. For example, the process for accessing the Internet and the process for managing files in the operating system do not have data that needs to be encoded or decoded, so the first codec associated with the process may not be created.
[0060] In step S101, the management module can determine whether each process in the operating system has created the first codec corresponding to the process, and determine those processes that have created the first codec as the first process, for example, determining the process corresponding to the video playback application and the process corresponding to the screen projection application as the first process.
[0061] At any time, there may be any number of first processes in the operating system, wherein each first process may create one or more first codecs corresponding to the process.
[0062] S102, in response to the target instruction, determining a target codec from the first codecs; wherein the target codec is a codec in a non-working state in the first codecs.
[0063] The target instructions may include instructions for reclaiming resources occupied by the codec.
[0064] The target instruction may be obtained by the operating system of the electronic device. After obtaining the target instruction, the operating system transmits the target instruction to the management module to trigger the management module to determine the target codec.
[0065] The system can obtain target instructions based on a variety of methods.
[0066] On the one hand, if when creating a new process, the system finds that the currently available resources cannot meet the needs of the new process, the system can obtain the target instruction.
[0067] On the one hand, the system can obtain target instructions when it finds that the currently available resources are less.
[0068] On the one hand, the system can obtain the target instruction in response to the user's active resource recovery operation.
[0069] The first codec is in a working state, which may indicate that the first codec is currently encoding or decoding data; the first codec is in a non-working state, which may indicate that the first codec is not currently encoding or decoding data.
[0070] The management module may determine a non-working target codec from among the plurality of first codecs in response to the target instruction. If one or more non-working target codecs are successfully determined, the management module may execute step S103 for the target codec.
[0071] S103: Reclaim the resources occupied by the target codec.
[0072] The resources occupied by the first codec may include memory resources and processor resources of the electronic device, and the processor may include a central processing unit (CPU), a graphics processing unit (GPU), and other processors of the electronic device.
[0073] When reclaiming the resources occupied by the target codec, the management module may mark the resources originally occupied by the target codec as unoccupied, and delete the data stored in the memory resources occupied by the target codec.
[0074] The beneficial effects of this embodiment are:
[0075] When reclaiming resources occupied by a codec, the present embodiment may first determine a target codec in a non-working state in the first codec, and reclaim resources for the target codec in the non-working state. Through this recycling method, the present embodiment may avoid recycling resources occupied by codecs in a working state, thereby preventing the functions of these codecs in a working state from being unable to be used normally after the resources are recycled.
[0076] The implementation process and beneficial effects of this embodiment are explained below in conjunction with relevant application scenarios.
[0077] In an application scenario, a first device can establish a data channel with a second device, the first device can run a screen projection application, and the screen projection process corresponding to the screen projection application can create at least one first codec, and use the first codec to encode each frame of the screen projection image that needs to be displayed on the second device in real time, and then the screen projection process sends each encoded frame of the screen projection image to the second device in the form of streaming media from the data channel, so that the second device can display each frame of the screen projection image on the display in real time. In this scenario, the screen projection process can be in the target state, at which time the screen projection process does not occupy the interactive interface of the screen projection application corresponding to the screen projection process.
[0078] The first device can also run game applications and video applications, wherein the video process corresponding to the video application is in a target state, and the game process corresponding to the game application is in a non-target state, that is, the game process currently occupies the interactive interface of the corresponding game application, and the game process can obtain the user's interactive instructions through the interactive interface of the game application displayed on the display of the first device.
[0079] The video process and the game process both have corresponding first codecs created. Since the video process is in the target state and the video process pauses playing the video, the first codec of the video process is in a non-working state and does not perform image encoding and decoding processing. The first codec of the game process is used to encode and decode each frame of the image displayed on the interactive interface of the game application in real time.
[0080] When the management module of the first device can determine that the above-mentioned screen projection process, video process and game process belong to the first process, when obtaining the target instruction, the management module can determine one by one whether the first codecs corresponding to the screen projection process, video process and game process are in a working state based on the method of this embodiment, and then determine that the first codec of the video process is in a non-working state. Then the management module determines that the first codec of the video process belongs to the target codec, and reclaims the resources occupied by the first codec of the video process.
[0081] It can be seen that the method of this embodiment can give priority to recovering the resources occupied by the first codec in a non-working state, and avoid recovering the resources occupied by the first codec in a working state, so that the corresponding functions of the first codec in a working state can be used normally. For example, in the above example, the management module gives priority to recovering the resources occupied by the first codec of the non-working video process, but does not recover the resources occupied by the first codec of the screen projection process, so that the screen projection function of the first device can be used normally.
[0082] In contrast, if resource recovery is performed based on relevant technologies, the resources occupied by the first codec of the screen projection process may be directly recovered because the first codec of the screen projection process occupies more resources, resulting in the screen projection function of the first device being unable to be used normally.
[0083] When determining the target codec, the management module may determine whether each first codec is in a working state one by one, and when determining that any first codec is in a non-working state, the first codec may be determined as the target codec.
[0084] Optionally, the management module may first determine, based on the target policy, a second codec in the set of first codecs that meets the target policy, and then determine whether the second codec is in a working state.
[0085] If the second codec is in a non-operating state, the second codec may be determined to be the target codec.
[0086] Alternatively, if the second codec is in a working state, the second codec can be removed from the set of first codecs, and then a third codec is determined from the set of first codecs removed from the second codec based on the target policy, that is, a third codec that meets the target policy is determined in the set of first codecs removed from the second codec, and then it is determined whether the third codec is in a working state.
[0087] If the third codec is in a non-operating state, the third codec may be determined as the target codec.
[0088] If the third codec is also in a working state, the codec that satisfies the target policy is determined in sequence by removing the codecs that have been determined to be in a working state from the first codec based on the target policy, until a codec that satisfies the target policy and is in a non-working state is determined as the target codec.
[0089] That is to say, if the third codec is also in a working state, the management module can further eliminate the third codec from the set of first codecs, and then determine the codecs that meet the target policy in the remaining set of first codecs, and determine whether these codecs that meet the target policy are in a working state. If the codecs that meet the target policy are in a non-working state, these codecs are determined as target codecs. If the codecs that meet the target policy are in a working state, these codecs that meet the target policy are eliminated from the set of first codecs, and the above steps of determining the codecs that meet the target policy and determining the working state of the codec are continued to be performed for the remaining set of first codecs until the target codec is determined.
[0090] As an example, assuming that when S102 is executed, there are 10 first codecs in the operating system, which are sequentially recorded as codec 1 to codec 10, the management module first determines that codec 8 is the second codec that satisfies the target policy, and then determines whether codec 8 is in a working state;
[0091] If the codec 8 is in a non-working state, the codec 8 is determined to be the target codec, and step S102 ends;
[0092] If codec 8 is in working state, codec 8 is eliminated, and a third codec satisfying the target policy is determined from the remaining codecs 1 to 7, codecs 9 and 10. For example, codec 1 is determined to be the third codec satisfying the target policy, and then the working state of codec 1 is determined;
[0093] If codec 1 is in a non-working state, codec 1 is determined to be the target codec, and step S102 ends;
[0094] If codec 1 is in working state, codec 1 is eliminated, and a codec satisfying the target policy is determined from the remaining codecs 2 to 7, codecs 9 and 10, for example, codec 10 is determined to satisfy the target policy, and then the working state of codec 10 is determined;
[0095] If codec 10 is in a non-working state, codec 10 is determined to be the target codec, and step S102 ends. If codec 10 is in a working state, codec 10 is eliminated, and a codec that meets the target strategy is determined from the remaining codecs 2 to 7 and codec 9, and so on, until the target codec is determined.
[0096] In different embodiments, different target strategies may be set as needed without limitation.
[0097] In some embodiments, the target policy may be that the codec that occupies the most processor resources in the set of first codecs. In this case, the method of determining the second codec from the set of first codecs based on the target policy may be to determine the first codec that occupies the most processor resources from the set of first codecs as the second codec. Similarly, the method of determining the third codec may be to determine the codec that occupies the most processor resources as the third codec in the set of first codecs excluding the second codec.
[0098] In some embodiments, the target strategy may be that the codec that occupies the most memory resources in the set of first codecs. In this case, the method of determining the second codec from the set of first codecs based on the target strategy may be to determine the first codec that occupies the most memory resources from the set of first codecs as the second codec. Similarly, the method of determining the third codec may be to determine the codec that occupies the most memory resources as the third codec in the set of first codecs excluding the second codec.
[0099] In some embodiments, the target policy may be the codec with the earliest creation time in the set of first codecs. In this case, the method for determining the second codec from the set of first codecs based on the target policy may be to determine the first codec with the earliest creation time from the set of first codecs as the second codec. Similarly, the method for determining the third codec may be to determine the first codec with the earliest creation time as the third codec in the set of first codecs excluding the second codec.
[0100] In some embodiments, the target policy may be that the corresponding process has the lowest execution priority among multiple first processes, and occupies the most resources (which may be processor resources or memory resources) in the first codec corresponding to the process with the lowest execution priority.
[0101] Based on the above target strategy, the second codec may be determined in the following manner:
[0102] Determine a target process with the lowest execution priority from among the plurality of first processes;
[0103] Determining, based on the target process, a set of at least one first codec corresponding to the target process;
[0104] A second codec that occupies the most resources is determined from a set of at least one first codec corresponding to the target process.
[0105] Further, the method of determining the codec that meets the target policy from the set of first codecs may be:
[0106] Determine a target process with the lowest execution priority from among the plurality of first processes;
[0107] Determining, based on the target process, a set of at least one first codec corresponding to the target process;
[0108] A codec that occupies the most resources is determined from a set of at least one first codec corresponding to the target process as a codec that satisfies the target policy.
[0109] In some embodiments, the operating system may also mark the first process as recyclable or non-recyclable according to the state of the first process. For example, the first process in the target state may be marked as recyclable, and the first process in the non-target state may be marked as non-recyclable.
[0110] Among them, the target state can also be called the background state. The first process being in the target state can represent that the first process does not occupy the interactive interface of the application corresponding to the first process; the non-target state can also be called the foreground state. The first process being in the non-target state can represent that the first process occupies the interactive interface of the application corresponding to the first process.
[0111] In addition, the management module can monitor whether each first codec is in a working state at a certain period, and configure the recycling priority of each first codec according to whether it is in a working state. If the first codec is in a working state, the first codec is configured to be in a low recycling priority; if the first codec is in a non-working state, the first codec is configured to be in a high recycling priority.
[0112] The operating system may configure the execution priority of the first process based on a variety of priority policies.
[0113] The operating system may configure the execution priority according to the state of the first process. For example, the operating system may configure a higher execution priority for the first process in a non-target state and a lower execution priority for the first process in a target state.
[0114] Alternatively, the operating system may configure the execution priority based on the function of the first process. For example, the operating system may configure a higher execution priority for a process used to provide basic services, such as network connection, resource allocation, etc., and a lower execution priority for a process corresponding to a specific application.
[0115] Alternatively, the operating system can configure the execution priority based on the application corresponding to the first process and the current usage scenario of the electronic device. For example, when it is determined that the electronic device currently establishes a screen projection connection with another device, a higher execution priority can be configured for the first process corresponding to the screen projection application, and a lower execution priority can be configured for other applications that are not related to screen projection, such as weather applications and navigation applications.
[0116] Based on the above priority settings and target strategies, see Figure 2 , the management module may determine the target codec from the set of first codecs in a manner as follows.
[0117] S201 , determining whether there is a recyclable first process in a set of first processes.
[0118] If there is a recyclable first process in the set of first processes, step S202 is executed.
[0119] If there is no recyclable first process in the set of first processes, step S209 may be executed.
[0120] S202: Determine a target process with the lowest execution priority from the recyclable first processes.
[0121] S203: Determine whether there is a first codec with a high recycling priority among the first codecs corresponding to the target process.
[0122] If there is a first codec with a high recycling priority among the first codecs corresponding to the target process, step S204 is executed.
[0123] If there is no first codec with a high recycling priority among the first codecs corresponding to the target process, step S208 may be executed.
[0124] S204: Determine the first codec that occupies the most resources among the first codecs with high recycling priorities corresponding to the target process as the codec that satisfies the target policy.
[0125] S205: Determine whether the codec that meets the target policy is in a working state.
[0126] If the codec that meets the target policy is in a non-working state, execute step S206; if the codec that meets the target policy is in a working state, execute step S207.
[0127] S206: Determine a codec that satisfies the target policy as a target codec.
[0128] S207: Configure the codec that meets the target policy as a low recycling priority.
[0129] After executing step S207, the process returns to executing step S203. In step S207, the codecs satisfying the target policy are configured as having a low recycling priority, which is equivalent to removing the first codecs that have been determined to be in a working state from the set of first codecs.
[0130] S208: Remove the target process from the set of first processes.
[0131] After executing step S205, the process may return to executing step S201 to determine whether there is a recyclable first process in the first process set after the target process is removed. If so, the process may continue to determine a codec that satisfies the target policy in the manner of steps S202 to S204.
[0132] When all first processes are traversed in the above manner and it is found that each first process is in an unrecyclable state, or when it is found that the first codec corresponding to each recyclable first process is in a working state, refer to Figure 2 , the management module can also determine the target codec as follows.
[0133] S209: Determine a target process with the lowest execution priority from among all first processes.
[0134] In step S209, the management module may traverse each first process of the operating system, including recyclable first processes and non-recyclable first processes, and also including first processes whose corresponding first codecs have been determined as having low recycling priorities, and determine the first process with the lowest execution priority among these first processes as the target process.
[0135] S210: Determine the first codec that occupies the most resources and corresponds to the target process as the target codec.
[0136] In step S210, the management module may determine the first codec that occupies the most memory resources among the plurality of first codecs corresponding to the target process as the target codec, or may determine the first codec that occupies the most processor resources as the target codec.
[0137] When the target codec is determined in step S210, for the first codec corresponding to the target process, no matter whether the codec has a low recycling priority or a high recycling priority, as long as the first codec meets the condition of occupying the most resources, the first codec is determined as the target codec.
[0138] In some optional embodiments, the management module may monitor the first codec in real time at a certain period to obtain a target parameter indicating whether the first codec is working, thereby determining whether the first codec is in working state based on the target parameter of each first codec.
[0139] If the target parameter meets the target condition, it indicates that the first codec is in a working state; if the target parameter does not meet the target condition, it indicates that the first codec is in a non-working state.
[0140] In some embodiments, the target parameter obtained by the management module may be an average frame rate of the first codec. In this case, the first codec may be monitored by:
[0141] Monitoring the number of image frames output by the first codec;
[0142] Determining an average frame rate of the first codec at a target time based on the number of image frames;
[0143] Wherein, if the average frame rate is greater than the threshold, it indicates that the first codec is in a working state;
[0144] If the average frame rate is less than the threshold, it indicates that the first codec is in a non-working state.
[0145] The target time may be a specific period of time in the past up to the current moment, for example, the last 10 seconds. The management module may monitor in real time the number of image frames output by the first codec in each unit time (for example, every 1 second), and then calculate the average frame rate of the first codec based on the number of image frames output by the first codec in each unit time within the target time. Finally, whether the first codec is in a working state is determined based on whether the average frame rate of the first codec is greater than a threshold.
[0146] It can be understood that the above method can be applied to a codec that encodes and decodes image data, and can also be applied to a codec that encodes and decodes other data.
[0147] For example, when the first codec is a codec used to encode and decode audio data, the number of audio frames output by the first codec can be monitored; the average frame rate of the first codec at the target time can be determined based on the audio number, and then whether the first codec is in a working state can be determined based on the average frame rate.
[0148] Optionally, for multiple first codecs, the threshold for determining whether they are in a working state may be the same. Exemplarily, a unified threshold may be set, such as 10 frames per second. For each first codec, as long as its average frame rate is greater than 10 frames per second, it is determined that the first codec is in a working state; as long as its average frame rate is less than or equal to 10 frames per second, it is determined that the first codec is in a non-working state.
[0149] Alternatively, for different first codecs, the thresholds for determining whether they are in a working state may also be different. That is, a corresponding threshold may be set for each first codec, and when determining whether a first codec is in a working state, the average frame rate of the first codec may be compared with the threshold corresponding to the first codec, and if the average frame rate is greater than the threshold corresponding to the first codec, it indicates that the first codec is in a working state; if the average frame rate is less than the threshold corresponding to the first codec, it indicates that the first codec is in a non-working state.
[0150] For each first codec, a threshold corresponding to the first codec may be determined according to the parameters of the first codec.
[0151] There are many parameters that can be used to set the threshold.
[0152] In some embodiments, the parameter used to set the threshold may be the execution priority of the first process corresponding to the first codec. If the execution priority of the first process corresponding to the first codec is higher, a lower threshold may be set for the first codec. If the execution priority of the first process corresponding to the first codec is lower, a higher threshold may be set for the first codec.
[0153] In some embodiments, the parameter used to set the threshold value may be the amount of data of each frame of data output by the first codec. Taking the codec used to encode and decode image data as an example, if the amount of data of a frame of image data output by the first codec is large, a lower threshold value may be set for the first codec. If the amount of data of a frame of image data output by the first codec is small, a higher threshold value may be set for the first codec.
[0154] In some embodiments, the parameter used to set the threshold may be the amount of resources occupied by the first codec, that is, the threshold corresponding to the first codec may be determined based on the resources occupied by the first codec; the more resources the first codec occupies, the larger the threshold may be set for the first codec, and the fewer resources the first codec occupies, the smaller the threshold may be set for the first codec.
[0155] In some embodiments, the target parameter obtained by the management module may be the output data of the first codec. In this case, each time the management module monitors a first codec, it may determine whether the first codec is currently outputting data. If it is found that the first codec is currently outputting data, it may be determined that the first codec is in a working state. If it is found that the first codec is not currently outputting data, it may be determined that the first codec is in a non-working state.
[0156] Taking the first codec used to encode and decode image data as an example, when monitoring a first codec, the management module can determine whether the first codec is currently outputting image frames. If the first codec is currently outputting image frames, it indicates that the first codec is in a working state; if the first codec is not currently outputting image frames, it indicates that the first codec is in a non-working state.
[0157] The above-mentioned management module can be run by any processor of the electronic device. The processor running the management module can exchange data with other processors, memory modules, and other hardware modules in the electronic device that can provide resources occupied by the first codec. Therefore, after determining the target codec through the method of this embodiment, the processor running the management module can exchange data with various other processors, memory modules and other hardware modules to reclaim the resources of these hardware modules occupied by the target codec.
[0158] For example, the management module may be a central processing unit (CPU) of an electronic device. After the CPU determines the target codec through the method of this embodiment, it may exchange data with hardware modules that provide corresponding resources, such as a graphics processing unit (GPU) and a memory module of the electronic device, thereby reclaiming the resources of these hardware modules occupied by the target codec.
[0159] The present application also provides a resource recovery device. Figure 3 , the device may include the following units.
[0160] An obtaining unit 301 is used to obtain a first process, where the first process creates at least one first codec;
[0161] A determination unit 302, configured to determine a target codec from the first codec in response to a target instruction;
[0162] A recycling unit 303, used to recycle resources occupied by the target codec;
[0163] The target codec is a codec in a non-working state in the first codec.
[0164] The apparatus of this embodiment can interact with a module for managing processes in an electronic device to obtain a first process that creates a first codec, and can determine which first processes are in a target state and which first processes are in a non-target state when determining a target codec through interaction with the module for managing processes.
[0165] The apparatus of this embodiment can also interact with a module for managing resources in the electronic device, so as to obtain a target instruction generated by the module for managing resources when resources are insufficient.
[0166] Optionally, when the determination unit 302 determines the target codec from the first codec, at least one of the following may be performed:
[0167] determining a second codec from the set of first codecs based on the target policy;
[0168] If the second codec is in a non-operating state, determining the second codec as the target codec; or;
[0169] determining a second codec from the set of first codecs based on the target policy;
[0170] If the second codec is in working state, determining a third codec from a set of first codecs excluding the second codec based on the target policy;
[0171] If the third codec is in a non-working state, determining the third codec as a target codec; or;
[0172] determining a second codec from the set of first codecs based on the target policy;
[0173] If the second codec is in working state, determining a third codec from a set of first codecs excluding the second codec based on the target policy;
[0174] If the third codec is in a working state, the codec that meets the target policy is determined by removing the codecs that have been determined to be in a working state from the first codec based on the target policy in sequence, until a codec that meets the target policy and is in a non-working state is determined as the target codec.
[0175] Optionally, when the determining unit 302 determines the second codec from the set of first codecs based on the target strategy, it can be used to:
[0176] Determine a target process with the lowest execution priority from among the plurality of first processes;
[0177] Determining, based on the target process, a set of at least one first codec corresponding to the target process;
[0178] A second codec that occupies the most resources is determined from a set of at least one first codec corresponding to the target process.
[0179] Optionally, when the determining unit 302 determines the second codec from the set of first codecs based on the target strategy, it can be used to:
[0180] A second codec that occupies the most resources is determined from the set of first codecs.
[0181] Optionally, the determining unit 302 is further configured to:
[0182] monitoring the first codec to obtain a target parameter indicating whether the first codec is working;
[0183] If the target parameter satisfies the target condition, it indicates that the first codec is in a working state;
[0184] If the target parameter does not meet the target condition, it indicates that the first codec is in a non-working state.
[0185] Optionally, when the determining unit 302 monitors the first codec to obtain a target parameter indicating whether the first codec is working, it can be used to:
[0186] Monitoring the number of image frames output by the first codec;
[0187] Determining an average frame rate of the first codec at a target time based on the number of image frames;
[0188] Wherein, if the average frame rate is greater than the threshold, it indicates that the first codec is in a working state;
[0189] If the average frame rate is less than the threshold, it indicates that the first codec is in a non-working state.
[0190] Optionally, the determining unit 302 may also be configured to:
[0191] Determine a threshold value corresponding to the first codec according to a parameter of the first codec;
[0192] If the average frame rate is greater than the threshold corresponding to the first codec, it indicates that the first codec is in a working state;
[0193] If the average frame rate is less than the threshold corresponding to the first codec, it indicates that the first codec is in a non-working state.
[0194] Optionally, when the determination unit 302 determines the threshold corresponding to the first codec according to the parameter of the first codec, it can be used to:
[0195] A threshold corresponding to the first codec is determined according to resources occupied by the first codec.
[0196] Optionally, when the determining unit 302 monitors the first codec to obtain a target parameter indicating whether the first codec is working, it can be used to:
[0197] monitoring whether the first codec outputs an image frame;
[0198] Wherein, if the image frame is output, it indicates that the first codec is in a working state;
[0199] If no image frame is output, it indicates that the first codec is in a non-working state.
[0200] The working principle of the resource recovery device provided in this embodiment can be found in the relevant steps of the resource recovery method provided in the embodiment of the present application, and will not be repeated here.
[0201] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0202] For the convenience of description, the above system or device is described by dividing it into various modules or units according to its functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0203] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the relevant technology in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.
[0204] Finally, it should be noted that, in this article, relational terms such as first, second, third and fourth 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 "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0205] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A resource recovery method, comprising: Obtaining a first process, the first process creating at least one first codec; In response to a target instruction, determining a target codec from among the first codecs; Reclaiming resources occupied by the target codec; The target codec is a codec in a non-working state among the first codecs.
2. The method according to claim 1, wherein determining the target codec from the first codec comprises at least one of the following: determining a second codec from the set of first codecs based on the target policy; If the second codec is in a non-working state, determining the second codec as the target codec; or; determining a second codec from the set of first codecs based on the target policy; If the second codec is in working state, determine a third codec from a set of the first codecs excluding the second codec based on a target policy; If the third codec is in a non-working state, determining that the third codec is the target codec; or; determining a second codec from the set of first codecs based on a target policy; If the second codec is in working state, determine a third codec from a set of the first codecs excluding the second codec based on a target policy; If the third codec is in a working state, the codec that satisfies the target policy is determined in sequence by removing the codecs that have been determined to be in a working state from the first codecs based on the target policy, until a codec that satisfies the target policy and is in a non-working state is determined as the target codec.
3. The method according to claim 2, wherein determining the second codec from the set of first codecs based on the target policy comprises: Determine a target process with the lowest execution priority from among the plurality of first processes; Determining, based on a target process, a set of at least one first codec corresponding to the target process; A second codec that occupies the most resources is determined from a set of at least one first codec corresponding to the target process.
4. The method according to claim 2, wherein determining the second codec from the set of first codecs based on the target policy comprises: A second codec that occupies the most resources is determined from the set of first codecs.
5. The method according to claim 1, further comprising: monitoring the first codec to obtain a target parameter indicating whether the first codec is working; If the target parameter meets the target condition, it indicates that the first codec is in a working state; If the target parameter does not meet the target condition, it indicates that the first codec is in a non-working state.
6. The method according to claim 5, wherein monitoring the first codec to obtain a target parameter indicating whether the first codec is working comprises: Monitoring the number of image frames output by the first codec; Determining an average frame rate of the first codec at a target time based on the number of image frames; If the average frame rate is greater than the threshold, it indicates that the first codec is in a working state; If the average frame rate is less than the threshold, it indicates that the first codec is in a non-working state.
7. The method according to claim 6, further comprising: Determine a threshold corresponding to the first codec according to a parameter of the first codec; If the average frame rate is greater than the threshold corresponding to the first codec, it indicates that the first codec is in a working state; If the average frame rate is less than a threshold corresponding to the first codec, it indicates that the first codec is in a non-working state.
8. The method according to claim 7, wherein determining the threshold corresponding to the first codec according to the parameter of the first codec comprises: A threshold corresponding to the first codec is determined according to resources occupied by the first codec.
9. The method according to claim 5, wherein monitoring the first codec to obtain a target parameter indicating whether the first codec is working comprises: monitoring whether the first codec outputs an image frame; If the image frame is output, it indicates that the first codec is in working state; If no image frame is output, it indicates that the first codec is in a non-working state.
10. A resource recovery device, comprising: An obtaining unit, configured to obtain a first process, wherein the first process creates at least one first codec; a determining unit, configured to determine a target codec from the first codecs in response to a target instruction; A recycling unit, used for recycling resources occupied by the target codec; The target codec is a codec in a non-working state among the first codecs.