Android also provides two classes with similar functions, namely AudioTrack and AudioRecorder. The internal implementation of MediaPlayerService is achieved through these classes, but MediaPlayer/MediaRecorder provides more powerful control functions, it is easier to use than the former. In addition, the Android system also provides AudioManager, AudioService, and AudioSystem for our audio control system. These are all designed by the framework to facilitate upper-layer application development.
Libraries
The framework serves as a bridge for applications to access the Android library. The specific functions are implemented in the library. For example, the above AudioTrack, AudioRecorder, MediaPlayer and MediaRecorder can find the corresponding classes in the library.
1. frameworks/av/media/libmedia [libmedia. so]
2. frameworks/av/services/audioflinger [libaudioflinger. so]
3. frameworks/av/media/libmediaplayerservice [libmediaplayerservice. so]
4. HAL
In terms of design, the hardware abstraction layer is the object directly accessed by AudioFlinger. This illustrates two problems. On the one hand, AudioFlinger does not directly call the underlying driver; on the other hand, the upper-layer module of AudioFlinger only needs to interact with it to implement audio-related functions. Therefore, we can think that AudioFlinger is the real "isolation board" in the Android audio system. The upper-layer implementation can be compatible regardless of the following changes.
The audio hardware abstraction layer consists of AudioFlinger and AudioPolicyService. In fact, the latter is not a real device, but a virtual device is used to allow manufacturers to conveniently customize their own policies. The abstract layer task is to associate AudioFlinger/AudioPolicyService with hardware devices, but it must provide a flexible structure to cope with changes-especially for systems with frequent Android updates. For example, in the Android system, the Audio system was dependent on ALSA-lib, but later it was changed to tinyalsa. Such a change should not cause damage to the upper layer. Therefore, Audio HAL provides a unified interface to define the communication mode between it and AudioFlinger/AudioPolicyService. This is the purpose of audio_hw_device, audio_stream_in, audio_stream_out, and so on, most of these Struct data types are defined as function pointers and are "shells ". When AudioFlinger/AudioPolicyService is initialized, they will find the most matched implementations in the system (these implementations reside in audio. primary. *, audio. a2dp. * fill in the "shells" in the various libraries named ". According to different products, there are great differences in audio devices. In the Android audio architecture, these problems are caused by the HAL-layer audio. primary and so on, without the need to modify the upper-layer implementation on a large scale. In other words, the focus of the manufacturer in customization is how to provide efficient implementation of this sub-database.
AudioRcorder and AudioTrack are APIs provided by the Audio system. AudioRcorder is mainly used to collect Audio data, while AudioTrack is used to output Audio data. AudioFlinger manages the input and output Audio streams in the system and performs Audio data mixing. It reads and writes Audio hardware to implement Audio data input and output functions. AudioPolicyService is the policy control center of the Audio system, in charge of the selection and switching of sound devices in the system, volume control, etc.