In Android, graphic interfaces and multimedia operations are easy to implement. In addition, most mobile phone users modify the system based on these features. We can use the source code of the Android multimedia framework introduced in this article to analyze the basic knowledge in this aspect.
The Android multimedia framework code is in the following directory: external/opencore /. This directory is the root directory of the Android multimedia framework. The subdirectories are as follows:
* Android: This is an upper-layer library. It implements a Player and Author for Android based on the PVPlayer and PVAuthor sdks.
* Baselibs: The underlying library that contains data structures and thread security.
* Codecs_v2: This is a library with a large amount of content, mainly including the implementation of codec and an OpenMAX implementation.
* Engines: including PVPlayer and PVAuthor engine implementation
* Extern_libs_v2: header file containing khronos's OpenMAX
* Fileformats: file format data parsing (parser) Class
* Nodes: each node class for Codec and file parsing.
* Oscl: compatible Operating System Library
* Pvmi: abstract interface for Input/Output Control
* Protocols: mainly related to network-related RTSP, RTP, HTTP, and other protocols
* Pvcommon: the Android. mk file of the pvcommon library file. There is no source file.
* Pvplayer: the Android. mk file of the pvplayer library file. No source file exists.
* Pvauthor: the Android. mk file of the pvauthor library file. No source file exists.
* Tools_v2: compilation tool and some registrable modules.
Definition and initialization of Splitter
Take the wav splitter as an example. In the fileformats directory, there are pvwavfileparser. cpp files that parse the wav file format, and in the nodes directory, files such as fuse, pvmf_wavffparser_node.h, and pvmf_wavffparser_port.h.
From the bottom up, the PV_Wav_Parser class in vwavfileparser. cpp contains member functions in wav format such as InitWavParser (), GetPCMData (), and RetrieveFileInfo (). This class should be the final parsing class. We can find out where the PV_Wav_Parser class is used. In the PVMFWAVFFParserNode class, there is a pointer member variable of PV_Wav_Parser.
The PVMFWAVFFParserNode class is generated through the CreatePVMFWAVFFParserNode () member function of PVMFWAVFFParserNodeFactory. The CreatePVMFWAVFFParserNode () function is registered to the vector of Oscl_Vector in the PVPlayerNodeRegistry: PVPlayerNodeRegistry () Class constructor through the PVPlayerNodeInfo class. In this constructor, AMR, mp3 and other nodes are also registered.
It can be seen from the above that the management of splitter In the Android multimedia framework is similar to ffmpeg and is all registered during framework initialization, but Opencore registers the factory function of each splitter.
Review the definition and initialization process of splitter:
Each splitter has a corresponding subdirectory under the fileformats Directory, which has its own parsing class.
Each splitter is related to the corresponding sub-directories under the nodes directory, and has its own unified interface node class and node factory class.
The PVPlayerEngine class contains the PVPlayerNodeRegistry iPlayerNodeRegistry member variable.
In the PVPlayerNodeRegistry constructor, set AMR, AAC, the input and output types of splitter such as MP3 and the create node and release delete interfaces in the node factory class are pushed to the Oscl_Vector iType member variables through the PVPlayerNodeInfo class.
Matching Process of current Splitter
PVMFStatus PVPlayerNodeRegistry: The function of QueryRegistry (PVMFFormatType & aInputType, PVMFFormatType & aOutputType, Oscl_Vector & aUuids) is based on the input and output types, check whether a matched node exists in the registered node vector. If yes, return the unique identification ID PVUuid.
From the QueryRegistry function to the bottom-up search, the matching process of splitter in android is as follows:
Android_media_MediaPlayer.cpp defines a number group gMethods of JNINativeMethod (JAVA local call method) type, for java code to find the corresponding c ++ function when calling the setDataSource member function of MultiPlayer class
1. {"setDataSource", "(Ljava/lang/String;) V", (void *)
Android_media_MediaPlayer_setDataSource },
2. static void android_media_MediaPlayer_setDataSource
(JNIEnv * env, jobject thiz, jstring path)
This function first obtains the current MediaPlayer instance, then calls its setDataSource function, and passes in the path
3. status_t MediaPlayer: setDataSource (const char * url)
Call getMediaPlayerService () to obtain the current MediaPlayerService, const sp & service (getMediaPlayerService ());
Create an IMediaPlayer variable, sp player (service-> create (getpid (), this, fd, offset, length ));
In sp MediaPlayerService: create (pid_t pid, const sp & client, const char * url)
Call the status_t MediaPlayerService: Client: setDataSource (const char * url) function. The Client is an internal class of MediaPlayerService.
In MediaPlayerService: Client: setDataSource, call sp MediaPlayerService: Client: createPlayer (player_type playerType)
Generates a PVPlayer instance inherited from MediaPlayerBase.
The above is an explanation of the source code of the Android multimedia framework.