return -1;
}
- pa_device_port_set_latency_offset(port, (pa_usec_t) offset);
+ pa_device_port_set_latency_offset(port, offset);
return 0;
}
pa_hashmap_free(h, NULL, NULL);
}
-void pa_device_port_set_latency_offset(pa_device_port *p, pa_usec_t offset) {
+void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
uint32_t state;
pa_assert(p);
pa_hashmap *profiles; /* Does not own the profiles */
pa_bool_t is_input:1;
pa_bool_t is_output:1;
- pa_usec_t latency_offset;
+ int64_t latency_offset;
/* .. followed by some implementation specific data */
};
/* The port's available status has changed */
void pa_device_port_set_available(pa_device_port *p, pa_port_available_t available);
-void pa_device_port_set_latency_offset(pa_device_port *p, pa_usec_t offset);
+void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset);
#endif
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0);
- usec += s->latency_offset;
+ /* usec is unsigned, so check that the offset can be added to usec without
+ * underflowing. */
+ if (-s->latency_offset <= (int64_t) usec)
+ usec += s->latency_offset;
+ else
+ usec = 0;
return usec;
}
if (o->process_msg(o, PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
return -1;
- usec += s->thread_info.latency_offset;
+ /* usec is unsigned, so check that the offset can be added to usec without
+ * underflowing. */
+ if (-s->thread_info.latency_offset <= (int64_t) usec)
+ usec += s->thread_info.latency_offset;
+ else
+ usec = 0;
return usec;
}
return 0;
case PA_SINK_MESSAGE_SET_LATENCY_OFFSET:
- s->thread_info.latency_offset = (pa_usec_t) offset;
+ s->thread_info.latency_offset = offset;
return 0;
case PA_SINK_MESSAGE_GET_LATENCY:
}
/* Called from main context */
-void pa_sink_set_latency_offset(pa_sink *s, pa_usec_t offset) {
+void pa_sink_set_latency_offset(pa_sink *s, int64_t offset) {
pa_sink_assert_ref(s);
s->latency_offset = offset;
if (PA_SINK_IS_LINKED(s->state))
- pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_LATENCY_OFFSET, NULL, (int64_t) offset, NULL) == 0);
+ pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_LATENCY_OFFSET, NULL, offset, NULL) == 0);
else
s->thread_info.fixed_latency = offset;
}
pa_atomic_t mixer_dirty;
/* The latency offset is inherited from the currently active port */
- pa_usec_t latency_offset;
+ int64_t latency_offset;
unsigned priority;
pa_usec_t fixed_latency; /* for sinks with PA_SINK_DYNAMIC_LATENCY this is 0 */
/* This latency offset is a direct copy from s->latency_offset */
- pa_usec_t latency_offset;
+ int64_t latency_offset;
/* Delayed volume change events are queued here. The events
* are stored in expiration order. The one expiring next is in
/**** May be called by everyone, from main context */
pa_bool_t pa_sink_update_rate(pa_sink *s, uint32_t rate, pa_bool_t passthrough);
-void pa_sink_set_latency_offset(pa_sink *s, pa_usec_t offset);
+void pa_sink_set_latency_offset(pa_sink *s, int64_t offset);
/* The returned value is supposed to be in the time domain of the sound card! */
pa_usec_t pa_sink_get_latency(pa_sink *s);
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0);
- usec += s->latency_offset;
+ /* usec is unsigned, so check that the offset can be added to usec without
+ * underflowing. */
+ if (-s->latency_offset <= (int64_t) usec)
+ usec += s->latency_offset;
+ else
+ usec = 0;
return usec;
}
if (o->process_msg(o, PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
return -1;
- usec += s->thread_info.latency_offset;
+ /* usec is unsigned, so check that the offset can be added to usec without
+ * underflowing. */
+ if (-s->thread_info.latency_offset <= (int64_t) usec)
+ usec += s->thread_info.latency_offset;
+ else
+ usec = 0;
return usec;
}
return 0;
case PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET:
- s->thread_info.latency_offset = (pa_usec_t) offset;
+ s->thread_info.latency_offset = offset;
return 0;
case PA_SOURCE_MESSAGE_MAX:
}
/* Called from main thread */
-void pa_source_set_latency_offset(pa_source *s, pa_usec_t offset) {
+void pa_source_set_latency_offset(pa_source *s, int64_t offset) {
pa_source_assert_ref(s);
s->latency_offset = offset;
if (PA_SOURCE_IS_LINKED(s->state))
- pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET, NULL, (int64_t) offset, NULL) == 0);
+ pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_LATENCY_OFFSET, NULL, offset, NULL) == 0);
else
s->thread_info.fixed_latency = offset;
}
pa_atomic_t mixer_dirty;
/* The latency offset is inherited from the currently active port */
- pa_usec_t latency_offset;
+ int64_t latency_offset;
unsigned priority;
pa_usec_t fixed_latency; /* for sources with PA_SOURCE_DYNAMIC_LATENCY this is 0 */
/* This latency offset is a direct copy from s->latency_offset */
- pa_usec_t latency_offset;
+ int64_t latency_offset;
/* Delayed volume change events are queued here. The events
* are stored in expiration order. The one expiring next is in
/*** May be called by everyone, from main context */
-void pa_source_set_latency_offset(pa_source *s, pa_usec_t offset);
+void pa_source_set_latency_offset(pa_source *s, int64_t offset);
/* The returned value is supposed to be in the time domain of the sound card! */
pa_usec_t pa_source_get_latency(pa_source *s);