How to Create a nuplayer in ics4.0.3

Source: Internet
Author: User

In ics4.0.3, the player framework used for playing RTSP Streaming Media is nuplayer. Now, we will analyze the process for creating nuplayer.

1. How to Create a nulayer

In the nuplayerdriver: nuplayerdriver () constructor:
1.1 create a alogue object mlodio and call the mlooper-> Start function. The priority is priority_audio.
In the alogue: Start function, the alogue: loop () function is cyclically executed. In the loop function, the glooperroster. delivermessage function is called,
Then, call the Handler-> onmessagereceived function in the alooperroster: delivermessag function, and finally execute the onmessagereceived function in the sub-struct of ahandler,
Process specific messages. For example, the onmessagereceived function of myhandler is used to process RTSP messages.
1.2 create a nuplayer object mplayer and call mlow.registerhandler to register mplayer to the global variable glooperroster's mhandlers member vector.
All ahandler objects must be registered to the mhandlers member of the global variable glooperroster.

2. nuplayer: The process of start processing is in the following order:
2.1 mediaplayer: Start ()-> mediaplayerservice: Client: Start ()->
2.2 nuplayerdriver: Start ()
In nuplayerdriver: setdatasource, The mstate is set to stopped. Therefore, mplayer-> Start () is executed in the Start function and called to the nuplayer: Start () function.
2.3 nuplayer: Start ()
Send kwhatstart messages
2.4 nuplayer: onmessagereceived processing of kwhatstart messages
2.4.1 after receiving the kwhatstart message, assign an initial value to some variables and call the msource-> Start () function. For the RTSP stream, call nuplayer: rtspsource: Start () function
2.4.1.1 nuplayer: rtspsource: Start ()
(1) Create the alogue object mlooper and call the mlooper-> setname ("RTSP") and mloname-> Start () functions.
(2) Create the ahandlerreflector <rtspsource> Object mreflector, and call mloctor-> registerhandler to register mreflector to the mhandlers member of the global variable glooperroster.
The role of ahandlerreflector is unclear for the moment. It seems that the rtspsource is specified to receive messages.
(3) create the message kwhaty y and use it as the parameter of myhandler. The kwhatnotify message is processed in the nuplayer: rtspsource: onmessagereceived function.
(4) Create the myhandler object mhandler and register it with the mhandlers member of glooperroster.
(5) execute mhandler-> connect (), link to the server, and set the mstate to connecting.
Call the connect function of artspconnection to process the connection server.
2.4.2 create the Renderer object mrenderer, send the kwhatrenderernotify message, and register the mrenderer to the mhandlers member of the global variable glooperroster.
The Renderer constructor simply assigns default values to the variables without any additional processing.
2.4.3 call the postscansources () function to initialize the decoder of audio/video.
(1) The message kwhatscansources is sent in the nuplayer: postscansources () function.

2.5 nuplayer: onmessagereceived processing of kwhatscansources messages
2.5.1 call the instantiatedecoder function to initialize the video and audio decoder.

    instantiateDecoder(false, &mVideoDecoder);    if (mAudioSink != NULL) {        instantiateDecoder(true, &mAudioDecoder);    }

2.5.2 nuplayer: instantiatedecoder
(1) When the audio decoder is initialized, kwhataudionoloud messages are sent.
When initializing the video decoder, send the kwhatvideonoworkflow message.
(2) the decoder object of the initial decoder is decoder and registered to the mhandlers member of the global variable glooperroster.

* Decoder = audio? New Decoder (incluy): New Decoder (incluy, mnativewindow); // when video is enabled, set the native1_wwrapper parameter Looper ()-> registerhandler (* decoder); (* decoder) -> Configure (Meta); // call the configure method of decoder to initialize the acodec decoder.

2.5.3 nuplayer: decoder: Configure
(1) create a message kwhatcodecnotify for the acodec object mcodec notification message
(2) Call the makeformat function to create the corresponding message format based on the meta type.
(3) create an acodec object mcodec,
(4) During video decoding, create the alogue object mcodecloers to release the main message event queue and register it with the mhandlers member of the global variable glooperroster.
Set the name of mcodecloder to "nuplayerdecoder"

2.6 nuplayer: onmessagereceived
Case kwhatvideonoloud:
Case kwhataudionoloud:

Obtain the "what" value corresponding to the amessage message "codec-request", and handle the following situations respectively.
2.6.1 acodec: kwhatfillthisbuffer
Run the feeddecoderinputdata function to obtain a valid buffer.

2.6.2 acodec: kwhateos
Send an EOS message to render
Mrenderer-> queueeos (audio, err );

