Android Multimedia Framework Summary (VI) C/s architecture of MediaPlayer

Source: Internet
Author: User

Reprint please the head source link and the tail two-dimensional code together reproduced, this article from:
http://blog.csdn.net/hejjunlin/article/details/52435789

In the preceding sections, all are called through the Java layer to JNI, and jni down to the C + + layer does not introduce
Look at the Java layer a method in the C + + layer MediaPlayer follow-up process
Frameworks/av/media/libmedia/mediaplayer.cpp
Find a familiar Setdataresource method to see the process of C/s mode, also refer to the Android Multimedia Framework Summary (iv) MediaPlayer from Java layer to C + + layer class relationship and prepare and other processes in the diagram To understand the overall C/s architecture. First look at the agenda:

    • For example, what happens after the Setdatasource method Mediaplayer.cpp?
    • What exactly is a client?
    • What is a relationship between client and MediaPlayer?
    • What do imediaplayer.h,mediaplayer.h,imediaplayerclient do separately?
For example, what happens after the Setdatasource method Mediaplayer.cpp?

First look at the Setdatasource method:

corresponding to see the MediaPlayerService.cpp in the Createt function, here MediaPlayerService.cpp location, 6.0 source is in the frameworks/av/media/ The libmediaplayerservice/mediaplayerservice.cpp. As follows:

In the new client, there is a ipcthreadstate, introduced here: in Android Processstate is the client and the server side of the public part, as the basis for binder communication, Processstate is a singleton class Each
The process has only one object, which is responsible for opening the binder drive and creating a thread pool so that all threads within its process can communicate through binder.
Associated with this is ipcthreadstate, where each thread has a ipcthreadstate instance registered in the context of the Linux thread, and is primarily responsible for
Binder's Read, write, and request processing framework. Ipcthreadstate gets the processstate of the process at the time of construction and records it in its member variable mprocess, and the handle of the binder can be obtained through mprocess. Learn more about Processstata and Ipcthreadstate source code, you can refer to: "Binder in the Processstate and Ipcthreadstate analysis", written very good, Ipcthreadstate data, and handle etc into the Binder_transaction_data through Ipcthreadstate::transact, communicating between two processes.

What exactly is a client?

What exactly is this client here? We have to trace it again under Frameworks/av/media/libmediaplayerservice/mediaplayerservice.h as follows:



The above code is not omitted, because it is true that we understand the MediaPlayer related methods from the Java layer, which have corresponding. If you remember the previous "Android Multimedia Framework Summary (iv) MediaPlayer from the Java layer to the C + + layer class relationship and prepare and other procedures in the article that the diagram, you can understand the overall role of the client and location." Inherits the Bnmediaplayer and contains the Imediaplayer related interfaces.
Summarize the above code: the client class inheritance relationship is: Client->bnmediaplayer->imediaplayer analysis of the above code, you can see the Create method, is to construct a client object, and add this client object to the global list of the Mediapalyerservice class: Mclients, is a sortedvector, followed by Player->setdatasource (URL, headers), That is Clients::setdatasource, so in the Setdatasource

Statement is equivalent to

That is, the player is ultimately initialized with the client object and can be considered directly player==client
This article is derived from the countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/52435789

What is the relationship between client and MediaPlayer?

Is this the waiting question? In C + +, what kind of relationship does this client and MediaPlayer have?

    • The client is a class within the mediaplayerservice, we know from the above code, because Mediaplayerservice runs on the server, so the client is also running on the server.
    • Client in the MediaPlayerService.h, then look at the implementation of the mediaplayerservice in the implementation process called the Mediaplayerservice class of some functions, the same back to Setdatasource


Next look at MediaPlayer, in the following code in FRAMEWORKS/AV/INCLUDE/MEDIA/MEDIAPLAYER.H:


Here the function and the function in the client correspond, and both are connected by the proxy class of the client.


The above two functions, one is MediaPlayer's setdatasouree, then the inside will be transferred to the Attachnewplayer function, this function will eventually call to the server client's corresponding function,
This article is derived from the countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/52435789

What do imediaplayer.h,mediaplayer.h,imediaplayerclient do separately?

Here, one might think: what is the difference between IMediaPlayer.h and mediaplayer.h? The main summary is as follows (plus a IMediaPlayerClient.h, introduced together):

    • From the package structure: first Imediaplayer and IMediaPlayerClient.h are under the Frameworks/av/media/libmedia package, and Mediaplayer.h is under the/av/include/media package. (previous code has been posted)
    • Functionally, they do not have the same responsibilities.

The IMediaPlayer.h and IMediaPlayerClient.h codes are posted here:
IMediaPlayer.h located under Frameworks/av/media/libmedia:


IMediaPlayer.h is basically a virtual function, and we know that virtual function in C + + is to achieve polymorphism (polymorphism), polymorphism is to separate the interface and implementation, in the image of the language to explain is to achieve a common approach, However, different strategies are adopted for individual differences. So its function is an interface to implement MediaPlayer function, see that ontransact method, naturally Lenovo binder communication, the underlying parcel pointer type data to the upper layer to another process.
Look again at the IMediaPlayerClient.h, also located under the Frameworks/av/media/libmedia:


    • The above code summarizes: Define a bpmediaplayerclient internally (that is, the parent of the client), and then it also has a ontransact, the general onxxx is the back of the callback, not by their own control, If the activity is Oncreate,onpause,onstart, these are handled elsewhere and notified to the actvitity. Here too, ontransact as a callback method in binder communication, in front of "Android Multimedia Framework Summary (iv) MediaPlayer from Java layer to C + + layer class relationship and prepare and other processes" Introduced to the player is actually the C/s mode overall, IMediaPlayerClient.h function is to describe a MediaPlayer client interface.

    • Finally summed up: mediaplayer.h function is the external (JNI layer) interface class, it is the most important to define a MediaPlayer class (C + + layer), we introduced in Android_media_mediaplayer.cpp media/ Mediaplayer.h,imediaplayer.h is an interface that implements the MediaPlayer (c + + layer) functionality. The function of the IMediaPlayerClient.h is to describe an interface to a MediaPlayer client, which is tentatively understood to be the previously-stated customer.

The first time to get blog update reminders, as well as more Android dry, source code Analysis , Welcome to follow my public number, sweep the bottom QR code or long press to identify two-dimensional code, you can pay attention to.

If you feel good, easy to praise, but also to the author's affirmation, can also share this public number to you more people, original not easy

Android Multimedia Framework Summary (VI) C/s architecture of MediaPlayer

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.