1. nuplayerdriver: reset ()
Mplayer-> resetasync (); // execute Asynchronous Reset while (mresetinprogress) {// wait for the reset to complete. If the reset is not completed in 5 seconds, ANR mcondition. Wait (mlock) will appear );}
2. nuplayer: resetasync ()
Send kwhatreset messages
3. kwhatreset Message Processing
Nuplayer: onmessagereceived
Case kwhatreset:
(1) If mflushingaudio or mflushingvideo is in awaiting_discontinuity status, run
mRenderer->resume(); if (mRenderer != NULL) { // There's an edge case where the renderer owns all output // buffers and is paused, therefore the decoder will not read // more input data and will never encounter the matching // discontinuity. To avoid this, we resume the renderer. if (mFlushingAudio == AWAITING_DISCONTINUITY || mFlushingVideo == AWAITING_DISCONTINUITY) { mRenderer->resume(); } }
(2) If flushing is in progress, the reset execution will be postponed.
If (mflushingaudio! = None | mflushingvideo! = None) {// we're currently flushing, postpone the reset until that's // completed. logv ("postponing reset mflushingaudio = % d, mflushingvideo = % d", mflushingaudio, mflushingvideo); mresetpostponed = true ;}
(3) If maudiodecoder = NULL & mvideodecoder = NULL, it indicates that the reset has been executed
Finishreset ()
(4) execute the flushdecoder of audio.
(5) execute the flushdecoder of video.
(6) set the variable mresetinprogress to true.
4. nuplayer: finishreset ()
(1) execute msource-> stop ();
(2) execute driver-> notifyresetcomplete ()
If (msource! = NULL) {msource-> stop (); // execute the nuplayer: rtspsource: Stop () function msource. Clear ();} If (mdriver! = NULL) {sp <nuplayerdriver> driver = mdriver. Promote (); If (driver! = NULL) {driver-> policyresetcomplete ();}}
4.1 nuplayer: rtspsource: Stop ()
After the stop function sends a message, the disconnection from the server must be completed in a timely manner. Otherwise, the timeout may cause ANR.
Void nuplayer: rtspsource: Stop () {sp <amessage> MSG = new amessage (kwhatdisconnect, mreflector-> ID (); sp <amessage> dummy; MSG-> postandawaitresponse (& dummy); // finally call the postandawaitresponse function of the global variable glooperroster}
4.2 process kwhatdisconnect messages
Void nuplayer: rtspsource: onmessagereceived (const sp <amessage> & MSG) {If (MSG-> what () = kwhatdisconnect) {uint32_t replyid; check (MSG-> senderawaitsresponse (& replyid); // obtain the replyid mdisconnectreplyid = replyid; finishdisconnectifpossible (); // disconnect the data link with the server and return ;}
4.3 nuplayer: rtspsource: finishdisconnectifpossible
If (mstate! = Disconnected) {mhandler-> disconnect (); // execute the disconnect function of myhandler. H, send the 'abor' message, disconnect the connection with the server, and return ;}
5. nuplayerdriver: notifyresetcomplete ()
If mresetinprogress is set to false, wait for completion in step 1, that is, the reset execution ends.
6. nuplayer: flushdecoder
(audio ? mAudioDecoder : mVideoDecoder)->signalFlush(); mRenderer->flush(audio);
7. nuplayer: decoder: signalflush ()
Call mcodec-> signalflush (); call the signalflush function of acodec.
8. acodec: signalflush ()
Send kwhatflush messages
9. acodec: uninitializedstate: onmessagereceived
Case acodec: kwhatflush:
Send acodec: kwhatflushcompleted message
10. Processing acodec: kwhatflushcompleted messages is in the nuplayer class.
Nuplayer: onmessagereceivedcase kwhatvideonoloud: Case kwhataudionoloud :...} else if (what = acodec: kwhatflushcompleted) {bool needshutdown; If (audio) {check (isflushingstate (mflushingaudio, & needshutdown); response = flushed ;} else {check (isflushingstate (mflushingvideo, & needshutdown); mflushingvideo = flushed; mvideolatebyus = 0;} logv ("decoder % s flush completed", audio? "Audio": "video"); If (needshutdown) {logv ("initiating % s decoder shutdown", audio? "Audio": "video"); // call initiateshudown of the decoder class --> acodec: initiateshudown () --> send kwhatshutdown message --> // then send acodec :: kwhatshutdowncompleted message --> return to this function to process the acodec: kwhatshutdowncompleted message (audio? Maudiodecoder: mvideodecoder)-> initiateshudown (); If (audio) {mflushingaudio = audio;} else {mflushingvideo = audio ;}} parse ();//}...} else if (what = acodec: kwhatshutdowncompleted) {logv ("% s shutdown completed", audio? "Audio": "video"); If (audio) {maudiodecoder. clear (); check_eq (INT) mflushingaudio, (INT) shutting_down_decoder); mflushingaudio = shut_down;} else {mvideodecoder. clear (); check_eq (INT) mflushingvideo, (INT) shutting_down_decoder); mflushingvideo = shut_down;} finishflushifpossible ();//}
11. finishflushifpossible Processing
Void nuplayer: finishflushifpossible () {If (mflushingaudio! = Flushed & mflushingaudio! = Shut_down) {return;} If (mflushingvideo! = Flushed & mflushingvideo! = Shut_down) {return;} logv ("both audio and video are flushed now. "); If (mtimediscontinuitypending) {mrenderer-> signaltimediscontinuity (); // send message response = false;} // nuplayer: decoder: signalresume --> acodec :: signalresume --> send a kwhatresume message --> // acodec: executingstate: resume --> acodec: executingstate: submitoutputbuffers --> // acodec: basestate: queue --> K Whatinputbufferfilled --> // acodec: basestate: oninputbufferfilled if (maudiodecoder! = NULL) {maudiodecoder-> signalresume ();} If (mvideodecoder! = NULL) {mvideodecoder-> signalresume ();} mflushingaudio = none; mflushingvideo = none; If (mresetinprogress) {// 3. (6) logv ("Reset completed"); mresetinprogress = false; finishreset (); // The reset execution is completed. For details, see processing in} else if (mresetpostponed) {// If 3. (2) If a delayed reset is set, the system resends the kwhatreset message (New amessage (kwhatreset, ID ()-> post (); mresetpostponed = false ;} else if (maudiodecoder = NULL | mvideodecoder = NULL) {postscansources ();}}