@@ -18,6 +18,10 @@ struct usbd_video_priv {
18
18
uint8_t power_mode ;
19
19
uint8_t error_code ;
20
20
struct video_entity_info info [3 ];
21
+ uint8_t * ep_buffer ;
22
+ uint8_t * stream_buf ;
23
+ uint32_t stream_len ;
24
+ uint32_t stream_offset ;
21
25
} g_usbd_video [CONFIG_USBDEV_MAX_BUS ];
22
26
23
27
static int usbd_video_control_request_handler (uint8_t busid , struct usb_setup_packet * setup , uint8_t * * data , uint32_t * len )
@@ -671,7 +675,7 @@ static int video_class_interface_request_handler(uint8_t busid, struct usb_setup
671
675
} else {
672
676
return usbd_video_control_unit_terminal_request_handler (busid , setup , data , len ); /* Unit and Terminal Requests */
673
677
}
674
- } else if (intf_num == 1 ) { /* Video Stream Inteface */
678
+ } else if (intf_num == 1 ) { /* Video Stream Inteface */
675
679
return usbd_video_stream_request_handler (busid , setup , data , len ); /* Interface Stream Requests */
676
680
}
677
681
return -1 ;
@@ -700,7 +704,7 @@ static void video_notify_handler(uint8_t busid, uint8_t event, void *arg)
700
704
}
701
705
}
702
706
703
- void usbd_video_probe_and_commit_controls_init (uint8_t busid , uint32_t dwFrameInterval , uint32_t dwMaxVideoFrameSize , uint32_t dwMaxPayloadTransferSize )
707
+ static void usbd_video_probe_and_commit_controls_init (uint8_t busid , uint32_t dwFrameInterval , uint32_t dwMaxVideoFrameSize , uint32_t dwMaxPayloadTransferSize )
704
708
{
705
709
g_usbd_video [busid ].probe .hintUnion .bmHint = 0x01 ;
706
710
g_usbd_video [busid ].probe .hintUnion1 .bmHint = 0 ;
@@ -739,7 +743,8 @@ void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dwFrameIn
739
743
g_usbd_video [busid ].commit .bMaxVersion = 0 ;
740
744
}
741
745
742
- struct usbd_interface * usbd_video_init_intf (uint8_t busid , struct usbd_interface * intf ,
746
+ struct usbd_interface * usbd_video_init_intf (uint8_t busid ,
747
+ struct usbd_interface * intf ,
743
748
uint32_t dwFrameInterval ,
744
749
uint32_t dwMaxVideoFrameSize ,
745
750
uint32_t dwMaxPayloadTransferSize )
@@ -763,14 +768,64 @@ struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface
763
768
return intf ;
764
769
}
765
770
771
+ bool usbd_video_stream_split_transfer (uint8_t busid , uint8_t ep )
772
+ {
773
+ struct video_payload_header * header = (struct video_payload_header * )g_usbd_video [busid ].ep_buffer ;
774
+ uint32_t remain ;
775
+ uint32_t len ;
776
+
777
+ remain = g_usbd_video [busid ].stream_len - g_usbd_video [busid ].stream_offset ;
778
+
779
+ if (remain == 0 ) {
780
+ return true;
781
+ }
782
+
783
+ header -> bHeaderLength = 2 ;
784
+ header -> headerInfoUnion .headerInfoBits .endOfHeader = 1 ;
785
+
786
+ len = MIN (remain , g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - header -> bHeaderLength );
787
+ memcpy (& g_usbd_video [busid ].ep_buffer [header -> bHeaderLength ],
788
+ & g_usbd_video [busid ].stream_buf [g_usbd_video [busid ].stream_offset ],
789
+ len );
790
+
791
+ g_usbd_video [busid ].stream_offset += len ;
792
+
793
+ if (g_usbd_video [busid ].stream_offset == g_usbd_video [busid ].stream_len ) {
794
+ header -> headerInfoUnion .headerInfoBits .endOfFrame = 1 ;
795
+ }
796
+
797
+ usbd_ep_start_write (busid , ep , g_usbd_video [busid ].ep_buffer , len + header -> bHeaderLength );
798
+ return false;
799
+ }
800
+
801
+ int usbd_video_stream_start_write (uint8_t busid , uint8_t ep , uint8_t * ep_buffer , uint8_t * buf , uint32_t len )
802
+ {
803
+ if (usb_device_is_configured (busid ) == 0 ) {
804
+ return -1 ;
805
+ }
806
+
807
+ g_usbd_video [busid ].ep_buffer = ep_buffer ;
808
+ g_usbd_video [busid ].stream_buf = buf ;
809
+ g_usbd_video [busid ].stream_len = len ;
810
+ g_usbd_video [busid ].stream_offset = 0 ;
811
+
812
+ struct video_payload_header * header = (struct video_payload_header * )g_usbd_video [busid ].ep_buffer ;
813
+
814
+ header -> headerInfoUnion .headerInfoBits .frameIdentifier ^= 1 ;
815
+ header -> headerInfoUnion .headerInfoBits .endOfFrame = 0 ;
816
+
817
+ usbd_video_stream_split_transfer (busid , ep );
818
+ return 0 ;
819
+ }
820
+
766
821
uint32_t usbd_video_payload_fill (uint8_t busid , uint8_t * input , uint32_t input_len , uint8_t * output , uint32_t * out_len )
767
822
{
768
823
uint32_t packets ;
769
824
uint32_t last_packet_size ;
770
825
uint32_t picture_pos = 0 ;
771
826
static uint8_t uvc_header [2 ] = { 0x02 , 0x80 };
772
827
773
- packets = (input_len + (g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - 2 ) ) / (g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - 2 );
828
+ packets = (input_len + (g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - 2 )) / (g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - 2 );
774
829
last_packet_size = input_len - ((packets - 1 ) * (g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - 2 ));
775
830
776
831
for (size_t i = 0 ; i < packets ; i ++ ) {
0 commit comments