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;
} 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);

View File

@ -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");

View File

@ -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 );
}

View File

@ -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