Commit aad5f30a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

RTP: use the right frequency for jitter computation

parent 08b2e648
...@@ -192,6 +192,10 @@ rtp_source_destroy (demux_t *demux, const rtp_session_t *session, ...@@ -192,6 +192,10 @@ rtp_source_destroy (demux_t *demux, const rtp_session_t *session,
free (source); free (source);
} }
static inline uint8_t rtp_ptype (const block_t *block)
{
return block->p_buffer[1] & 0x7F;
}
static inline uint16_t rtp_seq (const block_t *block) static inline uint16_t rtp_seq (const block_t *block)
{ {
...@@ -205,6 +209,24 @@ static inline uint32_t rtp_timestamp (const block_t *block) ...@@ -205,6 +209,24 @@ static inline uint32_t rtp_timestamp (const block_t *block)
return GetDWBE (block->p_buffer + 4); return GetDWBE (block->p_buffer + 4);
} }
static const struct rtp_pt_t *
rtp_find_ptype (const rtp_session_t *session, rtp_source_t *source,
const block_t *block, void **pt_data)
{
uint8_t ptype = rtp_ptype (block);
for (unsigned i = 0; i < session->ptc; i++)
{
if (session->ptv[i].number == ptype)
{
if (pt_data != NULL)
*pt_data = source->opaque[i];
return &session->ptv[i];
}
}
return NULL;
}
/** /**
* Receives an RTP packet and queues it. * Receives an RTP packet and queues it.
* @param demux VLC demux object * @param demux VLC demux object
...@@ -278,17 +300,22 @@ rtp_receive (demux_t *demux, rtp_session_t *session, block_t *block) ...@@ -278,17 +300,22 @@ rtp_receive (demux_t *demux, rtp_session_t *session, block_t *block)
tab[session->srcc++] = src; tab[session->srcc++] = src;
/* Cannot compute jitter yet */ /* Cannot compute jitter yet */
} }
else if (session->ptc > 0) else
{ {
/* Recompute jitter estimate. That is computed from the RTP timestamps const rtp_pt_t *pt = rtp_find_ptype (session, src, block, NULL);
* and the system clock. It is independent of RTP sequence. */
/* FIXME: payload types have the same frequency? */ if (pt != NULL)
uint32_t freq = session->ptv[0].frequency; {
uint32_t ts = rtp_timestamp (block); /* Recompute jitter estimate.
int64_t d = ((now - src->last_rx) * freq) / CLOCK_FREQ; * That is computed from the RTP timestamps and the system clock.
d -= ts - src->last_ts; * It is independent of RTP sequence. */
if (d < 0) d = -d; uint32_t freq = pt->frequency;
src->jitter += ((d - src->jitter) + 8) >> 4; uint32_t ts = rtp_timestamp (block);
int64_t d = ((now - src->last_rx) * freq) / CLOCK_FREQ;
d -= ts - src->last_ts;
if (d < 0) d = -d;
src->jitter += ((d - src->jitter) + 8) >> 4;
}
} }
src->last_rx = now; src->last_rx = now;
src->last_ts = rtp_timestamp (block); src->last_ts = rtp_timestamp (block);
...@@ -367,23 +394,12 @@ rtp_decode (demux_t *demux, const rtp_session_t *session, rtp_source_t *src) ...@@ -367,23 +394,12 @@ rtp_decode (demux_t *demux, const rtp_session_t *session, rtp_source_t *src)
src->last_seq = rtp_seq (block); src->last_seq = rtp_seq (block);
/* Match the payload type */ /* Match the payload type */
const rtp_pt_t *pt = NULL; void *pt_data;
void *pt_data = NULL; const rtp_pt_t *pt = rtp_find_ptype (session, src, block, &pt_data);
const uint8_t ptype = block->p_buffer[1] & 0x7F;
for (unsigned i = 0; i < session->ptc; i++)
{
if (session->ptv[i].number == ptype)
{
pt = &session->ptv[i];
pt_data = src->opaque[i];
break;
}
}
if (pt == NULL) if (pt == NULL)
{ {
msg_Dbg (demux, "ignoring unknown payload (%"PRIu8")", ptype); msg_Dbg (demux, "ignoring unknown payload (%"PRIu8")",
rtp_ptype (block));
goto drop; goto drop;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment