Process of creating audiotrack in mediaplayer

Source: Internet
Author: User

Process of creating audiotrack in mediaplayer

When you use mediaplayer to play audio and video, an audiotrack object is created for playing audio data. Let's take a look at the mediaplayer's process of creating audiotrack:

1. Create an audiotrack object
The mediaplayer class does not directly create an audiotrack. Instead, it places the operation for creating an audiotrack object in the internal class audiooutput of the mediaplayerservice class.
The specific code is implemented in the mediaplayerservice: audiooutput: OPEN function by creating (new) An audiotrack object and assigning it to the member variable mtrack of the audiooutput class.
Mtrack is a pointer variable of the audiotrack type.

In addition, the audiooutput class is not only the internal class of mediaplayerservice, but also inherited from the derived class of mediaplayerbase: audiosink.

Now that we know that the audiotrack object was created in the audiooutput: OPEN function, let's take a look at where the audiooutput class object was created and audiooutput :: when is open called.

2. Create an audiooutput Class Object
In the mediaplayerservice: Client: setdatasource function, the audiooutput Class Object maudiooutput is created when you use audioflinger for software mixing.
Then, call the setaudiosink function of the player to assign the maudiooutput object to the audiosink object of the corresponding player.
Assume that local audio and video are played. in GB and ICS, the default player framework is stagefrightplayer, and the corresponding Player Object is awesomeplayer.
Finally, call the awesomeplayer: setaudiosink function and assign maudiooutput to the maudiosink member variable of the awesomeplayer class.
The maudiosink member variable of the awesomeplayer class is also used as the constructor parameter for creating the audioplayer Class Object and passed to the maudiosink member variable of the audioplayer class. It is also a variable of the mediaplayerbase: audiosink.

In this way, the audiooutput class object created in mediaplayerservice is passed to maudiosink, a member of audioplayer, for use during playback.

3. Call the audiooutput: Open Function
Since the audiotrack object is created in the audiooutput: OPEN function, it is important to know when to call the audiooutput: OPEN function.
According to table 2, we know that the audiooutput object has been assigned to the maudiosink member of audioplayer. Therefore, as long as we know that the open function of maudiosink is called, we know how to call audiooutput: OPEN function.
The audioplayer class shows that the open function called maudiosink is implemented in the audioplayer: Start function.
In the audioplayer: Start function, when the maudiosink object is not null, The maudiosink OPEN function is called. The default file format of the parameter is audiosystem: pcm_16_bit. The default audio sink buffer is default_audiosink_buffercount and the value is 4. Then, call the start function of maudiosink, that is, the mediaplayerservice: audiooutput: Start function, to output audio data. The mediaplayerservice: audiooutput: Start function calls the start function of audiotrack.
When the maudiosink object is null, The audiotrack object is created directly and the start function of the audiotrack object is called. So far, you have never encountered the process of directly creating an audiotrack object because the maudiosink object is not empty.
Audioplayer: The start function is executed step by step after you call the start function of mediaplayer.

The above is my understanding of the process of creating audiotrack in mediaplayer. If you have any mistakes, please kindly advise. Thank you. Ameyume

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.