CN112114773A - Multi-sound-card management method and system based on Android system - Google Patents
Multi-sound-card management method and system based on Android system Download PDFInfo
- Publication number
- CN112114773A CN112114773A CN202010986751.0A CN202010986751A CN112114773A CN 112114773 A CN112114773 A CN 112114773A CN 202010986751 A CN202010986751 A CN 202010986751A CN 112114773 A CN112114773 A CN 112114773A
- Authority
- CN
- China
- Prior art keywords
- sound card
- sound
- card
- audio
- label
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/16—Sound input; Sound output
- G06F3/162—Interface to dedicated audio devices, e.g. audio drivers, interface to CODECs
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/16—Sound input; Sound output
- G06F3/165—Management of the audio stream, e.g. setting of volume, audio stream path
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- General Health & Medical Sciences (AREA)
- Human Computer Interaction (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Health & Medical Sciences (AREA)
- Multimedia (AREA)
- Computing Systems (AREA)
- Telephonic Communication Services (AREA)
Abstract
The invention discloses a multi-sound-card management method and a system based on an Android system, and relates to the technical field of audio, wherein the management method comprises the following steps: constructing an audio attribute object for an application party; setting a sound card label for the audio attribute object according to the setting information of the sound card; calling an HAL hardware layer through Audio Services according to the sound card label, and opening a sound card corresponding to the sound card label; and executing the request of playing or recording the sound by the application party through the opened sound card. In the invention, an audio attribute object is constructed for an application party using a specified sound card, a sound card label is constructed for the audio attribute object, and a corresponding sound card is selected to play according to the sound card label, thereby realizing the control of the input or output of multiple sound cards.
Description
Technical Field
The invention relates to the technical field of audio, in particular to a multi-sound-card management method and system based on an Android system.
Background
The Android system has complex Audio construction, including an application layer, a frame layer, a library layer (Audio libs) and a HAL layer.
The application layer is the top layer of the whole audio system and is used for generating playing data, such as a player and recording software. The framework layer is a class of audio functions provided by Android, such as MediaPlayer, AudioTrack, AudioRecorder, AudioManager, AudioService, AudioAttribute, and AudioSystem, and has many types, and actually, only the application uses an intermediate call of an Android library file. AudioManager, AudioService and AudioSystem in the Framework layer, which is the main part of the library layer audio system service, will finally call two main services, audioFlinger and audioPolicyservice. The audio HAL layer is in communication coordination with the Audio Flinger and the Audio Policyservice of the library layer and provides a standard interface for the audio operation Hardware, and the HAL layer describes the type of the lower Hareware-supported audio equipment; and completing specific system calling operations such as audio reading and writing.
Therefore, the process from data generation to playing of the audio of the Android system is complex, especially for the audio system of the dual sound card, the Android system defaults that the main audio only corresponds to one first sound card, and the audio can only be output or input from the sound card. The sound card is provided with a hardware audio coding and decoding chip for audio playing or recording.
Disclosure of Invention
Aiming at the technical problems in the prior art, the invention provides a multi-sound-card management method and system based on an Android system.
The invention discloses a multi-sound-card management method based on an Android system, which comprises the following steps: constructing an Audio Attributes (Audio Attributes) object for an application side; setting a sound card label for the audio attribute object according to the setting information of the sound card; calling an HAL hardware layer through AudioServices according to the sound card label, and opening a sound card corresponding to the sound card label; and executing the request of playing or recording the sound by the application party through the opened sound card.
Preferably, the Audio Services include an Audio flag and an Audio policy service,
the method for opening the sound card corresponding to the sound card label by calling the HAL hardware layer through the Audio Services comprises the following steps:
calling a sound card selection strategy of the audiopolicservice according to the sound card label;
and calling the AudioFlinger to execute the strategy, and calling the HAL hardware layer to open the corresponding sound card.
Preferably, the management method of the present invention further includes a method of querying policy content:
querying the policy content in the Engine.
Preferably, the management method of the present invention further includes a method of sound card registration:
providing a description file for the sound card;
the sound card is registered in an audio configuration of the system.
Preferably, the AudioFlinger executes the policy, and drives and opens the sound card according to the description file.
Preferably, the management method of the present invention further includes a method of setting a sound card tag according to a process of an application side:
acquiring process information of an application party;
and establishing a sound card label for the audio attribute object constructed by the application party according to the process information and preset configuration information.
Preferably, the dual sound cards include a first sound card and a second sound card, the first sound card is a default sound card of the system, and the management method of the first sound card and the second sound card includes:
judging whether the request is executed through a second sound card or not according to the process information of the application party and preset configuration information;
if so, setting a sound card label for the audio attribute object;
judging whether the Audio attribute object has a sound card label or not through the Audio Services;
if yes, opening a second sound card, and executing a request of playing or recording sound by the application party through the second sound card;
if not, opening the first sound card, and executing the request of playing or recording the sound by the application party through the first sound card.
Preferably, the sound card comprises a playing module and a recording module, and virtual playing equipment and recording equipment are respectively established for the playing module and the recording module;
and opening the playing equipment or the recording equipment according to the request of the application party.
The invention also provides a management system for realizing the management method, which comprises a construction module, a label setting module, a service calling module and an execution module;
the construction module is used for constructing an audio attribute object for an application party;
the label setting module is used for setting a sound card label for the audio attribute object according to the setting information of the output sound card;
the service calling module is used for calling Audio Services to open the sound card corresponding to the sound card label according to the sound card label;
the execution module is used for executing the request of playing or recording the sound of the application party through the opened sound card.
Compared with the prior art, the invention has the beneficial effects that:
in the invention, an audio attribute object is constructed for an application party using a specified sound card, a sound card label is constructed for the audio attribute object, and a corresponding sound card is selected to play according to the sound card label, thereby realizing the control of the input or output of multiple sound cards.
Drawings
FIG. 1 is a flowchart of a multi-sound-card management method based on an Android system according to the present invention;
FIG. 2 is a flowchart of a method for opening a sound card corresponding to a sound card tag through Audio Services;
FIG. 3 is a flow chart of a method of sound card registration;
FIG. 4 is a flow chart of a method of setting sound card labels according to a process on the application side;
fig. 5 is a flowchart of a method of managing a first sound card and a second sound card;
fig. 6 is a logical block diagram of the management system of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
The invention is described in further detail below with reference to the attached drawing figures:
a multi-sound card management method based on an Android system, as shown in fig. 1, the method includes:
step 101: and constructing an audio attribute object for an application side.
The application side refers to an application program calling a sound card for input or output, and the application side may be implemented by using MediaPlayer and MediaRecorder classes of a frame layer, and the MediaPlayer and the MediaRecorder create an object of an Audio attribute type of a default variable in a process of construction initialization, but not limited to this, for example, the application side may also independently construct an object of an Audio attribute (Audio Attributes) type.
Step 102: and setting a sound card label for the audio attribute object according to the setting information of the sound card. And if the music player is set to play by using the second sound card, setting a corresponding sound card label for the audio attribute object of the player.
Step 103: and calling the HAL hardware layer to open the sound card corresponding to the sound card label through Audio Services according to the sound card label.
The AudioServices of the library layer include AudioPolicyService and audioFlinger, and are used for connecting the frame layer and the HAL hardware layer. AudioPolicyService and AudioFlinger are used to manage and enforce audio policies, respectively, calling the sound card by calling the interface of the HAL hardware layer.
Step 104: and executing the request of playing or recording the sound by the application party through the opened sound card. After the sound card is called, the music data of the application party is played through the sound card, or the sound recording data is sent to the application party, so that the sound card control effect is achieved.
In the invention, an audio attribute object is constructed for an application party needing to use a specified sound card, a corresponding sound card label is constructed for the audio attribute object, and the corresponding sound card is selected to be played according to the sound card label, thereby realizing the control of sound card input or output; based on the improvement of the Android system, the Android system supports multiple sound cards, the sound cards are appointed for an application party to be played, and the applicability of the Android system is improved.
The Audio Services include an Audio flag and an Audio policy service, and as shown in fig. 2, the method for opening the sound card corresponding to the sound card tag through the Audio Services includes:
step 201: and calling a sound card selection strategy of the audiopolicservice according to the sound card label. The policy may include an input source corresponding to an entry device for entering sound and an output policy corresponding to a playback device for playing sound, and the sound card selection policy may include an audio device selection policy, the audio device including an entry device or a playback device.
Step 202: invoking the AudioFlinger to execute the policy: and calling a HAL hardware layer to open a corresponding sound card.
The sound card comprises a playing module and a recording module, and virtual playing equipment and recording equipment are respectively established for the playing module and the recording module on a HAL hardware layer; and opening corresponding playing equipment or recording equipment according to the strategy. Namely, the playing device or the entry device is selected to execute the request of the application party according to the request of the application party.
Example 1
As shown in fig. 3, the present embodiment provides a method for sound card registration:
step 301: providing a description file for the sound card. Specifically, the description file is a so file provided in the HAL library, such as the file audio. The description file is used for describing the name and the drive of the sound card, and the name of the playing device or the name of the recording device. And the audio system is facilitated to control the sound card.
In a specific embodiment, the description code is as follows:
step 302: the sound card is registered in the audio configuration of the system so that the system can identify the sound card. In which, steps 301 and 302 may have no execution sequence, such as registering first and then providing the description file.
In a specific embodiment, the code for registering the sound card is as follows:
example 2
As shown in fig. 4, the present embodiment provides a method for setting a sound card tag according to a process of an application side:
step 401: and acquiring the process information of the application side. And when the audio attribute object is constructed on the frame layer, the information of the application package name is obtained by looking up the process information of the application party. In one embodiment, the process information is obtained using the function getAppProcessName ().
Step 402: and establishing a sound card label for the audio attribute object constructed by the application party according to the process information and preset configuration information. And if the preset configuration information is that the music player uses a second sound card for playing, setting a second sound card label for the audio attribute object of the music player when the process information is matched with the music player.
Configuration information may be preset according to the association of the process information and the name of the application party. As the process name: com.tencent.qqmusiccar is matched with a QQ music player, and when the QQ music player is preset to play by using a second sound card, the process name is matched with a sound card label of the second sound card, so that the readability is improved, and the understanding is facilitated. But not limited to, the name of the application party may also be obtained by other means, such as directly receiving the name of the application party sent by the application party.
And establishing a sound card label for the application party according to the preset configuration information, so that the appointed sound card is used for playing or inputting for the appointed application party.
After the Audio attribute object is constructed, the Audio preparation phase is entered through a function prepareAsyn (), Audio Services of the library layer of the Audio preparation phase open corresponding playing equipment or recording equipment, and Audio data are output by the equipment.
Example 3
Take the second sound card for audio input as an example. Step 201, according to the sound card tag, invoking an audio device selection policy implementation code of AudioPolicyService as follows:
frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
status _ TaudioPolicyManager getInputForAttr (constaudio _ attributes _ t _ attr)// Call Audio attributes object
audio_source_tinputSource=attr->source;
if(attr!=NULL){
if((attr->flags&AUDIO_FLAG_SPECIAL_SECOND_SND)==AUDIO_FLAG_SPECIAL_SECOND_SND)
{inputSource=AUDIO_SOURCE_SPECIAL_SECOND_SND;
Matching input sources according to sound card labels }//
}
Wherein, AUDIO _ FLAG _ specific _ SECOND _ SND is a SECOND sound card label, and AUDIO _ SOURCE _ specific _ SECOND _ SND is a matched SECOND sound card input SOURCE.
Before executing step 202, the method for querying the policy content according to the policy obtained in step 201 may further: querying the policy content in the Engine.
The implementation code is as follows:
frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp
audio_devices_tEngine::getDeviceForInputSource(audio_source_tinputSource)const
{
caseAUDIO_SOURCE_SPECIAL_SECOND_SND:
DEVICE _ IN _ BACK _ MIC; strategy matching to strategy content: and the HAL layer is a recording device of a second sound card.
break;
}
And after the strategy is matched with the entry equipment of the HAL layer, the strategy and the content thereof are executed through the AudioFlinger, and the entry module of the second sound card is driven and opened by adopting the description file of the HAL library according to the strategy content so as to obtain the entry data.
Example 4
Taking the second sound card for audio output as an example, the implementation code of step 201 is as follows:
before executing step 202, policy content may also be queried according to the policy obtained in step 201.
And after the strategy content is matched, executing the strategy and the content thereof through the AudioFlinger, and driving and opening a playing module of the second sound card by adopting the description file of the HAL library according to the strategy content so as to play sound.
The Android audio system is complex in structure and can be called layer by layer, and when a policy is constructed, the content of the policy can be set in the policy and the audioFlinger is called to execute the policy.
Example 5
The Android system double sound card is taken as an example for explanation:
as shown in fig. 5, the dual sound card includes a first sound card and a second sound card, where the first sound card is a system default sound card, and the management method of the first sound card and the second sound card includes:
step 501: and judging whether the execution request of the application party is executed through the second sound card or not according to the process information of the application party and preset configuration information. The request may be a play request or an enter request.
If yes, go to step 502: and setting a sound card label for the audio attribute object. And if not, not establishing the sound card label.
Step 503: and judging whether the Audio attribute object has a sound card label or not through the Audio Services. The Audio Services include an Audio flag and an Audio policy service.
If yes, go to step 504: and opening a second sound card, and executing the request of playing or recording the sound by the application party through the second sound card.
If not, go to step 505: and opening a first sound card, and executing a request of playing or recording sound by the application party through the first sound card.
However, if the determination in step 501 is negative, a first sound card label may be established for the first sound card, and the corresponding sound card may be opened according to the type of the sound card label.
The invention also provides a management system for implementing the method, as shown in fig. 6, comprising a construction module 1, a tag setting module 2, a service calling module 3 and an execution module 4;
the construction module 1 is used for constructing an audio attribute object for an application party;
the label setting module 2 is used for setting a sound card label for the audio attribute object according to the setting information of the output sound card;
the service calling module 3 is used for calling Audio Services to open the sound card corresponding to the sound card label according to the sound card label;
the execution module 4 is used for executing the request of playing or recording the sound by the application party through the opened sound card.
The above is only a preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes will occur to those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. A multi-sound-card management method based on an Android system is characterized by comprising the following steps:
constructing an audio attribute object for an application party;
setting a sound card label for the audio attribute object according to the setting information of the sound card;
calling an HAL hardware layer through Audio Services according to the sound card label, and opening a sound card corresponding to the sound card label;
and executing the request of playing or recording the sound by the application party through the opened sound card.
2. The Android system multi-sound-card-based management method of claim 1, wherein the Audio Services comprise an Audio Flinger and an Audio Policyservice,
the method for opening the sound card corresponding to the sound card label by calling the HAL hardware layer through the Audio Services comprises the following steps:
calling a sound card selection strategy of the audiopolicservice according to the sound card label;
and calling the AudioFlinger to execute the strategy, and calling the HAL hardware layer to open the corresponding sound card.
3. The Android system multi-sound-card-based management method of claim 2, further comprising a method for querying policy content:
querying the policy content in the Engine.
4. The Android system multi-sound-card-based management method of claim 2, wherein the policy content comprises input source and output policies.
5. The Android system multi-sound-card-based management method according to claim 2, further comprising a sound card registration method:
providing a description file for the sound card;
the sound card is registered in an audio configuration of the system.
6. The Android system multi-sound-card-based management method of claim 5, wherein the AudioFlinger executes the policy, and drives and opens the sound card according to the description file.
7. The Android system-based multi-sound-card management method of claim 1, further comprising a method of setting a sound card label according to a process of an application party:
acquiring process information of an application party;
and establishing a sound card label for the audio attribute object constructed by the application party according to the process information and preset configuration information.
8. The Android-system-based multi-sound-card management method of claim 7, wherein the dual-sound card comprises a first sound card and a second sound card, the first sound card is a system default sound card, and the management method of the first sound card and the second sound card comprises the following steps:
judging whether the request is executed through a second sound card or not according to the process information of the application party and preset configuration information;
if so, setting a sound card label for the audio attribute object;
judging whether the Audio attribute object has a sound card label or not through the Audio Services;
if yes, opening a second sound card, and executing a request of playing or recording sound by the application party through the second sound card;
if not, opening the first sound card, and executing the request of playing or recording the sound by the application party through the first sound card.
9. The Android system-based multi-sound-card management method according to claim 1, wherein the sound card comprises a playing module and a recording module, and virtual playing equipment and recording equipment are respectively established for the playing module and the recording module;
and opening the playing equipment or the recording equipment according to the request of the application party.
10. The management system for implementing the Android system multi-sound-card-based management method of any one of claims 1 to 9, comprising a construction module, a tag setting module, a service calling module and an execution module;
the construction module is used for constructing an audio attribute object for an application party;
the label setting module is used for setting a sound card label for the audio attribute object according to the setting information of the output sound card;
the service calling module is used for calling Audio Services to open the sound card corresponding to the sound card label according to the sound card label;
the execution module is used for executing the request of playing or recording the sound of the application party through the opened sound card.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010986751.0A CN112114773A (en) | 2020-09-18 | 2020-09-18 | Multi-sound-card management method and system based on Android system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010986751.0A CN112114773A (en) | 2020-09-18 | 2020-09-18 | Multi-sound-card management method and system based on Android system |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN112114773A true CN112114773A (en) | 2020-12-22 |
Family
ID=73799910
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202010986751.0A Pending CN112114773A (en) | 2020-09-18 | 2020-09-18 | Multi-sound-card management method and system based on Android system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN112114773A (en) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113741984A (en) * | 2021-07-22 | 2021-12-03 | 深圳市智微智能科技股份有限公司 | Android application layer sound card specifying method, system, terminal and storage medium |
| CN116185329A (en) * | 2023-01-10 | 2023-05-30 | 上海赛连信息科技有限公司 | Multi-device multi-sound card audio synchronous acquisition method and system |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5943649A (en) * | 1997-10-29 | 1999-08-24 | International Business Machines Corporation | Configuring an audio interface for different microphone types |
| CN105204814A (en) * | 2014-06-24 | 2015-12-30 | Tcl集团股份有限公司 | Sound card switching method and system of Android system |
| CN205862318U (en) * | 2016-06-07 | 2017-01-04 | 深圳市航盛电子股份有限公司 | Many sound cards audio output device under a kind of embedded OS and system |
| CN108668203A (en) * | 2017-03-30 | 2018-10-16 | 腾讯科技(深圳)有限公司 | Audio frequency playing method, system and device |
-
2020
- 2020-09-18 CN CN202010986751.0A patent/CN112114773A/en active Pending
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5943649A (en) * | 1997-10-29 | 1999-08-24 | International Business Machines Corporation | Configuring an audio interface for different microphone types |
| CN105204814A (en) * | 2014-06-24 | 2015-12-30 | Tcl集团股份有限公司 | Sound card switching method and system of Android system |
| CN205862318U (en) * | 2016-06-07 | 2017-01-04 | 深圳市航盛电子股份有限公司 | Many sound cards audio output device under a kind of embedded OS and system |
| CN108668203A (en) * | 2017-03-30 | 2018-10-16 | 腾讯科技(深圳)有限公司 | Audio frequency playing method, system and device |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113741984A (en) * | 2021-07-22 | 2021-12-03 | 深圳市智微智能科技股份有限公司 | Android application layer sound card specifying method, system, terminal and storage medium |
| CN116185329A (en) * | 2023-01-10 | 2023-05-30 | 上海赛连信息科技有限公司 | Multi-device multi-sound card audio synchronous acquisition method and system |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| KR20140033494A (en) | Method and system for implementing function extension of open platform | |
| KR20080084966A (en) | Conforming web services to an updated contract | |
| US20130232506A1 (en) | Cross-extension messaging using a browser as an intermediary | |
| US7865390B2 (en) | Modeling of employee performance result data | |
| CN107547237A (en) | Virtual network function VNF update methods, device and VNF bags | |
| CN112114773A (en) | Multi-sound-card management method and system based on Android system | |
| CN113627145A (en) | A file generation method, device, device and medium for parameterized configuration | |
| CN112866268B (en) | Message processing method and system | |
| CN112764802A (en) | Business logic customization method and device, electronic equipment and storage medium | |
| CN106897153A (en) | Call the method and system of API | |
| CN114879930A (en) | Audio output optimization method for android compatible environment | |
| CN112911180A (en) | Video recording method and device, electronic equipment and readable storage medium | |
| CN108733374A (en) | Application program homepage development approach and terminal device | |
| US8510707B1 (en) | Mainframe-based web service development accelerator | |
| CN112130850A (en) | Method and device for implementing functions in application programs | |
| CN109816212A (en) | Creation method, device, storage medium and the electronic equipment of task list | |
| CN108769028B (en) | Method and device for assembling message | |
| CN112581257B (en) | Dispute service management method, system, equipment and medium supporting different card organizations | |
| CN114490104B (en) | Information forwarding method, device, equipment and medium in Android system module | |
| CN114219643B (en) | A transaction calling method, device, equipment and storage medium | |
| CN111221803A (en) | Characteristic library management method and coprocessor | |
| US20070209043A1 (en) | Routing calls via reflective interfaces and a proxy | |
| CN106778193B (en) | Client and UI interaction method | |
| CN115795537A (en) | Transaction log desensitization method and system | |
| US6970536B2 (en) | Method and apparatus for processing a voice system application |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20201222 |
|
| RJ01 | Rejection of invention patent application after publication |