bluetooth: adjust sync to source with different sample spec
authorIgor V. Kovalenko <igor.v.kovalenko@gmail.com>
Wed, 21 Apr 2021 21:09:09 +0000 (00:09 +0300)
committerPulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org>
Mon, 3 May 2021 10:49:32 +0000 (10:49 +0000)
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/544>

src/modules/bluetooth/module-bluez5-device.c

index 9cbb331..85a4191 100644 (file)
@@ -1407,7 +1407,10 @@ static void thread_func(void *userdata) {
                          * If source and sink sample specifications are not equal,
                          * expected write size needs to be adjusted accordingly.
                          */
-                        bytes_to_write += n_read;
+                        if (pa_sample_spec_equal(&u->encoder_sample_spec, &u->decoder_sample_spec))
+                            bytes_to_write += n_read;
+                        else
+                            bytes_to_write += pa_usec_to_bytes(pa_bytes_to_usec(n_read, &u->decoder_sample_spec), &u->encoder_sample_spec);
                         blocks_to_write += bytes_to_write / u->write_block_size;
                         bytes_to_write = bytes_to_write % u->write_block_size;
                     }