2.6.3 acodec: kwhatflushcompleted
(1) set mflushingaudio or mflushingvideo to flushed or shutting_down_decoder status.
(2) Call the finishflushifpossible () function to perform some flush operations, such:
Mrenderer-> signaltimediscontinuity ();
Maudiodecoder-> signalresume ();
Mvideodecoder-> signalresume ();
Finishreset ();
If maudiodecoder = NULL | mvideodecoder = NULL, The postscansources () function is executed to initialize the decoder of the audio/video decoder.

2.6.4 acodec: kwhatoutputformatchanged

2.6.5 acodec: kwhatshutdowncompleted

2.6.6 acodec: kwhaterror

2.6.7 acodec: kwhatdrainthisbuffer // sent in acodec: basestate: onomxfillbufferdone
Call renderbuffer (audio, codecrequest) to put the data to be decoded into the render queue.

2.7 nuplayer: renderbuffer
First check and discard the data to be skipped.
Call mrenderer-> queuebuffer (audio, buffer, reply); to put the data to be decoded into the Renderer queue

2.8 nuplayer: Renderer: queuebuffer
Send kwhatqueuebuffer messages

    sp<AMessage> msg = new AMessage(kWhatQueueBuffer, id());    msg->setInt32("audio", static_cast<int32_t>(audio));    msg->setObject("buffer", buffer);    msg->setMessage("notifyConsumed", notifyConsumed);    msg->post();

2.9 nuplayer: Renderer: onmessagereceived
Case kwhatqueuebuffer:
--->
Nuplayer: Renderer: onqueuebuffer
Call the postdrainvideoqueue function during video
--->
Nuplayer: Renderer: postdrainvideoqueue ()
Send the kwhatdrainvideoqueue message. The message delay time is delayus.

++ Variable annotation ++

Manchortimemediaus indicates the media time of audio mediatimeus. The initial value is-1 manchortimemediaus = mediatimeus; int64_t realtimeoffsetus = (maudiosink-> latency () /2/* XXX */+ numframespendingplayout * maudiosink-> msecsperframe () * 1000ll; // Logi ("realtimeoffsetus = % LLD us", realtimeoffsetus); usage = alohas :: getnowus () + realtimeoffsetus; manchortimerealus indicates the time when audio data has been processed (including played and to be played. If there is no audio, it is the current system time manchortimerealus = alogue: getnowus ();

++
--->
Nuplayer: Renderer: onmessagereceived
Case kwhatdrainvideoqueue:
Call ondrainvideoqueue () for processing
Continue to call the postdrainvideoqueue function and process the next buffer in a loop
--->

Nuplayer: Renderer: ondrainvideoqueue () // send a message indicating that the buffer has processed entry-> mpolicyconsumed-> setint32 ("render ",! Toolate); entry-> mnotifyconsumed-> post (); mvideoqueue. Erase (mvideoqueue. Begin (); entry = NULL; policyposition ();

Bytes --------------------------------------------------------------------------------------------------
* ************** Start ****************

Nuplayer: instantiatedecoder
Create a decoder object and then call
(* Decoder)-> Configure (Meta );
--->
Nuplayer: decoder: Configure
Call mcodec-> initiatesetup (format );
--->
Acodec: initiatesetup
Send kwhatsetup messages
--->
Acodec: uninitializedstate: onmessagereceived
Case acodec: kwhatsetup:
Call onsetup (MSG );
--->

ACodec::UninitializedState::onSetupstatus_t err = omx->allocateNode(componentName.c_str(), observer, &node);

--->
OMX: allocatenode
Creates an omxnodeinstance object and registers the omxnodeinstance: kcallbacks callback.
--->

// Staticomx_callbacktype omxnodeinstance: kcallbacks ={& onevent, & onemptybufferdone, & onfillbufferdone // registers the callback function onfillbufferdone };

--->

Using omxnodeinstance: Using (omx_in using hcomponent, omx_in omx_ptr pappdata, omx_in using * pbuffer) {omxnodeinstance * instance = static_cast <omxnodeinstance *> (pappdata); If (instance-> mdying) {return omx_errornone;} return instance-> owner ()-> onfillbufferdone (instance-> nodeid (), pbuffer); // omxnodeinstance contains OMX member variable OMX * mowner ;}

--->
OMX: onfillbufferdone
Set msg. type = omx_message: fill_buffer_done; and send
--->

ACodec::BaseState::onOMXMessage    case omx_message::FILL_BUFFER_DONE:        return onOMXFillBufferDone(                            bufferID,                            (size_t)rangeOffset, (size_t)rangeLength,                            (OMX_U32)flags,                            timeUs,                            platformPrivate,                            dataPtr);

--->

Acodec: basestate: onomxfillbufferdone portmode mode = getportmode (kportindexoutput); Switch (mode) {Case keep_buffers: break; Case resubmit_buffers: Set send message interval y-> setint32 ("what ", acodec: kwhatdrainthisbuffer );

* ************** End ****************

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.