Audio-related code analysis

Source: Internet
Author: User
I. Overview of the audio system is divided into the following layers: (1) Upper-layer interfaces of the audio system provided by the media library;
(2) audioflinger serves as the middle layer of the audio system;
(3) The hardware abstraction layer of audio provides underlying support;
(4) The audio interface is provided to the upper layer through the JNI and Java frameworks. The APIs of the audio system provide two functions: Sound Recording and recorder ).
In the android audio system, both the upper and lower layers use a management class and an output input class to represent the entire audio system. The output class and input class are responsible for the data channel. Ii. Audio Framework Analysis 1. Java section of audio
Code Path: frameworks/base/Media/Java/Android/Media
The Java package related to audio is Android. Media, which mainly includes several classes of audiomanager and audio systems. 2. JNI section of audio
Code path: Frameworks/base/CORE/JNI
Generate the libandroid_runtime.so library. The JNI of audio is a part of it. 3. Audio Framework
Header file path: Frameworks/base/include/Media/
Source code Path: frameworks/base/Media/libmedia/audio the local framework is part of the media library. This part of the content is compiled into the library libmedia. So,
Provides the audio interface (including the binder-based IPC Mechanism ).

The core framework of the audio system is provided in the media library, which mainly implements three categories: audiosystem, audiotrack, and audiorecorder. Iaudioflinger class interfaces are provided. In this class, iaudiotrack and iaudiorecorder can be obtained for playing and recording sounds respectively. Audiotrack and audiorecorder are implemented by calling iaudiotrack and iaudiorecorder respectively. The header file of the audio system is in the frameworks/base/include/Media/directory. The main header file is as follows:
Audiosystem. h: the upper-layer Manager interface of the audio part of the media library;
Iaudioflinger. h: the lower-layer Implementation of the main interface;
Audiotrack. h: Uploading interface;
Iaudiotrack. H: The playing part requires the interface implemented by the lower layer;
Audiorecorder. h: Specifies the upper interface of the recording part;
Iaudiorecorder. H: The interface implemented in the lower layer for the recording part. The iaudioflinger. H, iaudiotrack. H, and iaudiorecorder. h interfaces are implemented through lower-layer inheritance (namely, audioflinger ). Audioflinger. H, audiotrack. H, and audiorecorder. h are interfaces provided to the upper layer. Program Call (such as sound player and recorder), or provide interfaces to the Java layer through JNI. 4. Audio flinger
Code path: Frameworks/base/libs/audioflinger is compiled into library libaudioflinger. So, which is the local service part of the audio system. Audioflinger is the middle layer of the audio system and plays a service role in the system. It is mainly used as the implementation of some audio interfaces provided by libmedia. The core files of audioflinger are audioflinger. h and audioflinger. cpp, which are provided for the class audioflinger. This class is an iaudioflinger implementation. Audioflinger mainly provides createtrack () to create the iaudiotrack device for audio output, and openrecord () to create the iaudiorecord device for audio input. It also contains a GET/set interface for control. From a working point of view, after the audioflinger initialization, it first obtains the playing device, then creates a thread for the mixer, and then establishes the playing device thread to obtain the playing device in the thread. 5. Audio hardware abstraction layer interface
Header file path: Hardware/libhardware_legacy/include/hardware/
The main files are audiohardwarebase. h and audiohardwareinterface. h. The implementation of the audio hardware abstraction layer may be different in various systems. You need to use the code to inherit the corresponding classes and implement them as the local framework layer and driver interface of the Android system. The Hardware Abstraction Layer of audio is the interfaces of audioflinger and audio hardware. Different implementations can be implemented in the porting process of each system. The audio hardware abstraction layer can be implemented based on the Linux Standard ALSA or OSS audio driver, or based on the private audio driver interface. Classes such as audiostreamout, audiostreamin, and audiohardwareinterface are defined in audiohardwareinterface. h. In this audiohardwareinterface interface, use the openoutputstream () and openinputstream () functions to obtain audiostreamout and audiostreamin classes respectively. They are used as audio input/output devices. In addition, audiohardwareinterface. h defines the C language interface to obtain an audiohardware Interface Class pointer.
Extern "C" audiohardwareinterface * createaudiohardware (void); if an Android hardware abstraction layer is implemented, three classes are required: audiohardwareinterface, audiostream out, And audiostreamin, compile the code into a dynamic library libauido. so. Audioflinger connects to the dynamic library and calls the createaudiohardware () function to obtain the interface.

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.