diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-24 19:11:22 +0100 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-02-24 19:11:22 +0100 |
commit | 59d29c0254b9240a00ac9236cc8e92c0ae65ec8a (patch) | |
tree | 86173746d71a3737e649ce41ce39f4bd56f1adc6 | |
parent | 73f6d3e5c86244d468499d17321fd9abfc65b9f0 (diff) |
vidcodec: change rtp_ts from 32-bit to 64-bit
the extended RTP timestamp from the video encoder
should now contain a full extended timestamp, that
must never wrap.
-rw-r--r-- | include/baresip.h | 6 | ||||
-rw-r--r-- | modules/av1/encode.c | 4 | ||||
-rw-r--r-- | modules/avcodec/encode.c | 8 | ||||
-rw-r--r-- | modules/gst_video/encode.c | 4 | ||||
-rw-r--r-- | modules/gst_video1/encode.c | 4 | ||||
-rw-r--r-- | modules/h265/encode.c | 4 | ||||
-rw-r--r-- | modules/v4l2_codec/v4l2_codec.c | 6 | ||||
-rw-r--r-- | modules/vp8/encode.c | 4 | ||||
-rw-r--r-- | modules/vp9/encode.c | 6 | ||||
-rw-r--r-- | src/h264.c | 6 | ||||
-rw-r--r-- | src/vidutil.c | 16 | ||||
-rw-r--r-- | test/mock/mock_vidcodec.c | 2 | ||||
-rw-r--r-- | test/video.c | 4 |
13 files changed, 37 insertions, 37 deletions
diff --git a/include/baresip.h b/include/baresip.h index e8b354a..e67fc8d 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -1011,7 +1011,7 @@ int video_set_source(struct video *v, const char *name, const char *dev); 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); +uint64_t video_calc_rtp_timestamp(int64_t pts, unsigned fps); double video_calc_seconds(uint64_t rtp_ts); struct stream *video_strm(const struct video *v); @@ -1143,10 +1143,10 @@ int h264_fu_hdr_decode(struct h264_fu *fu, struct mbuf *mb); const uint8_t *h264_find_startcode(const uint8_t *p, const uint8_t *end); -int h264_packetize(uint32_t rtp_ts, const uint8_t *buf, size_t len, +int h264_packetize(uint64_t rtp_ts, const uint8_t *buf, size_t len, size_t pktsize, videnc_packet_h *pkth, void *arg); int h264_nal_send(bool first, bool last, - bool marker, uint32_t ihdr, uint32_t rtp_ts, + bool marker, uint32_t ihdr, uint64_t rtp_ts, const uint8_t *buf, size_t size, size_t maxsz, videnc_packet_h *pkth, void *arg); static inline bool h264_is_keyframe(int type) diff --git a/modules/av1/encode.c b/modules/av1/encode.c index 9e24bcc..7682b16 100644 --- a/modules/av1/encode.c +++ b/modules/av1/encode.c @@ -137,7 +137,7 @@ static inline void hdr_encode(uint8_t hdr[HDR_SIZE], bool noref, bool start, } -static inline int packetize(bool marker, uint32_t rtp_ts, +static inline int packetize(bool marker, uint64_t rtp_ts, const uint8_t *buf, size_t len, size_t maxlen, bool noref, uint8_t partid, uint16_t picid, videnc_packet_h *pkth, void *arg) @@ -222,7 +222,7 @@ int av1_encode(struct videnc_state *ves, bool update, bool keyframe = false, marker = true; const aom_codec_cx_pkt_t *pkt; uint8_t partid = 0; - uint32_t ts; + uint64_t ts; pkt = aom_codec_get_cx_data(&ves->ctx, &iter); if (!pkt) diff --git a/modules/avcodec/encode.c b/modules/avcodec/encode.c index 0bdb1d3..84e4691 100644 --- a/modules/avcodec/encode.c +++ b/modules/avcodec/encode.c @@ -346,7 +346,7 @@ static void param_handler(const struct pl *name, const struct pl *val, } -static int general_packetize(uint32_t rtp_ts, struct mbuf *mb, size_t pktsize, +static int general_packetize(uint64_t rtp_ts, struct mbuf *mb, size_t pktsize, videnc_packet_h *pkth, void *arg) { int err = 0; @@ -371,7 +371,7 @@ static int general_packetize(uint32_t rtp_ts, struct mbuf *mb, size_t pktsize, static int h263_packetize(struct videnc_state *st, - uint32_t rtp_ts, struct mbuf *mb, + uint64_t rtp_ts, struct mbuf *mb, videnc_packet_h *pkth, void *arg) { struct h263_strm h263_strm; @@ -569,7 +569,7 @@ int encode_x264(struct videnc_state *st, bool update, int i_nal; int i, err, ret; int csp, pln; - uint32_t ts; + uint64_t ts; if (!st || !frame) return EINVAL; @@ -670,7 +670,7 @@ int encode(struct videnc_state *st, bool update, const struct vidframe *frame) { int i, err, ret; int pix_fmt; - uint32_t ts; + uint64_t ts; if (!st || !frame) return EINVAL; diff --git a/modules/gst_video/encode.c b/modules/gst_video/encode.c index b6dfe8a..6377785 100644 --- a/modules/gst_video/encode.c +++ b/modules/gst_video/encode.c @@ -169,14 +169,14 @@ static void internal_appsink_new_buffer(GstElement *sink, if (buffer) { GstClockTime ts; - uint32_t rtp_ts; + uint64_t rtp_ts; guint8 *data = GST_BUFFER_DATA(buffer); guint size = GST_BUFFER_SIZE(buffer); ts = GST_BUFFER_TIMESTAMP(buffer); - rtp_ts = (uint32_t)((90000ULL*ts) / 1000000000UL ); + rtp_ts = (uint64_t)((90000ULL*ts) / 1000000000UL ); h264_packetize(rtp_ts, data, size, st->pktsize, st->pkth, st->pkth_arg); diff --git a/modules/gst_video1/encode.c b/modules/gst_video1/encode.c index d0a3d44..0c3a088 100644 --- a/modules/gst_video1/encode.c +++ b/modules/gst_video1/encode.c @@ -123,7 +123,7 @@ static GstFlowReturn appsink_new_sample_cb(GstAppSink *sink, if (sample) { GstClockTime ts; - uint32_t rtp_ts; + uint64_t rtp_ts; buffer = gst_sample_get_buffer(sample); gst_buffer_map( buffer, &info, (GstMapFlags)(GST_MAP_READ) ); @@ -139,7 +139,7 @@ static GstFlowReturn appsink_new_sample_cb(GstAppSink *sink, } else { /* convert from nanoseconds to RTP clock */ - rtp_ts = (uint32_t)((90000ULL * ts) / 1000000000UL); + rtp_ts = (uint64_t)((90000ULL * ts) / 1000000000UL); } h264_packetize(rtp_ts, data, size, st->encoder.pktsize, diff --git a/modules/h265/encode.c b/modules/h265/encode.c index f4835a3..fe5f5f9 100644 --- a/modules/h265/encode.c +++ b/modules/h265/encode.c @@ -140,7 +140,7 @@ static int open_encoder(struct videnc_state *st, const struct vidsz *size) static inline int packetize(bool marker, const uint8_t *buf, size_t len, - size_t maxlen, uint32_t rtp_ts, + size_t maxlen, uint64_t rtp_ts, videnc_packet_h *pkth, void *arg) { int err = 0; @@ -195,7 +195,7 @@ int h265_encode(struct videnc_state *st, bool update, uint32_t i, nalc = 0; int colorspace; int n, err = 0; - uint32_t ts; + uint64_t ts; if (!st || !frame) return EINVAL; diff --git a/modules/v4l2_codec/v4l2_codec.c b/modules/v4l2_codec/v4l2_codec.c index 8ffd897..faf4ad1 100644 --- a/modules/v4l2_codec/v4l2_codec.c +++ b/modules/v4l2_codec/v4l2_codec.c @@ -277,7 +277,7 @@ static void enc_destructor(void *arg) } -static void encoders_read(uint32_t rtp_ts, const uint8_t *buf, size_t sz) +static void encoders_read(uint64_t rtp_ts, const uint8_t *buf, size_t sz) { struct le *le; int err; @@ -301,7 +301,7 @@ static void read_handler(int flags, void *arg) struct v4l2_buffer buf; bool keyframe = false; struct timeval ts; - uint32_t rtp_ts; + uint64_t rtp_ts; int err; if (flags & FD_EXCEPT) { @@ -350,7 +350,7 @@ static void read_handler(int flags, void *arg) #if 0 debug("v4l2_codec: %s frame captured at %ldsec, %ldusec" - " (%zu bytes) rtp_ts=%u\n", + " (%zu bytes) rtp_ts=%llu\n", keyframe ? "KEY" : " ", buf.timestamp.tv_sec, buf.timestamp.tv_usec, (size_t)buf.bytesused, rtp_ts); diff --git a/modules/vp8/encode.c b/modules/vp8/encode.c index 83f136b..6707ead 100644 --- a/modules/vp8/encode.c +++ b/modules/vp8/encode.c @@ -157,7 +157,7 @@ static inline void hdr_encode(uint8_t hdr[HDR_SIZE], bool noref, bool start, static inline int packetize(bool marker, const uint8_t *buf, size_t len, size_t maxlen, bool noref, uint8_t partid, - uint16_t picid, uint32_t rtp_ts, + uint16_t picid, uint64_t rtp_ts, videnc_packet_h *pkth, void *arg) { uint8_t hdr[HDR_SIZE]; @@ -236,7 +236,7 @@ int vp8_encode(struct videnc_state *ves, bool update, bool keyframe = false, marker = true; const vpx_codec_cx_pkt_t *pkt; uint8_t partid = 0; - uint32_t ts; + uint64_t ts; pkt = vpx_codec_get_cx_data(&ves->ctx, &iter); if (!pkt) diff --git a/modules/vp9/encode.c b/modules/vp9/encode.c index 9de4d73..2a98026 100644 --- a/modules/vp9/encode.c +++ b/modules/vp9/encode.c @@ -172,7 +172,7 @@ static inline void hdr_encode(uint8_t hdr[HDR_SIZE], bool start, bool end, static int send_packet(struct videnc_state *ves, bool marker, const uint8_t *hdr, size_t hdr_len, const uint8_t *pld, size_t pld_len, - uint32_t rtp_ts) + uint64_t rtp_ts) { ves->n_bytes += (hdr_len + pld_len); @@ -184,7 +184,7 @@ static int send_packet(struct videnc_state *ves, bool marker, static inline int packetize(struct videnc_state *ves, bool marker, const uint8_t *buf, size_t len, size_t maxlen, uint16_t picid, - uint32_t rtp_ts) + uint64_t rtp_ts) { uint8_t hdr[HDR_SIZE]; bool start = true; @@ -280,7 +280,7 @@ int vp9_encode(struct videnc_state *ves, bool update, for (;;) { bool marker = true; const vpx_codec_cx_pkt_t *pkt; - uint32_t ts; + uint64_t ts; pkt = vpx_codec_get_cx_data(&ves->ctx, &iter); if (!pkt) @@ -104,7 +104,7 @@ const uint8_t *h264_find_startcode(const uint8_t *p, const uint8_t *end) static int rtp_send_data(const uint8_t *hdr, size_t hdr_sz, const uint8_t *buf, size_t sz, - bool eof, uint32_t rtp_ts, + bool eof, uint64_t rtp_ts, videnc_packet_h *pkth, void *arg) { return pkth(eof, rtp_ts, hdr, hdr_sz, buf, sz, arg); @@ -112,7 +112,7 @@ static int rtp_send_data(const uint8_t *hdr, size_t hdr_sz, int h264_nal_send(bool first, bool last, - bool marker, uint32_t ihdr, uint32_t rtp_ts, + bool marker, uint32_t ihdr, uint64_t rtp_ts, const uint8_t *buf, size_t size, size_t maxsz, videnc_packet_h *pkth, void *arg) { @@ -153,7 +153,7 @@ int h264_nal_send(bool first, bool last, } -int h264_packetize(uint32_t rtp_ts, const uint8_t *buf, size_t len, +int h264_packetize(uint64_t rtp_ts, const uint8_t *buf, size_t len, size_t pktsize, videnc_packet_h *pkth, void *arg) { const uint8_t *start = buf; diff --git a/src/vidutil.c b/src/vidutil.c index 9057688..26d17eb 100644 --- a/src/vidutil.c +++ b/src/vidutil.c @@ -14,23 +14,23 @@ * Calculate the RTP timestamp from Presentation Time Stamp (PTS) * or Decoding Time Stamp (DTS) and framerate. * - * @note The calculated RTP Timestamp may wrap around. + * @note The calculated RTP Timestamp may NOT wrap around. * * @param pts Presentation Time Stamp (PTS) * @param fps Framerate in [frames per second] * - * @return RTP Timestamp + * @return Extended RTP Timestamp */ -uint32_t video_calc_rtp_timestamp(int64_t pts, unsigned fps) +uint64_t video_calc_rtp_timestamp(int64_t pts, unsigned fps) { - uint64_t rtp_ts; + uint64_t rtp_ts; - if (!fps) - return 0; + if (!fps) + return 0; - rtp_ts = ((uint64_t)VIDEO_SRATE * pts) / fps; + rtp_ts = ((uint64_t)VIDEO_SRATE * pts) / fps; - return (uint32_t)rtp_ts; + return rtp_ts; } diff --git a/test/mock/mock_vidcodec.c b/test/mock/mock_vidcodec.c index 9609e65..9571f73 100644 --- a/test/mock/mock_vidcodec.c +++ b/test/mock/mock_vidcodec.c @@ -88,7 +88,7 @@ static int mock_encode(struct videnc_state *ves, bool update, { struct mbuf *hdr; uint8_t payload[2] = {0,0}; - uint32_t rtp_ts; + uint64_t rtp_ts; int err; (void)update; diff --git a/test/video.c b/test/video.c index 09c5e77..c2b829b 100644 --- a/test/video.c +++ b/test/video.c @@ -30,8 +30,8 @@ int test_video(void) ASSERT_EQ( 300000000, video_calc_rtp_timestamp( 100000, 30)); ASSERT_EQ(3000000000, video_calc_rtp_timestamp(1000000, 30)); - ASSERT_EQ(4294965000, video_calc_rtp_timestamp(1431655, 30)); - ASSERT_EQ( 704, video_calc_rtp_timestamp(1431656, 30)); + ASSERT_EQ(4294965000ULL, video_calc_rtp_timestamp(1431655, 30)); + ASSERT_EQ(4294968000ULL, video_calc_rtp_timestamp(1431656, 30)); out: return err; |