Audio service implementation method and device, electronic equipment and readable medium
By recording the identification, priority information and available status of the audio device in the resource playback sequence table, the pulse audio service realizes dynamic switching between multiple audio devices, solving the problem that PulseAudio cannot achieve dynamic switching, and improving the reliability and response efficiency of the audio service.
Patent Information
- Application Number
- CN202411940146.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-24
- Publication Date
- 2025-04-11
AI Technical Summary
PulseAudio cannot achieve dynamic switching between multiple different audio devices, especially in sequential memory after restart, and there are quality and reliability issues when switching audio devices.
By recording the identification, priority information and available status of the audio device in the resource playback sequence table, the pulse audio service determines the target audio device based on this information and updates the priority and available status in real time when the audio device is connected or unplugged.
Dynamic switching between multi-audio devices is realized, the response efficiency and reliability of pulsed audio services are improved, and the smooth interaction and playback of audio resources are ensured.
Smart Images

Figure CN119806466A_ABST
Abstract
Description
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] The present disclosure is a divisional application of an application with an application date of October 24, 2022, application number 202211305898.4, and invention name “Audio service implementation method, device, electronic device and readable medium”. The entire contents of the parent case are incorporated into this article by reference. Technical Field
[0003] The present disclosure relates to the field of audio technology, and in particular to an audio service implementation method, device, electronic device and readable medium. Background Art
[0004] Currently, PulseAudio is a service based on an audio server implementation, which receives sound input from one or more sound sources (including processes or input devices) through a background process, and then redirects it to one or more slots, such as sound cards, remote network PulseAudio services or other processes.
[0005] In the related art, one purpose of PulseAudio is to direct all sound streams, including processes that attempt to access hardware. PulseAudio provides audio resources to different sound systems by providing adapters.
[0006] However, without manual operation, PulseAudio cannot realize dynamic switching between multiple different audio devices (including the order after restart), such as multiple USB (Universal Serial Bus) headphones, multiple DP (DisplayPort) interfaces connected to external HDMI (High Definition Multimedia Interface) monitors, etc. In addition, there are many anomalies in the process of switching audio devices, which even affect the quality and reliability of Pulse Audio services.
[0007] It should be noted that the information disclosed in the above background technology section is only configured to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the invention
[0008] The purpose of the present disclosure is to provide an audio service implementation method, device, electronic device and readable medium, which are configured to at least to some extent overcome the problem of poor reliability of PulseAudio in providing pulse audio services due to limitations and defects of related technologies.
[0009] According to a first aspect of an embodiment of the present disclosure, a method for implementing an audio service is provided, comprising: when it is necessary to provide audio resources for a terminal device, a pulse audio service determines a target audio device according to the priority of at least one audio device in a resource playback sequence table, wherein the resource playback sequence table includes an audio device identifier, corresponding priority information, and an available status of the audio device, the audio device identifier includes device information and port information, and the available status indicates whether the priority information corresponding to the audio device identifier is valid; the pulse audio service provides audio resources based on the target audio device.
[0010] In an exemplary embodiment of the present disclosure, it also includes: when the pulse audio service is initialized, the pulse audio service loads a resource playback order table, and updates the priority information of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device; the access order of the audio device is the order in which at least one audio device accesses the terminal device; the pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that is not connected to the terminal device in the resource playback order table to the lowest priority.
[0011] In an exemplary embodiment of the present disclosure, updating the priority information of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device includes: when there is an audio device that does not belong to the resource playback order table among the audio devices of the access terminal device, the pulse audio service adds the audio device identifier corresponding to the audio device to the resource playback order table, and sets the corresponding priority information for the audio device identifier corresponding to the audio device.
[0012] In an exemplary embodiment of the present disclosure, it also includes: updating the priority information of the audio device identifier corresponding to the audio device in the resource playback sequence table according to the access order of at least one audio device, including: in response to a hot plug event of the audio device, determining the newly connected audio device or the newly unplugged audio device corresponding to the hot plug event; if it is a newly connected audio device, the pulse audio service determines whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table, and if so, sets the priority of the audio device identifier corresponding to the newly connected audio device in the resource playback sequence table to the highest priority; if not, writes the device identifier corresponding to the newly connected audio device into the resource playback sequence table, and sets the priority of the device identifier corresponding to the newly connected audio device in the resource playback sequence table to the highest priority; if it is a newly unplugged audio device, the pulse audio service sets the priority of the audio device identifier of the newly unplugged audio device in the resource playback sequence table to the lowest priority.
[0013] In an exemplary embodiment of the present disclosure, the pulse audio service sets the priority of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback order table to a preset priority, and performs static detection on the audio device that does not support hot plugging; updates the priority information of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device, including: in response to a hot plug event of a first audio device other than the audio device that does not support hot plugging, determining a newly connected first audio device or a newly unplugged first audio device corresponding to the hot plug event; if it is a newly connected first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource playback order table to be higher than the priority of the audio device that does not support hot plugging in the resource playback order table; if it is a newly unplugged first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource playback order table to be no higher than the priority of the audio device that does not support hot plugging in the resource playback order table.
[0014] In an exemplary embodiment of the present disclosure, priority information of an audio device identifier corresponding to an audio device in a resource playback order table is updated according to an access order of at least one audio device, including: updating priority information and an available status of an audio device identifier corresponding to an audio device in a resource playback order table according to an access order of at least one audio device; the available status is available or unavailable.
[0015] In an exemplary embodiment of the present disclosure, the resource playback sequence table also includes the available status of the audio device, and the pulse audio service determines the target audio device according to the priority of the audio device in the resource playback sequence table, including: the pulse audio service determines the target audio device according to the priority and available status of the audio device in the resource playback sequence table; the target audio device is determined according to the priority of at least one audio device in the resource playback sequence table, including: determining whether the priority information corresponding to the audio device identifier is valid according to the available status corresponding to each audio device identifier in the resource playback sequence table; wherein the priority information corresponding to the audio device identifier with an available status is valid, and the priority information corresponding to the audio device identifier with an available status is invalid; and determining the target audio device from at least one audio device based on the valid priority information.
[0016] In an exemplary embodiment of the present disclosure, it also includes: initializing the pulse audio service, including: initializing the pulse audio service, loading the resource playback sequence table; scanning the port status of the terminal device, and determining the initial access status of the audio device corresponding to each audio device identifier included in the resource playback sequence table; the initial access status is connected or not connected; writing the available status of the audio device identifier corresponding to the audio device whose initial access status is connected in the resource playback sequence table as available; writing the available status of the audio device identifier corresponding to the audio device whose initial access status is not connected in the resource playback sequence table as unavailable.
[0017] In an exemplary embodiment of the present disclosure, the priority information and available status of the audio device identifier corresponding to the audio device in the resource playback sequence table are updated according to the access order of at least one audio device, including: in response to a hot plug event of the audio device, determining the newly connected audio device or the newly unplugged audio device corresponding to the hot plug event; if it is a newly connected audio device, judging whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table, and if so, setting the priority information corresponding to the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and updating the corresponding available status to available; if not, writing the audio device identifier of the newly connected audio device into the resource playback sequence table, and setting the priority information of the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and writing the corresponding available status to available; if it is a newly unplugged audio device, setting the priority of the audio device identifier of the newly unplugged audio device in the resource playback sequence table to the lowest priority, and updating the corresponding available status to unavailable.
[0018] In an exemplary embodiment of the present disclosure, the pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback sequence table to a preset priority, and sets the corresponding available state to available; and performs static detection on the audio device that does not support hot plugging; updates the priority information and available state of the audio device identifier corresponding to the audio device in the resource playback sequence table according to the access order of at least one audio device, including: in response to a hot plug event of a second audio device other than the audio device that does not support hot plugging, determining a newly connected second audio device or a newly unplugged second audio device corresponding to the hot plug event; if it is a newly connected second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback sequence table to be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table, and sets the available state of the audio device identifier corresponding to the second audio device to available; if it is a newly unplugged second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback sequence table to not be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table, and sets the available state of the audio device identifier corresponding to the second audio device to unavailable.
[0019] According to a second aspect of an embodiment of the present disclosure, an audio service implementation device is provided, including: a determination module, when it is necessary to provide audio resources for a terminal device, a pulse audio service determines a target audio device according to the priority of at least one audio device in a resource playback sequence table, wherein the resource playback sequence table includes an audio device identifier, corresponding priority information, and an available status of the audio device, the audio device identifier includes device information and port information, and the available status indicates whether the priority information corresponding to the audio device identifier is valid; a control module, configured for the pulse audio service to provide audio resources based on the target audio device.
[0020] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the above methods based on instructions stored in the memory.
[0021] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a program is stored, and when the program is executed by a processor, the method for implementing an audio service as described above is implemented.
[0022] In the disclosed embodiments, when audio resources need to be provided, the pulse audio service determines the target audio device according to the priority information and available status of the audio device identifier in the resource playback sequence table. Since the resource playback sequence table includes the audio device identifier, the corresponding priority information and the available status, and the audio device identifier includes the device information and the port information, that is, PulseAudio can distinguish the access port by the audio device identifier. Furthermore, the pulse audio service provides audio resources based on the target audio device, and when the playback priority between multiple audio devices changes, the target audio device is switched in time to continue the interaction of audio resources, thereby realizing dynamic switching of audio between multiple audio devices and improving the response efficiency and reliability of the pulse audio service.
[0023] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are configured to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0025] Figure 1 A schematic diagram showing an exemplary system architecture for implementing an audio service solution according to an embodiment of the present invention;
[0026] Figure 2 is a flow chart of a method for implementing an audio service in an exemplary embodiment of the present disclosure;
[0027] Figure 3 is a flowchart of another method for implementing an audio service in an exemplary embodiment of the present disclosure;
[0028] Figure 4 is a schematic diagram of an application scenario of an audio service implementation method in an exemplary embodiment of the present disclosure;
[0029] Figure 5 is a schematic diagram of an application scenario of another method for implementing an audio service in an exemplary embodiment of the present disclosure;
[0030] Figure 6 is a schematic diagram of an application scenario of another method for implementing an audio service in an exemplary embodiment of the present disclosure;
[0031] Figure 7 is a schematic diagram of an application scenario of another method for implementing an audio service in an exemplary embodiment of the present disclosure;
[0032] Figure 8 is a flowchart of another audio service implementation scheme in an exemplary embodiment of the present disclosure;
[0033] Fig. 9 is a schematic diagram of an architecture of another audio service implementation solution in an exemplary embodiment of the present disclosure;
[0034] Fig.10 is a block diagram of an audio service implementation device in an exemplary embodiment of the present disclosure;
[0035] Fig.11 is a block diagram of an electronic device in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0036] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0037] In addition, the accompanying drawings are only schematic diagrams of the present disclosure, and the same reference numerals in the drawings represent the same or similar parts, so their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0038] Figure 1 The diagram shows an exemplary system architecture to which the audio service implementation solution of the embodiment of the present invention can be applied.
[0039] like Figure 1 As shown, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0040] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. According to the implementation requirements, there may be any number of terminal devices, networks and servers. For example, the server 105 may be a server cluster composed of multiple servers.
[0041] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, portable computers, desktop computers, etc.
[0042] In some embodiments, the audio service implementation method provided in the embodiments of the present invention is generally executed by the server 105. Accordingly, the audio service implementation device is generally set in the terminal device 103 (or the terminal device 101 or 102). In other embodiments, some terminals may have functions similar to those of the server device to execute the method.
[0043] The existing audio technology PulseAudio does not support the function of repeatedly plugging and unplugging multiple headphone devices and sequentially memorizing the output and input functions, so PulseAudio has many technical defects, as follows:
[0044] (1) The sink / source device of the sequential data table does not distinguish between ports;
[0045] (2) When the sequential data table records each audio device, the priority is reversed;
[0046] (3) When reading and writing sequential data tables, the sink / source priority is not updated in real time when headphones and HDMI / DP devices are connected;
[0047] (4) The sequence data table does not identify whether the sink / source is in an available state, causing the player audio to remain on an unavailable audio device;
[0048] (5) The laptop speakers and the earphone jacks are hardware-incompatible;
[0049] (6) When the system is restarted or logged off, the audio input and output devices are not memorized in order, and no cleanup check is performed on the existing devices;
[0050] (7) The sequential data table is not maintained and updated in a timely manner.
[0051] The embodiments of the present disclosure can solve the above technical defects. The exemplary implementation methods of the present disclosure are described in detail below with reference to the accompanying drawings.
[0052] Figure 2 FIG. 1 is a flowchart of a method for implementing an audio service provided by an exemplary embodiment of the present disclosure. Figure 2 , the audio service implementation method may include the following steps:
[0053] Step S202, when it is necessary to provide audio resources for the terminal device, the pulse audio service determines the target audio device according to the priority of at least one audio device in the resource playback order table, wherein the resource playback order table includes an audio device identifier, corresponding priority information, and an available status of the audio device, the audio device identifier includes device information and port information, and the available status indicates whether the priority information corresponding to the audio device identifier is valid.
[0054] In an embodiment of the present application, the pulse audio service is a background audio service of a terminal, and the device information is the identifier of the audio device accessing the terminal. For example, the audio device receiving audio resources from the terminal can be recorded as sink1, sink2, ..., sink n, and the audio device sending audio resources to the terminal can be recorded as source1, source2, ..., source n, where n is a positive integer.
[0055] Furthermore, the port information is determined based on the port to which the audio device is connected, and the port information is recorded as port. The audio device identifier includes device information and port information, which can usually be recorded as sink+port or source+port. Based on this, not only the devices are distinguished, but also the access ports are identified. Furthermore, by storing the audio device identifier and the priority information corresponding to each audio device identifier in the resource playback sequence table, and determining one of the multiple audio devices of the access terminal device as the target audio device based on the priority information, the efficiency and reliability of determining the priority of the audio device of the access terminal are improved.
[0056] Step S204: the pulse audio service provides audio resources based on the target audio device.
[0057] In an embodiment of the present application, when the pulse audio service needs to provide audio resources, the priority information corresponding to each audio device identifier is determined by querying the resource playback order table, and the target audio device is determined from at least one audio device based on the priority information. The target audio device interacts with the pulse audio service for audio resources based on the port contained in the audio device identifier.
[0058] Furthermore, the pulse audio service provides audio resources based on the target audio device. When the priority information of the audio device changes, the target audio device also changes accordingly. Based on this, dynamic switching between multiple audio devices accessing the terminal device can be achieved, thereby improving the response efficiency and reliability of the pulse audio service.
[0059] The following describes in detail the steps of the audio service implementation method.
[0060] In an exemplary embodiment disclosed in the present application, when executing Figure 2 Before the step S202 shown, relevant initialization steps may be performed, specifically including the following steps: when the pulse audio service is initialized, the pulse audio service loads the resource play sequence table, and updates the priority information of the audio device identifier corresponding to the audio device in the resource play sequence table according to the access sequence of at least one audio device; wherein the pulse audio service sets the priority of the audio device identifier corresponding to the audio device not connected in the resource play sequence table to the lowest priority. The access sequence of the audio device refers to the order in which at least one audio device is connected to the terminal device.
[0061] In the above embodiment, the resource play sequence table can be stored on the terminal side or the server side. In order to improve the efficiency of dynamic switching of audio devices, a resource play sequence table can be set to correspond to a terminal device. When providing audio resources for a terminal device, the table lookup rate and reliability can be improved by querying the resource play sequence table corresponding to the terminal device.
[0062] Specifically, when the pulse audio service is initialized, the audio device identification and priority information are preset in the resource playback sequence table loaded by the pulse audio service; after the terminal device completes the loading of the audio driver, the audio port of the terminal device is initialized to scan, determine at least one audio device connected to the terminal device, and determine the priority information of the audio device identification corresponding to all the audio devices connected to the terminal device in the resource playback sequence table; based on the priority information, the playback priority of all the audio devices connected to the terminal device is determined, and the target audio device is determined accordingly, wherein the target audio device refers to the audio device whose corresponding audio device identification has the highest playback priority and is connected to the terminal device. At the same time, the priority of the audio device identification corresponding to the audio device that is not connected to the terminal device included in the resource playback sequence table is set to the lowest priority to ensure that the audio resources provided by the pulse audio service will not switch to the unconnected audio device corresponding to the lowest priority.
[0063] In an exemplary embodiment disclosed in the present application, the priority information corresponding to each audio device can be set from low to high according to the access order of the audio devices connected to the terminal device, that is, the last connected audio device has the highest priority, the earlier the audio device is connected, the lower the priority is, and the unconnected audio device has the lowest priority. The pulse audio service determines the playback priority of all audio devices connected to the terminal device based on the priority information in the resource playback sequence table that is updated immediately, and always provides audio resources to the audio device with the highest playback priority.
[0064] Optionally, the priority information of the lowest priority audio device in the resource play order table may be recorded as “0” or a null value.
[0065] Furthermore, in an embodiment of the present application, the pulse audio service updates the priority information in the resource playback order table according to the access order of at least one audio device, and may also include: when there is an audio device that does not belong to the resource playback order table among the audio devices of the access terminal device, the pulse audio service adds the audio device identifier corresponding to the audio device to the resource playback order table, and sets the corresponding priority information for the audio device identifier corresponding to the audio device.
[0066] In an exemplary embodiment disclosed in the present application, when scanning the port to determine the audio device connected to the terminal device, if there is an unknown audio device, that is, when it is determined that the audio device identifier of the unknown audio device does not belong to the resource playback sequence table, the pulse audio service adds the audio device identifier of the audio device to the resource playback sequence table, and sets the corresponding priority information for the audio device identifier corresponding to the audio device, thereby realizing timely updating of the priority information in the resource playback sequence table. Based on the embodiment of the present application, not only the completeness of the resource playback sequence table is improved, but also the audio devices newly entered into the resource playback sequence table also support dynamic switching in the PulseAudio scenario, further improving the smoothness of audio resource playback and the response efficiency of dynamic switching of audio resources.
[0067] Furthermore, for a terminal device provided with a hot-plug port, a hot-plug event is generated when an audio device is connected to or unplugged from the hot-plug port. Based on this, an embodiment of the present application provides a technical solution, which can timely update the priority information of each audio device connected to the terminal device when a hot-plug event occurs in the terminal device, and after each hot-plug event occurs, the highest priority audio device can be timely determined as the target audio device based on the priority information in the updated resource playback sequence table, and audio resources can be interacted with the target audio device.
[0068] Based on this, for an audio device that supports hot plugging, in response to a hot plugging event of the audio device, the pulse audio service updates the priority information of the audio device in the resource play sequence table, which may specifically include the following steps A2-A6:
[0069] Step A2: In response to a hot plug event of the audio device, determining a newly connected audio device or a newly unplugged audio device corresponding to the hot plug event;
[0070] Step A4: If it is a newly connected audio device, the pulse audio service determines whether the audio device identifier of the newly connected audio device belongs to the resource playback order table. If so, the priority of the audio device identifier corresponding to the newly connected audio device in the resource playback order table is set to the highest priority; if not, the device identifier corresponding to the newly connected audio device is written into the resource playback order table, and the priority of the device identifier corresponding to the newly connected audio device in the resource playback order table is set to the highest priority.
[0071] In this embodiment, the pulse audio service can promptly set the priority of the audio device newly connected to the hot plug port of the terminal device to the highest priority, and while updating the resource playback sequence table, switch to the audio device corresponding to the highest priority to interact with audio resources.
[0072] Step A6: If it is a newly unplugged audio device, the pulse audio service sets the priority of the audio device identifier of the newly unplugged audio device in the resource play order table to the lowest priority.
[0073] In the above embodiment, the pulse audio service can timely set the priority of the audio device unplugged from the hot plug port of the terminal device to the lowest priority, and timely update the resource play order table. The audio device with the lowest priority does not interact with audio resources.
[0074] Furthermore, for audio devices that do not support hot plugging, the embodiments of the present application also provide a technical solution to update the priority information of audio devices in the resource playback order table, which may specifically include the pulse audio service setting the priority of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback order table to a preset priority, and performing static detection on the audio device that does not support hot plugging.
[0075] It should be noted that, in an embodiment of the present application, when the audio devices connected to the terminal device only include audio devices that do not support hot plugging, the audio devices that do not support hot plugging are used as target audio devices, and audio resources are interacted through the audio devices that do not support hot plugging; when the audio devices connected to the terminal device include other audio devices (for example, audio devices that support hot plugging) in addition to the audio devices that do not support hot plugging, then as in the aforementioned method, the target audio device is determined according to the priority information of the audio devices in the resource playback order table.
[0076] For an audio device that does not support hot plugging, updating priority information of an audio device identifier corresponding to the audio device in a resource playback sequence table according to an access sequence of at least one audio device includes the following steps B2-B6:
[0077] Step B2: In response to a hot plug event of a first audio device other than an audio device that does not support hot plug, determining a newly connected first audio device or a newly unplugged first audio device corresponding to the hot plug event.
[0078] Step B4: If it is a newly connected first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource play sequence table to be higher than the priority of the audio device that does not support hot plugging in the resource play sequence table.
[0079] Step B6: If the first audio device is newly unplugged, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource play sequence table to be no higher than the priority of the audio device that does not support hot plugging in the resource play sequence table.
[0080] Furthermore, in an embodiment of the present application, the resource playback order table may also include an available status of the audio device, and the available status is configured to indicate whether the priority information corresponding to the audio device identifier is valid. For example, for a certain audio device identifier, its corresponding priority is the highest priority, but its corresponding available status is unavailable, which indicates that the current priority information of the audio device corresponding to the audio device identifier is invalid. Therefore, even if the priority information of the audio device is the highest priority, the audio device is not selected as the target audio device.
[0081] Reference Figure 3 FIG. 1 is a flowchart of a method for implementing an audio service provided by the second exemplary embodiment of the present disclosure. Figure 3 , the audio service implementation method may include the following steps:
[0082] Step S302, when audio resources need to be provided, the pulse audio service determines the target audio device according to the priority information and available status of the audio device identifier in the resource playback sequence table; wherein the resource playback sequence table includes the audio device identifier, the corresponding priority information, and the available status of the audio device, and the audio device identifier includes the device information and port information.
[0083] In the second embodiment of the present application, the available state is configured to indicate whether the priority information corresponding to the audio device identifier is valid. Based on this, determining the target audio device according to the priority of the audio device in the resource playback sequence table may specifically include:
[0084] Step a1, determining whether the priority information corresponding to the audio device identifier is valid according to the available status corresponding to each audio device identifier in the resource playback sequence table; wherein the priority information corresponding to the audio device identifier whose available status is available is valid, and the priority information corresponding to the audio device identifier whose available status is unavailable is invalid;
[0085] Step a2: determining a target audio device from at least one audio device based on valid priority information.
[0086] Furthermore, in the embodiment of the present application, after each update of the available status of each audio device identifier in the resource playback sequence table, the target audio device can be updated in a timely manner, and the audio resource can be played based on the updated target audio device.
[0087] Step S304: the pulse audio service provides audio resources based on the target audio device.
[0088] In an exemplary embodiment disclosed in the present application, when executing Figure 3 Before the step S302 shown, relevant initialization steps can be performed, specifically including the following steps: when the pulse audio service is initialized, the pulse audio service loads the resource playback order table, and updates the priority information and available status of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device; the pulse audio service determines the target audio device according to the priority information and available status of the audio device identifier in the resource playback order table.
[0089] Specifically, initializing the pulse audio service may include the following steps C2-C8:
[0090] Step C2: When the pulse audio service is initialized, the pulse audio service loads the resource play sequence table;
[0091] Step C4: Scan the port status of the terminal device to determine the initial access status of the audio device corresponding to each audio device identifier included in the resource playback sequence table;
[0092] The initial access state may include connected and not connected; if the initial access state is connected, it indicates that the corresponding audio device is currently connected to the terminal device; if the initial access state is not connected, it indicates that the corresponding audio device is not currently connected to the terminal device.
[0093] Step C6: Write the available status of the audio device identifier corresponding to the audio device with the initial access status of connected in the resource playback sequence table as available.
[0094] For the audio devices that have been connected to the terminal device, the available status corresponding to the audio devices is written as available, so that the priority information of the connected audio devices in the resource playback sequence table is valid.
[0095] Step C8: writing the available status of the audio device identifier corresponding to the audio device whose initial access status is not connected in the resource play sequence table as unavailable.
[0096] After completing the initialization of the pulse audio service, the pulse audio service may update the available status of the audio device identifier corresponding to the audio device in the resource play sequence table according to the access sequence of the at least one audio device.
[0097] For a terminal device provided with a hot-plug port, a hot-plug event is generated when an audio device is connected to or unplugged from the hot-plug port. Based on this, Embodiment 2 of the present application provides a technical solution, which can timely update the priority information and available status of each audio device connected to the terminal device when a hot-plug event occurs in the terminal device, and after each hot-plug event occurs, can timely determine the effective highest-priority audio device as the target audio device based on the priority information and available status in the updated resource playback sequence table, and interact with the target audio device for audio resources.
[0098] Based on this, for an audio device that supports hot plugging, in response to a hot plugging event of the audio device, the pulse audio service updates the priority information and available status of the audio device in the resource play sequence table, which may specifically include the following steps D2-D6:
[0099] Step D2: In response to a hot plug event of the audio device, determining a newly connected audio device or a newly unplugged audio device corresponding to the hot plug event;
[0100] Step D4: if it is a newly connected audio device, determine whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table. If so, set the priority information corresponding to the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and update the corresponding available status to available; if not, write the audio device identifier of the newly connected audio device into the resource playback sequence table, and set the priority information of the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and write the corresponding available status to available;
[0101] In this embodiment, the pulse audio service can promptly set the priority of the audio device of the hot plug port newly connected to the terminal device to the highest priority, set the available status to available, and while updating the resource playback order table, switch to the audio device corresponding to the highest priority to interact with audio resources.
[0102] Step D6: If it is a newly unplugged audio device, the priority of the audio device identifier of the newly unplugged audio device in the resource play sequence table is set to the lowest priority, and the corresponding available status is updated to unavailable.
[0103] In the above embodiment, the pulse audio service can promptly set the priority of the audio device unplugged from the hot plug port of the terminal device to the lowest priority, set the available status to unavailable, and promptly update the resource playback order table. The audio device with the lowest priority does not interact with audio resources.
[0104] Furthermore, for audio devices that do not support hot plugging, Example 2 of the present application also provides a technical solution to update the priority information of audio devices in the resource playback order table, which may specifically include: the pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback order table to a preset priority, and sets the corresponding available status to available; and performs static detection on the audio devices that do not support hot plugging.
[0105] It should be noted that, in an embodiment of the present application, when the audio devices connected to the terminal device only include audio devices that do not support hot plugging, and the available status of the audio devices is available, the audio devices that do not support hot plugging are used as target audio devices, and audio resources are interacted through the audio devices that do not support hot plugging; when the audio devices connected to the terminal device include other audio devices (for example, audio devices that support hot plugging) in addition to the audio devices that do not support hot plugging, then as in the aforementioned method, the target audio device is determined according to the priority information and available status of the audio devices in the resource playback order table.
[0106] For an audio device that does not support hot plugging, updating the priority information and available status of the audio device identifier corresponding to the audio device in the resource playback sequence table according to the access sequence of at least one audio device includes the following steps E2-E6:
[0107] Step E2: in response to a hot plug event of a second audio device other than the audio device that does not support hot plug, determining a newly connected second audio device or a newly unplugged second audio device corresponding to the hot plug event;
[0108] Step E4: If it is a newly connected second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback sequence table to be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table, and sets the available state of the audio device identifier corresponding to the second audio device to available;
[0109] Step E6: If it is a newly unplugged second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback order table to be no higher than the priority of the audio device that does not support hot plugging in the resource playback order table, and sets the available state of the audio device identifier corresponding to the second audio device to unavailable.
[0110] In the above embodiment, in the process of dynamically switching the audio devices in the available state, the priority information in the resource playback order may not be modified. When a hot plug event occurs, the corresponding priority information is valid based on the audio device being connected to the terminal device and being written as available. The corresponding priority information is invalid based on the audio device being unplugged from the terminal device and being written as unavailable.
[0111] The priority information is determined based on the access status of the audio device. In addition, in actual applications, in order to meet the user's use requirements for the audio device, the priority information of the audio device identifier in the resource playback sequence table can be adjusted based on the user's selection instruction. The priority setting event includes the user's preference setting for the audio device, which can specifically include the following steps F2-F4:
[0112] Step F2: In response to the audio device priority setting event triggered by the user, determine the user's priority setting instruction for the audio device identifier in the resource play sequence table based on the priority setting event.
[0113] Step F4: selecting one of the at least one audio device as a target audio device based on the priority setting instruction, and adjusting the priority information corresponding to the audio device identifier of the audio device in the resource playback sequence table to the highest priority.
[0114] Based on this, an audio device selected by the user can be determined as the target audio device in a timely manner, and the audio resource interaction is switched to the audio device selected by the user, thereby improving the user's experience of using the audio device.
[0115] In the above exemplary embodiment, while dynamically switching the audio devices based on the resource playback order table, the audio service implementation method also includes: the pulse audio service reports the resource playback order table to the multimedia application based on priority setting events and / or hot plug events, so that the multimedia application can display the priority information of the audio device to the user.
[0116] In the above exemplary embodiment, the pulse audio service reports the resource playback order table to the multimedia application based on events, so that the multimedia application can display the playback priority of at least one audio device to the user, thereby improving the intuitiveness of the priority information in the pulse audio service process and the convenience and efficiency of the user in setting the priority.
[0117] In the above exemplary embodiment, the resource play sequence table includes priority information of at least one audio device in an application scenario of the multimedia application.
[0118] In the above exemplary embodiment, the audio type information includes audio, video, music, games, etc., but is not limited thereto. Based on this, by setting the priority information of each audio device under each audio type, PulseAudio realizes the dynamic switching of independent audio devices in various application scenarios.
[0119] In the above exemplary embodiment, the pulse audio service updates the priority information in the resource play order table according to the access order of the audio devices, including the following specific steps G2-G6:
[0120] Step G2: After the pulse audio service is started, the audio device is loaded based on the audio driver.
[0121] Step G4: Obtain device information and port information of the audio device based on the loading result of the audio device.
[0122] Step G6: Determine the audio device identifier corresponding to the audio device in the resource play sequence table according to the device information and port information of the audio device.
[0123] In the above embodiment, after the pulse audio service is started, the audio device is loaded based on the audio driver, the device identification information is determined based on the device information and port information, and the priority corresponding to the device identification information in the resource playback sequence table is updated according to the access sequence.
[0124] In the above exemplary embodiment, loading the audio device based on the audio driver includes the following specific steps H2-H8:
[0125] Step H2: Load the audio driver supported by the manufacturer's onboard audio chip.
[0126] Step H4: Start the alsa module to check whether there is a user-defined configuration in the loaded audio driver.
[0127] Step H6: Start the udev process to check whether the loaded audio driver supports the udev audio rules, and check whether there is a user-defined configuration for the audio driver that supports the udev audio rules.
[0128] Step H8: Load the user-defined configuration if it exists.
[0129] In the above exemplary embodiment, alsa (abbreviation of Advanced Linux Sound Architecture) provides audio and MIDI (Musical Instrument Digital Interface) support on the Linux operating system, and starts the alsa module to check whether there is a user-defined configuration for the loaded audio driver. If so, the user-defined configuration is loaded, and then HiFi (High-Fidelity) quality audio resources are provided through the connected audio device.
[0130] The embodiments of the present disclosure provide an application scenario of an audio service implementation solution. Figures 4 to 7 The application scenario shown is used to illustrate how to prioritize the resource playback sequence table and determine the target audio device based on the priority information.
[0131] like Figure 4 As shown, application scenario 1:
[0132] On a Linux system with PulseAudio installed, after powering on and entering the Linux system desktop, the user opens the UI (User Interface) sound setting interface. After that, plug in and unplug the round-hole earphone, the UI sound setting interface can automatically display the round-hole audio device. After the user opens the audio player, the round-hole earphone also has sound output, including the following steps:
[0133] Step S402: The terminal device is powered on.
[0134] Step S404, entering the Linux system desktop.
[0135] Step S406: Open the UI (User Interface) of the pulse audio service.
[0136] Step S408, the user inserts a jack earphone into the port of the terminal device, and adjusts the priority information corresponding to the audio device identifier of the jack earphone in the resource playback sequence table to the highest priority. The pulse audio service immediately determines that the jack earphone is the target audio device and has the highest priority for playing audio resources.
[0137] Step S410: The UI interface dynamically displays the round-hole earphone.
[0138] Step S412, open the audio player, and the round-hole earphones play sound (audio resources).
[0139] Application scenario 2:
[0140] After opening the UI sound settings interface in application scenario 1, Figure 5 As shown, the sound setting interface has a round hole earphone (audio device) by default, which is a static display. When the user plugs in or unplugs the round hole earphone, there is no change. However, after opening the audio player, the round hole earphone still has sound output, including the following steps:
[0141] Step S502: The terminal device is powered on.
[0142] Step S504, entering the Linux system desktop.
[0143] Step S506, opening the UI interface of the pulse audio service.
[0144] Step S508: The UI interface statically displays the round-hole earphone.
[0145] Step S510: No UI changes.
[0146] Application scenario three:
[0147] like Figure 6 As shown, after entering the system desktop, without opening the UI sound setting interface, the user opens the audio player, and then plugs in and out various hardware interface devices such as round-hole headphones, USB headphones, and HDMI (High Definition Multimedia Interface) in the order preset by the user, and the player can play the sound in sequence in the preset order, including the following steps:
[0148] Step S602: The terminal device is powered on.
[0149] Step S604, entering the Linux system desktop.
[0150] Step S606: Do not open the UI interface of the pulse audio service.
[0151] Step S608, open the audio player.
[0152] In step S610, the user plugs in and unplugs the jack earphones, the USB earphones and the HDMI device in turn, and adjusts the priority information of the audio device identifiers of the jack earphones, the USB earphones and the HDMI device in the resource playback sequence table to the highest priority. The playback priority of the HDMI device is higher than that of the USB earphones, and the playback priority of the USB earphones is higher than that of the jack earphones.
[0153] Step S612, according to the plug-in and unplugging order of the round-hole earphone, the USB earphone, and the HDMI device, the round-hole earphone, the USB earphone, and the HDMI device have sound output in turn.
[0154] Application scenario 4:
[0155] Based on the application scenario three, Figure 7 As shown in the figure, the pulse audio service records the order of each round hole headset, USB headset, HDMI and other audio devices. After restarting or logging out, when you enter the Linux system desktop again, open the audio player, and then play the sound, you can find the corresponding audio device in the memory order, and the sound is also played in this order, including the following steps:
[0156] Step S702: the round hole device, USB headset, and HDMI device are inserted into or unplugged from the terminal device.
[0157] Step S704, Reboot or log out.
[0158] Step S706, entering the Linux system desktop.
[0159] Step S708, open the audio player.
[0160] Step S710, determine the priority information corresponding to the audio device identifier according to the resource playback sequence table memorized before the last restart / logout, instantly determine the target audio device based on the priority information, and play the audio resource through the target audio device.
[0161] Figure 8 FIG. 4 is a flowchart of another audio service implementation scheme in an exemplary embodiment of the present disclosure.
[0162] like Figure 8 As shown, the overall process of another audio service implementation solution in the exemplary embodiment of the present disclosure includes:
[0163] Step S802: Power on the Linux system.
[0164] Step S804, the kernel loads the audio driver modules of the jack device, USB headset, HDMI and other devices.
[0165] Step S806, Alsa module loading and initialization.
[0166] Step S808, the PlusAudio service is started.
[0167] Step S810, entering the Linux system desktop.
[0168] Step S812: The user opens the sound setting interface.
[0169] Step S814: the user turns on the audio device.
[0170] Step S816, the manufacturer's onboard audio firmware supports the audio protocol specification, and the Card driver includes corresponding drivers for round hole devices, HDMI devices, DP monitors and USB headphones, but is not limited to these.
[0171] Step S818, start the Alsa-lib module.
[0172] Step S820, checking udev rules, that is, checking whether udev rules are supported. If udev rules are supported, executing step S822.
[0173] Among them, the rule file is the most important part of udev, and is stored in / etc / udev / rules.d / by default. All rule files must have the suffix ".rules". The rules in the rule file consist of a series of key / value pairs, separated by commas (,). Each key is either a user match key or an assignment key. The match key determines whether the rule is applied, and the assignment key indicates the assignment of a value to the key. These values will affect the device files created by udev, and the assignment key can handle a multi-value list.
[0174] Step S822, checking the user-defined configuration.
[0175] Step S824, determine whether the port stores the user-defined configuration, if so, execute step S826, if not, execute step S828.
[0176] Step S826, using default port information.
[0177] Step S828, parse the configuration and load and return.
[0178] like Figure 8As shown in the figure, when the machine with Linux system is powered on, the system kernel will load the drivers supported by the manufacturer's onboard audio chip, including USB / HDMI and audio drivers provided by third-party manufacturers, etc., and then the system starts the Alsa module for initialization, and then the system starts the PulseAudio service. After entering the Linux system desktop, finally, whether the user opens the sound settings or the audio player, they interact with the PulseAudio daemon, and an audio device is selected by default as the main audio device for playback.
[0179] Among them, the PulseAudio daemon is first started by the PulseAudio service boot, and then runs in the background; when it starts, it first performs initialization processing, such as Figure 8 Each audio driver device card n (n=0...N) in the card driver box shown in the figure passes through the Alsa-lib module and udev rules in sequence to check whether it has a user-defined configuration. If there is a configuration, it is parsed and loaded to take effect, thereby realizing automatic detection of inserted headphones. Otherwise, if it cannot be found, it is skipped and PulseAudio loads its own default configuration.
[0180] The improved Pulseaduio daemon can remember the order in which users plug and unplug multiple jack headphones, USB headphones, HDMI, and DP interface monitors with audio functions at any time, and then return to the sound settings interface and audio player, so that audio playback devices can be switched at will. In addition to plugging and unplugging by the current user, it can also realize restart or logout audio memory switching.
[0181] Figure 8 The PulseAudio daemon shown is the most important part of the entire Linux audio system and the center of all audio data information interaction processing. For the sound setting interface and audio player application, it only needs to obtain the event data Event reported by the audio device from PulseAudio, and then parse which audio device to switch to.
[0182] Figure 8 The Alsa module (short for Advanced Linux Sound Architecture) shown is also an integral part of the audio system, providing support for audio and MIDI (Musical Instrument Digital Interface). Its main function is to cooperate with PulseAudio to parse user-defined configuration specifications in order to achieve automatic detection and recognition.
[0183] Among them, the user-defined configuration specification is written for the manufacturer's onboard audio chip, which requires the manufacturer's onboard audio firmware to support the audio protocol standard, otherwise it is impossible to achieve HiFi high-fidelity sound quality. If the manufacturer's onboard audio firmware does not support the audio protocol specification, PulseAudio uses the default configuration to define a profile attribute of an analog headphone or analog microphone for the manufacturer's onboard audio chip to facilitate users to control the headphone audio or microphone device.
[0184] In addition, the changes to the sound settings interface are mainly focused on the display and interaction of user settings. For example, when a user plays audio, if he wants to change the playback order of all current audio devices, he can choose to click on any audio device to play it first through the sound settings interface, and let PulseAudio operate the audio memory repository to read and find the corresponding sink+port or source+port, and then update the priority value to the maximum +1, that is, give the user-selected audio device the highest priority.
[0185] Fig. 9 It is a schematic diagram of the architecture of the audio service implementation scheme in the exemplary embodiment of the present disclosure.
[0186] like Fig. 9 As shown, the audio service implementation scheme in the exemplary embodiment of the present disclosure includes the following core processing stages:
[0187] (1) Add port and enter sink+port or source+port as the identifier of the audio device.
[0188] Among them, each sink (source) corresponds to each headset (microphone device), and some sink or source devices have multiple port attributes in actual applications. Each port represents an audio output or audio input interface. For example, a pair of round-hole headphones represents a sink, but it is necessary to distinguish between the front output and the rear output, or the speakers and analog headphones on a laptop. Some Nvidia graphics cards even have multiple DP interfaces on the back, and one DP interface represents a sink. Therefore, different headphones, microphones, graphics card HDMI, and DP interfaces will have different hardware functions and cannot be represented by only sink or source, otherwise it will cause data conflicts in audio devices.
[0189] In the exemplary embodiments of the present disclosure, by introducing the concept of port, each audio output device is specifically represented by a sink+port method. Similarly, each audio input device is specifically represented by a source+port method.
[0190] (2) Determine a pre-stored sequential data table, which includes the above-mentioned identifiers and corresponding priorities.
[0191] The priority refers to the order in which headphones are connected to the audio device, not the attribute priority on the sink / source.
[0192] (3) Connect the round hole device, USB headset and HDMI output device, and update the sequence data table.
[0193] (4) Determine whether the port is available.
[0194] In the prior art, if a device such as a round hole earphone is not connected, its status is unavailable, but the audio player mistakenly defaults to the round hole earphone sink being available during playback, resulting in audio freeze when playing on this sink.
[0195] In an exemplary embodiment of the present disclosure, by increasing the available status recognition of the port, the code robustness and reliability are enhanced, and other abnormal bugs caused by audio device switching are reduced.
[0196] (5) The port hook method is introduced to solve the mutual exclusion between speakers and round-hole headphones.
[0197] In the prior art, the jack earphone and speaker on the notebook belong to the same sink but different ports. The two ports are exclusive in hardware (choose one or the other). When the jack earphone is unplugged, the speaker will be automatically recognized and the sequence data table will be updated in real time, resulting in a disordered order of playing sounds.
[0198] In an exemplary embodiment of the present disclosure, an additional handle hook is added to independently handle this situation, and when the round-hole earphone is unplugged, the sequence data table is not updated to avoid the exception.
[0199] (6) Clear non-existent devices when restarting and logging out.
[0200] In the prior art, when the system is restarted and logged out, the user may unplug an audio device midway, and the sink / source is no longer available. However, the open source code does not check and clean up the boot login, which may cause the playing audio to stay on the unavailable sink / source.
[0201] In an exemplary embodiment of the present disclosure, by adding a startup timer to clean up audio devices in a non-available state, the priority of the audio devices in a non-available state is directly modified to 0, thereby further reducing other abnormal bugs caused by audio device switching.
[0202] (7) Restart and cancel the maintenance sequence data table.
[0203] As time goes by, there may be more and more different sink / source audio devices connected to the audio system.
[0204] In an exemplary embodiment of the present disclosure, by timely adjusting and updating the priority order of the sequential data table, it is ensured that the audio is played in the memory order every time the system is restarted and logged off.
[0205] In addition, Pulsecore is the core and key component of the PulseAudio program. Almost all sink / source data operations are related to it. The main reason is that the audio player playback stays on the unavailable state sink by default. In the exemplary embodiment of the present disclosure, the available state recognition of the port port is added and the default best sink or best source value is updated. The audio device corresponding to the best best sink or best source value has the highest priority.
[0206] in, Fig. 9 The sink shown here represents the audio output of a simulated device (i.e., headphones), and the source represents the audio input of a simulated device (i.e., microphone). In actual application scenarios, some devices do not have a source, such as a display with an HDMI / DP interface, so there is at least one sink audio device. An Sndcard represents an audio logic device card, which contains all the driver data structure information of this audio device.
[0207] in addition, Fig. 9 The audio memory storage shown is actually a copy of the sequential data table. It can be understood that the sequential data table is running in the memory, while the audio memory storage has a physical media medium. This is to ensure that the latest audio memory sequence table can be obtained every time the computer is turned on, restarted or logged off, so as to ensure that various audio devices such as headphones play the output sound in sequence every time the computer is turned on, restarted or logged off.
[0208] in addition, Fig. 9 The daemon shown is a continuously running program that is configured to handle periodic requests for services that the computer system wishes to receive. The daemon program submits the request to other appropriate programs (or processes). Every web server on the Internet has an HTTPD or Hypertext Transfer Protocol daemon that continuously waits for requests from network clients and their users.
[0209] Corresponding to the embodiments shown in the above methods and architectures, the present disclosure also provides an audio service implementation device, which can be configured to execute the above method embodiments.
[0210] Fig.10It is a block diagram of an audio service implementation device in an exemplary embodiment of the present disclosure.
[0211] refer to Fig.10 , the audio service implementation device 1000 may include:
[0212] Determination module 1002, when it is necessary to provide audio resources for a terminal device, the pulse audio service determines the target audio device according to the priority of at least one audio device in a resource playback sequence table, wherein the resource playback sequence table includes an audio device identifier, corresponding priority information, and an available status of the audio device, the audio device identifier includes device information and port information, and the available status indicates whether the priority information corresponding to the audio device identifier is valid.
[0213] The control module 1004 is configured to provide audio resources based on the target audio device.
[0214] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured as follows: when the pulse audio service is initialized, the pulse audio service loads a resource playback order table, and updates the priority information of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device; the access order of the audio devices is the order in which at least one audio device accesses the terminal device; the pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that is not connected to the terminal device in the resource playback order table to the lowest priority.
[0215] In an exemplary embodiment of the present disclosure, the determination module 1002 is also configured to: when there is an audio device in the audio device of the access terminal device that does not belong to the resource playback order table, the pulse audio service adds the audio device identifier corresponding to the audio device to the resource playback order table, and sets corresponding priority information for the audio device identifier corresponding to the audio device.
[0216] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: in response to a hot plug event of an audio device, determine a newly connected audio device or a newly unplugged audio device corresponding to the hot plug event; if it is a newly connected audio device, the pulse audio service determines whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table, and if so, sets the priority of the audio device identifier corresponding to the newly connected audio device in the resource playback sequence table to the highest priority; if not, write the device identifier corresponding to the newly connected audio device into the resource playback sequence table, and set the priority of the device identifier corresponding to the newly connected audio device in the resource playback sequence table to the highest priority; if it is a newly unplugged audio device, the pulse audio service sets the priority of the audio device identifier of the newly unplugged audio device in the resource playback sequence table to the lowest priority.
[0217] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: the pulse audio service sets the priority of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback order table to a preset priority, and performs static detection on the audio device that does not support hot plugging; updates the priority information of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device, including: in response to a hot plug event of a first audio device other than the audio device that does not support hot plugging, determining a newly connected first audio device or a newly unplugged first audio device corresponding to the hot plug event; if it is a newly connected first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource playback order table to be higher than the priority of the audio device that does not support hot plugging in the resource playback order table; if it is a newly unplugged first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource playback order table to be no higher than the priority of the audio device that does not support hot plugging in the resource playback order table.
[0218] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: update the priority information of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device, including: updating the priority information and available status of the audio device identifier corresponding to the audio device in the resource playback order table according to the access order of at least one audio device; the available status is available or unavailable.
[0219] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: determine the target audio device according to the priority of at least one audio device in the resource playback order table, including: determining whether the priority information corresponding to the audio device identifier is valid according to the available status corresponding to each audio device identifier in the resource playback order table; wherein the priority information corresponding to the audio device identifier with an available status of available is valid, and the priority information corresponding to the audio device identifier with an available status of unavailable is invalid; and determining the target audio device from at least one audio device based on the valid priority information.
[0220] In an exemplary embodiment of the present disclosure, the determination module 1002 is also configured to: initialize the pulse audio service, including: initializing the pulse audio service, loading the resource playback sequence table; scanning the port status of the terminal device, and determining the initial access status of the audio device corresponding to each audio device identifier included in the resource playback sequence table; the initial access status is connected or not connected; writing the available status of the audio device identifier corresponding to the audio device whose initial access status is connected in the resource playback sequence table as available; writing the available status of the audio device identifier corresponding to the audio device whose initial access status is not connected in the resource playback sequence table as unavailable.
[0221] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: update the priority information and available status of the audio device identifier corresponding to the audio device in the resource playback sequence table according to the access order of at least one audio device, including: in response to a hot plug event of the audio device, determine the newly connected audio device or the newly unplugged audio device corresponding to the hot plug event; if it is a newly connected audio device, determine whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table, if so, set the priority information corresponding to the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and update the corresponding available status to available; if not, write the audio device identifier of the newly connected audio device into the resource playback sequence table, and set the priority information of the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and write the corresponding available status to available; if it is a newly unplugged audio device, set the priority of the audio device identifier of the newly unplugged audio device in the resource playback sequence table to the lowest priority, and update the corresponding available status to unavailable.
[0222] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: the pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback sequence table to a preset priority, and sets the corresponding available state to available; and statically detects the audio device that does not support hot plugging; updates the priority information and available state of the audio device identifier corresponding to the audio device in the resource playback sequence table according to the access order of at least one audio device, including: in response to a hot plug event of a second audio device other than the audio device that does not support hot plugging, determining a newly connected second audio device or a newly unplugged second audio device corresponding to the hot plug event; if it is a newly connected second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback sequence table to be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table, and sets the available state of the audio device identifier corresponding to the second audio device to available; if it is a newly unplugged second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback sequence table to not be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table, and sets the available state of the audio device identifier corresponding to the second audio device to unavailable.
[0223] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: the pulse audio service reports a resource playback order table to the multimedia application based on the priority setting event and / or the hot plug event of the audio device, so that the multimedia application displays the priority information of the audio device to the user.
[0224] In an exemplary embodiment of the present disclosure, the resource playback sequence table includes priority information of at least one audio device in an application scenario of the multimedia application.
[0225] In an exemplary embodiment of the present disclosure, the determination module 1002 is further configured to: after the pulse audio service is started, load the audio device based on the audio driver; obtain the device information and port information of the audio device based on the loading result of the audio device; and determine the audio device identifier corresponding to the audio device in the resource playback order table according to the device information and port information of the audio device.
[0226] In an exemplary embodiment of the present disclosure, the determination module 1002 is also configured to: load the audio driver supported by the manufacturer's onboard audio chip; start the alsa module to check whether there is a user-defined configuration for the loaded audio driver; and / or, start the udev process to check whether the loaded audio driver supports udev audio rules, and check whether there is a user-defined configuration for the audio driver that supports udev audio rules; if so, load the user-defined configuration.
[0227] Since the functions of the audio service implementation device 1000 have been described in detail in the corresponding method embodiments, the present disclosure will not elaborate on them here.
[0228] It should be noted that, although several modules or units of the device configured to perform actions are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0229] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0230] Refer to the following Fig.11 The electronic device 1100 according to this embodiment of the present invention is described. Fig.11 The electronic device 1100 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0231] like Fig.11 As shown, the electronic device 1100 is in the form of a general computing device. The components of the electronic device 1100 may include but are not limited to: at least one processing unit 1110, at least one storage unit 1120, and a bus 1130 connecting different system components (including the storage unit 1120 and the processing unit 1110).
[0232] The storage unit stores program codes, which can be executed by the processing unit 1110, so that the processing unit 1110 performs the steps of various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 1110 can perform the method shown in the embodiment of the present disclosure.
[0233] The storage unit 1120 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 11201 and / or a cache storage unit 11202 , and may further include a read-only storage unit (ROM) 11203 .
[0234] The storage unit 1120 may also include a program / utility 11204 having a set (at least one) of program modules 11205, such program modules 11205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0235] Bus 1130 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0236] The electronic device 1100 may also communicate with one or more external devices 1140 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1100, and / or communicate with any device that enables the electronic device 1100 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1150. Furthermore, the electronic device 1100 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 11110. As shown, the network adapter 11110 communicates with other modules of the electronic device 1100 via a bus 1130. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1100, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0237] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0238] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention may also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is configured to cause the terminal device to perform the steps according to various exemplary implementations of the present invention described in the above "Exemplary Method" section of the present specification.
[0239] The program product configured to implement the above method according to an embodiment of the present invention can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited to this. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0240] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0241] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program configured to be used by or in conjunction with an instruction execution system, apparatus, or device.
[0242] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0243] Program code configured to perform the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0244] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0245] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and concept of the present disclosure are indicated by the claims.
Claims
1. A method for implementing an audio service, characterized in that: The method comprises: When it is necessary to provide audio resources for a terminal device, the pulse audio service determines a target audio device according to the priority of at least one audio device in a resource playback sequence table, wherein the resource playback sequence table includes an audio device identifier, corresponding priority information, and an available status of the audio device, the audio device identifier includes device information and port information, and the available status indicates whether the priority information corresponding to the audio device identifier is valid; The pulse audio service provides the audio resource based on the target audio device.
2. The method for implementing an audio service according to claim 1, wherein: The method further comprises: When the pulse audio service is initialized, the pulse audio service loads the resource play sequence table, and updates priority information of the audio device identifier corresponding to the audio device in the resource play sequence table according to the access order of the at least one audio device; The access order of the audio devices is the order in which the at least one audio device is accessed to the terminal device; The pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that is not connected to the terminal device in the resource playback sequence table to the lowest priority.
3. The method for implementing an audio service as claimed in claim 2, wherein: The updating, according to the access order of the at least one audio device, the priority information of the audio device identifier corresponding to the audio device in the resource playback sequence table comprises: When there is an audio device that does not belong to the resource playback order table among the audio devices connected to the terminal device, the pulse audio service adds the audio device identifier corresponding to the audio device to the resource playback order table, and sets corresponding priority information for the audio device identifier corresponding to the audio device.
4. The method for implementing an audio service as claimed in claim 2, wherein: The updating, according to the access order of the at least one audio device, the priority information of the audio device identifier corresponding to the audio device in the resource playback sequence table comprises: In response to a hot plug event of an audio device, determining a newly connected audio device or a newly unplugged audio device corresponding to the hot plug event; If it is a newly connected audio device, the pulse audio service determines whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table, and if so, sets the priority of the audio device identifier corresponding to the newly connected audio device in the resource playback sequence table to the highest priority; if not, writes the device identifier corresponding to the newly connected audio device into the resource playback sequence table, and sets the priority of the device identifier corresponding to the newly connected audio device in the resource playback sequence table to the highest priority; If it is a newly unplugged audio device, the pulse audio service sets the priority of the audio device identifier of the newly unplugged audio device in the resource play order table to the lowest priority.
5. The method for implementing an audio service as claimed in claim 2, wherein: The pulse audio service sets the priority of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback sequence table to a preset priority, and performs static detection on the audio device that does not support hot plugging; The updating, according to the access order of the at least one audio device, the priority information of the audio device identifier corresponding to the audio device in the resource playback sequence table comprises: In response to a hot plug event of a first audio device other than the audio device that does not support hot plug, determining a newly connected first audio device or a newly unplugged first audio device corresponding to the hot plug event; If it is a newly connected first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource playback sequence table to be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table; If it is a newly unplugged first audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the first audio device in the resource play sequence table to be no higher than the priority of the audio device that does not support hot plugging in the resource play sequence table.
6. The method for implementing an audio service as claimed in claim 2, wherein: The updating, according to the access order of the at least one audio device, the priority information of the audio device identifier corresponding to the audio device in the resource playback sequence table comprises: The priority information and the available status of the audio device identifier corresponding to the audio device in the resource playback sequence table are updated according to the access order of the at least one audio device; the available status is available or unavailable.
7. The method for implementing an audio service as claimed in claim 6, wherein: The step of determining the target audio device according to the priority of at least one audio device in the resource playback sequence table comprises: Determine whether the priority information corresponding to the audio device identifier is valid according to the available status corresponding to each audio device identifier in the resource playback order table; wherein the available status is that the priority information corresponding to the audio device identifier is valid, and the available status is that the priority information corresponding to the audio device identifier is invalid; A target audio device is determined from among the at least one audio device based on the valid priority information.
8. The method for implementing an audio service as claimed in claim 6, wherein: The initializing the pulse audio service comprises: The pulse audio service is initialized and the resource play sequence table is loaded; Scan the port status of the terminal device to determine the initial access status of the audio device corresponding to each audio device identifier included in the resource playback sequence table; the initial access status is connected or not connected; Writing the available state of the audio device identifier corresponding to the audio device whose initial access state is connected in the resource playback sequence table as available; The available state of the audio device identifier corresponding to the audio device whose initial access state is not connected in the resource playback sequence table is written as unavailable.
9. The method for implementing an audio service as claimed in claim 6, wherein: The updating, according to the access order of the at least one audio device, the priority information and the available status of the audio device identifier corresponding to the audio device in the resource playback sequence table includes: In response to a hot plug event of an audio device, determining a newly connected audio device or a newly unplugged audio device corresponding to the hot plug event; If it is a newly connected audio device, determine whether the audio device identifier of the newly connected audio device belongs to the resource playback sequence table, and if so, set the priority information corresponding to the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and update the corresponding available state to available; if not, write the audio device identifier of the newly connected audio device into the resource playback sequence table, and set the priority information of the audio device identifier of the newly connected audio device in the resource playback sequence table to the highest priority, and write the corresponding available state to available; If it is a newly unplugged audio device, the priority of the audio device identifier of the newly unplugged audio device in the resource play sequence table is set to the lowest priority, and the corresponding available state is updated to unavailable.
10. The method for implementing an audio service according to claim 6, wherein: The pulse audio service sets the priority information of the audio device identifier corresponding to the audio device that does not support hot plugging in the resource playback sequence table to the preset priority, and sets the corresponding available state to available; and performs static detection on the audio device that does not support hot plugging; The updating, according to the access order of the at least one audio device, the priority information and the available status of the audio device identifier corresponding to the audio device in the resource playback sequence table includes: In response to a hot plug event of a second audio device other than the audio device that does not support hot plug, determining a newly connected second audio device or a newly unplugged second audio device corresponding to the hot plug event; If it is a newly connected second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback sequence table to be higher than the priority of the audio device that does not support hot plugging in the resource playback sequence table, and sets the available state of the audio device identifier corresponding to the second audio device to available; If it is a newly unplugged second audio device, the pulse audio service sets the priority of the audio device identifier corresponding to the second audio device in the resource playback order table to be no higher than the priority of the audio device that does not support hot plugging in the resource playback order table, and sets the available state of the audio device identifier corresponding to the second audio device to unavailable.
11. An audio service implementation device, characterized in that: include: a determination module configured to, when it is necessary to provide audio resources for a terminal device, determine the target audio device according to the priority of at least one audio device in a resource playback sequence table by the pulse audio service, wherein the resource playback sequence table includes an audio device identifier, corresponding priority information, and an available status of the audio device; the audio device identifier includes device information and port information, and the available status indicates whether the priority information corresponding to the audio device identifier is valid; The control module is configured to provide the audio resource based on the target audio device.
12. An electronic device, characterized in that: include: Memory; as well as A processor coupled to the memory, wherein the processor is configured to execute the audio service implementation method according to any one of claims 1 to 10 based on instructions stored in the memory.
13. A computer-readable storage medium, characterized in that: A program is stored thereon, and when the program is executed by a processor, the audio service implementation method as described in any one of claims 1-10 is implemented.
Citation Information
Cited By
Audio input switching method and system, storage medium and equipment
CN121166067A