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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*
* Copyright (C) 2002 the xine project
*
* This file is part of xine, a unix video player.
*
* xine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* $Id: strict_scr.c,v 1.2 2002/02/09 07:13:23 guenter Exp $
*
* scr plugin that may not allow others to adjust it (used for streaming)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include "xine_internal.h"
#include "strict_scr.h"
static int strictscr_get_priority (scr_plugin_t *scr) {
return 100; /* very high priority */
}
/* Only call this when already mutex locked */
static void strictscr_set_pivot (strictscr_t *this) {
struct timeval tv;
uint32_t pts;
double pts_calc;
gettimeofday(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
pts = this->cur_pts + pts_calc;
/* This next part introduces a one off inaccuracy
* to the scr due to rounding tv to pts.
*/
this->cur_time.tv_sec=tv.tv_sec;
this->cur_time.tv_usec=tv.tv_usec;
this->cur_pts=pts;
return ;
}
static int strictscr_set_speed (scr_plugin_t *scr, int speed) {
strictscr_t *this = (strictscr_t*) scr;
pthread_mutex_lock (&this->lock);
strictscr_set_pivot( this );
this->speed_factor = (double) speed * 90000.0 / 4.0;
pthread_mutex_unlock (&this->lock);
return speed;
}
static void strictscr_adjust (scr_plugin_t *scr, int64_t vpts) {
strictscr_t *this = (strictscr_t*) scr;
struct timeval tv;
if (this->adjustable) {
pthread_mutex_lock (&this->lock);
gettimeofday(&tv, NULL);
this->cur_time.tv_sec=tv.tv_sec;
this->cur_time.tv_usec=tv.tv_usec;
this->cur_pts = vpts;
pthread_mutex_unlock (&this->lock);
}
}
static void strictscr_start (scr_plugin_t *scr, int64_t start_vpts) {
strictscr_t *this = (strictscr_t*) scr;
pthread_mutex_lock (&this->lock);
gettimeofday(&this->cur_time, NULL);
this->cur_pts = start_vpts;
pthread_mutex_unlock (&this->lock);
}
static int64_t strictscr_get_current (scr_plugin_t *scr) {
strictscr_t *this = (strictscr_t*) scr;
struct timeval tv;
int64_t pts;
double pts_calc;
pthread_mutex_lock (&this->lock);
gettimeofday(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
pts = this->cur_pts + pts_calc;
pthread_mutex_unlock (&this->lock);
return pts;
}
strictscr_t* strictscr_init () {
strictscr_t *this;
this = malloc(sizeof(*this));
memset(this, 0, sizeof(*this));
this->scr.interface_version = 2;
this->scr.get_priority = strictscr_get_priority;
this->scr.set_speed = strictscr_set_speed;
this->scr.adjust = strictscr_adjust;
this->scr.start = strictscr_start;
this->scr.get_current = strictscr_get_current;
strictscr_set_speed (&this->scr, SPEED_NORMAL);
this->adjustable = 0;
pthread_mutex_init (&this->lock, NULL);
return this;
}
|