ffplayer——视频解码线程startThread(start)

xiaoxiao2021-02-28  23

FFMPlayer::start()会调用enqueueMessage(new MessageStart(NULL));创建类型为CMD_START的meg,然后将该meg放入mQueue。

根据meg的类型会调用FFMPlayer::doStart(),该函数会调用SAFE_CALL_STARTASYNC(mDecoderVideo);即DecoderVideo::startAsync()。

class DecoderVideo : public IDecoder class IDecoder : public PlayerThread DecoderVideo::startAsync()调用了IDecoder::startAsync(); IDecoder::startAsync()调用了PlayerThread::startAsync(); PlayerThread::startAsync()调用了startThread() void PlayerThread::startAsync() { mThreadStatus = pthread_create(&mThread, NULL, startThread, this);//创建PlayerThread::mThread;//startThread线程 } void* PlayerThread::startThread(void* ptr) { PlayerThread* thread = (PlayerThread *) ptr; ALOGD("%s:starting thread",thread->threadname); thread->mRunning = true; thread->notify(); thread->handleRun(ptr); thread->mRunning = false; ALOGD("%s:thread ended",thread->threadname); return NULL; } void PlayerThread::handleRun(void* ptr) { } void IDecoder::handleRun(void* ptr) { if (!prepare()) { ALOGE("Couldn't prepare decoder"); return; } decode(ptr); } bool IDecoder::decode(void* ptr) { return false; } bool IDecoder::prepare() { return false; } bool DecoderVideo::decode(void* ptr) { while (mRunning) { switch (mState) { case DECODE_PLAY: { if (!pPacket.size) { ret = mQueue->get(&pPacket, false);//从队列中取一个包放入pPacket } //主要部分process() if (!process(&pPacket,VIDEO_READ_LEFT_EYE_DATA,ret)) break; } return true; } bool DecoderVideo::process(AVPacket *packet,int direct,int needDecode) { AVCodecContext *avctx = NULL; // Decode video frame if (mHwdecFlag) {//硬解 if (!Hwdec(packet,direct,needDecode)) {//主要过程Hwdec(), 链接到mpp,主要为decode_sendstream、decode_getframe } else {//软解 if(mNeedKeyFrame){ if((packet->flags & AV_PKT_FLAG_KEY) == 0){ checkVideoEnd(); packet->size =0; ALOGE("%s: need key frame",__FUNCTION__); }else{ mNeedKeyFrame = false; return Sfdec(packet,direct,needDecode); } }else{ return Sfdec(packet,direct,needDecode);//主要过程Sfdec(), 链接到ffmpeg } } return true; } bool DecoderVideo::Sfdec(AVPacket *packet, int direct, int needDecode) { if (!noFfmeg_codecsupport) { pthread_mutex_lock(&mMutex); avcodec_decode_video2(mStream->codec,mFrame,&completed,packet);//链接到ffmpeg if (completed) { onDecode((void*)mFrame,direct,pts,rawPts,SW,mparm); } } return true; }

问题:怎么从PlayerThread::handleRun到IDecoder::handleRun; 怎么从IDecoder::handleRun中的IDecoder::decode到DecoderVideo::decode 多态 onDecode() 回调函数,调用FFMPlayer::decodeVideo()

class DecoderVideo : public IDecoder class IDecoder : public PlayerThread

在mpp中mpp_list mFrames;//用于存放解码好的待输出的图像的链表,怎么与Vector

转载请注明原文地址: https://www.6miu.com/read-2603179.html

最新回复(0)