Set the MaxIsoPacket field in the endpoint info if the endpoint is

an isochronous endpoint. Use MaxIsoPacket as the iso packet size
when preparing the iso transfer.
This commit is contained in:
Sebastian Zagrodzki
2017-02-05 16:20:58 +01:00
parent 4319ef2cc2
commit f13728c6e1
2 changed files with 16 additions and 11 deletions

View File

@@ -126,15 +126,22 @@ func newConfig(dev *C.libusb_device, cfg *C.struct_libusb_config_descriptor) Con
}
i.Endpoints = make([]EndpointInfo, 0, len(ends))
for _, end := range ends {
i.Endpoints = append(i.Endpoints, EndpointInfo{
ei := EndpointInfo{
Address: uint8(end.bEndpointAddress),
Attributes: uint8(end.bmAttributes),
MaxPacketSize: uint16(end.wMaxPacketSize),
//MaxIsoPacket: uint32(C.libusb_get_max_iso_packet_size(dev, C.uchar(end.bEndpointAddress))),
PollInterval: uint8(end.bInterval),
RefreshRate: uint8(end.bRefresh),
SynchAddress: uint8(end.bSynchAddress),
})
}
if TransferType(ei.Attributes)&TRANSFER_TYPE_MASK == TRANSFER_TYPE_ISOCHRONOUS {
// bits 0-10 identify the packet size, bits 11-12 are the number of additional transactions per microframe.
// Don't use libusb_get_max_iso_packet_size, as it has a bug where it returns the same value
// regardless of alternative setting used, where different alternative settings might define different
// max packet sizes.
ei.MaxIsoPacket = uint32(end.wMaxPacketSize) & 0x07ff * (uint32(end.wMaxPacketSize)>>11&3 + 1)
}
i.Endpoints = append(i.Endpoints, ei)
}
descs = append(descs, i)
}

View File

@@ -37,10 +37,8 @@ func iso_callback(cptr unsafe.Pointer) {
}
func (end *endpoint) allocTransfer() *Transfer {
// Use libusb_get_max_iso_packet_size ?
const (
iso_packets = 8 // 128 // 242
packet_size = 2 * 960 // 1760
)
xfer := C.libusb_alloc_transfer(C.int(iso_packets))
@@ -49,7 +47,7 @@ func (end *endpoint) allocTransfer() *Transfer {
return nil
}
buf := make([]byte, iso_packets*packet_size)
buf := make([]byte, iso_packets*end.EndpointInfo.MaxIsoPacket)
done := make(chan struct{}, 1)
xfer.dev_handle = end.Device.handle
@@ -60,7 +58,7 @@ func (end *endpoint) allocTransfer() *Transfer {
xfer.length = C.int(len(buf))
xfer.num_iso_packets = iso_packets
C.libusb_set_iso_packet_lengths(xfer, packet_size)
C.libusb_set_iso_packet_lengths(xfer, C.uint(end.EndpointInfo.MaxIsoPacket))
/*
pkts := *(*[]C.struct_libusb_packet_descriptor)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&xfer.iso_packet_desc)),