diff options
-rw-r--r-- | sound/firewire/amdtp-stream.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index 46f1167bf69f..4d86da0355ba 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c | |||
@@ -566,6 +566,13 @@ static inline u32 increment_cycle_count(u32 cycle, unsigned int addend) | |||
566 | return cycle; | 566 | return cycle; |
567 | } | 567 | } |
568 | 568 | ||
569 | static inline u32 decrement_cycle_count(u32 cycle, unsigned int subtrahend) | ||
570 | { | ||
571 | if (cycle < subtrahend) | ||
572 | cycle += 8 * CYCLES_PER_SECOND; | ||
573 | return cycle - subtrahend; | ||
574 | } | ||
575 | |||
569 | static void out_stream_callback(struct fw_iso_context *context, u32 tstamp, | 576 | static void out_stream_callback(struct fw_iso_context *context, u32 tstamp, |
570 | size_t header_length, void *header, | 577 | size_t header_length, void *header, |
571 | void *private_data) | 578 | void *private_data) |
@@ -607,6 +614,7 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp, | |||
607 | unsigned int payload_quadlets, max_payload_quadlets; | 614 | unsigned int payload_quadlets, max_payload_quadlets; |
608 | unsigned int data_blocks; | 615 | unsigned int data_blocks; |
609 | __be32 *buffer, *headers = header; | 616 | __be32 *buffer, *headers = header; |
617 | u32 cycle; | ||
610 | 618 | ||
611 | if (s->packet_index < 0) | 619 | if (s->packet_index < 0) |
612 | return; | 620 | return; |
@@ -614,10 +622,16 @@ static void in_stream_callback(struct fw_iso_context *context, u32 tstamp, | |||
614 | /* The number of packets in buffer */ | 622 | /* The number of packets in buffer */ |
615 | packets = header_length / IN_PACKET_HEADER_SIZE; | 623 | packets = header_length / IN_PACKET_HEADER_SIZE; |
616 | 624 | ||
625 | cycle = compute_cycle_count(tstamp); | ||
626 | |||
627 | /* Align to actual cycle count for the last packet. */ | ||
628 | cycle = decrement_cycle_count(cycle, packets); | ||
629 | |||
617 | /* For buffer-over-run prevention. */ | 630 | /* For buffer-over-run prevention. */ |
618 | max_payload_quadlets = amdtp_stream_get_max_payload(s) / 4; | 631 | max_payload_quadlets = amdtp_stream_get_max_payload(s) / 4; |
619 | 632 | ||
620 | for (p = 0; p < packets; p++) { | 633 | for (p = 0; p < packets; p++) { |
634 | cycle = increment_cycle_count(cycle, 1); | ||
621 | buffer = s->buffer.packets[s->packet_index].buffer; | 635 | buffer = s->buffer.packets[s->packet_index].buffer; |
622 | 636 | ||
623 | /* The number of quadlets in this packet */ | 637 | /* The number of quadlets in this packet */ |