|
|
|
@ -385,7 +385,11 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i |
|
|
|
char Buffer[1024] = {0}; |
|
|
|
char tChar[128] = {0}; |
|
|
|
strncpy( m_pVideoState->m_pFileName, URI, MAX_PATH_LEN ); |
|
|
|
sprintf( m_pCookie, "%s", MD5String(m_pVideoState->m_pFileName) ); |
|
|
|
CSTR tMD5 = MD5String(m_pVideoState->m_pFileName ); |
|
|
|
if ( tMD5 ) { |
|
|
|
sprintf( m_pCookie, "%s", tMD5 ); |
|
|
|
free( tMD5 ); |
|
|
|
} else sprintf( m_pCookie, "some-random-id" ); |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_OPENING; |
|
|
|
|
|
|
|
if( strncmp( m_pVideoState->m_pFileName, "video=", 6 ) == 0 ){ |
|
|
|
@ -788,44 +792,42 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
*/ |
|
|
|
|
|
|
|
m_bThreadStatus = TH_WORKING; |
|
|
|
pPacket = (AVPacket *) av_malloc( sizeof(AVPacket) ); |
|
|
|
if ( pPacket == NULL ) { |
|
|
|
|
|
|
|
AVPacket Packet; |
|
|
|
av_init_packet( &Packet ); // Optional in newer API
|
|
|
|
Packet.data = NULL; |
|
|
|
Packet.size = 0; |
|
|
|
pFrame = av_frame_alloc(); |
|
|
|
if ( pFrame == NULL ) { |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
LOG_ERROR("Error allocating AVPacket!"); |
|
|
|
LOG_ERROR("Error allocating SRC AVFrame!"); |
|
|
|
} else { |
|
|
|
av_init_packet( pPacket ); |
|
|
|
pFrame = av_frame_alloc(); |
|
|
|
if ( pFrame == NULL ) { |
|
|
|
pFrameBGR = av_frame_alloc(); |
|
|
|
if ( pFrameBGR == NULL ) { |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
LOG_ERROR("Error allocating SRC AVFrame!"); |
|
|
|
LOG_ERROR("Error allocating BGR AVFrame!"); |
|
|
|
} else { |
|
|
|
pFrameBGR = av_frame_alloc(); |
|
|
|
if ( pFrameBGR == NULL ) { |
|
|
|
dec_ret = av_image_alloc( pFrameBGR->data, pFrameBGR->linesize, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, BUFFER_ALIGN ); |
|
|
|
sprintf( tB, "Allocated: %d bytes to Frame", dec_ret ); |
|
|
|
LOG( tB ); |
|
|
|
if ( dec_ret < 0 ) { |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
LOG_ERROR("Error allocating BGR AVFrame!"); |
|
|
|
LOG_ERROR("Error allocating BGR AVFrame Buffer!"); |
|
|
|
} else { |
|
|
|
dec_ret = av_image_alloc ( pFrameBGR->data, pFrameBGR->linesize, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, BUFFER_ALIGN ); |
|
|
|
sprintf( tB, "Allocated: %d bytes to Frame", dec_ret ); |
|
|
|
LOG( tB ); |
|
|
|
if ( dec_ret < 0 ) { |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
LOG_ERROR("Error allocating BGR AVFrame Buffer!"); |
|
|
|
} else { |
|
|
|
//pBGRbuffer = (uint8_t *) av_malloc( av_image_get_buffer_size( AV_PIX_FMT_BGR24, m_nWidth , m_nHeight , BUFFER_ALIGN ));
|
|
|
|
//if ( pBGRbuffer == NULL ) {
|
|
|
|
// m_bThreadStatus = TH_ENDED;
|
|
|
|
// LOG_ERROR("Error allocating BGR AVFrame Buffer!");
|
|
|
|
//} else {
|
|
|
|
// av_image_fill_arrays ( pFrameBGR->data, pFrameBGR->linesize, pBGRbuffer, AV_PIX_FMT_BGR24, m_nWidth, m_nHeight, BUFFER_ALIGN );
|
|
|
|
//
|
|
|
|
// pFrameBGR->width = m_nWidth;
|
|
|
|
// pFrameBGR->height = m_nHeight;
|
|
|
|
// m_pVideoState->m_bStatus = MS_ALOCATED;
|
|
|
|
//pBGRbuffer = (uint8_t *) av_malloc( av_image_get_buffer_size( AV_PIX_FMT_BGR24, m_nWidth , m_nHeight , BUFFER_ALIGN ));
|
|
|
|
//if ( pBGRbuffer == NULL ) {
|
|
|
|
// m_bThreadStatus = TH_ENDED;
|
|
|
|
// LOG_ERROR("Error allocating BGR AVFrame Buffer!");
|
|
|
|
//} else {
|
|
|
|
// av_image_fill_arrays ( pFrameBGR->data, pFrameBGR->linesize, pBGRbuffer, AV_PIX_FMT_BGR24, m_nWidth, m_nHeight, BUFFER_ALIGN );
|
|
|
|
//
|
|
|
|
// pFrameBGR->width = m_nWidth;
|
|
|
|
// pFrameBGR->height = m_nHeight;
|
|
|
|
// m_pVideoState->m_bStatus = MS_ALOCATED;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Video Reader Thread Started."); |
|
|
|
LOG("Video Reader Thread Started."); |
|
|
|
#endif
|
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -847,11 +849,11 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
#endif
|
|
|
|
while( m_pVideoState->m_bStatus < MS_CLOSING && m_bThreadStatus != TH_ENDED ){ |
|
|
|
if ( m_pMediaDestination != NULL ){ |
|
|
|
dec_ret = av_read_frame( m_pVideoState->m_pFormatCtx, pPacket ); |
|
|
|
dec_ret = av_read_frame( m_pVideoState->m_pFormatCtx, &Packet ); |
|
|
|
if( dec_ret >= 0 ){ |
|
|
|
if( pPacket->stream_index == m_pVideoState->m_iVideoStreamID ){ |
|
|
|
if( Packet.stream_index == m_pVideoState->m_iVideoStreamID ){ |
|
|
|
m_pVideoState->m_bStatus = MS_PRESENT; |
|
|
|
dec_ret = avcodec_send_packet( m_pVideoState->m_pCodecCtx, pPacket ); |
|
|
|
dec_ret = avcodec_send_packet( m_pVideoState->m_pCodecCtx, &Packet ); |
|
|
|
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; |
|
|
|
@ -888,6 +890,7 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
av_packet_unref( &Packet ); |
|
|
|
} else if( dec_ret != AVERROR(EAGAIN) && dec_ret != AVERROR_EOF ){ |
|
|
|
LOG_ERROR( "Error reading video package" ); |
|
|
|
char tBuffer[1024]; |
|
|
|
@ -907,10 +910,7 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
}; |
|
|
|
}; |
|
|
|
//m_pVideoState->m_bStatus = MS_STOPED;
|
|
|
|
SLEEP( 5 ); |
|
|
|
}; |
|
|
|
av_packet_unref( pPacket ); |
|
|
|
SLEEP( 5 ); |
|
|
|
} else SLEEP( 5 ); |
|
|
|
}; |
|
|
|
@ -920,10 +920,11 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
if ( pFrame != NULL ) { |
|
|
|
av_frame_free( &pFrame ); |
|
|
|
}; |
|
|
|
if ( pPacket != NULL ) { |
|
|
|
av_free( pPacket ); |
|
|
|
if ( pFrameBGR ) { |
|
|
|
if( pFrameBGR->data[0] ) av_freep(&pFrameBGR->data[0]); |
|
|
|
av_frame_free( &pFrameBGR ); |
|
|
|
}; |
|
|
|
if( pBGRbuffer != NULL ) { |
|
|
|
if (pBGRbuffer != NULL) { |
|
|
|
av_free( pBGRbuffer ); |
|
|
|
}; |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
|