|
|
|
@ -44,7 +44,7 @@ videoAVLIBSource::videoAVLIBSource( void *opaque ): basicMediaSource(), basicThr |
|
|
|
m_pVideoState->m_pFormatCtx = avformat_alloc_context(); |
|
|
|
|
|
|
|
if (m_pVideoState->m_pFormatCtx == NULL){ |
|
|
|
LOG_ERROR("VideoCodec Context Memory Allocation Error"); |
|
|
|
LOG_ERROR("Video Format Context Memory Allocation Error"); |
|
|
|
return; |
|
|
|
}; |
|
|
|
|
|
|
|
@ -80,7 +80,7 @@ videoAVLIBSource::videoAVLIBSource( char *Source, void *opaque ) : basicMediaSou |
|
|
|
m_pVideoState->m_pFormatCtx = avformat_alloc_context(); |
|
|
|
|
|
|
|
if (m_pVideoState->m_pFormatCtx == NULL){ |
|
|
|
LOG_ERROR("VideoCodec Context Memory Allocation Error"); |
|
|
|
LOG_ERROR("Video Format Context Memory Allocation Error"); |
|
|
|
return; |
|
|
|
}; |
|
|
|
m_pVideoState->m_iVideoStreamID = -1; |
|
|
|
@ -94,30 +94,10 @@ videoAVLIBSource::videoAVLIBSource( char *Source, void *opaque ) : basicMediaSou |
|
|
|
|
|
|
|
videoAVLIBSource::~videoAVLIBSource(){ |
|
|
|
LOG("Destructor"); |
|
|
|
if (m_pVideoState != NULL){ |
|
|
|
if( m_pVideoState->m_bStatus > MS_INIT ){ |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
while (m_pVideoState->m_bStatus == MS_PRESENT) SLEEP( 10 ); |
|
|
|
|
|
|
|
#ifndef _NOAUDIO_
|
|
|
|
if( m_pVideoState->m_pAudioCtx!=NULL ){ |
|
|
|
avcodec_close( m_pVideoState->m_pAudioCtx ); |
|
|
|
//avcodec_free_context(&m_pVideoState->m_pAudioCtx);
|
|
|
|
}; |
|
|
|
#endif
|
|
|
|
if( m_pVideoState->m_pCodecCtx != NULL ){ |
|
|
|
avcodec_close(m_pVideoState->m_pCodecCtx); |
|
|
|
//avcodec_free_context(&m_pVideoState->m_pCodecCtx);
|
|
|
|
}; |
|
|
|
if( m_pVideoState->m_pFormatCtx != NULL ){ |
|
|
|
avformat_close_input(&m_pVideoState->m_pFormatCtx); |
|
|
|
//avformat_free_context(m_pVideoState->m_pFormatCtx);
|
|
|
|
}; |
|
|
|
if( m_pVideoState->m_pSwsCtx != NULL ){ |
|
|
|
sws_freeContext( m_pVideoState->m_pSwsCtx ); |
|
|
|
}; |
|
|
|
av_free(m_pVideoState); |
|
|
|
}; |
|
|
|
if ( m_pVideoState != NULL ){ |
|
|
|
_close(); |
|
|
|
av_free( m_pVideoState ); |
|
|
|
m_pVideoState = NULL; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
@ -166,38 +146,67 @@ bool videoAVLIBSource::setFrameAspectRatio( FrameAspectRatio AspectRatio ){ |
|
|
|
}; |
|
|
|
|
|
|
|
bool videoAVLIBSource::_close(void){ |
|
|
|
|
|
|
|
if (m_pVideoState == NULL) return true; |
|
|
|
|
|
|
|
if (m_pVideoState->m_bStatus < MS_OPENED) return true; |
|
|
|
if (m_pVideoState->m_bStatus == MS_CLOSED) return true; |
|
|
|
_stop(); |
|
|
|
if (m_pVideoState->m_bStatus > MS_ALOCATED){ |
|
|
|
//set Close Status - to prevent continue
|
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_CLOSED; |
|
|
|
|
|
|
|
#ifndef _NOAUDIO_
|
|
|
|
if ( m_pVideoState == NULL) return true; |
|
|
|
|
|
|
|
_stop(); //stops the Thread
|
|
|
|
|
|
|
|
if ( m_pVideoState->m_pFormatOpts ) { |
|
|
|
av_dict_free( &m_pVideoState->m_pFormatOpts ); |
|
|
|
m_pVideoState->m_pFormatOpts = NULL; |
|
|
|
}; |
|
|
|
|
|
|
|
if ( m_pVideoState->m_pFormatCtx ) { |
|
|
|
avformat_close_input( &m_pVideoState->m_pFormatCtx ); |
|
|
|
m_pVideoState->m_iVideoStreamID = -1; |
|
|
|
}; |
|
|
|
|
|
|
|
if( m_pVideoState->m_bStatus > MS_INIT ){ |
|
|
|
|
|
|
|
#if ( LIBAVCODEC_VERSION_MAJOR < 58 ) // && ( LIBAVCODEC_VERSION_MINOR < 50 )
|
|
|
|
#ifndef _NOAUDIO_
|
|
|
|
if (m_pVideoState->m_pAudioCtx != NULL){ |
|
|
|
avcodec_close(m_pVideoState->m_pAudioCtx); |
|
|
|
//avcodec_free_context(&m_pVideoState->m_pAudioCtx);
|
|
|
|
avcodec_free_context(&m_pVideoState->m_pAudioCtx); |
|
|
|
}; |
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if (m_pVideoState->m_pCodecCtx != NULL){ |
|
|
|
avcodec_close(m_pVideoState->m_pCodecCtx); |
|
|
|
//avcodec_free_context(&m_pVideoState->m_pCodecCtx);
|
|
|
|
avformat_close_input(&m_pVideoState->m_pFormatCtx); |
|
|
|
//av_free(m_pVideoState->m_pVideoCodec);
|
|
|
|
m_pVideoState->m_iVideoStreamID = -1; |
|
|
|
}; |
|
|
|
|
|
|
|
#else
|
|
|
|
#ifndef _NOAUDIO_
|
|
|
|
if (m_pVideoState->m_pAudioCtx != NULL){ |
|
|
|
avcodec_close(m_pVideoState->m_pAudioCtx); |
|
|
|
avcodec_free_context(&m_pVideoState->m_pAudioCtx); |
|
|
|
}; |
|
|
|
#endif
|
|
|
|
if (m_pVideoState->m_pCodecCtx != NULL){ |
|
|
|
avcodec_close(m_pVideoState->m_pCodecCtx); |
|
|
|
avcodec_free_context(&m_pVideoState->m_pCodecCtx); |
|
|
|
}; |
|
|
|
#endif
|
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_INIT; |
|
|
|
}; |
|
|
|
|
|
|
|
m_pVideoState->m_bStatus = MS_INIT; |
|
|
|
return true; |
|
|
|
sws_freeContext( m_pVideoState->m_pSwsCtx ); |
|
|
|
|
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
bool videoAVLIBSource::_continue( void ){ |
|
|
|
if( m_pVideoState->m_bStatus == MS_STOPED ){ |
|
|
|
return basicThread::init(); |
|
|
|
}; |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
bool videoAVLIBSource::_stop(void){ |
|
|
|
basicThread::waitThreadEnd( true ); |
|
|
|
return true; |
|
|
|
return basicThread::uninit(); |
|
|
|
}; |
|
|
|
|
|
|
|
//https://www.youtube.com/watch?v=Lu3LZmhC_DY
|
|
|
|
|
|
|
|
bool videoAVLIBSource::_restart( void ){ |
|
|
|
@ -418,6 +427,8 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i |
|
|
|
|
|
|
|
//av_dict_set(&m_pVideoState->m_pFormatOpts, "show_audio_crossbar_connection_dialog", "true", 0);
|
|
|
|
//av_dict_set(&m_pVideoState->m_pFormatOpts, "show_video_crossbar_connection_dialog", "true", 0);
|
|
|
|
|
|
|
|
//AVInputFormat * is Internal Const in CoDec Lib
|
|
|
|
AVInputFormat *iformat = av_find_input_format("dshow"); |
|
|
|
//av_dict_set(&options, "pixel_format", "bgr24", 0);
|
|
|
|
av_dict_set(&m_pVideoState->m_pFormatOpts, "timeout", "5000", 0); |
|
|
|
@ -428,8 +439,8 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i |
|
|
|
//avdevice_free_list_devices(&device_list);
|
|
|
|
|
|
|
|
if( avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, iformat, &m_pVideoState->m_pFormatOpts) != 0 ){ |
|
|
|
av_dict_free(&m_pVideoState->m_pFormatOpts); |
|
|
|
//av_free( iformat );
|
|
|
|
av_dict_free( &m_pVideoState->m_pFormatOpts ); |
|
|
|
m_pVideoState->m_pFormatOpts = NULL; |
|
|
|
sprintf(Buffer, "VideoSource Couldn't open input device: %s", URI); |
|
|
|
LOG_ERROR(Buffer); |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_INIT; |
|
|
|
@ -510,7 +521,8 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i |
|
|
|
int RetVal = 0; |
|
|
|
//LOG("Before Open1");
|
|
|
|
if( ( RetVal = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, NULL, &m_pVideoState->m_pFormatOpts) ) != 0 ){ |
|
|
|
//av_dict_free(&options);
|
|
|
|
av_dict_free( &m_pVideoState->m_pFormatOpts); |
|
|
|
m_pVideoState->m_pFormatOpts = NULL; |
|
|
|
char tBuffer[1024]; |
|
|
|
av_strerror( RetVal, tBuffer, 1024 ); |
|
|
|
sprintf(Buffer, "VideoSource Couldn't open input stream[%s](Code:%d): %s", tBuffer, RetVal, m_pVideoState->m_pFileName ); |
|
|
|
@ -523,6 +535,7 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i |
|
|
|
sprintf(Buffer, "Option %s not recognized by the demuxer", e->key); |
|
|
|
LOG_ERROR(Buffer); |
|
|
|
}; |
|
|
|
// e is pointer to entry!
|
|
|
|
//av_dict_free( &e );
|
|
|
|
}; |
|
|
|
|
|
|
|
@ -562,18 +575,20 @@ bool videoAVLIBSource::_open( char *URI, bool ShowDeviceMenu, float framerate, i |
|
|
|
LOG_ERROR( "Didn't find a video stream."); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
// Video Stream found
|
|
|
|
m_pVideoState->m_pCodecCtx = m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iVideoStreamID]->codec; |
|
|
|
// Static pointer
|
|
|
|
m_pVideoState->m_pVideoCodec = avcodec_find_decoder( m_pVideoState->m_pCodecCtx->codec_id ); |
|
|
|
|
|
|
|
# ifndef _NOAUDIO_
|
|
|
|
if( m_pVideoState->m_iAudioStreamID == -1 ){ |
|
|
|
LOG_ERROR("Didn't find a audio stream."); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
//ToDo: Bind Audio Codec
|
|
|
|
# endif
|
|
|
|
|
|
|
|
// Stream found
|
|
|
|
m_pVideoState->m_pCodecCtx = m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iVideoStreamID]->codec; |
|
|
|
//m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iVideoStreamID]->codecpar->codec_id
|
|
|
|
m_pVideoState->m_pVideoCodec = avcodec_find_decoder( m_pVideoState->m_pCodecCtx->codec_id ); |
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
# ifdef DEBUG_EXTRA
|
|
|
|
LOG("YABABA-2!"); |
|
|
|
@ -889,8 +904,8 @@ void videoAVLIBSource::m_fThreadProc( void ){ |
|
|
|
if( pBGRbuffer != NULL ) { |
|
|
|
av_free( pBGRbuffer ); |
|
|
|
}; |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_CLOSED; |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
m_bThreadStatus = TH_ENDED; |
|
|
|
m_eMediaStatus = m_pVideoState->m_bStatus = MS_STOPED; |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Video Structures Cleared!"); |
|
|
|
#endif
|
|
|
|
|