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; diff --git a/src/class/video/video_device.c b/src/class/video/video_device.c index 344c4e0f9..ad7057d30 100644 --- a/src/class/video/video_device.c +++ b/src/class/video/video_device.c @@ -128,9 +128,9 @@ static video_probe_and_commit_control_t const def_stm_settings = { .wCompWindowSize = 1, /* Maybe it is match to GOP size */ .wDelay = 240, /* milliseconds */ .dwMaxVideoFrameSize = 128 * 96 * 12 / 8, - .dwMaxPayloadTransferSize = 256, /* Maybe it is the maximum packet size under this settings */ + .dwMaxPayloadTransferSize = ((128 * 96 * 12 / 8 * 10) + 999) / 1000 + 2, .dwClockFrequency = 27000000, /* same as MPEG-2 system time clock */ - .bmFramingInfo = 0, + .bmFramingInfo = 0x3, .bPreferedVersion = 1, .bMinVersion = 1, .bMaxVersion = 1,