UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ptime.c
Go to the documentation of this file.
1/*
2 * AUTHOR: N.Cihan Tas
3 * MODIFIED: Ladan Gharai
4 * Colin Perkins
5 *
6 * This program is the playout time calculation for each frame
7 * received.
8 *
9 * Copyright (c) 2003 University of Southern California
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, is permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 *
25 * This product includes software developed by the University of Southern
26 * California Information Sciences Institute.
27 *
28 * 4. Neither the name of the University nor of the Institute may be used
29 * to endorse or promote products derived from this software without
30 * specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
34 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
35 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
36 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
42 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 *
45 *
46 */
47
48#include "config.h"
49#include "config_unix.h"
50#include "config_win32.h"
51#include "debug.h"
52#include "tv.h"
53#include "rtp/rtp.h"
54#include "rtp/rtp_callback.h"
55#include "rtp/pbuf.h"
56#include "rtp/ptime.h"
57
58#define SKEW_THRESHOLD 1500
59#define W 10 /* Window size for mapping to local timeline. */
60
61#ifdef NDEF
62/* Colin's book pg. 178 */
63static uint32_t adjustment_due_to_skew(uint32_t ts, uint32_t curr_time)
64{
65
66 static int first_time = 1;
67 static uint32_t delay_estimate;
68 static uint32_t active_delay;
69 int adjustment = 0;
70 uint32_t d_n = ts - curr_time;
71
72 if (first_time) {
73
74 first_time = 0;
75 delay_estimate = d_n;
76 active_delay = d_n;
77 } else {
78 delay_estimate = (31 * delay_estimate + d_n) / 32.0;
79 }
80
81 if (active_delay - delay_estimate > SKEW_THRESHOLD) {
82
83 adjustment = SKEW_THRESHOLD;
84 active_delay = delay_estimate;
85 }
86 if ((double)active_delay - (double)delay_estimate < -SKEW_THRESHOLD) {
87 adjustment = -SKEW_THRESHOLD;
88 active_delay = delay_estimate;
89 }
90
91 return (uint32_t) ((double)active_delay + (double)adjustment);
92}
93#endif
94
95#ifdef NDEF
96static uint32_t map_local_timeline(uint32_t ts, uint32_t curr_time)
97{
98
99 static uint32_t d[W];
100 static int w = 0;
101 static int FULL = 0;
102 uint32_t min;
103 uint32_t new_difference = ts - curr_time;
104 int i;
105
106 d[w++] = new_difference;
107
108 /* Do we have enough records? If so, begin to rewrite oldest first. */
109 if (w >= W - 1) {
110
111 FULL = 1;
112 w = 0;
113
114 }
115
116 min = d[0];
117
118 if (!FULL) {
119 for (i = 1; i < w; i++)
120 if (d[i] < min)
121 //if (((d[i] - min) & (1<<15)) != 0)
122 min = d[i];
123 } else
124 for (i = 1; i < W; i++)
125 if (d[i] < min)
126 //if (((d[i] - min) & (1<<15)) != 0)
127 min = d[i];
128
129 return (min);
130
131}
132#endif
133
134//uint32_t
135//calculate_playout_time(struct timeval atime_s, uint32_t timestamp){
136//uint32_t atime = tv_timeval2uint(atime_s);
137//return(map_local_timeline( atime , timestamp ) + adjustment_due_to_skew( atime , timestamp ));
138//}
#define W
Definition ptime.c:59
#define SKEW_THRESHOLD
Definition ptime.c:58
#define min(a, b)
Definition rtp.c:99
uint32_t ts
Definition tfrc.c:101