[FFmpeg-cvslog] rtpenc: Simplify code by introducing a macro for rescaling NTP timestamps

Martin Storsjö git at videolan.org
Thu Aug 1 11:47:16 CEST 2013


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Wed Jan  9 18:55:52 2013 +0200| [2e814d0329aded98c811d0502839618f08642685] | committer: Martin Storsjö

rtpenc: Simplify code by introducing a macro for rescaling NTP timestamps

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2e814d0329aded98c811d0502839618f08642685
---

 libavformat/rtp.h    |    3 +++
 libavformat/rtpenc.c |    3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtp.h b/libavformat/rtp.h
index f8d406e..feaf167 100644
--- a/libavformat/rtp.h
+++ b/libavformat/rtp.h
@@ -23,6 +23,7 @@
 
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
+#include "libavutil/mathematics.h"
 
 /**
  * Return the payload type for a given stream used in the given format context.
@@ -109,4 +110,6 @@ enum RTCPType {
 #define RTP_PT_IS_RTCP(x) (((x) >= RTCP_FIR && (x) <= RTCP_IJ) || \
                            ((x) >= RTCP_SR  && (x) <= RTCP_TOKEN))
 
+#define NTP_TO_RTP_FORMAT(x) av_rescale((x), INT64_C(1) << 32, 1000000)
+
 #endif /* AVFORMAT_RTP_H */
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index c82a73a..d330607 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -273,8 +273,7 @@ static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
     avio_w8(s1->pb, RTCP_SR);
     avio_wb16(s1->pb, 6); /* length in words - 1 */
     avio_wb32(s1->pb, s->ssrc);
-    avio_wb32(s1->pb, ntp_time / 1000000);
-    avio_wb32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000);
+    avio_wb64(s1->pb, NTP_TO_RTP_FORMAT(ntp_time));
     avio_wb32(s1->pb, rtp_ts);
     avio_wb32(s1->pb, s->packet_count);
     avio_wb32(s1->pb, s->octet_count);



More information about the ffmpeg-cvslog mailing list