@@ -992,7 +992,7 @@ class Device_manager_Worker_thread_args
992
992
993
993
std::vector<unsigned char *> decodedFrameBuff;
994
994
std::vector<unsigned > decodedFrameLenBuff;
995
- int decodedFrameBuffMaxSize;
995
+ unsigned decodedFrameBuffMaxSize;
996
996
997
997
Device_manager_Worker_thread_args (const char *devNameIn)
998
998
{
@@ -1008,7 +1008,7 @@ class Device_manager_Worker_thread_args
1008
1008
frameWidth = 0 ;
1009
1009
frameHeight = 0 ;
1010
1010
decodedFrameBuffMaxSize = 10 ;
1011
- verbose = 0 ;
1011
+ verbose = 1 ;
1012
1012
}
1013
1013
1014
1014
virtual ~Device_manager_Worker_thread_args ()
@@ -1374,11 +1374,14 @@ class Device_manager_Worker_thread_args
1374
1374
if (this ->deviceStarted )
1375
1375
StopDeviceInternal ();
1376
1376
1377
- for ( int i = 0 ; i < this ->buffer_counts ; i++ )
1377
+ if ( this ->buffers != NULL )
1378
1378
{
1379
- v4l2_munmap (buffers[i].start , buffers[i].length );
1379
+ for (int i = 0 ; i < this ->buffer_counts ; i++)
1380
+ {
1381
+ v4l2_munmap (this ->buffers [i].start , this ->buffers [i].length );
1382
+ }
1383
+ delete [] this ->buffers ;
1380
1384
}
1381
- delete [] this ->buffers ;
1382
1385
this ->buffers = NULL ;
1383
1386
1384
1387
// Release memory
@@ -1406,25 +1409,24 @@ class Device_manager_Worker_thread_args
1406
1409
if (deviceStarted) this ->ReadFrame ();
1407
1410
1408
1411
pthread_mutex_lock (&this ->lock );
1412
+ try
1413
+ {
1414
+
1409
1415
if (this ->openDeviceFlag .size () > 0 )
1410
1416
{
1411
1417
std::string devName = this ->openDeviceFlag [this ->openDeviceFlag .size ()-1 ];
1412
1418
this ->openDeviceFlag .pop_back ();
1413
1419
this ->OpenDeviceInternal ();
1414
1420
}
1415
- pthread_mutex_unlock (&this ->lock );
1416
-
1417
- pthread_mutex_lock (&this ->lock );
1421
+
1418
1422
if (this ->setFormatFlags .size () > 0
1419
1423
&& this ->openDeviceFlag .size () == 0 )
1420
1424
{
1421
1425
class SetFormatParams params = this ->setFormatFlags [this ->setFormatFlags .size ()-1 ];
1422
1426
this ->setFormatFlags .pop_back ();
1423
1427
this ->SetFormatInternal (params);
1424
1428
}
1425
- pthread_mutex_unlock (&this ->lock );
1426
1429
1427
- pthread_mutex_lock (&this ->lock );
1428
1430
if (this ->startDeviceFlag .size () > 0
1429
1431
&& this ->openDeviceFlag .size () == 0
1430
1432
&& this ->setFormatFlags .size () == 0 )
@@ -1433,9 +1435,7 @@ class Device_manager_Worker_thread_args
1433
1435
this ->startDeviceFlag .pop_back ();
1434
1436
this ->StartDeviceInternal (buffer_count);
1435
1437
}
1436
- pthread_mutex_unlock (&this ->lock );
1437
1438
1438
- pthread_mutex_lock (&this ->lock );
1439
1439
if (this ->stopDeviceFlag
1440
1440
&& this ->openDeviceFlag .size () == 0
1441
1441
&& this ->setFormatFlags .size () == 0
@@ -1444,9 +1444,7 @@ class Device_manager_Worker_thread_args
1444
1444
this ->StopDeviceInternal ();
1445
1445
this ->stopDeviceFlag = 0 ;
1446
1446
}
1447
- pthread_mutex_unlock (&this ->lock );
1448
1447
1449
- pthread_mutex_lock (&this ->lock );
1450
1448
if (this ->closeDeviceFlag
1451
1449
&& this ->openDeviceFlag .size () == 0
1452
1450
&& this ->setFormatFlags .size () == 0
@@ -1456,10 +1454,14 @@ class Device_manager_Worker_thread_args
1456
1454
this ->CloseDeviceInternal ();
1457
1455
this ->closeDeviceFlag = 0 ;
1458
1456
}
1459
- pthread_mutex_unlock (&this ->lock );
1460
-
1461
- pthread_mutex_lock (&this ->lock );
1457
+
1462
1458
running = !this ->stop ;
1459
+ }
1460
+ catch (std::exception &err)
1461
+ {
1462
+ if (verbose) printf (" An exception has occured: %s\n " , err.what ());
1463
+ running = 0 ;
1464
+ }
1463
1465
pthread_mutex_unlock (&this ->lock );
1464
1466
}
1465
1467
}
0 commit comments