@@ -18,20 +18,14 @@ 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_buf0 ;
22
- uint8_t * ep_buf1 ;
23
- bool ep_buf0_ready ;
24
- bool ep_buf1_ready ;
25
- uint32_t ep_buf0_len ;
26
- uint32_t ep_buf1_len ;
27
- uint8_t ep_buf_idx ;
21
+ uint8_t * ep_buf ;
28
22
bool stream_finish ;
29
- uint32_t max_packets ;
30
23
uint8_t * stream_buf ;
31
24
uint32_t stream_len ;
32
25
uint32_t stream_offset ;
33
26
uint8_t stream_frameid ;
34
27
uint32_t stream_headerlen ;
28
+ bool do_copy ;
35
29
} g_usbd_video [CONFIG_USBDEV_MAX_BUS ];
36
30
37
31
static int usbd_video_control_request_handler (uint8_t busid , struct usb_setup_packet * setup , uint8_t * * data , uint32_t * len )
@@ -756,40 +750,6 @@ static void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dw
756
750
g_usbd_video [busid ].stream_headerlen = 2 ;
757
751
}
758
752
759
- static uint32_t usbd_video_prepare_ep_buf_data (uint8_t busid , uint32_t remain , uint8_t * ep_buf )
760
- {
761
- struct video_payload_header * header ;
762
- uint32_t len ;
763
- uint32_t offset ;
764
-
765
- len = MIN (remain , (g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - g_usbd_video [busid ].stream_headerlen ) * g_usbd_video [busid ].max_packets );
766
- offset = 0 ;
767
- while (len > 0 ) {
768
- header = (struct video_payload_header * )& ep_buf [offset ];
769
- header -> bHeaderLength = g_usbd_video [busid ].stream_headerlen ;
770
- header -> headerInfoUnion .bmheaderInfo = 0 ;
771
- header -> headerInfoUnion .headerInfoBits .endOfHeader = 1 ;
772
- header -> headerInfoUnion .headerInfoBits .endOfFrame = 0 ;
773
- header -> headerInfoUnion .headerInfoBits .frameIdentifier = g_usbd_video [busid ].stream_frameid ;
774
-
775
- uint32_t len2 = MIN (len , g_usbd_video [busid ].probe .dwMaxPayloadTransferSize - g_usbd_video [busid ].stream_headerlen );
776
-
777
- usb_memcpy (& ep_buf [offset + g_usbd_video [busid ].stream_headerlen ],
778
- & g_usbd_video [busid ].stream_buf [g_usbd_video [busid ].stream_offset ],
779
- len2 );
780
-
781
- g_usbd_video [busid ].stream_offset += len2 ;
782
- len -= len2 ;
783
- offset += (len2 + g_usbd_video [busid ].stream_headerlen );
784
-
785
- if (g_usbd_video [busid ].stream_offset == g_usbd_video [busid ].stream_len ) {
786
- header -> headerInfoUnion .headerInfoBits .endOfFrame = 1 ;
787
- }
788
- }
789
-
790
- return offset ;
791
- }
792
-
793
753
struct usbd_interface * usbd_video_init_intf (uint8_t busid ,
794
754
struct usbd_interface * intf ,
795
755
uint32_t dwFrameInterval ,
@@ -817,69 +777,87 @@ struct usbd_interface *usbd_video_init_intf(uint8_t busid,
817
777
818
778
bool usbd_video_stream_split_transfer (uint8_t busid , uint8_t ep )
819
779
{
820
- uint32_t remain ;
821
-
822
- if (g_usbd_video [busid ].ep_buf1_ready && (g_usbd_video [busid ].ep_buf_idx == 0 )) { /* callback: buf1 ready and buf0 was sent */
823
- g_usbd_video [busid ].ep_buf0_ready = false;
824
- g_usbd_video [busid ].ep_buf_idx = 1 ;
825
- usbd_ep_start_write (busid , ep , g_usbd_video [busid ].ep_buf1 , g_usbd_video [busid ].ep_buf1_len );
826
- } else if (g_usbd_video [busid ].ep_buf0_ready && (g_usbd_video [busid ].ep_buf_idx == 1 )) { /* callback: buf0 ready and buf1 was sent */
827
- g_usbd_video [busid ].ep_buf1_ready = false;
828
- g_usbd_video [busid ].ep_buf_idx = 0 ;
829
- usbd_ep_start_write (busid , ep , g_usbd_video [busid ].ep_buf0 , g_usbd_video [busid ].ep_buf0_len );
780
+ struct video_payload_header * header ;
781
+ static uint32_t offset = 0 ;
782
+ static uint32_t len = 0 ;
783
+
784
+ if (g_usbd_video [busid ].stream_finish ) {
785
+ g_usbd_video [busid ].stream_finish = false;
786
+ return true;
787
+ }
788
+
789
+ offset = g_usbd_video [busid ].stream_offset ;
790
+
791
+ len = MIN (g_usbd_video [busid ].stream_len ,
792
+ g_usbd_video [busid ].probe .dwMaxPayloadTransferSize -
793
+ g_usbd_video [busid ].stream_headerlen );
794
+
795
+ if (g_usbd_video [busid ].do_copy ) {
796
+ header = (struct video_payload_header * )& g_usbd_video [busid ].ep_buf [0 ];
797
+ usb_memcpy (& g_usbd_video [busid ].ep_buf [g_usbd_video [busid ].stream_headerlen ], & g_usbd_video [busid ].stream_buf [offset ], len );
830
798
} else {
831
- if (g_usbd_video [busid ].stream_finish ) {
832
- return true;
833
- }
799
+ header = (struct video_payload_header * )& g_usbd_video [busid ].stream_buf [offset - g_usbd_video [busid ].stream_headerlen ];
834
800
}
835
801
836
- if (! g_usbd_video [busid ].ep_buf0_ready ) {
837
- remain = g_usbd_video [ busid ]. stream_len - g_usbd_video [ busid ]. stream_offset ;
838
- if ( remain == 0 ) {
839
- g_usbd_video [ busid ]. stream_frameid ^= 1 ;
840
- g_usbd_video [busid ].stream_finish = true ;
841
- } else {
842
- g_usbd_video [busid ].ep_buf0_len = usbd_video_prepare_ep_buf_data ( busid , remain , g_usbd_video [ busid ]. ep_buf0 ) ;
843
- g_usbd_video [busid ].ep_buf0_ready = true ;
844
- if (! g_usbd_video [ busid ]. ep_buf1_ready ) {
845
- g_usbd_video [busid ].ep_buf_idx = 0 ;
846
- usbd_ep_start_write ( busid , ep , g_usbd_video [ busid ]. ep_buf0 , g_usbd_video [ busid ]. ep_buf0_len ) ;
847
- }
848
- }
802
+ header -> bHeaderLength = g_usbd_video [busid ].stream_headerlen ;
803
+ header -> headerInfoUnion . bmheaderInfo = 0 ;
804
+ header -> headerInfoUnion . headerInfoBits . endOfHeader = 1 ;
805
+ header -> headerInfoUnion . headerInfoBits . endOfFrame = 0 ;
806
+ header -> headerInfoUnion . headerInfoBits . frameIdentifier = g_usbd_video [busid ].stream_frameid ;
807
+
808
+ g_usbd_video [busid ].stream_offset += len ;
809
+ g_usbd_video [busid ].stream_len -= len ;
810
+
811
+ if ( g_usbd_video [busid ].stream_len == 0 ) {
812
+ header -> headerInfoUnion . headerInfoBits . endOfFrame = 1 ;
813
+ g_usbd_video [ busid ]. stream_frameid ^= 1 ;
814
+ g_usbd_video [ busid ]. stream_finish = true;
849
815
}
850
816
851
- if (!g_usbd_video [busid ].ep_buf1_ready ) {
852
- remain = g_usbd_video [busid ].stream_len - g_usbd_video [busid ].stream_offset ;
853
- if (remain == 0 ) {
854
- g_usbd_video [busid ].stream_frameid ^= 1 ;
855
- g_usbd_video [busid ].stream_finish = true;
856
- } else {
857
- g_usbd_video [busid ].ep_buf1_len = usbd_video_prepare_ep_buf_data (busid , remain , g_usbd_video [busid ].ep_buf1 );
858
- g_usbd_video [busid ].ep_buf1_ready = true;
859
- }
817
+ if (g_usbd_video [busid ].do_copy ) {
818
+ usbd_ep_start_write (busid , ep ,
819
+ g_usbd_video [busid ].ep_buf ,
820
+ g_usbd_video [busid ].stream_headerlen + len );
821
+ } else {
822
+ usbd_ep_start_write (busid , ep ,
823
+ & g_usbd_video [busid ].stream_buf [offset - g_usbd_video [busid ].stream_headerlen ],
824
+ g_usbd_video [busid ].stream_headerlen + len );
860
825
}
861
826
862
827
return false;
863
828
}
864
829
865
- int usbd_video_stream_start_write (uint8_t busid , uint8_t ep , uint8_t * ep_buf0 , uint8_t * ep_buf1 , uint32_t ep_bufsize , uint8_t * stream_buf , uint32_t stream_len )
830
+ int usbd_video_stream_start_write (uint8_t busid , uint8_t ep , uint8_t * ep_buf , uint8_t * stream_buf , uint32_t stream_len , bool do_copy )
866
831
{
832
+ struct video_payload_header * header ;
833
+
867
834
if ((usb_device_is_configured (busid ) == 0 ) || (stream_len == 0 )) {
868
835
return -1 ;
869
836
}
870
837
871
- g_usbd_video [busid ].ep_buf0 = ep_buf0 ;
872
- g_usbd_video [busid ].ep_buf1 = ep_buf1 ;
873
- g_usbd_video [busid ].ep_buf0_ready = false;
874
- g_usbd_video [busid ].ep_buf1_ready = false;
875
- g_usbd_video [busid ].ep_buf_idx = 0 ;
876
- g_usbd_video [busid ].stream_finish = false;
877
- g_usbd_video [busid ].max_packets = ep_bufsize / g_usbd_video [busid ].probe .dwMaxPayloadTransferSize ;
838
+ g_usbd_video [busid ].ep_buf = ep_buf ;
878
839
g_usbd_video [busid ].stream_buf = stream_buf ;
879
840
g_usbd_video [busid ].stream_len = stream_len ;
880
841
g_usbd_video [busid ].stream_offset = 0 ;
842
+ g_usbd_video [busid ].stream_finish = false;
843
+ g_usbd_video [busid ].do_copy = do_copy ;
844
+
845
+ uint32_t len = MIN (g_usbd_video [busid ].stream_len ,
846
+ g_usbd_video [busid ].probe .dwMaxPayloadTransferSize -
847
+ g_usbd_video [busid ].stream_headerlen );
848
+
849
+ header = (struct video_payload_header * )& ep_buf [0 ];
850
+ header -> bHeaderLength = g_usbd_video [busid ].stream_headerlen ;
851
+ header -> headerInfoUnion .bmheaderInfo = 0 ;
852
+ header -> headerInfoUnion .headerInfoBits .endOfHeader = 1 ;
853
+ header -> headerInfoUnion .headerInfoBits .endOfFrame = 0 ;
854
+ header -> headerInfoUnion .headerInfoBits .frameIdentifier = g_usbd_video [busid ].stream_frameid ;
855
+
856
+ usb_memcpy (& ep_buf [g_usbd_video [busid ].stream_headerlen ], stream_buf , len );
857
+ g_usbd_video [busid ].stream_offset += len ;
858
+ g_usbd_video [busid ].stream_len -= len ;
881
859
882
- usbd_video_stream_split_transfer (busid , ep );
860
+ usbd_ep_start_write (busid , ep , ep_buf , g_usbd_video [ busid ]. stream_headerlen + len );
883
861
return 0 ;
884
862
}
885
863
0 commit comments