Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
b1d048d8
Commit
b1d048d8
authored
Sep 27, 2008
by
Laurent Aimar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect input_clock_GetTS from concurrent access.
parent
a18cf1de
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
src/input/clock.c
src/input/clock.c
+39
-5
src/input/input_clock.h
src/input/input_clock.h
+3
-0
No files found.
src/input/clock.c
View file @
b1d048d8
...
...
@@ -34,6 +34,11 @@
#include <vlc_input.h>
#include "input_clock.h"
/* TODO:
* - clean up locking once clock code is stable
*
*/
/*
* DISCUSSION : SYNCHRONIZATION METHOD
*
...
...
@@ -68,6 +73,7 @@
* new_average = (old_average * c_average + new_sample_value) / (c_average +1)
*/
/*****************************************************************************
* Constants
*****************************************************************************/
...
...
@@ -117,6 +123,9 @@ static inline clock_point_t clock_point_Create( mtime_t i_stream, mtime_t i_syst
/* */
struct
input_clock_t
{
/* */
vlc_mutex_t
lock
;
/* Reference point */
bool
b_has_reference
;
clock_point_t
ref
;
...
...
@@ -148,6 +157,7 @@ input_clock_t *input_clock_New( int i_cr_average, int i_rate )
if
(
!
cl
)
return
NULL
;
vlc_mutex_init
(
&
cl
->
lock
);
cl
->
b_has_reference
=
false
;
cl
->
ref
=
clock_point_Create
(
0
,
0
);
...
...
@@ -169,6 +179,7 @@ input_clock_t *input_clock_New( int i_cr_average, int i_rate )
void
input_clock_Delete
(
input_clock_t
*
cl
)
{
AvgClean
(
&
cl
->
drift
);
vlc_mutex_destroy
(
&
cl
->
lock
);
free
(
cl
);
}
...
...
@@ -184,6 +195,7 @@ void input_clock_Update( input_clock_t *cl,
{
bool
b_reset_reference
=
false
;
vlc_mutex_lock
(
&
cl
->
lock
);
if
(
(
!
cl
->
b_has_reference
)
||
(
i_ck_stream
==
0
&&
cl
->
last
.
i_stream
!=
0
)
)
{
...
...
@@ -224,6 +236,8 @@ void input_clock_Update( input_clock_t *cl,
cl
->
i_next_drift_update
=
i_ck_system
+
CLOCK_FREQ
/
5
;
/* FIXME why that */
}
cl
->
last
=
clock_point_Create
(
i_ck_stream
,
i_ck_system
);
vlc_mutex_unlock
(
&
cl
->
lock
);
}
/*****************************************************************************
...
...
@@ -231,9 +245,13 @@ void input_clock_Update( input_clock_t *cl,
*****************************************************************************/
void
input_clock_Reset
(
input_clock_t
*
cl
)
{
vlc_mutex_lock
(
&
cl
->
lock
);
cl
->
b_has_reference
=
false
;
cl
->
ref
=
clock_point_Create
(
0
,
0
);
cl
->
i_ts_max
=
0
;
vlc_mutex_unlock
(
&
cl
->
lock
);
}
/*****************************************************************************
...
...
@@ -241,11 +259,15 @@ void input_clock_Reset( input_clock_t *cl )
*****************************************************************************/
void
input_clock_ChangeRate
(
input_clock_t
*
cl
,
int
i_rate
)
{
vlc_mutex_lock
(
&
cl
->
lock
);
/* Move the reference point */
if
(
cl
->
b_has_reference
)
cl
->
ref
=
cl
->
last
;
cl
->
i_rate
=
i_rate
;
vlc_mutex_unlock
(
&
cl
->
lock
);
}
/*****************************************************************************
...
...
@@ -253,12 +275,17 @@ void input_clock_ChangeRate( input_clock_t *cl, int i_rate )
*****************************************************************************/
mtime_t
input_clock_GetWakeup
(
input_clock_t
*
cl
)
{
/* Not synchronized, we cannot wait */
if
(
!
cl
->
b_has_reference
)
return
0
;
mtime_t
i_wakeup
=
0
;
/* */
return
ClockStreamToSystem
(
cl
,
cl
->
last
.
i_stream
);
vlc_mutex_lock
(
&
cl
->
lock
);
/* Synchronized, we can wait */
if
(
cl
->
b_has_reference
)
i_wakeup
=
ClockStreamToSystem
(
cl
,
cl
->
last
.
i_stream
);
vlc_mutex_unlock
(
&
cl
->
lock
);
return
i_wakeup
;
}
/*****************************************************************************
...
...
@@ -269,14 +296,21 @@ mtime_t input_clock_GetTS( input_clock_t *cl,
{
mtime_t
i_converted_ts
;
vlc_mutex_lock
(
&
cl
->
lock
);
if
(
!
cl
->
b_has_reference
)
{
vlc_mutex_unlock
(
&
cl
->
lock
);
return
0
;
}
/* */
i_converted_ts
=
ClockStreamToSystem
(
cl
,
i_ts
+
AvgGet
(
&
cl
->
drift
)
);
if
(
i_converted_ts
>
cl
->
i_ts_max
)
cl
->
i_ts_max
=
i_converted_ts
;
vlc_mutex_unlock
(
&
cl
->
lock
);
return
i_converted_ts
+
i_pts_delay
;
}
...
...
src/input/input_clock.h
View file @
b1d048d8
...
...
@@ -33,6 +33,9 @@
/**
* This structure is used to manage clock drift and reception jitters
*
* XXX input_clock_GetTS can be called from any threads. All others functions
* MUST be called from one and only one thread.
*/
typedef
struct
input_clock_t
input_clock_t
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment