Change the video image to scrolling color bars.

This commit is contained in:
kkitayam
2021-10-09 19:51:51 +09:00
parent a1788da410
commit a3a18c9ed3
4 changed files with 1717 additions and 7707 deletions

View File

@@ -31,7 +31,6 @@
#include "tusb.h"
#include "usb_descriptors.h"
#include "images.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
@@ -104,15 +103,54 @@ void tud_resume_cb(void)
//--------------------------------------------------------------------+
// USB Video
//--------------------------------------------------------------------+
static unsigned char const *frames[] = {
white_128x96_yuv, white_128x96_yuv, white_128x96_yuv,
t_128x96_yuv, ti_128x96_yuv, tin_128x96_yuv, logo_128x96_yuv,
logo_128x96_yuv, logo_128x96_yuv, logo_128x96_yuv, logo_128x96_yuv
};
static unsigned current_frame = 0;
static unsigned frame_num = 0;
static unsigned tx_busy = 0;
static unsigned interval_ms = 1000 / FRAME_RATE;
/* YUY2 frame buffer */
#ifdef CFG_EXAMPLE_VIDEO_READONLY
#include "images.h"
#else
static uint8_t frame_buffer[FRAME_WIDTH * FRAME_HEIGHT * 16 / 8];
static void fill_color_bar(uint8_t *buffer, unsigned start_position)
{
/* EBU color bars
* See also https://stackoverflow.com/questions/6939422 */
static uint8_t const bar_color[8][4] = {
/* Y, U, Y, V */
{ 235, 128, 235, 128}, /* 100% White */
{ 219, 16, 219, 138}, /* Yellow */
{ 188, 154, 188, 16}, /* Cyan */
{ 173, 42, 173, 26}, /* Green */
{ 78, 214, 78, 230}, /* Magenta */
{ 63, 102, 63, 240}, /* Red */
{ 32, 240, 32, 118}, /* Blue */
{ 16, 128, 16, 128}, /* Black */
};
uint8_t *p;
/* Generate the 1st line */
uint8_t *end = &buffer[FRAME_WIDTH * 2];
unsigned idx = (FRAME_WIDTH / 2 - 1) - (start_position % (FRAME_WIDTH / 2));
p = &buffer[idx * 4];
for (unsigned i = 0; i < 8; ++i) {
for (int j = 0; j < FRAME_WIDTH / (2 * 8); ++j) {
memcpy(p, &bar_color[i], 4);
p += 4;
if (end <= p) {
p = buffer;
}
}
}
/* Duplicate the 1st line to the others */
p = &buffer[FRAME_WIDTH * 2];
for (unsigned i = 1; i < FRAME_HEIGHT; ++i) {
memcpy(p, buffer, FRAME_WIDTH * 2);
p += FRAME_WIDTH * 2;
}
}
#endif
void video_task(void)
{
static unsigned start_ms = 0;
@@ -120,14 +158,20 @@ void video_task(void)
if (!tud_video_n_streaming(0, 0)) {
already_sent = 0;
current_frame = 0;
frame_num = 0;
return;
}
if (!already_sent) {
already_sent = 1;
start_ms = board_millis();
tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], FRAME_WIDTH * FRAME_HEIGHT * 12/8);
#ifdef CFG_EXAMPLE_VIDEO_READONLY
tud_video_n_frame_xfer(0, 0, (void*)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
#else
fill_color_bar(frame_buffer, frame_num);
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
#endif
}
unsigned cur = board_millis();
@@ -135,7 +179,13 @@ void video_task(void)
if (tx_busy) return;
start_ms += interval_ms;
tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], FRAME_WIDTH * FRAME_HEIGHT * 12/8);
#ifdef CFG_EXAMPLE_VIDEO_READONLY
tud_video_n_frame_xfer(0, 0, (void*)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
#else
fill_color_bar(frame_buffer, frame_num);
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
#endif
}
void tud_video_frame_xfer_complete_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx)
@@ -143,9 +193,7 @@ void tud_video_frame_xfer_complete_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx
(void)ctl_idx; (void)stm_idx;
tx_busy = 0;
/* flip buffer */
++current_frame;
if (current_frame == sizeof(frames)/sizeof(frames[0]))
current_frame = 0;
++frame_num;
}
int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,