1
1
/*
2
2
* hdhomerun_config.c
3
3
*
4
- * Copyright © 2006-2008 Silicondust USA Inc. <www.silicondust.com>.
4
+ * Copyright © 2006-2008 Silicondust USA Inc. <www.silicondust.com>.
5
5
*
6
6
* This library is free software; you can redistribute it and/or
7
7
* modify it under the terms of the GNU Lesser General Public
@@ -202,11 +202,30 @@ static int cmd_set(const char *item, const char *value)
202
202
return cmd_set_internal (item , value );
203
203
}
204
204
205
- static bool_t sigabort = FALSE;
205
+ static volatile sig_atomic_t sigabort_flag = FALSE;
206
+ static volatile sig_atomic_t siginfo_flag = FALSE;
207
+
208
+ static void sigabort_handler (int arg )
209
+ {
210
+ sigabort_flag = TRUE;
211
+ }
206
212
207
- static void signal_abort (int arg )
213
+ static void siginfo_handler (int arg )
208
214
{
209
- sigabort = TRUE;
215
+ siginfo_flag = TRUE;
216
+ }
217
+
218
+ static void register_signal_handlers (sig_t sigpipe_handler , sig_t sigint_handler , sig_t siginfo_handler )
219
+ {
220
+ #if defined(SIGPIPE )
221
+ signal (SIGPIPE , sigpipe_handler );
222
+ #endif
223
+ #if defined(SIGINT )
224
+ signal (SIGINT , sigint_handler );
225
+ #endif
226
+ #if defined(SIGINFO )
227
+ signal (SIGINFO , siginfo_handler );
228
+ #endif
210
229
}
211
230
212
231
static void cmd_scan_printf (FILE * fp , const char * fmt , ...)
@@ -274,19 +293,18 @@ static int cmd_scan(const char *tuner_str, const char *filename)
274
293
}
275
294
}
276
295
277
- signal (SIGINT , signal_abort );
278
- signal (SIGPIPE , signal_abort );
296
+ register_signal_handlers (sigabort_handler , sigabort_handler , siginfo_handler );
279
297
280
298
int ret = 0 ;
281
- while (!sigabort ) {
299
+ while (!sigabort_flag ) {
282
300
struct hdhomerun_channelscan_result_t result ;
283
301
ret = hdhomerun_device_channelscan_advance (hd , & result );
284
302
if (ret <= 0 ) {
285
303
break ;
286
304
}
287
305
288
306
cmd_scan_printf (fp , "SCANNING: %lu (%s)\n" ,
289
- result .frequency , result .channel_str
307
+ ( unsigned long ) result .frequency , result .channel_str
290
308
);
291
309
292
310
ret = hdhomerun_device_channelscan_detect (hd , & result );
@@ -321,6 +339,20 @@ static int cmd_scan(const char *tuner_str, const char *filename)
321
339
return ret ;
322
340
}
323
341
342
+ static void cmd_save_print_stats (void )
343
+ {
344
+ struct hdhomerun_video_stats_t stats ;
345
+ hdhomerun_device_get_video_stats (hd , & stats );
346
+
347
+ fprintf (stderr , "%u packets received, %u overflow errors, %u network errors, %u transport errors, %u sequence errors\n" ,
348
+ (unsigned int )stats .packet_count ,
349
+ (unsigned int )stats .overflow_error_count ,
350
+ (unsigned int )stats .network_error_count ,
351
+ (unsigned int )stats .transport_error_count ,
352
+ (unsigned int )stats .sequence_error_count
353
+ );
354
+ }
355
+
324
356
static int cmd_save (const char * tuner_str , const char * filename )
325
357
{
326
358
if (hdhomerun_device_set_tuner_from_str (hd , tuner_str ) <= 0 ) {
@@ -350,21 +382,26 @@ static int cmd_save(const char *tuner_str, const char *filename)
350
382
return ret ;
351
383
}
352
384
353
- signal (SIGINT , signal_abort );
354
- signal (SIGPIPE , signal_abort );
385
+ register_signal_handlers (sigabort_handler , sigabort_handler , siginfo_handler );
355
386
356
387
struct hdhomerun_video_stats_t stats_old , stats_cur ;
357
388
hdhomerun_device_get_video_stats (hd , & stats_old );
358
389
359
390
uint64_t next_progress = getcurrenttime () + 1000 ;
360
391
361
- while (!sigabort ) {
392
+ while (!sigabort_flag ) {
362
393
uint64_t loop_start_time = getcurrenttime ();
363
394
395
+ if (siginfo_flag ) {
396
+ fprintf (stderr , "\n" );
397
+ cmd_save_print_stats ();
398
+ siginfo_flag = FALSE;
399
+ }
400
+
364
401
size_t actual_size ;
365
402
uint8_t * ptr = hdhomerun_device_stream_recv (hd , VIDEO_DATA_BUFFER_SIZE_1S , & actual_size );
366
403
if (!ptr ) {
367
- msleep (64 );
404
+ msleep_approx (64 );
368
405
continue ;
369
406
}
370
407
@@ -381,6 +418,12 @@ static int cmd_save(const char *tuner_str, const char *filename)
381
418
next_progress = loop_start_time + 1000 ;
382
419
}
383
420
421
+ /* Windows - indicate activity to suppress auto sleep mode. */
422
+ #if defined(__WINDOWS__ )
423
+ SetThreadExecutionState (ES_SYSTEM_REQUIRED );
424
+ #endif
425
+
426
+ /* Video stats. */
384
427
hdhomerun_device_get_video_stats (hd , & stats_cur );
385
428
386
429
if (stats_cur .overflow_error_count > stats_old .overflow_error_count ) {
@@ -404,24 +447,18 @@ static int cmd_save(const char *tuner_str, const char *filename)
404
447
continue ;
405
448
}
406
449
407
- msleep (delay );
450
+ msleep_approx (delay );
408
451
}
409
452
410
453
if (fp ) {
411
454
fclose (fp );
412
455
}
413
456
414
457
hdhomerun_device_stream_stop (hd );
415
- hdhomerun_device_get_video_stats (hd , & stats_cur );
416
458
417
459
fprintf (stderr , "\n" );
418
460
fprintf (stderr , "-- Video statistics --\n" );
419
- fprintf (stderr , "%u packets received, %u overflow errors, %u network errors, %u transport errors, %u sequence errors\n" ,
420
- (unsigned int )stats_cur .packet_count ,
421
- (unsigned int )stats_cur .overflow_error_count ,
422
- (unsigned int )stats_cur .network_error_count ,
423
- (unsigned int )stats_cur .transport_error_count ,
424
- (unsigned int )stats_cur .sequence_error_count );
461
+ cmd_save_print_stats ();
425
462
426
463
return 0 ;
427
464
}
@@ -440,10 +477,10 @@ static int cmd_upgrade(const char *filename)
440
477
fclose (fp );
441
478
return -1 ;
442
479
}
443
- sleep ( 2 );
480
+ msleep_minimum ( 2000 );
444
481
445
482
printf ("upgrading firmware...\n" );
446
- sleep ( 8 );
483
+ msleep_minimum ( 8000 );
447
484
448
485
printf ("rebooting...\n" );
449
486
int count = 0 ;
@@ -460,7 +497,7 @@ static int cmd_upgrade(const char *filename)
460
497
return -1 ;
461
498
}
462
499
463
- sleep ( 1 );
500
+ msleep_minimum ( 1000 );
464
501
}
465
502
466
503
printf ("upgrade complete - now running firmware %s\n" , version_str );
0 commit comments