diff options
| author | kkitayam <[email protected]> | 2021-09-25 20:49:04 +0900 |
|---|---|---|
| committer | kkitayam <[email protected]> | 2021-09-29 21:23:17 +0900 |
| commit | 0d6496886cae22f33408bd126925b5d6c4908d65 (patch) | |
| tree | 569f8c168ecc188e400b83d0dd6bddaf11a552f2 /examples | |
| parent | d88cc23ca5eced51167edad00ea43c86038ee481 (diff) | |
Change frame buffer management
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/video_capture/src/main.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c index 4ca0e5d90..4a124c537 100644 --- a/examples/device/video_capture/src/main.c +++ b/examples/device/video_capture/src/main.c @@ -109,30 +109,35 @@ void tud_resume_cb(void) static unsigned char const *frames[] = { black_128x96_yuv, white_128x96_yuv, green_128x96_yuv }; -uint8_t current_frame = 0; +static unsigned current_frame = 0; +static unsigned tx_busy = 0; void video_task(void) { static unsigned start_ms = 0; - static unsigned interval_ms = 66; + static unsigned interval_ms = 100; static unsigned frame_num = 0; static unsigned already_sent = 0; - if (!tud_video_n_streaming(0)) return; + if (!tud_video_n_streaming(0)) { + already_sent = 0; + current_frame = 0; + return; + } if (!already_sent) { - tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8); - ++current_frame; - if (current_frame == sizeof(frames)/sizeof(frames[0])) - current_frame = 0; already_sent = 1; + start_ms = board_millis(); + tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8); } unsigned cur = board_millis(); if (cur - start_ms < interval_ms) return; // not enough time + if (tx_busy) return; start_ms += interval_ms; - /* flip buffer */ + tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8); + ++frame_num; if (frame_num % 3) { interval_ms = 66; @@ -143,8 +148,8 @@ void video_task(void) int tud_video_frame_xfer_complete_cb(unsigned itf) { - /* prepare tx */ - tud_video_n_frame_xfer(itf, 0, (void*)frames[current_frame], 128 * 96 * 12/8); + tx_busy = 0; + /* flip buffer */ ++current_frame; if (current_frame == sizeof(frames)/sizeof(frames[0])) current_frame = 0; |
