Buffer allocation method and apparatus, computer device and storage medium
By acquiring and decoding the frames to be processed, matching the target frame with the display frame or reference frame, and adjusting the buffer state, the problem of low buffer utilization is solved, and efficient management of buffer resources and reduction of waste are achieved.
Patent Information
- Application Number
- CN202211530615.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-01
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2042-12-01
AI Technical Summary
Improper buffer allocation in traditional decoders leads to low buffer utilization, serious resource waste, and failure to effectively utilize the specific number of decoding reference frames.
By acquiring and decoding the frames to be processed, matching the target frame with the display frame or reference frame, adjusting the usage status of the buffer according to the status, and releasing idle buffers to reduce resource waste.
This improved the utilization efficiency of buffers, reduced resource waste, and optimized buffer allocation and management.
Smart Images

Figure CN115883529B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer application, in particular to a buffer allocation method and device, computer equipment, storage medium and computer program product. BACKGROUND
[0002] With the rapid development of multimedia, the resolution of the decoded code stream is getting larger and larger, and the buffer used in the decoder is also getting larger and larger.
[0003] In the traditional technology, different numbers of buffers need to be allocated due to the characteristics of the code stream during decoding.
[0004] However, the specific number of decoding reference frames is not specified in the decoding standard, only the maximum number of reference frames is specified, so the number of decoding buffers allocated for each code stream will be greater than the demand, resulting in low utilization rate of the buffer. SUMMARY
[0005] Therefore, it is necessary to provide a buffer allocation method, device, computer equipment, computer readable storage medium and computer program product capable of reducing buffer resource waste and improving buffer utilization efficiency in view of the above technical problems.
[0006] In a first aspect, the present application provides a buffer allocation method. The method comprises:
[0007] When entering a decoding state, a to-be-processed frame is obtained;
[0008] The to-be-processed frame is decoded by a decoder to obtain a target frame, and the target frame is stored in a decoding buffer; wherein the state of the decoding buffer is a first state;
[0009] The target frame is matched with a display frame, and the target frame is matched with a reference frame, and when the target frame matching is matched successfully or the reference frame matching is matched successfully, the state of the decoding buffer is set to a second state;
[0010] When the state of the decoding buffer is the second state, when the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed, the state of the decoding buffer is set to the first state, and the decoding buffer in the first state is released to a buffer pool.
[0011] In one of the embodiments, after the target frame is matched with the display frame, the method further comprises:
[0012] When the target frame matching is matched successfully, the target frame is added to a display queue, and the target frame is displayed.
[0013] In one of the embodiments, after the target frame is matched with the reference frame, the method further comprises:
[0014] When the reference frame matching is successful, the target frame corresponding to the frame to be processed is added to the reference frame set in which the reference frame is located.
[0015] In one of the embodiments, the decoding buffer is obtained from the buffer pool, comprising:
[0016] The states of the plurality of buffers in the buffer pool are polled to obtain the state of each buffer;
[0017] When the state of the buffer corresponds to the first state, the buffer is used as the decoding buffer, and the polling of the plurality of buffers in the buffer pool is stopped.
[0018] In one of the embodiments, the method further comprises:
[0019] When there is a thread polling the plurality of buffers in the buffer pool, the plurality of waiting threads are added to the waiting queue; wherein, the waiting thread is a thread that has obtained the polling permission and has not polled the buffer pool; the order of the waiting queue is consistent with the order of the plurality of waiting threads obtaining the polling permission;
[0020] When there is no thread polling the plurality of buffers in the buffer pool, the first waiting thread in the waiting queue is caused to poll the plurality of buffers in the buffer pool, and the first waiting thread in the waiting queue is removed from the waiting queue.
[0021] In one of the embodiments, the decoding buffer is obtained from the buffer pool, further comprising:
[0022] When the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than the maximum number of buffers, a new buffer is obtained as the decoding buffer, and the new buffer is added to the buffer pool, and the number of buffers in the buffer pool is increased by 1; wherein, the maximum number of buffers is the maximum number of buffers in the buffer pool.
[0023] In one of the embodiments, the decoding buffer is obtained from the buffer pool, further comprising:
[0024] When the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no new buffer is obtained as the decoding buffer; wherein, the maximum number of buffers is the maximum number of buffers in the buffer pool.
[0025] The thread waiting time is obtained, and when the thread waiting time is greater than the maximum waiting time, the waiting is ended, and an error prompt is returned.
[0026] In one of the embodiments, the maximum number of buffers is determined based on a coding standard, a memory size, and an application specification.
[0027] In one of the embodiments, the maximum latency is determined based on a decoding period of a frame to be processed and a preset latency coefficient.
[0028] In one of the embodiments, the method further comprises:
[0029] obtaining a sequence of image frames;
[0030] determining whether the frame to be processed is the last frame in the sequence of image frames;
[0031] when the frame to be processed is not the last frame in the sequence of image frames, determining a next image frame adjacent to the frame to be processed in the sequence of image frames as a new frame to be processed.
[0032] In a second aspect, the present application further provides a buffer allocation device. The device comprises:
[0033] an obtaining module configured to obtain a frame to be processed when entering a decoding state;
[0034] a target frame obtaining module configured to obtain a decoding buffer from a buffer pool, decode the frame to be processed by a decoder to obtain a target frame, and store the target frame in the decoding buffer; wherein a state of the decoding buffer is a first state;
[0035] a matching module configured to perform target frame matching between the target frame and a display frame, and reference frame matching between the target frame and a reference frame, and set the state of the decoding buffer to a second state when the target frame matching is successful or the reference frame matching is successful;
[0036] a buffer releasing module configured to, when the state of the decoding buffer is the second state, set the state of the decoding buffer to the first state when the target frame is no longer used as the reference frame and is not the display frame, or the target frame is no longer used as the reference frame and the target frame has been displayed completely, and release the decoding buffer in the first state to the buffer pool.
[0037] In a third aspect, the present application further provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the steps of the method according to any one of the embodiments when executing the computer program.
[0038] In a fourth aspect, the present application further provides a computer device readable storage medium. The computer device readable storage medium stores a computer program, and the computer program implements the steps of the method according to any one of the embodiments when executed by a processor.
[0039] In a fifth aspect, the present application provides a computer program product. The computer program product comprises a computer program which, when executed by a processor, implements the steps of the method according to any one of the preceding embodiments.
[0040] The buffer allocation method, device, computer device, storage medium and computer program product can acquire a to-be-processed frame when entering a decoding state. Then, a decoding buffer is acquired from a buffer pool, the to-be-processed frame is decoded by a decoder to obtain a target frame, and the target frame is stored in the decoding buffer; wherein the state of the decoding buffer is a first state. Then, the target frame is matched with a display frame, and the target frame is matched with a reference frame, and when the target frame matching is matched successfully or the reference frame matching is matched successfully, the state of the decoding buffer is set to a second state. Finally, when the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed completely, the state of the decoding buffer is set to the first state, and the decoding buffer in the first state is released to the buffer pool. The to-be-processed frame is acquired first, then the decoding buffer in the first state is acquired, the state of the decoding buffer is changed through matching of the to-be-processed frame, and the decoding buffer is selected based on the state, so that the waste of buffer resources is reduced, and the utilization efficiency of the buffer is improved. BRIEF DESCRIPTION OF DRAWINGS
[0041] Figure 1 An application environment diagram of the buffer allocation method in an embodiment;
[0042] Figure 2 A flowchart of the buffer allocation method in an embodiment;
[0043] Figure 3 A flowchart of the buffer allocation and polling of the buffer pool in an embodiment;
[0044] Figure 4 A structural block diagram of the buffer allocation device in an embodiment;
[0045] Figure 5 An internal structure diagram of the computer device in an embodiment. DETAILED DESCRIPTION
[0046] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.
[0047] The buffer allocation method provided by the embodiments of the present application can be applied to, for example, Figure 1The application environment is shown. Among them, the buffer pool 102 communicates with the server 104 through the network. The data storage system can store the data required to be processed by the analysis system. The data storage system can be integrated on the server, or placed on the cloud or other network servers. First, when entering the decoding state, the server 104 acquires the to-be-processed frame. Then, the server 104 acquires the decoding buffer from the buffer pool 102, sets the state of the decoding buffer to the first state, decodes the to-be-processed frame through the decoding buffer to obtain the target frame. Further, the server 104 performs the first matching on the target frame and the display frame, and sets the state of the decoding buffer to the second state when the first matching is successful. Finally, when the state of the decoding buffer is the second state, the target frame is displayed, and the state of the decoding buffer is set to the first state. Among them, the server 104 can be realized by an independent server or a server cluster composed of multiple servers.
[0048] The buffer allocation method provided by the embodiment of the application can be applied to the server single side.
[0049] In one embodiment, as shown in Figure 2 , a buffer allocation method is provided. Taking the server side in Figure 1 as an example, the method includes the following steps 202 to 208.
[0050] Step 202, when entering the decoding state, acquiring the to-be-processed frame.
[0051] In this embodiment, the to-be-processed frame is an image frame that has not been decoded in a plurality of image frames corresponding to each code stream.
[0052] In this embodiment, each code stream corresponds to a plurality of image frames, and the server can acquire the to-be-processed frame based on the image frame sequence of the image frames in turn.
[0053] Step 204, decoding the to-be-processed frame through the decoder to obtain a target frame, and storing the target frame to a decoding buffer; wherein the state of the decoding buffer is the first state.
[0054] In this embodiment, the state of the buffer can be represented by an identifier.
[0055] In this embodiment, after the server acquires the to-be-processed frame, the identifier of the plurality of buffers in the buffer pool can be polled, and the buffer corresponding to the first queried identifier in the first state is taken as the decoding buffer.
[0056] In the embodiment, the identifier of the buffer can include but is not limited to a reference identifier, a display identifier, and the like. When the reference identifier is in the first state, it indicates that the to-be-processed frame processed by the buffer is not a reference frame; when the reference identifier is in the second state, it indicates that the to-be-processed frame processed by the buffer is a reference frame; when the display identifier is in the first state, it indicates that the target frame corresponding to the to-be-processed frame processed by the buffer is not displayed; and when the display identifier is in the second state, it indicates that the target frame corresponding to the to-be-processed frame processed by the buffer is to be displayed.
[0057] In the embodiment, the states of the multiple identifiers of the buffer can be inconsistent.
[0058] In the embodiment, as shown in Figure 3 , the server can represent the state (the first state or the second state) corresponding to the identifier by using a number, a letter, a special character, or the like. For example, when the server can use the number 0 to represent that the identifier corresponds to the first state, and use 1 to represent that the identifier corresponds to the second state, when the reference identifier of the buffer corresponds to the first state and the display identifier corresponds to the second state, the reference identifier of the buffer is 0, and the display identifier of the buffer is 1.
[0059] In the embodiment, the buffer in the first state is an idle state buffer, where the idle state buffer refers to a buffer in which the multiple identifiers of the buffer all correspond to the first state. For example, when the identifiers of the buffer include a reference identifier and a display identifier, the buffer in which the identifier state corresponds to the first state is a buffer in which the reference identifier and the display identifier are both 0 (the first state).
[0060] In the embodiment, the buffer in the second state is a non-idle state buffer, where the non-idle state buffer refers to a buffer in which the display identifier or the reference identifier corresponds to the second state. For example, when the server can use the number 0 to represent that the identifier corresponds to the first state, and use 1 to represent that the identifier corresponds to the second state, and the identifiers of the buffer include a reference identifier and a display identifier, when the reference identifier is 1 (the second state) or the display identifier is 1 (the second state), the identifier of the buffer corresponds to the second state.
[0061] Step 206, as shown in Figure 3 , the target frame is matched with the display frame, and the target frame is matched with the reference frame; when the target frame matching is successful or the reference frame matching is successful, the state of the decoding buffer is set to the second state.
[0062] In the embodiment, when the target frame matching is successful, the display identifier of the buffer is in the second state.
[0063] In the embodiment, when the reference frame matching is successful, the reference identifier of the buffer is in the second state.
[0064] In the embodiment, when the display identifier of the buffer is in the second state or the reference identifier of the buffer is in the second state, the state of the buffer is changed from the first state to the second state.
[0065] In step 208, when the state of the decoding buffer is in the second state, if the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed completely, the state of the decoding buffer is set to the first state, and the decoding buffer in the first state is released to the buffer pool.
[0066] In the embodiment, when the target frame is no longer a reference frame, the reference identifier of the buffer is changed from the second state to the first state.
[0067] In the embodiment, when the target frame is not a display frame, the display identifier of the buffer is in the first state.
[0068] In the embodiment, when the target frame has been displayed completely, the display identifier of the buffer is changed from the second state to the first state.
[0069] In the embodiment, when the reference identifier and the display identifier of the buffer are both in the first state, the state of the buffer is changed from the second state to the first state.
[0070] In another embodiment, when the state of the decoding buffer is in the second state, if the target frame is not a reference frame and the target frame has been displayed completely, the server can set the state of the decoding buffer to the first state, and release the decoding buffer in the first state to the buffer pool.
[0071] In the above buffer allocation method, when entering the decoding state, the to-be-processed frame is acquired. Then, the decoding buffer is acquired from the buffer pool, the to-be-processed frame is decoded by the decoder to obtain the target frame, and the target frame is stored in the decoding buffer; wherein the state of the decoding buffer is in the first state. Then, the target frame is matched with the display frame, and the target frame is matched with the reference frame, when the target frame matching is matched successfully or the reference frame matching is matched successfully, the state of the decoding buffer is set to the second state. Finally, when the state of the decoding buffer is in the second state, if the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed completely, the state of the decoding buffer is set to the first state, and the decoding buffer in the first state is released to the buffer pool. The to-be-processed frame is acquired first, and then the decoding buffer in the first state is acquired. The state of the decoding buffer is changed based on the matching of the to-be-processed frame, and the decoding buffer is selected based on the state, which can reduce the waste of buffer resources and improve the utilization efficiency of the buffer.
[0072] In one of the embodiments, after the target frame is matched with the display frame, the method can further comprise: when the target frame matching is successful, adding the target frame into a display queue and waiting for displaying the target frame.
[0073] In the embodiment, when the target frame matching is successful, i.e., the display identifier of the buffer is 1 (the second state), the server can add the target frame into the display queue and wait for displaying the target frame.
[0074] In the embodiment, when the target frame has been displayed completely, the server can change the display identifier of the buffer corresponding to the target frame from the second state to the first state.
[0075] In one of the embodiments, after the target frame is matched with the reference frame, the method can further comprise: when the reference frame matching is successful, adding the target frame corresponding to the to-be-processed frame into the reference frame set in which the reference frame is located.
[0076] In the embodiment, when the reference frame matching is successful, i.e., the reference identifier of the buffer is 1 (the second state), the server can update the reference frame set by taking the target frame corresponding to the to-be-processed frame as the reference frame, i.e., adding the target frame into the reference frame set in which the reference frame is located, and setting the reference identifier of the decoding buffer corresponding to the target frame to the second state.
[0077] In the embodiment, when the target frame is no longer the reference frame, the server can remove the target frame corresponding to the to-be-processed frame from the reference frame set in which the reference frame is located, and change the reference identifier of the buffer from the second state to the first state.
[0078] In some embodiments, obtaining the decoding buffer from the buffer pool can comprise: polling a plurality of buffers in the buffer pool, obtaining the state of each buffer; when the state of the buffer corresponds to the first state, taking the buffer as the decoding buffer, and stopping polling the plurality of buffers in the buffer pool.
[0079] In the embodiment, the polling of the plurality of buffers in the buffer pool by the server can comprise: polling a plurality of identifiers of each buffer in the plurality of buffers.
[0080] In the embodiment, the identifiers of the buffer can include but are not limited to the reference identifier, the display identifier, etc.
[0081] In the embodiment, when the plurality of identifiers of the buffer all correspond to the first state, the buffer is the first state buffer; when the display identifier of the buffer corresponds to the second state, the buffer is the second state buffer.
[0082] In some embodiments, the method may further include: when a thread is polling multiple buffers in the buffer pool, adding multiple waiting threads to a waiting queue; wherein the waiting threads are multiple threads that have obtained polling privileges but have not yet polled the buffer pool; the order of the waiting queue is consistent with the order in which the multiple waiting threads obtained polling privileges; when no thread is polling multiple buffers in the buffer pool, causing the first waiting thread in the waiting queue to poll multiple buffers in the buffer pool, and removing the first waiting thread from the waiting queue.
[0083] In this embodiment, when multiple threads poll the buffer pool, in order to avoid multiple threads simultaneously using the idle buffer as a decoding buffer, the server can lock the buffer pool while one thread is polling it, that is, only one thread can poll the buffer pool at a time.
[0084] In this embodiment, when multiple threads obtain polling permissions at the same time, the server can determine the order of the multiple threads in the waiting queue based on the access priority of the multiple threads.
[0085] In some embodiments, such as Figure 3 As shown, obtaining a decoding buffer from the buffer pool may further include: when the state of each buffer in the multiple buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than the maximum number of buffers, obtaining a new buffer as a decoding buffer, adding the new buffer to the buffer pool, and incrementing the number of buffers in the buffer pool by 1; wherein, the maximum number of buffers is the maximum number of buffers in the buffer pool.
[0086] In this embodiment, when the state of each buffer in the buffer pool corresponds to the second state (i.e., the display is marked as non-idle), the buffer pool is in a non-idle state, and the server can obtain a new buffer as a decoding buffer. The state of the new buffer corresponds to the first state, i.e., the idle state.
[0087] In some embodiments, such as Figure 3 As shown, obtaining a decoding buffer from the buffer pool may further include: when the state of each buffer in the multiple buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no new buffer is obtained as a decoding buffer; wherein, the maximum number of buffers is the maximum number of buffers in the buffer pool; obtaining the thread waiting time, and when the thread waiting time is greater than the maximum waiting time, ending the wait and returning an error message.
[0088] In this embodiment, the thread waiting time is the time the thread waits for the buffer pool to allocate a decoding buffer.
[0089] In the embodiment, when the thread waiting time is less than or equal to the maximum waiting time, the plurality of buffers in the buffer pool are polled to obtain the state of each buffer; when the state of the buffer corresponds to the first state, the buffer is taken as the decoding buffer, and the polling of the plurality of buffers in the buffer pool is stopped.
[0090] In the embodiment, when the thread waiting time is greater than the maximum waiting time, the polling of the plurality of buffers in the buffer pool is stopped.
[0091] In some embodiments, the maximum number of buffers can be determined based on a coding standard, a memory size and an APP (Application) regulation.
[0092] In one of the embodiments, the server can determine the maximum number of buffers in the buffer pool based on the coding standard and the number of buffers. For example, when the coding standard is H.264, the maximum number of reference frames is 16, and 2 display buffers and 1 redundant buffer are required, the server can set the maximum number of buffers to be 19 (i.e. the sum of the maximum number of reference frames, the number of display buffers and the number of redundant buffers).
[0093] In one of the embodiments, the server can determine the maximum number of buffers in the buffer pool based on the memory. For example, when the total available memory is 100M, 30M of the memory can be used for decoding buffers, the picture is in the format of 1920x1080xNV12, the maximum number of buffers is 10 (i.e. the quotient of the memory available for decoding buffers divided by the memory required for each frame to be processed).
[0094] In one of the embodiments, the server can determine the maximum number of buffers in the buffer pool based on the APP regulation, i.e. the number of buffers allocated according to the APP regulation, and the maximum number of buffers set by the server is greater than or equal to the number of buffers allocated according to the APP regulation. For example, when the APP requires 30 buffers to be allocated, the maximum number of buffers is greater than or equal to 30.
[0095] In some embodiments, the maximum waiting time can be determined based on the decoding period of a frame to be processed and a preset waiting coefficient.
[0096] In the embodiment, the decoding period of a frame to be processed can be the time period from when a frame to be processed is decoded to when the frame to be processed is no longer a reference frame.
[0097] In another embodiment, the decoding period of a frame to be processed can also be the time period from when a frame to be processed is decoded to when the frame to be processed is displayed (in the case that the frame to be processed is not a reference frame).
[0098] In another embodiment, the decoding period of a frame to be processed can also be a time period during which a frame to be processed is completed decoding (neither a reference frame nor a display frame).
[0099] In the embodiment, the preset waiting coefficient can be a positive number greater than or equal to 1. The maximum waiting time is determined by the decoding period of a frame to be processed and the preset waiting coefficient. When the waiting time of a thread is greater than the maximum waiting time, it indicates that the decoding buffer is not in the idle state (the first state) at present, and the thread ends the waiting and returns an error prompt.
[0100] In some embodiments, as shown in Figure 3 The method can further include: obtaining a sequence of image frames; determining whether the frame to be processed is the last frame in the sequence of image frames; and when the frame to be processed is not the last frame in the sequence of image frames, determining a next image frame adjacent to the frame to be processed in the sequence of image frames as a new frame to be processed.
[0101] In the embodiment, the server obtains a sequence of image frames of a current bitstream. When the frame to be processed is the last frame in the sequence of image frames, the decoding process of the current bitstream ends.
[0102] It should be understood that, although each step in the flowchart involved in each of the above embodiments is shown in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other sequences. Moreover, at least part of the steps in the flowchart involved in each of the above embodiments can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these steps or stages is not necessarily sequential, but can be executed in rotation or alternation with at least part of other steps or steps or stages in other steps.
[0103] Based on the same inventive concept, the embodiments of the present application also provide a buffer allocation device for implementing the above-mentioned buffer allocation method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, and therefore the specific limitations in one or more buffer allocation device embodiments provided below can refer to the limitations of the buffer allocation method described above, which will not be described here again.
[0104] In one embodiment, as shown in Figure 4 A buffer allocation device is provided, which includes an obtaining module 402, a target frame obtaining module 404, a matching module 406, and a buffer releasing module 408, wherein:
[0105] The acquisition module 402 is configured to acquire a frame to be processed when entering a decoding state.
[0106] The target frame acquisition module 404 is configured to acquire a decoding buffer from the buffer pool, decode the frame to be processed by using the decoder to obtain a target frame, and store the target frame in the decoding buffer; wherein the decoding buffer is in a first state.
[0107] The matching module 406 is configured to perform target frame matching between the target frame and a display frame, and reference frame matching between the target frame and a reference frame, and set the state of the decoding buffer to a second state when the target frame matching is successful or the reference frame matching is successful.
[0108] The buffer release module 408 is configured to set the state of the decoding buffer to the first state when the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed completely, and release the decoding buffer in the first state to the buffer pool.
[0109] In one of the embodiments, after the matching module 406, the apparatus further includes:
[0110] The display module is configured to add the target frame to a display queue when the target frame matching is successful, and wait for displaying the target frame.
[0111] In one of the embodiments, after the matching module 406, the apparatus further includes:
[0112] The reference frame updating module is configured to add the frame to be processed corresponding to the target frame to a reference frame set in which the reference frame is located when the reference frame matching is successful.
[0113] In one of the embodiments, the target frame acquisition module 404 can include:
[0114] The polling sub-module is configured to poll a plurality of buffers in the buffer pool, and acquire a state of each buffer.
[0115] The decoding buffer acquisition sub-module is configured to acquire the buffer as a decoding buffer when the state of the buffer corresponds to the first state, and stop polling the plurality of buffers in the buffer pool.
[0116] In one of the embodiments, the target frame acquisition module 404 can further include:
[0117] The buffer period increasing submodule is configured to: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than the maximum number of buffers, obtain a new buffer as a decoding buffer, and add the new buffer to the buffer pool, so that the number of buffers in the buffer pool is increased by 1.
[0118] In one of the embodiments, the apparatus can further include:
[0119] The first waiting module is configured to: when there is a thread polling the plurality of buffers in the buffer pool, add a plurality of waiting threads to a waiting queue; the waiting threads are a plurality of threads that have obtained the polling permission and have not polled the buffer pool; and the order of the waiting queue is consistent with the order in which the plurality of waiting threads obtained the polling permission.
[0120] The second waiting module is configured to: when there is no thread polling the plurality of buffers in the buffer pool, poll the plurality of buffers in the buffer pool by a first waiting thread in the waiting queue, and remove the first waiting thread in the waiting queue from the waiting queue.
[0121] In one of the embodiments, the target frame obtaining module 404 can further include:
[0122] The buffer period number management submodule is configured to: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no longer obtain a new buffer as a decoding buffer; the maximum number of buffers is the maximum number of buffers in the buffer pool.
[0123] The waiting end submodule is configured to: obtain a thread waiting time, and when the thread waiting time is greater than a maximum waiting time, end the waiting, and return an error prompt.
[0124] In one of the embodiments, the maximum number of buffers is determined based on an encoding standard, a memory size, and an application program.
[0125] In one of the embodiments, the maximum waiting time is determined based on a decoding period of a to-be-processed frame and a preset waiting coefficient.
[0126] In one of the embodiments, the apparatus can further include:
[0127] The image frame sequence obtaining module is configured to: obtain an image frame sequence.
[0128] The frame judging module is configured to: judge whether the to-be-processed frame is the last frame in the image frame sequence.
[0129] The to-be-processed frame updating module is configured to, when the to-be-processed frame is not the last frame in the image frame sequence, determine a next image frame adjacent to the to-be-processed frame in the image frame sequence as a new to-be-processed frame.
[0130] The modules in the buffer allocation apparatus can be implemented wholly or partially by software, hardware, or a combination thereof. The modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in the computer device in software form, so as to be invoked and executed by the processor to perform operations corresponding to the modules.
[0131] In an embodiment, a computer device, which can be a server, is provided. An internal structure diagram of the computer device can be as shown in FIG. 1. Figure 5 The computer device includes a processor, a memory, an input / output interface, and a communication interface. The processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store an image frame sequence, a buffer identifier, and the like. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to communicate with terminals outside through a network connection. The computer program is executed by the processor to implement a buffer allocation method.
[0132] Those skilled in the art can understand that Figure 5 The structure shown in FIG. 1 is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. Specifically, the computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0133] In one embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program: obtaining a to-be-processed frame when entering a decoding state; obtaining a decoding buffer from a buffer pool, decoding the to-be-processed frame through a decoder to obtain a target frame, and storing the target frame into the decoding buffer; wherein the state of the decoding buffer is a first state; performing target frame matching between the target frame and a display frame, and performing reference frame matching between the target frame and a reference frame, and setting the state of the decoding buffer to a second state when the target frame matching is matched successfully or the reference frame matching is matched successfully; setting the state of the decoding buffer to the first state when the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed completely, in a case where the state of the decoding buffer is the second state, and releasing the decoding buffer in the first state into the buffer pool.
[0134] In one embodiment, the processor, when executing the computer program, after implementing the target frame matching between the target frame and the display frame, can further comprise: adding the target frame into a display queue when the target frame matching is matched successfully, and waiting to display the target frame.
[0135] In one embodiment, the processor, when executing the computer program, after implementing the reference frame matching between the target frame and the reference frame, can further comprise: adding the to-be-processed frame corresponding to the target frame into a reference frame set in which the reference frame is located when the reference frame matching is matched successfully.
[0136] In one embodiment, the processor, when executing the computer program, further implements obtaining the decoding buffer from the buffer pool, which can comprise: polling a plurality of buffers in the buffer pool, obtaining the state of each buffer; when the state of the buffer corresponds to the first state, taking the buffer as the decoding buffer, and stopping polling the plurality of buffers in the buffer pool.
[0137] In one embodiment, the processor, when executing the computer program, further implements obtaining the decoding buffer from the buffer pool, which can further comprise: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than a maximum number of buffers, obtaining a new buffer as the decoding buffer, adding the new buffer into the buffer pool, and increasing the number of buffers in the buffer pool by 1; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool.
[0138] In one embodiment, the processor, when executing the computer program, can further implement the following steps: when there is a thread polling the plurality of buffers in the buffer pool, adding a plurality of waiting threads to a waiting queue; wherein the waiting threads are a plurality of threads that have obtained the polling right and have not polled the buffer pool; the order of the waiting queue is consistent with the order of the plurality of waiting threads obtaining the polling right; when there is no thread polling the plurality of buffers in the buffer pool, causing the first waiting thread in the waiting queue to poll the plurality of buffers in the buffer pool, and removing the first waiting thread in the waiting queue from the waiting queue.
[0139] In one embodiment, the processor, when executing the computer program, can further implement the following steps: when each of the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no new buffer is obtained as a decoding buffer; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool; the thread waiting time, when the thread waiting time is greater than the maximum waiting time, the waiting is ended, and an error prompt is returned.
[0140] In one embodiment, the processor, when executing the computer program, can implement that the maximum number of buffers is determined based on an encoding standard, a memory size, and an application program.
[0141] In one embodiment, the processor, when executing the computer program, can implement that the maximum waiting time is determined based on a decoding period of a to-be-processed frame and a preset waiting coefficient.
[0142] In one embodiment, the processor, when executing the computer program, can further implement the following steps: obtaining a sequence of image frames; determining whether the to-be-processed frame is the last frame in the sequence of image frames; when the to-be-processed frame is not the last frame in the sequence of image frames, determining a next image frame adjacent to the to-be-processed frame in the sequence of image frames as a new to-be-processed frame.
[0143] In one embodiment, a computer readable storage medium is provided, and the computer program is stored on the computer readable storage medium, and the computer program is executed by a processor to implement the following steps: when entering a decoding state, obtaining a frame to be processed; obtaining a decoding buffer from a buffer pool, decoding the frame to be processed by a decoder to obtain a target frame, and storing the target frame into the decoding buffer; wherein the state of the decoding buffer is a first state; performing target frame matching between the target frame and a display frame, and performing reference frame matching between the target frame and a reference frame, and when the target frame matching is matched successfully or the reference frame matching is matched successfully, setting the state of the decoding buffer as a second state; when the state of the decoding buffer is the second state, and when the target frame is no longer a reference frame and is not a display frame, or when the target frame is no longer a reference frame and the target frame has been displayed completely, setting the state of the decoding buffer as the first state, and releasing the decoding buffer in the first state into the buffer pool.
[0144] In one embodiment, after the computer program is executed by the processor to implement the target frame matching between the target frame and the display frame, the computer program can further be executed by the processor to implement: when the target frame matching is matched successfully, adding the target frame into a display queue, and waiting to display the target frame.
[0145] In one embodiment, after the computer program is executed by the processor to implement the reference frame matching between the target frame and the reference frame, the computer program can further be executed by the processor to implement: when the reference frame matching is matched successfully, adding the frame to be processed corresponding to the target frame into a reference frame set in which the reference frame is located.
[0146] In one embodiment, the computer program is executed by the processor to further implement the obtaining of the decoding buffer from the buffer pool, which can include: polling a plurality of buffers in the buffer pool, and obtaining the state of each buffer; when the state of the buffer corresponds to the first state, taking the buffer as the decoding buffer, and stopping the polling of the plurality of buffers in the buffer pool.
[0147] In one embodiment, the computer program is executed by the processor to implement the obtaining of the decoding buffer from the buffer pool, which can further include: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than a maximum number of buffers, obtaining a new buffer as the decoding buffer, and adding the new buffer into the buffer pool, and the number of buffers in the buffer pool is increased by 1; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool.
[0148] In one embodiment, the computer program, when executed by the processor, further implements the following steps: when there is a thread polling the plurality of buffers in the buffer pool, adding a plurality of waiting threads to a waiting queue; wherein the waiting threads are a plurality of threads that have obtained the polling right and have not polled the buffer pool; the order of the waiting queue is consistent with the order of the plurality of waiting threads obtaining the polling right; when there is no thread polling the plurality of buffers in the buffer pool, making the first waiting thread of the waiting queue poll the plurality of buffers in the buffer pool, and removing the first waiting thread of the waiting queue from the waiting queue.
[0149] In one embodiment, the computer program, when executed by the processor, implements obtaining a decoding buffer from the buffer pool, and further includes: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no new buffer is obtained as a decoding buffer; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool; the thread waiting time, when the thread waiting time is greater than the maximum waiting time, the waiting is ended, and an error prompt is returned.
[0150] In one embodiment, the computer program, when executed by the processor, can implement that the maximum number of buffers is determined based on an encoding standard, a memory size and an application program.
[0151] In one embodiment, the computer program, when executed by the processor, can implement that the maximum waiting time is determined based on a decoding period of a to-be-processed frame and a preset waiting coefficient.
[0152] In one embodiment, the computer program, when executed by the processor, further implements the following steps: obtaining a sequence of image frames; determining whether the to-be-processed frame is the last frame in the sequence of image frames; when the to-be-processed frame is not the last frame in the sequence of image frames, determining a next image frame adjacent to the to-be-processed frame in the sequence of image frames as a new to-be-processed frame.
[0153] In one embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the following steps: obtaining a frame to be processed when entering a decoding state; obtaining a decoding buffer from a buffer pool, decoding the frame to be processed by a decoder to obtain a target frame, and storing the target frame into the decoding buffer; wherein the state of the decoding buffer is a first state; performing target frame matching of the target frame with a display frame, and performing reference frame matching of the target frame with a reference frame, and setting the state of the decoding buffer to a second state when the target frame matching is successful or the reference frame matching is successful; setting the state of the decoding buffer to the first state when the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed completely, in a case where the state of the decoding buffer is the second state, and releasing the decoding buffer in the first state to the buffer pool.
[0154] In one embodiment, the computer program which, when executed by the processor, implements the target frame matching of the target frame with the display frame, can further comprise: adding the target frame into a display queue and waiting for displaying the target frame when the target frame matching is successful.
[0155] In one embodiment, the computer program which, when executed by the processor, implements the reference frame matching of the target frame with the reference frame, can further comprise: adding the frame to be processed corresponding to the target frame into a reference frame set in which the reference frame is located when the reference frame matching is successful.
[0156] In one embodiment, the computer program which, when executed by the processor, further implements the obtaining of the decoding buffer from the buffer pool, can comprise: polling a plurality of buffers in the buffer pool, and obtaining a state of each buffer; when the state of the buffer corresponds to the first state, taking the buffer as the decoding buffer, and stopping the polling of the plurality of buffers in the buffer pool.
[0157] In one embodiment, the computer program which, when executed by the processor, implements the obtaining of the decoding buffer from the buffer pool, can further comprise: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than a maximum number of buffers, obtaining a new buffer as the decoding buffer, adding the new buffer into the buffer pool, and increasing the number of buffers in the buffer pool by 1; wherein the maximum number of buffers is a maximum number of buffers in the buffer pool.
[0158] In one embodiment, the computer program, when executed by the processor, further implements the following steps: when there is a thread polling the plurality of buffers in the buffer pool, adding a plurality of waiting threads to a waiting queue; wherein the waiting threads are a plurality of threads that have obtained the polling right and have not polled the buffer pool; the order of the waiting queue is consistent with the order of the plurality of waiting threads obtaining the polling right; when there is no thread polling the plurality of buffers in the buffer pool, making the first waiting thread of the waiting queue poll the plurality of buffers in the buffer pool, and removing the first waiting thread of the waiting queue from the waiting queue.
[0159] In one embodiment, the computer program, when executed by the processor, implements obtaining a decoding buffer from the buffer pool, and further includes: when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no new buffer is obtained as a decoding buffer; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool; the thread waiting time, when the thread waiting time is greater than the maximum waiting time, the waiting is ended, and an error prompt is returned.
[0160] In one embodiment, the computer program, when executed by the processor, can implement that the maximum number of buffers is determined based on an encoding standard, a memory size and an application program.
[0161] In one embodiment, the computer program, when executed by the processor, can implement that the maximum waiting time is determined based on a decoding period of a to-be-processed frame and a preset waiting coefficient.
[0162] In one embodiment, the computer program, when executed by the processor, further implements the following steps: obtaining a sequence of image frames; determining whether the to-be-processed frame is the last frame in the sequence of image frames; when the to-be-processed frame is not the last frame in the sequence of image frames, determining a next image frame adjacent to the to-be-processed frame in the sequence of image frames as a new to-be-processed frame.
[0163] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric memory (Ferroelectric Random Access Memory, FRAM), phase change memory (Phase Change Memory, PCM), graphene memory, etc. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0164] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application.
[0165] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A method of buffer allocation, characterized by, The method comprises: When entering a decoding state, a frame to be processed is acquired; A decoding buffer is acquired from a buffer pool, the frame to be processed is decoded by a decoder to obtain a target frame, and the target frame is stored in the decoding buffer; wherein the state of the decoding buffer is a first state; the first state is an idle state; The target frame is matched with a display frame, and the target frame is matched with a reference frame; when the target frame matching is successful or the reference frame matching is successful, the state of the decoding buffer is set to a second state; the second state is a non-idle state; When the state of the decoding buffer is the second state, if the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed, the state of the decoding buffer is set to the first state, and the decoding buffer in the first state is released to the buffer pool; the decoding buffer acquired from the buffer pool comprises: A plurality of buffers in the buffer pool are polled to acquire the state of each buffer; When the state of the buffer corresponds to the first state, the buffer is used as a decoding buffer, and polling of the plurality of buffers in the buffer pool is stopped; The decoding buffer acquired from the buffer pool further comprises: When the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than a maximum buffer number, a new buffer is acquired as a decoding buffer, and the new buffer is added to the buffer pool, and the number of buffers in the buffer pool is increased by 1; wherein the maximum buffer number is the maximum number of buffers in the buffer pool; The maximum buffer number is the sum of a maximum reference frame number, a display buffer number, and a redundant buffer number; or The maximum buffer number is obtained according to memory occupied by the decoding buffer divided by memory required by each frame to be processed.
2. The method of claim 1, wherein, After the target frame is matched with the display frame, the method further comprises: When the target frame matching is successful, the target frame is added to a display queue, and the target frame is displayed.
3. The method of claim 1, wherein, After the target frame is matched with the reference frame, the method further comprises: When the reference frame matching is successful, the frame to be processed corresponding to the target frame is added to a reference frame set in which the reference frame is located.
4. The method of claim 1, wherein, The method further comprises: When there is one thread polling the plurality of buffers in the buffer pool, a plurality of waiting threads are added to a waiting queue; wherein the waiting thread is a thread that acquires a polling permission and has not polled the buffer pool; the order of the waiting queue is consistent with the order of the plurality of waiting threads acquiring the polling permission; When there is no thread polling the plurality of buffers in the buffer pool, the first waiting thread in the waiting queue polls the plurality of buffers in the buffer pool, and the first waiting thread in the waiting queue is removed from the waiting queue.
5. The method of claim 1, wherein, The decoding buffer acquired from the buffer pool further comprises: When the state of each buffer in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is equal to the maximum number of buffers, no new buffer is acquired as a decoding buffer; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool; The thread waiting time is acquired, and when the thread waiting time is greater than the maximum waiting time, the waiting is ended, and an error prompt is returned.
6. The method of claim 5, wherein, The maximum number of buffers is determined based on an encoding standard, a memory size, and an application program.
7. The method of claim 1, wherein, The maximum waiting time is determined based on a decoding period of a frame to be processed and a preset waiting coefficient.
8. The method of claim 1, wherein, The method further includes: Acquiring a sequence of image frames; Determining whether the frame to be processed is the last frame in the sequence of image frames; When the frame to be processed is not the last frame in the sequence of image frames, determining a next image frame adjacent to the frame to be processed from the sequence of image frames as a new frame to be processed.
9. A buffer allocation apparatus characterized by comprising: The device includes: An acquiring module configured to acquire a frame to be processed when entering a decoding state; A target frame acquiring module configured to acquire a decoding buffer from a buffer pool, decode the frame to be processed by a decoder to obtain a target frame, and store the target frame in the decoding buffer; wherein the state of the decoding buffer is a first state; and the first state is an idle state; A matching module configured to perform target frame matching on the target frame with a display frame, and reference frame matching on the target frame with a reference frame, and set the state of the decoding buffer to a second state when the target frame matching is successful or the reference frame matching is successful; wherein the second state is a non-idle state; A buffer releasing module configured to, when the state of the decoding buffer is the second state, set the state of the decoding buffer to the first state when the target frame is no longer a reference frame and is not a display frame, or the target frame is no longer a reference frame and the target frame has been displayed, and release the decoding buffer in the first state to the buffer pool. The target frame acquiring module includes: A polling sub-module configured to poll a plurality of buffers in the buffer pool to acquire the state of each buffer; A decoding buffer acquiring sub-module configured to, when the state of each buffer corresponds to the first state, acquire the buffer as a decoding buffer, and stop polling the plurality of buffers in the buffer pool; The target frame acquiring module further includes: A buffer increasing sub-module configured to, when the state of each buffer in the plurality of buffers in the buffer pool corresponds to the second state, and the number of buffers in the buffer pool is less than the maximum number of buffers, acquire a new buffer as a decoding buffer, and add the new buffer to the buffer pool, so that the number of buffers in the buffer pool is increased by 1; wherein the maximum number of buffers is the maximum number of buffers in the buffer pool. The maximum number of buffers is the sum of a maximum number of reference frames, a number of display buffers, and a number of redundant buffers; or The maximum number of buffers is the memory occupied by the decoding buffer divided by the memory required by each frame to be processed.
10. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 8.
11. A computer readable storage medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 8.
12. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 8.
Citation Information
Patent Citations
Video decoded picture buffer
US20080002773A1
Image signal decoding device and decoding method thereof
US20130011074A1