mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-18 02:42:37 +00:00
Change frame buffer management
This commit is contained in:
parent
d88cc23ca5
commit
0d6496886c
@ -109,30 +109,35 @@ void tud_resume_cb(void)
|
|||||||
static unsigned char const *frames[] = {
|
static unsigned char const *frames[] = {
|
||||||
black_128x96_yuv, white_128x96_yuv, green_128x96_yuv
|
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)
|
void video_task(void)
|
||||||
{
|
{
|
||||||
static unsigned start_ms = 0;
|
static unsigned start_ms = 0;
|
||||||
static unsigned interval_ms = 66;
|
static unsigned interval_ms = 100;
|
||||||
static unsigned frame_num = 0;
|
static unsigned frame_num = 0;
|
||||||
static unsigned already_sent = 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) {
|
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;
|
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();
|
unsigned cur = board_millis();
|
||||||
if (cur - start_ms < interval_ms) return; // not enough time
|
if (cur - start_ms < interval_ms) return; // not enough time
|
||||||
|
if (tx_busy) return;
|
||||||
start_ms += interval_ms;
|
start_ms += interval_ms;
|
||||||
|
|
||||||
/* flip buffer */
|
tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8);
|
||||||
|
|
||||||
++frame_num;
|
++frame_num;
|
||||||
if (frame_num % 3) {
|
if (frame_num % 3) {
|
||||||
interval_ms = 66;
|
interval_ms = 66;
|
||||||
@ -143,8 +148,8 @@ void video_task(void)
|
|||||||
|
|
||||||
int tud_video_frame_xfer_complete_cb(unsigned itf)
|
int tud_video_frame_xfer_complete_cb(unsigned itf)
|
||||||
{
|
{
|
||||||
/* prepare tx */
|
tx_busy = 0;
|
||||||
tud_video_n_frame_xfer(itf, 0, (void*)frames[current_frame], 128 * 96 * 12/8);
|
/* flip buffer */
|
||||||
++current_frame;
|
++current_frame;
|
||||||
if (current_frame == sizeof(frames)/sizeof(frames[0]))
|
if (current_frame == sizeof(frames)/sizeof(frames[0]))
|
||||||
current_frame = 0;
|
current_frame = 0;
|
||||||
|
@ -128,9 +128,9 @@ static video_probe_and_commit_control_t const def_stm_settings = {
|
|||||||
.wCompWindowSize = 1, /* Maybe it is match to GOP size */
|
.wCompWindowSize = 1, /* Maybe it is match to GOP size */
|
||||||
.wDelay = 240, /* milliseconds */
|
.wDelay = 240, /* milliseconds */
|
||||||
.dwMaxVideoFrameSize = 128 * 96 * 12 / 8,
|
.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 */
|
.dwClockFrequency = 27000000, /* same as MPEG-2 system time clock */
|
||||||
.bmFramingInfo = 0,
|
.bmFramingInfo = 0x3,
|
||||||
.bPreferedVersion = 1,
|
.bPreferedVersion = 1,
|
||||||
.bMinVersion = 1,
|
.bMinVersion = 1,
|
||||||
.bMaxVersion = 1,
|
.bMaxVersion = 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user