1. Use setDataSource to specify the player data source. It can be URI or fd. It can be http: //, rtsp: //, local address, or local file descriptor fd. The final call is to convert the parameters passed by the upper layer to DataSource to provide data support for the next demux.
2. In the real Prepare function onPrepareAsyncEvent (), finishsetperformance_l is called. The DataSource generated in the first step is used to generate an extractor. Because there are many encapsulation formats, you need to create different extractor through DataSource information.
[Cpp]
Extractor = MediaExtractor: Create (
DataSource, sniffedMIME. empty ()? NULL: sniffedMIME. c_str ());
[Cpp]
If (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_MPEG4)
|! Strcasecmp (mime, "audio/mp4 ")){
Ret = new MPEG4Extractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_AUDIO_MPEG )){
Ret = new MP3Extractor (source, meta );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)
|! Strcasecmp (mime, MEDIA_MIMETYPE_AUDIO_AMR_WB )){
Ret = new AMRExtractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_AUDIO_FLAC )){
Ret = new external Extractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_WAV )){
Ret = new WAVExtractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_OGG )){
Ret = new OggExtractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_MATROSKA )){
Ret = new MatroskaExtractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_MPEG2TS )){
Ret = new MPEG2TSExtractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_WVM )){
// Return now. WVExtractor shocould not have the DrmFlag set in the block below.
Return new WVMExtractor (source );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_AUDIO_AAC_ADTS )){
Ret = new AACExtractor (source, meta );
} Else if (! Strcasecmp (mime, MEDIA_MIMETYPE_CONTAINER_MPEG2PS )){
Ret = new MPEG2PSExtractor (source );
}
3. After obtaining the extractor, use setVideoSource () setAudioSource () to generate independent mVideoTrack (video) and mAudioTrack (audio) data streams, which provide the audio and video decoder with their own data streams.
In fact, extractor, mVideoTrack, and mAudioTrack constitute the demuxer part of the player model. The audio and video streams in the encapsulated format are split and sent to the audio and video decoder respectively.
4. The next step is initVideoDecoder () initAudioDecoder (). dependent on the above-generated mVideoTrack (video) and mAudioTrack (audio) data streams. Two audio and video decoder mVideoSource and mAudioSource are generated. Different types match different decoder.
[Cpp]
MVideoSource = OMXCodec: Create (
MClient. interface (), mVideoTrack-> getFormat (),
False, // createEncoder
MVideoTrack,
NULL, flags, USE_SURFACE_ALLOC? MNativeWindow: NULL );
MAudioSource = OMXCodec: Create (
MClient. interface (), mAudioTrack-> getFormat (),
False, // createEncoder
MAudioTrack );
}
MVideoSource and mAudioSource constitute the decoder part of the player model.
Openmax is used for the encoding and decoding in the android system. Openma x is a set of standard interfaces. Each hardware manufacturer can follow this standard to implement it and use its chip features. Then it is provided to the android system for use. Because the hardware codec of most set-top box chips is its advantage, this advantage can be fully integrated into the android platform. Hard decoding of HD videos on mobile phones will also be a trend in the future.
5. The decoded data will be output. AwesomePlayer uses mVideoRenderer for video output and mAudioPlayer for audio output respectively. They call android image and audio services respectively. These two parts are very important in the android platform and will be further understood in the future.
MVideoRenderer and mAudioPlayer constitute the output part of the player.
In summary, the overall framework and process of AwesomePlayer are clear. In fact, it cannot be separated from DataSource, demux, decoder, and output. Next, we will learn how each part is implemented.