wip, crashes

This commit is contained in:
Isaac Connor 2017-11-28 11:11:41 -05:00
parent 1e50df741f
commit d73f9e8a73
4 changed files with 34 additions and 18 deletions

View File

@ -190,7 +190,7 @@ int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat
return ret; return ret;
} else { } else {
s->oformat = oformat; s->oformat = oformat;
#if 0 #if 1
// This is some very wrong code, and I don't think it is neccessary // This is some very wrong code, and I don't think it is neccessary
if (s->oformat->priv_data_size > 0) { if (s->oformat->priv_data_size > 0) {
s->priv_data = av_mallocz(s->oformat->priv_data_size); s->priv_data = av_mallocz(s->oformat->priv_data_size);

View File

@ -328,6 +328,9 @@ int FfmpegCamera::PostCapture() {
int FfmpegCamera::OpenFfmpeg() { int FfmpegCamera::OpenFfmpeg() {
Debug ( 2, "OpenFfmpeg called." ); Debug ( 2, "OpenFfmpeg called." );
uint32_t last_event_id = monitor->GetLastEventId() ;
uint32_t video_writer_event_id = monitor->GetVideoWriterEventId();
Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id );
int ret; int ret;
@ -372,6 +375,9 @@ int FfmpegCamera::OpenFfmpeg() {
//FIXME can speed up initial analysis but need sensible parameters... //FIXME can speed up initial analysis but need sensible parameters...
//mFormatContext->probesize = 32; //mFormatContext->probesize = 32;
//mFormatContext->max_analyze_duration = 32; //mFormatContext->max_analyze_duration = 32;
last_event_id = monitor->GetLastEventId() ;
video_writer_event_id = monitor->GetVideoWriterEventId();
Debug(2, "last_event(%d), our current (%d), mpath (%s)", last_event_id, video_writer_event_id, mPath.c_str() );
if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 ) if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 )
#endif #endif
@ -380,12 +386,18 @@ int FfmpegCamera::OpenFfmpeg() {
Error( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) ); Error( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) );
return -1; return -1;
} }
last_event_id = monitor->GetLastEventId() ;
video_writer_event_id = monitor->GetVideoWriterEventId();
Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id );
AVDictionaryEntry *e=NULL; AVDictionaryEntry *e=NULL;
while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
Warning( "Option %s not recognized by ffmpeg", e->key); Warning( "Option %s not recognized by ffmpeg", e->key);
} }
last_event_id = monitor->GetLastEventId() ;
video_writer_event_id = monitor->GetVideoWriterEventId();
Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id );
mIsOpening = false; mIsOpening = false;
Debug ( 1, "Opened input" ); Debug ( 1, "Opened input" );
@ -524,15 +536,15 @@ int FfmpegCamera::OpenFfmpeg() {
Debug ( 1, "Calling avcodec_open2" ); Debug ( 1, "Calling avcodec_open2" );
if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 ) { if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 ) {
#endif #endif
AVDictionaryEntry *e; AVDictionaryEntry *e = NULL;
if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
Warning( "Option %s not recognized by ffmpeg", e->key); Warning( "Option %s not recognized by ffmpeg", e->key);
} }
Fatal( "Unable to open codec for video stream from %s", mPath.c_str() ); Fatal( "Unable to open codec for video stream from %s", mPath.c_str() );
} else { } else {
AVDictionaryEntry *e; AVDictionaryEntry *e = NULL;
if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { if ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) {
Warning( "Option %s not recognized by ffmpeg", e->key); Warning( "Option %s not recognized by ffmpeg", e->key);
} }
} }
@ -567,7 +579,7 @@ int FfmpegCamera::OpenFfmpeg() {
} }
} }
Debug ( 1, "Opened codec" ); Debug ( 1, "Opened audio codec" );
// Allocate space for the native video frame // Allocate space for the native video frame
mRawFrame = zm_av_frame_alloc(); mRawFrame = zm_av_frame_alloc();
@ -667,14 +679,14 @@ int FfmpegCamera::CloseFfmpeg() {
if ( mVideoCodecContext ) { if ( mVideoCodecContext ) {
avcodec_close(mVideoCodecContext); avcodec_close(mVideoCodecContext);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
av_free(mVideoCodecContext); avcodec_free_context(&mVideoCodecContext);
#endif #endif
mVideoCodecContext = NULL; // Freed by av_close_input_file mVideoCodecContext = NULL; // Freed by av_close_input_file
} }
if ( mAudioCodecContext ) { if ( mAudioCodecContext ) {
avcodec_close(mAudioCodecContext); avcodec_close(mAudioCodecContext);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
av_free(mAudioCodecContext); avcodec_free_context(&mAudioCodecContext);
#endif #endif
mAudioCodecContext = NULL; // Freed by av_close_input_file mAudioCodecContext = NULL; // Freed by av_close_input_file
} }
@ -784,9 +796,10 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
if ( recording.tv_sec ) { if ( recording.tv_sec ) {
uint32_t last_event_id = monitor->GetLastEventId() ; uint32_t last_event_id = monitor->GetLastEventId() ;
uint32_t video_writer_event_id = monitor->GetVideoWriterEventId();
if ( last_event_id != monitor->GetVideoWriterEventId() ) { if ( last_event_id != video_writer_event_id ) {
Debug(2, "Have change of event. last_event(%d), our current (%d)", last_event_id, monitor->GetVideoWriterEventId() ); Debug(2, "Have change of event. last_event(%d), our current (%d)", last_event_id, video_writer_event_id );
if ( videoStore ) { if ( videoStore ) {
Info("Re-starting video storage module"); Info("Re-starting video storage module");

View File

@ -473,9 +473,12 @@ Monitor::Monitor(
videoRecording = ((GetOptVideoWriter() == H264PASSTHROUGH) && camera->SupportsNativeVideo()); videoRecording = ((GetOptVideoWriter() == H264PASSTHROUGH) && camera->SupportsNativeVideo());
if ( purpose == ANALYSIS ) { if ( purpose == ANALYSIS ) {
Debug(2,"last_write_index(%d), last_write_time(%d)", shared_data->last_write_index, shared_data->last_write_time );
while( shared_data->last_write_index == (unsigned int)image_buffer_count while(
&& shared_data->last_write_time == 0) { ( shared_data->last_write_index == (unsigned int)image_buffer_count )
&&
( shared_data->last_write_time == 0)
) {
Warning( "Waiting for capture daemon" ); Warning( "Waiting for capture daemon" );
sleep( 1 ); sleep( 1 );
} }

View File

@ -414,13 +414,13 @@ VideoStore::~VideoStore() {
if (video_out_stream) { if (video_out_stream) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// We allocate and copy in newer ffmpeg, so need to free it // We allocate and copy in newer ffmpeg, so need to free it
av_free(video_in_ctx); avcodec_free_context(&video_in_ctx);
#endif #endif
video_in_ctx=NULL; video_in_ctx=NULL;
avcodec_close(video_out_ctx); avcodec_close(video_out_ctx);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
av_free(video_out_ctx); avcodec_free_context(&video_out_ctx);
#endif #endif
video_out_ctx = NULL; video_out_ctx = NULL;
Debug(4, "Success freeing video_out_ctx"); Debug(4, "Success freeing video_out_ctx");
@ -430,7 +430,7 @@ VideoStore::~VideoStore() {
avcodec_close(audio_in_ctx); avcodec_close(audio_in_ctx);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// We allocate and copy in newer ffmpeg, so need to free it // We allocate and copy in newer ffmpeg, so need to free it
av_free(audio_in_ctx); avcodec_free_context(&audio_in_ctx);
#endif #endif
audio_in_ctx = NULL; audio_in_ctx = NULL;
audio_in_codec = NULL; audio_in_codec = NULL;
@ -438,7 +438,7 @@ VideoStore::~VideoStore() {
avcodec_close(audio_out_ctx); avcodec_close(audio_out_ctx);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
av_free(audio_out_ctx); avcodec_free_context(&audio_out_ctx);
#endif #endif
audio_out_ctx = NULL; audio_out_ctx = NULL;
#ifdef HAVE_LIBAVRESAMPLE #ifdef HAVE_LIBAVRESAMPLE