fix calculation of offset with a negative offset
This commit is contained in:
@@ -290,8 +290,8 @@ void *rtp_control_receiver(void *arg) {
|
||||
obfp += 2;
|
||||
};
|
||||
*obfp = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
// get raw timestamp information
|
||||
// I think that a good way to understand these timestamps is that
|
||||
// (1) the rtlt below is the timestamp of the frame that should be playing at the
|
||||
@@ -302,19 +302,19 @@ void *rtp_control_receiver(void *arg) {
|
||||
// Thus, (3) the latency can be calculated by subtracting the second from the
|
||||
// first.
|
||||
// There must be more to it -- there something missing.
|
||||
|
||||
|
||||
// In addition, it seems that if the value of the short represented by the second
|
||||
// pair of bytes in the packet is 7
|
||||
// then an extra time lag is expected to be added, presumably by
|
||||
// the AirPort Express.
|
||||
|
||||
|
||||
// Best guess is that this delay is 11,025 frames.
|
||||
|
||||
|
||||
uint32_t rtlt = nctohl(&packet[4]); // raw timestamp less latency
|
||||
uint32_t rt = nctohl(&packet[16]); // raw timestamp
|
||||
|
||||
|
||||
uint32_t fl = nctohs(&packet[2]); //
|
||||
|
||||
|
||||
debug(1,"Sync Packet of %d bytes received: \"%s\", flags: %d, timestamps %u and %u,
|
||||
giving a latency of %d frames.",plen,obf,fl,rt,rtlt,rt-rtlt);
|
||||
//debug(1,"Monotonic timestamps are: %" PRId64 " and %" PRId64 "
|
||||
@@ -364,17 +364,12 @@ void *rtp_control_receiver(void *arg) {
|
||||
// loop around in
|
||||
// modulo. Not sure if
|
||||
// you'll get an error!
|
||||
// debug(3, "Latency derived just from the sync packet is %" PRIu32 " frames.", la);
|
||||
// debug(1, "Latency from the sync packet is %" PRIu32 " frames.", la);
|
||||
|
||||
if ((flags == 7) || ((conn->AirPlayVersion > 0) && (conn->AirPlayVersion <= 353)) ||
|
||||
((conn->AirPlayVersion > 0) && (conn->AirPlayVersion >= 371))) {
|
||||
la += config.fixedLatencyOffset;
|
||||
// debug(3, "A fixed latency offset of %d frames has been added, giving a latency of
|
||||
// "
|
||||
// "%" PRId64
|
||||
// " frames with flags: %d and AirPlay version %d (triggers if 353 or
|
||||
// less).",
|
||||
// config.fixedLatencyOffset, la, flags, conn->AirPlayVersion);
|
||||
// debug(1, "Latency offset by %" PRIu32" frames due to the source flags and version giving a latency of %" PRIu32 " frames.", config.fixedLatencyOffset, la);
|
||||
}
|
||||
if ((conn->maximum_latency) && (conn->maximum_latency < la))
|
||||
la = conn->maximum_latency;
|
||||
@@ -394,7 +389,9 @@ void *rtp_control_receiver(void *arg) {
|
||||
// here we have the latency but it does not yet account for the
|
||||
// audio_backend_latency_offset
|
||||
int32_t latency_offset =
|
||||
(uint32_t)(config.audio_backend_latency_offset * conn->input_rate);
|
||||
(int32_t)(config.audio_backend_latency_offset * conn->input_rate);
|
||||
|
||||
// debug(1,"latency offset is %" PRId32 ", input rate is %u", latency_offset, conn->input_rate);
|
||||
int32_t adjusted_latency = latency_offset + (int32_t)la;
|
||||
if ((adjusted_latency < 0) ||
|
||||
(adjusted_latency >
|
||||
@@ -411,7 +408,7 @@ void *rtp_control_receiver(void *arg) {
|
||||
", minimum latency: %" PRIu32 ", maximum "
|
||||
"latency: %" PRIu32 ", fixed offset: %" PRIu32
|
||||
", audio_backend_latency_offset: %f.",
|
||||
la, sync_rtp_timestamp - rtp_timestamp_less_latency, conn->minimum_latency,
|
||||
conn->latency, sync_rtp_timestamp - rtp_timestamp_less_latency, conn->minimum_latency,
|
||||
conn->maximum_latency, config.fixedLatencyOffset,
|
||||
config.audio_backend_latency_offset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user