Audio Data Process

Source: Internet
Author: User

When the system starts, mediasever loads two services: audiopolicyservice and audioflinger.

 

1.3.1 audiopolicyservice

AudiopolicyserviceMainly to complete the following tasks

The Java application layer uses JNI to access the services provided by audiopolicyservice through the iaudiopolicyservice interface.

Connection status of input and output devices

System Strategy Switching

Volume/audio parameter settings

 

1.3.2 audioflinger

AudioflingerAccess audiohardware to output audio data and control audio parameters. At the same time, audioflinger provides services through the iaudiofinger interface. Therefore, audioflinger plays a crucial role in the android audio system framework.

 

1.3.3 how towork

Audiotrack: In the android Audio Subsystem, each audio stream corresponds to an audiotrack instance, and each audiotrack is registered to audioflinger at creation, audioflinger is used to mix all audiotracks and then deliver them to audiohardware for playback. Currently, the froyo version of Android allows you to create up to 32 audio streams at the same time, the opened space is 1 m, and each audio track is 32 K. That is to say, mixer can process up to 32 audiotrack data streams simultaneously.

 

Binder: Audiotrack and audioflinger are not in the same process. They are connected through the Binder Mechanism in Android.

Audio_track_cblk_t implements a circular FIFO;
Audiotrack is a FIFO data producer;

Audioflinger is a FIFO data consumer.

Establishing a connection
Java layer uses JNI, new audiotrack ();

Getoutput () is called in a series of ways based on streamtype and other parameters ();

If necessary, audioflinger enables different hardware devices based on streamtype;
Audioflinger creates a mixing thread for the output device: mixerthread (), and returns the thread ID to audiotrack as the return value of getoutput;

Audiotrack calls audioflinger's createtrack () through the Binder Mechanism ();

Audioflinger registers the audiotrack to mixerthread;

Audioflinger creates a trackhandle for control and uses the iaudiotrack interface as the return value of createtrack;

Audiotrack uses the iaudiotrack interface to obtain the FIFO (audio_track_cblk_t) created in audioflinger );

Audiotrack creates its own monitoring thread: audiotrackthread;

Since then, audiotrack has established all contact work with audioflinger. Next, audiotrack can: Use the iaudiotrack interface to control the status of the audio track, such as start, stop, and pause, implements continuous audio playback. Monitors the occurrence of thread monitoring events and interacts with user programs through the audiocallback callback function;

FIFO management
The audio_track_cblk_t structure is the key to implement FIFO. This structure is applied for memory by audioflinger during createtrack, and then the audiotrack is returned through the imemory interface, in this way, audiotrack and audioflinger manage the same audio_track_cblk_t through which audio data is written to the first-in-first-out (FIFO) and audioflinger reads audio data from the first-in-first-out (FIFO, after being mixer, it is sent to audiohardware for playback.

The main data member of audio_track_cblk_t:
User -- audiotrack current write location offset
Userbase -- the reference position of the audiotrack write offset, which can be determined based on the user value.
Server -- audioflinger current read location offset
Serverbase -- the reference location of the audioflinger read offset. The FIFO address pointer can be determined based on the server value.
Framecount -- the size of the FIFO, in the unit of audio data frames. The size of each 16-bit audio frame is 2 bytes.
Buffers -- the starting address pointing to the FIFO address
Out -- audio stream direction. For audiotrack, out = 1, for audiorecord, out = 0

The main member functions of audio_track_cblk_t:
Framesavailable_l () and framesavailable () are used to obtain the size of the writable free space in the first-in-first-out (only the difference between locking and non-locking.

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.