Android audio process 3 (various types and main methods)

Source: Internet
Author: User

Audiotrack

Audio Track creation:

Audiotrack: createtrack

1) audiosystem: get_audio_flinger

2) audiosystem: getoutputsamplingrate

3) audiosystem: getoutputframecount

4) audiosystem: getoutputlatency

5) audioflinger-> createtrack calls the audioflinger method.

6) sp <imemory> cblk = track-> getcblk (); the buffer is actually applied in audioflinger.

7) mcblk = static_cast <audio_track_cblk_t *> (cblk-> pointer (); obtain the buffer pointer

8) mcblk-> buffers = (char *) mcblk + sizeof (audio_track_cblk_t );

Obtain the buffer:

Audiotrack: obtainbuffer

1) uint32_t framesavail = cblk-> framesavailable (); how many frames of data are available in the buffer

2) while (framesavail = 0) {}

3) cblk-> userbase cblk-> framecount ring buffer start and end position adjustment

Write audio data

Audiotrack: Write

1) obtainbuffer (& audiobuffer,-1) gets a buffer without waiting

2) memcpy (audiobuffer. i8, SRC, towrite) Copy Data

3) releasebuffer (& audiobuffer) releases the buffer

Get output device

Audiotrack: getoutput

1) audiosystem: getoutput

In short, audiotrack calls audioflinger to create audio tracks, obtain buffer, and CALLS audiosystem to obtain parameters.


Audiosystem

Get output device

Audiosystem: getoutput

1) audiosystem: gstreamoutputmap. valuefor get iohandle

2) APS = audiosystem: get_audio_policy_service cannot obtain iohandle and requests APS help.

3) Output = APS-> getoutput: Get the output device through APS

4) audiosystem: gstreamoutputmap. Add saves the result to avoid calling APS next time.


Other methods are similar. They call the audiopolicyservice method.


Audiopolicyservice

Create a service

Audiopolicyservice: audiopolicyservice

1) mppolicymanager = createaudiopolicymanager (this)

Get output device

Audiopolicyservice: getoutput

1) mppolicymanager-> getoutput

Other methods are similar. They call audiopolicymanager.

However, audiopolicymanager is not implemented, but implements methods in its parent class. The inheritance relationship is as follows:

Class audiopolicymanager: Public audiopolicymanagerbase

Audiopolicymanagerbase

Create a service

Audiopolicymanagerbase: getoutput

1) audiooutputdescriptor * outputdesc = new audiooutputdescriptor ()

2) mhardwareoutput = mpclientinterface-> the openoutput parameter must be set to client.

3) addoutput

4) setoutputdevice

Get Device

Audiopolicymanagerbase: getoutput

1) Output = mhardwareoutput

Audioflinger

Audioflinger is the middle layer of the entire audio architecture and plays an important role in connecting to the audio architecture. audioflinger. cpp also defines many classes and their respective method implementations.

Audioflinger: openoutput

1) audiostreamout * output = maudiohardware-> openoutputstream

2) New directoutputthread or new mixerthread

3) thread-> audioconfigchanged_l (audiosystem: output_opened );

Audioflinger: closeoutput

1) dupthread-> removeoutputtrack

2) audioconfigchanged_l

3) thread-> exit ();

4) maudiohardware-> closeoutputstream

The audioflinger method can be divided into two parts: playback and record. The process and function are similar. The class construction and function implementation of the sound effect are not analyzed for the moment.


Related Article

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.