summaryrefslogtreecommitdiff
path: root/src/vidutil.c
blob: abdddf70e828a59edc2bdb0ba3220200db333a09 (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 NOT wrap around.
 *
 * @param pts Presentation Time Stamp (PTS)
 * @param fps Framerate in [frames per second]
 *
 * @return Extended RTP Timestamp
 */
uint64_t video_calc_rtp_timestamp(int64_t pts, double fps)
{
	uint64_t rtp_ts;

	if (!fps)
		return 0;

	rtp_ts = ((uint64_t)VIDEO_SRATE * pts) / fps;

	return rtp_ts;
}


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

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

	return timestamp;
}