From cd596d49e39daa10f85b9720221a8988b263430c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 17 Nov 2017 16:49:01 -0500 Subject: [PATCH] fix local camera inputstream --- src/zm_local_camera.cpp | 30 ++++++++++++++++++++++++++++++ src/zm_local_camera.h | 1 + src/zm_logger.cpp | 2 +- src/zm_monitor.cpp | 12 ++++++++---- src/zm_videostore.cpp | 2 ++ src/zmc.cpp | 2 +- 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/zm_local_camera.cpp b/src/zm_local_camera.cpp index a97a6470e..47ab5f065 100644 --- a/src/zm_local_camera.cpp +++ b/src/zm_local_camera.cpp @@ -650,6 +650,9 @@ LocalCamera::LocalCamera( } } // end if capture and conversion_tye == swscale #endif + mVideoStreamId = 0; + mAudioStreamId = -1; + video_stream = NULL; } // end LocalCamera::LocalCamera LocalCamera::~LocalCamera() { @@ -2105,5 +2108,32 @@ int LocalCamera::PostCapture() { } return( 0 ); } +AVStream *LocalCamera::get_VideoStream() { + if ( ! video_stream ) { + AVFormatContext *oc = avformat_alloc_context(); + video_stream = avformat_new_stream( oc, NULL ); + if ( video_stream ) { +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + video_stream->codecpar->width = width; + video_stream->codecpar->height = height; + video_stream->codecpar->format = GetFFMPEGPixelFormat(colours,subpixelorder); + video_stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; +#else + video_stream->codec->width = width; + video_stream->codec->height = height; + video_stream->codec->pix_fmt = GetFFMPEGPixelFormat(colours,subpixelorder); + video_stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; +#endif + } else { + Error("Can't create video stream"); + } + } else { + Debug(2,"Have videostream"); + } + Debug(2,"Get videoStream"); + return video_stream; +} + #endif // ZM_HAS_V4L + diff --git a/src/zm_local_camera.h b/src/zm_local_camera.h index de1d7f9c5..57f8aaa40 100644 --- a/src/zm_local_camera.h +++ b/src/zm_local_camera.h @@ -159,6 +159,7 @@ public: int Capture(ZMPacket &p); int PostCapture(); static bool GetCurrentSettings( const char *device, char *output, int version, bool verbose ); +AVStream* get_VideoStream(); }; #endif // ZM_HAS_V4L diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index ffebff726..f2797f8e7 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -498,7 +498,7 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co va_start( argPtr, fstring ); if ( hex ) { unsigned char *data = va_arg( argPtr, unsigned char * ); - int len = va_arg( argPtr, int ); + int len = va_arg( argPtr, int32_t ); int i; logPtr += snprintf( logPtr, sizeof(logString)-(logPtr-logString), "%d:", len ); for ( i = 0; i < len; i++ ) { diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 80684ad53..9ab4e9a37 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -600,6 +600,7 @@ Monitor::~Monitor() { if ( purpose == ANALYSIS ) { shared_data->state = state = IDLE; + // I think we set it to the count so that it is technically 1 behind capture, which starts at 0 shared_data->last_read_index = image_buffer_count; shared_data->last_read_time = 0; @@ -1202,10 +1203,13 @@ bool Monitor::Analyse() { ZMPacket *snap = &image_buffer[index]; if ( snap->packet.stream_index != camera->get_VideoStreamId() ) { + Debug(2, "Non video packet in analysis (%d) != (%d)", snap->packet.stream_index, camera->get_VideoStreamId() ); if ( event ) { //event->AddFrame( snap_image, *timestamp, score ); event->AddPacket( snap, 0 ); } + shared_data->last_read_index = index % image_buffer_count; + shared_data->last_read_time = now.tv_sec; mutex.unlock(); return false; } @@ -3022,10 +3026,10 @@ packet->reset(); } #endif - shared_data->signal = CheckSignal(capture_image); - shared_data->last_write_index = index; - shared_data->last_write_time = image_buffer[index].timestamp.tv_sec; - image_count++; + shared_data->signal = CheckSignal(capture_image); + shared_data->last_write_index = index; + shared_data->last_write_time = image_buffer[index].timestamp.tv_sec; + image_count++; } else { // result == 0 } // end if result diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 453e6a8e0..a72627bbb 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -86,8 +86,10 @@ VideoStore::VideoStore( video_in_stream_index = video_in_stream->index; #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) video_in_ctx = avcodec_alloc_context3(NULL); + Debug(2, "copy to context"); avcodec_parameters_to_context(video_in_ctx, video_in_stream->codecpar); + Debug(2, "dump to context"); zm_dump_codecpar( video_in_stream->codecpar ); //video_in_ctx.codec_id = video_in_stream->codecpar.codec_id; #else diff --git a/src/zmc.cpp b/src/zmc.cpp index 6dd833e5d..7d391d22a 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -317,7 +317,7 @@ int main(int argc, char *argv[]) { DELTA_TIMEVAL(delta_time, now, last_capture_times[i], DT_PREC_3); long sleep_time = next_delays[i]-delta_time.delta; if ( sleep_time > 0 ) { - Debug(2,"usleeping (%d)", sleep_time*(DT_MAXGRAN/DT_PREC_3) ); + //Debug(2,"usleeping (%d)", sleep_time*(DT_MAXGRAN/DT_PREC_3) ); usleep(sleep_time*(DT_MAXGRAN/DT_PREC_3)); } last_capture_times[i] = now;