After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 762147 - adaptivedemux: use GstSystemClock to all real-time calculations
adaptivedemux: use GstSystemClock to all real-time calculations
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal normal
: 1.9.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-02-16 14:44 UTC by Florin Apostol
Modified: 2016-04-28 14:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
1/3 use GstSystemClock to all real-time calculations (13.85 KB, patch)
2016-02-16 14:47 UTC, Florin Apostol
reviewed Details | Review
2/3 use realtime_clock for waiting for a condition (9.31 KB, patch)
2016-02-16 14:47 UTC, Florin Apostol
committed Details | Review
3/3 tests: use a GstTestClock as the system clock (4.46 KB, patch)
2016-02-16 14:48 UTC, Florin Apostol
committed Details | Review
adaptivedemux: use GstSystemClock to all real-time calculations (13.95 KB, patch)
2016-04-21 13:52 UTC, A Ashley
committed Details | Review
testclock: add clock-type property (3.13 KB, patch)
2016-04-21 13:54 UTC, A Ashley
committed Details | Review

Description Florin Apostol 2016-02-16 14:44:50 UTC
A realtime clock is used in many places, such as deciding which
fragment to select at start up and deciding how long to sleep
before a fragment becomes available. For example dashdemux needs
sample the client's estimate of UTC when selecting where to start
in a live DASH stream.

The problem with dashdemux calculating the client's idea of UTC is
that it makes it difficult to create unit tests, because the passage
of time is a factor in the test.

We need to change dashdemux and adaptivedemux to use the
GstSystemClock, so that a unit test can replace the system clock when
it needs to be able to control the clock.
Comment 1 Florin Apostol 2016-02-16 14:47:29 UTC
Created attachment 321392 [details] [review]
1/3 use GstSystemClock to all real-time calculations
Comment 2 Florin Apostol 2016-02-16 14:47:55 UTC
Created attachment 321393 [details] [review]
2/3 use realtime_clock for waiting for a condition
Comment 3 Florin Apostol 2016-02-16 14:48:28 UTC
Created attachment 321394 [details] [review]
3/3 tests: use a GstTestClock as the system clock
Comment 4 Thiago Sousa Santos 2016-04-19 21:02:37 UTC
Review of attachment 321392 [details] [review]:

This is a good idea, just a minor comment below.

::: gst-libs/gst/adaptivedemux/gstadaptivedemux.c
@@ +400,3 @@
 {
   GstPadTemplate *pad_template;
+  GstClockType clock_type = GST_CLOCK_TYPE_REALTIME;

Isn't it safer to default to non-realtime here?
Comment 5 A Ashley 2016-04-20 15:27:14 UTC
(In reply to Thiago Sousa Santos from comment #4)

> 
> Isn't it safer to default to non-realtime here?

The problem is that GstTestClock does not have the clock-type property. Defaulting to non-realtime would cause the unit tests to be based upon current time of day, which breaks the ability to make the tests reproducible.

I wasn't feeling brave enough to add a property to GstTestClock, but maybe that's an option.
Comment 6 Thiago Sousa Santos 2016-04-20 16:49:58 UTC
(In reply to A Ashley from comment #5)
> (In reply to Thiago Sousa Santos from comment #4)
> 
> > 
> > Isn't it safer to default to non-realtime here?
> 
> The problem is that GstTestClock does not have the clock-type property.
> Defaulting to non-realtime would cause the unit tests to be based upon
> current time of day, which breaks the ability to make the tests reproducible.
> 
> I wasn't feeling brave enough to add a property to GstTestClock, but maybe
> that's an option.

I think that adding the property to GstTestClock would be a safer bet. Can you provide a patch for it so we can merge this all?
Comment 7 A Ashley 2016-04-21 13:52:44 UTC
Created attachment 326492 [details] [review]
adaptivedemux: use GstSystemClock to all real-time calculations

Obsoletes patch 1/3

Changes default clock type to GST_CLOCK_TYPE_OTHER
Comment 8 A Ashley 2016-04-21 13:54:05 UTC
Created attachment 326493 [details] [review]
testclock: add clock-type property
Comment 9 Thiago Sousa Santos 2016-04-21 19:47:15 UTC
Thanks, merged. Only changed the default clock-type to be monotonic as we can't assume all testclock usage out there is returning us realtime.

core:
commit 57a9919eb16d87b19bb5d91792f3460bd34f4fcc
Author: Alex Ashley <bugzilla@ashley-family.net>
Date:   Thu Apr 21 14:45:39 2016 +0100

    testclock: add clock-type property
    
    To allow the GstTestClock to be used as a GstSystemClock, it is
    useful to implement the clock-type property that GstSystemClock
    provides. This allows GstTestClock to be used as the system clock
    with code that expects a GstSystemClock.
    
        https://bugzilla.gnome.org/show_bug.cgi?id=762147


-bad:
commit e86e08b4ac9a939393353729e0ae598ea2ea4fc4
Author: Florin Apostol <florin.apostol@oregan.net>
Date:   Tue Feb 16 14:44:39 2016 +0000

    adaptivedemux: tests: use a GstTestClock as the system clock
    
    To allow the adaptivedemux live stream tests to run in non-realtime, use a
    GstTestClock as the system clock. This allows the unit tests to complete
    more quickly than if they had to complete in real time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762147

commit aa58a70d6676f9bc394780a90a39ff47d538fa68
Author: Florin Apostol <florin.apostol@oregan.net>
Date:   Tue Feb 16 14:44:27 2016 +0000

    adaptivedemux: use realtime_clock for waiting for a condition
    
    There are several places in adaptivedemux where it waits for
    time to pass, for example to wait until it should next download
    a fragment. The problem with this approach is that it means that
    unit tests are forced to execute in realtime.
    
    This commit replaces the use of g_cond_wait_until() with single
    shot GstClockID that signals the condition variable. Under normal
    usage, this behaves exactly as before. A unit test can replace the
    system clock with a GstTestClock, allowing the test to control the
    timing in adaptivedemux.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762147

commit 74d62b91449b2f21d417bc67b58792217c185b8d
Author: Florin Apostol <florin.apostol@oregan.net>
Date:   Tue Feb 16 14:44:10 2016 +0000

    adaptivedemux: use GstSystemClock to all real-time calculations
    
    A realtime clock is used in many places, such as deciding which
    fragment to select at start up and deciding how long to sleep
    before a fragment becomes available. For example dashdemux needs
    sample the client's estimate of UTC when selecting where to start
    in a live DASH stream.
    
    The problem with dashdemux calculating the client's idea of UTC is
    that it makes it difficult to create unit tests, because the passage
    of time is a factor in the test.
    
    This commit changes dashdemux and adaptivedemux to use the
    GstSystemClock, so that a unit test can replace the system clock when
    it needs to be able to control the clock.
    
    This commit makes no change to the behaviour under normal usage, as
    GstSystemClock is based upon the system time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762147