support CFG_EXAMPLE_VIDEO_READONLY for stream0 for small mcu

This commit is contained in:
hathach 2024-04-05 16:12:31 +07:00
parent df1f84adad
commit 5b2441d8a3
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
2 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,8 @@
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG) #if defined(CFG_EXAMPLE_VIDEO_READONLY)
// uncopmressed frame //--------------------------------------------------------------------+
static const unsigned char frame_buffer[128 * (96 + 1) * 2] = { // YUY2 Uncompressed Frame (fixed)
//--------------------------------------------------------------------+
static const unsigned char framebuf_yuy2_readonly[128 * (96 + 1) * 2] = {
/* 0 */ /* 0 */
0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80,
0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80,
@ -1654,9 +1656,10 @@ static const unsigned char frame_buffer[128 * (96 + 1) * 2] = {
#endif #endif
#if 1 //--------------------------------------------------------------------+
// MPEG Compressed Frame (fixed)
//--------------------------------------------------------------------+
// mpeg compressed data (not CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
unsigned char color_bar_0_jpg[] = { unsigned char color_bar_0_jpg[] = {
0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@ -1929,7 +1932,3 @@ unsigned char color_bar_7_jpg[] = {
0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a, 0x42, 0x51, 0x59, 0x8c, 0xb1, 0x45, 0x00, 0x25, 0x15, 0x98, 0xc4, 0xa2, 0xb5, 0x32, 0x12, 0x8a,
0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x47, 0xff, 0xd9 0xcc, 0x63, 0x68, 0xad, 0x8d, 0x84, 0xa2, 0xb3, 0x18, 0x94, 0x56, 0xa6, 0x47, 0xff, 0xd9
}; };
#endif

View File

@ -112,6 +112,8 @@ void tud_resume_cb(void) {
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USB Video // USB Video
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define FRAMEBUF_SIZE (FRAME_WIDTH * FRAME_HEIGHT * 16 / 8)
static unsigned frame_num[CFG_TUD_VIDEO_STREAMING] = {1}; static unsigned frame_num[CFG_TUD_VIDEO_STREAMING] = {1};
static unsigned tx_busy = 0; static unsigned tx_busy = 0;
static unsigned interval_ms[CFG_TUD_VIDEO_STREAMING] = {1000 / FRAME_RATE}; static unsigned interval_ms[CFG_TUD_VIDEO_STREAMING] = {1000 / FRAME_RATE};
@ -134,8 +136,8 @@ static struct {
{sizeof(color_bar_7_jpg), color_bar_7_jpg}, {sizeof(color_bar_7_jpg), color_bar_7_jpg},
}; };
#if !defined(CFG_EXAMPLE_VIDEO_READONLY)
// YUY2 frame buffer // YUY2 frame buffer
#define FRAMEBUF_SIZE (FRAME_WIDTH * FRAME_HEIGHT * 16 / 8)
static uint8_t framebuf_yuy2[FRAMEBUF_SIZE]; static uint8_t framebuf_yuy2[FRAMEBUF_SIZE];
static void fill_color_bar(uint8_t* buffer, unsigned start_position) { static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
@ -174,14 +176,20 @@ static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
p += FRAME_WIDTH * 2; p += FRAME_WIDTH * 2;
} }
} }
#endif
size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) { size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
uint32_t idx = ctl_idx + stm_idx; uint32_t idx = ctl_idx + stm_idx;
if (idx == 0) { if (idx == 0) {
// stream 0 use uncompressed YUY2 frame // stream 0 use uncompressed YUY2 frame
#if defined(CFG_EXAMPLE_VIDEO_READONLY)
*fb = (void*)(uintptr_t ) framebuf_yuy2_readonly[(fnum % (FRAME_WIDTH / 2)) * 4];
#else
fill_color_bar(framebuf_yuy2, frame_num[idx]); fill_color_bar(framebuf_yuy2, frame_num[idx]);
*fb = framebuf_yuy2; *fb = framebuf_yuy2;
#endif
return FRAMEBUF_SIZE; return FRAMEBUF_SIZE;
}else { }else {
// stream 1 use MJPEG frame // stream 1 use MJPEG frame