From: Clemens L. <cl...@la...> - 2011-02-24 16:32:59
|
Libraw1394 uses raw1394's convention of cycle numbers always being less than one second, i.e., in the range 0..7999. Firewire-core uses raw cycle numbers as used by the hardware, i.e., with several additional bits for the seconds. This was correctly handled when presenting timestamps returned by the kernel to the application, but the application's start_on_cycle value was passed directly to the kernel. To fix this, do the same calculations that ohci1394 did internally, i.e., interpret the start_on_cycle value as relative to the current seconds value of the cycle timer. Signed-off-by: Clemens Ladisch <cl...@la...> --- src/fw-iso.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) Warning: this patch is completely untested! --- libraw1394-2.0.6/src/fw-iso.c.orig +++ libraw1394-2.0.6/src/fw-iso.c @@ -21,6 +21,34 @@ #include "fw.h" #include "raw1394_private.h" +static int calculate_start_cycle(fw_handle_t handle) +{ + int cycle; + u_int32_t cycle_timer; + u_int64_t local_time; + + cycle = handle->iso.start_on_cycle; + if (cycle < 0) + return cycle; + + /* libraw1394's cycle is always mod 8000 */ + cycle &= 0x1fff; + + /* get the seconds from the current value of the cycle timer */ + if (fw_read_cycle_timer(handle, &cycle_timer, &local_time) != 0) + return cycle; + cycle += (cycle_timer & 0xfe000000) >> 12; + + /* + * For compatibility with raw1394, add one second + * "to give some extra time for DMA to start". + * TODO: are there still races due to cycle rollover? + */ + cycle += 1 << 13; + + return cycle & 0x7fff; +} + static int queue_packet(fw_handle_t handle, unsigned int length, unsigned int header_length, @@ -142,7 +170,7 @@ int fw_iso_xmit_start(raw1394handle_t ha if (fwhandle->iso.prebuffer <= fwhandle->iso.packet_count) { start_iso.sync = 0; /* unused */ start_iso.tags = 0; /* unused */ - start_iso.cycle = start_on_cycle; + start_iso.cycle = calculate_start_cycle(fwhandle); start_iso.handle = fwhandle->iso.kernel_handle; retval = ioctl(fwhandle->iso.fd, @@ -260,7 +288,8 @@ int fw_iso_recv_start(fw_handle_t handle queue_recv_packets(handle); - start_iso.cycle = start_on_cycle; + handle->iso.start_on_cycle = start_on_cycle; + start_iso.cycle = calculate_start_cycle(handle); start_iso.tags = tag_mask == -1 ? FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS : tag_mask; /* sync is documented as 'not used' */ @@ -355,7 +384,7 @@ int fw_iso_xmit_write(raw1394handle_t ha fwhandle->iso.packet_count >= fwhandle->iso.prebuffer) { /* Set this to 0 to indicate that we're running. */ fwhandle->iso.prebuffer = 0; - start_iso.cycle = fwhandle->iso.start_on_cycle; + start_iso.cycle = calculate_start_cycle(fwhandle); start_iso.handle = fwhandle->iso.kernel_handle; retval = ioctl(fwhandle->iso.fd, |