2011-01-06 04:21:18 +01:00
|
|
|
|
/*
|
|
|
|
|
|
QuantiserBasics(Test) - a demo quantiser to cover the basic quantiser API
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** 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. See the file COPYING for further details.
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file quantiser-basics-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref QuantiserBasics_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2011-01-09 11:41:08 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2011-01-06 04:21:18 +01:00
|
|
|
|
#include "lib/time/quantiser.hpp"
|
2024-11-13 02:23:23 +01:00
|
|
|
|
#include "lib/random.hpp"
|
2011-01-06 04:21:18 +01:00
|
|
|
|
#include "lib/util.hpp"
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
#include "lib/test/diagnostic-output.hpp"
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
2011-01-09 11:41:08 +01:00
|
|
|
|
using lumiera::error::LUMIERA_ERROR_BOTTOM_VALUE;
|
2011-01-06 04:21:18 +01:00
|
|
|
|
using util::isnil;
|
2024-11-13 02:23:23 +01:00
|
|
|
|
using lib::rani;
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace time{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
Timehandling: choose safer representation for fractional seconds (closes #939)
When drafting the time handling framework some years ago,
I foresaw the possible danger of mixing up numbers relating
to fractional seconds, with other plain numbers intended as
frame counts or as micro ticks. Thus I deliberately picked
an incompatible integer type for FSecs = boost::rational<long>
However, using long is problematic in itself, since its actual
bit length is not fixed, and especially on 32bit platforms long
is quite surprisingly defined to be the same as int.
However, meanwhile, using the new C++ features, I have blocked
pretty much any possible implicit conversion path, requiring
explicit conversions in the relevant ctor invocations. So,
after weighting in the alternatives, FSecs is now defined
as boost::rational<int64_t>.
2020-02-17 02:36:54 +01:00
|
|
|
|
const int MAX_FRAMES = 25*500;
|
|
|
|
|
|
const int DIRT_GRAIN = 50;
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
2011-03-31 18:43:50 +02:00
|
|
|
|
const FSecs F25(1,25); // duration of one PAL frame
|
|
|
|
|
|
|
|
|
|
|
|
inline Time
|
|
|
|
|
|
secs (int seconds)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Time(FSecs(seconds));
|
|
|
|
|
|
}
|
2011-01-06 04:21:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/****************************************************//**
|
2011-01-06 04:21:18 +01:00
|
|
|
|
* @test cover the basic Quantiser API.
|
2011-01-09 11:41:08 +01:00
|
|
|
|
* This test uses a standalone quantiser implementation
|
|
|
|
|
|
* to demonstrate and verify the basic behaviour
|
|
|
|
|
|
* and the usage corner cases of a quantiser.
|
|
|
|
|
|
*
|
|
|
|
|
|
* In this most simple form, a quantiser is defined
|
|
|
|
|
|
* by the time reference point (origin) to use, and
|
|
|
|
|
|
* the frame rate (grid spacing). For each raw time
|
|
|
|
|
|
* value, the quantiser yields a time value aligned
|
|
|
|
|
|
* at the next lower frame bound. Besides that,
|
|
|
|
|
|
* time values are confined to be within
|
2024-12-07 18:15:44 +01:00
|
|
|
|
* the interval (Time::MIN, Time::MAX)
|
2011-01-09 11:41:08 +01:00
|
|
|
|
*
|
|
|
|
|
|
* @see TimeQuantisation_test
|
2011-01-06 04:21:18 +01:00
|
|
|
|
*/
|
|
|
|
|
|
class QuantiserBasics_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
|
|
|
|
|
checkSimpleQuantisation();
|
2011-01-08 03:30:10 +01:00
|
|
|
|
coverQuantisationStandardCases();
|
|
|
|
|
|
coverQuantisationCornerCases();
|
2011-01-06 04:21:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
checkSimpleQuantisation ()
|
|
|
|
|
|
{
|
|
|
|
|
|
FixedFrameQuantiser fixQ(25);
|
|
|
|
|
|
|
2024-11-13 02:23:23 +01:00
|
|
|
|
int frames = rani(MAX_FRAMES);
|
|
|
|
|
|
FSecs dirt = (F25 / (2 + rani(DIRT_GRAIN)));
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
Timehandling: choose safer representation for fractional seconds (closes #939)
When drafting the time handling framework some years ago,
I foresaw the possible danger of mixing up numbers relating
to fractional seconds, with other plain numbers intended as
frame counts or as micro ticks. Thus I deliberately picked
an incompatible integer type for FSecs = boost::rational<long>
However, using long is problematic in itself, since its actual
bit length is not fixed, and especially on 32bit platforms long
is quite surprisingly defined to be the same as int.
However, meanwhile, using the new C++ features, I have blocked
pretty much any possible implicit conversion path, requiring
explicit conversions in the relevant ctor invocations. So,
after weighting in the alternatives, FSecs is now defined
as boost::rational<int64_t>.
2020-02-17 02:36:54 +01:00
|
|
|
|
Time rawTime = Time(frames*F25) + Duration(dirt);
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (Time( frames *F25) <= rawTime);
|
2011-01-06 04:21:18 +01:00
|
|
|
|
CHECK (Time((frames+1)*F25) > rawTime);
|
|
|
|
|
|
|
2022-12-05 01:05:23 +01:00
|
|
|
|
Time quantTime (fixQ.gridLocal (rawTime));
|
2011-01-06 04:21:18 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (Time(frames*F25) == quantTime);
|
|
|
|
|
|
}
|
2011-01-08 03:30:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Test Quantiser
|
|
|
|
|
|
* allowing to use plain numbers.
|
|
|
|
|
|
* 1 Frame == 3 micro ticks */
|
|
|
|
|
|
struct TestQuant
|
|
|
|
|
|
: FixedFrameQuantiser
|
|
|
|
|
|
{
|
|
|
|
|
|
TestQuant (int origin=0)
|
2018-11-17 18:00:39 +01:00
|
|
|
|
: FixedFrameQuantiser( FrameRate(TimeValue::SCALE, 3 ), TimeValue(origin))
|
2011-01-08 03:30:10 +01:00
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
quant (int testPoint)
|
|
|
|
|
|
{
|
2022-12-05 01:05:23 +01:00
|
|
|
|
TimeVar quantised = this->gridLocal(TimeValue(testPoint));
|
2025-06-18 16:50:19 +02:00
|
|
|
|
return _raw(quantised);
|
2011-01-08 03:30:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coverQuantisationStandardCases()
|
|
|
|
|
|
{
|
|
|
|
|
|
TestQuant q0;
|
|
|
|
|
|
TestQuant q1(1);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( 6 == q0.quant(7) );
|
|
|
|
|
|
CHECK ( 6 == q0.quant(6) );
|
|
|
|
|
|
CHECK ( 3 == q0.quant(5) );
|
|
|
|
|
|
CHECK ( 3 == q0.quant(4) );
|
|
|
|
|
|
CHECK ( 3 == q0.quant(3) );
|
|
|
|
|
|
CHECK ( 0 == q0.quant(2) );
|
|
|
|
|
|
CHECK ( 0 == q0.quant(1) );
|
|
|
|
|
|
CHECK ( 0 == q0.quant(0) );
|
|
|
|
|
|
CHECK (-3 == q0.quant(-1));
|
|
|
|
|
|
CHECK (-3 == q0.quant(-2));
|
|
|
|
|
|
CHECK (-3 == q0.quant(-3));
|
|
|
|
|
|
CHECK (-6 == q0.quant(-4));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( 6 == q1.quant(7) );
|
|
|
|
|
|
CHECK ( 3 == q1.quant(6) );
|
|
|
|
|
|
CHECK ( 3 == q1.quant(5) );
|
|
|
|
|
|
CHECK ( 3 == q1.quant(4) );
|
|
|
|
|
|
CHECK ( 0 == q1.quant(3) );
|
|
|
|
|
|
CHECK ( 0 == q1.quant(2) );
|
|
|
|
|
|
CHECK ( 0 == q1.quant(1) );
|
|
|
|
|
|
CHECK (-3 == q1.quant(0) );
|
|
|
|
|
|
CHECK (-3 == q1.quant(-1));
|
|
|
|
|
|
CHECK (-3 == q1.quant(-2));
|
|
|
|
|
|
CHECK (-6 == q1.quant(-3));
|
|
|
|
|
|
CHECK (-6 == q1.quant(-4));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coverQuantisationCornerCases()
|
|
|
|
|
|
{
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
// For this test we exploit the limits of the time system
|
|
|
|
|
|
Time SUB_MIN{-Duration::MAX};
|
|
|
|
|
|
Time SUP_MAX{ Duration::MAX};
|
|
|
|
|
|
|
2011-01-09 11:41:08 +01:00
|
|
|
|
// origin at lower end of the time range
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
FixedFrameQuantiser case1 (1, SUB_MIN);
|
|
|
|
|
|
CHECK (secs(0) == case1.gridLocal(SUB_MIN ));
|
|
|
|
|
|
CHECK (secs(0) == case1.gridLocal(SUB_MIN +TimeValue(1) ));
|
|
|
|
|
|
CHECK (secs(1) == case1.gridLocal(SUB_MIN +secs(1) ));
|
|
|
|
|
|
CHECK (SUP_MAX -secs(1) > case1.gridLocal( secs(-1) ));
|
|
|
|
|
|
CHECK (SUP_MAX -secs(1) <= case1.gridLocal( secs (0) ));
|
|
|
|
|
|
CHECK (SUP_MAX > case1.gridLocal( secs (0) ));
|
|
|
|
|
|
CHECK (SUP_MAX > case1.gridLocal( secs(+1) ));
|
|
|
|
|
|
CHECK (SUP_MAX > case1.gridLocal( secs(+2) ));
|
|
|
|
|
|
|
|
|
|
|
|
TimeValue largestPoint = case1.gridLocal(secs (0));
|
|
|
|
|
|
CHECK (largestPoint == case1.gridLocal( secs(+1) ));
|
|
|
|
|
|
CHECK (largestPoint == case1.gridLocal( secs(+2) ));
|
|
|
|
|
|
CHECK (largestPoint < SUP_MAX);
|
|
|
|
|
|
CHECK (largestPoint == Offset{secs(1)} * case1.gridPoint(secs(0)));
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
|
|
|
|
|
// origin at upper end of the time range
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
FixedFrameQuantiser case2 (1, SUP_MAX);
|
|
|
|
|
|
CHECK (secs( 0) == case2.gridLocal(SUP_MAX ));
|
|
|
|
|
|
CHECK (secs(-1) == case2.gridLocal(SUP_MAX -TimeValue(1) )); // note: next lower frame
|
|
|
|
|
|
CHECK (secs(-1) == case2.gridLocal(SUP_MAX -secs(1) )); // i.e. the same as a whole frame down
|
|
|
|
|
|
CHECK (SUB_MIN +secs(1) < case2.gridLocal( secs(+2) ));
|
|
|
|
|
|
CHECK (SUB_MIN +secs(1) >= case2.gridLocal( secs(+1) ));
|
|
|
|
|
|
CHECK (SUB_MIN < case2.gridLocal( secs(+1) ));
|
|
|
|
|
|
CHECK (SUB_MIN == case2.gridLocal( secs( 0) )); // note: because of downward truncating,
|
|
|
|
|
|
CHECK (SUB_MIN == case2.gridLocal( secs(-1) )); // resulting values will already exceed
|
|
|
|
|
|
CHECK (SUB_MIN == case2.gridLocal( secs(-2) )); // allowed range and thus will be clipped
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
Library: rectify clipping of time::Duration (see #1263)
This is a deep refactoring to allow to represent the distance
between all valid time points as a time::Offset or time::Duration.
By design this is possible, since Time::MAX was defined as 1/30 of
the maximum value technically representable as int64_t. However,
introducing a different limiter for offsets and durations turns
out difficult, due to the inconsistencies in the exiting hierarchy
of temporal entities. Which in turn seems to stem from the unfortunate
decision to make time entities immutable, see #1261
Since the limiter is hard wired into the `time::TimeValue` constructor,
we are forced to create a "backdoor" of sorts, to pass up values
with different limiting from child classes. This would not be so
much of a problem if calculations weren't forced to go through `TimeVar`,
which does not distinguish between time points and time durations.
This solution rearranges all checks to be performed now by time::Offset,
while time::Duration will only take the absolute value at construction,
based on the fact that there is no valid construction path to yield
a duration which does not go through an offset first.
Later, when we're ready to sort out the implementation base of time values
(see #1258), this design issue should be revisited
- either we'll allow derived classes explicitly to invoke the limiter functions
- or we may be able to have an automatic conversion path from clearly
marked base implementation types, in which case we wouldn't use the
buildRaw_() and _raw() "backdoor" functions any more...
2022-12-05 00:58:32 +01:00
|
|
|
|
// use very large frame with size of half the time range
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
Duration hugeFrame(SUP_MAX);
|
2011-01-09 11:41:08 +01:00
|
|
|
|
FixedFrameQuantiser case3 (hugeFrame);
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
CHECK (SUB_MIN == case3.gridLocal(SUB_MIN ));
|
|
|
|
|
|
CHECK (SUB_MIN == case3.gridLocal(SUB_MIN +TimeValue(1) ));
|
|
|
|
|
|
CHECK (SUB_MIN == case3.gridLocal( secs(-1) ));
|
|
|
|
|
|
CHECK (TimeValue(0) == case3.gridLocal( secs( 0) ));
|
|
|
|
|
|
CHECK (TimeValue(0) == case3.gridLocal( secs(+1) ));
|
|
|
|
|
|
CHECK (TimeValue(0) == case3.gridLocal(SUP_MAX -TimeValue(1) ));
|
|
|
|
|
|
CHECK (SUP_MAX == case3.gridLocal(SUP_MAX ));
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
|
|
|
|
|
// now displacing this grid by +1sec....
|
2011-03-31 18:43:50 +02:00
|
|
|
|
FixedFrameQuantiser case4 (hugeFrame, secs(1));
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
CHECK (SUB_MIN == case4.gridLocal(SUB_MIN ));
|
|
|
|
|
|
CHECK (SUB_MIN == case4.gridLocal(SUB_MIN +TimeValue(1) )); // clipped...
|
|
|
|
|
|
CHECK (SUB_MIN == case4.gridLocal(SUB_MIN +secs(1) )); // but now exact (unclipped)
|
|
|
|
|
|
CHECK (SUB_MIN == case4.gridLocal( secs(-1) ));
|
|
|
|
|
|
CHECK (SUB_MIN == case4.gridLocal( secs( 0) ));
|
|
|
|
|
|
CHECK (TimeValue(0) == case4.gridLocal( secs(+1) )); //.....now exactly the frame number zero
|
|
|
|
|
|
CHECK (TimeValue(0) == case4.gridLocal(SUP_MAX -TimeValue(1) ));
|
|
|
|
|
|
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
Library: rectify clipping of time::Duration (see #1263)
This is a deep refactoring to allow to represent the distance
between all valid time points as a time::Offset or time::Duration.
By design this is possible, since Time::MAX was defined as 1/30 of
the maximum value technically representable as int64_t. However,
introducing a different limiter for offsets and durations turns
out difficult, due to the inconsistencies in the exiting hierarchy
of temporal entities. Which in turn seems to stem from the unfortunate
decision to make time entities immutable, see #1261
Since the limiter is hard wired into the `time::TimeValue` constructor,
we are forced to create a "backdoor" of sorts, to pass up values
with different limiting from child classes. This would not be so
much of a problem if calculations weren't forced to go through `TimeVar`,
which does not distinguish between time points and time durations.
This solution rearranges all checks to be performed now by time::Offset,
while time::Duration will only take the absolute value at construction,
based on the fact that there is no valid construction path to yield
a duration which does not go through an offset first.
Later, when we're ready to sort out the implementation base of time values
(see #1258), this design issue should be revisited
- either we'll allow derived classes explicitly to invoke the limiter functions
- or we may be able to have an automatic conversion path from clearly
marked base implementation types, in which case we wouldn't use the
buildRaw_() and _raw() "backdoor" functions any more...
2022-12-05 00:58:32 +01:00
|
|
|
|
// think big...
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
TimeVar excess{SUP_MAX +secs(1)}; // this is a *loophole* to slide by the limitation of Time values
|
|
|
|
|
|
CHECK (SUP_MAX < excess);
|
|
|
|
|
|
CHECK (Duration{excess} < excess); // ...yet as soon as we construct another entity, the limitation applies
|
|
|
|
|
|
CHECK (Duration{excess} == SUP_MAX);
|
2011-01-09 11:41:08 +01:00
|
|
|
|
|
clean-up: relocate frame quantisation operations
The `FixedFrameQuantiser` relied on three functions from the raw-time handling library.
Since this (and NTSC drop-frame) are the only usages, these functions
can be relocated into the implemntation translation unit `lib/time/quantiser.cpp`
On closer inspection, this reveals some room for improvements:
Instead of relying on raw-computation functions written in C,
we could rather revert the dependency and express these computations
in terms of our Time-entities, which are written in C++, are much more
systematic and provide consistency checks and protection against numeric
overflow, all integrated with linear arithmetic and concise notation.
After performing these rearrangements,
most of the functions can be collapsed into ''almost nothing''.
This was taken as opportunity to re-check and improve the remaining
implementation core of the `FixedFrameQuantiser` -- the handling of
extreme corner cases can be much improved, now representing the
"grid-local time" as `Offset`, which doubles the possible value range.
The reworked unit test shows that, with this change, now the limitation
happens prior to quantisation, meaning that we always get a grid-aligned
result, even in the most extreme corner cases.
2025-05-28 23:49:01 +02:00
|
|
|
|
CHECK (SUP_MAX == case4.gridLocal(excess )); // Thus, more by accident, the next higher grid point can be computed
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (secs(1) == case4.timeOf(0));
|
|
|
|
|
|
CHECK (excess == case4.timeOf(1)); // The same loophole also allows to generate this next higher grid point
|
|
|
|
|
|
CHECK (excess == case4.timeOf(2)); // ...while the next after next will limited in computation
|
|
|
|
|
|
|
|
|
|
|
|
FixedFrameQuantiser broken (Duration::MAX, SUP_MAX); // Can drive this loophole to the extreme...
|
|
|
|
|
|
CHECK (secs(0) == broken.timeOf(-1)); // since there is leeway by one order of magnitude
|
|
|
|
|
|
CHECK (SUP_MAX == broken.timeOf(0));
|
|
|
|
|
|
CHECK (SUP_MAX+SUP_MAX > Duration::MAX);
|
|
|
|
|
|
CHECK (SUP_MAX+SUP_MAX == broken.timeOf(1));
|
|
|
|
|
|
CHECK (SUP_MAX+SUP_MAX == broken.timeOf(2));
|
|
|
|
|
|
|
2011-01-09 11:41:08 +01:00
|
|
|
|
// frame sizes below the time micro grid get trapped
|
2018-11-17 18:00:39 +01:00
|
|
|
|
long subAtomic = 2*TimeValue::SCALE; // too small for this universe...
|
2011-01-09 11:41:08 +01:00
|
|
|
|
VERIFY_ERROR (BOTTOM_VALUE, FixedFrameQuantiser quark(subAtomic) );
|
|
|
|
|
|
VERIFY_ERROR (BOTTOM_VALUE, FixedFrameQuantiser quark(Duration (FSecs (1,subAtomic))) );
|
2011-01-08 03:30:10 +01:00
|
|
|
|
}
|
2011-01-06 04:21:18 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (QuantiserBasics_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::time::test
|