2010-12-22 04:09:27 +01:00
|
|
|
|
/*
|
|
|
|
|
|
TimeQuantisation(Test) - handling of virtually grid aligned time values
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-22 04:09:27 +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.
|
2010-12-22 04:09:27 +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
|
|
|
|
* *****************************************************************/
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file time-quantisation-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TimeQuantisation_test
|
2024-12-07 18:15:44 +01:00
|
|
|
|
** @todo 2024/24 only two of the four timecode formats are implemented /////////////////////////////////////TICKET #736 : HMS and Seconds not implemented
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2011-01-01 03:56:31 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/asset/meta/time-grid.hpp"
|
2011-01-05 05:14:10 +01:00
|
|
|
|
#include "lib/time/timequant.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2010-12-22 04:09:27 +01:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
2010-12-26 23:00:34 +01:00
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
2010-12-26 23:00:34 +01:00
|
|
|
|
using boost::lexical_cast;
|
|
|
|
|
|
using util::isnil;
|
2011-01-02 01:21:39 +01:00
|
|
|
|
using util::contains;
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace time{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
2018-11-15 23:59:23 +01:00
|
|
|
|
using steam::asset::meta::TimeGrid;
|
2011-01-02 01:21:39 +01:00
|
|
|
|
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/****************************************************//**
|
2011-01-01 03:56:31 +01:00
|
|
|
|
* @test verify handling of quantised time values.
|
2024-12-07 18:15:44 +01:00
|
|
|
|
* - the simple usage, just referring to an
|
2011-01-17 07:25:22 +01:00
|
|
|
|
* predefined grid by name
|
|
|
|
|
|
* - explicitly defining an quantiser
|
|
|
|
|
|
* - converting these quantised values into
|
|
|
|
|
|
* various timecode formats
|
|
|
|
|
|
* - error detection
|
2010-12-22 04:09:27 +01:00
|
|
|
|
*/
|
|
|
|
|
|
class TimeQuantisation_test : public Test
|
|
|
|
|
|
{
|
2011-01-17 07:25:22 +01:00
|
|
|
|
int
|
|
|
|
|
|
random_or_get (Arg arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isnil(arg))
|
2024-11-13 02:23:23 +01:00
|
|
|
|
{// use random time value for all tests
|
|
|
|
|
|
seedRand();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
return 1 + rani(100'000);
|
2024-11-13 02:23:23 +01:00
|
|
|
|
}
|
2024-12-07 18:15:44 +01:00
|
|
|
|
else // use argument as 1/10 seconds
|
|
|
|
|
|
return 10 * lexical_cast<int> (arg[1]);
|
2011-01-17 07:25:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-07 18:15:44 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* @param arg number as 1/10sec
|
|
|
|
|
|
* @note using random time 0..100s if no argument given
|
|
|
|
|
|
*/
|
2010-12-22 04:09:27 +01:00
|
|
|
|
virtual void
|
2024-12-07 18:15:44 +01:00
|
|
|
|
run (Arg arg)
|
2010-12-22 04:09:27 +01:00
|
|
|
|
{
|
2024-12-07 18:15:44 +01:00
|
|
|
|
Time ref (random_or_get(arg),0,0,0);
|
2011-03-31 18:43:50 +02:00
|
|
|
|
CHECK (TimeValue(0) < ref);
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
2011-01-02 01:21:39 +01:00
|
|
|
|
checkSimpleUsage (ref);
|
2011-01-01 03:56:31 +01:00
|
|
|
|
check_theFullStory (ref);
|
|
|
|
|
|
checkMultipleGrids (ref);
|
2011-01-17 07:25:22 +01:00
|
|
|
|
checkGridBinding (ref);
|
2025-06-07 23:59:57 +02:00
|
|
|
|
}
|
2010-12-22 04:09:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-02 01:21:39 +01:00
|
|
|
|
checkSimpleUsage (TimeValue org)
|
2010-12-22 04:09:27 +01:00
|
|
|
|
{
|
2011-01-01 03:56:31 +01:00
|
|
|
|
TimeGrid::build("my_simple_grid", 25); // "someone" has defined a time grid
|
|
|
|
|
|
|
|
|
|
|
|
QuTime qVal (org, "my_simple_grid"); // create time quantised to this grid
|
|
|
|
|
|
|
|
|
|
|
|
FrameNr count(qVal); // materialise this quantised time into..
|
|
|
|
|
|
int n = count; // frame count, accessible as plain number
|
|
|
|
|
|
|
2024-12-07 18:15:44 +01:00
|
|
|
|
CHECK (Time(FSecs(n, 25)) <= org); // verify quantisation: the original time
|
|
|
|
|
|
CHECK (org < Time(FSecs(n+1, 25))); // is properly bracketed by [n, n+1[
|
2010-12-22 04:09:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-01 03:56:31 +01:00
|
|
|
|
check_theFullStory (TimeValue org)
|
|
|
|
|
|
{
|
2024-12-07 18:15:44 +01:00
|
|
|
|
cout << "TEST rawTime:"<<Time{org} << endl;
|
2011-01-15 00:52:02 +01:00
|
|
|
|
PQuant fixQ (new FixedFrameQuantiser(25));
|
2011-01-01 03:56:31 +01:00
|
|
|
|
QuTime qVal (org, fixQ);
|
|
|
|
|
|
|
2024-12-07 18:15:44 +01:00
|
|
|
|
CHECK ( qVal == org); // Note: stores the raw value, but tagged with a grid
|
|
|
|
|
|
CHECK ( fixQ.get() == PQuant(qVal).get());
|
2011-01-04 01:45:11 +01:00
|
|
|
|
CHECK ( qVal.supports<format::Frames>());
|
|
|
|
|
|
CHECK ( qVal.supports<format::Smpte>());
|
2011-01-01 03:56:31 +01:00
|
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
|
SmpteTC smpteTCode = qVal.formatAs<format::Smpte>();
|
2011-01-01 03:56:31 +01:00
|
|
|
|
showTimeCode (smpteTCode);
|
|
|
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
|
HmsTC pureTimeCode = qVal.formatAs<format::Hms>();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
showTimeCode (pureTimeCode); ////////////////////////////////////////////////////////////////TICKET #736 : HMS not implemented yet
|
2011-01-05 02:43:29 +01:00
|
|
|
|
|
|
|
|
|
|
FrameNr frameTCode = qVal.formatAs<format::Frames>();
|
2011-01-01 03:56:31 +01:00
|
|
|
|
showTimeCode (frameTCode);
|
|
|
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
|
Secs seconds = qVal.formatAs<format::Seconds>();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
showTimeCode (seconds); ////////////////////////////////////////////////////////////////TICKET #736 : Seconds not implemented yet
|
2011-01-01 03:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class TC>
|
|
|
|
|
|
void
|
|
|
|
|
|
showTimeCode (TC timecodeValue)
|
2010-12-22 04:09:27 +01:00
|
|
|
|
{
|
2024-12-07 18:15:44 +01:00
|
|
|
|
cout << timecodeValue.describe()
|
|
|
|
|
|
<< " time = "<< timecodeValue.getTime()
|
2011-01-05 05:14:10 +01:00
|
|
|
|
<< " code = "<< timecodeValue
|
2011-01-05 02:43:29 +01:00
|
|
|
|
<< endl;
|
2010-12-22 04:09:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-01 03:56:31 +01:00
|
|
|
|
checkMultipleGrids (TimeValue org)
|
2010-12-22 04:09:27 +01:00
|
|
|
|
{
|
2011-01-15 03:49:35 +01:00
|
|
|
|
TimeGrid::build("my_alternate_grid", FrameRate::NTSC);
|
2011-01-01 03:56:31 +01:00
|
|
|
|
|
|
|
|
|
|
QuTime palVal (org, "my_simple_grid");
|
|
|
|
|
|
QuTime ntscVal (org, "my_alternate_grid");
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (org == palVal);
|
|
|
|
|
|
CHECK (org == ntscVal);
|
|
|
|
|
|
|
|
|
|
|
|
FrameNr palNr (palVal);
|
|
|
|
|
|
FrameNr ntscNr(ntscVal);
|
2011-01-17 07:25:22 +01:00
|
|
|
|
CHECK (palNr <= ntscNr);
|
2010-12-22 04:09:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-01-01 03:56:31 +01:00
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-17 07:25:22 +01:00
|
|
|
|
checkGridBinding (TimeValue org)
|
2011-01-01 03:56:31 +01:00
|
|
|
|
{
|
2011-01-16 23:58:42 +01:00
|
|
|
|
// refer to a grid not yet defined
|
2012-02-06 02:49:54 +01:00
|
|
|
|
VERIFY_ERROR (UNKNOWN_GRID, QuTime weird(org, "special_funny_grid"));
|
2011-01-01 03:56:31 +01:00
|
|
|
|
|
|
|
|
|
|
TimeGrid::build("special_funny_grid", 1); // provide the grid's definition (1 frame per second)
|
|
|
|
|
|
|
2011-01-16 23:58:42 +01:00
|
|
|
|
QuTime funny (org, "special_funny_grid"); // now OK, grid is known
|
2011-01-05 02:43:29 +01:00
|
|
|
|
int cnt = funny.formatAs<format::Frames>();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
// and now performing quantisation is OK
|
2011-01-01 03:56:31 +01:00
|
|
|
|
SmpteTC smpte (funny); // also converting into SMPTE (which implies frame quantisation)
|
2011-01-18 05:01:25 +01:00
|
|
|
|
CHECK (0 == smpte.frames); // we have 1fps, thus the frame part is always zero!
|
|
|
|
|
|
CHECK (cnt % 60 == smpte.secs); // and the seconds part will be in sync with the frame count
|
2011-01-01 03:56:31 +01:00
|
|
|
|
}
|
2010-12-22 04:09:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (TimeQuantisation_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::time::test
|