Android2.3 Audio System HAL

Source: Internet
Author: User

In a big aspect, the android audio system architecture has not changed much compared with Android. The analysis of the audio architecture of 2.2 still applies to 2.3. Many people have already elaborated on this aspect in detail and I will not repeat it here. The storage location of files in each module has changed, so you need to understand this.

 

1. A major improvement is the introduction of the mixable audio effects system. I flipped through the Code, which should be implemented by opensles. Opensles is also a new audio library introduced by 2.3, which makes Android sound more powerful. However, some performance should be sacrificed. For example, the android framework layer fixed audio sample rate to 44.1 kHz and the audio stream was resample (audioresampler. CPP), which makes the CPU usage of Audio-related threads very high.

Android gives me the feeling that it takes too much care of developers. Even though the underlying layer uses cross-platform software methods in many places, Hal should be minimized, such as mixer and equalizer. Mixer is good. At least audiohardwareinterface. H provides interfaces for Hal implementation. Sound effects such as equalizer are only software implementation. For Hal implementation, refer to the files in the hardware and device directories. for audio, android2.3.1-Gingerbread/device/Samsung/Crespo/libaudio are extremely valuable. I guess even if we port another platform, there are very few changes to this part.

 

2. In the android2.2 era, the opencore multimedia framework is retained. Although only OMX-component is used, stagefright is selected by default. In 2.3, stagefright is fully used, and opencore is also removed from Android. For an introduction to opencore and stagefright, see: http://blogold.chinaunix.net/u2/61880/showart.php? Id = 2339481

ALSA-lib is the same fate as opencore. I was surprised at the beginning. opencore can be replaced by stagefright, But what underlying audio library can replace ALSA-lib? We can see android2.3.1-Gingerbread/device/Samsung/Crespo/libaudio. The original alsa_pcm.c and alsa_mixer.c implemented a mini ALSA-lib.

I think in future versions, Google may continue to do the same thing and remove some open-source libraries to implement its own set, which is more concise. I personally do not like this practice very much. Open-source libraries are often more powerful and have standard interfaces. Now, developers need to spend more time familiarizing themselves with the interfaces of the android castrated version-perhaps more worrying. After all, developers rarely change the framework layer; the other is that open-source libraries will be constantly updated and fixed, and it is hard to say whether Google can keep up with it.

 

 

 

 

4/9 2011

Let's take a look at the following parts of audio HAL: audioflinger. It seems that some errors may not be clearly explained after reading several articles on the Internet.

First, audioflinger. cpp:

Audioflinger: audioflinger ()
: Bnaudioflinger (),
Maudiohardware (0), mmastervolume (1.0f), mmastermute (false), mnextuniqueid (1)
{
Mhardwarestatus = audio_hw_idle;

Maudiohardware = audiohardwareinterface: Create ();

Mhardwarestatus = audio_hw_init;
If (maudiohardware-> initcheck () = no_error ){
// Open 16-bit output stream for S/W Mixer
Mmode = audiosystem: mode_normal;
Setmode (mmode );

Setmastervolume (1.0f );
Setmastermute (false );
} Else {
LogE ("couldn't even initialize the stubbed audio hardware! ");
}
# Ifdef lvmx
Lifevibes: Init ();
Mlifevibesclientpid =-1;
# Endif
}

We can see that the red part is used to create an audio hardware interface through audiohardwareinterface. Create. We traced back to audiohardwareinterface. cpp:

Audiohardwareinterface * audiohardwareinterface: Create ()
{
/*
* Fixme: This code needs to instantiate the correct audio device
* Interface. For now-we use compile-time switches.
*/
Audiohardwareinterface * hW = 0;
Char value [property_value_max];

# Ifdef generic_audio
HW = new audiohardwaregeneric ();
# Else
// If running in Emulation-use the emulator driver
If (property_get ("Ro. kernel. qemu", value, 0 )){
Logd ("running in Emulation-using generic audio driver ");
HW = new audiohardwaregeneric ();
}
Else {
Logv ("creating Vendor Specific audiohardware ");
HW = createaudiohardware ();
}
# Endif
If (HW-> initcheck ()! = No_error ){
Logw ("using stubbed audio hardware. No sound will be produced .");
Delete HW;
HW = new audiohardwarestub ();
}

# Ifdef with_a2dp
HW = new a2dpaudiointerface (HW );
# Endif

# Ifdef enable_audio_dump
// This Code adds a record of buffers in a file to write callmade by audioflinger.
// It replaces the current audiohardwareinterface object by an intermediate one which
// Will record buffers in a file (after sending them to hardware) for testing purpose.
// This feature is enabled by defining symbol enable_audio_dump.
// The output file is set with setparameters ("test_assist_file_name = <Name>"). Pause are not recorded in the file.
Logv ("Opening PCM dump interface ");
HW = new audiodumpinterface (HW); // replace Interface
# Endif
Return HW;
}

It is distinguished by different colors. The following six audio interfaces are supported:

1. Generic audio: it is the default audio hardware selected by Android, and the underlying device node is/dev/EAC. For details, see audiohardwaregeneric. cpp. I am not familiar with the underlying driver corresponding to this interface.

2. emulator audio: Generic audio is also used.

3. Vendor Specific audio: the vendor's custom audio hardware interface. This is our focus. Generally, we need to implement this interface. We will analyze it later.

4. a2dp audio: Bluetooth audio, which has no in-depth knowledge.

5. Stubbed audio: the implementation method is in audiohardwarestub. cpp. You can see that most functions only return a value without actual operations. It only ensures that android can get at least an audio hardware instance so that it can start and run without sound.

6. Dump audio: For details, see annotations. It is mainly used to debug upper-layer audio programs and save the upper-layer record sound to a file for analysis.

 

Vendor Specific audio

Generally, we only need to implement hardware/libhardware_legacy/include/hardware_legacy/audiohardwareinterface. the interface provided by H is ready, and then extern "C" audiohardwareinterface * createaudiohardware (void); facilitates the call of audiohardwareinterface * audiohardwareinterface: Create.

Taking Samsung's Crespo as an example, device/Samsung/Crespo/libaudio/audiohardware. CPP, which implements an audiohardware class. Its method is also based on audiohardwareinterface. implemented by the pure virtual function interface provided by H.

Extern "C" audiohardwareinterface * createaudiohardware (void ){
Return new audiohardware ();
}

Note: As mentioned in the opening section, android2.3 has removed ALSA-lib, which is actually called to the underlying layer or ALSA-driver. It implements a mini ALSA-Lib. If you are interested, you can check it out. Of course, you can also use other audio driver architectures as needed, such as OSS or the vendor's own firmware (not open-source, or android Hal ).

 

Boardconfig

For the panel configuration option file, see build/target/board/generic/boardconfig. mk. The default definition is as follows:

Board_uses_generic_audio: = true

This is the use of the generic audio interface.

If you want to use the Vendor Specific audio interface, you can modify it:

Have_htc_audio_driver: = false
Board_uses_generic_audio: = false

Then add:

Board_uses_vendor_specific_audio: = true

Board_uses_vendor_specific_audio depends on the Android. mk of the Board.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.