usbh_uvc_queue.c 1.9 KB

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