diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index ad8d1aa3..3c6292d6 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -28,9 +28,13 @@ static void *thread_hal(void *data) { - //Mpp *mpp = (Mpp*)data; + Mpp *mpp = (Mpp*)data; + MppThread *thd_dec = mpp->thd_codec; + MppThread *thd_hal = mpp->thd_hal; + mpp_list *packets = mpp->packets; + mpp_list *frames = mpp->frames; - while (0) { + while (MPP_THREAD_RUNNING == thd_hal->get_status()) { /* * hal thread wait for dxva interface intput firt */ @@ -53,6 +57,8 @@ static void *thread_hal(void *data) // signal() // mark frame in output queue // wait up output thread to get a output frame + + msleep(10); } return NULL; @@ -61,12 +67,14 @@ static void *thread_hal(void *data) static void *thread_dec(void *data) { Mpp *mpp = (Mpp*)data; - mpp_list *packets = mpp->packets; - mpp_list *frames = mpp->frames; + MppThread *thd_dec = mpp->thd_codec; + MppThread *thd_hal = mpp->thd_hal; + mpp_list *packets = mpp->packets; + mpp_list *frames = mpp->frames; MppPacketImpl packet; MppFrame frame; - while (mpp->thread_codec_running) { + while (MPP_THREAD_RUNNING == thd_dec->get_status()) { if (packets->list_size()) { /* * packet will be destroyed outside, here just copy the content diff --git a/osal/mpp_thread.cpp b/osal/mpp_thread.cpp index 27a44320..b6732464 100644 --- a/osal/mpp_thread.cpp +++ b/osal/mpp_thread.cpp @@ -61,11 +61,13 @@ void MppThread::start() pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (MPP_THREAD_UNINITED == mStatus) { - if (0 == pthread_create(&mThread, &attr, mFunction, mContext)) { - mStatus = MPP_THREAD_RUNNING; + // NOTE: set status here first to avoid unexpected loop quit racing condition + mStatus = MPP_THREAD_RUNNING; + if (0 == pthread_create(&mThread, &attr, mFunction, mContext)) thread_dbg(MPP_THREAD_DBG_FUNCTION, "mThread %p mContext %p create success\n", mFunction, mContext); - } + else + mStatus = MPP_THREAD_UNINITED; } pthread_attr_destroy(&attr); }