ALSA: firewire-lib: record cycle count for the first packet
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 22 Mar 2017 12:30:15 +0000 (21:30 +0900)
committerTakashi Iwai <tiwai@suse.de>
Tue, 28 Mar 2017 10:33:24 +0000 (12:33 +0200)
Currently, packet streaming layer passes generated SYT value to data block
processing layer. However, this is not enough in a case that the data block
processing layer generates time stamps by its own ways.

For out-packet stream, the packet streaming layer guarantees 8,000 times
calls of data block processing layers per sec. Therefore, when cycle count
of the first packet is recorded, data block processing layers can calculate
own time stamps with the recorded value.

For the reason, this commit allows packet streaming layer to record the
first cycle count. Each data block processing layer can read the count by
accessing a member of structure for packet streaming layer.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/amdtp-stream.c
sound/firewire/amdtp-stream.h

index 00060c4a9deb4ec239f34dc857ceebf75615d65c..371cf978fbed369b72a0018c5a034d67b23a88d2 100644 (file)
@@ -671,6 +671,8 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context,
                                        void *header, void *private_data)
 {
        struct amdtp_stream *s = private_data;
+       u32 cycle;
+       unsigned int packets;
 
        /*
         * For in-stream, first packet has come.
@@ -679,10 +681,19 @@ static void amdtp_stream_first_callback(struct fw_iso_context *context,
        s->callbacked = true;
        wake_up(&s->callback_wait);
 
-       if (s->direction == AMDTP_IN_STREAM)
+       cycle = compute_cycle_count(tstamp);
+
+       if (s->direction == AMDTP_IN_STREAM) {
+               packets = header_length / IN_PACKET_HEADER_SIZE;
+               cycle = decrement_cycle_count(cycle, packets);
                context->callback.sc = in_stream_callback;
-       else
+       } else {
+               packets = header_length / 4;
+               cycle = increment_cycle_count(cycle, QUEUE_LENGTH - packets);
                context->callback.sc = out_stream_callback;
+       }
+
+       s->start_cycle = cycle;
 
        context->callback.sc(context, tstamp, header_length, header, s);
 }
index c1bc7fad056e82c62ee81e8f6a615f0a5d5fa85b..edf5646b37089c6e4cdff15b5321886e1e6f3a35 100644 (file)
@@ -130,6 +130,7 @@ struct amdtp_stream {
        /* To wait for first packet. */
        bool callbacked;
        wait_queue_head_t callback_wait;
+       u32 start_cycle;
 
        /* For backends to process data blocks. */
        void *protocol;