1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "usbh_uvc_queue.h"
#include "chry_pool.h"
struct chry_pool usbh_uvc_pool;
uint32_t usbh_uvc_pool_buf[10];
int usbh_uvc_frame_create(struct usbh_videoframe *frame, uint32_t count)
{
return chry_pool_create(&usbh_uvc_pool, usbh_uvc_pool_buf, frame, sizeof(struct usbh_videoframe), count);
}
struct usbh_videoframe *usbh_uvc_frame_alloc(void)
{
return (struct usbh_videoframe *)chry_pool_item_alloc(&usbh_uvc_pool);
}
int usbh_uvc_frame_free(struct usbh_videoframe *frame)
{
return chry_pool_item_free(&usbh_uvc_pool, (uintptr_t *)frame);
}
int usbh_uvc_frame_send(struct usbh_videoframe *frame)
{
return chry_pool_item_send(&usbh_uvc_pool, (uintptr_t *)frame);
}
int usbh_uvc_frame_recv(struct usbh_videoframe **frame, uint32_t timeout)
{
return chry_pool_item_recv(&usbh_uvc_pool, (uintptr_t **)frame, timeout);
}
uint8_t frame_buffer1[1]; /* just for test */
uint8_t frame_buffer2[1]; /* just for test */
struct usbh_videoframe frame_pool[2];
void usbh_uvc_frame_init(void)
{
frame_pool[0].frame_buf = frame_buffer1;
frame_pool[0].frame_bufsize = 640 * 480 * 2;
frame_pool[1].frame_buf = frame_buffer2;
frame_pool[1].frame_bufsize = 640 * 480 * 2;
usbh_uvc_frame_create(frame_pool, 2);
}
static void usbh_frame_thread(void *argument)
{
int ret;
struct usbh_videoframe *frame;
while (1) {
ret = usbh_uvc_frame_recv(&frame, 0xfffffff);
if (ret < 0) {
continue;
}
USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
usbh_uvc_frame_free(frame);
}
}
void usbh_uvc_frame_alloc_send_test(void)
{
struct usbh_videoframe *frame = NULL;
frame = usbh_uvc_frame_alloc();
if (frame) {
frame->frame_size = 640 * 480 * 2;
usbh_uvc_frame_send(frame);
}
}
void usbh_uvc_frame_test(void)
{
usbh_uvc_frame_init();
usb_osal_thread_create("usbh_video", 3072, 5, usbh_frame_thread, NULL);
}
|