An audio thread processing method and device, computer equipment and storage medium
By pointing the call entry of the audio instance destruction function to the audio processing function in the iOS system and detecting the status of the audio status notification thread, the system lag or crash caused by audio thread concurrency is solved, and sequential execution is achieved to avoid resource contention.
Patent Information
- Application Number
- CN202210365555.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-06
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2042-04-06
AI Technical Summary
In iOS systems, when audio playback stops, the concurrent execution of the audio status notification thread and the audio instance destruction thread can cause system lag or crashes.
By pointing the call entry point of the audio instance destruction function to a preset audio processing function, the running status of the audio status notification thread is detected, and the audio instance destruction function is executed after the audio status notification information is returned, thus limiting the execution order of the audio status notification thread and the audio instance destruction thread.
This avoids the concurrent execution of the audio status notification thread and the audio instance destruction thread, preventing system resource contention and avoiding system lag or crashes.
Smart Images

Figure CN114721800B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computer, and in particular, to an audio thread processing method and device, a computer device and a storage medium. BACKGROUND
[0002] When an application in an IOS system plays audio, an audio instance for playing audio needs to be created. In the case of audio stopping playing, a thread running the audio instance will call a destruction function to destroy the audio instance. Meanwhile, the IOS system also runs an audio state notification thread for notifying state information of each audio playing in the system. In the case of audio stopping playing, the audio state notification thread also needs to be run to generate notification information for notifying audio stopping playing and feed back to the application.
[0003] Thus, in the case of a certain audio stopping playing, the audio state notification thread and the thread for destroying the audio instance will run at the same time, which will cause the system to appear to be stuck or even to crash. SUMMARY
[0004] The present disclosure provides at least an audio thread processing method and device, a computer device and a storage medium.
[0005] In a first aspect, the present disclosure provides an audio thread processing method, comprising:
[0006] pointing an invocation entry of an audio instance destruction function corresponding to an application to a preset audio processing function; the audio instance destruction function is used for destroying a created audio instance; the audio instance is used for playing audio;
[0007] in the case of audio stopping playing, using a first thread running the audio instance to invoke the audio processing function pointed by the audio instance destruction function;
[0008] obtaining a running state of an audio state notification thread detected by executing the audio processing function;
[0009] in the case that the running state indicates that the audio state notification thread has fed back audio state notification information for the audio, using the first thread to execute the audio instance destruction function to destroy the audio instance.
[0010] In a possible implementation, the running state of the audio state notification thread is detected according to the following steps:
[0011] determining the audio state notification thread from a plurality of threads running in the application;
[0012] obtaining an instruction address pointed to by the audio state notification thread at a current time, and determining whether the audio state notification thread is in an idle state according to the instruction address;
[0013] If yes, suspending execution of the audio state notification thread, and performing a stack backtracking operation on the audio state notification thread to determine calling stack information corresponding to the audio state notification thread;
[0014] determining the running state according to the calling stack information.
[0015] In a possible implementation, the method further includes:
[0016] In a case where it is determined that the audio state notification thread is not in the idle state, returning to the step of obtaining the instruction address pointed to by the audio state notification thread at the current time after waiting for a first preset time length until it is determined that the audio state notification thread is in the idle state.
[0017] In a possible implementation, the determining the running state according to the calling stack information includes:
[0018] determining whether there is a target calling library address corresponding to a target logical library from a plurality of calling library addresses included in the calling stack information; the target logical library stores audio interrupt processing logic information, and the audio interrupt processing logic information is used to generate audio state notification information;
[0019] If no, determining that the running state includes that the audio state notification thread has fed back audio state notification information for the audio.
[0020] In a possible implementation, the method further includes:
[0021] In a case where the target calling library address exists in the plurality of calling library addresses, resuming execution of the audio state notification thread, and returning to the step of obtaining the instruction address pointed to by the audio state notification thread at the current time after waiting for a second preset time length until it is determined that the target calling library address does not exist in the plurality of calling library addresses.
[0022] In a possible implementation, after the audio instance destruction function is executed by the first thread to destroy the audio instance, the method further includes:
[0023] resuming execution of the audio state notification thread to generate audio state notification information for other audio by using the executed audio state notification thread and feed back to the application.
[0024] In a possible implementation, the instruction address includes a program counter (PC) address and a return address;
[0025] The determining whether the audio status notification thread is in an idle state according to the instruction address comprises:
[0026] In a case where the PC address and the return address are both matched with the address corresponding to the target function body, it is determined that the audio status notification thread is in an idle state.
[0027] In a possible implementation, before detecting the running state of the audio status notification thread, the method further comprises:
[0028] determining reference information corresponding to the audio instance, and storing the reference information;
[0029] The executing the audio instance destruction function by using the first thread to destroy the audio instance comprises:
[0030] determining a storage location of the audio instance according to the stored reference information, and executing the audio instance destruction function by using the first thread to destroy the audio instance at the storage location.
[0031] In a second aspect, the embodiments of the present disclosure further provide an audio thread processing apparatus, comprising:
[0032] a first processing module configured to point an application corresponding audio instance destruction function call entry to a preset audio processing function; the audio instance destruction function is configured to destroy a created audio instance; the audio instance is configured to perform audio playing;
[0033] a calling module configured to, in a case where audio playing is stopped, call the audio processing function pointed by the audio instance destruction function by using a first thread running the audio instance;
[0034] an obtaining module configured to obtain a running state of an audio status notification thread detected by executing the audio processing function;
[0035] an executing module configured to, in a case where the running state indicates that the audio status notification thread has fed back audio status notification information of the audio, execute the audio instance destruction function by using the first thread to destroy the audio instance.
[0036] In a possible implementation, the apparatus further comprises:
[0037] a detecting module configured to determine the audio status notification thread from a plurality of threads running in the application according to the following steps:
[0038] acquire an instruction address pointed to by the audio status notification thread at a current time, and determine whether the audio status notification thread is in an idle state according to the instruction address;
[0039] If yes, suspend execution of the audio status notification thread, and perform a stack backtracking operation on the audio status notification thread to determine calling stack information corresponding to the audio status notification thread;
[0040] determine the running state according to the calling stack information.
[0041] In a possible implementation, the detection module is further configured to, in a case where it is determined that the audio status notification thread is not in the idle state, return to the step of acquiring the instruction address pointed to by the audio status notification thread at the current time after waiting for a first preset time length, until it is determined that the audio status notification thread is in the idle state.
[0042] In a possible implementation, the detection module is configured to determine, from a plurality of calling library addresses included in the calling stack information, whether a target calling library address corresponding to a target logical library exists, the target logical library storing audio interrupt processing logic information, and the audio interrupt processing logic information being used to generate audio status notification information.
[0043] If no, it is determined that the running state includes that the audio status notification thread has fed back the audio status notification information for the audio.
[0044] In a possible implementation, the detection module is further configured to, in a case where the target calling library address exists in the plurality of calling library addresses, resume execution of the audio status notification thread, and return to the step of acquiring the instruction address pointed to by the audio status notification thread at the current time after waiting for a second preset time length, until it is determined that the target calling library address does not exist in the plurality of calling library addresses.
[0045] In a possible implementation, the apparatus further includes:
[0046] The second processing module is configured to, after the audio instance destruction function is executed by using the first thread to destroy the audio instance, resume execution of the audio status notification thread, so as to generate audio status notification information for other audio by using the executed audio status notification thread and feed back the audio status notification information to the application.
[0047] In a possible implementation, the instruction address includes a program counter (PC) address and a return address.
[0048] The detection module is configured to determine that the audio status notification thread is in an idle state if the PC address and the return address both match the address corresponding to the target function body.
[0049] In a possible implementation, the apparatus further includes a storage module.
[0050] The storage module is configured to determine reference information corresponding to the audio instance and store the reference information before detecting the running state of the audio status notification thread.
[0051] The execution module is configured to determine a storage location of the audio instance according to the stored reference information, and execute the audio instance destruction function by using the first thread to destroy the audio instance at the storage location.
[0052] In a third aspect, the present disclosure provides a computer device, a processor, and a memory. The memory stores machine readable instructions executable by the processor. The processor is configured to execute the machine readable instructions stored in the memory. When the machine readable instructions are executed by the processor, the machine readable instructions perform the steps of the first aspect or any possible implementation of the first aspect.
[0053] In a fourth aspect, the present disclosure provides a computer readable storage medium. The computer readable storage medium stores a computer program. When the computer program is executed, the computer program performs the steps of the first aspect or any possible implementation of the first aspect.
[0054] The effects of the audio thread processing apparatus, the computer device, and the computer readable storage medium are described above in the description of the audio thread processing method, and thus are not described here again.
[0055] The audio thread processing method, device, computer device and storage medium provided by the embodiments of the present disclosure can accurately determine whether the audio state notification thread has fed back the audio state notification information for the audio that stops playing before the audio instance is destroyed by executing the audio instance destruction function using the first thread, by calling the audio processing function pointed to by the audio instance destruction function when the audio stops playing, and then detecting the running state of the audio state notification thread by executing the audio processing function. Then, the audio instance is destroyed by executing the audio instance destruction function using the first thread when it is determined that the audio state notification information has been fed back. In this way, the execution order of the audio state notification thread and the first thread for destroying the audio instance is limited by using the preset audio processing function, which does not affect the running of the first thread for destroying the audio instance and the audio state notification thread in the system, and avoids the concurrent execution of the audio state notification thread and the first thread for destroying the audio instance. Furthermore, the problem of system freezing or crashing caused by the competition of system resources by the two threads is avoided.
[0056] In order to make the above objectives, characteristics and advantages of the present disclosure more apparent and easy to understand, a preferred embodiment is described below, and the accompanying drawings are described in detail as follows. BRIEF DESCRIPTION OF DRAWINGS
[0057] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings needed in the embodiments will be briefly introduced as follows. The drawings are incorporated into the specification and form a part of the specification, which illustrate the embodiments consistent with the present disclosure, and are used to explain the technical solutions of the present disclosure together with the specification. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be considered as a limitation on the scope, and other related drawings can also be obtained by those skilled in the art without creative labor.
[0058] Figure 1 A flowchart of an audio thread processing method provided by the embodiments of the present disclosure is shown;
[0059] Figure 2 A specific implementation flowchart of an audio thread processing method provided by the embodiments of the present disclosure is shown;
[0060] Figure 3 A schematic diagram of an audio thread processing device provided by the embodiments of the present disclosure is shown;
[0061] Figure 4 A structural schematic diagram of a computer device provided by the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0062] To make the purposes, technical solutions, and advantages of the embodiments of the present disclosure clearer, the following will be combined with the accompanying drawings in the embodiments of the present disclosure to make a clear and complete description of the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, but not all the embodiments. The components of the embodiments of the present disclosure described and shown herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure is not intended to limit the scope of the claimed present disclosure, but only represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work belong to the scope of protection of the present disclosure.
[0063] In addition, the terms "first", "second", and the like in the specification and claims of the embodiments of the present disclosure and the above-described accompanying drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein.
[0064] "Multiple or several" mentioned herein refers to two or more. "And / or" describes the association between the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent the three cases of A alone, A and B together, and B alone. The character " / " generally represents that the front and rear associated objects are in an "or" relationship.
[0065] It is found through research that, in the IOS system, in the case of stopping playing, the audio state notification thread usually competes with the thread for destroying the audio instance for system resources, causing the audio application and the system to appear to be stuck or even to crash.
[0066] Based on the above research, the present disclosure provides an audio thread processing method and device, computer equipment and storage medium, which uses a preset audio processing function to limit the execution order of the audio state notification thread and the first thread for destroying the audio instance, so as to neither affect the running of the first thread for destroying the audio instance and the audio state notification thread in the system, nor avoid the concurrent execution of the audio state notification thread and the first thread for destroying the audio instance. Further, the problem of system sticking or crashing caused by the competition of the two threads for system resources is avoided.
[0067] The defects of the above solutions are the result of the inventors' practice and careful research, so the discovery process of the above problems and the solutions proposed by the present disclosure to solve the above problems should be the contribution of the inventors to the present disclosure in the process of the present disclosure.
[0068] It should be noted that like reference numerals and characters refer to like elements throughout the following figures and the detailed description, and thus, once certain terms are defined in one figure, they should not necessitate further detailing and explanation in a following figure.
[0069] It should be noted that the specific terms mentioned in the embodiments of the present disclosure include:
[0070] Program Counter (PC): a register in a computer processor that contains the address of the instruction currently being executed. When each instruction is fetched, the program counter's memory address is incremented by one, and after each instruction is fetched, the program counter points to the next instruction in the sequence.
[0071] To facilitate the understanding of the present embodiment, first, the online course resource usage method disclosed by the present embodiment is introduced in detail. The execution subject of the online course resource usage method provided by the present embodiment is generally a terminal device or other processing device with certain computing power, wherein the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computer device, etc. In some possible implementation manners, the online course resource usage method can be realized by a processor calling computer readable instructions stored in a memory.
[0072] The audio thread processing method provided by the present embodiment will be described below taking a computer device as an example.
[0073] As shown in FIG. 1, the flowchart of the audio thread processing method provided by the present embodiment can include the following steps: Figure 1
[0074] S101: Point the call entry of the audio instance destruction function corresponding to the application to a preset audio processing function; the audio instance destruction function is used to destroy the created audio instance; the audio instance is used for audio playing.
[0075] Here, the application can be any application running in the IOS system and capable of audio playing. The audio instance destruction function is an audio unit in the IOS system, which is used to destroy the created audio instance. The audio unit is created when audio playing, and is used for audio playing. The audio unit can be destroyed when audio playing is stopped, so as to release the system resources. The audio playing stop can include but is not limited to two cases of audio content playing being completed and playing being interrupted.
[0076] The audio processing function (My_dispose function) is a preset processing function corresponding to an audio processing logic for detecting whether the audio state notification thread in the system has fed back the audio state notification information for the currently stopped playing audio.
[0077] In implementation, the calling entry of the audio instance destruction function corresponding to the application in the IOS system can be directed to the preset audio processing function by using the GOTHook. The GOT is a table for storing function address information, and the IOS system can store various functions in the table, such as execution functions, destruction functions, and replacement functions. The GOTHOOK is a way of replacing the function address stored in the GOT table with the address of another function.
[0078] The calling entry of the audio instance destruction function corresponding to the application in the IOS system is directed to the preset audio processing function, that is, the entry address of the audio instance destruction function is replaced with the address of the preset audio processing function.
[0079] Alternatively, if the audio instance destruction functions corresponding to various applications in the IOS system are different, the calling entries of the audio instance destruction functions corresponding to various applications can be directed to the preset audio processing function. Similarly, if each application in the IOS system corresponds to an audio instance destruction function, the calling entry of the unique audio instance destruction function can be directed to the preset audio processing function.
[0080] S102: In the case of audio stopping playing, the audio processing function pointed to by the audio instance destruction function is called by the first thread running the audio instance.
[0081] The first thread can be any thread running in the application, and specifically can be the thread of the audio instance corresponding to the currently stopped playing audio.
[0082] In implementation, in the case of audio stopping playing, the audio instance destruction function can be called by the first thread, and since the entry address corresponding to the first audio instance destruction function has been replaced with the address of the preset audio processing function, the audio processing function pointed to by the replaced entry address will be automatically called after the audio instance destruction function is called. In this way, the audio processing function pointed to by the calling entry of the audio instance destruction function called by the first thread running the audio instance is realized.
[0083] It should be noted that there is no strict execution order between S101 and S102. In specific implementation, the call entry of the audio instance destruction function can be pre-pointed to the preset audio processing function by using the GOTHook mode, or the call entry of the audio instance destruction function corresponding to the application playing the audio can be pointed to the preset audio processing function when it is determined that there is currently audio to be stopped playing, and the embodiments of the present disclosure do not make specific limitation.
[0084] S103: Obtain the running state of the audio state notification thread detected by executing the audio processing function.
[0085] Here, the audio state notification thread is a default notification thread in the IOS system, that is, AVAudioSessionNotify Thread, which is used to send the state of the audio in the IOS system to the application corresponding to the audio. For example, a notification of starting to play the current audio is generated, a notification of stopping playing the audio is generated, and a notification of an exception in playing the audio is generated. The audio state notification thread can be created when the IOS system first plays the audio, and can exist after being created, and is used to notify the state of each audio in the IOS system.
[0086] The running state is used to indicate whether the audio state notification thread has generated audio state notification information for the current audio to be stopped playing and has fed back.
[0087] In specific implementation, after the audio processing function is called, the audio processing function can be executed, and the running state of the audio state notification thread is detected according to the detection logic indicated by the audio processing function. Further, by executing the audio processing function, the running state of the audio state notification thread detected can be obtained.
[0088] In an embodiment, the running state of the audio state notification thread can be detected according to the following steps:
[0089] Step one, determine the audio state notification thread from a plurality of threads running in the application.
[0090] Here, an application can run multiple threads, for example, an audio thread, a system default thread, a picture display thread, and the like.
[0091] In specific implementation, in the process of executing the audio processing function, the audio state notification thread can be determined from a plurality of threads running in the application.
[0092] Step two, obtain the instruction address pointed to by the audio state notification thread at the current time, and determine whether the audio state notification thread is in an idle state according to the instruction address.
[0093] Here, the instruction address is used to indicate the pointer address corresponding to the audio status notification thread.
[0094] In implementation, after the audio status notification thread is determined, the instruction address pointed to by the audio status notification thread at the current time can be acquired, and it is determined whether the instruction address is located in the target function body (mach_msg function body) or not, that is, whether the instruction address matches the address corresponding to the mach_msg function body. The mach_msg function is a function used to indicate whether a thread is running in a processor or not.
[0095] If it is determined that the instruction address is located in the mach_msg function body, it can be determined that the audio status notification thread is in the idle state; otherwise, it can be determined that the audio status notification thread is not in the idle state, that is, it is running.
[0096] In an embodiment, if it is determined that the audio status notification thread is not in the idle state, it indicates that the current audio status notification thread is still executing, and then a timer can be created, and when the timer counts to a first preset time length, the above step two is returned to be executed until it is determined that the audio status notification thread is in the idle state.
[0097] The timer counts to the first preset time length, that is, waits for the first preset time length. The first preset time length can be a waiting time length preset by a developer, for example, the first preset time length can be 10 seconds (S), 8S, etc.
[0098] In an embodiment, the instruction address can include at least one of the PC address and the return address corresponding to the audio status notification thread. In the case where the instruction address only includes the PC address or the return address, if it is determined that one of the addresses is located in the mach_msg function body, it can be determined that the audio status notification thread is in the idle state.
[0099] In the case where the instruction address includes both the PC address and the return address, it is necessary to determine that both the PC address and the return address match the address corresponding to the target function body, that is, it is necessary to determine that both the PC address and the return address are located in the mach_msg function body, before it can be determined that the audio status notification thread is in the idle state. Otherwise, it is determined that the audio status notification thread is not in the idle state. In this way, the use of the PC address and the return address for idle state verification can improve the accuracy of determining the idle state of the audio status notification thread.
[0100] Step three, if yes, the execution of the audio status notification thread is suspended, and a stack backtracking operation on the audio status notification thread is performed to determine the call stack information corresponding to the audio status notification thread.
[0101] Here, the call stack information includes each call library address called by the audio status notification thread in the execution process.
[0102] In a specific implementation, in a case where it is determined that the audio status notification thread is in the idle state, the audio status notification thread in the idle state can be suspended. Meanwhile, a stack backtracking operation can be performed on the audio status notification thread to determine each call library address called by the audio status notification thread in the execution process, that is, to obtain the call stack information.
[0103] Step 4: determining a running state according to the call stack information.
[0104] In a specific implementation, according to each call library address included in the call stack information, it can be determined whether the audio status notification thread has fed back the audio status notification information for the currently stopped audio.
[0105] In an embodiment, for step 4, the following steps can be implemented: from the multiple call library addresses included in the call stack information, it is determined whether there is a target call library address corresponding to a target logical library. The target logical library can be libEmbeddedSystemAUs.dylib in particular, where the audio interruption processing logic information is stored, and the audio interruption processing logic information is used to generate the audio status notification information. libEmbeddedSystemAUs.dylib is a system library created in an IOS system and used to store the audio interruption processing logic information.
[0106] The audio status notification thread can execute the audio interruption processing operation according to the audio interruption processing logic information to generate the audio status notification information.
[0107] In a specific implementation, in a case where it is determined that there is no target call library address corresponding to the target logical library in the multiple call library addresses included in the call stack information, it can be indicated that the audio status notification thread has currently completed the audio interruption processing operation for the currently stopped audio. In this way, it can be determined that the running state of the audio status notification thread includes that the audio status notification thread has generated the audio status notification information for the currently stopped audio and has fed back the audio status notification information to the application corresponding to the audio.
[0108] In another embodiment, in a case where there is the target call library address in the multiple call library addresses, the execution of the audio status notification thread is resumed, and the step of obtaining the instruction address pointed to by the audio status notification thread at the current time is returned after waiting for a second preset time length, until it is determined that there is no target call library address in the multiple call library addresses.
[0109] Here, if it is determined that the target calling library address exists in the multiple calling library addresses included in the calling stack information, it indicates that the audio state notification thread has not completed the audio interrupt processing operation for the currently stopped audio, and needs to continue to execute. Therefore, it is necessary to resume the execution of the audio state notification thread in the idle state suspended when the above step three is executed, and create a timer timer, and when it is determined that the timer counts to the second preset time length, return to execute the above step two, step three, until it is determined that the target calling library address does not exist in the multiple calling library addresses included in the calling stack information.
[0110] Here, the reason for returning to execute the above step two is that the instruction address corresponding to the audio state notification thread will change in real time during execution, and then the result of whether the audio state notification thread is in the idle state will also change. Therefore, by returning to execute the above step two, the idle state of the audio state notification thread can be determined again, and then the accurate running state of the audio state notification thread can be determined.
[0111] The second preset time length is also a waiting time length preset by the developer, which can be equal to or not equal to the first preset time length, which is not limited here.
[0112] S104: In the case where the running state indicates that the audio state notification thread has fed back the audio state notification information for the audio, the audio instance destruction function is executed by the first thread to destroy the audio instance.
[0113] Here, the audio state notification information is used to notify the application that the audio has stopped playing.
[0114] Specifically, in the case where the running state indicates that the audio state notification thread has fed back the audio state notification information for the audio to the application, according to the above step three, it can be known that the audio state notification thread has been suspended at this time. Therefore, the audio instance destruction function corresponding to the currently stopped audio can be executed by the first thread to achieve the destruction of the audio instance.
[0115] Thus, based on the above embodiments, the detection logic indicated by the audio processing function can be specifically that whether the audio state notification thread is idle is first detected, if not, the first preset time period is waited, and whether the audio state notification thread is idle is detected again until it is determined that the audio state notification thread is in an idle state. If yes, whether the target call library address corresponding to the target logic library exists in the plurality of call library addresses corresponding to the audio state notification thread is detected, if not, it is determined that the running state is that the audio state notification information for the audio currently stopped playing has been generated and fed back. If yes, the second preset time period is waited, and it is returned to detect whether the audio state notification thread is idle until it is determined that the target call library address does not exist in the plurality of call library addresses. Further, the audio instance destruction function can be executed to destroy the audio instance.
[0116] In an embodiment, after the audio instance destruction function is executed by the first thread to destroy the audio instance, the audio state notification thread at this time is still in a suspended state. Therefore, the execution of the audio state notification thread can also be restored to generate the audio state notification information for other audio by the executed audio state notification thread and feed back to the application.
[0117] In this way, by restoring the execution of the audio state notification thread, the audio state notification information for the subsequent audio playing in the system can be generated by the audio state notification thread, for example, the notification of the current start playing audio is generated, and the notification of the audio stop playing is generated. Thus, the audio state notification information corresponding to each audio playing in the system can be acquired in time.
[0118] In an embodiment, before detecting the running state of the audio state notification thread, the reference information corresponding to the audio instance can also be determined and stored. The reference information is used to indicate the storage location of the audio instance. For example, the reference information can be the pointer address, reference relationship, storage address, and the like corresponding to the audio instance. In this way, by storing the reference information corresponding to the audio instance, the audio instance can be temporarily stored, which facilitates finding the audio instance when the destruction operation is performed subsequently.
[0119] Further, when the step of executing the audio instance destruction function by the first thread to destroy the audio instance is performed, the storage location of the audio instance can be determined according to the stored reference information corresponding to the audio instance. Then, the audio instance destruction function can be executed by the first thread to destroy the audio instance stored at the storage location.
[0120] Thus, based on the above embodiments, the preset audio processing function is used to limit the execution sequence of the audio state notification thread and the first thread for destroying the audio instance, which does not affect the running of the first thread for destroying the audio instance and the audio state notification thread in the system, and avoids the concurrent execution of the audio state notification thread and the first thread for destroying the audio instance. Further, the problem of system freezing or death caused by the competition of the two threads for system resources is effectively avoided.
[0121] As shown in Figure 2 a specific implementation flowchart of an audio thread processing method provided by the embodiment of the present disclosure can include the following steps:
[0122] S201: Point the call entry of the audio instance destruction function corresponding to the application to the preset audio processing function.
[0123] S202: In the case of audio stop playing, the audio processing function pointed by the audio instance destruction function is called by the first thread.
[0124] S203: Determine the audio state notification thread from the multiple threads running in the application.
[0125] S204: Obtain the instruction address pointed by the audio state notification thread at the current time, and determine whether the audio state notification thread is in an idle state according to the instruction address.
[0126] Here, the instruction address can include a PC address and a return address.
[0127] If yes, S205 is executed; if no, a timer can be started, and after the timer counts for a first preset time length, S204 is returned to be executed until it is determined that the audio state notification thread is in an idle state.
[0128] S205: Perform a stack backtracking operation on the audio state notification thread to determine the call stack information corresponding to the audio state notification thread.
[0129] S206: Determine whether there is a target call library address corresponding to a target logic library from the multiple call library addresses included in the call stack information.
[0130] If no, it is determined that the running state corresponding to the audio state notification thread includes that the audio state notification thread has fed back the audio state notification information for the audio, and S207 is executed; if yes, the execution of the audio state notification thread is resumed, and a timer is started, and after the timer counts for a second preset time length, S204 is returned to be executed until it is determined that there is no target call library address in the multiple call library addresses.
[0131] S207: Execute the audio instance destruction function by the first thread to destroy the audio instance.
[0132] S208: Resuming execution of the audio state notification thread.
[0133] The specific implementation steps of S201-S208 can refer to the above embodiments, and will not be described here.
[0134] Those skilled in the art can understand that, in the above method of the specific implementation, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process, and the specific execution order of each step should be determined by its function and possible internal logic.
[0135] Based on the same inventive concept, the present disclosure also provides an audio thread processing device corresponding to the audio thread processing method. Since the device in the present disclosure solves the problem in the same principle as the above-mentioned audio thread processing method of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described here.
[0136] As shown in FIG. 1, a schematic diagram of an audio thread processing device provided by the present disclosure includes: Figure 3
[0137] The first processing module 301 is configured to point the call entry of the audio instance destruction function of the application to a preset audio processing function; the audio instance destruction function is configured to destroy the created audio instance; and the audio instance is configured to play audio.
[0138] The calling module 302 is configured to, in the case of stopping playing audio, call the audio processing function pointed by the audio instance destruction function by using the first thread running the audio instance.
[0139] The obtaining module 303 is configured to obtain the running state of the audio state notification thread detected by executing the audio processing function.
[0140] The execution module 304 is configured to, in the case that the running state indicates that the audio state notification thread has fed back the audio state notification information of the audio, execute the audio instance destruction function by using the first thread to destroy the audio instance.
[0141] In a possible implementation, the device further includes:
[0142] The detection module 305 is configured to determine the audio state notification thread from a plurality of threads running in the application according to the following steps:
[0143] obtaining an instruction address pointed to by the audio state notification thread at a current time, and determining whether the audio state notification thread is in an idle state according to the instruction address;
[0144] If yes, suspending execution of the audio state notification thread, and performing a stack backtracking operation on the audio state notification thread to determine calling stack information corresponding to the audio state notification thread;
[0145] determining the running state according to the calling stack information.
[0146] In a possible implementation, the detection module 305 is further configured to, in a case where it is determined that the audio state notification thread is not in the idle state, return to the step of obtaining the instruction address pointed to by the audio state notification thread at the current time after waiting for a first preset time length, until it is determined that the audio state notification thread is in the idle state.
[0147] In a possible implementation, the detection module 305 is configured to determine, from a plurality of calling library addresses included in the calling stack information, whether a target calling library address corresponding to a target logical library exists, the target logical library storing audio interrupt processing logic information, and the audio interrupt processing logic information being used to generate audio state notification information.
[0148] If no, it is determined that the running state includes that the audio state notification thread has fed back the audio state notification information for the audio.
[0149] In a possible implementation, the detection module 305 is further configured to, in a case where the target calling library address exists in the plurality of calling library addresses, resume execution of the audio state notification thread, and return to the step of obtaining the instruction address pointed to by the audio state notification thread at the current time after waiting for a second preset time length, until it is determined that the target calling library address does not exist in the plurality of calling library addresses.
[0150] In a possible implementation, the apparatus further includes:
[0151] The second processing module 306 is configured to, after the audio instance destruction function is executed by the first thread to destroy the audio instance, resume execution of the audio state notification thread, so as to generate audio state notification information for other audio by the executed audio state notification thread and feed back to the application.
[0152] In a possible implementation, the instruction address includes a program counter (PC) address and a return address.
[0153] The detection module 305 is configured to determine that the audio state notification thread is in an idle state if the PC address and the return address both match the address corresponding to the target function body.
[0154] In a possible implementation, the apparatus further includes a storage module 307.
[0155] The storage module 307 is configured to determine reference information corresponding to the audio instance and store the reference information before detecting the running state of the audio state notification thread.
[0156] The execution module 304 is configured to determine a storage location of the audio instance according to the stored reference information, and execute the audio instance destruction function by using the first thread to destroy the audio instance at the storage location.
[0157] The description of the processing procedure of each module in the apparatus and the interaction procedure between the modules can refer to the related description in the method embodiments, and will not be repeated here.
[0158] Based on the same technical concept, the embodiments of the present application further provide a computer device. Referring to FIG. 11, Figure 4 The computer device provided by the embodiments of the present application includes:
[0159] a processor 41, a memory 42, and a bus 43. The memory 42 stores machine readable instructions executable by the processor 41, and the processor 41 is configured to execute the machine readable instructions stored in the memory 42. When the machine readable instructions are executed by the processor 41, the processor 41 performs the following steps: S101: pointing an application corresponding audio instance destruction function call entry to a preset audio processing function; the audio instance destruction function is used to destroy the created audio instance; the audio instance is used for audio playing; S102: in the case of audio stopping playing, calling the audio processing function pointed by the audio instance destruction function by using a first thread running the audio instance; S103: obtaining the running state of an audio state notification thread detected by executing the audio processing function; and S104: in the case of the running state indicating that the audio state notification thread has fed back the audio state notification information of the audio, executing the audio instance destruction function by using the first thread to destroy the audio instance.
[0160] The memory 42 includes an internal memory 421 and an external memory 422; the internal memory 421 is also referred to as an internal storage, and is used to temporarily store operation data in the processor 41 and exchange data with the external memory 422 such as a hard disk; the processor 41 exchanges data with the external memory 422 through the internal memory 421; when the computer device is running, the processor 41 communicates with the memory 42 through a bus 43, so that the processor 41 executes the execution instructions mentioned in the above method embodiments.
[0161] The computer readable storage medium provided in the embodiments of the present disclosure stores a computer program, and the computer program is run by a processor to execute the steps of the audio thread processing method described in the above method embodiments. The storage medium can be a volatile or non-volatile computer readable storage medium.
[0162] The computer program product of the audio thread processing method provided in the embodiments of the present disclosure includes a computer readable storage medium storing program codes, and the program codes include instructions for executing the steps of the audio thread processing method described in the above method embodiments. For details, refer to the above method embodiments, which will not be described here.
[0163] The computer program product can be specifically implemented in the form of hardware, software or a combination thereof. In an optional embodiment, the computer program product is specifically embodied as a computer storage medium, and in another optional embodiment, the computer program product is specifically embodied as a software product, such as a software development kit (Software Development Kit, SDK) and the like.
[0164] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device can refer to the corresponding process in the foregoing method embodiments, which will not be described here. In several embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division, and actual implementation can be in another division manner. For example, a plurality of units or components can be combined, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some communication interfaces, devices or units, and can be electrical, mechanical or other forms.
[0165] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e., may be located in one place, or may be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0166] In addition, each functional unit in various embodiments of the present disclosure can be integrated into one processing unit, or each unit can exist physically, or two or more units can be integrated into one unit.
[0167] If the functions are realized in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer readable storage medium executable by a processor. Based on this understanding, the technical solutions of the present disclosure essentially or say the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in various embodiments of the present disclosure. The foregoing storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk, and various media that can store program codes.
[0168] If the technical solutions of the present application involve personal information, the product applying the technical solutions of the present application has been explicitly informed of the personal information processing rules before processing the personal information, and has obtained the personal independent consent. If the technical solutions of the present application involve sensitive personal information, the product applying the technical solutions of the present application has obtained the personal independent consent before processing the sensitive personal information, and at the same time meets the requirement of "explicit consent". For example, at the personal information collection device such as camera, set up clear and obvious mark to inform that it has entered the personal information collection range, and will collect personal information, if the individual voluntarily enters the collection range, it is considered to agree to collect personal information; or on the device for processing personal information, through the pop-up information or by uploading personal information by the individual, the individual is authorized under the condition of using obvious mark / information to inform the personal information processing rules; wherein, the personal information processing rules can include personal information processor, personal information processing purpose, processing method, processing personal information type and other information.
[0169] Finally, it should be noted that the above-described embodiments are merely specific embodiments of the present disclosure, used to illustrate the technical solutions of the present disclosure, and are not intended to limit the present disclosure. The protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can make modifications or easy changes to the technical solutions described in the foregoing embodiments, or easily think of changes or equivalent replacements for some of the technical features; and these modifications, changes or replacements do not cause the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. A method of audio thread processing, the method comprising: The method comprises the following steps: pointing an application corresponding audio instance destruction function call entry to a preset audio processing function; the audio instance destruction function is used to destroy the created audio instance; the audio instance is used to play audio; in the case of audio stop playing, calling the audio processing function pointed by the audio instance destruction function by using a first thread running the audio instance; obtaining the running state of the audio state notification thread detected by executing the audio processing function; in the case that the running state indicates that the audio state notification thread has fed back the audio state notification information of the audio, executing the audio instance destruction function by using the first thread to destroy the audio instance.
2. The method of claim 1, wherein, The running state of the audio state notification thread is detected according to the following steps: determining the audio state notification thread from a plurality of threads running in the application; obtaining the instruction address pointed by the audio state notification thread at the current time, and determining whether the audio state notification thread is in an idle state according to the instruction address; if yes, suspending the execution of the audio state notification thread and performing a stack backtracking operation on the audio state notification thread to determine the call stack information corresponding to the audio state notification thread; determining the running state according to the call stack information.
3. The method of claim 2, wherein, The method further comprises: in the case that the audio state notification thread is not in an idle state, returning to the step of obtaining the instruction address pointed by the audio state notification thread at the current time after waiting for a first preset time length until determining that the audio state notification thread is in an idle state.
4. The method of claim 2, wherein, The method further comprises: from the plurality of call library addresses included in the call stack information, determining whether there is a target call library address corresponding to a target logical library; the target logical library stores audio interruption processing logic information, and the audio interruption processing logic information is used to generate audio state notification information; if no, determining that the running state includes that the audio state notification thread has fed back the audio state notification information of the audio.
5. The method of claim 4, wherein, The method further comprises: in the case that the target call library address exists in the plurality of call library addresses, resuming the execution of the audio state notification thread, and returning to the step of obtaining the instruction address pointed by the audio state notification thread at the current time after waiting for a second preset time length until determining that the target call library address does not exist in the plurality of call library addresses.
6. The method of claim 5, wherein, After the audio instance is destroyed by executing the audio instance destruction function by using the first thread, the method further comprises: resuming the execution of the audio state notification thread to generate audio state notification information of other audio by using the executed audio state notification thread and feed back to the application.
7. The method of claim 2, wherein, The instruction address includes a program counter PC address and a return address. The method further comprises: In a case where it is determined that the PC address and the return address both match an address corresponding to a target function body, it is determined that the audio status notification thread is in an idle state, wherein the target function body is a function indicating whether a thread is running in a processor.
8. The method of claim 1, wherein, Before detecting the running state of the audio status notification thread, the method further includes: determining reference information corresponding to the audio instance, and storing the reference information; the audio instance destruction function is executed by the first thread to destroy the audio instance, including: determining a storage location of the audio instance according to the stored reference information, and executing the audio instance destruction function by the first thread to destroy the audio instance at the storage location.
9. An audio thread processing apparatus, characterized by comprising: including: a first processing module configured to point an application corresponding audio instance destruction function call entry to a preset audio processing function; the audio instance destruction function is configured to destroy a created audio instance; and the audio instance is configured to perform audio playing; a calling module configured to, in a case where audio playing is stopped, call the audio processing function pointed by the audio instance destruction function by a first thread running the audio instance; an obtaining module configured to obtain a running state of an audio status notification thread detected by executing the audio processing function; an executing module configured to, in a case where the running state indicates that the audio status notification thread has fed back audio status notification information for the audio, execute the audio instance destruction function by the first thread to destroy the audio instance.
10. A computer device, comprising: including: a processor and a memory, the memory storing machine readable instructions executable by the processor, the processor being configured to execute the machine readable instructions stored in the memory, and the machine readable instructions being executed by the processor to perform the steps of the audio thread processing method according to any one of claims 1 to 8.
11. A computer readable storage medium, characterized in that, a computer readable storage medium storing a computer program, and the computer program being executed by a computer device to perform the steps of the audio thread processing method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method for managing thread group of program
CN101751293A