diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-07-22 13:27:29 +0200 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-07-22 13:27:29 +0200 |
commit | 33206f7738cb135cadc764a13ff89c974bdbbfaa (patch) | |
tree | d472a2dd785b101a261bf43e3636195e13a882cf | |
parent | 834f7b72305fab45776c9df081a691e2b541805f (diff) |
video: add video_calc_rtp_timestamp()
-rw-r--r-- | include/baresip.h | 1 | ||||
-rw-r--r-- | src/video.c | 24 | ||||
-rw-r--r-- | test/main.c | 1 | ||||
-rw-r--r-- | test/srcs.mk | 1 | ||||
-rw-r--r-- | test/test.h | 2 | ||||
-rw-r--r-- | test/video.c | 38 |
6 files changed, 67 insertions, 0 deletions
diff --git a/include/baresip.h b/include/baresip.h index 10aaf0c..d59d23f 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -990,6 +990,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); /* diff --git a/src/video.c b/src/video.c index ad70f56..595f472 100644 --- a/src/video.c +++ b/src/video.c @@ -1351,3 +1351,27 @@ void video_set_devicename(struct video *v, const char *src, const char *disp) str_ncpy(v->vtx.device, src, sizeof(v->vtx.device)); str_ncpy(v->vrx.device, disp, sizeof(v->vrx.device)); } + + +/** + * Calculate the RTP timestamp from Presentation Time Stamp (PTS) + * or Decoding Time Stamp (DTS) and framerate. + * + * @note The calculated RTP Timestamp may wrap around. + * + * @param pts Presentation Time Stamp (PTS) + * @param fps Framerate in [frames per second] + * + * @return RTP Timestamp + */ +uint32_t video_calc_rtp_timestamp(int64_t pts, unsigned fps) +{ + uint64_t rtp_ts; + + if (!fps) + return 0; + + rtp_ts = ((uint64_t)SRATE * pts) / fps; + + return (uint32_t)rtp_ts; +} diff --git a/test/main.c b/test/main.c index b9f8601..ee3c58e 100644 --- a/test/main.c +++ b/test/main.c @@ -53,6 +53,7 @@ static const struct test tests[] = { TEST(test_ua_register_auth), TEST(test_ua_register_auth_dns), TEST(test_uag_find_param), + TEST(test_video), }; diff --git a/test/srcs.mk b/test/srcs.mk index b3a2637..5a0457d 100644 --- a/test/srcs.mk +++ b/test/srcs.mk @@ -19,6 +19,7 @@ TEST_SRCS += mos.c TEST_SRCS += net.c TEST_SRCS += play.c TEST_SRCS += ua.c +TEST_SRCS += video.c # diff --git a/test/test.h b/test/test.h index 29e9569..3d55cff 100644 --- a/test/test.h +++ b/test/test.h @@ -207,6 +207,8 @@ int test_call_video(void); int test_call_aulevel(void); int test_call_progress(void); +int test_video(void); + #ifdef __cplusplus extern "C" { diff --git a/test/video.c b/test/video.c new file mode 100644 index 0000000..09c5e77 --- /dev/null +++ b/test/video.c @@ -0,0 +1,38 @@ +/** + * @file test/video.c Baresip selftest -- video + * + * Copyright (C) 2010 - 2017 Creytiv.com + */ + +#include <re.h> +#include <baresip.h> +#include "test.h" + + +#define DEBUG_MODULE "video" +#define DEBUG_LEVEL 5 +#include <re_dbg.h> + + +int test_video(void) +{ + int err = 0; + + /* test with framerate of zero */ + ASSERT_EQ(0, video_calc_rtp_timestamp(1, 0)); + + ASSERT_EQ( 0, video_calc_rtp_timestamp( 0, 30)); + ASSERT_EQ( 3000, video_calc_rtp_timestamp( 1, 30)); + ASSERT_EQ( 30000, video_calc_rtp_timestamp( 10, 30)); + ASSERT_EQ( 300000, video_calc_rtp_timestamp( 100, 30)); + ASSERT_EQ( 3000000, video_calc_rtp_timestamp( 1000, 30)); + ASSERT_EQ( 30000000, video_calc_rtp_timestamp( 10000, 30)); + 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)); + + out: + return err; +} |