mirror of
https://github.com/steve-m/hsdaoh.git
synced 2025-12-10 07:44:41 +01:00
improve error reporting and startup
This commit is contained in:
parent
6f904d2fbb
commit
361c666bba
2 changed files with 27 additions and 17 deletions
|
|
@ -158,6 +158,8 @@ static int ppm_report(uint64_t nsamples, uint64_t interval)
|
|||
return (int)round(ppm);
|
||||
}
|
||||
|
||||
unsigned int counter_errors = -1;
|
||||
|
||||
static void ppm_test(uint32_t len)
|
||||
{
|
||||
static uint64_t nsamples = 0;
|
||||
|
|
@ -208,6 +210,12 @@ static void ppm_test(uint32_t len)
|
|||
ppm_report(nsamples_total, interval_total));
|
||||
ppm_recent = ppm_now;
|
||||
nsamples = 0;
|
||||
|
||||
if (counter_errors) {
|
||||
printf("Encountered %d counter errors\n", counter_errors);
|
||||
counter_errors = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint16_t last_value = 0;
|
||||
|
|
@ -219,9 +227,8 @@ static void hsdaoh_callback(unsigned char *buf, uint32_t len, void *ctx)
|
|||
int n = len / sizeof(uint16_t);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (cnt[i] != ((last_value+1) & 0xffff) ) {
|
||||
printf("Counter error: %02x != %02x\n", cnt[i], ((last_value+1) & 0xffff));
|
||||
}
|
||||
if (cnt[i] != ((last_value+1) & 0xffff))
|
||||
counter_errors++;
|
||||
|
||||
last_value = cnt[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ struct hsdaoh_dev {
|
|||
int discard_start_frames;
|
||||
uint16_t last_frame_cnt;
|
||||
uint16_t idle_cnt;
|
||||
bool stream_synced;
|
||||
|
||||
unsigned int width, height, fps;
|
||||
|
||||
|
|
@ -590,13 +591,15 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
|||
if (meta.framecounter == dev->last_frame_cnt)
|
||||
return;
|
||||
|
||||
// FIXME: calculate number of dropped frames
|
||||
if (dev->stream_synced) {
|
||||
if (meta.framecounter != ((dev->last_frame_cnt + 1) & 0xffff))
|
||||
printf("Missed at least one frame, fcnt %d, expected %d!\n", meta.framecounter, ((dev->last_frame_cnt + 1) & 0xffff));
|
||||
printf("Missed at least one frame, fcnt %d, expected %d!\n",
|
||||
meta.framecounter, ((dev->last_frame_cnt + 1) & 0xffff));
|
||||
}
|
||||
|
||||
dev->last_frame_cnt = meta.framecounter;
|
||||
|
||||
int frame_error = 0;
|
||||
int frame_errors = 0;
|
||||
|
||||
for (unsigned int i = 0; i < dev->height; i++) {
|
||||
uint8_t *line_dat = data + (dev->width * 2 * i);
|
||||
|
|
@ -615,10 +618,7 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
|||
}
|
||||
|
||||
uint16_t idle_len = (dev->width-1) - payload_len;
|
||||
int r = hsdaoh_check_idle_cnt(dev, (uint16_t *)line_dat + payload_len, idle_len);
|
||||
|
||||
if (r)
|
||||
printf("%d idle counter errors in line %d\n", r, i);
|
||||
frame_errors += hsdaoh_check_idle_cnt(dev, (uint16_t *)line_dat + payload_len, idle_len);
|
||||
|
||||
if (payload_len > 0)
|
||||
memmove(data + frame_payload_bytes, line_dat, payload_len * sizeof(uint16_t));
|
||||
|
|
@ -629,11 +629,16 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
|||
if (dev->cb)
|
||||
dev->cb(data, frame_payload_bytes, dev->cb_ctx);
|
||||
|
||||
if (frame_error) {
|
||||
fprintf(stderr,"%d counter errors, %d frames since last error\n", frame_error, dev->frames_since_error);
|
||||
if (frame_errors && dev->stream_synced) {
|
||||
fprintf(stderr,"%d idle counter errors, %d frames since last error\n", frame_errors, dev->frames_since_error);
|
||||
dev->frames_since_error = 0;
|
||||
} else
|
||||
dev->frames_since_error++;
|
||||
|
||||
if (!dev->stream_synced) {
|
||||
fprintf(stderr, "Syncronized to HDMI input stream\n");
|
||||
dev->stream_synced = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _uvc_callback(uvc_frame_t *frame, void *ptr)
|
||||
|
|
@ -717,11 +722,9 @@ int hsdaoh_stop_stream(hsdaoh_dev_t *dev)
|
|||
dev->async_status = HSDAOH_CANCELING;
|
||||
dev->async_cancel = 1;
|
||||
|
||||
|
||||
|
||||
/* End the stream. Blocks until last callback is serviced */
|
||||
// uvc_stop_streaming(dev->uvc_devh);
|
||||
// puts("Done streaming.");
|
||||
uvc_stop_streaming(dev->uvc_devh);
|
||||
puts("Done streaming.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue