25
25
*
26
26
* 1. struct usbi_transfer
27
27
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
28
- index 646c938..3900241 100644
28
+ index 646c938..79ba6c6 100644
29
29
--- a/libusb/os/darwin_usb.c
30
30
+++ b/libusb/os/darwin_usb.c
31
31
@@ -1137,6 +1137,8 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) {
@@ -37,7 +37,31 @@ index 646c938..3900241 100644
37
37
if (is_read)
38
38
ret = (*(cInterface->interface))->ReadPipeAsyncTO(cInterface->interface, pipeRef, transfer->buffer,
39
39
transfer->length, transfer->timeout, transfer->timeout,
40
- @@ -1198,9 +1200,11 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
40
+ @@ -1171,10 +1173,19 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
41
+ /* are we reading or writing? */
42
+ is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN;
43
+
44
+ - /* construct an array of IOUSBIsocFrames */
45
+ - tpriv->isoc_framelist = (IOUSBIsocFrame*) calloc (transfer->num_iso_packets, sizeof(IOUSBIsocFrame));
46
+ - if (!tpriv->isoc_framelist)
47
+ - return LIBUSB_ERROR_NO_MEM;
48
+ + /* construct an array of IOUSBIsocFrames, reuse the old one if possible */
49
+ + if (tpriv->isoc_framelist != NULL && tpriv->num_iso_packets != transfer->num_iso_packets)
50
+ + {
51
+ + free(tpriv->isoc_framelist);
52
+ + tpriv->isoc_framelist = NULL;
53
+ + }
54
+ + if (tpriv->isoc_framelist == NULL)
55
+ + {
56
+ + tpriv->isoc_framelist = (IOUSBIsocFrame*) calloc (transfer->num_iso_packets, sizeof(IOUSBIsocFrame));
57
+ + tpriv->num_iso_packets = transfer->num_iso_packets;
58
+ + if (!tpriv->isoc_framelist)
59
+ + return LIBUSB_ERROR_NO_MEM;
60
+ + }
61
+
62
+ /* copy the frame list from the libusb descriptor (the structures differ only is member order) */
63
+ for (i = 0 ; i < transfer->num_iso_packets ; i++)
64
+ @@ -1198,9 +1209,11 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
41
65
42
66
return darwin_to_libusb (kresult);
43
67
}
@@ -51,15 +75,15 @@ index 646c938..3900241 100644
51
75
52
76
/* submit the request */
53
77
if (is_read)
54
- @@ -1211,6 +1215 ,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
78
+ @@ -1211,6 +1224 ,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
55
79
kresult = (*(cInterface->interface))->WriteIsochPipeAsync(cInterface->interface, pipeRef, transfer->buffer, frame,
56
80
transfer->num_iso_packets, tpriv->isoc_framelist, darwin_async_io_callback,
57
81
itransfer);
58
82
+ cInterface->frames[transfer->endpoint] = frame + transfer->num_iso_packets / 8;
59
83
60
84
if (kresult != kIOReturnSuccess) {
61
85
usbi_err (TRANSFER_CTX (transfer), "isochronous transfer failed (dir: %s): %s", is_read ? "In" : "Out",
62
- @@ -1243,6 +1248 ,8 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) {
86
+ @@ -1243,6 +1257 ,8 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) {
63
87
tpriv->req.pData = transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
64
88
tpriv->req.completionTimeout = transfer->timeout;
65
89
tpriv->req.noDataTimeout = transfer->timeout;
@@ -68,7 +92,7 @@ index 646c938..3900241 100644
68
92
69
93
/* all transfers in libusb-1.0 are async */
70
94
kresult = (*(dpriv->device))->DeviceRequestAsyncTO(dpriv->device, &(tpriv->req), darwin_async_io_callback, itransfer);
71
- @@ -1358,6 +1365 ,9 @@ static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0)
95
+ @@ -1358,6 +1374 ,9 @@ static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0)
72
96
}
73
97
74
98
static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_t result) {
@@ -78,7 +102,7 @@ index 646c938..3900241 100644
78
102
switch (result) {
79
103
case kIOReturnUnderrun:
80
104
case kIOReturnSuccess:
81
- @@ -1372,6 +1382 ,7 @@ static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_
105
+ @@ -1372,6 +1391 ,7 @@ static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_
82
106
return LIBUSB_TRANSFER_OVERFLOW;
83
107
case kIOUSBTransactionTimeout:
84
108
usbi_err (ITRANSFER_CTX (itransfer), "transfer error: timed out");
@@ -87,7 +111,7 @@ index 646c938..3900241 100644
87
111
default:
88
112
usbi_err (ITRANSFER_CTX (itransfer), "transfer error: %s (value = 0x%08x)", darwin_error_str (result), result);
89
113
diff --git a/libusb/os/darwin_usb.h b/libusb/os/darwin_usb.h
90
- index a71d464..e3bdad8 100644
114
+ index a71d464..4aadf8c 100644
91
115
--- a/libusb/os/darwin_usb.h
92
116
+++ b/libusb/os/darwin_usb.h
93
117
@@ -139,6 +139,7 @@ struct darwin_device_handle_priv {
@@ -97,4 +121,12 @@ index a71d464..e3bdad8 100644
97
121
+ UInt64 frames[256];
98
122
uint8_t endpoint_addrs[USB_MAXENDPOINTS];
99
123
} interfaces[USB_MAXINTERFACES];
100
- };
124
+ };
125
+ @@ -146,6 +147,7 @@ struct darwin_device_handle_priv {
126
+ struct darwin_transfer_priv {
127
+ /* Isoc */
128
+ IOUSBIsocFrame *isoc_framelist;
129
+ + size_t num_iso_packets;
130
+
131
+ /* Control */
132
+ #if !defined (LIBUSB_NO_TIMEOUT_DEVICE)
0 commit comments