ffplayer——FFMPlayer::start() FFMPlayer::stop()

xiaoxiao2021-02-28  16

status_t FFMPlayer::start() { int status = getCurrentStatus(); if (status == PLAYER_PREPARED) { if (mMessageQ.get() != NULL) { enqueueMessage(new MessageStart(NULL)); //创建类型为CMD_START的meg,然后将该meg放入mQueue return OK; } } else { //if(status == PLAYER_PAUSED) if(!isNetworkProtocol() && isPlayerEndOfStream() && checkConsumeAll()) { ALOGD("resume: end of stream seekto 0"); modifyFlags(AT_EOS, CLEAR); setPlayerEndOfStream(false); doSeekto(0, true); } recordResumeTime(); return resume();//创建类型为CMD_RESUME的meg,然后将该meg放入mQueue } return UNKNOWN_ERROR; } MessageStart(complete_cb cb):RkMessage(CMD_START,cb) {}; RkMessage(int t,complete_cb cb,void* userdata=0):mType(t),mCb(cb),mUserData(userdata),mWhenUs(0) {} status_t FFMPlayer::doStart() { if (getCurrentStatus() == PLAYER_PREPARED) { setCurrentStatus(PLAYER_STARTED); modifyFlags(FIRST_FRAME, SET); modifyFlags(PLAYING, SET); if(mNoBlankDisplay){ allocDecoderBuffer(mNewAllocMode); } RECSTACK3(CALLSTACK_ID_SWITCH_CH, "AllocBuffer", GetNowUs()); SAFE_CALL_START(mAudioPlayer); if (pfrmanager) { pfrmanager->start(this); pfrmanager->play(); } SAFE_CALL_STARTASYNC(mDecoderVideo);//启动视频解码线程 ALOGD("doStart(): mSeekTimeUs = %lld",mSeekTimeUs); if (mSeekTimeUs >= 0) { if (mHevcTsFlag == true) { doSeekto(0, true); } else { doSeekto(mSeekTimeUs); } } } else { return INVALID_OPERATION; } ALOGD("doStart ok"); return OK; } status_t FFMPlayer::resume() { if(mSeekToDuration) {//mSeekToDuration为1时 ALOGE("resume: already seek to eof, don't resume"); return NO_ERROR; } enqueueMessage(new MessageResume(NULL, OP_UI));//创建类型为CMD_RESUME的meg,然后将该meg放入mQueue return NO_ERROR; } status_t FFMPlayer::stop() { int status = getCurrentStatus(); if (status == PLAYER_STOPPED) { return NO_ERROR; } if ((status == PLAYER_PREPARING)||(status == PLAYER_PREPARED) || (status == PLAYER_STARTED) ||(status == PLAYER_PAUSED) || (status == PLAYER_PLAYBACK_COMPLETE) || !mPlayer_sisExited) { stop_l(); } return NO_ERROR; } status_t FFMPlayer::stop_l() { //1.创建创建类型为CMD_STOP的meg,然后将该meg放入mQueue enqueueMessage(new MessageStop(NULL)); //MessageStop(complete_cb cb):RkMessage(CMD_STOP,cb) {}; ALOGD("doRelease() clearQueue************"); if (mMessageQ.get() != NULL) { mMessageQ->clearQueue();//2.清空mMessageQ,相当于清空mQueue } ALOGD("stop_l:MessageStop down"); dumpStatus(); if (mMediaSource != NULL) { mMediaSource->setExit(true); } ALOGD("stop_l : create CancelThread"); if (mCancelThreadStatus < 0) { Mutex::Autolock l(mCancelThreadLock); mCancelThreadStatus = pthread_create(&mCancelThread, NULL, CancelThread, (void*)this);//3.创建CancelThread线程 mCancelThreadCond.wait(mCancelThreadLock); } ALOGD("stop_l :CancelThread create ok"); if (mBufferingStatus >= 0) { int ret = 0; if ((ret=pthread_join(mBufferingThread, NULL)) != 0) {//4.等待线程mBufferingThread结束 ALOGE("Couldn't cancel onBuffering player thread ret=%s", strerror(ret)); } mBufferingStatus = -1; } ALOGD("stop_l buffer thread quit"); mPlayer_sisExited = true; return OK; } void* FFMPlayer::CancelThread(void* ptr) { FFMPlayer *player = (FFMPlayer *)ptr; ALOGD("CancelThread start"); if (player->mReadThreadStatus >= 0) { if (pthread_join(player->mReadThread, NULL) != 0) {//1.等待线程mReadThread结束 ALOGE("Couldn't cancel mReadThread"); } player->mReadThreadStatus = -1; AUTO_LOCK_BEGIN(player->mMsgQueueLock); if (player->mMessageQ.get() != NULL && player->mPlayer_sisExited) { player->mMsgQueueCond.wait(player->mMsgQueueLock); } AUTO_LOCK_END(player->mMsgQueueLock); player->closeContext();//2.调用MediaSource->close(); ALOGD("CancelThread end"); } SAFE_DELETE(player->pfrmanager);//3.删除pfrmanager player->doInit();//4.player回到最初状态 ALOGD("CancelThread return"); return NULL; }
转载请注明原文地址: https://www.6miu.com/read-2630987.html

最新回复(0)