[vlc-commits] [Git][videolan/vlc][master] 28 commits: decoder: start the clock with the first picture date
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sun Nov 29 09:52:19 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
f5142f23 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
decoder: start the clock with the first picture date
The input decoder is waiting for two frames before unblocking the
buffering phase and the first one gets displayed but the clock gets
started with the second picture date instead of the first then. This
date is used for context selection and providing the wrong one might
lead to unwanted consequences, like setting up the wrong wait_sync_ref
start date pseudo-randomly depending on whether the video output was
faster than the audio output.
- - - - -
11f1e006 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: move clock context log to debug level
- - - - -
82c792bc by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: switch all clocks when main is reset
This is necessary for now because vlc_clock_main_Reset() is still used
in the codebase, but it should be noted that a reset of the clock bus
doesn't actually translate into a reset of the underlying pipeline
because we cannot trigger event from the clock to the output.
Indeed, the output is using the clock itself, usually under its own
pipeline lock, and it might lead to deadlocking, since we'd need the
clock lock to trigger this from another context.
The proper way is to let the pipeline actually handle the flush by:
- resetting the input vlc_clock to have a new context
- flush every outputs and other client clocks to make them reset their
clock too
This would trigger the same result, without going through the clock bus.
The vlc_clock_main_Reset() will eventually be deleted.
In the current version, a parameter is added so that
vlc_clock_main_SetFirstPcr doesn't switch and only
vlc_clock_main_Reset does the switch.
The original commit was made by Thomas who also noticed this issue and
provided a patch for it, but suffered from use-after-free issues because
of how contexts are unprovisioned. I also added the parameter to handle
this case and detailed the rationale for the commit as well as when it
will be removed for a proper solution.
Co-authored-by: Thomas Guillem <thomas at gllm.fr>
- - - - -
2540a8aa by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: check context when switching
vlc_clock_switch_context is releasing the old context when switching so
make sure we're not switching for the same context. This allows using
vlc_clock_switch_context() in every scenario to factor the logging and
make it readable.
- - - - -
2b347f46 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: free the previous contexts only after usage
When a clock switched from a previous context, the context was freed as
soon as no clock used it anymore, even though some clocks might not be
using this context yet because they are playing an even earlier context.
prev_contexts: A --> B --> context: C
| | |
video input ------------>|
B freed while video
hasn't switched to it
In that case, the video output is converting the points from B using the
clock context A.
Free the previous contexts from the oldest one instead, but only if they
are not used anymore, and stop at the first one still used. Note that
the wrong context can still be picked after this commit.
- - - - -
1823f4ff by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: use vlc_clock_switch_context() in output start
We can use the function now that it checks the edge case of switching to
the same current context, which avoids specific code for this case.
- - - - -
e07a7cc8 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: remove assertion on start_time
The assertion is checking that the context was properly started before a
reset but seek can trigger this assertion.
This is reachable only once vlc_clock_Start() is the main mechanism
since it needs clock->context->system_time to be defined, but this check
doesn't actually protect it from the main_clock->context being yet to be
started.
Remove the assertion as it's not true.
- - - - -
a900e743 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: keep the unstarted main context on input reset
The input clock only switches to the main context when it is started,
while the outputs switch to it when they are reset. When the input is
reset twice before being started again, the second reset will pick the
main context used by the outputs but never started, which moves it to
previous contexts.
The outputs then stay on a context that will never be started until
their next start.
Keep the main context when it was not started: the input clock will
start it, and the outputs already attached to it convert from it.
This is not yet needed since we are using vlc_clock_main_SetFirstPcr for
now, so it returns early here. But once we fully switch to
vlc_clock_Start, it becomes visible when seeking multiple times. Note
that seeking while not being really started yet at the output level is
already an issue that was triggering assertions in the past.
- - - - -
892956db by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: clock: check the outputs after resetting the input clock twice
When the input clock is reset twice before being started again, the
outputs reset in between are attached to a main context that will never
be started, and they must convert through the context the input starts
afterwards.
This test is a non-regression test for this case.
- - - - -
7f799abc by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
es_out: reset the input vlc_clock before the decoders
EsOutChangePosition() is flushing the decoders before resetting the
input vlc_clock. The flush resets the output clocks synchronously, which
attaches them to the current context from main clock, and the input
reset then moves this context to the previous contexts while the outputs
still use it.
This does not matter as long as the end of the buffering resets the main
clock, which moves every clock to the main context. But once the input
vlc_clock is restarted with vlc_clock_Start() instead, the outputs will
stay on the context from before the seek and would pick it again when
starting if their first picture converts to their last date through it.
For instance, when seeking to the same position: the pictures are then
scheduled from the previous timeline and the first ones are late.
Reset the input clock first, so that the flush attaches the outputs to
the context the input vlc_clock will start.
- - - - -
0722846f by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: convert using start_time when wait_sync_ref is undefined
wait_sync_ref is defined when the output clock is driving the bus but is
not yet started and the outputs need to share a potential startup date.
In that case, the input vlc_clock must already be started with the
clock-start mechanism and we can use this date to setup the start.
- - - - -
95ca11a5 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
audio_output: keep clock_id in sync on seek
Since 1ed24f1195b490f7b9a8f3e35d9dc0ee0e72be43, stream_ClockConvert()
only detects a changed clock_id when sync.played was already true, so
the first frame after a flush (in particular, in the case of a seek)
kept the stale clock_id. The second frame then detected a context change
and triggered the discontinuity recovery, leading to silence right after
a seek under clock-master=audio or monotonic.
Record the new clock_id whenever it changes, and only trigger the
recovery when we had already played on the previous context.
It is not harmful as long as we use vlc_clock_main_SetFirstPcr and
vlc_clock_main_Reset() since the contexts are reset then, but as soon as
we switch to vlc_clock_Start(), we'll reproduce this problem with a seek
that creates a new clock context.
- - - - -
bedfd987 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: clock: adapt to vlc_clock_Start()
Adapt the [contexts] scenario to clock start, and add a second clock to
test conversion against an older context.
Note that wait_sync_ref should not be reset when resetting a derived
clock. reset() should only let the clock switch context, and the clock
bus chooses the best start time for the context.
- - - - -
f8e04d3d by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
input: es_out: resume the main clock before the input clock
Since commit abd8991d8e22ef3a3629259cd4442b168e264eda, the input_clock
is also generating points to the main clock on different events,
including resuming from pause.
It means that the order for pausing the input_clock vs the vlc clock
must be properly reversed, so that the points are not moved twice the
amount of pause. This is particularly important for unpausing since both
implementation are applying the offset there, and harmless currently for
pausing, but this commit fixes it for good.
This is the proper fix for 4174da77cfa04d3c653e9e533ae1a0aefa4d57d6.
Refs #29468
Refs #30247
Refs #30180
- - - - -
192539d9 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: refactor time shift into a function
When resuming from pause, vlc_clock_main_ChangePause() shifted the
reference points of the current context of the main clock by the pause
duration.
Move this shift to context_resume() so that it can be applied to the
other contexts of the main clock. No functional changes.
- - - - -
caba2c67 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: use pause date for monotonic startup while paused
vlc_clock_monotonic_to_system() is currently creating startup point
without reference clocks. When the point is created while paused, the
system time associated with it was the current date but it would be
shifted as soon as we resume, by the difference against the pause date.
We need to setup the monotonic startup point at the pause date so that
it can behave properly when starting up.
The main clock reset still clears the pause date at this point, so this
will mostly change the situation later in following commits. It does
apply in some cases when the first conversion happens while paused
before any update of the master clock.
- - - - -
2c789b44 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
es_out: use the pause date for the first PCR after a discontinuity
This is the same fix as for the previous PCR update fix during
buffering, but this time happening during a discontinuity where new
points are setup as reference.
When the input clock detects a stream discontinuity, the first PCR of
the main clock is set with vlc_tick_now(). In our other locations, we've
fixed the pause case to use the pause date instead. Since this location
is not updated, and since the pause date is a clock bus property, it
accumulates during resume across the two timelines.
pause date discontinuity
-----|------------|-----------------> system time (clock context 0)
offset applied on resume
<------------------>
<-late value-> resume date
-----+------------|-----|-----------> system time (clock context 1)
|
| vlc_clock_main_SetFirstPcr()
| with system_time = vlc_tick_now()
even while paused, and vlc_clock_main_SetFirstPcr() starts a new clock
context on the main clock, so the resume does not shift the new
reference anymore.
With the monotonic clock source, the frames following a discontinuity
received while paused were played late after resuming, by the time
spent paused after the discontinuity. This will be fixed in further
commits.
Use the pause date while paused, like when the buffering ends while
paused. The main clock reset still clears the pause date at this point,
so this will only change the situation later in following commits when
rate = 1x. Above 1x, the timeline is however started earlier.
- - - - -
617c9c00 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: shift every context + last_conversion when resuming
When resuming from pause, only the current context of the main clock was
shifted by the pause duration. After a discontinuity, the previous
contexts stay in prev_contexts as long as an output still converts data
to be rendered, and their reference points were left before the pause.
The frames of the old timeline still held by the outputs were then
converted as if no pause happened and played late by the pause duration,
both when pausing after the discontinuity and (later in the branch) when
the discontinuity happens while paused.
This is not supposed to happen in usual scenarios but could happen when
pausing right after a discontinuity or (also later in the branch) when
more data is needed from the demuxer while paused.
Note that this commit _also_ shifts the last_conversion which is
necessary since context selection relies on it.
- - - - -
30b4cdac by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: keep the pause date on reset
Since commit 4174da77cfa04d3c653e9e533ae1a0aefa4d57d6, resetting the
main clock clears the pause_date but leaves the clock paused.
This happens when seeking while the player is paused in particular: the
buffering ends while paused and es_out sets the first PCR of the main
clock from the pause date, but the reset cleared the pause date so the
resume returns early without shifting anything. The points stay dated
from the pause date and are late by the time spent paused, leading to
lots of drops.
pause date seek / buffering end resume date
-----|-----------------------|--------------------------|-----> t
first PCR |
<-------------------------------------------------->
offset not applied on resume
The same happens when the master clock is deleted while paused with an
input master, since deleting it also resets the main clock.
The pause date was cleared because the first PCR after a seek while
paused used to be dated with vlc_tick_now(), and shifting it on resume
moved it too far. Now that the end of buffering uses the pause date
while paused, the pause date is a state of the main clock that the reset
must keep, like the paused state.
Note that the shift from the previous commit now also applies after a
main clock reset, since we will keep this pause date starting from this
commit. It also means that a discontinuity happening while paused will
no longer have vlc_clock_main_SetFirstPcr() clear the pause date, so the
previous changes on discontinuity will apply from now on.
In addition, the last_conversion is also shifted in the previous commit
so we need to handle this special case too since the context is chosen
by how close it is to last_conversion. Without this, it would break
subtitle tracks when the subtitles were not displayed yet before pausing
and seeking, by converting using the older context and making the
presentation late. In this commit, the last_conversion is set up on the
pause date when it's updated while paused, if the output clock is first
started while paused.
This raises the question when multiple contexts are piling up at the
pause date, which is very niche though. When several discontinuities are
triggered while paused, they will all start at the pause date. This is
preexisting and might be solved at some point.
Partial revert from 4174da77cfa04d3c653e9e533ae1a0aefa4d57d6.
Ref #29468
Ref #30247
Ref #30180
- - - - -
94c6d63d by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: clock_start: check the previous contexts are shifted on resume
Check the conversion of the old context after resuming, when pausing
after the discontinuity and when the discontinuity happens while
paused, with the new timeline started from vlc_clock_main_SetFirstPcr()
and from vlc_clock_Start() on the input clock.
This is a non-regression test for the two previous commits that shift
every context when resuming from pause.
- - - - -
53bc6637 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: clock_start: check monotonic startup with SetFirstPcr
Check that a conversion done after calling SetFirstPcr, which will be
setting up the monotonic startup point since no clock calls
vlc_clock_Start(), doesn't break when it's setup during pause.
When the input dejitter is used, now is not used, but when the output
dejitter is used, the startup is made using now and the pause matters
then.
Note: the test is useless w.r.t. vlc_clock_Start() and should be deleted
once the switch is fully done. In practice, the switch to
vlc_clock_Start() will always setup the startup point for the input
when it's the master clock so it won't trigger this startup either.
- - - - -
d1722da6 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: es_out: keep the clock paused when buffering ends while paused
This provides the base scenario for testing PCR updates during pause in
the es_out. To that end, the current time is mocked also.
- - - - -
a21219d9 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
clock: start the outputs on the pause date while paused
When seeking while paused, the buffering ends during the pause and the
decoders start their output clock with vlc_tick_now(), but es_out
starts the input clock from the pause date in that case.
Since the pause date is then used when resuming from pause to offset
everything, the output start date ends up much later than the input
start date, depending on the pause duration.
pause_date output start time
--------|--------------------------|-------------> system time
| |
vlc_clock_Start(input) vlc_clock_Start(output)
<-------------------------->
extra offset on resume
applied to wait_sync_ref
The wait_sync_ref computed from the output start date was then moved
ahead of time by the extra offset on resume in the graph, i.e. the time
spent since the pause was triggered.
It currently doesn't happen but it will be triggered once we switch
fully to the vlc_clock_Start() mechanism.
- - - - -
105416e4 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: clock_start: check the clock dates of outputs
Add a test to ensure that whenever an output is started while paused, it
is started on the pause date instead of the provided date so that
resuming start it at the proper date.
- - - - -
ac7e3410 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
es_out: use the pause date for PCR received while paused
Regression from commit ec61ad747487a721d220aabf9723a05971e3c40d
Triggered because of the commits:
- ec61ad747487a721d220aabf9723a05971e3c40d
- b529d4e20e10027d0a5c42945335819e34343f64
- 9dd9d811bf4a43f249ba8e20ebd0d0401a0ce4ee (makes it very visible)
The first one shows the pause state was not handled everywhere and
is really linked to the current issue. The second one is the trigger
condition that was added back then to let the SPU decode on startup
instead of waiting, but was broken by the third one. The two last ones
are mainly the trigger that allows the problem to be visible but are
fixed in a follow-up commit.
The PCR system date was only set to the pause date while rebuffering
after ec61ad747487a721d220aabf9723a05971e3c40d. A PCR received while the
user paused the playback was set at vlc_tick_now(), although the input
clock is paused too and will shift its point by the pause duration when
the playback resumes.
<-------- PCR late value --------->
pause date buffering end PCR received resume time
-----|----------|----------------------|-------|-----> system time
<----------------------------------------->
additional offset added by resume,
leading to the PCR being late
This happens after a seek while paused, since the input keeps demuxing
while paused when a decoder requests more data for the next frame. In
particular, since b529d4e20e10027d0a5c42945335819e34343f64, SPU_ES
continue decoding even after the wait, which is necessary to display
early, but since 9dd9d811bf4a43f249ba8e20ebd0d0401a0ce4ee, it _also_
asks for more data indefinitely since this commit was written for the
video output that would consume the frames countdown.
With an SPU track then, PCR were always received and shifted
incorrectly.
./bin/vlc-static vv \
--sub-track=0 \
--clock-master=input \
"mock://video_track_count=1;audio_track_count=1;sub_track_count=1;length=300000000;video_colorbar=true"
With clock-master=input, the input clock origin is set on the pause date
at the end of the buffering, so every PCR post-buffering during pause
are considered late by the time spent in pause, which forces a new
buffering through ES_OUT_RESET_PCR and increased the pts-delay, in a
loop that lasts until the playback resumed.
With the command above, pause and seek right, and it keeps doing:
[00007dfff4bf4080] main input debug: Buffering 97%
[00007dfff4bf4080] main input debug: Buffering 98%
[00007dfff4bf4080] main input debug: Buffering 99%
[00007dfff4bf4080] main input debug: Stream buffering done (5120 ms in 86 ms)
[00007dfff4bf4080] main input debug: Decoder wait done in 0 ms
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input error: ES_OUT_SET_(GROUP_)PCR is called 4682 ms late (jitter of 9160 ms ignored)
[00007dfff4bf4080] main input debug: ES_OUT_RESET_PCR called
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007d0ff4c20c80] [clock] main generic warning: resetting master clock: coefficient too unstable: 251.451650
[00007dfff4bf4080] main input debug: Buffering 0%
[00007daff4bf0380] main decoder debug: Received first picture
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: Buffering 1%
Note that the problem would not have been visible if the PCR was not
received in the first place, real issue fixed here is forgetting the
case from commit ec61ad747487a721d220aabf9723a05971e3c40d.
Also independently found by Pierre Bogdanovscky.
Refs #30233
- - - - -
1a6c9bf3 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: es_out: check post-buffering PCR received while paused
A PCR received after the end of the buffering while paused was using
vlc_tick_now() instead of the pause date, so the input clock considered
it late by the time spent paused, which triggered PCR reset and started
buffering again.
PCR
^
| first PCR post buffering
| v
| / . . . . . . . . . . . . . . ./
+ -- / -------buffering end ^
| / where the es_out
| / see the PCR
| /
+-----|------------------------------|----> time
<-------PCR late value--------->
This commit adds a non-regression test that ensures the fixes are
properly in place for this, which is particularly important given that
situation where PCRs are received post-buffering while paused is quite
uncommon.
It uses the flush() detection from the input decoder mock to check
whether the es_out has triggered the RESET_PCR or not but builds on the
existing pause test.
- - - - -
a72e6a93 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
decoder: only request next-frame data for video
frames_countdown is defined for SPU_ES and VIDEO_ES, and set to 1 when
flushing, but even though it's handled for VIDEO_ES, it always stays at
the value 1 for SPU_ES. The decoder thread only blocks when
frames_countdown = 0, so it makes the SPU decoder running, which makes
the input decoder request more data and lead to extra demuxing.
This is particularly visible when seeking in pause mode since it starts
demuxing up to the end of the file.
Regression from commit 9dd9d811bf4a43f249ba8e20ebd0d0401a0ce4ee.
Triggered because of b529d4e20e10027d0a5c42945335819e34343f64 too, which
added the frames_countdown increase for SPU_ES without accounting for
the input decoder side. Setting frames_countdown = 1 is accurate to
force the decoder doing the decoding without waiting. But the code path
that leads to asking more data from the demuxer must be bound to the
video output so that the SPU is displayed only if it's part of the
buffering itself.
The problem can be reproduced regardless of the reference clock, with:
./bin/vlc-static vv \
--sub-track=0 \
"mock://video_track_count=1;audio_track_count=1;sub_track_count=1;length=300000000;video_colorbar=true"
After previous commits, there's no RESET_PCR issues, but the demuxing is
still ongoing. With the command above, pause and seek right, and it
keeps doing:
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007daff4bf0380] main decoder warning: decoder/packetizer fifo full (data not consumed quickly enough), resetting fifo!
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
[00007dfff4bf4080] main input debug: control type=35
This does not yet fix the subpictures not being displayed on seek and
disappearing on pause but this will be fixed in another commit.
- - - - -
2db16fa5 by Alexandre Janniaux at 2026-11-29T10:02:14+01:00
test: es_out: check PCR during discontinuity while paused
The outputs and the PCR received while paused are dated with the pause
date, so that the resume shifts them like the input clock origin, but
nothing checked the dates obtained after resuming.
Add an es_out test buffering and receiving PCR while paused with the
monotonic and input clock sources, with and without a stream
discontinuity.
- - - - -
7 changed files:
- src/audio_output/dec.c
- src/clock/clock.c
- src/input/decoder.c
- src/input/es_out.c
- src/input/test/es_out.c
- test/src/clock/clock.c
- test/src/clock/clock_start.c
Changes:
=====================================
src/audio_output/dec.c
=====================================
@@ -824,10 +824,11 @@ static vlc_tick_t stream_ClockConvert(vlc_aout_stream *stream,
stream->sync.rate, &clock_id);
vlc_clock_Unlock(stream->sync.clock);
- if (clock_id != stream->sync.clock_id && stream->sync.played)
+ if (clock_id != stream->sync.clock_id)
{
stream->sync.clock_id = clock_id;
- return VLC_TICK_INVALID;
+ if (stream->sync.played)
+ return VLC_TICK_INVALID;
}
return play_date;
}
=====================================
src/clock/clock.c
=====================================
@@ -277,8 +277,33 @@ static vlc_tick_t context_stream_to_system(const struct vlc_clock_context *ctx,
+ ctx->start_time.system;
}
+static void context_resume(struct vlc_clock_context *ctx,
+ vlc_tick_t delay)
+{
+ vlc_clock_t *clock;
+ vlc_list_foreach(clock, &ctx->using_clocks, node)
+ if (clock->last_conversion != VLC_TICK_INVALID)
+ clock->last_conversion += delay;
+
+ /**
+ * Only apply a delay if the clock has a reference point to avoid
+ * messing up the timings if the stream was paused then seeked
+ */
+ if (ctx->last.system != VLC_TICK_INVALID)
+ {
+ ctx->last.system += delay;
+ if (ctx->start_time.system == VLC_TICK_INVALID)
+ ctx->offset += delay;
+ }
+ if (ctx->start_time.system != VLC_TICK_INVALID)
+ ctx->start_time.system += delay;
+ if (ctx->wait_sync_ref.system != VLC_TICK_INVALID)
+ ctx->wait_sync_ref.system += delay;
+}
+
static void
-vlc_clock_remove_current_context(vlc_clock_t *clock)
+vlc_clock_remove_current_context(vlc_clock_t *clock,
+ const struct vlc_clock_context *next)
{
vlc_clock_main_t *main_clock = clock->owner;
struct vlc_clock_context *ctx = clock->context;
@@ -291,12 +316,16 @@ vlc_clock_remove_current_context(vlc_clock_t *clock)
/* Free the context if it is not used anymore. Don't free the main context
* that should stay alive even when no clocks are referencing it. */
- if (vlc_list_is_empty(&ctx->using_clocks) && ctx != main_clock->context)
+ struct vlc_clock_context *prev;
+ vlc_list_foreach(prev, &main_clock->prev_contexts, node)
{
- /* Remove the context from the list of previous contexts */
- vlc_list_remove(&ctx->node);
- free(ctx);
- removed = true;
+ if (prev == next || !vlc_list_is_empty(&prev->using_clocks))
+ break;
+
+ if (prev == ctx)
+ removed = true;
+ vlc_list_remove(&prev->node);
+ free(prev);
}
clock->context = NULL;
@@ -318,11 +347,16 @@ vlc_clock_switch_context(vlc_clock_t *clock, struct vlc_clock_context *ctx)
{
vlc_clock_main_t *main_clock = clock->owner;
- vlc_clock_remove_current_context(clock);
+ if (clock->context == ctx)
+ return;
+
+ vlc_clock_remove_current_context(clock, ctx);
+ if (ctx == NULL)
+ return;
vlc_clock_attach_context(clock, ctx);
if (main_clock->logger != NULL && clock->track_str_id != NULL)
- vlc_warning(main_clock->logger, "clock(%s): using clock context(%u)",
+ vlc_debug(main_clock->logger, "clock(%s): using clock context(%u)",
clock->track_str_id, ctx->clock_id);
}
@@ -386,7 +420,8 @@ vlc_clock_get_context(vlc_clock_t *clock, vlc_tick_t system_now, vlc_tick_t ts,
return ctx;
}
-static void vlc_clock_main_reset(vlc_clock_main_t *main_clock)
+static void vlc_clock_main_reset(vlc_clock_main_t *main_clock,
+ bool switch_contexts)
{
struct vlc_clock_context *ctx = main_clock->context;
@@ -394,8 +429,22 @@ static void vlc_clock_main_reset(vlc_clock_main_t *main_clock)
AvgResetAndFill(&main_clock->coeff_avg, ctx->coeff);
main_clock->wait_sync_ref_priority = UINT_MAX;
- main_clock->pause_date = VLC_TICK_INVALID;
vlc_cond_broadcast(&main_clock->cond);
+
+ if (!switch_contexts)
+ return;
+
+ struct vlc_clock_context *ctx_it;
+ while ((ctx_it = vlc_list_first_entry_or_null(&main_clock->prev_contexts,
+ struct vlc_clock_context,
+ node)) != NULL)
+ {
+ vlc_clock_t *clock_it =
+ vlc_list_first_entry_or_null(&ctx_it->using_clocks,
+ vlc_clock_t, node);
+ assert(clock_it != NULL);
+ vlc_clock_switch_context(clock_it, ctx);
+ }
}
static inline void vlc_clock_on_update(vlc_clock_t *clock,
@@ -650,13 +699,12 @@ static void vlc_clock_input_reset(vlc_clock_t *clock)
has_other_clock = true;
}
- if (!has_other_clock)
+ if (!has_other_clock || context->start_time.system == VLC_TICK_INVALID)
{
context_reset(context);
return;
}
- assert(context->start_time.stream != VLC_TICK_INVALID);
vlc_list_append(&context->node, &main_clock->prev_contexts);
main_clock->context = context_new();
@@ -669,11 +717,18 @@ vlc_clock_monotonic_to_system(vlc_clock_t *clock, struct vlc_clock_context *ctx,
vlc_tick_t now, vlc_tick_t ts, double rate)
{
vlc_clock_main_t *main_clock = clock->owner;
+ assert(ctx != NULL);
+
+ if (ctx->wait_sync_ref.system == VLC_TICK_INVALID && ctx->start_time.system != VLC_TICK_INVALID)
+ return (ts - ctx->start_time.stream) / rate + ctx->start_time.system;
if (clock->priority < main_clock->wait_sync_ref_priority
&& ctx == main_clock->context
&& main_clock->first_pcr.system != VLC_TICK_INVALID)
{
+ if (main_clock->paused && main_clock->pause_date != VLC_TICK_INVALID)
+ now = main_clock->pause_date;
+
/* XXX: This input_delay calculation is needed until we (finally) get
* ride of the input clock. This code is adapted from input_clock.c and
* is used to introduce the same delay than the input clock (first PTS
@@ -809,6 +864,9 @@ vlc_clock_output_start(vlc_clock_t *clock,
vlc_clock_main_t *main_clock = clock->owner;
vlc_mutex_assert(&main_clock->lock);
+ if (main_clock->paused && main_clock->pause_date != VLC_TICK_INVALID)
+ start_date = main_clock->pause_date;
+
if (clock->last_conversion == VLC_TICK_INVALID)
clock->last_conversion = start_date;
@@ -826,7 +884,7 @@ vlc_clock_output_start(vlc_clock_t *clock,
return;
/* Attach to the correct context in case of reset */
- clock->context = context;
+ vlc_clock_switch_context(clock, context);
if (clock->priority >= main_clock->wait_sync_ref_priority)
return;
@@ -995,7 +1053,7 @@ void vlc_clock_main_Reset(vlc_clock_main_t *main_clock)
{
vlc_mutex_assert(&main_clock->lock);
- vlc_clock_main_reset(main_clock);
+ vlc_clock_main_reset(main_clock, true);
main_clock->first_pcr =
clock_point_Create(VLC_TICK_INVALID, VLC_TICK_INVALID);
@@ -1023,7 +1081,7 @@ void vlc_clock_main_SetFirstPcr(vlc_clock_main_t *main_clock,
vlc_warning(main_clock->logger, "new clock context(%u) @%"PRId64,
ctx->clock_id, ts);
}
- vlc_clock_main_reset(main_clock);
+ vlc_clock_main_reset(main_clock, false);
main_clock->first_pcr = clock_point_Create(system_now, ts);
main_clock->wait_sync_ref_priority = UINT_MAX;
@@ -1061,28 +1119,17 @@ void vlc_clock_main_ChangePause(vlc_clock_main_t *main_clock, vlc_tick_t now,
return;
}
- /* Reset was called before resume from Pause */
- if (main_clock->pause_date == VLC_TICK_INVALID)
- return;
+ assert(main_clock->pause_date != VLC_TICK_INVALID);
- struct vlc_clock_context *ctx = main_clock->context;
- /**
- * Only apply a delay if the clock has a reference point to avoid
- * messing up the timings if the stream was paused then seeked
- */
const vlc_tick_t delay = now - main_clock->pause_date;
- if (ctx->last.system != VLC_TICK_INVALID)
- {
- ctx->last.system += delay;
- if (ctx->start_time.system == VLC_TICK_INVALID)
- ctx->offset += delay;
- }
+
+ struct vlc_clock_context *ctx;
+ vlc_list_foreach(ctx, &main_clock->prev_contexts, node)
+ context_resume(ctx, delay);
+ context_resume(main_clock->context, delay);
+
if (main_clock->first_pcr.system != VLC_TICK_INVALID)
main_clock->first_pcr.system += delay;
- if (ctx->start_time.system != VLC_TICK_INVALID)
- ctx->start_time.system += delay;
- if (ctx->wait_sync_ref.system != VLC_TICK_INVALID)
- ctx->wait_sync_ref.system += delay;
main_clock->pause_date = VLC_TICK_INVALID;
vlc_cond_broadcast(&main_clock->cond);
}
@@ -1360,8 +1407,7 @@ void vlc_clock_Delete(vlc_clock_t *clock)
vlc_clock_main_t *main_clock = clock->owner;
vlc_mutex_lock(&main_clock->lock);
- if (clock->context != NULL)
- vlc_clock_remove_current_context(clock);
+ vlc_clock_switch_context(clock, NULL);
if (clock == main_clock->input_master)
{
@@ -1373,7 +1419,7 @@ void vlc_clock_Delete(vlc_clock_t *clock)
/* Don't reset the main clock if the master has been overridden by the
* input master */
if (main_clock->input_master != NULL)
- vlc_clock_main_reset(main_clock);
+ vlc_clock_main_reset(main_clock, false);
main_clock->master = NULL;
}
main_clock->rc--;
=====================================
src/input/decoder.c
=====================================
@@ -239,6 +239,7 @@ struct vlc_input_decoder_t
bool b_first;
bool b_has_data;
bool out_started;
+ vlc_tick_t out_first_ts;
/* Flushing */
bool flushing;
@@ -1196,7 +1197,10 @@ static int DecoderWaitUnblock(vlc_input_decoder_t *p_owner, vlc_tick_t date)
vlc_tracer_TraceEvent(tracer, "DEC", p_owner->psz_id, "stop wait");
vlc_clock_Lock(p_owner->p_clock);
- vlc_clock_Start(p_owner->p_clock, vlc_tick_now(), date);
+ vlc_tick_t first_ts = p_owner->out_first_ts != VLC_TICK_INVALID
+ ? p_owner->out_first_ts : date;
+ p_owner->out_first_ts = VLC_TICK_INVALID;
+ vlc_clock_Start(p_owner->p_clock, vlc_tick_now(), first_ts);
vlc_clock_Unlock(p_owner->p_clock);
}
@@ -1523,6 +1527,7 @@ static int ModuleThread_PlayVideo( vlc_input_decoder_t *p_owner, picture_t *p_pi
{
msg_Dbg( p_dec, "Received first picture" );
p_owner->b_first = false;
+ p_owner->out_first_ts = p_picture->date;
p_picture->b_force = true;
}
else
@@ -2009,6 +2014,7 @@ static void *DecoderThread( void *p_data )
* harmless). */
p_owner->flushing = false;
p_owner->out_started = false;
+ p_owner->out_first_ts = VLC_TICK_INVALID;
p_owner->i_preroll_end = PREROLL_NONE;
continue;
}
@@ -2062,7 +2068,7 @@ static void *DecoderThread( void *p_data )
p_owner->b_idle = true;
vlc_cond_signal( &p_owner->wait_acknowledge );
- if (p_owner->frames_countdown > 0)
+ if (p_owner->cat == VIDEO_ES && p_owner->frames_countdown > 0)
{
/* next-frames are requested but the FIFO is empty, ask for
* more buffering */
@@ -2200,6 +2206,7 @@ CreateDecoder( vlc_object_t *p_parent, const struct vlc_input_decoder_cfg *cfg )
p_owner->b_first = true;
p_owner->b_has_data = false;
p_owner->out_started = false;
+ p_owner->out_first_ts = VLC_TICK_INVALID;
p_owner->error = false;
@@ -2683,7 +2690,8 @@ void vlc_input_decoder_DecodeWithStatus(vlc_input_decoder_t *p_owner, vlc_frame_
vlc_fifo_WaitCond( p_owner->p_fifo, &p_owner->wait_fifo );
}
- if (vlc_fifo_IsEmpty(p_owner->p_fifo) && p_owner->frames_countdown > 0)
+ if (p_owner->cat == VIDEO_ES && vlc_fifo_IsEmpty(p_owner->p_fifo)
+ && p_owner->frames_countdown > 0)
decoder_Notify(p_owner, frame_next_need_data, false);
vlc_fifo_QueueUnlocked( p_owner->p_fifo, frame );
@@ -2925,6 +2933,7 @@ void vlc_input_decoder_StartWait( vlc_input_decoder_t *p_owner )
vlc_fifo_Lock(p_owner->p_fifo);
p_owner->b_has_data = false;
p_owner->b_first = true;
+ p_owner->out_first_ts = VLC_TICK_INVALID;
p_owner->b_waiting = true;
vlc_cond_signal(&p_owner->wait_request);
vlc_fifo_Unlock(p_owner->p_fifo);
=====================================
src/input/es_out.c
=====================================
@@ -66,6 +66,7 @@ typedef struct
{
/* Program context */
input_source_t *source;
+ struct vlc_input_es_out *out;
/* Program ID */
int i_id;
@@ -1165,6 +1166,19 @@ static void EsOutChangePosition(es_out_sys_t *p_sys,
input_SendEventCache( p_sys->p_input, 0.0 );
+ es_out_pgrm_t *pgrm;
+ vlc_list_foreach(pgrm, &p_sys->programs, node)
+ {
+ input_clock_Reset(pgrm->p_input_clock);
+ if (pgrm->clocks.input != NULL)
+ {
+ vlc_clock_Lock(pgrm->clocks.input);
+ pgrm->i_last_pcr = VLC_TICK_INVALID;
+ vlc_clock_Reset(pgrm->clocks.input);
+ vlc_clock_Unlock(pgrm->clocks.input);
+ }
+ }
+
foreach_es_then_es_slaves(p_es)
{
if( p_es->p_dec != NULL )
@@ -1181,19 +1195,6 @@ static void EsOutChangePosition(es_out_sys_t *p_sys,
p_es->i_pts_level = VLC_TICK_INVALID;
}
- es_out_pgrm_t *pgrm;
- vlc_list_foreach(pgrm, &p_sys->programs, node)
- {
- input_clock_Reset(pgrm->p_input_clock);
- if (pgrm->clocks.input != NULL)
- {
- vlc_clock_Lock(pgrm->clocks.input);
- pgrm->i_last_pcr = VLC_TICK_INVALID;
- vlc_clock_Reset(pgrm->clocks.input);
- vlc_clock_Unlock(pgrm->clocks.input);
- }
- }
-
p_sys->b_buffering = true;
p_sys->i_buffering_extra_initial = 0;
p_sys->i_buffering_extra_stream = 0;
@@ -1416,13 +1417,33 @@ static void EsOutProgramChangePause(es_out_sys_t *p_sys, bool b_paused, vlc_tick
{
es_out_pgrm_t *pgrm;
+ /* We need to pause the input clock, then the vlc_clock, and only
+ * unpause in the reverse order, so that the following operation are
+ * properly ordered:
+ * - input clock is paused, the date is registered
+ * - vlc_clock is paused, the date is registered
+ * - ...
+ * - vlc_clock is unpaused, the proper offsets are applied
+ * - input_clock in unpaused, a new point is emitted right after
+ *
+ * Without this ordering for unpausing, the pause duration is accounted
+ * twice by the vlc_clock since the input clock point is registered while
+ * pause is in place in the vlc_clock, so it also gets the offset.
+ *
+ * Technically, pausing the input clock after has no harmful
+ * consequences currently, but is still semantically more correct.
+ * */
vlc_list_foreach(pgrm, &p_sys->programs, node)
{
- input_clock_ChangePause(pgrm->p_input_clock, b_paused, i_date);
+ if (b_paused)
+ input_clock_ChangePause(pgrm->p_input_clock, b_paused, i_date);
vlc_clock_main_Lock(pgrm->clocks.main);
vlc_clock_main_ChangePause(pgrm->clocks.main, i_date, b_paused);
vlc_clock_main_Unlock(pgrm->clocks.main);
+
+ if (!b_paused)
+ input_clock_ChangePause(pgrm->p_input_clock, b_paused, i_date);
}
}
@@ -1563,12 +1584,15 @@ ClockListenerUpdate(void *opaque, vlc_tick_t ck_system,
vlc_tick_t ck_stream, double rate, bool discontinuity)
{
es_out_pgrm_t *pgrm = opaque;
+ es_out_sys_t *p_sys = PRIV(&pgrm->out->out);
+ vlc_mutex_assert(&p_sys->lock);
assert(pgrm->clocks.input != NULL);
vlc_clock_Lock(pgrm->clocks.input);
if (discontinuity)
{
- const vlc_tick_t current_date = vlc_tick_now();
+ const vlc_tick_t current_date = EsOutIsPaused(p_sys)
+ ? p_sys->i_pause_date : vlc_tick_now();
vlc_clock_main_SetFirstPcr(pgrm->clocks.main, current_date, ck_stream);
}
@@ -1797,6 +1821,7 @@ static es_out_pgrm_t *EsOutProgramAdd(es_out_sys_t *p_sys, input_source_t *sourc
/* Init */
p_pgrm->source = source;
+ p_pgrm->out = &p_sys->out;
p_pgrm->i_id = i_group;
p_pgrm->i_es = 0;
p_pgrm->b_selected = false;
@@ -3723,9 +3748,10 @@ static int EsOutVaControlLocked(es_out_sys_t *p_sys, input_source_t *source,
const bool b_low_delay = priv->b_low_delay;
bool b_extra_buffering_allowed = !b_low_delay && EsOutIsExtraBufferingAllowed(p_sys);
bool buffering = EsOutIsBuffering(p_sys) || p_sys->p_next_frame_es != NULL;
- /* Do not account the download stall as clock lateness. The input
- * clock will shift this frozen system date when rebuffering ends. */
- const vlc_tick_t system_now = p_sys->b_rebuffering
+ /* Do not account the download stall and user pause as clock lateness.
+ * The input clock will shift this frozen system date when rebuffering
+ * ends. */
+ const vlc_tick_t system_now = EsOutIsPaused(p_sys)
? p_sys->i_pause_date : vlc_tick_now();
vlc_tick_t i_late = input_clock_Update(
p_pgrm->p_input_clock,
=====================================
src/input/test/es_out.c
=====================================
@@ -39,6 +39,7 @@
#include <vlc_list.h>
#include <limits.h>
+#include <time.h>
#include "../src/libvlc.h"
#include "../lib/libvlc_internal.h"
@@ -55,10 +56,23 @@ struct vlc_input_decoder_t {
vlc_clock_t *clock;
bool drained;
bool started;
+ unsigned flush_count;
};
static struct vlc_list opened_decoders;
+static vlc_tick_t mock_now = VLC_TICK_INVALID;
+
+vlc_tick_t vlc_tick_now(void)
+{
+ if (mock_now != VLC_TICK_INVALID)
+ return mock_now;
+
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return vlc_tick_from_timespec(&ts);
+}
+
VLC_EXPORT vlc_input_decoder_t *
vlc_input_decoder_Create(vlc_object_t *, const es_format_t *, const char *es_id,
struct vlc_clock_t *, input_resource_t *) VLC_USED;
@@ -92,6 +106,7 @@ vlc_input_decoder_New(vlc_object_t *parent,
dec->clock = cfg->clock;
dec->drained = false;
dec->started = false;
+ dec->flush_count = 0;
vlc_list_append(&dec->node, &opened_decoders);
return dec;
}
@@ -171,7 +186,7 @@ void vlc_input_decoder_Drain(vlc_input_decoder_t *owner)
void vlc_input_decoder_Flush(vlc_input_decoder_t *owner)
{
- (void)owner;
+ owner->flush_count++;
}
size_t vlc_input_decoder_GetFifoSize(vlc_input_decoder_t *owner)
@@ -574,11 +589,125 @@ static void test_preroll_rate(float rate)
can_pace_control = false;
}
+static vlc_tick_t ConvertToSystem(struct vlc_clock_t *clock, vlc_tick_t ts)
+{
+ vlc_clock_Lock(clock);
+ vlc_tick_t system = vlc_clock_ConvertToSystem(clock, mock_now, ts, 1.f, NULL);
+ vlc_clock_Unlock(clock);
+ return system;
+}
+
+static void test_pcr_while_paused(vlc_tick_t pts_delay, vlc_tick_t last_pcr,
+ bool discontinuity)
+{
+ can_pace_control = true;
+ mock_now = VLC_TICK_FROM_SEC(100);
+
+ struct test_ctx ctx;
+ test_ctx_Init(&ctx, 1.f, pts_delay);
+ struct vlc_input_es_out *out = ctx.out;
+
+ es_out_id_t *video_track = AddVideoTrack(out);
+ SendBlock(out, video_track);
+
+ /* Finish the buffering */
+ for (vlc_tick_t pcr = 0;
+ pcr <= pts_delay;
+ pcr += VLC_TICK_FROM_MS(100))
+ {
+ es_out_SetPCR(&out->out, VLC_TICK_0 + pcr);
+ }
+
+ struct vlc_input_decoder_t *dec =
+ vlc_list_first_entry_or_null(&opened_decoders,
+ struct vlc_input_decoder_t, node);
+ assert(dec != NULL && dec->started);
+ assert(dec->clock != NULL);
+
+ /* In this test, we need to:
+ * - finish the buffering, mainly to prepare the test
+ * - pause the playback
+ * - "seek" by resetting the PCR
+ * - send new PCR again
+ * - restart the playback */
+ mock_now += VLC_TICK_FROM_SEC(1);
+ es_out_SetPauseState(out, true, true, mock_now);
+
+ mock_now += VLC_TICK_FROM_SEC(1);
+ es_out_Control(&out->out, ES_OUT_RESET_PCR);
+
+ const vlc_tick_t seek_ts = VLC_TICK_0 + VLC_TICK_FROM_SEC(10);
+ SendBlock(out, video_track);
+
+ for (vlc_tick_t pcr = 0;
+ pcr <= last_pcr;
+ pcr += VLC_TICK_FROM_MS(100))
+ {
+ es_out_SetPCR(&out->out, seek_ts + pcr);
+ }
+ /* pcr is now seek_ts + last_pcr */
+
+ ConvertToSystem(dec->clock, seek_ts);
+
+ /* In this part, we also check that the input keeps demuxing even
+ * while being paused when a decoder continue to ask for more data.
+ * flush count allows detecting this, since the es_out would trigger
+ * a PCR_RESET to accommodate for the late PCR if incorrectly
+ * accounted. */
+ const unsigned flush_count = dec->flush_count;
+ mock_now += VLC_TICK_FROM_SEC(3);
+ SendBlock(out, video_track);
+ es_out_SetPCR(&out->out, seek_ts + last_pcr + VLC_TICK_FROM_MS(100));
+
+ assert(!es_out_GetBuffering(out));
+ assert(dec->flush_count == flush_count);
+
+ /* In this part, we also check that discontinuity are accounting for
+ * the pause date. In that case, we know from previous part it won't
+ * trigger a PCR_RESET to continue sending PCRs, so we try to create
+ * a huge PCR jump to trigger the discontinuity detection. */
+ vlc_tick_t pcr = seek_ts + last_pcr + VLC_TICK_FROM_MS(100);
+ if (discontinuity)
+ {
+ pcr += VLC_TICK_FROM_SEC(100);
+ es_out_SetPCR(&out->out, pcr);
+ }
+
+ /* Now resume playback 3s later */
+ mock_now += VLC_TICK_FROM_SEC(3);
+ es_out_SetPauseState(out, false, false, mock_now);
+
+ /* We've finished reproducing the scenario above, so now we need to
+ * check that the reported times to the decoders are correct. */
+
+ const vlc_tick_t resume_date = mock_now;
+ const vlc_tick_t origin = discontinuity ? pcr : seek_ts;
+ const vlc_tick_t start_date = discontinuity ? resume_date + pts_delay
+ : resume_date;
+ const vlc_tick_t system = ConvertToSystem(dec->clock, origin);
+
+ assert(system >= start_date);
+ assert(system <= start_date + pts_delay);
+
+ es_out_Del(&out->out, video_track);
+
+ test_ctx_Destroy(&ctx);
+
+ mock_now = VLC_TICK_INVALID;
+ can_pace_control = false;
+}
+
int main(void)
{
test_playback();
test_multiple_programs();
test_preroll_rate(0.25f);
test_preroll_rate(2.f);
+
+ /* We need to test the situation at end of buffering and after the
+ * end of buffering has landed. */
+ test_pcr_while_paused(VLC_TICK_FROM_MS(300), VLC_TICK_FROM_MS(300), false);
+ test_pcr_while_paused(VLC_TICK_FROM_MS(300), VLC_TICK_FROM_MS(500), false);
+ test_pcr_while_paused(VLC_TICK_FROM_MS(300), VLC_TICK_FROM_MS(300), true);
return 0;
}
=====================================
test/src/clock/clock.c
=====================================
@@ -775,13 +775,24 @@ static void contexts_run(const struct clock_ctx *ctx)
{
vlc_tick_t converted;
vlc_tick_t system = ctx->system_start;
- vlc_tick_t stream_context0 = 1;
+ vlc_tick_t stream_context0 = ctx->stream_start;
uint32_t clock_id;
vlc_clock_main_Lock(ctx->mainclk);
- /* Initial SetFirstPcr, that will initialise the default and main context */
- vlc_clock_main_SetFirstPcr(ctx->mainclk, system, stream_context0);
+ /* We create another clock to track points from the first created context
+ * after the second context is being created. See below. */
+ char *track2_name;
+ int ret = asprintf(&track2_name, "%s/video2", ctx->scenario->name);
+ assert(ret != -1);
+ vlc_clock_t *track2 = vlc_clock_main_CreateSlave(
+ ctx->mainclk, track2_name, VIDEO_ES,
+ NULL, NULL);
+ assert(track2 != NULL);
+
+ // NOTE: the input clock is already started by the scenario
+ vlc_clock_Start(ctx->slave, system, stream_context0);
+ vlc_clock_Start(track2, system, stream_context0);
/* Check that the converted point is valid */
converted = vlc_clock_ConvertToSystem(ctx->slave, system, stream_context0,
@@ -793,11 +804,17 @@ static void contexts_run(const struct clock_ctx *ctx)
assert(converted == system);
vlc_clock_Update(ctx->slave, system, stream_context0, 1.0f);
- /* Discontinuity from 1us to 30 sec */
+ /* Discontinuity of 30 sec */
vlc_tick_t system_context0 = system;
- vlc_tick_t stream_context1 = VLC_TICK_FROM_SEC(30);
+ vlc_tick_t stream_context1 = stream_context0 + VLC_TICK_FROM_SEC(30);
system += VLC_TICK_FROM_MS(100);
- vlc_clock_main_SetFirstPcr(ctx->mainclk, system, stream_context1);
+ vlc_clock_Reset(ctx->input);
+ vlc_clock_Update(ctx->input, system, stream_context1, 1.0f);
+ vlc_clock_Start(ctx->input, system, stream_context1);
+
+ /* We detect the discontinuity on the first track, acknowledge the new context. */
+ vlc_clock_Reset(ctx->slave);
+ vlc_clock_Start(ctx->slave, system, stream_context1);
/* Check that we can use the new context (or new origin) */
converted = vlc_clock_ConvertToSystem(ctx->slave, system, stream_context1,
@@ -809,7 +826,7 @@ static void contexts_run(const struct clock_ctx *ctx)
/* Check that we can still use the old context when converting a point
* closer to the original context */
- converted = vlc_clock_ConvertToSystem(ctx->slave, system,
+ converted = vlc_clock_ConvertToSystem(track2, system,
VLC_TICK_FROM_MS(10) + stream_context0,
1.0f, &clock_id);
fprintf(stderr, "%s:%d: clock_id=%" PRIu32 " == 0\n", __func__, __LINE__, clock_id);
@@ -824,7 +841,12 @@ static void contexts_run(const struct clock_ctx *ctx)
/* Discontinuity back to 1us */
system += VLC_TICK_FROM_MS(100);
vlc_tick_t stream_context2 = 1;
- vlc_clock_main_SetFirstPcr(ctx->mainclk, system, stream_context2);
+ vlc_clock_Reset(ctx->input);
+ vlc_clock_Update(ctx->input, system, stream_context2, 1.0f);
+ vlc_clock_Start(ctx->input, system, stream_context2);
+
+ vlc_clock_Reset(ctx->slave);
+ vlc_clock_Start(ctx->slave, system, stream_context2);
/* Check that we can use the new context (or new origin) */
converted = vlc_clock_ConvertToSystem(ctx->slave, system, stream_context2,
@@ -849,6 +871,9 @@ static void contexts_run(const struct clock_ctx *ctx)
assert(converted != system_context0);
vlc_clock_main_Unlock(ctx->mainclk);
+
+ vlc_clock_Delete(track2);
+ free(track2_name);
}
#define VLC_TICK_12H VLC_TICK_FROM_SEC(12 * 60 * 60)
=====================================
test/src/clock/clock_start.c
=====================================
@@ -373,6 +373,153 @@ static void test_clock_slave_only(
destroy_fixture_simple(&f);
}
+
+static void test_clock_input_reset_twice_restart(struct vlc_logger *logger)
+{
+ fprintf(stderr, "%s:\n", __func__);
+ struct clock_fixture_simple f = init_fixture_simple(logger, false, 0, 0);
+ vlc_clock_main_Lock(f.main);
+
+ const vlc_tick_t now = VLC_TICK_FROM_SEC(10);
+ vlc_clock_Start(f.input, now, now);
+ vlc_clock_Start(f.master, now, now);
+ vlc_clock_Start(f.slave, now, now);
+
+ vlc_clock_Reset(f.input);
+ vlc_clock_Reset(f.master);
+ vlc_clock_Reset(f.slave);
+ vlc_clock_Reset(f.input);
+
+ const vlc_tick_t ts = VLC_TICK_FROM_SEC(12);
+ vlc_clock_Start(f.input, 2 * now, ts);
+ vlc_clock_Start(f.master, 2 * now, ts);
+ vlc_clock_Start(f.slave, 2 * now, ts);
+
+ vlc_tick_t result = vlc_clock_ConvertToSystem(
+ f.slave, 2 * now, ts + VLC_TICK_FROM_SEC(1), 1., NULL);
+ fprintf(stderr, "%" PRId64 " = %" PRId64 "\n", result,
+ 2 * now + VLC_TICK_FROM_SEC(1));
+ assert(result == 2 * now + VLC_TICK_FROM_SEC(1));
+ vlc_clock_main_Unlock(f.main);
+
+ destroy_fixture_simple(&f);
+}
+
+static void test_clock_monotonic_start_paused(struct vlc_logger *logger)
+{
+ fprintf(stderr, "%s:\n", __func__);
+ struct clock_fixture_simple f = init_fixture_simple(logger, false, 0, 0);
+ vlc_clock_main_Lock(f.main);
+
+ const vlc_tick_t pause_date = VLC_TICK_FROM_SEC(10);
+ const vlc_tick_t resume_date = pause_date + VLC_TICK_FROM_SEC(5);
+ const vlc_tick_t ts = VLC_TICK_FROM_SEC(100);
+
+ vlc_clock_main_ChangePause(f.main, pause_date, true);
+ vlc_clock_main_SetFirstPcr(f.main, pause_date, ts);
+ vlc_clock_ConvertToSystem(f.slave, pause_date + VLC_TICK_FROM_SEC(2), ts, 1., NULL);
+ vlc_clock_main_ChangePause(f.main, resume_date, false);
+
+ vlc_tick_t result =
+ vlc_clock_ConvertToSystem(f.slave, resume_date, ts, 1., NULL);
+ fprintf(stderr, "%" PRId64 " = %" PRId64 "\n", result, resume_date);
+ assert(result == resume_date);
+ vlc_clock_main_Unlock(f.main);
+
+ destroy_fixture_simple(&f);
+}
+
+static void start_clock_context(struct clock_fixture_simple *f,
+ bool clock_start,
+ vlc_tick_t system, vlc_tick_t ts)
+{
+ if (clock_start)
+ {
+ vlc_clock_Reset(f->input);
+ vlc_clock_Start(f->input, system, ts);
+ }
+ else
+ vlc_clock_main_SetFirstPcr(f->main, system, ts);
+}
+
+static void test_clock_prev_context_paused(struct vlc_logger *logger,
+ bool clock_start,
+ bool paused_discontinuity)
+{
+ fprintf(stderr, "%s(%s, %s):\n", __func__,
+ clock_start ? "vlc_clock_Start" : "vlc_clock_main_SetFirstPcr",
+ paused_discontinuity ? "discontinuity while paused"
+ : "pause after discontinuity");
+ struct clock_fixture_simple f = init_fixture_simple(logger, false, 0, 0);
+ vlc_clock_main_Lock(f.main);
+
+ const vlc_tick_t start_date = VLC_TICK_FROM_SEC(10);
+ const vlc_tick_t old_ts = VLC_TICK_FROM_SEC(100);
+ const vlc_tick_t new_ts = VLC_TICK_FROM_SEC(500);
+ const vlc_tick_t pause_date = start_date + VLC_TICK_FROM_SEC(2);
+ const vlc_tick_t discontinuity_date = pause_date - VLC_TICK_FROM_SEC(1);
+ const vlc_tick_t pause_duration = VLC_TICK_FROM_SEC(5);
+ const vlc_tick_t resume_date = pause_date + pause_duration;
+
+ start_clock_context(&f, clock_start, start_date, old_ts);
+ vlc_clock_Update(f.master, start_date, old_ts, 1.);
+ vlc_clock_Update(f.master, start_date + VLC_TICK_FROM_SEC(1),
+ old_ts + VLC_TICK_FROM_SEC(1), 1.);
+
+ vlc_tick_t result =
+ vlc_clock_ConvertToSystem(f.slave, start_date + VLC_TICK_FROM_SEC(1),
+ old_ts + VLC_TICK_FROM_SEC(1), 1., NULL);
+ assert(result == start_date + VLC_TICK_FROM_SEC(1));
+
+ if (paused_discontinuity)
+ {
+ vlc_clock_main_ChangePause(f.main, pause_date, true);
+ start_clock_context(&f, clock_start, pause_date, new_ts);
+ }
+ else
+ {
+ start_clock_context(&f, clock_start, discontinuity_date, new_ts);
+ vlc_clock_Update(f.master, discontinuity_date, new_ts, 1.);
+ vlc_clock_main_ChangePause(f.main, pause_date, true);
+ }
+ vlc_clock_main_ChangePause(f.main, resume_date, false);
+
+ const vlc_tick_t point = old_ts + VLC_TICK_FROM_MS(1500);
+ result = vlc_clock_ConvertToSystem(f.slave, resume_date, point, 1., NULL);
+ fprintf(stderr, "%" PRId64 " = %" PRId64 "\n", result,
+ start_date + VLC_TICK_FROM_MS(1500) + pause_duration);
+ assert(result == start_date + VLC_TICK_FROM_MS(1500) + pause_duration);
+ vlc_clock_main_Unlock(f.main);
+
+ destroy_fixture_simple(&f);
+}
+
+
+static void test_clock_output_start_paused(struct vlc_logger *logger)
+{
+ fprintf(stderr, "%s:\n", __func__);
+ struct clock_fixture_simple f = init_fixture_simple(logger, false, 0, 0);
+ vlc_clock_main_Lock(f.main);
+
+ const vlc_tick_t pause_date = VLC_TICK_FROM_SEC(10);
+ const vlc_tick_t seek_date = pause_date + VLC_TICK_FROM_SEC(2);
+ const vlc_tick_t resume_date = seek_date + VLC_TICK_FROM_SEC(3);
+ const vlc_tick_t ts = VLC_TICK_FROM_SEC(100);
+
+ vlc_clock_main_ChangePause(f.main, pause_date, true);
+ vlc_clock_Start(f.input, pause_date, ts);
+ vlc_clock_Start(f.slave, seek_date, ts);
+ vlc_clock_main_ChangePause(f.main, resume_date, false);
+
+ vlc_tick_t result =
+ vlc_clock_ConvertToSystem(f.slave, resume_date, ts, 1., NULL);
+ fprintf(stderr, "%" PRId64 " = %" PRId64 "\n", result, resume_date);
+ assert(result == resume_date);
+ vlc_clock_main_Unlock(f.main);
+
+ destroy_fixture_simple(&f);
+}
+
int main(void)
{
libvlc_instance_t *libvlc = libvlc_new(0, NULL);
@@ -456,6 +603,13 @@ int main(void)
test_clock_start_reset(logger);
test_clock_slave_only(logger);
+ test_clock_input_reset_twice_restart(logger);
+ test_clock_monotonic_start_paused(logger);
+ test_clock_prev_context_paused(logger, false, false);
+ test_clock_prev_context_paused(logger, false, true);
+ test_clock_prev_context_paused(logger, true, false);
+ test_clock_prev_context_paused(logger, true, true);
+ test_clock_output_start_paused(logger);
libvlc_release(libvlc);
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e0bc4a81fd17bdd4deadbee08dfe6df6034421b7...2db16fa53d6662d1e9f12971c6573ffd234c3911
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e0bc4a81fd17bdd4deadbee08dfe6df6034421b7...2db16fa53d6662d1e9f12971c6573ffd234c3911
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list