Implement an error count. Return -1 when it gets over 100 so that the camera will be reopened.

This commit is contained in:
Isaac Connor 2018-11-29 13:09:29 -05:00
parent af501128f2
commit 9cbc3352b9
2 changed files with 12 additions and 1 deletions

View File

@ -141,6 +141,7 @@ FfmpegCamera::FfmpegCamera(
video_last_pts = 0; video_last_pts = 0;
have_video_keyframe = false; have_video_keyframe = false;
packetqueue = NULL; packetqueue = NULL;
error_count = 0;
#if HAVE_LIBSWSCALE #if HAVE_LIBSWSCALE
mConvertContext = NULL; mConvertContext = NULL;
@ -334,6 +335,7 @@ int FfmpegCamera::OpenFfmpeg() {
int ret; int ret;
have_video_keyframe = false; have_video_keyframe = false;
error_count = 0;
// Open the input, not necessarily a file // Open the input, not necessarily a file
#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0) #if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0)
@ -745,10 +747,18 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
if ( packet.pts < -100000 ) { if ( packet.pts < -100000 ) {
// Ignore packets that have crazy negative pts. They aren't supposed to happen. // Ignore packets that have crazy negative pts. They aren't supposed to happen.
Warning("Ignore packet because pts is massively negative"); Warning("Ignore packet because pts %" PRId64 " is massively negative", packet.pts);
dumpPacket(&packet,"Ignored packet"); dumpPacket(&packet,"Ignored packet");
if ( error_count > 100 ) {
Error("Bad packet count over 100, going to close and re-open stream");
return -1;
}
error_count += 1;
continue; continue;
} }
// If we get a goot frame, decrease the error count.. We could zero it...
if ( error_count ) error_count -= 1;
int keyframe = packet.flags & AV_PKT_FLAG_KEY; int keyframe = packet.flags & AV_PKT_FLAG_KEY;
bytes += packet.size; bytes += packet.size;
dumpPacket(&packet,"Captured Packet"); dumpPacket(&packet,"Captured Packet");

View File

@ -87,6 +87,7 @@ class FfmpegCamera : public Camera {
#endif #endif
int64_t startTime; int64_t startTime;
int error_count;
public: public:
FfmpegCamera( int p_id, const std::string &path, const std::string &p_method, const std::string &p_options, int p_width, int p_height, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio ); FfmpegCamera( int p_id, const std::string &path, const std::string &p_method, const std::string &p_options, int p_width, int p_height, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio );