From d73f9e8a738529fdfc73066f71f8620674af7f75 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 28 Nov 2017 11:11:41 -0500 Subject: [PATCH] wip, crashes --- src/zm_ffmpeg.cpp | 2 +- src/zm_ffmpeg_camera.cpp | 33 +++++++++++++++++++++++---------- src/zm_monitor.cpp | 9 ++++++--- src/zm_videostore.cpp | 8 ++++---- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 1d7e25ec3..c73da27e8 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -190,7 +190,7 @@ int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat return ret; } else { s->oformat = oformat; -#if 0 +#if 1 // This is some very wrong code, and I don't think it is neccessary if (s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 4a5dbee0f..c368feefc 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -328,6 +328,9 @@ int FfmpegCamera::PostCapture() { int FfmpegCamera::OpenFfmpeg() { 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; @@ -372,6 +375,9 @@ int FfmpegCamera::OpenFfmpeg() { //FIXME can speed up initial analysis but need sensible parameters... //mFormatContext->probesize = 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 ) #endif @@ -380,12 +386,18 @@ int FfmpegCamera::OpenFfmpeg() { Error( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) ); 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; while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { 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; Debug ( 1, "Opened input" ); @@ -524,15 +536,15 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 1, "Calling avcodec_open2" ); if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 ) { #endif - AVDictionaryEntry *e; - if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { + AVDictionaryEntry *e = NULL; + while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { Warning( "Option %s not recognized by ffmpeg", e->key); } Fatal( "Unable to open codec for video stream from %s", mPath.c_str() ); } else { - AVDictionaryEntry *e; - if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { + AVDictionaryEntry *e = NULL; + if ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { 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 mRawFrame = zm_av_frame_alloc(); @@ -667,14 +679,14 @@ int FfmpegCamera::CloseFfmpeg() { if ( mVideoCodecContext ) { avcodec_close(mVideoCodecContext); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(mVideoCodecContext); + avcodec_free_context(&mVideoCodecContext); #endif mVideoCodecContext = NULL; // Freed by av_close_input_file } if ( mAudioCodecContext ) { avcodec_close(mAudioCodecContext); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(mAudioCodecContext); + avcodec_free_context(&mAudioCodecContext); #endif 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 ) { uint32_t last_event_id = monitor->GetLastEventId() ; + uint32_t video_writer_event_id = monitor->GetVideoWriterEventId(); - if ( last_event_id != monitor->GetVideoWriterEventId() ) { - Debug(2, "Have change of event. last_event(%d), our current (%d)", 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, video_writer_event_id ); if ( videoStore ) { Info("Re-starting video storage module"); diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 4f69012f3..a550b4370 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -473,9 +473,12 @@ Monitor::Monitor( videoRecording = ((GetOptVideoWriter() == H264PASSTHROUGH) && camera->SupportsNativeVideo()); if ( purpose == ANALYSIS ) { - - while( shared_data->last_write_index == (unsigned int)image_buffer_count - && shared_data->last_write_time == 0) { +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 ) + && + ( shared_data->last_write_time == 0) + ) { Warning( "Waiting for capture daemon" ); sleep( 1 ); } diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 20b895c81..8c02d6e3f 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -414,13 +414,13 @@ VideoStore::~VideoStore() { if (video_out_stream) { #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // We allocate and copy in newer ffmpeg, so need to free it - av_free(video_in_ctx); + avcodec_free_context(&video_in_ctx); #endif video_in_ctx=NULL; avcodec_close(video_out_ctx); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(video_out_ctx); + avcodec_free_context(&video_out_ctx); #endif video_out_ctx = NULL; Debug(4, "Success freeing video_out_ctx"); @@ -430,7 +430,7 @@ VideoStore::~VideoStore() { avcodec_close(audio_in_ctx); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // We allocate and copy in newer ffmpeg, so need to free it - av_free(audio_in_ctx); + avcodec_free_context(&audio_in_ctx); #endif audio_in_ctx = NULL; audio_in_codec = NULL; @@ -438,7 +438,7 @@ VideoStore::~VideoStore() { avcodec_close(audio_out_ctx); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(audio_out_ctx); + avcodec_free_context(&audio_out_ctx); #endif audio_out_ctx = NULL; #ifdef HAVE_LIBAVRESAMPLE