summaryrefslogtreecommitdiff
path: root/src/vidutil.c
blob: b55f216df15cac001acb2f8d5d58342e31b4ea5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * @file vidutil.c  Video utility functions
 *
 * Copyright (C) 2017 Creytiv.com
 */

#include <re.h>
#include <rem.h>
#include <baresip.h>
#include "core.h"


/**
 * 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)VIDEO_SRATE * pts) / fps;

       return (uint32_t)rtp_ts;
}


/**
 * Calculate the timestamp in seconds from the RTP timestamp.
 *
 * @param rtp_ts RTP Timestamp
 *
 * @return Timestamp in seconds
 */
double video_calc_seconds(uint32_t rtp_ts)
{
	double timestamp;

	/* convert from RTP clockrate to seconds */
	timestamp = (double)rtp_ts / (double)VIDEO_SRATE;

	return timestamp;
}