Skip to content

Commit 3c6e256

Browse files
authored
Add maximum limit on attempts to get data from camera
1 parent d55394f commit 3c6e256

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/netcam_rtsp.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ static int netcam_rtsp_read_image(struct rtsp_context *rtsp_data)
11441144
{
11451145

11461146
int size_decoded;
1147-
int retcd, errcnt, haveimage;
1147+
int retcd, nodata, haveimage;
11481148
char errstr[128];
11491149
netcam_buff *xchg;
11501150

@@ -1164,32 +1164,30 @@ static int netcam_rtsp_read_image(struct rtsp_context *rtsp_data)
11641164
rtsp_data->status = RTSP_READINGIMAGE;
11651165
rtsp_data->img_recv->used = 0;
11661166
size_decoded = 0;
1167-
errcnt = 0;
1167+
nodata = 0;
11681168
haveimage = FALSE;
11691169

1170-
/* We allow for one failure on the av_read_frame. Upon the second failure, we exit the function
1171-
* with a fail code to either end the program or possibly try to reconnnect to camera
1172-
*/
1173-
while ((!haveimage) && (!rtsp_data->interrupted)) {
1170+
while ((haveimage == FALSE) && (rtsp_data->interrupted == FALSE)) {
11741171
retcd = av_read_frame(rtsp_data->format_context, rtsp_data->packet_recv);
1175-
if (retcd < 0 ) {
1176-
errcnt++;
1177-
}
1178-
if ((rtsp_data->interrupted) || (errcnt > 1)) {
1172+
/* The 2000 for nodata tries is arbritrary*/
1173+
if ((rtsp_data->interrupted) || (retcd < 0 ) || (nodata > 2000)) {
11791174
if (rtsp_data->interrupted) {
11801175
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
11811176
,_("%s: Interrupted"),rtsp_data->cameratype);
1182-
} else {
1177+
} else if (retcd < 0) {
11831178
av_strerror(retcd, errstr, sizeof(errstr));
11841179
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
11851180
,_("%s: av_read_frame: %s")
11861181
,rtsp_data->cameratype, errstr);
1182+
} else {
1183+
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO
1184+
,_("%s: Excessive tries to get data from camera %d")
1185+
,rtsp_data->cameratype, nodata);
11871186
}
11881187
netcam_rtsp_free_pkt(rtsp_data);
11891188
netcam_rtsp_close_context(rtsp_data);
11901189
return -1;
11911190
} else {
1192-
errcnt = 0;
11931191
if (rtsp_data->packet_recv->stream_index == rtsp_data->video_stream_index) {
11941192
/* For a high resolution pass-through we don't decode the image */
11951193
if (rtsp_data->high_resolution && rtsp_data->passthrough) {
@@ -1205,6 +1203,7 @@ static int netcam_rtsp_read_image(struct rtsp_context *rtsp_data)
12051203
haveimage = TRUE;
12061204
} else if (size_decoded == 0) {
12071205
/* Did not fail, just didn't get anything. Try again */
1206+
nodata++;
12081207
netcam_rtsp_free_pkt(rtsp_data);
12091208
rtsp_data->packet_recv = my_packet_alloc(rtsp_data->packet_recv);
12101209
} else {

0 commit comments

Comments
 (0)