|
|
|
@ -143,6 +143,7 @@ bool videoAVLIBSource::_close(void){ |
|
|
|
|
|
|
|
if ( m_pVideoState == NULL) return true; |
|
|
|
|
|
|
|
m_pMediaDestination = NULL;//??
|
|
|
|
//_stop(); //stops the Thread
|
|
|
|
basicThread::waitThreadEnd( true ); |
|
|
|
|
|
|
|
@ -801,42 +802,32 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_STOPED; |
|
|
|
while( m_pMediaDestination == NULL && m_bThreadStatus == TH_WORKING ){ |
|
|
|
SLEEP(20); |
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef DEBUG_EXTRA
|
|
|
|
LOG("Waiting Destination"); |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_PRESENT; |
|
|
|
if( m_bSrcType == AVLIB_SOURCE_IPSTREAM ){ |
|
|
|
//av_read_play( m_pVideoState->m_pFormatCtx );
|
|
|
|
av_read_play( m_pVideoState->m_pFormatCtx ); |
|
|
|
}; |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Presentation Started."); |
|
|
|
#endif
|
|
|
|
while( m_pVideoState->m_bStatus < MS_CLOSING && m_bThreadStatus != TH_ENDED ){ |
|
|
|
//LOG("1");
|
|
|
|
if ( m_pMediaDestination != NULL ){ |
|
|
|
//LOG("2");
|
|
|
|
dec_ret = av_read_frame( m_pVideoState->m_pFormatCtx, pPacket ); |
|
|
|
//LOG("3");
|
|
|
|
if( dec_ret >= 0 ){ |
|
|
|
//LOG("4");
|
|
|
|
if( pPacket->stream_index == m_pVideoState->m_iVideoStreamID ){ |
|
|
|
//LOG("5");
|
|
|
|
m_pVideoState->m_bStatus = MS_PRESENT; |
|
|
|
dec_ret = avcodec_send_packet( m_pVideoState->m_pCodecCtx, pPacket ); |
|
|
|
//LOG("6");
|
|
|
|
if( dec_ret < 0 && dec_ret != AVERROR(EAGAIN) /* && dec_ret != AVERROR_EOF */ ){ |
|
|
|
LOG_ERROR( "Error sending video package to decoder" ); |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_CLOSING; |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
} else { |
|
|
|
//LOG("7");
|
|
|
|
while( dec_ret >= 0 && m_bThreadStatus != TH_ENDED ) { |
|
|
|
//LOG("8");
|
|
|
|
dec_ret = avcodec_receive_frame( m_pVideoState->m_pCodecCtx, pFrame ); |
|
|
|
//LOG("9");
|
|
|
|
if( dec_ret == AVERROR(EAGAIN) || dec_ret == AVERROR_EOF ){ |
|
|
|
//LOG("S");
|
|
|
|
break;//Skip to next data
|
|
|
|
} else if( dec_ret < 0 ){ |
|
|
|
LOG_ERROR("Error decoding video frame"); |
|
|
|
@ -844,21 +835,17 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
break; |
|
|
|
}; |
|
|
|
//LOG("10");
|
|
|
|
sws_scale( m_pVideoState->m_pSwsCtx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, m_pVideoState->m_pCodecCtx->height, pFrameBGR->data, pFrameBGR->linesize ); |
|
|
|
//LOG("11");
|
|
|
|
try{ |
|
|
|
//sprintf( tB, "Try to copy %d[%dx%d] bytes to %d[%dx%d]", pFrameBGR->linesize[0] * m_nHeight, pFrameBGR->width, pFrameBGR->height, mRGB.total() * mRGB.elemSize(), mRGB.cols, mRGB.rows );
|
|
|
|
//LOG(tB);
|
|
|
|
memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nOutHeight ); |
|
|
|
//LOG("P");
|
|
|
|
if(!m_pMediaDestination->pushFrame( mRGB, m_pOpaque )){ |
|
|
|
m_pMediaDestination = NULL; |
|
|
|
LOG_ERROR("Error Consume Frame by Media Destination!"); |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_CLOSING; |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
if ( m_pMediaDestination ) { |
|
|
|
memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nOutHeight ); |
|
|
|
if (!m_pMediaDestination->pushFrame(mRGB, m_pOpaque)) { |
|
|
|
m_pMediaDestination = NULL; |
|
|
|
LOG_ERROR("Error Consume Frame by Media Destination!"); |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_CLOSING; |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
}; |
|
|
|
}; |
|
|
|
//LOG("14");
|
|
|
|
} catch (cv::Exception & e) { |
|
|
|
LOG_ERROR( e.msg.c_str() ); |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_CLOSING; |
|
|
|
|