diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-23 14:07:32 +0100 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-23 14:07:32 +0100 |
commit | 1bd937ce90f34a53f5ef3ffddafb3a8e05a75214 (patch) | |
tree | 49104a3522887763afae6de56e3f2f1864929ad9 | |
parent | 676c89f7185d07e903efc1d9b109f842d3bdeb3e (diff) |
video: change RTP send timestamp to 64-bit
- change RTP timestamp for packet_handler from 32-bit to 64-bit
(extended RTP timestamp). This timestamp must be monotonically
increasing, and now the application does not have to handle
wrapping of send timestamp.
- save first/last RTP timestamp sent
-rw-r--r-- | include/baresip.h | 4 | ||||
-rw-r--r-- | modules/vidloop/vidloop.c | 2 | ||||
-rw-r--r-- | src/video.c | 31 | ||||
-rw-r--r-- | src/vidutil.c | 2 |
4 files changed, 21 insertions, 18 deletions
diff --git a/include/baresip.h b/include/baresip.h index e404e9b..e8b354a 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -892,7 +892,7 @@ struct videnc_state; struct viddec_state; struct vidcodec; -typedef int (videnc_packet_h)(bool marker, uint32_t rtp_ts, +typedef int (videnc_packet_h)(bool marker, uint64_t rtp_ts, const uint8_t *hdr, size_t hdr_len, const uint8_t *pld, size_t pld_len, void *arg); @@ -1012,7 +1012,7 @@ void video_set_devicename(struct video *v, const char *src, const char *disp); void video_encoder_cycle(struct video *video); int video_debug(struct re_printf *pf, const struct video *v); uint32_t video_calc_rtp_timestamp(int64_t pts, unsigned fps); -double video_calc_seconds(uint32_t rtp_ts); +double video_calc_seconds(uint64_t rtp_ts); struct stream *video_strm(const struct video *v); diff --git a/modules/vidloop/vidloop.c b/modules/vidloop/vidloop.c index a24dbd0..40301eb 100644 --- a/modules/vidloop/vidloop.c +++ b/modules/vidloop/vidloop.c @@ -116,7 +116,7 @@ static int display(struct video_loop *vl, struct vidframe *frame) } -static int packet_handler(bool marker, uint32_t rtp_ts, +static int packet_handler(bool marker, uint64_t rtp_ts, const uint8_t *hdr, size_t hdr_len, const uint8_t *pld, size_t pld_len, void *arg) diff --git a/src/video.c b/src/video.c index 5f55340..f6c4b18 100644 --- a/src/video.c +++ b/src/video.c @@ -97,8 +97,8 @@ struct vtx { bool muted; /**< Muted flag */ int frames; /**< Number of frames sent */ int efps; /**< Estimated frame-rate */ - uint32_t ts_min; - uint32_t ts_max; + uint64_t ts_base; /**< First RTP timestamp sent */ + uint64_t ts_last; /**< Last RTP timestamp sent */ /** Statistics */ struct { @@ -345,7 +345,7 @@ static int get_fps(const struct video *v) } -static int packet_handler(bool marker, uint32_t ts, +static int packet_handler(bool marker, uint64_t ts, const uint8_t *hdr, size_t hdr_len, const uint8_t *pld, size_t pld_len, void *arg) @@ -356,14 +356,12 @@ static int packet_handler(bool marker, uint32_t ts, uint32_t rtp_ts; int err; - /* NOTE: does not handle timestamp wrap around */ - if (ts < vtx->ts_min) - vtx->ts_min = ts; - if (ts > vtx->ts_max) - vtx->ts_max = ts; + if (!vtx->ts_base) + vtx->ts_base = ts; + vtx->ts_last = ts; /* add random timestamp offset */ - rtp_ts = vtx->ts_offset + ts; + rtp_ts = vtx->ts_offset + ts & 0xffffffff; err = vidqent_alloc(&qent, marker, strm->pt_enc, rtp_ts, hdr, hdr_len, pld, pld_len); @@ -508,8 +506,6 @@ static int vtx_alloc(struct vtx *vtx, struct video *video) tmr_start(&vtx->tmr_rtp, 1, rtp_tmr_handler, vtx); - vtx->ts_min = ~0; - return err; } @@ -1328,9 +1324,16 @@ static int vtx_debug(struct re_printf *pf, const struct vtx *vtx) vtx->vsrc_size.w, vtx->vsrc_size.h, vtx->vsrc_prm.fps, vtx->stats.src_frames); - err |= re_hprintf(pf, " skipc=%u\n", vtx->skipc); - err |= re_hprintf(pf, " time = %.3f sec\n", - video_calc_seconds(vtx->ts_max - vtx->ts_min)); + err |= re_hprintf(pf, " skipc=%u sendq=%u\n", + vtx->skipc, list_count(&vtx->sendq)); + + if (vtx->ts_base) { + err |= re_hprintf(pf, " time = %.3f sec\n", + video_calc_seconds(vtx->ts_last - vtx->ts_base)); + } + else { + err |= re_hprintf(pf, " time = (not started)\n"); + } return err; } diff --git a/src/vidutil.c b/src/vidutil.c index b55f216..9057688 100644 --- a/src/vidutil.c +++ b/src/vidutil.c @@ -41,7 +41,7 @@ uint32_t video_calc_rtp_timestamp(int64_t pts, unsigned fps) * * @return Timestamp in seconds */ -double video_calc_seconds(uint32_t rtp_ts) +double video_calc_seconds(uint64_t rtp_ts) { double timestamp; |