summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2020-09-02 13:36:22 +0200
committerWim Taymans <wtaymans@redhat.com>2020-09-02 13:36:22 +0200
commit6b50279364c93166b2cdc063a042a60285970faf (patch)
treed5b960845a60aa07a8df7cdcf4416d4302ea3ec3
parent4867edb9479aa5fdf0ac191b53bb216ec8ca2479 (diff)
bluez5: add a simple clock to sinks/sources
Fixes #269
-rw-r--r--spa/plugins/bluez5/a2dp-sink.c9
-rw-r--r--spa/plugins/bluez5/a2dp-source.c8
-rw-r--r--spa/plugins/bluez5/sco-sink.c9
-rw-r--r--spa/plugins/bluez5/sco-source.c11
4 files changed, 36 insertions, 1 deletions
diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c
index caa7dd5b..faeb7bf9 100644
--- a/spa/plugins/bluez5/a2dp-sink.c
+++ b/spa/plugins/bluez5/a2dp-sink.c
@@ -678,6 +678,15 @@ static int flush_data(struct impl *this, uint64_t now_time)
spa_system_timerfd_settime(this->data_system, this->timerfd, SPA_FD_TIMER_ABSTIME, &ts, NULL);
this->source.mask = SPA_IO_IN;
spa_loop_update_source(this->data_loop, &this->source);
+
+ if (this->clock) {
+ this->clock->nsec = now_time;
+ this->clock->position = this->sample_count;
+ this->clock->duration = this->write_samples;
+ this->clock->delay = queued;
+ this->clock->rate_diff = 1.0f;
+ this->clock->next_nsec = SPA_TIMESPEC_TO_NSEC(&ts.it_value);
+ }
} else {
this->start_time = now_time;
this->sample_time = 0;
diff --git a/spa/plugins/bluez5/a2dp-source.c b/spa/plugins/bluez5/a2dp-source.c
index 4724be11..41adf8c1 100644
--- a/spa/plugins/bluez5/a2dp-source.c
+++ b/spa/plugins/bluez5/a2dp-source.c
@@ -442,6 +442,14 @@ static void a2dp_on_ready_read(struct spa_source *source)
this->sample_count += datas[0].chunk->size / port->frame_size;
spa_list_append(&port->ready, &port->current_buffer->link);
port->current_buffer = NULL;
+
+ if (!this->following && this->clock) {
+ this->clock->nsec = SPA_TIMESPEC_TO_NSEC(&this->now);
+ this->clock->position = this->sample_count;
+ this->clock->delay = 0;
+ this->clock->rate_diff = 1.0f;
+ this->clock->next_nsec = this->clock->nsec;
+ }
}
/* done if there are no buffers ready */
diff --git a/spa/plugins/bluez5/sco-sink.c b/spa/plugins/bluez5/sco-sink.c
index 77b1f203..1413c16f 100644
--- a/spa/plugins/bluez5/sco-sink.c
+++ b/spa/plugins/bluez5/sco-sink.c
@@ -354,8 +354,15 @@ static void flush_data(struct impl *this)
spa_log_debug(this->log, "wrote socket data %d", written);
next_timeout = get_next_timeout(this, now_time, written / port->frame_size);
- }
+ if (this->clock) {
+ this->clock->nsec = now_time;
+ this->clock->position = this->total_samples;
+ this->clock->delay = written / port->frame_size;
+ this->clock->rate_diff = 1.0f;
+ this->clock->next_nsec = next_timeout;
+ }
+ }
/* schedule next timeout */
set_timeout(this, next_timeout);
diff --git a/spa/plugins/bluez5/sco-source.c b/spa/plugins/bluez5/sco-source.c
index 5d3dcf15..975247f9 100644
--- a/spa/plugins/bluez5/sco-source.c
+++ b/spa/plugins/bluez5/sco-source.c
@@ -335,6 +335,9 @@ static void sco_on_ready_read(struct spa_source *source)
}
datas = port->current_buffer->buf->datas;
+ /* update the current pts */
+ spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &this->now);
+
/* read */
size_read = read_data(this, (uint8_t *)datas[0].data + port->ready_offset, this->transport->read_mtu);
if (size_read < 0) {
@@ -353,6 +356,14 @@ static void sco_on_ready_read(struct spa_source *source)
this->sample_count += datas[0].chunk->size / port->frame_size;
spa_list_append(&port->ready, &port->current_buffer->link);
port->current_buffer = NULL;
+
+ if (this->clock) {
+ this->clock->nsec = SPA_TIMESPEC_TO_NSEC(&this->now);
+ this->clock->position = this->sample_count;
+ this->clock->delay = 0;
+ this->clock->rate_diff = 1.0f;
+ this->clock->next_nsec = this->clock->nsec;
+ }
}
/* done if there are no buffers ready */